aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Tuexen <tuexen@FreeBSD.org>2022-06-08 20:35:14 +0000
committerMichael Tuexen <tuexen@FreeBSD.org>2022-06-08 20:35:14 +0000
commitad6ae52d1c2144b6bb6bca8edc485f3a97de2f4b (patch)
tree6fdfc2e88c9030fab19a2353ee9f22664ed6c952
parent9f009e066f088e2c31442db31d2a85001040abfe (diff)
downloadsrc-ad6ae52d1c2144b6bb6bca8edc485f3a97de2f4b.tar.gz
src-ad6ae52d1c2144b6bb6bca8edc485f3a97de2f4b.zip
sctp: cleanup, no functional change
MFC after: 3 days
-rw-r--r--sys/netinet/sctp_output.c134
-rw-r--r--sys/netinet/sctp_structs.h42
2 files changed, 89 insertions, 87 deletions
diff --git a/sys/netinet/sctp_output.c b/sys/netinet/sctp_output.c
index dfeed2dec563..0a3827899888 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));
}
@@ -12278,7 +12278,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,
@@ -12363,25 +12363,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;
@@ -12394,15 +12391,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);
}
@@ -12413,38 +12412,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;
@@ -12518,17 +12517,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;
}
@@ -12546,7 +12547,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;
}
@@ -12723,11 +12724,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;
}
@@ -12753,18 +12754,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;
@@ -13046,16 +13048,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) ||
@@ -13097,7 +13099,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;
@@ -13109,7 +13111,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;
}
@@ -13241,7 +13243,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;
@@ -13405,13 +13407,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;
@@ -13428,7 +13430,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.