From nobody Fri Dec 02 20:08:57 2022 X-Original-To: dev-commits-src-all@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 4NP3tK6HmRz4j9CB; Fri, 2 Dec 2022 20:08:57 +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 4NP3tK5nG5z4G5J; Fri, 2 Dec 2022 20:08:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670011737; 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=2NmIHTTzcDwYFSrqJv6w0xv17nIK+TgpHqssa4v/jXE=; b=xKaN9YPLEypVcPNzOIFGxtkemrzwCLAFF+jaWUB8KQ8QAsbivHh7pGUiLvSL4Edf9xBDha w7QFuSV0RWluCz/mUWqHmZwQgOTvRs9eyprHKHoTWA+bMNqWbnX2oEGEiEVIimkoFrKh7V L5ztBXZlD0o1p5Zip+mWAjGcSBBvE6COqCt2U50NC7id/0cIVFcqMDK1LccNdHKPqJ0QY5 01cTj//U6iDXuI/VSyt0/+uPuXXZmMUwcjdklV/ocDMTx1Yb0uKeloIuibsVlfP3vxztXS qxg7ReYGI6w0tdFfvNZ8Wpso/cnxCFLvIAZg2h3QmFHC0ScBx3+QmXWrJj4AMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670011737; 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=2NmIHTTzcDwYFSrqJv6w0xv17nIK+TgpHqssa4v/jXE=; b=n8lXKchCSFjI0LqcwlwmyaMrvgtOtXXUgEAAIaeSSru+G3mbcQkpYbH5DUZ9pXfK8WhUap TAOyTvQjZq5mE6GXbDOmMm6kf0iDOhAek3G8nLOD5Unk2v/1dlpDxgXWFnMaR5dRAKA3IA 1q64ATptvUM87JOYLp/p2xG6xBAuFcNZH+VQt+7yTLShSmaW9kx29UARlto6L6m+Cshy/b W1hbIEk3E7XD4cotyScwiK9CK0uAhQWnSVTiALZ70rz9vwcnMt2idC9mUpBox9iIX2JlSa eEKYPgIco3hU7fNpfLtGDW46GvnHSbpmyO/msqNDpD5jfgoltRDy5Bn6vw+ssw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1670011737; a=rsa-sha256; cv=none; b=dfG4Eq1LYlKnjYYIJiw47EjwzgVPOoBXLHUOjl3sXOPu0olx7A6Z60zOYbb3Qn16vJlwEz k7hFaHA0Hp4eCd+GbxFVz2ZrnFdiKIvqrYEDR75GtJEZ7dsmuhPoiYxcKPB9/+U1J3WLCe 2YfsZN5r7/Xbc9wxdcXec7NjVxMVrD4J2i1aE9I4mxafPkvZlsaWIWnzpnPULac1dAkNZ2 0+oY11vE+PqdKaWFz/F0/DRZuCgp+cywdGXHDjqe8KaD7YYp7CyewGuQ1azl/YYKyTvSb0 NJI3etsuF2pHe4j3w0RyhkeY1DnhX9ZdWqU0F+5cLZ7eI78jTQQg6ZfmI5eifg== 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 4NP3tK4c6ZzSZT; Fri, 2 Dec 2022 20:08:57 +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 2B2K8vME006239; Fri, 2 Dec 2022 20:08:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2B2K8vnQ006238; Fri, 2 Dec 2022 20:08:57 GMT (envelope-from git) Date: Fri, 2 Dec 2022 20:08:57 GMT Message-Id: <202212022008.2B2K8vnQ006238@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: 42f8123a4fa8 - main - routing: provide dedicated function for nhgrp creation and linking. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: 42f8123a4fa8354f07e3ebce1d3b6c2def7db5a3 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=42f8123a4fa8354f07e3ebce1d3b6c2def7db5a3 commit 42f8123a4fa8354f07e3ebce1d3b6c2def7db5a3 Author: Alexander V. Chernikov AuthorDate: 2022-12-02 17:58:03 +0000 Commit: Alexander V. Chernikov CommitDate: 2022-12-02 20:08:47 +0000 routing: provide dedicated function for nhgrp creation and linking. There is a need to store client metadata in nexthops and nexthop groups. This metadata is immutable and participate in nhop/nhg comparison. Nexthops KPI already supports its: nexthop creation pattern is ``` nhop_alloc() nhop_set_...() ... nhop_get_nhop() ``` This change provides a similar pattern for the nexthop groups. Specifically, it adds nhgrp_alloc(), nhgrp_get_nhgrp() and nhgrp_set_uidx(). MFC after: 2 weeks --- sys/net/route/nhgrp_ctl.c | 84 ++++++++++++++++++++++++++++++++++++++++------- sys/net/route/nhop.h | 4 +++ 2 files changed, 77 insertions(+), 11 deletions(-) diff --git a/sys/net/route/nhgrp_ctl.c b/sys/net/route/nhgrp_ctl.c index 842f9d5376bc..5d6fb219f877 100644 --- a/sys/net/route/nhgrp_ctl.c +++ b/sys/net/route/nhgrp_ctl.c @@ -459,15 +459,24 @@ free_nhgrp_nhops(struct nhgrp_priv *nhg_priv) } /* - * Creates or looks up an existing nexthop group based on @wn and @num_nhops. - * - * Returns referenced nhop group or NULL, passing error code in @perror. + * Allocate nexthop group of size @num_nhops with nexthops specified by + * @wn. Nexthops have to be unique and match the fibnum/family of the group. + * Returns unlinked nhgrp object on success or NULL and non-zero perror. */ -struct nhgrp_priv * -get_nhgrp(struct nh_control *ctl, struct weightened_nhop *wn, int num_nhops, - uint32_t uidx, int *perror) +struct nhgrp_object * +nhgrp_alloc(uint32_t fibnum, int family, struct weightened_nhop *wn, int num_nhops, + int *perror) { - struct nhgrp_priv *key, *nhg_priv; + struct rib_head *rh = rt_tables_get_rnh(fibnum, family); + struct nhgrp_priv *nhg_priv; + struct nh_control *ctl; + + if (rh == NULL) { + *perror = E2BIG; + return (NULL); + } + + ctl = rh->nh_control; if (num_nhops > RIB_MAX_MPATH_WIDTH) { *perror = E2BIG; @@ -486,6 +495,10 @@ get_nhgrp(struct nh_control *ctl, struct weightened_nhop *wn, int num_nhops, sort_weightened_nhops(wn, num_nhops); uint32_t last_id = 0; for (int i = 0; i < num_nhops; i++) { + if (wn[i].nh->nh_priv->nh_control != ctl) { + *perror = EINVAL; + return (NULL); + } if (wn[i].nh->nh_priv->nh_idx == last_id) { *perror = EEXIST; return (NULL); @@ -493,11 +506,25 @@ get_nhgrp(struct nh_control *ctl, struct weightened_nhop *wn, int num_nhops, last_id = wn[i].nh->nh_priv->nh_idx; } - if ((key = alloc_nhgrp(wn, num_nhops)) == NULL) { + if ((nhg_priv = alloc_nhgrp(wn, num_nhops)) == NULL) { *perror = ENOMEM; return (NULL); } - key->nhg_uidx = uidx; + nhg_priv->nh_control = ctl; + + *perror = 0; + return (nhg_priv->nhg); +} + +/* + * Finds an existing group matching @nhg or links @nhg to the tree. + * Returns the referenced group or NULL and non-zero @perror. + */ +struct nhgrp_object * +nhgrp_get_nhgrp(struct nhgrp_object *nhg, int *perror) +{ + struct nhgrp_priv *nhg_priv, *key = NHGRP_PRIV(nhg); + struct nh_control *ctl = key->nh_control; nhg_priv = find_nhgrp(ctl, key); if (nhg_priv != NULL) { @@ -508,7 +535,7 @@ get_nhgrp(struct nh_control *ctl, struct weightened_nhop *wn, int num_nhops, */ destroy_nhgrp_int(key); *perror = 0; - return (nhg_priv); + return (nhg_priv->nhg); } else { /* No existing group, try to link the new one */ if (!ref_nhgrp_nhops(key)) { @@ -529,12 +556,35 @@ get_nhgrp(struct nh_control *ctl, struct weightened_nhop *wn, int num_nhops, return (NULL); } *perror = 0; - return (key); + return (nhg); } /* NOTREACHED */ } +/* + * Creates or looks up an existing nexthop group based on @wn and @num_nhops. + * + * Returns referenced nhop group or NULL, passing error code in @perror. + */ +struct nhgrp_priv * +get_nhgrp(struct nh_control *ctl, struct weightened_nhop *wn, int num_nhops, + uint32_t uidx, int *perror) +{ + struct nhgrp_object *nhg; + + nhg = nhgrp_alloc(ctl->ctl_rh->rib_fibnum, ctl->ctl_rh->rib_family, + wn, num_nhops, perror); + if (nhg == NULL) + return (NULL); + nhgrp_set_uidx(nhg, uidx); + nhg = nhgrp_get_nhgrp(nhg, perror); + if (nhg != NULL) + return (NHGRP_PRIV(nhg)); + return (NULL); +} + + /* * Appends one or more nexthops denoted by @wm to the nexthop group @gr_orig. * @@ -732,6 +782,18 @@ nhgrp_get_nhops(const struct nhgrp_object *nhg, uint32_t *pnum_nhops) return (nhg_priv->nhg_nh_weights); } +void +nhgrp_set_uidx(struct nhgrp_object *nhg, uint32_t uidx) +{ + struct nhgrp_priv *nhg_priv; + + KASSERT(((nhg->nhg_flags & MPF_MULTIPATH) != 0), ("nhop is not mpath")); + + nhg_priv = NHGRP_PRIV(nhg); + + nhg_priv->nhg_uidx = uidx; +} + uint32_t nhgrp_get_uidx(const struct nhgrp_object *nhg) { diff --git a/sys/net/route/nhop.h b/sys/net/route/nhop.h index f0feccd6c0f2..f79cdb3459e9 100644 --- a/sys/net/route/nhop.h +++ b/sys/net/route/nhop.h @@ -224,6 +224,10 @@ void nhop_set_expire(struct nhop_object *nh, uint32_t expire); struct rib_head *nhop_get_rh(const struct nhop_object *nh); struct nhgrp_object; +struct nhgrp_object *nhgrp_alloc(uint32_t fibnum, int family, + struct weightened_nhop *wn, int num_nhops, int *perror); +struct nhgrp_object *nhgrp_get_nhgrp(struct nhgrp_object *nhg, int *perror); +void nhgrp_set_uidx(struct nhgrp_object *nhg, uint32_t uidx); uint32_t nhgrp_get_uidx(const struct nhgrp_object *nhg); uint8_t nhgrp_get_origin(const struct nhgrp_object *nhg); void nhgrp_set_origin(struct nhgrp_object *nhg, uint8_t origin);