git: 5cebd8305afe - main - sctp: more sb_cc related cleanups

From: Michael Tuexen <tuexen_at_FreeBSD.org>
Date: Mon, 23 May 2022 14:12:17 UTC
The branch main has been updated by tuexen:

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

commit 5cebd8305afecad82f5d9628d8f7981d33559037
Author:     Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2022-05-23 14:09:23 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2022-05-23 14:09:23 +0000

    sctp: more sb_cc related cleanups
    
    No functional change intended. It allows a simpler patch for PR 260116.
    
    MFC after:      3 days
---
 sys/netinet/sctp_var.h |  2 +-
 sys/netinet/sctputil.c | 15 +++++++--------
 sys/netinet/sctputil.h | 24 ------------------------
 3 files changed, 8 insertions(+), 33 deletions(-)

diff --git a/sys/netinet/sctp_var.h b/sys/netinet/sctp_var.h
index b45c4ac410f9..0f2d3d9c61d6 100644
--- a/sys/netinet/sctp_var.h
+++ b/sys/netinet/sctp_var.h
@@ -85,7 +85,7 @@ extern struct pr_usrreqs sctp_usrreqs;
 
 #define	sctp_sbspace(asoc, sb) ((long) ((sctp_maxspace(sb) > (asoc)->sb_cc) ? (sctp_maxspace(sb) - (asoc)->sb_cc) : 0))
 
-#define	sctp_sbspace_failedmsgs(sb) ((long) ((sctp_maxspace(sb) > (sb)->sb_cc) ? (sctp_maxspace(sb) - (sb)->sb_cc) : 0))
+#define	sctp_sbspace_failedmsgs(sb) ((long) ((sctp_maxspace(sb) > SCTP_SBAVAIL(sb)) ? (sctp_maxspace(sb) - SCTP_SBAVAIL(sb)) : 0))
 
 #define sctp_sbspace_sub(a,b) (((a) > (b)) ? ((a) - (b)) : 0)
 
diff --git a/sys/netinet/sctputil.c b/sys/netinet/sctputil.c
index a851631d2f74..23f95353323f 100644
--- a/sys/netinet/sctputil.c
+++ b/sys/netinet/sctputil.c
@@ -5003,7 +5003,6 @@ sctp_generate_no_user_data_cause(uint32_t tsn)
 	return (m);
 }
 
-#ifdef SCTP_MBCNT_LOGGING
 void
 sctp_free_bufspace(struct sctp_tcb *stcb, struct sctp_association *asoc,
     struct sctp_tmit_chunk *tp1, int chk_cnt)
@@ -5011,7 +5010,8 @@ sctp_free_bufspace(struct sctp_tcb *stcb, struct sctp_association *asoc,
 	if (tp1->data == NULL) {
 		return;
 	}
-	asoc->chunks_on_out_queue -= chk_cnt;
+	atomic_subtract_int(&asoc->chunks_on_out_queue, chk_cnt);
+#ifdef SCTP_MBCNT_LOGGING
 	if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBCNT_LOGGING_ENABLE) {
 		sctp_log_mbcnt(SCTP_LOG_MBCNT_DECREASE,
 		    asoc->total_output_queue_size,
@@ -5019,24 +5019,23 @@ sctp_free_bufspace(struct sctp_tcb *stcb, struct sctp_association *asoc,
 		    0,
 		    tp1->mbcnt);
 	}
+#endif
 	if (asoc->total_output_queue_size >= tp1->book_size) {
-		atomic_add_int(&asoc->total_output_queue_size, -tp1->book_size);
+		atomic_subtract_int(&asoc->total_output_queue_size, tp1->book_size);
 	} else {
 		asoc->total_output_queue_size = 0;
 	}
-
-	if (stcb->sctp_socket && (((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) ||
+	if ((stcb->sctp_socket != NULL) &&
+	    (((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) ||
 	    ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE)))) {
 		if (stcb->sctp_socket->so_snd.sb_cc >= tp1->book_size) {
-			stcb->sctp_socket->so_snd.sb_cc -= tp1->book_size;
+			atomic_subtract_int(&((stcb)->sctp_socket->so_snd.sb_cc), tp1->book_size);
 		} else {
 			stcb->sctp_socket->so_snd.sb_cc = 0;
 		}
 	}
 }
 
-#endif
-
 int
 sctp_release_pr_sctp_chunk(struct sctp_tcb *stcb, struct sctp_tmit_chunk *tp1,
     uint8_t sent, int so_locked)
diff --git a/sys/netinet/sctputil.h b/sys/netinet/sctputil.h
index 8253fde829e1..1105ea14e1ad 100644
--- a/sys/netinet/sctputil.h
+++ b/sys/netinet/sctputil.h
@@ -239,34 +239,10 @@ sctp_bindx_delete_address(struct sctp_inpcb *inp, struct sockaddr *sa,
 
 int sctp_local_addr_count(struct sctp_tcb *stcb);
 
-#ifdef SCTP_MBCNT_LOGGING
 void
 sctp_free_bufspace(struct sctp_tcb *, struct sctp_association *,
     struct sctp_tmit_chunk *, int);
 
-#else
-#define sctp_free_bufspace(stcb, asoc, tp1, chk_cnt)  \
-do { \
-	if (tp1->data != NULL) { \
-		atomic_subtract_int(&((asoc)->chunks_on_out_queue), chk_cnt); \
-		if ((asoc)->total_output_queue_size >= tp1->book_size) { \
-			atomic_subtract_int(&((asoc)->total_output_queue_size), tp1->book_size); \
-		} else { \
-			(asoc)->total_output_queue_size = 0; \
-		} \
-		if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \
-		    (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \
-			if (stcb->sctp_socket->so_snd.sb_cc >= tp1->book_size) { \
-				atomic_subtract_int(&((stcb)->sctp_socket->so_snd.sb_cc), tp1->book_size); \
-			} else { \
-				stcb->sctp_socket->so_snd.sb_cc = 0; \
-			} \
-		} \
-	} \
-} while (0)
-
-#endif
-
 #define sctp_free_spbufspace(stcb, asoc, sp)  \
 do { \
 	if (sp->data != NULL) { \