From nobody Fri Feb 21 01:57:22 2025 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 4YzYD26TBPz5nmN4; Fri, 21 Feb 2025 01:57:22 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YzYD23hgVz3nmY; Fri, 21 Feb 2025 01:57:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1740103042; 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=9UXkE+JX/OTy37BkhRdqODupG1rQKcxeeHVIfupBz4o=; b=BJCfAPlgI44wiWJCDg1T2J9XYiIj9V9UvIeJnKpGCTqhGPAUIkBZ4163ZpGmgg1d7AvcHO VQEuG6j5u/MfQkUy11FXzIAdo5AgMDsMiq4MCkP2QkLFZ8dVRotlXIphZ9xJqOMIsoY52J JC4dM28JidpPTjs0hf2YUzxMftjzsLL1Q4YH6f8c4+ilNL49ZYM82cxbamwpCrll+kpFJg KSqnJk3tqggL9kPw8Da7x54TW9OtMZ5ze7HJEk9h21yiBfRWZbTlzcRlJEEIyKdFN9w69H fTIOww1jfA9UXJmb6K95GXQJ8lEMNqWM7EzL8WYUCsHW4UjjbgPFt4LRe9uFyA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1740103042; a=rsa-sha256; cv=none; b=A/MFS3Y2xUGI61A2NKCx7yVaByRHfHEtgw8BqrSCu8fUluQ+Gq43gZxryFtOctiHrx8+gM yVj9NJ7WIwuZSCGKyDr4qY+vkkUjQNWOGTItMmvVAo2BryZvXg1t6BoVs+FSbk0QW0yNVk 2N4z5pc6MyeUUaC4rBHRdjBU/YYi9+nXXUxnq1dwbQc4a/OWpswZLxfaS4UVSnfaxVoPrz 2GLJlA6E9R26BCF6tad0b88Cd3Zay+g0dgjcSb6CsAfFXQlVyZ0EcwNYdcUtRkL2YAYUGU DhMZzchRKpmY2kGcx5qBoTF4n2H17tPM8ejWMNMzGCPc4C72Pek+ng31t72EXA== 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=1740103042; 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=9UXkE+JX/OTy37BkhRdqODupG1rQKcxeeHVIfupBz4o=; b=F/Epy+dSfecFwU2W5pT1CfuYUvi3AmBoEZc31U/kPqP+MmYI/3tfbwxlz/vE7rgH81zK2V g8YfMe7k+oLRY7ebQ2y5Am2/KF4xZ5sxY2jwENzPQ1YaSvHdaVekRHRu3cF7eaGYwiSgvs sbjy4byNrBt+RzMXXHkOeJn1oapSF46dFxnJ56HP8Wv8KGt3WdBiWcAvI2gxY84DIWBvHT hlXBUU5pVTrY2U4m/IWSfJtBUKoeUlRAMxuoevOqGRrgBRxCU8slFleRPrhEqCvz9ftFGD qdoS4F7Qi1mZLviIAoFuqZCxRy/TYZ/MovG1KkhwHpsBO/LR9YGlzwlupQK47Q== 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 4YzYD23GSYz1GXd; Fri, 21 Feb 2025 01:57:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 51L1vMJI067594; Fri, 21 Feb 2025 01:57:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 51L1vMmc067591; Fri, 21 Feb 2025 01:57:22 GMT (envelope-from git) Date: Fri, 21 Feb 2025 01:57:22 GMT Message-Id: <202502210157.51L1vMmc067591@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: ce80cdeb1370 - stable/14 - rawip: Add a bind_all_fibs sysctl 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 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/14 X-Git-Reftype: branch X-Git-Commit: ce80cdeb1370705d72a7aa6c5784581592c89a61 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=ce80cdeb1370705d72a7aa6c5784581592c89a61 commit ce80cdeb1370705d72a7aa6c5784581592c89a61 Author: Mark Johnston AuthorDate: 2025-02-06 14:16:36 +0000 Commit: Mark Johnston CommitDate: 2025-02-21 01:04:50 +0000 rawip: Add a bind_all_fibs sysctl As with net.inet.{tcp,udp}.bind_all_fibs, this causes raw sockets to accept only packets from the same FIB. Reviewed by: glebius Sponsored by: Klara, Inc. Sponsored by: Stormshield Differential Revision: https://reviews.freebsd.org/D48707 (cherry picked from commit 4009a98fe80b8a51837d471076152e6ff505b675) --- sys/netinet/raw_ip.c | 21 +++++++++++++++++++-- sys/netinet6/icmp6.c | 13 ++++++++++++- sys/netinet6/raw_ip6.c | 14 ++++++++++++-- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index 287a806845c4..36258b3283d6 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -32,7 +32,6 @@ * @(#)raw_ip.c 8.7 (Berkeley) 5/15/95 */ -#include #include "opt_inet.h" #include "opt_inet6.h" #include "opt_ipsec.h" @@ -130,6 +129,12 @@ int (*ip_rsvp_vif)(struct socket *, struct sockopt *); void (*ip_rsvp_force_done)(struct socket *); #endif /* INET */ +#define V_rip_bind_all_fibs VNET(rip_bind_all_fibs) +VNET_DEFINE(int, rip_bind_all_fibs) = 1; +SYSCTL_INT(_net_inet_raw, OID_AUTO, bind_all_fibs, CTLFLAG_VNET | CTLFLAG_RDTUN, + &VNET_NAME(rip_bind_all_fibs), 0, + "Bound sockets receive traffic from all FIBs"); + u_long rip_sendspace = 9216; SYSCTL_ULONG(_net_inet_raw, OID_AUTO, maxdgram, CTLFLAG_RW, &rip_sendspace, 0, "Maximum outgoing raw IP datagram size"); @@ -304,7 +309,9 @@ rip_input(struct mbuf **mp, int *offp, int proto) struct mbuf *m = *mp; struct inpcb *inp; struct sockaddr_in ripsrc; - int appended; + int appended, fib; + + M_ASSERTPKTHDR(m); *mp = NULL; appended = 0; @@ -314,6 +321,7 @@ rip_input(struct mbuf **mp, int *offp, int proto) ripsrc.sin_family = AF_INET; ripsrc.sin_addr = ctx.ip->ip_src; + fib = M_GETFIB(m); ifp = m->m_pkthdr.rcvif; inpi.hash = INP_PCBHASH_RAW(proto, ctx.ip->ip_src.s_addr, @@ -328,6 +336,12 @@ rip_input(struct mbuf **mp, int *offp, int proto) */ continue; } + if (V_rip_bind_all_fibs == 0 && fib != inp->inp_inc.inc_fibnum) + /* + * Sockets bound to a specific FIB can only receive + * packets from that FIB. + */ + continue; appended += rip_append(inp, ctx.ip, m, &ripsrc); } @@ -345,6 +359,9 @@ rip_input(struct mbuf **mp, int *offp, int proto) * and fall through into normal filter path if so. */ continue; + if (V_rip_bind_all_fibs == 0 && fib != inp->inp_inc.inc_fibnum) + continue; + /* * If this raw socket has multicast state, and we * have received a multicast, check if this socket diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index 39c252e16b75..0a0ca80de721 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -145,6 +145,9 @@ SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_NODEINFO, nodeinfo, VNET_DECLARE(struct inpcbinfo, ripcbinfo); #define V_ripcbinfo VNET(ripcbinfo) +VNET_DECLARE(int, rip_bind_all_fibs); +#define V_rip_bind_all_fibs VNET(rip_bind_all_fibs) + static void icmp6_errcount(int, int); static int icmp6_rip6_input(struct mbuf **, int); static void icmp6_reflect(struct mbuf *, size_t); @@ -1936,7 +1939,7 @@ icmp6_rip6_input(struct mbuf **mp, int off) struct sockaddr_in6 fromsa; struct icmp6_hdr *icmp6; struct mbuf *opts = NULL; - int delivered = 0; + int delivered = 0, fib; /* This is assumed to be safe; icmp6_input() does a pullup. */ icmp6 = (struct icmp6_hdr *)((caddr_t)ip6 + off); @@ -1955,7 +1958,15 @@ icmp6_rip6_input(struct mbuf **mp, int off) return (IPPROTO_DONE); } + fib = M_GETFIB(m); + while ((inp = inp_next(&inpi)) != NULL) { + if (V_rip_bind_all_fibs == 0 && fib != inp->inp_inc.inc_fibnum) + /* + * Sockets bound to a specific FIB can only receive + * packets from that FIB. + */ + continue; if (ICMP6_FILTER_WILLBLOCK(icmp6->icmp6_type, inp->in6p_icmp6filt)) continue; diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index 803dc3c1804e..caee18cab071 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -61,7 +61,6 @@ * @(#)raw_ip.c 8.2 (Berkeley) 1/4/94 */ -#include #include "opt_ipsec.h" #include "opt_inet6.h" #include "opt_route.h" @@ -120,6 +119,9 @@ VNET_DECLARE(struct inpcbinfo, ripcbinfo); #define V_ripcbinfo VNET(ripcbinfo) +VNET_DECLARE(int, rip_bind_all_fibs); +#define V_rip_bind_all_fibs VNET(rip_bind_all_fibs) + extern u_long rip_sendspace; extern u_long rip_recvspace; @@ -192,14 +194,16 @@ rip6_input(struct mbuf **mp, int *offp, int proto) struct rip6_inp_match_ctx ctx = { .ip6 = ip6, .proto = proto }; struct inpcb_iterator inpi = INP_ITERATOR(&V_ripcbinfo, INPLOOKUP_RLOCKPCB, rip6_inp_match, &ctx); - int delivered = 0; + int delivered = 0, fib; + M_ASSERTPKTHDR(m); NET_EPOCH_ASSERT(); RIP6STAT_INC(rip6s_ipackets); init_sin6(&fromsa, m, 0); /* general init */ + fib = M_GETFIB(m); ifp = m->m_pkthdr.rcvif; while ((inp = inp_next(&inpi)) != NULL) { @@ -223,6 +227,12 @@ rip6_input(struct mbuf **mp, int *offp, int proto) * and fall through into normal filter path if so. */ continue; + if (V_rip_bind_all_fibs == 0 && fib != inp->inp_inc.inc_fibnum) + /* + * Sockets bound to a specific FIB can only receive + * packets from that FIB. + */ + continue; if (inp->in6p_cksum != -1) { RIP6STAT_INC(rip6s_isum); if (m->m_pkthdr.len - (*offp + inp->in6p_cksum) < 2 ||