From nobody Mon Aug 10 17:40:31 2026 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 4hJhqP13Xyz6X2fT for ; Mon, 10 Aug 2026 17:40: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 "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hJhqM6J0Nz48jM for ; Mon, 10 Aug 2026 17:40:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1786383631; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RuC4sLezOGpTDx4yXcqYG9MeXjHMMuzdYF0WMKxSkJU=; b=jpWeSF1Y3bOpAmYtUXh+v70JWGjZuEgQzCzZPZqA4OZP+lCOZeMFhvOeRTn6sLd6YTZWka e2rsX2wOcyxF6y43Ij7QYw1sLeTIP8CBCcoquyArsACoL01ou4981zM43zn6Z8tOW0p4/4 2+Hh/voppg0Mi00tDUV+/3NcJET3Nfg3+iXHbwqnO8pLBMe1tqaUPPqI4KMWcWY/0wmBYq Qbofrwt60dlC5a2asitHA6JV2h4UQSpv7vBmE1h9AT5OXrVTnfT5hN9i92EIgc3PqQf4qS fzSTEiu1egduupt3k9FajE7QODjW59MnRJIMWOpHCIs6lDTV7QxHU9puLyCJCA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1786383631; a=rsa-sha256; cv=none; b=BiNSOjIImHpZQafPmbaI0454id0c0yynD/Kr4wcjodhi+oJONjitF1YIEV7Yp024tw+eqW Ur98UjLsa65Y/eOH62gk/PkuSEDjsgqYXL4ZNPOSWYtpfLwZtpTrh5sHxTUl69UNU8p0ZE /Nw6CYQ81QqkfxuwsTF3B0xuslLfJmxx0ERhZHf+Td7NE3FVfkb8DNS/AFwGmwdJnqyc0H oQKsyAwtsj0sygmKOThLw3XpHQT1FTvAJG2Fsz448P9Q8zCHpYnbnXO0y8jWqyyLLO3sTO pJYq02+4LZ0rpPHDPHAQ4jdJrmTM4hf9gTVSAQKHTCpZpFipQxhws9AGxdBFWA== 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=1786383631; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RuC4sLezOGpTDx4yXcqYG9MeXjHMMuzdYF0WMKxSkJU=; b=hGB8cc3CTUUt0jdB8QV1HLUYyc4LlmEisT8SUAZLo5qVWPT2m1yTSa0icUel6GTBJYXGDh 5FUR+SScjAXV80jH7cuLt8H5VT5vLG1a9PwPTOGNwXYJDANUnosRwi+guz8+pJrrp3yMVA iZ0/CP0AFj8uT2nus+Dvcg1qAj4u83PrQusmhWZCDXAP0Wx921FZUa5BcwQz9s/FSJz4ET Pt9Ee+mPrO6iebbAOsU4VCru+3IByCX/SbkJFqTvXLckbkjp1MrfX3X9wCVvMngGJSbhcO wHio6GhuxX4YX7kx6MmAmTwBewAg+PwRJ8g5cI4PNOox4qtomfAJ8EHEr/ktag== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hJhqM1l2dz3YJ for ; Mon, 10 Aug 2026 17:40:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3f93f by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 10 Aug 2026 17:40:31 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: John Ericson From: Mark Johnston Subject: git: 7977edb76560 - main - unix: split unp_connectat() in two 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 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/main X-Git-Reftype: branch X-Git-Commit: 7977edb7656082d90a539b85bd2a750b383602da Auto-Submitted: auto-generated Date: Mon, 10 Aug 2026 17:40:31 +0000 Message-Id: <6a7a0d0f.3f93f.49cb6403@gitrepo.freebsd.org> The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=7977edb7656082d90a539b85bd2a750b383602da commit 7977edb7656082d90a539b85bd2a750b383602da Author: John Ericson AuthorDate: 2026-08-10 15:04:18 +0000 Commit: Mark Johnston CommitDate: 2026-08-10 17:31:21 +0000 unix: split unp_connectat() in two Factor the second half — connecting to an already-resolved peer PCB — out into a new `unp_connect_peer()`, leaving `unp_connectat()` with the connection state machine and pathname resolution. No functional change. The helper's contract: the caller guarantees stability of the peer PCB (vnode lock plus `unp_vp_mtxpool` lock for peers found via `VOP_UNP_CONNECT()`), has set `UNP_CONNECTING` on the connecting socket, and clears it again on error; the helper clears it on success. This prepares for connecting to a peer named by something other than a pathname. Signed-off-by: John Ericson Reviewed by: markj MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D58404 --- sys/kern/uipc_usrreq.c | 102 +++++++++++++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 41 deletions(-) diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 0e3f0d13c12d..c1d00e66f614 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -294,6 +294,8 @@ static int unp_connect(struct socket *, struct sockaddr *, struct thread *); static int unp_connectat(int, struct socket *, struct sockaddr *, struct thread *, bool); +static int unp_connect_peer(struct socket *, struct unpcb *, + struct sockaddr **, struct thread *, bool); static void unp_connect2(struct socket *, struct socket *, bool); static void unp_disconnect(struct unpcb *unp, struct unpcb *unp2); static void unp_dispose(struct socket *so); @@ -2889,8 +2891,7 @@ unp_connectat(int fd, struct socket *so, struct sockaddr *nam, struct mtx *vplock; struct sockaddr_un *soun; struct vnode *vp; - struct socket *so2; - struct unpcb *unp, *unp2, *unp3; + struct unpcb *unp, *unp2; struct nameidata nd; char buf[SOCK_MAXADDRLEN]; struct sockaddr *sa; @@ -2979,40 +2980,80 @@ unp_connectat(int fd, struct socket *so, struct sockaddr *nam, if (error) goto bad; - unp = sotounpcb(so); - KASSERT(unp != NULL, ("unp_connect: unp == NULL")); - vplock = mtx_pool_find(unp_vp_mtxpool, vp); mtx_lock(vplock); VOP_UNP_CONNECT(vp, &unp2); - if (unp2 == NULL) { + if (unp2 == NULL) error = ECONNREFUSED; - goto bad2; + else + error = unp_connect_peer(so, unp2, &sa, td, return_locked); + mtx_unlock(vplock); +bad: + if (vp != NULL) { + /* + * If we are returning locked (called via uipc_sosend_dgram()), + * we need to be sure that vput() won't sleep. This is + * guaranteed by VOP_UNP_CONNECT() call above and unp2 lock. + * SOCK_STREAM/SEQPACKET can't request return_locked (yet). + */ + MPASS(!(return_locked && connreq)); + vput(vp); } - so2 = unp2->unp_socket; - if (so->so_type != so2->so_type) { - error = EPROTOTYPE; - goto bad2; + free(sa, M_SONAME); + if (__predict_false(error)) { + UNP_PCB_LOCK(unp); + KASSERT((unp->unp_flags & UNP_CONNECTING) != 0, + ("%s: unp %p has UNP_CONNECTING clear", __func__, unp)); + unp->unp_flags &= ~UNP_CONNECTING; + UNP_PCB_UNLOCK(unp); } + return (error); +} + +/* + * Second half of connecting a unix socket: 'so' is our connecting socket, + * with UNP_CONNECTING set, and 'unp2' is the PCB of the peer named by the + * caller, which must guarantee its stability (by holding a reference on the + * peer socket, or the vnode lock plus unp_vp_mtxpool lock for a peer found + * via VOP_UNP_CONNECT()). + * + * For connection-oriented sockets '*sap' points to a buffer to hold the + * listener's address; it is consumed (set to NULL) if used. On success + * UNP_CONNECTING is cleared; on error the caller must clear it. + */ +static int +unp_connect_peer(struct socket *so, struct unpcb *unp2, struct sockaddr **sap, + struct thread *td, bool return_locked) +{ + struct socket *so2; + struct unpcb *unp, *unp3; + int error; + bool connreq; + + unp = sotounpcb(so); + KASSERT(unp != NULL, ("%s: unp == NULL", __func__)); + connreq = (so->so_proto->pr_flags & PR_CONNREQUIRED) != 0; + + so2 = unp2->unp_socket; + if (so->so_type != so2->so_type) + return (EPROTOTYPE); if (connreq) { if (SOLISTENING(so2)) so2 = solisten_clone(so2); else so2 = NULL; - if (so2 == NULL) { - error = ECONNREFUSED; - goto bad2; - } + if (so2 == NULL) + return (ECONNREFUSED); if ((error = uipc_attach(so2, 0, NULL)) != 0) { sodealloc(so2); - goto bad2; + return (error); } unp3 = sotounpcb(so2); unp_pcb_lock_pair(unp2, unp3); if (unp2->unp_addr != NULL) { - bcopy(unp2->unp_addr, sa, unp2->unp_addr->sun_len); - unp3->unp_addr = (struct sockaddr_un *) sa; - sa = NULL; + bcopy(unp2->unp_addr, *sap, unp2->unp_addr->sun_len); + unp3->unp_addr = (struct sockaddr_un *)*sap; + *sap = NULL; } unp_copy_peercred(td, unp3, unp, unp2); @@ -3043,28 +3084,7 @@ unp_connectat(int fd, struct socket *so, struct sockaddr *nam, unp->unp_flags &= ~UNP_CONNECTING; if (!return_locked) unp_pcb_unlock_pair(unp, unp2); -bad2: - mtx_unlock(vplock); -bad: - if (vp != NULL) { - /* - * If we are returning locked (called via uipc_sosend_dgram()), - * we need to be sure that vput() won't sleep. This is - * guaranteed by VOP_UNP_CONNECT() call above and unp2 lock. - * SOCK_STREAM/SEQPACKET can't request return_locked (yet). - */ - MPASS(!(return_locked && connreq)); - vput(vp); - } - free(sa, M_SONAME); - if (__predict_false(error)) { - UNP_PCB_LOCK(unp); - KASSERT((unp->unp_flags & UNP_CONNECTING) != 0, - ("%s: unp %p has UNP_CONNECTING clear", __func__, unp)); - unp->unp_flags &= ~UNP_CONNECTING; - UNP_PCB_UNLOCK(unp); - } - return (error); + return (0); } /*