From nobody Thu Dec 18 14:24:57 2025 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DCB8EEC5 for ; Mon, 24 Mar 2025 13:18:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742822311; cv=none; b=jRdxh0K9otAsxGsZBQ5AJOUbSxyQ7jZAk31cFegIj8Em8mzKfnqk1reKk310Ayt4+D4clqTPtqJb/wwtxfY34+SoAJrY4J6C7CFAqXtAlQdybiua51O5uWmY9+HZ1k8VA/Mg+y3a3JFeh4B9CiP4vSH+y2a+ky2YKIv1I1DzA0Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742822311; c=relaxed/simple; bh=faIuof2bnzW67oXVuBrYIpaMR6d/9J3/MBt7/pgmqUc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=NfRUPI4SVysN5BWpzGcGHKkxMk9L26E3vwBwD4g0h5i+rIkSQyZA1iPrcEsdafgx2LExrrzuKjdlvkIm0U0o8cwhXK/kMreiSnqc+yPTQWvTniQluuSliLRO5CRdp060neYx9sC3kkLsN5XpuskRfHErX5zdHvG8G5HHdWwZzmw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=R3W4Emdm; arc=none smtp.client-ip=91.218.175.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="R3W4Emdm" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1742822305; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=arVVZeeqZTaqIGfn9u6dowfrXYyiC4MWEKz0N9ovA/8=; b=R3W4Emdmc9Sid1dh2oAh9Ifw1p9FDGceIqGUczTsswwsFTYpBgK2yjpCjMWXGQTVM1aWSO 5Oa2zAoGW1LdhqqmVuyDQYgcOutADGJTzLhsHMVgqkHE1PZEW4cr42HntikXmkU4iLX65+ tjDyEuOhJDo6TYBHG1kbRvJtoWLJX+s= From: Jiayuan Chen To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, edumazet@google.com, kuniyu@amazon.com, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, dsahern@kernel.org, ncardwell@google.com, mrpre@163.com, Jiayuan Chen Subject: [PATCH net-next v1] tcp: Support skb PAWS drop reason when TIME-WAIT Date: Mon, 24 Mar 2025 21:18:05 +0800 Message-ID: <20250324131805.23103-1-jiayuan.chen@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" When the server actively closes a connection and enters the TIME_WAIT state, if PAWS validation fails, the discarded skb previously lacked a corresponding reason identifier. This commit assigns the existing SKB_DROP_REASON_TCP_RFC7323_PAWS as the reason for such drops. We use 'pwru' to capture drop reason. Before this commit: '''' ./pwru 'port 9999' 2025/03/24 13:46:03 Listening for events.. TUPLE FUNC 172.31.75.115:12345->172.31.75.114:9999(tcp) sk_skb_reason_drop(SKB_DROP_RE= ASON_NOT_SPECIFIED) ''' After this commit: ''' ./pwru 'port 9999' 2025/03/24 16:06:59 Listening for events.. TUPLE FUNC 172.31.75.115:12345->172.31.75.114:9999(tcp) sk_skb_reason_drop(SKB_DROP_RE= ASON_TCP_RFC7323_PAWS) ''' Signed-off-by: Jiayuan Chen --- My apologize. I struggled for a long time to get packetdrill to fix the client port, but ultimately failed to do so, which is why I couldn't provide a packetdrill script. Instead, I wrote my own program to trigger PAWS, which can be found at https://github.com/mrpre/nettrigger/tree/main --- include/net/tcp.h | 2 +- net/ipv4/tcp_ipv4.c | 2 +- net/ipv4/tcp_minisocks.c | 6 ++++-- net/ipv6/tcp_ipv6.c | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 2d08473a6dc0..16e6efef939a 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -388,7 +388,7 @@ enum tcp_tw_status { enum tcp_tw_status tcp_timewait_state_process(struct inet_timewait_sock *t= w, struct sk_buff *skb, const struct tcphdr *th, - u32 *tw_isn); + u32 *tw_isn, enum skb_drop_reason *drop_reason); struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb, struct request_sock *req, bool fastopen, bool *lost_race); diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 2632844d2c35..ad168a3a73bb 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -2406,7 +2406,7 @@ int tcp_v4_rcv(struct sk_buff *skb) inet_twsk_put(inet_twsk(sk)); goto csum_error; } - switch (tcp_timewait_state_process(inet_twsk(sk), skb, th, &isn)) { + switch (tcp_timewait_state_process(inet_twsk(sk), skb, th, &isn, &drop_re= ason)) { case TCP_TW_SYN: { struct sock *sk2 =3D inet_lookup_listener(net, net->ipv4.tcp_death_row.hashinfo, diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c index b089b08e9617..39e5b55041f1 100644 --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c @@ -97,7 +97,7 @@ static void twsk_rcv_nxt_update(struct tcp_timewait_sock = *tcptw, u32 seq, */ enum tcp_tw_status tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *= skb, - const struct tcphdr *th, u32 *tw_isn) + const struct tcphdr *th, u32 *tw_isn, enum skb_drop_reason *drop_rea= son) { struct tcp_timewait_sock *tcptw =3D tcp_twsk((struct sock *)tw); u32 rcv_nxt =3D READ_ONCE(tcptw->tw_rcv_nxt); @@ -245,8 +245,10 @@ tcp_timewait_state_process(struct inet_timewait_sock *= tw, struct sk_buff *skb, return TCP_TW_SYN; } =20 - if (paws_reject) + if (paws_reject) { + *drop_reason =3D SKB_DROP_REASON_TCP_RFC7323_PAWS; __NET_INC_STATS(twsk_net(tw), LINUX_MIB_PAWSESTABREJECTED); + } =20 if (!th->rst) { /* In this case we must reset the TIMEWAIT timer. diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 2debdf085a3b..66d30df95f7a 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -1965,7 +1965,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff= *skb) goto csum_error; } =20 - switch (tcp_timewait_state_process(inet_twsk(sk), skb, th, &isn)) { + switch (tcp_timewait_state_process(inet_twsk(sk), skb, th, &isn, &drop_re= ason)) { case TCP_TW_SYN: { struct sock *sk2; --=20 2.47.1