From nobody Mon Jan 23 22:12:02 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4P148M1dSkz2t0TV; Mon, 23 Jan 2023 22:12:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4P148L6w86z3LDV; Mon, 23 Jan 2023 22:12:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674511923; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=yTFBD2svIFz/XCOqcn0BmILZhshu1p/xJVCkmOv5dQY=; b=YP9fwoY1TwRuHJGhQTjL4ZznEM71HAQVLqqNLpcmOhB0Wux9qb0loqFvKnsYraCjIosPbs kcxlMSTV6l5ftQU2KHbvst5L4L+PoQRfidp3bWmHSokctGOhzn+oP/Hcw/+9SqRilg0esw qJBido/N7H7mcj5smUx8tR8sCO+M7EL2FahpjswdDZFeiZQZmS96RDLdPj68eZp2HjQK5q 1zFJ3rhYzgQ7yVImOJBwl4kfUqOEayp+5VH9M8jJtputNbZ+H/gEBTOVyhgfY+q/JpHqWQ uAeOC2a6Ewtm40bbsoS4OIt9bJTGMqkLfR6nSP56OHztyajCsWePNfEitblfUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674511923; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=yTFBD2svIFz/XCOqcn0BmILZhshu1p/xJVCkmOv5dQY=; b=MlFMXzvFbNll/xFC7den56JBWvenH5grdJd5nSXfFo68sza3UmMhX484La/BcLJl3RIBrj IN7nk7brBR5RiS0IPNnvpUh3jbHncabIzo/alXaP4Rns7Sh10R+RZw0wZquVCaTeLsaPG3 OX60ZCRsp7PwUyE0uXJkHrT76bjPQO0xKa+6Ue2wbaiPT3KFb732tiYC0Cd1AF7SY0nv60 nH996BWqoMLCBRuk2Fc8K7zlZTzSPbZePZjG8zhQuGKBhA1I0XxC92r1ZGodL10cpeV8/H oG4ms6VMaX3vjkUqP6Sw1A3IoS7CAAMkgYeECMoEQCXXO/ab5JhQBw4ID00O5w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674511923; a=rsa-sha256; cv=none; b=vztpgycpk9Txv4QIenBcnYSKOrOn3H4VsepRo7eo5U5+fOpMy7BdmmY4xkVW9tjiRNMtd/ 8Hp/a0+lT/0DGLGHpTJjnwgUrxaC8i4lPFLhz7dtGPpesdrhXVumL34xLw1GMHKeeyMirS deXo3DrKuzSU1NBvBXZSCDdb07P14m69ceBFxPqPKtSbxflYDALwfSphwfe3E548zI1PAT 5BpvfJp1k/V8vmijkCto+OUBN8W7ScdNQ80i1zMMiNlz2zOD/I8h9bNYKvEfaxuGqdGeHR wVYur54ywcpBc8xVp+3mXvCUL5ZkELJK1/7OO0RtKLXBI0Hrt+NY+FgVdW6ZmA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4P148L54kszlnh; Mon, 23 Jan 2023 22:12:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30NMC2Xf012903; Mon, 23 Jan 2023 22:12:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30NMC2f4012902; Mon, 23 Jan 2023 22:12:02 GMT (envelope-from git) Date: Mon, 23 Jan 2023 22:12:02 GMT Message-Id: <202301232212.30NMC2f4012902@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: 5713f31ca0d9 - stable/13 - netlink: store user-provided rtm_protocol List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 5713f31ca0d96e90beb274000683656d171a77d9 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=5713f31ca0d96e90beb274000683656d171a77d9 commit 5713f31ca0d96e90beb274000683656d171a77d9 Author: Alexander V. Chernikov AuthorDate: 2022-12-02 19:26:34 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-01-23 22:04:03 +0000 netlink: store user-provided rtm_protocol Store user-supplied source protocol in the nexthops and nexthop groups. Protocol specification help routing daemons like bird to quickly identify self-originated routes after the crash or restart. Example: ``` 10.2.0.0/24 via 10.0.0.2 dev vtnet0 proto bird 10.3.0.0/24 proto bird nexthop via 10.0.0.2 dev vtnet0 weight 3 nexthop via 10.0.0.3 dev vtnet0 weight 4 ``` (cherry picked from commit cc2be311772d368541157dcf8bf989f216a5b994) --- sys/net/route/nhop_ctl.c | 1 + sys/netlink/route/route.c | 33 +++++++++++++++++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/sys/net/route/nhop_ctl.c b/sys/net/route/nhop_ctl.c index 9359a0b5126e..d042d9519f6b 100644 --- a/sys/net/route/nhop_ctl.c +++ b/sys/net/route/nhop_ctl.c @@ -714,6 +714,7 @@ nhop_copy(struct nhop_object *nh, const struct nhop_object *nh_orig) nh_priv->nh_type = nh_orig->nh_priv->nh_type; nh_priv->rt_flags = nh_orig->nh_priv->rt_flags; nh_priv->nh_fibnum = nh_orig->nh_priv->nh_fibnum; + nh_priv->nh_origin = nh_orig->nh_priv->nh_origin; } void diff --git a/sys/netlink/route/route.c b/sys/netlink/route/route.c index 852843af1b7d..78949a643227 100644 --- a/sys/netlink/route/route.c +++ b/sys/netlink/route/route.c @@ -271,13 +271,8 @@ dump_px(uint32_t fibnum, const struct nlmsghdr *hdr, if (fibnum < 255) rtm->rtm_table = (unsigned char)fibnum; rtm->rtm_scope = RT_SCOPE_UNIVERSE; - if (!NH_IS_NHGRP(rnd->rnd_nhop)) { - rtm->rtm_protocol = nl_get_rtm_protocol(rnd->rnd_nhop); - rtm->rtm_type = get_rtm_type(rnd->rnd_nhop); - } else { - rtm->rtm_protocol = RTPROT_UNSPEC; /* TODO: protocol from nhg? */ - rtm->rtm_type = RTN_UNICAST; - } + rtm->rtm_protocol = nl_get_rtm_protocol(rnd->rnd_nhop); + rtm->rtm_type = get_rtm_type(rnd->rnd_nhop); nlattr_add_u32(nw, NL_RTA_TABLE, fibnum); @@ -445,6 +440,7 @@ struct nl_parsed_route { uint32_t rtax_mtu; uint8_t rtm_family; uint8_t rtm_dst_len; + uint8_t rtm_protocol; }; #define _IN(_field) offsetof(struct rtmsg, _field) @@ -469,6 +465,7 @@ static const struct nlattr_parser nla_p_rtmsg[] = { static const struct nlfield_parser nlf_p_rtmsg[] = { {.off_in = _IN(rtm_family), .off_out = _OUT(rtm_family), .cb = nlf_get_u8 }, {.off_in = _IN(rtm_dst_len), .off_out = _OUT(rtm_dst_len), .cb = nlf_get_u8 }, + {.off_in = _IN(rtm_protocol), .off_out = _OUT(rtm_protocol), .cb = nlf_get_u8 }, }; #undef _IN #undef _OUT @@ -736,6 +733,8 @@ create_nexthop_one(struct nl_parsed_route *attrs, struct rta_mpath_nh *mpnh, if (mpnh->ifp != NULL) nhop_set_transmit_ifp(nh, mpnh->ifp); nhop_set_rtflags(nh, attrs->rta_rtflags); + if (attrs->rtm_protocol > RTPROT_STATIC) + nhop_set_origin(nh, attrs->rtm_protocol); *pnh = finalize_nhop(nh, &error); @@ -748,13 +747,13 @@ create_nexthop_from_attrs(struct nl_parsed_route *attrs, struct nl_pstate *npt, int *perror) { struct nhop_object *nh = NULL; - int error = 0; if (attrs->rta_multipath != NULL) { #ifdef ROUTE_MPATH /* Multipath w/o explicit nexthops */ int num_nhops = attrs->rta_multipath->num_nhops; struct weightened_nhop *wn = npt_alloc(npt, sizeof(*wn) * num_nhops); + int error = 0; for (int i = 0; i < num_nhops; i++) { struct rta_mpath_nh *mpnh = &attrs->rta_multipath->nhops[i]; @@ -769,12 +768,20 @@ create_nexthop_from_attrs(struct nl_parsed_route *attrs, } if (error == 0) { struct rib_head *rh = nhop_get_rh(wn[0].nh); - - error = nhgrp_get_group(rh, wn, num_nhops, 0, - (struct nhgrp_object **)&nh); - + struct nhgrp_object *nhg; + + nhg = nhgrp_alloc(rh->rib_fibnum, rh->rib_family, + wn, num_nhops, perror); + if (nhg != NULL) { + if (attrs->rtm_protocol > RTPROT_STATIC) + nhgrp_set_origin(nhg, attrs->rtm_protocol); + nhg = nhgrp_get_nhgrp(nhg, perror); + } for (int i = 0; i < num_nhops; i++) nhop_free(wn[i].nh); + if (nhg != NULL) + return ((struct nhop_object *)nhg); + error = *perror; } #else error = ENOTSUP; @@ -799,6 +806,8 @@ create_nexthop_from_attrs(struct nl_parsed_route *attrs, if (attrs->rta_rtflags & RTF_REJECT) nhop_set_blackhole(nh, NHF_REJECT); nhop_set_rtflags(nh, attrs->rta_rtflags); + if (attrs->rtm_protocol > RTPROT_STATIC) + nhop_set_origin(nh, attrs->rtm_protocol); nh = finalize_nhop(nh, perror); }