From nobody Fri Jun 24 16:10:30 2022 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 B920A865460; Fri, 24 Jun 2022 16:10:31 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LV2CW1Fwsz3JG1; Fri, 24 Jun 2022 16:10:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656087031; 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=Cr5Uvlj10Hl4Ty3eeaWu7UZpVAz4K5vbBJXqz+pdFiA=; b=fQKi+lky9xMPhoT9HWLMtYRWv17bkD8e6RUoZoYQZ9Q54MrnGKishsJlV0sgSdkYz/Iv4E znBfX8usm8D+p1R7WaGqxJ3f6bN1BYIPkkRrdyha8dnSYkq58EBjipEsnc7NoDxrXCIBFf yLkYz1LecDPhX0Pc3YHryenpMsJDhKoyook7uxrtLl0hgL1e0xrse0R727oiZ6NGDS+oTH YO9P8/zTGuS7ouRHpYpPLqfW7hphMUYWhVwWW8madkApPENgKSoXhG6TkLHT37Jj45Ajyi 5fcbpoxn150sNCpGSZdJu30QstK5lJNjJi2mrl3yiNjYDfG90Z6PWMMfZMDGtQ== 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 EF76012F42; Fri, 24 Jun 2022 16:10:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 25OGAUa4006113; Fri, 24 Jun 2022 16:10:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25OGAUnF006112; Fri, 24 Jun 2022 16:10:30 GMT (envelope-from git) Date: Fri, 24 Jun 2022 16:10:30 GMT Message-Id: <202206241610.25OGAUnF006112@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: f384a97c839a - main - unix/dgram: cleanup uipc_send of PF_UNIX/SOCK_DGRAM, step 2 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f384a97c839ac6f8a51785a0e394154b320eca9b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656087031; 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=Cr5Uvlj10Hl4Ty3eeaWu7UZpVAz4K5vbBJXqz+pdFiA=; b=iM+sa9VKZ2UEfQs0vy2UlBqd5ZrIGFEEZlMjVIMcdCXM2Q+HOAo6nQaTABgyRghcocX0Or u5/C1h/cUU0A6s3DZRcKTc920w5qUIvk+ZdHSZvPF2K0JtjLCQMkCcWPgKhS+Q3f5wg+4W I834cdSp+5VRFkWfyjRmkCteiElKKLjkN/HOPyq6esPsAlTvAQjQKMSZNYZoaTPOvtTL94 Fs5OBhANBvRvjKmyTOwEpQrwhHLgeYEjMIUGA1/OTl0j5KmVYvv9Ao39hIgVJgcWH/Pybm FS98+TIdjnzVRFH/FrPuYN7fkBrGorl8jF+M+mjIBCQbcsSMelL15+PV/IPPsw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1656087031; a=rsa-sha256; cv=none; b=waCPVIFtBPuM19TbUQHt2Vif4a7BSB1xN0/ommuB5NZdiM1VzkVGEa2A7w1ZFuQ5Pk5xBA ojv7Zlz7fN9xQhYY9J5uHQsenzOVXfVafPx0ztzstrwg5O0KoHfhYMj/Im9bammt2N7S7K uslxovaR+ZGNbpUVlzzspJy0QhAxFqTB3DvcBAaCXiEEnncpHKRREKdZWjXwG8V7rm1atx FO4i5hT/JlbaaPYBOxoVR9iOUX20GGXTiVkYVcV6v/8NaU2mcUj9iOx60/GMZF6zqLFhyK FMfV5m7T3On6T8rFqU3GawpAKzXxUgsZT5nIfenF6NVvRRZIU1VO+BA772hAsA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=f384a97c839ac6f8a51785a0e394154b320eca9b commit f384a97c839ac6f8a51785a0e394154b320eca9b Author: Gleb Smirnoff AuthorDate: 2022-06-24 16:09:10 +0000 Commit: Gleb Smirnoff CommitDate: 2022-06-24 16:09:10 +0000 unix/dgram: cleanup uipc_send of PF_UNIX/SOCK_DGRAM, step 2 Just remove one level of indentation as the case clause always match. Reviewed by: markj Differential revision: https://reviews.freebsd.org/D35295 --- sys/kern/uipc_usrreq.c | 154 ++++++++++++++++++++++++------------------------- 1 file changed, 74 insertions(+), 80 deletions(-) diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 5141ca6a2ad3..f612bdecfc6b 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1008,96 +1008,90 @@ uipc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam, goto release; unp2 = NULL; - switch (so->so_type) { - case SOCK_SEQPACKET: - case SOCK_STREAM: - if ((so->so_state & SS_ISCONNECTED) == 0) { - if (nam != NULL) { - error = unp_connect(so, nam, td); - if (error != 0) - break; - } else { - error = ENOTCONN; - break; - } - } - - UNP_PCB_LOCK(unp); - if ((unp2 = unp_pcb_lock_peer(unp)) == NULL) { - UNP_PCB_UNLOCK(unp); - error = ENOTCONN; - break; - } else if (so->so_snd.sb_state & SBS_CANTSENDMORE) { - unp_pcb_unlock_pair(unp, unp2); - error = EPIPE; - break; - } - UNP_PCB_UNLOCK(unp); - if ((so2 = unp2->unp_socket) == NULL) { - UNP_PCB_UNLOCK(unp2); + if ((so->so_state & SS_ISCONNECTED) == 0) { + if (nam != NULL) { + if ((error = unp_connect(so, nam, td)) != 0) + goto out; + } else { error = ENOTCONN; - break; - } - SOCKBUF_LOCK(&so2->so_rcv); - if (unp2->unp_flags & UNP_WANTCRED_MASK) { - /* - * Credentials are passed only once on SOCK_STREAM and - * SOCK_SEQPACKET (LOCAL_CREDS => WANTCRED_ONESHOT), or - * forever (LOCAL_CREDS_PERSISTENT => WANTCRED_ALWAYS). - */ - control = unp_addsockcred(td, control, unp2->unp_flags); - unp2->unp_flags &= ~UNP_WANTCRED_ONESHOT; + goto out; } + } + UNP_PCB_LOCK(unp); + if ((unp2 = unp_pcb_lock_peer(unp)) == NULL) { + UNP_PCB_UNLOCK(unp); + error = ENOTCONN; + goto out; + } else if (so->so_snd.sb_state & SBS_CANTSENDMORE) { + unp_pcb_unlock_pair(unp, unp2); + error = EPIPE; + goto out; + } + UNP_PCB_UNLOCK(unp); + if ((so2 = unp2->unp_socket) == NULL) { + UNP_PCB_UNLOCK(unp2); + error = ENOTCONN; + goto out; + } + SOCKBUF_LOCK(&so2->so_rcv); + if (unp2->unp_flags & UNP_WANTCRED_MASK) { /* - * Send to paired receive port and wake up readers. Don't - * check for space available in the receive buffer if we're - * attaching ancillary data; Unix domain sockets only check - * for space in the sending sockbuf, and that check is - * performed one level up the stack. At that level we cannot - * precisely account for the amount of buffer space used - * (e.g., because control messages are not yet internalized). + * Credentials are passed only once on SOCK_STREAM and + * SOCK_SEQPACKET (LOCAL_CREDS => WANTCRED_ONESHOT), or + * forever (LOCAL_CREDS_PERSISTENT => WANTCRED_ALWAYS). */ - switch (so->so_type) { - case SOCK_STREAM: - if (control != NULL) { - sbappendcontrol_locked(&so2->so_rcv, m, - control, flags); - control = NULL; - } else - sbappend_locked(&so2->so_rcv, m, flags); - break; - - case SOCK_SEQPACKET: - if (sbappendaddr_nospacecheck_locked(&so2->so_rcv, - &sun_noname, m, control)) - control = NULL; - break; - } + control = unp_addsockcred(td, control, unp2->unp_flags); + unp2->unp_flags &= ~UNP_WANTCRED_ONESHOT; + } - mbcnt = so2->so_rcv.sb_mbcnt; - sbcc = sbavail(&so2->so_rcv); - if (sbcc) - sorwakeup_locked(so2); - else - SOCKBUF_UNLOCK(&so2->so_rcv); + /* + * Send to paired receive port and wake up readers. Don't + * check for space available in the receive buffer if we're + * attaching ancillary data; Unix domain sockets only check + * for space in the sending sockbuf, and that check is + * performed one level up the stack. At that level we cannot + * precisely account for the amount of buffer space used + * (e.g., because control messages are not yet internalized). + */ + switch (so->so_type) { + case SOCK_STREAM: + if (control != NULL) { + sbappendcontrol_locked(&so2->so_rcv, m, + control, flags); + control = NULL; + } else + sbappend_locked(&so2->so_rcv, m, flags); + break; - /* - * The PCB lock on unp2 protects the SB_STOP flag. Without it, - * it would be possible for uipc_rcvd to be called at this - * point, drain the receiving sockbuf, clear SB_STOP, and then - * we would set SB_STOP below. That could lead to an empty - * sockbuf having SB_STOP set - */ - SOCKBUF_LOCK(&so->so_snd); - if (sbcc >= so->so_snd.sb_hiwat || mbcnt >= so->so_snd.sb_mbmax) - so->so_snd.sb_flags |= SB_STOP; - SOCKBUF_UNLOCK(&so->so_snd); - UNP_PCB_UNLOCK(unp2); - m = NULL; + case SOCK_SEQPACKET: + if (sbappendaddr_nospacecheck_locked(&so2->so_rcv, + &sun_noname, m, control)) + control = NULL; break; } + mbcnt = so2->so_rcv.sb_mbcnt; + sbcc = sbavail(&so2->so_rcv); + if (sbcc) + sorwakeup_locked(so2); + else + SOCKBUF_UNLOCK(&so2->so_rcv); + + /* + * The PCB lock on unp2 protects the SB_STOP flag. Without it, + * it would be possible for uipc_rcvd to be called at this + * point, drain the receiving sockbuf, clear SB_STOP, and then + * we would set SB_STOP below. That could lead to an empty + * sockbuf having SB_STOP set + */ + SOCKBUF_LOCK(&so->so_snd); + if (sbcc >= so->so_snd.sb_hiwat || mbcnt >= so->so_snd.sb_mbmax) + so->so_snd.sb_flags |= SB_STOP; + SOCKBUF_UNLOCK(&so->so_snd); + UNP_PCB_UNLOCK(unp2); + m = NULL; +out: /* * PRUS_EOF is equivalent to pru_send followed by pru_shutdown. */