From nobody Tue Apr 25 11:15:29 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 4Q5KDK3TWkz473gl; Tue, 25 Apr 2023 11:15:29 +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 4Q5KDK1TgZz45Gs; Tue, 25 Apr 2023 11:15:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682421329; 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=1K3rbTyK3/oBQYGOKEVvlrZqjzPjtaiDEajhD0jRrQk=; b=S0XZoT/z/1t3fgjTWxtcSF4c0wvHqBDoqgU03vYiVFYwJUygYH04BriR4RjFN/UQwV9Lgi jkvQKPczT7SFY1j3ZEYtxP049TzW3rGma1iNF58WrDL8IWLnp4RJ6q33W0TOSsFSoZ0aGv v0FIWYuoFJneR2fSxqJe9EGoMKXbrAYUNzawCpmBDme5vSy586hslE4/hWDO3Sj9u/c+CT UeZcSWj0JCJyAgAwlrmDjJAnkulcpgGSKEH7zPl0d1T7eBO8sf4GkcmyyglI6xNWIb7k3o PO+G3C6lSA6D7TVmTgoq/0WEMs7bC1NzEwFGvG/y8/X65+J73lIcLkjJ3FNdmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682421329; 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=1K3rbTyK3/oBQYGOKEVvlrZqjzPjtaiDEajhD0jRrQk=; b=IjXYZE1UcqFYzMbhxBl0ssXCA4cMIFjJe5LhsFpRktDKd0hVXRmH7FRFOfHu5v4DKfg+XV AzqoSLTsDMbEOrMpKYhbkeutMWI65qznyZGFiMqHHtAEAXdufsGFsPssWzEZQo1NlVMbmk v4ie6kSA1VodnRpcQSDvpqYpkrySlKPyahDDLPxd2rQMFUTmIiDiedKT9bTgKcNi/RBrVb tUs8/3EEU8ZWRAMoie1xCcD7hlZ00PMiyF4SKAn6+LLaMfkua3jIiODC/pg0Kdbb9fO1Rk KJWdnjtZtQss4LeqYUs9u+3JOlFwsrfOGRg1PZFOm/y11+slsNzuBINY3NQ4sA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1682421329; a=rsa-sha256; cv=none; b=t6QzxZBslvm7BCliDM0sCcoPrF65YRsLEzdrTxaMaPT7EL7D9mS7iJ9+kAYTkSQDRA5T+g lbBb7ZlpvfzdnMB5UTL5w3hXebTivKQRf3OkX7c4CGmz7LPkjmJLoGAnleDJ0VKbhTALfc 8SfWu9N31qPQNiwELBHWtf6sxriRZHDlTDxeNkPo9HPdHkiDXzj07aLple0XabcL5QYSW9 UyESAoDG1m3c4PqQx694CDa0Uu7q9yQHWGkKZu0QAndlvGa9OXSszMDAoyLvCviqOr6DmT iGpJXN5jtFaS6vzMrIZutaQLIW5pvOgCxxxJME7ecODLObcO5Wpf0jv8pBRZ8g== 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 4Q5KDK0bJHz14TM; Tue, 25 Apr 2023 11:15:29 +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 33PBFTqg012702; Tue, 25 Apr 2023 11:15:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 33PBFTfN012701; Tue, 25 Apr 2023 11:15:29 GMT (envelope-from git) Date: Tue, 25 Apr 2023 11:15:29 GMT Message-Id: <202304251115.33PBFTfN012701@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: 34066d0008b6 - main - routing: add iterator-based nhop traversal KPI. 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: 34066d0008b6b5f0c7f9fbef8d82e468aaf3f7cf Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=34066d0008b6b5f0c7f9fbef8d82e468aaf3f7cf commit 34066d0008b6b5f0c7f9fbef8d82e468aaf3f7cf Author: Alexander V. Chernikov AuthorDate: 2023-04-25 10:55:16 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-04-25 10:55:16 +0000 routing: add iterator-based nhop traversal KPI. MFC after: 2 weeks --- sys/net/route/nhop_ctl.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++ sys/net/route/route_ctl.h | 13 ++++++++++++ 2 files changed, 63 insertions(+) diff --git a/sys/net/route/nhop_ctl.c b/sys/net/route/nhop_ctl.c index d99b78351952..3b7cab0cdd35 100644 --- a/sys/net/route/nhop_ctl.c +++ b/sys/net/route/nhop_ctl.c @@ -1076,6 +1076,56 @@ nhops_update_ifmtu(struct rib_head *rh, struct ifnet *ifp, uint32_t mtu) } +struct nhop_object * +nhops_iter_start(struct nhop_iter *iter) +{ + if (iter->rh == NULL) + iter->rh = rt_tables_get_rnh_safe(iter->fibnum, iter->family); + if (iter->rh != NULL) { + struct nh_control *ctl = iter->rh->nh_control; + + NHOPS_RLOCK(ctl); + + iter->_i = 0; + iter->_next = CHT_FIRST(&ctl->nh_head, iter->_i); + + return (nhops_iter_next(iter)); + } else + return (NULL); +} + +struct nhop_object * +nhops_iter_next(struct nhop_iter *iter) +{ + struct nhop_priv *nh_priv = iter->_next; + + if (nh_priv != NULL) { + iter->_next = nh_priv->nh_next; + return (nh_priv->nh); + } + + struct nh_control *ctl = iter->rh->nh_control; + while (++iter->_i < ctl->nh_head.hash_size) { + nh_priv = CHT_FIRST(&ctl->nh_head, iter->_i); + if (nh_priv != NULL) { + iter->_next = nh_priv->nh_next; + return (nh_priv->nh); + } + } + + return (NULL); +} + +void +nhops_iter_stop(struct nhop_iter *iter) +{ + if (iter->rh != NULL) { + struct nh_control *ctl = iter->rh->nh_control; + + NHOPS_RUNLOCK(ctl); + } +} + /* * Prints nexthop @nh data in the provided @buf. * Example: nh#33/inet/em0/192.168.0.1 diff --git a/sys/net/route/route_ctl.h b/sys/net/route/route_ctl.h index d3c457cdeaae..4e4444296a9c 100644 --- a/sys/net/route/route_ctl.h +++ b/sys/net/route/route_ctl.h @@ -159,6 +159,19 @@ void ip6_writemask(struct in6_addr *addr6, uint8_t mask); /* Nexthops */ uint32_t nhops_get_count(struct rib_head *rh); +struct nhop_priv; +struct nhop_iter { + uint32_t fibnum; + uint8_t family; + struct rib_head *rh; + int _i; + struct nhop_priv *_next; +}; + +struct nhop_object *nhops_iter_start(struct nhop_iter *iter); +struct nhop_object *nhops_iter_next(struct nhop_iter *iter); +void nhops_iter_stop(struct nhop_iter *iter); + /* Multipath */ struct weightened_nhop;