From nobody Sat Aug 03 23:13:05 2024 X-Original-To: dev-commits-src-all@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 4Wbz5G38xjz5RWp9; Sat, 03 Aug 2024 23:13:06 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Wbz5G1X0Sz4QqW; Sat, 3 Aug 2024 23:13:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722726786; 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=yswoB8My7ipqjBDVnfx8sdDQJlQ8mCV+HEu+HSl57OY=; b=uwLZq3ndgM8xjVOAEgq8Ha03AnSkOA4gN8F6HfjHHDBNN1BJd6TrUvTLp5O2qG/cZa22ZM 04r97fxAsnezrV/2JbypigU+ijJi+fhorR/MKz81HhQooSy+G7RUXU7F1j9KCmNHsVUtAt P9/coGc40HLk/lUHeojOq9wdZz22OJ+7lRPS3CJ+pQ2M3v1VzF9XwjA3KbDvtpFAwGIuoG /MTJK7cwNnNvcNVa4ZrRjhwf5lSB+Upw337LKPgqkXkr9tR7t4P7Jb5OsmZ3+U2wQHHsHA aLeuHW14o0+ObJicagYfpI+rFsF/nHqy1FMEX47839gcdUQk3FPgLDjnAcfNSg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1722726786; a=rsa-sha256; cv=none; b=BXv1cgRjyAZDH3uVxH17IGrjoubguvGgORJ07EOHG1+5UhKkihAyaGWEsYlM3qO6GYB+hb v0fcgdlp2KOTEJp2nsu+m/kcHMycwGGn9w7b4tyHN71S4VTP++rJCntHwPMm8KtoeGKygi 1gYWL55PYYXzMtP0eRZjInFiBgm6lBhMnBa/i7mTz1lNNDUliMCo+ARlkiXulDvAKh2OS6 OCVwgIKMgWliOhJd3OvRsjlWgySD2RNh0lGsVYsoxg3Qj9xQxXN7KCi9Q2aRb0RKwS3+7R hDxeukKYmjHHtgs8678Pclmlj7efSRsXJV0KgVefl442zJmBsHRnAZGywChu6Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722726786; 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=yswoB8My7ipqjBDVnfx8sdDQJlQ8mCV+HEu+HSl57OY=; b=Y34Y87yk6U3smSUvYcRb6FaWQgF//DY8iZULz1WE9zRPVT2ZUVACv2b9O8ks9/SiI2/G1H Mf7eppIyxzdvyzQ6Xv9xm1i46QgLmIIDAo1l512CT6DFjaW3L/KZqbBF//UD/zHv+gfzvB aagMk7zJ3AngqHZvlaLY/F7pVpO3xXskV2+IV/EBfgAXK4iGva2mk3kbBjwWkGMWFaAc8w G8GHOXSh0P9vlvrlz6p2jToH7u4/A0HJq9QMC//UB1Pt292mZU2AuDqDwdNUm5JV0rTYiT jJqj6lPfyzm+6vadOhOnNGGnjC78ULqLnJ/hxgc2bmP7/WiF85GwD7KriidUjQ== 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 4Wbz5G0SLYzX4j; Sat, 3 Aug 2024 23:13:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 473ND549012621; Sat, 3 Aug 2024 23:13:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 473ND5f6012618; Sat, 3 Aug 2024 23:13:05 GMT (envelope-from git) Date: Sat, 3 Aug 2024 23:13:05 GMT Message-Id: <202408032313.473ND5f6012618@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: 25d9ade9aa50 - stable/14 - tcp: implement challenge ACK throttling for the base stack List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/14 X-Git-Reftype: branch X-Git-Commit: 25d9ade9aa50b22eb5fb0b6aaabbc808fb076c18 Auto-Submitted: auto-generated The branch stable/14 has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=25d9ade9aa50b22eb5fb0b6aaabbc808fb076c18 commit 25d9ade9aa50b22eb5fb0b6aaabbc808fb076c18 Author: Michael Tuexen AuthorDate: 2024-07-25 11:54:52 +0000 Commit: Michael Tuexen CommitDate: 2024-08-03 23:12:28 +0000 tcp: implement challenge ACK throttling for the base stack Implement ACK throttling of challenge ACKs as described in RFC 5961. Reviewed by: Peter Lei, rscheff, cc Sponsored by: Netflix, Inc. Differential Revision: https://reviews.freebsd.org/D46066 (cherry picked from commit 40299c55a05ff008102e24269d5f2d7fa7b6842d) --- sys/netinet/tcp_input.c | 15 +++------------ sys/netinet/tcp_subr.c | 39 +++++++++++++++++++++++++++++++++++++++ sys/netinet/tcp_var.h | 6 ++++++ 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c index cb72ddbef947..500d208b7756 100644 --- a/sys/netinet/tcp_input.c +++ b/sys/netinet/tcp_input.c @@ -2187,10 +2187,7 @@ tcp_do_segment(struct tcpcb *tp, struct mbuf *m, struct tcphdr *th, } } else { TCPSTAT_INC(tcps_badrst); - /* Send challenge ACK. */ - tcp_respond(tp, mtod(m, void *), th, m, - tp->rcv_nxt, tp->snd_nxt, TH_ACK); - tp->last_ack_sent = tp->rcv_nxt; + tcp_send_challenge_ack(tp, th, m); m = NULL; } } @@ -2212,10 +2209,7 @@ tcp_do_segment(struct tcpcb *tp, struct mbuf *m, struct tcphdr *th, rstreason = BANDLIM_UNLIMITED; } else { tcp_ecn_input_syn_sent(tp, thflags, iptos); - /* Send challenge ACK. */ - tcp_respond(tp, mtod(m, void *), th, m, tp->rcv_nxt, - tp->snd_nxt, TH_ACK); - tp->last_ack_sent = tp->rcv_nxt; + tcp_send_challenge_ack(tp, th, m); m = NULL; } goto drop; @@ -2453,10 +2447,7 @@ tcp_do_segment(struct tcpcb *tp, struct mbuf *m, struct tcphdr *th, TCPSTAT_INC(tcps_rcvghostack); else TCPSTAT_INC(tcps_rcvacktooold); - /* Send a challenge ACK. */ - tcp_respond(tp, mtod(m, void *), th, m, - tp->rcv_nxt, tp->snd_nxt, TH_ACK); - tp->last_ack_sent = tp->rcv_nxt; + tcp_send_challenge_ack(tp, th, m); m = NULL; goto drop; } diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index 9fc744c42e0c..e2b120223bc0 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -2222,6 +2222,45 @@ tcp_respond(struct tcpcb *tp, void *ipgen, struct tcphdr *th, struct mbuf *m, lgb->tlb_errno = output_ret; } +/* + * Send a challenge ack (no data, no SACK option), but not more than + * tcp_ack_war_cnt per tcp_ack_war_time_window (per TCP connection). + */ +void +tcp_send_challenge_ack(struct tcpcb *tp, struct tcphdr *th, struct mbuf *m) +{ + sbintime_t now; + bool send_challenge_ack; + + if (tcp_ack_war_time_window == 0 || tcp_ack_war_cnt == 0) { + /* ACK war protection is disabled. */ + send_challenge_ack = true; + } else { + /* Start new epoch, if the previous one is already over. */ + now = getsbinuptime(); + if (tp->t_challenge_ack_end < now) { + tp->t_challenge_ack_cnt = 0; + tp->t_challenge_ack_end = now + + tcp_ack_war_time_window * SBT_1MS; + } + /* + * Send a challenge ACK, if less than tcp_ack_war_cnt have been + * sent in the current epoch. + */ + if (tp->t_challenge_ack_cnt < tcp_ack_war_cnt) { + send_challenge_ack = true; + tp->t_challenge_ack_cnt++; + } else { + send_challenge_ack = false; + } + } + if (send_challenge_ack) { + tcp_respond(tp, mtod(m, void *), th, m, tp->rcv_nxt, + tp->snd_nxt, TH_ACK); + tp->last_ack_sent = tp->rcv_nxt; + } +} + /* * Create a new TCP control block, making an empty reassembly queue and hooking * it to the argument protocol control block. The `inp' parameter must have diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h index e7cccd60a95e..f41fdaca13ac 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -461,6 +461,11 @@ struct tcpcb { /* TCP Fast Open */ uint8_t t_tfo_client_cookie_len; /* TFO client cookie length */ uint32_t t_end_info_status; /* Status flag of end info */ + sbintime_t t_challenge_ack_end; /* End of the challenge ack epoch */ + uint32_t t_challenge_ack_cnt; /* Number of challenge ACKs sent in + * current epoch + */ + unsigned int *t_tfo_pending; /* TFO server pending counter */ union { uint8_t client[TCP_FASTOPEN_MAX_COOKIE_LEN]; @@ -1469,6 +1474,7 @@ int tcp_default_output(struct tcpcb *); void tcp_state_change(struct tcpcb *, int); void tcp_respond(struct tcpcb *, void *, struct tcphdr *, struct mbuf *, tcp_seq, tcp_seq, uint16_t); +void tcp_send_challenge_ack(struct tcpcb *, struct tcphdr *, struct mbuf *); bool tcp_twcheck(struct inpcb *, struct tcpopt *, struct tcphdr *, struct mbuf *, int); void tcp_setpersist(struct tcpcb *);