From nobody Fri Jan 13 21:25:58 2023 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 4Ntvbp6nX1z2qlQh; Fri, 13 Jan 2023 21:25:58 +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 4Ntvbp6D7Wz44L0; Fri, 13 Jan 2023 21:25:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673645158; 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=g4IfQQ40g+yMSBVEP45GNX09G7RGIuOHORurMry2rvo=; b=PkzoE4gmR8kSoDOELHVLucMXWxFTnbBbZlT/q3VYfJ251urMyLeAhIGmyh9tz/D0Wfwwn1 BzFQVO8lWohHeimH5HXGz3i1b4IPrWSs0GAiQBNr6a7pMPtLekcQMwsvV+SqafaypdpA18 BXQTWlm29LShcSxzKQoCmZSA3l9lDzA3gOkfx51DnofAnCSZGGJToCgjwCU7hInwRX2MY+ jR/Ph7/HOTuAtf+e6FFquBsfHYes1ZPuAeN/9ceecpzHLUCCeNN/eRTQ4wt+I5AShMb3PB ihpxWtmelkpE53DR7kLltjjpjRhEG2wJEmGpd97wA7x3KQD0L9IoIXd3k4PKaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673645158; 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=g4IfQQ40g+yMSBVEP45GNX09G7RGIuOHORurMry2rvo=; b=DE/ALEtN9iqxnIXKE3IiAiasHa9cKma87oMCU8+YvZgEQqmqsiQhY1Vd6cvVJNRR33+0D6 79sEk02/wINV9ZCChZIgcrmquQOHYlR92R3MOOcmPKhR6PkcYI1UtHz6AInEGrCDI0LN+8 nQxLRPJVg3DiXdyrSPWKgSa+MxBCFCnfMw8DZvqzIf8mNW7JBuGLbwLwQP/wAL/2DVKxRi JMSP52kSdPC77x2JEGS9Y+LCl2uPxqiLHRk+ONRrPMXN+OiJ4CBZxELvoHhFLLNQqHuVwS khtcu0l9uitsVy+MfLXW39XDSr56/NfDOfNMVa5dF9jfgKaIMNfAnpIOJsBp4Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1673645158; a=rsa-sha256; cv=none; b=FMiKgaSNdYnJpaDvJe+3mXvmgW9b6p8mnfnalbVUdp5G8BoMEK46DBDNzQt3UvQeCBnPGy vuFeMhJp1aUyyxGGSUvXKdZl8YYKxIYJWSpC+ddOELmOyudL12MxUp403ew9xKquwbbviM MMH56C1umiWnsh1NnrOkaaA9HEdF4YQagxxjGnVBggmvTgQBZ+ktwMLUdgJIqeSaKnwVqQ erzD5imqXPFi2XrBRY3/c7ZUuPbiNiGx+iaXiVJFNPa+geUe344l87IwSlYF4Tv4ucEErb qx/Y9ec8b/fhiFIOzxBEAE+6jAK5ZMJMejbhWgCCsyb2ZYsc70RPXsDlFEiUoQ== 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 4Ntvbp5KyczNGg; Fri, 13 Jan 2023 21:25: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 30DLPwwZ042597; Fri, 13 Jan 2023 21:25:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30DLPwJh042596; Fri, 13 Jan 2023 21:25:58 GMT (envelope-from git) Date: Fri, 13 Jan 2023 21:25:58 GMT Message-Id: <202301132125.30DLPwJh042596@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: cf75fac619e5 - stable/13 - 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/stable/13 X-Git-Reftype: branch X-Git-Commit: cf75fac619e5c2945a0cf86b5a90c5e748ba7853 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=cf75fac619e5c2945a0cf86b5a90c5e748ba7853 commit cf75fac619e5c2945a0cf86b5a90c5e748ba7853 Author: Alexander V. Chernikov AuthorDate: 2022-12-02 17:58:03 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-01-13 21:24:12 +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 (cherry picked from commit 42f8123a4fa8354f07e3ebce1d3b6c2def7db5a3) --- 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);