From nobody Fri Dec 02 20:08:58 2022 X-Original-To: dev-commits-src-main@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 4NP3tM0z5Cz4j92h; Fri, 2 Dec 2022 20:08:59 +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 4NP3tL5qDlz4G9f; Fri, 2 Dec 2022 20:08:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670011738; 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=xyaQunhA9vVH727EsCvywHW/mQCob9/Qc8oaA7ZuaHM=; b=JeOZL6zQzA+4vA0ZW5vWMC67m7v2g6DcBO4PeHsUCk9Pss1OvP5lrt6CWPMH71jV8Xw2ey wRVEGuZnbaKuxejZbtNwVN1dYA4QQWCd1vXLleuTJBTBpa5o3SjEAO+NRXESMEV2ykj8y3 UI0u+luVViEZxyXFl8w/YvGeEE8xEfvIBHvXa/mRd7/t4QSO+pW/TfX6uKRDsMp7xaUtB1 pIOlxeny6SvwnxACGEjVQWgmaicmbLdGciHg4Bx2YsYUcHX90+L8Upw/kALBxLF8QX4+gS tvFsRkGrVd3TFKFdKF6bxk+17GPYNZiC9rSq0gvPE4iWJuXFmH8cdz26V6pAeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670011738; 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=xyaQunhA9vVH727EsCvywHW/mQCob9/Qc8oaA7ZuaHM=; b=Mz5QDNlYXp0g4e8sl69N7xiulNFKNEs3A26jO1ru1ICZ/7CZyfJuev3tQmj/Jxz6vagh3F cfYnpbR/n0nQDg0AfKj+aoBvxesQPYyFU/IHzD2jQFAOctOd/j+L6K1ZHWUbLcQVfnf9so h9yqq5SPxr15LdH2fzxt4jjP8EIuG1+oY00VxFbsjD875EmLrZh/BZGgiU8aOZXi4IQKqp aZ1ALEB2RDCuMpQPRsO2FMsIAi+RcX0BI/QTxxloRJxHv1VKrwZdNqSQBTFn89BqUrsg3Y f20kFOJuqPd9Ic36bWUUZMrDTMtUiIb3CqXMOhtJo+4FP9XuNgIxhnM4RXin9Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1670011738; a=rsa-sha256; cv=none; b=fZDO+rhWuwmY1AbmcevljAkPUlpdIAZKCeCn424E31CFTncKQUUifoiELz7cm96l+nmUvM GWaEYrrUSEQ8qWLN7OGDDJjgR6KQcm/BPjBC5ZHQJobp6bBAAea2DqC/U/neFA7tKy8YMR JEWUJDXUVsLmPgEfqOKuLdD7Cc0uzTWmSklRzSARiFvUC0+Ea/TGHQLINY46MqrnsUM322 /Bt6TpKQ7Jv4BDQ7goTxhC/YD5xl+EZEpKLCpH8+5IYeWxLcSlR8OI+HTNe+RrcUY7TFgJ jqZNN+5jpD42R+q0fYuKQlFKDfGHVm/XwtuNajVzd/sLhJbZGYSXgvoZhEJXcw== 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 4NP3tL4vCNzSZV; Fri, 2 Dec 2022 20:08:58 +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 2B2K8wZP006264; Fri, 2 Dec 2022 20:08:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2B2K8w73006263; Fri, 2 Dec 2022 20:08:58 GMT (envelope-from git) Date: Fri, 2 Dec 2022 20:08:58 GMT Message-Id: <202212022008.2B2K8w73006263@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: cc2be311772d - main - netlink: store user-provided rtm_protocol List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: cc2be311772d368541157dcf8bf989f216a5b994 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=cc2be311772d368541157dcf8bf989f216a5b994 commit cc2be311772d368541157dcf8bf989f216a5b994 Author: Alexander V. Chernikov AuthorDate: 2022-12-02 19:26:34 +0000 Commit: Alexander V. Chernikov CommitDate: 2022-12-02 20:08:47 +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 ``` --- 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 d5d921dd66c7..201a1ed0a094 100644 --- a/sys/net/route/nhop_ctl.c +++ b/sys/net/route/nhop_ctl.c @@ -715,6 +715,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); }