From nobody Mon Aug 29 12:59:36 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 4MGVrn0FKKz4b5f0; Mon, 29 Aug 2022 12:59:37 +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 4MGVrm6kxVz47Jn; Mon, 29 Aug 2022 12:59:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1661777976; 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=P6fzowI4nxmbZgx4aO7NKElzlx/M+llcp1Od2Oy+dKQ=; b=Zyq0924lWmhhRYTctAms8CbdbFiIV10x4cX0ftahb1cR5VrdUfPeYpTKKve8FwOcDWBkYH lM2TQ/Mzxd2Pu7q0n9avyhF7ir2d6JxsyfG41/8eUQD394TYLz4xyNS/4+JK6hETPhKxJ3 NWr4TswIDGVcNTc+nmIpmfGHfCqVsQOblPF8nCIakZCpi1FQU6jCr7hwgklDj/vbe5Z7zi aXQ/d28nIiQI4PahZugnlTe38H+2dZWeHn3nas3diB0VqXb0/6cq6QVAH/poEdT5rlyePy u1DWtSCnbeitGGBYn1Oh0oKP7URKdcDesAuf4Gxyc7Yc0t8E2KdNtFT2xtpt7A== 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 4MGVrm5c8ZzR5c; Mon, 29 Aug 2022 12:59:36 +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 27TCxaYh001090; Mon, 29 Aug 2022 12:59:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27TCxagN001089; Mon, 29 Aug 2022 12:59:36 GMT (envelope-from git) Date: Mon, 29 Aug 2022 12:59:36 GMT Message-Id: <202208291259.27TCxagN001089@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: db4ca19002c0 - main - routing: add ability to store opaque indentifiers in nhops/nhgs 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: db4ca19002c05d0bf83e85a5402005c9162aeee9 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1661777977; 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=P6fzowI4nxmbZgx4aO7NKElzlx/M+llcp1Od2Oy+dKQ=; b=DrCwj6mMhiNrcXzQM89yJ4VCRSMfW1xnItmz8qiZwieecaeJ5DZjcLgkbjKdgHNyTmgy9+ 1xW9xOxdbeNY4FF8G4Jg/Fz+/Bl/5jXYZyWUQupwIv7exzlV801mAtBtRzhxR69wofCvhV IBJ14pLws8eN1tS0ffL4rM1VnitpiEO3UvlgDSkfYqRiza76e5vl/nf0+z+ZgBdqSvWLPA wX3ihhzGEZQQRnYlx6mCYZMhuAKljld3RbaYo27ta0pHl7DSc8IrgMHKwAA1kZESm8Ruw4 CFAzKFaT104WJ/+iuoz7oor5/1OOstE07Vnth6OLV0rSFeqjbuYnPCP41YDhZw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1661777977; a=rsa-sha256; cv=none; b=BzzZaeZ+I+LOc1vJvwCNV2pwmcvZxyEIoMS2qxAOz1pJfWU5Cyfzt87YKvtfexH4qMJT9K vNLVI6faMLHBIQSD+OWQJhjg3CGZf9KFnGLyaOlWj85nod8XVjSSPaEEGLQnlPEKi1vWpb y6/4RAFC7wWOly0hKNdUt30XhBx+MfRqHfzUaa7iVA5Wokxr0iyJq7UqZw2DMrri8NMgfx fXSTSQXmtzKqZSD2upnFAC4uMOf+AAzN8W1jZNYqdh5Yn2bmo+CibQ/gWc3XrpsaRvNTgX tWUOufLUHI0oQLkFeYZ09hD3cMAWoaCW+7n0igXHPXnZqXjxT2Dd3djPE+nZKQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=db4ca19002c05d0bf83e85a5402005c9162aeee9 commit db4ca19002c05d0bf83e85a5402005c9162aeee9 Author: Alexander V. Chernikov AuthorDate: 2022-08-29 12:20:24 +0000 Commit: Alexander V. Chernikov CommitDate: 2022-08-29 12:20:28 +0000 routing: add ability to store opaque indentifiers in nhops/nhgs This is a pre-requisite for the direct nexthop/nexhop group operations via netlink. MFC after: 2 weeks --- sys/net/route/nhgrp.c | 2 +- sys/net/route/nhgrp_ctl.c | 26 +++++++++++++++++++------- sys/net/route/nhgrp_var.h | 1 + sys/net/route/nhop.h | 4 ++++ sys/net/route/nhop_ctl.c | 12 ++++++++++++ sys/net/route/nhop_var.h | 1 + sys/net/route/route_ctl.c | 2 +- sys/net/route/route_ctl.h | 2 ++ sys/net/route/route_var.h | 2 -- 9 files changed, 41 insertions(+), 11 deletions(-) diff --git a/sys/net/route/nhgrp.c b/sys/net/route/nhgrp.c index f565842bb7d4..358e5d1eaace 100644 --- a/sys/net/route/nhgrp.c +++ b/sys/net/route/nhgrp.c @@ -115,7 +115,7 @@ cmp_nhgrp(const struct nhgrp_priv *a, const struct nhgrp_priv *b) * different set of "data plane" nexthops. * For now, ignore the data plane and focus on the control plane list. */ - if (a->nhg_nh_count != b->nhg_nh_count) + if (a->nhg_nh_count != b->nhg_nh_count || a->nhg_uidx != b->nhg_uidx) return (0); return !memcmp(a->nhg_nh_weights, b->nhg_nh_weights, sizeof(struct weightened_nhop) * a->nhg_nh_count); diff --git a/sys/net/route/nhgrp_ctl.c b/sys/net/route/nhgrp_ctl.c index 3a7ebee8def2..90cd5b1e45a0 100644 --- a/sys/net/route/nhgrp_ctl.c +++ b/sys/net/route/nhgrp_ctl.c @@ -80,7 +80,7 @@ static int wn_cmp_idx(const void *a, const void *b); static void sort_weightened_nhops(struct weightened_nhop *wn, int num_nhops); static struct nhgrp_priv *get_nhgrp(struct nh_control *ctl, - struct weightened_nhop *wn, int num_nhops, int *perror); + struct weightened_nhop *wn, int num_nhops, uint32_t uidx, int *perror); static void destroy_nhgrp(struct nhgrp_priv *nhg_priv); static void destroy_nhgrp_epoch(epoch_context_t ctx); static void free_nhgrp_nhops(struct nhgrp_priv *nhg_priv); @@ -465,7 +465,7 @@ free_nhgrp_nhops(struct nhgrp_priv *nhg_priv) */ struct nhgrp_priv * get_nhgrp(struct nh_control *ctl, struct weightened_nhop *wn, int num_nhops, - int *perror) + uint32_t uidx, int *perror) { struct nhgrp_priv *key, *nhg_priv; @@ -497,6 +497,7 @@ get_nhgrp(struct nh_control *ctl, struct weightened_nhop *wn, int num_nhops, *perror = ENOMEM; return (NULL); } + key->nhg_uidx = uidx; nhg_priv = find_nhgrp(ctl, key); if (nhg_priv != NULL) { @@ -577,7 +578,7 @@ append_nhops(struct nh_control *ctl, const struct nhgrp_object *gr_orig, memcpy(&pnhops[curr_nhops], wn, num_nhops * sizeof(struct weightened_nhop)); curr_nhops += num_nhops; - nhg_priv = get_nhgrp(ctl, pnhops, curr_nhops, perror); + nhg_priv = get_nhgrp(ctl, pnhops, curr_nhops, 0, perror); if (pnhops != (struct weightened_nhop *)&storage[0]) free(pnhops, M_TEMP); @@ -598,13 +599,13 @@ append_nhops(struct nh_control *ctl, const struct nhgrp_object *gr_orig, */ int nhgrp_get_group(struct rib_head *rh, struct weightened_nhop *wn, int num_nhops, - struct nhgrp_object **pnhg) + uint32_t uidx, struct nhgrp_object **pnhg) { struct nh_control *ctl = rh->nh_control; struct nhgrp_priv *nhg_priv; int error; - nhg_priv = get_nhgrp(ctl, wn, num_nhops, &error); + nhg_priv = get_nhgrp(ctl, wn, num_nhops, uidx, &error); if (nhg_priv != NULL) *pnhg = nhg_priv->nhg; @@ -658,7 +659,7 @@ nhgrp_get_filtered_group(struct rib_head *rh, const struct rtentry *rt, if (nhop_try_ref_object(rnd->rnd_nhop) == 0) error = EAGAIN; } else { - mp_priv = get_nhgrp(ctl, pnhops, num_nhops, &error); + mp_priv = get_nhgrp(ctl, pnhops, num_nhops, 0, &error); if (mp_priv != NULL) rnd->rnd_nhgrp = mp_priv->nhg; rnd->rnd_weight = 0; @@ -699,7 +700,7 @@ nhgrp_get_addition_group(struct rib_head *rh, struct route_nhop_data *rnd_orig, /* Simple merge of 2 non-multipath nexthops */ wn[1].nh = rnd_orig->rnd_nhop; wn[1].weight = rnd_orig->rnd_weight; - nhg_priv = get_nhgrp(ctl, wn, 2, &error); + nhg_priv = get_nhgrp(ctl, wn, 2, 0, &error); } else { /* Get new nhop group with @rt->rt_nhop as an additional nhop */ nhg_priv = append_nhops(ctl, rnd_orig->rnd_nhgrp, &wn[0], 1, @@ -731,6 +732,17 @@ nhgrp_get_nhops(const struct nhgrp_object *nhg, uint32_t *pnum_nhops) return (nhg_priv->nhg_nh_weights); } +uint32_t +nhgrp_get_uidx(const struct nhgrp_object *nhg) +{ + const struct nhgrp_priv *nhg_priv; + + KASSERT(((nhg->nhg_flags & MPF_MULTIPATH) != 0), ("nhop is not mpath")); + + nhg_priv = NHGRP_PRIV_CONST(nhg); + return (nhg_priv->nhg_uidx); +} + /* * Prints nexhop group @nhg data in the provided @buf. * Example: nhg#33/sz=3:[#1:100,#2:100,#3:100] diff --git a/sys/net/route/nhgrp_var.h b/sys/net/route/nhgrp_var.h index ba90a3feedc8..3d894857558d 100644 --- a/sys/net/route/nhgrp_var.h +++ b/sys/net/route/nhgrp_var.h @@ -47,6 +47,7 @@ struct nhgrp_priv { uint32_t nhg_idx; + uint32_t nhg_uidx; uint8_t nhg_nh_count; /* number of items in nh_weights */ uint8_t nhg_spare[3]; u_int nhg_refcount; /* use refcount */ diff --git a/sys/net/route/nhop.h b/sys/net/route/nhop.h index ee4f79d2bb47..9d0891c5b978 100644 --- a/sys/net/route/nhop.h +++ b/sys/net/route/nhop.h @@ -199,6 +199,8 @@ void nhop_set_src(struct nhop_object *nh, struct ifaddr *ifa); void nhop_set_transmit_ifp(struct nhop_object *nh, struct ifnet *ifp); uint32_t nhop_get_idx(const struct nhop_object *nh); +uint32_t nhop_get_uidx(const struct nhop_object *nh); +void nhop_set_uidx(struct nhop_object *nh, uint32_t uidx); enum nhop_type nhop_get_type(const struct nhop_object *nh); int nhop_get_rtflags(const struct nhop_object *nh); struct vnet *nhop_get_vnet(const struct nhop_object *nh); @@ -210,6 +212,8 @@ void nhop_set_fibnum(struct nhop_object *nh, uint32_t fibnum); uint32_t nhop_get_expire(const struct nhop_object *nh); void nhop_set_expire(struct nhop_object *nh, uint32_t expire); +struct nhgrp_object; +uint32_t nhgrp_get_uidx(const struct nhgrp_object *nhg); #endif /* _KERNEL */ /* Kernel <> userland structures */ diff --git a/sys/net/route/nhop_ctl.c b/sys/net/route/nhop_ctl.c index 46a5c7befd65..4af57d766ab7 100644 --- a/sys/net/route/nhop_ctl.c +++ b/sys/net/route/nhop_ctl.c @@ -780,6 +780,18 @@ nhop_get_idx(const struct nhop_object *nh) return (nh->nh_priv->nh_idx); } +uint32_t +nhop_get_uidx(const struct nhop_object *nh) +{ + return (nh->nh_priv->nh_uidx); +} + +void +nhop_set_uidx(struct nhop_object *nh, uint32_t uidx) +{ + nh->nh_priv->nh_uidx = uidx; +} + enum nhop_type nhop_get_type(const struct nhop_object *nh) { diff --git a/sys/net/route/nhop_var.h b/sys/net/route/nhop_var.h index 3cc7da4649a5..c3c442a4bfa3 100644 --- a/sys/net/route/nhop_var.h +++ b/sys/net/route/nhop_var.h @@ -79,6 +79,7 @@ struct nhop_priv { uint16_t nh_type; /* nexthop type */ uint32_t rt_flags; /* routing flags for the control plane */ uint32_t nh_expire; /* path expiration time */ + uint32_t nh_uidx; /* userland-provided index */ /* nhop lookup comparison end */ uint32_t nh_idx; /* nexthop index */ uint32_t nh_fibnum; /* nexthop fib */ diff --git a/sys/net/route/route_ctl.c b/sys/net/route/route_ctl.c index dbfa25500df4..8256fa0c7162 100644 --- a/sys/net/route/route_ctl.c +++ b/sys/net/route/route_ctl.c @@ -1181,7 +1181,7 @@ change_mpath_route(struct rib_head *rnh, struct rtentry *rt, wn_new[found_idx].nh = nh_new; wn_new[found_idx].weight = get_info_weight(info, wn[found_idx].weight); - error = nhgrp_get_group(rnh, wn_new, num_nhops, &rnd_new.rnd_nhgrp); + error = nhgrp_get_group(rnh, wn_new, num_nhops, 0, &rnd_new.rnd_nhgrp); nhop_free(nh_new); free(wn_new, M_TEMP); diff --git a/sys/net/route/route_ctl.h b/sys/net/route/route_ctl.h index 530a8fb5c8f0..1fc67591c2e8 100644 --- a/sys/net/route/route_ctl.h +++ b/sys/net/route/route_ctl.h @@ -166,6 +166,8 @@ struct weightened_nhop; const struct weightened_nhop *nhgrp_get_nhops(const struct nhgrp_object *nhg, uint32_t *pnum_nhops); uint32_t nhgrp_get_count(struct rib_head *rh); +int nhgrp_get_group(struct rib_head *rh, struct weightened_nhop *wn, int num_nhops, + uint32_t uidx, struct nhgrp_object **pnhg); /* Route subscriptions */ enum rib_subscription_type { diff --git a/sys/net/route/route_var.h b/sys/net/route/route_var.h index 2f21d959387b..51a4285e673e 100644 --- a/sys/net/route/route_var.h +++ b/sys/net/route/route_var.h @@ -304,8 +304,6 @@ void nhgrp_ctl_unlink_all(struct nh_control *ctl); /* nhgrp_ctl.c */ int nhgrp_dump_sysctl(struct rib_head *rh, struct sysctl_req *w); -int nhgrp_get_group(struct rib_head *rh, struct weightened_nhop *wn, - int num_nhops, struct nhgrp_object **pnhg); int nhgrp_get_filtered_group(struct rib_head *rh, const struct rtentry *rt, const struct nhgrp_object *src, rib_filter_f_t flt_func, void *flt_data, struct route_nhop_data *rnd);