From nobody Wed Jun 08 20:36:01 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 39E13857985; Wed, 8 Jun 2022 20:36:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LJJsG05LSz3pXb; Wed, 8 Jun 2022 20:36:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1654720562; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=wYbQQ0qVlGzhD7JYXPqJQLhRIrQqAmYak67BeFx7dfI=; b=WsmRo3W2XDISwxe4LPW0E8JzkFxPl9up+vL2LCK9XMY4AcmImjlHB7n2yHXs4bCocOhq3i XBXv3FanyhU/IOClNGoUuXH2sWkTw/+3AgzaTWS8DHyxm04HnfnSVx+H7EADpSCXmV/+er 7NuQDWHhgSZtvmpXqmECKMt1a1XnJzDG+VcglPkqt5HbFYiJnyQPk8fqnala1yrHQ1fGJ0 R34qVnm3Uqex3c5/zvQYGLT3VvxD0ze1TMYGB9MmBOuvN136OlK9x3rT9xUt57YFjX16vB 00795GrFnLn6+o6OuFqNPiFR0CcNbpRTdJC0Y2ElHumaIj+VISHIuQtK3vWRGg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D851916AA4; Wed, 8 Jun 2022 20:36:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 258Ka1Vf073591; Wed, 8 Jun 2022 20:36:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 258Ka1IT073590; Wed, 8 Jun 2022 20:36:01 GMT (envelope-from git) Date: Wed, 8 Jun 2022 20:36:01 GMT Message-Id: <202206082036.258Ka1IT073590@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Michael Tuexen Subject: git: ad6ae52d1c21 - main - sctp: cleanup, no functional change List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: tuexen X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ad6ae52d1c2144b6bb6bca8edc485f3a97de2f4b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1654720562; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=wYbQQ0qVlGzhD7JYXPqJQLhRIrQqAmYak67BeFx7dfI=; b=Q81FLKZrApTtfB+uhehcpin4ZnlAOuRcumk+WKLkAeBjyz89wehOiIR4+4PUZMkS0HAZo5 lucc60ukrdJAr5FnHeIeC3Coblo2cgw+j/Yu9KRMi4IMq3+BXnGQHFBeMPyEVMD7zljjgA lA5SSecqM9ADiLra/b/2FsC9ktUlV5IoGmcq5Ddy16BCbCqoLZFo1xWy3czr+3AI/+dl+M LY/p/6LFaqDRWF5N/tzXgm6g2oupcR/iszoDTjOhtrHy48adugsBc+2fVF17SL1VmsWg8V 5B7JDL+stThOTCDmUnwDGetzTni4oOf+v5DnJOfXLP0UAtizeDGHD54K7WWGIg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1654720562; a=rsa-sha256; cv=none; b=hMSnVSaxanBEjXVvnEd/3PNiLfNUv3k+QymKSArkU8i0000Z3pzQggGjx+t5iK43u5sM1J clqSFC9AE5L3ZQaswPrZnMuMki6GvA3yrizcndesYLlA4riabGzwTljdgPVUndb/ka6uqz TmKMVOzfYmjpIWp/XHDSR0FKgcVmk27MODnn4VAu1lfyyVu118XaM8YkshtOmXlYyN+lVh bO2zTAsOEJhbF4fSNBurZsQ+usVHHSHmSV/6klhNal72oo68pvA6GLBRH6wdPbgcOlXR6H 2hS2pe3X1b/xWJrLvPbp035KUhQ/igKPZT6iXTDQGiLgaD5RXIdzWRJRtc26Wg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=ad6ae52d1c2144b6bb6bca8edc485f3a97de2f4b commit ad6ae52d1c2144b6bb6bca8edc485f3a97de2f4b Author: Michael Tuexen AuthorDate: 2022-06-08 20:35:14 +0000 Commit: Michael Tuexen CommitDate: 2022-06-08 20:35:14 +0000 sctp: cleanup, no functional change MFC after: 3 days --- 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 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.