From nobody Tue Aug 20 21:34:39 2024 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 4WpN5r0bHsz5SgMP; Tue, 20 Aug 2024 21:34:40 +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 4WpN5q70LNz4nNG; Tue, 20 Aug 2024 21:34:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724189680; 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=2Shwap851Tk00JyIXYY8Y2nA7OW03XuiNKCT/BNivho=; b=cVx6+JgrB86viq3LkQWXYKoyqlgt+f38Rs9BSjElOQz2FMtWZJeUhua64I68XBtrjdZSQY x1WizVFuX3eZqaAhdDVeQWEd95t2cSIiDq2hbMSnhcwZ+Uw4oBk8jhKICObT4vA+Geil+0 bu4VbmZMQqkJ2QDfJp3kgGQzpEBfT3LAeK3d6m//ohoci0IzLFFroSFaz6Tul8li00kFby uMq/dl+b92/GL+iERl1VOg35d2sZtdHijpGhADFgvFpMvEtTHIy4V+reOnRSw4Ht3gGlic 3TG3d2rJsf1oIKIb1xlsPWM69/wZQOrF9qYaoqPiVVz22GDJ39d9spb51ssi/Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1724189680; a=rsa-sha256; cv=none; b=p9+ntgUSJl6hM01/wHGlObqhSfL2XtCSpf1cAmRn9SdKhWqO2gw81kqgX3C0hOPbI8gdT2 qP8EEiOk8ghOoSq7KgrNZRFc76POe0LjfN8wWGP00Rx3DM34QnW+T7dZSUUmIgMGqMo2BS E08nnCvn8VPE/Q6adQmZa4BNRBoDRdYa23VXRrf1Yp2ZlegENurS/ZMPkDbn1osoGVfrnZ JYbD5iL22crn+LtODWQ4kRXbrLDfItV8aq33QT9oq3hDJpEcB0pnhedRrfMN1mHuyta8ta 2Cqp/KalVA+8JvtKj9wvCcDXguDBZZpe7S/OrbuVcr7Posob+RTcZbBUVwJ1AQ== 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=1724189680; 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=2Shwap851Tk00JyIXYY8Y2nA7OW03XuiNKCT/BNivho=; b=Fi7jcbsILQAk2xIZzv8m/W18xd1NbbjsbzxBWRNloiKNO65XK8pN1Tk1IhRM9a8sR2GsP5 AW2+34ABJB4/ogRqYYAgcamZ05Du/4ufETsfjecg1ZJmqy5brUEJVsh38LnayD9rZJZtxw kBILQC7w3zaRCyqYSeLjw/xGPIAcaRz5kVU7s+FlvCEYD0Nlk0OXOpLrLqDP+i/AahJII1 XccOeuN0AEwVR5pzXhEMSNDHLa46nyRZrGyNxhHOj4QA17FGXvksahPgz8DtcZjDhnMlq9 /m+UI0AYTFJeedI9v4yWzdxwGeE46CviAIbFbYRyzqOZz85cmGNvincoz89aqw== 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 4WpN5q6bdvzGsf; Tue, 20 Aug 2024 21:34:39 +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 47KLYduh055389; Tue, 20 Aug 2024 21:34:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 47KLYdPH055386; Tue, 20 Aug 2024 21:34:39 GMT (envelope-from git) Date: Tue, 20 Aug 2024 21:34:39 GMT Message-Id: <202408202134.47KLYdPH055386@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: 417b35a97b76 - main - netinet: Add a sysctl to allow disabling connections to INADDR_ANY 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: 417b35a97b7669eb0bf417b43e97cccbedbce6f9 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=417b35a97b7669eb0bf417b43e97cccbedbce6f9 commit 417b35a97b7669eb0bf417b43e97cccbedbce6f9 Author: Mark Johnston AuthorDate: 2024-08-20 21:31:57 +0000 Commit: Mark Johnston CommitDate: 2024-08-20 21:31:57 +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 --- 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 1a341d421f31..3fc90f1e12c2 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -234,6 +234,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 *); /* @@ -1309,7 +1315,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 e6ec0f24c898..098b4e50483c 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -83,6 +83,7 @@ #include #include #include +#include #include #include #include @@ -97,6 +98,7 @@ #include #include #include +#include #include #include @@ -112,6 +114,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) { @@ -351,7 +361,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.