From nobody Sun May 3 23:51:54 2026 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 4g81lb0pqyz6bvvn for ; Sun, 03 May 2026 23:51:55 +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 "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4g81lZ4Cg9z3gpH for ; Sun, 03 May 2026 23:51:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1777852314; 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=DGJFk+CB0JIdWvRAY29XODerEW+ou35vLnQ3AiQA7lw=; b=Lh1/IVTo/OrevdnZ9Sg2jd+o/j+3JRm+CzYt2FlWkbtPWC24vwBtdGcEgRPo8G4SRzwDKu km1HEcof2PnlfnqKev7o1SycFNtOwJShaEF4P2vWSN0xMhDigbt5SfsvROSggNSwmN5TVf dNOI1KvRjrstJKHnUxHKoBddXSssgmXjpjoCCXHwXiZMpy6JJ7kmV512x0DoOPZhaxRyGe 2kBvGpIPnylAuRn92yERSoeMYqRy70d4qksiDJt2HZHW8NyIYqYmLfqUFnEljWSEjIUk3S WNCADpMFiNWimJp0tc80BMwNWd/c/bBM3UqVubjncSzmSvd61lfbRAwXv3b2dA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1777852314; a=rsa-sha256; cv=none; b=Vcgd0P+aZazBBTxxhr39Ga0u6MBSQBfCoQayG/6fftvFXHgQbjUYNA+Ip2IJIyMBnae0+c QW3BJc0BqF0xVekU+7e5I2re0vn5gxGRdbQ3WzrjqAWslJgO9o8IqgfOrI4KUgHsxy4RJf yr3TRlfEFnOrtT8aQRfkEd3zEPZ8KBiIwXq8NlhfZUY7FsCCnk9E7gJpI4mL4E4f40Y27o TNRkIP4B3voY5KEg5i/SXCfw4VNZbz/XwdcWaMr+ISq3xXyCetxzvVWu6p1X5/+mru7djr 5ZkNuvm9wOc0VVAWpd3aN17n6rSjxaSrXyMhLmNW0LR0WAmsGnhWMfDDpjB9bA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1777852314; 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=DGJFk+CB0JIdWvRAY29XODerEW+ou35vLnQ3AiQA7lw=; b=l3kAS81A7+fa6AGyVBlKkSM9Vrfsl/o5kS+jhMlzrV9dVpZxYeYoLYbpGUbuvTjSZ36iu2 a/tb8BWMq9YoLU7k8qjeWk2ZauSCo4Cf4rwONu8lDTRWNhELK83a8REnp3a8o76wR7Jj0D sKI7uz++9nqOoENStzRiLAXhrXzPafM+Ukp7XmnKcjVUrY6FMNFObJqohZl+xpDW0dbqrX a4gDbDZLUxOOv0B1zgjzrxbUoehtnoI7p4kyX3TR7zUG1o3lTmnk/SyMyLEvx24LTak+PL OV9biSW+oQOl24KSGhuotfKG12TugaeO9P3j9ZRowsZLfuKGmZULkDBxYRRkXQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g81lZ3cX6zvbC for ; Sun, 03 May 2026 23:51:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 31f84 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 03 May 2026 23:51:54 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: f6a4a0c33c7b - stable/15 - ip(6)_mroute: Grow the routing tables when the number of FIBs changes 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: f6a4a0c33c7b5d609fd6c97abfb2a3efeea7e655 Auto-Submitted: auto-generated Date: Sun, 03 May 2026 23:51:54 +0000 Message-Id: <69f7df9a.31f84.1a667bfb@gitrepo.freebsd.org> The branch stable/15 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=f6a4a0c33c7b5d609fd6c97abfb2a3efeea7e655 commit f6a4a0c33c7b5d609fd6c97abfb2a3efeea7e655 Author: Mark Johnston AuthorDate: 2026-03-30 13:30:38 +0000 Commit: Mark Johnston CommitDate: 2026-05-03 23:10:42 +0000 ip(6)_mroute: Grow the routing tables when the number of FIBs changes Use the new rtnumfibs_change event to expand the mfctable array when the number of FIBs increases. MFC after: 2 weeks Sponsored by: Stormshield Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D55240 (cherry picked from commit 97a4bc9a0da7cd63c660ce59a9dd7c87efe1f218) --- sys/netinet/ip_mroute.c | 54 ++++++++++++++++++++++++++++++++++++++--------- sys/netinet6/ip6_mroute.c | 43 ++++++++++++++++++++++++++++++++++--- 2 files changed, 84 insertions(+), 13 deletions(-) diff --git a/sys/netinet/ip_mroute.c b/sys/netinet/ip_mroute.c index a4d09aa55098..45b42aefbc11 100644 --- a/sys/netinet/ip_mroute.c +++ b/sys/netinet/ip_mroute.c @@ -190,6 +190,8 @@ struct mfctable { VNET_DEFINE_STATIC(struct mfctable *, mfctables); #define V_mfctables VNET(mfctables) +VNET_DEFINE_STATIC(uint32_t, nmfctables); +#define V_nmfctables VNET(nmfctables) VNET_DEFINE_STATIC(u_long, mfchash); #define V_mfchash VNET(mfchash) @@ -207,7 +209,8 @@ VNET_DEFINE_STATIC(struct taskqueue *, task_queue); VNET_DEFINE_STATIC(struct task, task); #define V_task VNET(task) -static eventhandler_tag if_detach_event_tag = NULL; +static eventhandler_tag if_detach_event_tag; +static eventhandler_tag rtnumfibs_change_tag; VNET_DEFINE_STATIC(struct callout, expire_upcalls_ch); #define V_expire_upcalls_ch VNET(expire_upcalls_ch) @@ -2809,7 +2812,6 @@ out_locked: MRW_RUNLOCK(); return (error); } - static SYSCTL_NODE(_net_inet_ip, OID_AUTO, mfctable, CTLFLAG_RD | CTLFLAG_MPSAFE, sysctl_mfctable, "IPv4 Multicast Forwarding Table " @@ -2839,26 +2841,51 @@ sysctl_viflist(SYSCTL_HANDLER_ARGS) MRW_RUNLOCK(); return (error); } - SYSCTL_PROC(_net_inet_ip, OID_AUTO, viftable, CTLTYPE_OPAQUE | CTLFLAG_VNET | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0, sysctl_viflist, "S,vif[MAXVIFS]", "IPv4 Multicast Interfaces (struct vif[MAXVIFS], netinet/ip_mroute.h)"); static void -vnet_mroute_init(const void *unused __unused) +ip_mroute_rtnumfibs_change(void *arg __unused, uint32_t ntables) { - V_mfctables = mallocarray(V_rt_numfibs, sizeof(*V_mfctables), M_MRTABLE, + struct mfctable *mfctables, *omfctables; + + KASSERT(ntables >= V_nmfctables, + ("%s: ntables %u nmfctables %u", __func__, ntables, V_nmfctables)); + + mfctables = mallocarray(ntables, sizeof(*mfctables), M_MRTABLE, M_WAITOK | M_ZERO); - for (int i = 0; i < V_rt_numfibs; i++) { + omfctables = V_mfctables; + + for (int i = V_nmfctables; i < ntables; i++) { struct mfctable *mfct; - mfct = &V_mfctables[i]; + mfct = &mfctables[i]; mfct->nexpire = malloc(mfchashsize, M_MRTABLE, M_WAITOK | M_ZERO); mfct->register_vif = VIFI_INVALID; } + MRW_TEARDOWN_WLOCK(); + MRW_WLOCK(); + for (int i = 0; i < V_nmfctables; i++) + memcpy(&mfctables[i], &omfctables[i], sizeof(*mfctables)); + atomic_store_rel_ptr((uintptr_t *)&V_mfctables, (uintptr_t)mfctables); + MRW_WUNLOCK(); + MRW_TEARDOWN_WUNLOCK(); + + NET_EPOCH_WAIT(); + + V_nmfctables = ntables; + free(omfctables, M_MRTABLE); +} + +static void +vnet_mroute_init(const void *unused __unused) +{ + ip_mroute_rtnumfibs_change(NULL, V_rt_numfibs); + callout_init_rw(&V_expire_upcalls_ch, &mrouter_lock, 0); callout_init_rw(&V_bw_upcalls_ch, &mrouter_lock, 0); @@ -2896,8 +2923,12 @@ ip_mroute_modevent(module_t mod, int type, void *unused) MRW_TEARDOWN_LOCK_INIT(); MRW_LOCK_INIT(); - if_detach_event_tag = EVENTHANDLER_REGISTER(ifnet_departure_event, - if_detached_event, NULL, EVENTHANDLER_PRI_ANY); + if_detach_event_tag = EVENTHANDLER_REGISTER( + ifnet_departure_event, if_detached_event, NULL, + EVENTHANDLER_PRI_ANY); + rtnumfibs_change_tag = EVENTHANDLER_REGISTER( + rtnumfibs_change, ip_mroute_rtnumfibs_change, + NULL, EVENTHANDLER_PRI_ANY); if (!powerof2(mfchashsize)) { printf("WARNING: %s not a power of 2; using default\n", @@ -2938,7 +2969,10 @@ ip_mroute_modevent(module_t mod, int type, void *unused) ip_mrouter_unloading = 1; MRW_WUNLOCK(); - EVENTHANDLER_DEREGISTER(ifnet_departure_event, if_detach_event_tag); + EVENTHANDLER_DEREGISTER(rtnumfibs_change, + rtnumfibs_change_tag); + EVENTHANDLER_DEREGISTER(ifnet_departure_event, + if_detach_event_tag); if (pim_encap_cookie) { ip_encap_detach(pim_encap_cookie); diff --git a/sys/netinet6/ip6_mroute.c b/sys/netinet6/ip6_mroute.c index 91e5e53fe273..b3b1bfc45bd8 100644 --- a/sys/netinet6/ip6_mroute.c +++ b/sys/netinet6/ip6_mroute.c @@ -84,6 +84,7 @@ #include #include #include +#include #include #include #include @@ -208,6 +209,10 @@ struct mf6ctable { VNET_DEFINE_STATIC(struct mf6ctable *, mfctables); #define V_mfctables VNET(mfctables) +VNET_DEFINE_STATIC(uint32_t, nmfctables); +#define V_nmfctables VNET(nmfctables) + +static eventhandler_tag rtnumfibs_change_tag; static int sysctl_mfctable(SYSCTL_HANDLER_ARGS) @@ -1927,11 +1932,36 @@ pim6_input(struct mbuf *m, int off, int proto, void *arg __unused) return (rip6_input(&m, &off, proto)); } +static void +ip6_mroute_rtnumfibs_change(void *arg __unused, uint32_t ntables) +{ + struct mf6ctable *mfctables, *omfctables; + + KASSERT(ntables >= V_nmfctables, + ("%s: ntables %u nmfctables %u", __func__, ntables, V_nmfctables)); + + mfctables = mallocarray(ntables, sizeof(*mfctables), M_MRTABLE6, + M_WAITOK | M_ZERO); + omfctables = V_mfctables; + + MROUTER6_LOCK(); + MFC6_LOCK(); + for (int i = 0; i < V_nmfctables; i++) + memcpy(&mfctables[i], &omfctables[i], sizeof(*mfctables)); + atomic_store_rel_ptr((uintptr_t *)&V_mfctables, (uintptr_t)mfctables); + MFC6_UNLOCK(); + MROUTER6_UNLOCK(); + + NET_EPOCH_WAIT(); + + V_nmfctables = ntables; + free(omfctables, M_MRTABLE6); +} + static void vnet_mroute_init(const void *unused __unused) { - V_mfctables = mallocarray(V_rt_numfibs, sizeof(*V_mfctables), - M_MRTABLE6, M_WAITOK | M_ZERO); + ip6_mroute_rtnumfibs_change(NULL, V_rt_numfibs); callout_init_mtx(&V_expire_upcalls_ch, MFC6_LOCKPTR(), 0); } @@ -1958,6 +1988,10 @@ ip6_mroute_modevent(module_t mod, int type, void *unused) MFC6_LOCK_INIT(); MIF6_LOCK_INIT(); + rtnumfibs_change_tag = EVENTHANDLER_REGISTER( + rtnumfibs_change, ip6_mroute_rtnumfibs_change, + NULL, EVENTHANDLER_PRI_ANY); + pim6_encap_cookie = ip6_encap_attach(&ipv6_encap_cfg, NULL, M_WAITOK); if (pim6_encap_cookie == NULL) { @@ -1979,6 +2013,9 @@ ip6_mroute_modevent(module_t mod, int type, void *unused) if (V_ip6_mrouting_enabled) return (EBUSY); + EVENTHANDLER_DEREGISTER(rtnumfibs_change, + rtnumfibs_change_tag); + if (pim6_encap_cookie) { ip6_encap_detach(pim6_encap_cookie); pim6_encap_cookie = NULL; @@ -2008,4 +2045,4 @@ static moduledata_t ip6_mroutemod = { 0 }; -DECLARE_MODULE(ip6_mroute, ip6_mroutemod, SI_SUB_PROTO_MC, SI_ORDER_ANY); +DECLARE_MODULE(ip6_mroute, ip6_mroutemod, SI_SUB_PROTO_MC, SI_ORDER_MIDDLE);