From nobody Tue Sep 03 14:55:00 2024 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 4WypZF2Nncz5TN8t; Tue, 03 Sep 2024 14:55:01 +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 4WypZD5wkJz4xBF; Tue, 3 Sep 2024 14:55:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725375300; 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=kk/xarI3yKww3lRQM/QewRgNAu7V9aEU3WRjGeFjLWg=; b=xj/JcbhWnApovRlKzxb5THUVV9qdBTtUSCkddlcvM9+kX6GehLfrDLTva+sP13vgxKIwRa xPJmsKCvb2LA2ljbKSXVDlNKEL2RnlVBelWUNXipg7TyKtRav4fwXkm0zglUDrtO/haMD3 bHE06EjlF/2Ak4cJG7TZvUtRno7/wP+qdnOEW0G9W70exq/1mb8N30qiTJTzwVwZubnLlC TI/pd3rRtRFYQu+AKENT4T/ToQWKeKOFTuPksAZw0HFYpg0+wRC7A0vwed/rl8SUej/FqR lA+R8OSAlZc/2udO4PViGUcaUvBYuTnJJ5SGhb/bgByl/W55L/4lv1UyWDb/Kg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1725375300; a=rsa-sha256; cv=none; b=Y7kjS7BUj56Jr7tpRfgE88+sp7kiiNHDu18jLmUb+THXwxBvaJPfXY955En2Q2oINkPvHe Wz0/USaWY4ZC1P2aPpvTx+afv+YgYsMmsfvlWLZC1chJzxx5wOAmMRpSw2VYwEXzPupnM6 7j8alqfscesGAGWnZasjM5Ay4Ion2j8wyHi0moFdc4jOsPR8v71x3zns04927xlz5aMQfj D5VIxcotCdJv88PXk9NtjGYHKey0zTDNHyDwejCb4/iVaPZQaVYKu2xWI74Uv8Oirbqoch LbXHcHUEPt7MhguUr3slTBgtVMcDW57Mbhvy5rpJPfURoFJ+7m/Q/hVKLeiDOw== 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=1725375300; 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=kk/xarI3yKww3lRQM/QewRgNAu7V9aEU3WRjGeFjLWg=; b=ww+niR2XkTedh3hEKGnTK24f6wzpKzwm5ZIMF+KjTpl1N7CGW4a75soV4wxTe5X/0zWrRp o+1QtERS2wN3Aagtyp6qDO5VeiEjhFzC3Tj89peBFuB7iLSdWACYk8mKqsLEhS77rYkEiH q576PZzfWbAYzU9F8ukNcx6YX3WPCl/9ydXUC0fGaYxGjeZa11cmYBS8sdQtHyjRPl9bMj CVsF2Htg+W+YGcR48g+52S3mxYfP2od/wODToJysteVJXUTCnZtYmBOp+X0Hif3d8t9FL4 CaQiO4RVqdYdFX9jLFpIl5fAobgzjA5ITWNvFeQqQTU4UO4WtGjLu15v87LApg== 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 4WypZD5XVbzlld; Tue, 3 Sep 2024 14:55:00 +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 483Et0Bj070580; Tue, 3 Sep 2024 14:55:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 483Et0Dn070577; Tue, 3 Sep 2024 14:55:00 GMT (envelope-from git) Date: Tue, 3 Sep 2024 14:55:00 GMT Message-Id: <202409031455.483Et0Dn070577@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: 8ae58e0edbfb - stable/14 - netinet: Add a sysctl to allow disabling connections to INADDR_ANY 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: 8ae58e0edbfb4c56125fb6d7468ebfea638847b9 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=8ae58e0edbfb4c56125fb6d7468ebfea638847b9 commit 8ae58e0edbfb4c56125fb6d7468ebfea638847b9 Author: Mark Johnston AuthorDate: 2024-08-20 21:31:57 +0000 Commit: Mark Johnston CommitDate: 2024-09-03 14:54:42 +0000 netinet: Add a sysctl to allow disabling connections to INADDR_ANY See the discussion in Bugzilla PR 280705 for context. PR: 280705 MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D46259 (cherry picked from commit 417b35a97b7669eb0bf417b43e97cccbedbce6f9) --- sys/netinet/in_pcb.c | 8 +++++++- sys/netinet6/in6_pcb.c | 12 +++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 0fffd285fb17..897a3ef991d5 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -236,6 +236,12 @@ in_pcbhashseed_init(void) VNET_SYSINIT(in_pcbhashseed_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_FIRST, in_pcbhashseed_init, 0); +VNET_DEFINE_STATIC(int, connect_inaddr_wild) = 1; +#define V_connect_inaddr_wild VNET(connect_inaddr_wild) +SYSCTL_INT(_net_inet_ip, OID_AUTO, connect_inaddr_wild, + CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(connect_inaddr_wild), 0, + "Allow connecting to INADDR_ANY or INADDR_BROADCAST for connect(2)"); + static void in_pcbremhash(struct inpcb *); /* @@ -1311,7 +1317,7 @@ in_pcbconnect_setup(struct inpcb *inp, struct sockaddr_in *sin, inp->inp_flowtype = hash_type; } #endif - if (!CK_STAILQ_EMPTY(&V_in_ifaddrhead)) { + if (V_connect_inaddr_wild && !CK_STAILQ_EMPTY(&V_in_ifaddrhead)) { /* * If the destination address is INADDR_ANY, * use the primary local address. diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c index 90f91eef1daa..8046e0fa530d 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -85,6 +85,7 @@ #include #include #include +#include #include #include #include @@ -99,6 +100,7 @@ #include #include #include +#include #include #include @@ -114,6 +116,14 @@ #include #include +SYSCTL_DECL(_net_inet6); +SYSCTL_DECL(_net_inet6_ip6); +VNET_DEFINE_STATIC(int, connect_in6addr_wild) = 1; +#define V_connect_in6addr_wild VNET(connect_in6addr_wild) +SYSCTL_INT(_net_inet6_ip6, OID_AUTO, connect_in6addr_wild, + CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(connect_in6addr_wild), 0, + "Allow connecting to the unspecified address for connect(2)"); + int in6_pcbsetport(struct in6_addr *laddr, struct inpcb *inp, struct ucred *cred) { @@ -353,7 +363,7 @@ in6_pcbladdr(struct inpcb *inp, struct sockaddr_in6 *sin6, if ((error = sa6_embedscope(sin6, V_ip6_use_defzone)) != 0) return(error); - if (!CK_STAILQ_EMPTY(&V_in6_ifaddrhead)) { + if (V_connect_in6addr_wild && !CK_STAILQ_EMPTY(&V_in6_ifaddrhead)) { /* * If the destination address is UNSPECIFIED addr, * use the loopback addr, e.g ::1.