The branch main has been updated by tuexen:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=edc5b6ea881d7e196fee8df7ebcd372f8f5b4469

commit edc5b6ea881d7e196fee8df7ebcd372f8f5b4469
Author:     Michael Tuexen <[email protected]>
AuthorDate: 2022-05-14 10:38:43 +0000
Commit:     Michael Tuexen <[email protected]>
CommitDate: 2022-05-14 10:38:43 +0000

    sctp: use sb_avail() when accessing sb_acc for reading
    
    This is a cleanup to simplify a patch for PR 260116.
    
    PR:             260116
    MFC after:      3 days
---
 sys/netinet/sctp_indata.c |  2 +-
 sys/netinet/sctp_os_bsd.h |  2 ++
 sys/netinet/sctp_output.c |  2 +-
 sys/netinet/sctp_pcb.c    |  2 +-
 sys/netinet/sctp_usrreq.c |  7 +++----
 sys/netinet/sctputil.c    | 30 +++++++++++++++---------------
 6 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/sys/netinet/sctp_indata.c b/sys/netinet/sctp_indata.c
index b43aa8208239..8a2c30827198 100644
--- a/sys/netinet/sctp_indata.c
+++ b/sys/netinet/sctp_indata.c
@@ -1942,7 +1942,7 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct 
sctp_association *asoc,
                 * When we have NO room in the rwnd we check to make sure
                 * the reader is doing its job...
                 */
-               if (stcb->sctp_socket->so_rcv.sb_cc) {
+               if (SCTP_SBAVAIL(&stcb->sctp_socket->so_rcv) > 0) {
                        /* some to read, wake-up */
                        sctp_sorwakeup(stcb->sctp_ep, stcb->sctp_socket);
                }
diff --git a/sys/netinet/sctp_os_bsd.h b/sys/netinet/sctp_os_bsd.h
index faca8a3b6276..8240fca64c48 100644
--- a/sys/netinet/sctp_os_bsd.h
+++ b/sys/netinet/sctp_os_bsd.h
@@ -381,6 +381,8 @@ typedef struct callout sctp_os_timer_t;
 #define SCTP_SORESERVE(so, send, recv) soreserve(so, send, recv)
 /* wakeup a socket */
 #define SCTP_SOWAKEUP(so)      wakeup(&(so)->so_timeo)
+/* number of bytes ready to read */
+#define SCTP_SBAVAIL(sb)       sbavail(sb)
 /* clear the socket buffer state */
 #define SCTP_SB_CLEAR(sb)      \
        (sb).sb_cc = 0;         \
diff --git a/sys/netinet/sctp_output.c b/sys/netinet/sctp_output.c
index 3a891eb86116..2614e333e84e 100644
--- a/sys/netinet/sctp_output.c
+++ b/sys/netinet/sctp_output.c
@@ -11519,7 +11519,7 @@ jump_out:
                drp->current_onq = htonl(asoc->size_on_reasm_queue +
                    asoc->size_on_all_streams +
                    asoc->my_rwnd_control_len +
-                   stcb->sctp_socket->so_rcv.sb_cc);
+                   SCTP_SBAVAIL(&stcb->sctp_socket->so_rcv));
        } else {
                /*-
                 * If my rwnd is 0, possibly from mbuf depletion as well as
diff --git a/sys/netinet/sctp_pcb.c b/sys/netinet/sctp_pcb.c
index 09f5d86fa1a6..38c88d8ae8e4 100644
--- a/sys/netinet/sctp_pcb.c
+++ b/sys/netinet/sctp_pcb.c
@@ -3409,7 +3409,7 @@ sctp_inpcb_free(struct sctp_inpcb *inp, int immediate, 
int from)
                        if ((stcb->asoc.size_on_reasm_queue > 0) ||
                            (stcb->asoc.control_pdapi) ||
                            (stcb->asoc.size_on_all_streams > 0) ||
-                           (so && (so->so_rcv.sb_cc > 0))) {
+                           ((so != NULL) && (SCTP_SBAVAIL(&so->so_rcv) > 0))) {
                                /* Left with Data unread */
                                struct mbuf *op_err;
 
diff --git a/sys/netinet/sctp_usrreq.c b/sys/netinet/sctp_usrreq.c
index 98102722c53e..05820f2b2859 100644
--- a/sys/netinet/sctp_usrreq.c
+++ b/sys/netinet/sctp_usrreq.c
@@ -545,7 +545,7 @@ sctp_close(struct socket *so)
        if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
                inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_GONE | 
SCTP_PCB_FLAGS_CLOSE_IP;
                if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
-                   (so->so_rcv.sb_cc > 0)) {
+                   (SCTP_SBAVAIL(&so->so_rcv) > 0)) {
 #ifdef SCTP_LOG_CLOSING
                        sctp_log_closing(inp, NULL, 13);
 #endif
@@ -707,9 +707,8 @@ sctp_disconnect(struct socket *so)
                                return (0);
                        }
                        NET_EPOCH_ENTER(et);
-                       if (((so->so_options & SO_LINGER) &&
-                           (so->so_linger == 0)) ||
-                           (so->so_rcv.sb_cc > 0)) {
+                       if (((so->so_options & SO_LINGER) && (so->so_linger == 
0)) ||
+                           (SCTP_SBAVAIL(&so->so_rcv) > 0)) {
                                if (SCTP_GET_STATE(stcb) != 
SCTP_STATE_COOKIE_WAIT) {
                                        /* Left with Data unread */
                                        struct mbuf *op_err;
diff --git a/sys/netinet/sctputil.c b/sys/netinet/sctputil.c
index 8ec934e83cfc..a851631d2f74 100644
--- a/sys/netinet/sctputil.c
+++ b/sys/netinet/sctputil.c
@@ -76,7 +76,7 @@ sctp_sblog(struct sockbuf *sb, struct sctp_tcb *stcb, int 
from, int incr)
        struct sctp_cwnd_log sctp_clog;
 
        sctp_clog.x.sb.stcb = stcb;
-       sctp_clog.x.sb.so_sbcc = sb->sb_cc;
+       sctp_clog.x.sb.so_sbcc = SCTP_SBAVAIL(sb);
        if (stcb)
                sctp_clog.x.sb.stcb_sbcc = stcb->asoc.sb_cc;
        else
@@ -5565,11 +5565,11 @@ sctp_sorecvmsg(struct socket *so,
        in_eeor_mode = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
        if (SCTP_BASE_SYSCTL(sctp_logging_level) & 
SCTP_RECV_RWND_LOGGING_ENABLE) {
                sctp_misc_ints(SCTP_SORECV_ENTER,
-                   rwnd_req, in_eeor_mode, so->so_rcv.sb_cc, 
(uint32_t)uio->uio_resid);
+                   rwnd_req, in_eeor_mode, SCTP_SBAVAIL(&so->so_rcv), 
(uint32_t)uio->uio_resid);
        }
        if (SCTP_BASE_SYSCTL(sctp_logging_level) & 
SCTP_RECV_RWND_LOGGING_ENABLE) {
                sctp_misc_ints(SCTP_SORECV_ENTERPL,
-                   rwnd_req, block_allowed, so->so_rcv.sb_cc, 
(uint32_t)uio->uio_resid);
+                   rwnd_req, block_allowed, SCTP_SBAVAIL(&so->so_rcv), 
(uint32_t)uio->uio_resid);
        }
 
        error = SOCK_IO_RECV_LOCK(so, SBLOCKWAIT(in_flags));
@@ -5588,21 +5588,21 @@ restart_nosblocks:
            (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE)) {
                goto out;
        }
-       if ((so->so_rcv.sb_state & SBS_CANTRCVMORE) && (so->so_rcv.sb_cc == 0)) 
{
+       if ((so->so_rcv.sb_state & SBS_CANTRCVMORE) && 
SCTP_SBAVAIL(&so->so_rcv) == 0) {
                if (so->so_error) {
                        error = so->so_error;
                        if ((in_flags & MSG_PEEK) == 0)
                                so->so_error = 0;
                        goto out;
                } else {
-                       if (so->so_rcv.sb_cc == 0) {
+                       if (SCTP_SBAVAIL(&so->so_rcv) == 0) {
                                /* indicate EOF */
                                error = 0;
                                goto out;
                        }
                }
        }
-       if (so->so_rcv.sb_cc <= held_length) {
+       if (SCTP_SBAVAIL(&so->so_rcv) <= held_length) {
                if (so->so_error) {
                        error = so->so_error;
                        if ((in_flags & MSG_PEEK) == 0) {
@@ -5610,7 +5610,7 @@ restart_nosblocks:
                        }
                        goto out;
                }
-               if ((so->so_rcv.sb_cc == 0) &&
+               if ((SCTP_SBAVAIL(&so->so_rcv) == 0) &&
                    ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
                    (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
                        if ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0) {
@@ -5670,7 +5670,7 @@ restart_nosblocks:
                        SCTP_INP_READ_LOCK(inp);
                }
                control = TAILQ_FIRST(&inp->read_queue);
-               if ((control == NULL) && (so->so_rcv.sb_cc != 0)) {
+               if ((control == NULL) && (SCTP_SBAVAIL(&so->so_rcv) > 0)) {
 #ifdef INVARIANTS
                        panic("Huh, its non zero and nothing on control?");
 #endif
@@ -5805,8 +5805,8 @@ restart_nosblocks:
                 * <or> fragment interleave is NOT on. So stuff the sb_cc
                 * into the our held count, and its time to sleep again.
                 */
-               held_length = so->so_rcv.sb_cc;
-               control->held_length = so->so_rcv.sb_cc;
+               held_length = SCTP_SBAVAIL(&so->so_rcv);
+               control->held_length = SCTP_SBAVAIL(&so->so_rcv);
                goto restart;
        }
        /* Clear the held length since there is something to read */
@@ -6255,7 +6255,7 @@ wait_some_more:
                    (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE))) {
                        goto release;
                }
-               if (so->so_rcv.sb_cc <= control->held_length) {
+               if (SCTP_SBAVAIL(&so->so_rcv) <= control->held_length) {
                        error = sbwait(so, SO_RCV);
                        if (error) {
                                goto release;
@@ -6282,8 +6282,8 @@ wait_some_more:
                                }
                                goto done_with_control;
                        }
-                       if (so->so_rcv.sb_cc > held_length) {
-                               control->held_length = so->so_rcv.sb_cc;
+                       if (SCTP_SBAVAIL(&so->so_rcv) > held_length) {
+                               control->held_length = 
SCTP_SBAVAIL(&so->so_rcv);
                                held_length = 0;
                        }
                        goto wait_some_more;
@@ -6432,13 +6432,13 @@ out:
                            freed_so_far,
                            (uint32_t)((uio) ? (slen - uio->uio_resid) : slen),
                            stcb->asoc.my_rwnd,
-                           so->so_rcv.sb_cc);
+                           SCTP_SBAVAIL(&so->so_rcv));
                } else {
                        sctp_misc_ints(SCTP_SORECV_DONE,
                            freed_so_far,
                            (uint32_t)((uio) ? (slen - uio->uio_resid) : slen),
                            0,
-                           so->so_rcv.sb_cc);
+                           SCTP_SBAVAIL(&so->so_rcv));
                }
        }
 stage_left:

Reply via email to