From nobody Thu Feb 6 16:27:31 2025 X-Original-To: dev-commits-src-main@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 4YpjF15SCkz5mhQj; Thu, 06 Feb 2025 16:27:33 +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 4YpjF017Hfz4MvR; Thu, 06 Feb 2025 16:27:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1738859252; 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=3xOkZmz8+8N7PZioDxpphzE+M7dSsM0owUDhqEjDAAs=; b=NrY3mWzIo+Vm0XhWj5PfERKtw7NDW0+Dp7pBOiDWWnosV60T5qzXaJ+rAf68Pb8Fv4A+CM //P8ZmZJSMZIzGpXKMqZ/3JUO7k5TpRTdevdDSsFPHp2gkYjc2W+KY3ESkvZWJ8MJ/PU2y Xe1bKxBRC1Qyrm/ctaQRRE/75iWAAinPoQnuLqRXre1I+yjGTZt0afTluxVp92XCG3cF3T mWXww4Xre0jaPmyUX1LxL8S1bhiDZJvtOZGrgga7fWj/233gGAUPhpXlbYl5n71/hKobbp NMfR33fzHQgNi4wcGjmRXNgEt+NdoyJg7cplQnLMuWotpifZpI8jSfC1z3ys9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1738859252; 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=3xOkZmz8+8N7PZioDxpphzE+M7dSsM0owUDhqEjDAAs=; b=fby3j82IJ+Cp85Y26KBJO2475RS+ijG47xXQeXJKb1kVVcJxgqXIB3BvfhYgakdwFjoR/v z00pkw7S02vWdErkpCHY3F6SPRBVAt5aOQvJmDUsLlRTZdvt6NRY8sKB4RiJtNl+hq/fKB xVXAfgOusuUyONUDSN4asT32ogXVngyv5yWy+aI2oO6m9VVccyElK6BQ85cPGsQkIhszO6 YkOe0WNAAlpTIJcHqWU7+i8wgWnVIDbCDnzW0zSTnFbC/aNbyQ+HAYBe5fG8uv4vtZd6AE UJGI+StoacSDSpcLT0t3Qkstyr2TbYnOVVVBCxrU1zFSgT9ppMNsdufDA6PO5Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1738859252; a=rsa-sha256; cv=none; b=byyL/IcR2xTCse78roLhcLPw0PKOzHUeeILu5/88jrnc9hiW8tgrk54HNBpw3yN/zhXIQl DAPhDZz3BtJ8txYaudVbT6sQxcezNnVwGl2x1ainU+fqzbbF064pY1ir2C1gsNNCgMZ0Xc GzlrnJTRaQDKlnDYIiIqLSf7iUAhvGwlyFEINkbgMNhMN6D84WsiZJSx2phCRY4tgy7yUM +vusu78o7fcuvw8095ouo+Fu49Htel6aHLBfHAlAMIXDtBwUPYE8pfP5+NiKZKiUELfy5q ++q6EProj5XNvwXhiQBdEJtSeVjRanzM23Oauukz9n6P4CtLcJthARRy6X0Zqg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4YpjF00BHRzmX5; Thu, 06 Feb 2025 16:27:32 +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 516GRVUU095342; Thu, 6 Feb 2025 16:27:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 516GRVhs095339; Thu, 6 Feb 2025 16:27:31 GMT (envelope-from git) Date: Thu, 6 Feb 2025 16:27:31 GMT Message-Id: <202502061627.516GRVhs095339@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 4009a98fe80b - main - rawip: Add a bind_all_fibs sysctl List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 4009a98fe80b8a51837d471076152e6ff505b675 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=4009a98fe80b8a51837d471076152e6ff505b675 commit 4009a98fe80b8a51837d471076152e6ff505b675 Author: Mark Johnston AuthorDate: 2025-02-06 14:16:36 +0000 Commit: Mark Johnston CommitDate: 2025-02-06 14:16:36 +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 --- 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 5f6acbaa5e6f..0d677d954f11 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -30,7 +30,6 @@ * SUCH DAMAGE. */ -#include #include "opt_inet.h" #include "opt_inet6.h" #include "opt_ipsec.h" @@ -128,6 +127,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"); @@ -302,7 +307,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; @@ -312,6 +319,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, @@ -326,6 +334,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); } @@ -343,6 +357,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 d1c2f2c85142..b962d39151e9 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -143,6 +143,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); @@ -1934,7 +1937,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); @@ -1953,7 +1956,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 b761dc422feb..1bb0c0e835cf 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -59,7 +59,6 @@ * SUCH DAMAGE. */ -#include #include "opt_ipsec.h" #include "opt_inet6.h" #include "opt_route.h" @@ -118,6 +117,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; @@ -190,14 +192,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) { @@ -221,6 +225,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 ||