From nobody Thu Sep 25 18:24:45 2025 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 4cXhvf1qwfz68Q2H; Thu, 25 Sep 2025 18:24:46 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cXhvf0nTwz3sNr; Thu, 25 Sep 2025 18:24:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758824686; 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=MUf+Gd5yRG71BV/fIk8QWiL0FWKJBNQvJCtVKeYTkx0=; b=ezb3D6ePExaKancHd/bd7troHG5diVOUWKIy3wabhOZKuBC28t2Na6TBrbKjU0UypEJIRt CHW3ZJeeszL6LbdCfTk5cltN34ANakNUpeOi2n+XkDIfoXL3qO4C3VR592GlOaO2Evsd7V hgAk4+0/HYTh+HN553HgiecqqgSPhUR1aj255j0ROI03uI7YY+vdhP9ycfGvxzv2VXh6s6 2BRaGeFQ6dX/702x0IgLuiRP9c5G6/nU/eNdTEGwH0i336aWMj9DS7qQES0dN1ijgtsouI lPuPW7cI2Mxn46xXu/Qg/VO5JH7KvwaQoCCx44orERQq1o6D2fS13BVkz56J/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758824686; 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=MUf+Gd5yRG71BV/fIk8QWiL0FWKJBNQvJCtVKeYTkx0=; b=aSPqHH35MrAFyxM4iV6LLjqkgI9dXc3ik/ASCZLYjiSoLRCxUglq1UkZgcaVlGGc+8IZMq xihpQMteihA1qw+NJnw4SHHt/vxoRnu0eVBBJHrddTKy2+iLZ3Tb21aqCSGSP7gl4juKP6 Mhv9dXQdZptmeGCwZWeUk+uhJPlwYSnE99W3v3YQXxbuij9McCtRVC0ao/eJP1HI2sutt3 5bePhf3jnEq7044ponP/7l6UI7hQvVZqlMd4qLsUs9v/3cG6+bGfWWF4VMNMuUKrsAE42w hNSvRMR8p/uGbss8Oan6u2w9gh91TaZ6JlEyHHdIAH1G5/PcD7KnpZL7KeFlUg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1758824686; a=rsa-sha256; cv=none; b=Qf2734oszPBRC+n7IDePxFSY8LGqUjfKxsiVwEvzNgypofQfxikUzyppce9p59vRVy638d D5ptvKc/FpWx4GM5dK5ET67pW4V0No+aN2LSJeeHEuW3wJfocgbUj/XaRShZUCyTJwf57A 5k83N7Kov/zDbAisSvkiTFqGDG8osiruQRRPow0sK8G1IHdaqu3iFryrE7vK2CLqy13Nk4 RGkXcCpgIZOh91h+4bRUGxtnjFrHaJEneQmp/IXcPaanC+r0jJgy9LKGrUbtlTXbt1D2zt 3e9LcUfYYyYjP0KRtipGXU69R+qU8Wjkxtbdm5Hm+VdNfZp5XkpG86DfAKcJhg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4cXhvd6ZGFz1RlB; Thu, 25 Sep 2025 18:24:45 +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 58PIOjvM047611; Thu, 25 Sep 2025 18:24:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58PIOjDq047609; Thu, 25 Sep 2025 18:24:45 GMT (envelope-from git) Date: Thu, 25 Sep 2025 18:24:45 GMT Message-Id: <202509251824.58PIOjDq047609@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: db37256ce543 - main - tcp: refactor tcp_send_challenge_ack() 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/main X-Git-Reftype: branch X-Git-Commit: db37256ce5437e6c667a537afff0fd9f59576514 Auto-Submitted: auto-generated The branch main has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=db37256ce5437e6c667a537afff0fd9f59576514 commit db37256ce5437e6c667a537afff0fd9f59576514 Author: Michael Tuexen AuthorDate: 2025-09-25 01:40:33 +0000 Commit: Michael Tuexen CommitDate: 2025-09-25 01:40:33 +0000 tcp: refactor tcp_send_challenge_ack() Refactor tcp_send_challenge_ack() such that the logic checking whether a challenge ACK is sent or not is available in the separate function tcp_challenge_ack_check(). This new function will also be used for sending challenge ACKs in the SYN-cache code, which will be added in upcoming commits. No functional change intended. Reviewed by: cc, Nick Banks, Peter Lei MFC after: 3 days Sponsored by: Netflix, Inc. Differential Revision: https://reviews.freebsd.org/D52717 --- sys/netinet/tcp_subr.c | 42 +++++++++++++++++++++++++++--------------- sys/netinet/tcp_var.h | 1 + 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index cc83a21773a8..c817c79881d6 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -2148,14 +2148,16 @@ tcp_respond(struct tcpcb *tp, void *ipgen, struct tcphdr *th, struct mbuf *m, } /* - * Send a challenge ack (no data, no SACK option), but not more than - * V_tcp_ack_war_cnt per V_tcp_ack_war_time_window (per TCP connection). + * Check that no more than V_tcp_ack_war_cnt per V_tcp_ack_war_time_window + * are sent. *epoch_end is the end of the current epoch and is updated, if the + * current epoch ended in the past. *ack_cnt is the counter used during the + * current epoch. It might be reset and incremented. + * The function returns true if a challenge ACK should be sent. */ -void -tcp_send_challenge_ack(struct tcpcb *tp, struct tcphdr *th, struct mbuf *m) +bool +tcp_challenge_ack_check(sbintime_t *epoch_end, uint32_t *ack_cnt) { sbintime_t now; - bool send_challenge_ack; /* * The sending of a challenge ACK could be triggered by a blind attacker @@ -2164,29 +2166,39 @@ tcp_send_challenge_ack(struct tcpcb *tp, struct tcphdr *th, struct mbuf *m) * would have guessed wrongly. */ (void)badport_bandlim(BANDLIM_TCP_RST); + if (V_tcp_ack_war_time_window == 0 || V_tcp_ack_war_cnt == 0) { /* ACK war protection is disabled. */ - send_challenge_ack = true; + return (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 + - V_tcp_ack_war_time_window * SBT_1MS; + if (*epoch_end < now) { + *ack_cnt = 0; + *epoch_end = now + V_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 < V_tcp_ack_war_cnt) { - send_challenge_ack = true; - tp->t_challenge_ack_cnt++; + if (*ack_cnt < V_tcp_ack_war_cnt) { + (*ack_cnt)++; + return (true); } else { - send_challenge_ack = false; + return (false); } } - if (send_challenge_ack) { +} + +/* + * Send a challenge ack (no data, no SACK option), but not more than + * V_tcp_ack_war_cnt per V_tcp_ack_war_time_window (per TCP connection). + */ +void +tcp_send_challenge_ack(struct tcpcb *tp, struct tcphdr *th, struct mbuf *m) +{ + if (tcp_challenge_ack_check(&tp->t_challenge_ack_end, + &tp->t_challenge_ack_cnt)) { tcp_respond(tp, mtod(m, void *), th, m, tp->rcv_nxt, tp->snd_nxt, TH_ACK); tp->last_ack_sent = tp->rcv_nxt; diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h index 53856bae9a66..c3be95c80798 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -1462,6 +1462,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); +bool tcp_challenge_ack_check(sbintime_t *, uint32_t *); void tcp_send_challenge_ack(struct tcpcb *, struct tcphdr *, struct mbuf *); bool tcp_twcheck(struct inpcb *, struct tcpopt *, struct tcphdr *, struct mbuf *, int);