From nobody Tue Feb 22 23:59:36 2022 X-Original-To: dev-commits-src-branches@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 CAC6D19D04FF; Tue, 22 Feb 2022 23:59:36 +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 4K3GP45K2Sz4Tgk; Tue, 22 Feb 2022 23:59:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645574376; 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=rWdSjZANNbLqMzamL4xmOjXnXnYid/VqLOmfzGrdqCI=; b=b/kt/3T+0ra5xQKWCBnSpDgK/BW7fvWxfX+M2NUbTmNaT//kp1RwSkWYpnGzfcAqn/m8Dc ZQGw7KnL8K2xj7dp/fod09UrPtNlukV1EFRxG6JhLOnk33+woYympqd5unmnmQGSR9m4aF /c/AfJtzPchRKo79DmJj89e2ZGVmQ44BYFnyGWNT4J7fSZyCq+Ylz2sZHvSduAgjnWvwPV T+QhAq9lau3R86C+BuN1bSV5ZdL3c8GNoRWa+3wzUvJc+Rq9uxRQH5LpbPHqB2Msa7iFE6 1BKUpEZcjeUlbmwamiv1p6AaSbV3GC4D1TrmnzuY09BBE40KRLLbZ1uIXMgV6A== 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 95F645CF8; Tue, 22 Feb 2022 23:59:36 +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 21MNxa1p052143; Tue, 22 Feb 2022 23:59:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21MNxaj2052142; Tue, 22 Feb 2022 23:59:36 GMT (envelope-from git) Date: Tue, 22 Feb 2022 23:59:36 GMT Message-Id: <202202222359.21MNxaj2052142@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Michael Tuexen Subject: git: 81a1bfac592b - stable/13 - sctp: improve sctp_pathmtu_adjustment() List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 81a1bfac592bc2ca29788a5b8cc6e5ff1e86fb9d Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645574376; 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=rWdSjZANNbLqMzamL4xmOjXnXnYid/VqLOmfzGrdqCI=; b=ZnrJHVaHo0ZIHQkkBHvkK1JM85AjxhiSesE+YlEPBkuOx3dfbzzsepP9f2NYTfA/CEfLEf hzW7TSjKGjdcQcgDRl2IbkbpbazWhBVu0DF4S54rOX8xp85cr84BQKPhOi1i2NB+KI/pp/ XXhFgQYmrp9sC0KJBwFVrTakuEOiHmWWYRYAjHqgYsrHCKkHpgDJKMI1utBUvdfc31zH7B CK9hEU1MIPmNhG6QG1+6fhLMMp/NkRUwg9ruGW6Kqc0fSgIbTD5ZNVUzki3D7eqdbIt8x5 spG9PSr7yCNSFwlGW6u1uWXEa8xTMqIUFpnJ7ksFHMppSLlxxU25xDsGZUl+7Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1645574376; a=rsa-sha256; cv=none; b=Qevlu3ERpoE5iMiB9FMEPNfOnGdBKYk1bZ3QtjWH30qVQt5c/KjA1aIwUBhPhYkR06Q0iN TASY05/g7qlHCHbbA02Di9Y50ZnNybYceGf8xGEPlyXfBMc7ETeiOQjCtrwKILwg7yA0R2 yigikTfR4yJPK5WquFmm39WVxFFvALfDs2WtaII2adZEzVbG0kOxobALPAwd8TmFkVVFvm KfQ3ao020yBdaJAEBkzmT0H1lrrgjAP/o4J4lOy0pYs+nchPDHHikUCI+13CarL8zuTYrx zuNj4xcQeUkkgOW5RenrzhQzOzZwndgrKQCPEuX8+qXNclpmeV51ysTCe2Y64Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=81a1bfac592bc2ca29788a5b8cc6e5ff1e86fb9d commit 81a1bfac592bc2ca29788a5b8cc6e5ff1e86fb9d Author: Michael Tuexen AuthorDate: 2021-12-30 14:16:05 +0000 Commit: Michael Tuexen CommitDate: 2022-02-22 23:58:06 +0000 sctp: improve sctp_pathmtu_adjustment() Allow the resending of DATA chunks to be controlled by the caller, which allows retiring sctp_mtu_size_reset() in a separate commit. Also improve the computaion of the overhead and use 32-bit integers consistently. Thanks to Timo Voelker for pointing me to the code. (cherry picked from commit 2de2ae331be2504d1038b2124e7d44f23aa70405) --- sys/netinet/sctp_input.c | 6 ++--- sys/netinet/sctp_pcb.c | 2 +- sys/netinet/sctp_usrreq.c | 62 ++++++++++++++++++++++++++++----------------- sys/netinet/sctp_var.h | 2 +- sys/netinet6/sctp6_usrreq.c | 2 +- 5 files changed, 45 insertions(+), 29 deletions(-) diff --git a/sys/netinet/sctp_input.c b/sys/netinet/sctp_input.c index f707bc1de11e..f4a698b3a775 100644 --- a/sys/netinet/sctp_input.c +++ b/sys/netinet/sctp_input.c @@ -5291,7 +5291,7 @@ sctp_common_input_processing(struct mbuf **mm, int iphlen, int offset, int lengt /* UDP encapsulation turned on. */ net->mtu -= sizeof(struct udphdr); if (stcb->asoc.smallest_mtu > net->mtu) { - sctp_pathmtu_adjustment(stcb, net->mtu); + sctp_pathmtu_adjustment(stcb, net->mtu, true); } } else if (port == 0) { /* UDP encapsulation turned off. */ @@ -5331,7 +5331,7 @@ sctp_common_input_processing(struct mbuf **mm, int iphlen, int offset, int lengt /* UDP encapsulation turned on. */ net->mtu -= sizeof(struct udphdr); if (stcb->asoc.smallest_mtu > net->mtu) { - sctp_pathmtu_adjustment(stcb, net->mtu); + sctp_pathmtu_adjustment(stcb, net->mtu, true); } } else if (port == 0) { /* UDP encapsulation turned off. */ @@ -5426,7 +5426,7 @@ sctp_common_input_processing(struct mbuf **mm, int iphlen, int offset, int lengt /* UDP encapsulation turned on. */ net->mtu -= sizeof(struct udphdr); if (stcb->asoc.smallest_mtu > net->mtu) { - sctp_pathmtu_adjustment(stcb, net->mtu); + sctp_pathmtu_adjustment(stcb, net->mtu, true); } } else if (port == 0) { /* UDP encapsulation turned off. */ diff --git a/sys/netinet/sctp_pcb.c b/sys/netinet/sctp_pcb.c index 176a35220688..23bef0ebaf05 100644 --- a/sys/netinet/sctp_pcb.c +++ b/sys/netinet/sctp_pcb.c @@ -4026,7 +4026,7 @@ sctp_add_remote_addr(struct sctp_tcb *stcb, struct sockaddr *newaddr, stcb->asoc.smallest_mtu = net->mtu; } if (stcb->asoc.smallest_mtu > net->mtu) { - sctp_pathmtu_adjustment(stcb, net->mtu); + sctp_pathmtu_adjustment(stcb, net->mtu, true); } #ifdef INET6 if (newaddr->sa_family == AF_INET6) { diff --git a/sys/netinet/sctp_usrreq.c b/sys/netinet/sctp_usrreq.c index a49bebc7edec..a9ca2d063202 100644 --- a/sys/netinet/sctp_usrreq.c +++ b/sys/netinet/sctp_usrreq.c @@ -104,35 +104,51 @@ VNET_SYSUNINIT(sctp, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, sctp_finish, NULL); #endif void -sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz) +sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint32_t mtu, bool resend) { + struct sctp_association *asoc; struct sctp_tmit_chunk *chk; - uint16_t overhead; - - /* Adjust that too */ - stcb->asoc.smallest_mtu = nxtsz; - /* now off to subtract IP_DF flag if needed */ - overhead = IP_HDR_SIZE + sizeof(struct sctphdr); - if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) { - overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id); + uint32_t overhead; + + asoc = &stcb->asoc; + KASSERT(mtu < asoc->smallest_mtu, + ("Currently only reducing association MTU %u supported (MTU %u)", + asoc->smallest_mtu, mtu)); + asoc->smallest_mtu = mtu; + if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) { + overhead = SCTP_MIN_OVERHEAD; + } else { + overhead = SCTP_MIN_V4_OVERHEAD; + } + if (asoc->idata_supported) { + if (sctp_auth_is_required_chunk(SCTP_IDATA, asoc->peer_auth_chunks)) { + overhead += sctp_get_auth_chunk_len(asoc->peer_hmac_id); + } + } else { + if (sctp_auth_is_required_chunk(SCTP_DATA, asoc->peer_auth_chunks)) { + overhead += sctp_get_auth_chunk_len(asoc->peer_hmac_id); + } } - TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) { - if ((chk->send_size + overhead) > nxtsz) { + KASSERT(overhead % 4 == 0, + ("overhead (%u) not a multiple of 4", overhead)); + TAILQ_FOREACH(chk, &asoc->send_queue, sctp_next) { + if (((uint32_t)chk->send_size + overhead) > mtu) { chk->flags |= CHUNK_FLAGS_FRAGMENT_OK; } } - TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) { - if ((chk->send_size + overhead) > nxtsz) { - /* - * For this guy we also mark for immediate resend - * since we sent to big of chunk - */ + TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) { + if (((uint32_t)chk->send_size + overhead) > mtu) { chk->flags |= CHUNK_FLAGS_FRAGMENT_OK; - if (chk->sent < SCTP_DATAGRAM_RESEND) { + if (resend && chk->sent < SCTP_DATAGRAM_RESEND) { + /* + * If requested, mark the chunk for + * immediate resend, since we sent it being + * too big. + */ sctp_flight_size_decrease(chk); sctp_total_flight_decrease(stcb, chk); chk->sent = SCTP_DATAGRAM_RESEND; - sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt); + sctp_ucount_incr(asoc->sent_queue_retran_cnt); chk->rec.data.doing_fast_retransmit = 0; if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU, @@ -141,7 +157,7 @@ sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz) (uint32_t)(uintptr_t)chk->whoTo, chk->rec.data.tsn); } - /* Clear any time so NO RTT is being done */ + /* Clear any time, so NO RTT is being done. */ if (chk->do_rtt == 1) { chk->do_rtt = 0; chk->whoTo->rto_needed = 1; @@ -229,7 +245,7 @@ sctp_notify(struct sctp_inpcb *inp, } /* Update the association MTU */ if (stcb->asoc.smallest_mtu > next_mtu) { - sctp_pathmtu_adjustment(stcb, next_mtu); + sctp_pathmtu_adjustment(stcb, next_mtu, true); } /* Finally, start the PMTU timer if it was running before. */ if (timer_stopped) { @@ -5363,7 +5379,7 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, break; } if (net->mtu < stcb->asoc.smallest_mtu) { - sctp_pathmtu_adjustment(stcb, net->mtu); + sctp_pathmtu_adjustment(stcb, net->mtu, true); } } } @@ -5507,7 +5523,7 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, break; } if (net->mtu < stcb->asoc.smallest_mtu) { - sctp_pathmtu_adjustment(stcb, net->mtu); + sctp_pathmtu_adjustment(stcb, net->mtu, true); } } } diff --git a/sys/netinet/sctp_var.h b/sys/netinet/sctp_var.h index ed01de7d7014..a18dbb5e66e2 100644 --- a/sys/netinet/sctp_var.h +++ b/sys/netinet/sctp_var.h @@ -328,7 +328,7 @@ int sctp_ctloutput(struct socket *, struct sockopt *); void sctp_input_with_port(struct mbuf *, int, uint16_t); int sctp_input(struct mbuf **, int *, int); #endif -void sctp_pathmtu_adjustment(struct sctp_tcb *, uint16_t); +void sctp_pathmtu_adjustment(struct sctp_tcb *, uint32_t, bool); void sctp_drain(void); void sctp_init(void); void diff --git a/sys/netinet6/sctp6_usrreq.c b/sys/netinet6/sctp6_usrreq.c index 516107caf408..361bc4a18a2f 100644 --- a/sys/netinet6/sctp6_usrreq.c +++ b/sys/netinet6/sctp6_usrreq.c @@ -233,7 +233,7 @@ sctp6_notify(struct sctp_inpcb *inp, } /* Update the association MTU */ if (stcb->asoc.smallest_mtu > next_mtu) { - sctp_pathmtu_adjustment(stcb, next_mtu); + sctp_pathmtu_adjustment(stcb, next_mtu, true); } /* Finally, start the PMTU timer if it was running before. */ if (timer_stopped) {