git: f384a97c839a - main - unix/dgram: cleanup uipc_send of PF_UNIX/SOCK_DGRAM, step 2
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 24 Jun 2022 16:10:30 UTC
The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=f384a97c839ac6f8a51785a0e394154b320eca9b commit f384a97c839ac6f8a51785a0e394154b320eca9b Author: Gleb Smirnoff <glebius@FreeBSD.org> AuthorDate: 2022-06-24 16:09:10 +0000 Commit: Gleb Smirnoff <glebius@FreeBSD.org> 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. */