Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 1 Feb 2023 23:18:47 GMT
From:      Michael Tuexen <tuexen@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: cce40fca85ce - stable/13 - sctp: cleanup, no functional change
Message-ID:  <202302012318.311NIlIZ047838@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by tuexen:

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

commit cce40fca85ce4af528f4c387d8d51ee3c2a5f16c
Author:     Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2022-06-08 20:35:14 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2023-02-01 23:18:24 +0000

    sctp: cleanup, no functional change
    
    (cherry picked from commit ad6ae52d1c2144b6bb6bca8edc485f3a97de2f4b)
---
 sys/netinet/sctp_output.c  | 134 +++++++++++++++++++++++----------------------
 sys/netinet/sctp_structs.h |  42 +++++++-------
 2 files changed, 89 insertions(+), 87 deletions(-)

diff --git a/sys/netinet/sctp_output.c b/sys/netinet/sctp_output.c
index 7695784aafff..7dcd2eab8ed2 100644
--- a/sys/netinet/sctp_output.c
+++ b/sys/netinet/sctp_output.c
@@ -3452,7 +3452,7 @@ sctp_source_address_selection(struct sctp_inpcb *inp,
 	return (answer);
 }
 
-static int
+static bool
 sctp_find_cmsg(int c_type, void *data, struct mbuf *control, size_t cpsize)
 {
 	struct cmsghdr cmh;
@@ -3460,13 +3460,13 @@ sctp_find_cmsg(int c_type, void *data, struct mbuf *control, size_t cpsize)
 	struct sctp_prinfo prinfo;
 	struct sctp_authinfo authinfo;
 	int tot_len, rem_len, cmsg_data_len, cmsg_data_off, off;
-	int found;
+	bool found;
 
 	/*
 	 * Independent of how many mbufs, find the c_type inside the control
 	 * structure and copy out the data.
 	 */
-	found = 0;
+	found = false;
 	tot_len = SCTP_BUF_LEN(control);
 	for (off = 0; off < tot_len; off += CMSG_ALIGN(cmh.cmsg_len)) {
 		rem_len = tot_len - off;
@@ -3505,7 +3505,7 @@ sctp_find_cmsg(int c_type, void *data, struct mbuf *control, size_t cpsize)
 				struct sctp_sndrcvinfo *sndrcvinfo;
 
 				sndrcvinfo = (struct sctp_sndrcvinfo *)data;
-				if (found == 0) {
+				if (!found) {
 					if (cpsize < sizeof(struct sctp_sndrcvinfo)) {
 						return (found);
 					}
@@ -3546,7 +3546,7 @@ sctp_find_cmsg(int c_type, void *data, struct mbuf *control, size_t cpsize)
 				default:
 					return (found);
 				}
-				found = 1;
+				found = true;
 			}
 		}
 	}
@@ -6136,7 +6136,7 @@ do_a_abort:
 static void
 sctp_prune_prsctp(struct sctp_tcb *stcb,
     struct sctp_association *asoc,
-    struct sctp_sndrcvinfo *srcv,
+    struct sctp_nonpad_sndrcvinfo *srcv,
     int dataout)
 {
 	int freed_spc = 0;
@@ -6317,7 +6317,7 @@ static int
 sctp_msg_append(struct sctp_tcb *stcb,
     struct sctp_nets *net,
     struct mbuf *m,
-    struct sctp_sndrcvinfo *srcv)
+    struct sctp_nonpad_sndrcvinfo *srcv)
 {
 	int error = 0;
 	struct mbuf *at;
@@ -6825,7 +6825,7 @@ sctp_copy_out_all(struct uio *uio, ssize_t len)
 
 static int
 sctp_sendall(struct sctp_inpcb *inp, struct uio *uio, struct mbuf *m,
-    struct sctp_sndrcvinfo *srcv)
+    struct sctp_nonpad_sndrcvinfo *srcv)
 {
 	int ret;
 	struct sctp_copy_all *ca;
@@ -6844,7 +6844,7 @@ sctp_sendall(struct sctp_inpcb *inp, struct uio *uio, struct mbuf *m,
 	memset(ca, 0, sizeof(struct sctp_copy_all));
 
 	ca->inp = inp;
-	if (srcv) {
+	if (srcv != NULL) {
 		memcpy(&ca->sndrcv, srcv, sizeof(struct sctp_nonpad_sndrcvinfo));
 	}
 
@@ -12276,7 +12276,7 @@ sctp_copy_one(struct sctp_stream_queue_pending *sp,
 static struct sctp_stream_queue_pending *
 sctp_copy_it_in(struct sctp_tcb *stcb,
     struct sctp_association *asoc,
-    struct sctp_sndrcvinfo *srcv,
+    struct sctp_nonpad_sndrcvinfo *srcv,
     struct uio *uio,
     struct sctp_nets *net,
     ssize_t max_send_len,
@@ -12361,25 +12361,22 @@ sctp_sosend(struct socket *so,
     struct mbuf *top,
     struct mbuf *control,
     int flags,
-    struct thread *p
-)
+    struct thread *p)
 {
-	int error, use_sndinfo = 0;
 	struct sctp_sndrcvinfo sndrcvninfo;
-	struct sockaddr *addr_to_use;
 #if defined(INET) && defined(INET6)
 	struct sockaddr_in sin;
 #endif
+	struct sockaddr *addr_to_use;
+	int error;
+	bool use_sndinfo;
 
-	if (control) {
+	if (control != NULL) {
 		/* process cmsg snd/rcv info (maybe a assoc-id) */
-		if (sctp_find_cmsg(SCTP_SNDRCV, (void *)&sndrcvninfo, control,
-		    sizeof(sndrcvninfo))) {
-			/* got one */
-			use_sndinfo = 1;
-		}
+		use_sndinfo = sctp_find_cmsg(SCTP_SNDRCV, (void *)&sndrcvninfo, control, sizeof(sndrcvninfo));
+	} else {
+		use_sndinfo = false;
 	}
-	addr_to_use = addr;
 #if defined(INET) && defined(INET6)
 	if ((addr != NULL) && (addr->sa_family == AF_INET6)) {
 		struct sockaddr_in6 *sin6;
@@ -12392,15 +12389,17 @@ sctp_sosend(struct socket *so,
 		if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
 			in6_sin6_2_sin(&sin, sin6);
 			addr_to_use = (struct sockaddr *)&sin;
+		} else {
+			addr_to_use = addr;
 		}
+	} else {
+		addr_to_use = addr;
 	}
+#else
+	addr_to_use = addr;
 #endif
-	error = sctp_lower_sosend(so, addr_to_use, uio, top,
-	    control,
-	    flags,
-	    use_sndinfo ? &sndrcvninfo : NULL
-	    ,p
-	    );
+	error = sctp_lower_sosend(so, addr_to_use, uio, top, control, flags,
+	    use_sndinfo ? &sndrcvninfo : NULL, p);
 	return (error);
 }
 
@@ -12411,38 +12410,38 @@ sctp_lower_sosend(struct socket *so,
     struct mbuf *top,
     struct mbuf *control,
     int flags,
-    struct sctp_sndrcvinfo *srcv
-    ,
-    struct thread *p
-)
+    struct sctp_sndrcvinfo *srcv,
+    struct thread *p)
 {
-	struct sctp_nonpad_sndrcvinfo sndrcvninfo;
+	struct sctp_nonpad_sndrcvinfo sndrcvninfo_buf;
 	struct epoch_tracker et;
-	ssize_t sndlen = 0, max_len, local_add_more;
-	int error;
-	int queue_only = 0, queue_only_for_init = 0;
-	bool free_cnt_applied = false;
-	int un_sent;
-	int now_filled = 0;
-	unsigned int inqueue_bytes = 0;
+	struct timeval now;
 	struct sctp_block_entry be;
 	struct sctp_inpcb *inp;
 	struct sctp_tcb *stcb = NULL;
-	struct timeval now;
 	struct sctp_nets *net;
 	struct sctp_association *asoc;
 	struct sctp_inpcb *t_inp;
+	struct sctp_nonpad_sndrcvinfo *sndrcvninfo;
+	ssize_t sndlen = 0, max_len, local_add_more;
+	ssize_t local_soresv = 0;
+	sctp_assoc_t sinfo_assoc_id;
 	int user_marks_eor;
-	bool create_lock_applied = false;
 	int nagle_applies = 0;
+	int error;
+	int queue_only = 0, queue_only_for_init = 0;
+	int un_sent;
+	int now_filled = 0;
+	unsigned int inqueue_bytes = 0;
+	uint16_t port;
+	uint16_t sinfo_flags;
+	uint16_t sinfo_stream;
+	bool create_lock_applied = false;
+	bool free_cnt_applied = false;
 	bool some_on_control;
 	bool got_all_of_the_send = false;
 	bool hold_tcblock = false;
 	bool non_blocking = false;
-	ssize_t local_soresv = 0;
-	uint16_t port;
-	uint16_t sinfo_flags;
-	sctp_assoc_t sinfo_assoc_id;
 
 	error = 0;
 	net = NULL;
@@ -12516,17 +12515,19 @@ sctp_lower_sosend(struct socket *so,
 	atomic_add_int(&inp->total_sends, 1);
 
 	if (srcv != NULL) {
-		sinfo_flags = srcv->sinfo_flags;
-		sinfo_assoc_id = srcv->sinfo_assoc_id;
+		sndrcvninfo = (struct sctp_nonpad_sndrcvinfo *)srcv;
+		sinfo_assoc_id = sndrcvninfo->sinfo_assoc_id;
+		sinfo_flags = sndrcvninfo->sinfo_flags;
 		if (INVALID_SINFO_FLAG(sinfo_flags) ||
 		    PR_SCTP_INVALID_POLICY(sinfo_flags)) {
 			error = EINVAL;
 			goto out_unlocked;
 		}
-		if (srcv->sinfo_flags != 0) {
+		if (sinfo_flags != 0) {
 			SCTP_STAT_INCR(sctps_sends_with_flags);
 		}
 	} else {
+		sndrcvninfo = NULL;
 		sinfo_flags = inp->def_send.sinfo_flags;
 		sinfo_assoc_id = inp->def_send.sinfo_assoc_id;
 	}
@@ -12544,7 +12545,7 @@ sctp_lower_sosend(struct socket *so,
 	if ((sinfo_flags & SCTP_SENDALL) &&
 	    (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
 		SCTP_INP_RUNLOCK(inp);
-		error = sctp_sendall(inp, uio, top, srcv);
+		error = sctp_sendall(inp, uio, top, sndrcvninfo);
 		top = NULL;
 		goto out_unlocked;
 	}
@@ -12721,11 +12722,11 @@ sctp_lower_sosend(struct socket *so,
 	/* Keep the stcb from being freed under our feet. */
 	atomic_add_int(&asoc->refcnt, 1);
 	free_cnt_applied = true;
-	if (srcv == NULL) {
+	if (sndrcvninfo == NULL) {
 		/* Use a local copy to have a consistent view. */
-		sndrcvninfo = asoc->def_send;
-		srcv = (struct sctp_sndrcvinfo *)&sndrcvninfo;
-		sinfo_flags = srcv->sinfo_flags;
+		sndrcvninfo_buf = asoc->def_send;
+		sndrcvninfo = &sndrcvninfo_buf;
+		sinfo_flags = sndrcvninfo->sinfo_flags;
 		if (flags & MSG_EOR) {
 			sinfo_flags |= SCTP_EOR;
 		}
@@ -12751,18 +12752,19 @@ sctp_lower_sosend(struct socket *so,
 			net = asoc->primary_destination;
 		}
 	}
+	sinfo_stream = sndrcvninfo->sinfo_stream;
 	/* Is the stream no. valid? */
-	if (srcv->sinfo_stream >= asoc->streamoutcnt) {
+	if (sinfo_stream >= asoc->streamoutcnt) {
 		/* Invalid stream number */
 		error = EINVAL;
 		goto out_unlocked;
 	}
-	if ((asoc->strmout[srcv->sinfo_stream].state != SCTP_STREAM_OPEN) &&
-	    (asoc->strmout[srcv->sinfo_stream].state != SCTP_STREAM_OPENING)) {
+	if ((asoc->strmout[sinfo_stream].state != SCTP_STREAM_OPEN) &&
+	    (asoc->strmout[sinfo_stream].state != SCTP_STREAM_OPENING)) {
 		/*
 		 * Can't queue any data while stream reset is underway.
 		 */
-		if (asoc->strmout[srcv->sinfo_stream].state > SCTP_STREAM_OPEN) {
+		if (asoc->strmout[sinfo_stream].state > SCTP_STREAM_OPEN) {
 			error = EAGAIN;
 		} else {
 			error = EINVAL;
@@ -13044,16 +13046,16 @@ skip_preblock:
 		uint32_t sndout;
 
 		if ((asoc->stream_locked) &&
-		    (asoc->stream_locked_on != srcv->sinfo_stream)) {
+		    (asoc->stream_locked_on != sinfo_stream)) {
 			error = EINVAL;
 			goto out;
 		}
-		strm = &asoc->strmout[srcv->sinfo_stream];
+		strm = &asoc->strmout[sinfo_stream];
 		if (strm->last_msg_incomplete == 0) {
 	do_a_copy_in:
 			SCTP_TCB_UNLOCK(stcb);
 			hold_tcblock = false;
-			sp = sctp_copy_it_in(stcb, asoc, srcv, uio, net, max_len, user_marks_eor, &error);
+			sp = sctp_copy_it_in(stcb, asoc, sndrcvninfo, uio, net, max_len, user_marks_eor, &error);
 			SCTP_TCB_LOCK(stcb);
 			hold_tcblock = true;
 			if ((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) ||
@@ -13095,7 +13097,7 @@ skip_preblock:
 				goto out_unlocked;
 			}
 			/* The out streams might be reallocated. */
-			strm = &asoc->strmout[srcv->sinfo_stream];
+			strm = &asoc->strmout[sinfo_stream];
 			if (sp->msg_is_complete) {
 				strm->last_msg_incomplete = 0;
 				asoc->stream_locked = 0;
@@ -13107,7 +13109,7 @@ skip_preblock:
 				strm->last_msg_incomplete = 1;
 				if (asoc->idata_supported == 0) {
 					asoc->stream_locked = 1;
-					asoc->stream_locked_on = srcv->sinfo_stream;
+					asoc->stream_locked_on = sinfo_stream;
 				}
 				sp->sender_all_done = 0;
 			}
@@ -13239,7 +13241,7 @@ skip_preblock:
 				 * This is ugly but we must assure locking
 				 * order
 				 */
-				sctp_prune_prsctp(stcb, asoc, srcv, (int)sndlen);
+				sctp_prune_prsctp(stcb, asoc, sndrcvninfo, (int)sndlen);
 				inqueue_bytes = asoc->total_output_queue_size - (asoc->chunks_on_out_queue * SCTP_DATA_CHUNK_OVERHEAD(stcb));
 				if (SCTP_SB_LIMIT_SND(so) > inqueue_bytes)
 					max_len = SCTP_SB_LIMIT_SND(so) - inqueue_bytes;
@@ -13403,13 +13405,13 @@ skip_preblock:
 		    ("Association was aborted"));
 
 		/* The out streams might be reallocated. */
-		strm = &asoc->strmout[srcv->sinfo_stream];
+		strm = &asoc->strmout[sinfo_stream];
 		if (sp != NULL) {
 			if (sp->msg_is_complete == 0) {
 				strm->last_msg_incomplete = 1;
 				if (asoc->idata_supported == 0) {
 					asoc->stream_locked = 1;
-					asoc->stream_locked_on = srcv->sinfo_stream;
+					asoc->stream_locked_on = sinfo_stream;
 				}
 			} else {
 				sp->sender_all_done = 1;
@@ -13426,7 +13428,7 @@ skip_preblock:
 			got_all_of_the_send = true;
 		}
 	} else {
-		error = sctp_msg_append(stcb, net, top, srcv);
+		error = sctp_msg_append(stcb, net, top, sndrcvninfo);
 		top = NULL;
 		if ((sinfo_flags & SCTP_EOF) != 0) {
 			got_all_of_the_send = true;
diff --git a/sys/netinet/sctp_structs.h b/sys/netinet/sctp_structs.h
index 026e3319dd23..e28c2265589d 100644
--- a/sys/netinet/sctp_structs.h
+++ b/sys/netinet/sctp_structs.h
@@ -129,6 +129,26 @@ struct sctp_mcore_ctrl {
 };
 #endif
 
+/* This struct is here to cut out the compatiabilty
+ * pad that bulks up both the inp and stcb. The non
+ * pad portion MUST stay in complete sync with
+ * sctp_sndrcvinfo... i.e. if sinfo_xxxx is added
+ * this must be done here too.
+ */
+struct sctp_nonpad_sndrcvinfo {
+	uint16_t sinfo_stream;
+	uint16_t sinfo_ssn;
+	uint16_t sinfo_flags;
+	uint32_t sinfo_ppid;
+	uint32_t sinfo_context;
+	uint32_t sinfo_timetolive;
+	uint32_t sinfo_tsn;
+	uint32_t sinfo_cumtsn;
+	sctp_assoc_t sinfo_assoc_id;
+	uint16_t sinfo_keynumber;
+	uint16_t sinfo_keynumber_valid;
+};
+
 struct sctp_iterator {
 	TAILQ_ENTRY(sctp_iterator) sctp_nxt_itr;
 	struct vnet *vn;
@@ -159,7 +179,7 @@ TAILQ_HEAD(sctpiterators, sctp_iterator);
 struct sctp_copy_all {
 	struct sctp_inpcb *inp;	/* ep */
 	struct mbuf *m;
-	struct sctp_sndrcvinfo sndrcv;
+	struct sctp_nonpad_sndrcvinfo sndrcv;
 	ssize_t sndlen;
 	int cnt_sent;
 	int cnt_failed;
@@ -675,26 +695,6 @@ struct sctp_fs_spec_log {
 	uint8_t decr;
 };
 
-/* This struct is here to cut out the compatiabilty
- * pad that bulks up both the inp and stcb. The non
- * pad portion MUST stay in complete sync with
- * sctp_sndrcvinfo... i.e. if sinfo_xxxx is added
- * this must be done here too.
- */
-struct sctp_nonpad_sndrcvinfo {
-	uint16_t sinfo_stream;
-	uint16_t sinfo_ssn;
-	uint16_t sinfo_flags;
-	uint32_t sinfo_ppid;
-	uint32_t sinfo_context;
-	uint32_t sinfo_timetolive;
-	uint32_t sinfo_tsn;
-	uint32_t sinfo_cumtsn;
-	sctp_assoc_t sinfo_assoc_id;
-	uint16_t sinfo_keynumber;
-	uint16_t sinfo_keynumber_valid;
-};
-
 /*
  * JRS - Structure to hold function pointers to the functions responsible
  * for congestion control.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202302012318.311NIlIZ047838>