Skip to content

Commit 300d66f

Browse files
committed
tcp: add TCP_RFC7323_TW_PAWS drop reason
JIRA: https://issues.redhat.com/browse/RHEL-88891 Upstream Status: net-next.git Conflicts:\ - Small code differences due to missing upstream commit 4618e19 ("tcp: add new TCP_TW_ACK_OOW state and allow ECN bits in TOS") in c10s. commit 0427141 Author: Jiayuan Chen <jiayuan.chen@linux.dev> Date: Wed Apr 9 19:26:04 2025 +0800 tcp: add TCP_RFC7323_TW_PAWS drop reason Devices in the networking path, such as firewalls, NATs, or routers, which can perform SNAT or DNAT, use addresses from their own limited address pools to masquerade the source address during forwarding, causing PAWS verification to fail more easily. Currently, packet loss statistics for PAWS can only be viewed through MIB, which is a global metric and cannot be precisely obtained through tracing to get the specific 4-tuple of the dropped packet. In the past, we had to use kprobe ret to retrieve relevant skb information from tcp_timewait_state_process(). We add a drop_reason pointer, similar to what previous commit does: commit e34100c ("tcp: add a drop_reason pointer to tcp_check_req()") This commit addresses the PAWSESTABREJECTED case and also sets the corresponding drop reason. We use 'pwru' to test. Before this commit: '''' ./pwru 'port 9999' 2025/04/07 13:40:19 Listening for events.. TUPLE FUNC 172.31.75.115:12345->172.31.75.114:9999(tcp) sk_skb_reason_drop(SKB_DROP_REASON_NOT_SPECIFIED) ''' After this commit: ''' ./pwru 'port 9999' 2025/04/07 13:51:34 Listening for events.. TUPLE FUNC 172.31.75.115:12345->172.31.75.114:9999(tcp) sk_skb_reason_drop(SKB_DROP_REASON_TCP_RFC7323_TW_PAWS) ''' Suggested-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev> Reviewed-by: Eric Dumazet <edumazet@google.com> Link: https://patch.msgid.link/20250409112614.16153-2-jiayuan.chen@linux.dev Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Antoine Tenart <atenart@redhat.com>
1 parent db64ebe commit 300d66f

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

include/net/dropreason-core.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
FN(TCP_OFOMERGE) \
4141
FN(TCP_RFC7323_PAWS) \
4242
FN(TCP_RFC7323_PAWS_ACK) \
43+
FN(TCP_RFC7323_TW_PAWS) \
4344
FN(TCP_RFC7323_TSECR) \
4445
FN(TCP_LISTEN_OVERFLOW) \
4546
FN(TCP_OLD_SEQUENCE) \
@@ -283,6 +284,11 @@ enum skb_drop_reason {
283284
* Corresponds to LINUX_MIB_PAWS_OLD_ACK.
284285
*/
285286
SKB_DROP_REASON_TCP_RFC7323_PAWS_ACK,
287+
/**
288+
* @SKB_DROP_REASON_TCP_RFC7323_TW_PAWS: PAWS check, socket is in
289+
* TIME_WAIT state.
290+
*/
291+
SKB_DROP_REASON_TCP_RFC7323_TW_PAWS,
286292
/**
287293
* @SKB_DROP_REASON_TCP_RFC7323_TSECR: PAWS check, invalid TSEcr.
288294
* Corresponds to LINUX_MIB_TSECRREJECTED.

include/net/tcp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ enum tcp_tw_status {
387387
enum tcp_tw_status tcp_timewait_state_process(struct inet_timewait_sock *tw,
388388
struct sk_buff *skb,
389389
const struct tcphdr *th,
390-
u32 *tw_isn);
390+
u32 *tw_isn,
391+
enum skb_drop_reason *drop_reason);
391392
struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
392393
struct request_sock *req, bool fastopen,
393394
bool *lost_race, enum skb_drop_reason *drop_reason);

net/ipv4/tcp_ipv4.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2404,7 +2404,8 @@ int tcp_v4_rcv(struct sk_buff *skb)
24042404
inet_twsk_put(inet_twsk(sk));
24052405
goto csum_error;
24062406
}
2407-
switch (tcp_timewait_state_process(inet_twsk(sk), skb, th, &isn)) {
2407+
switch (tcp_timewait_state_process(inet_twsk(sk), skb, th, &isn,
2408+
&drop_reason)) {
24082409
case TCP_TW_SYN: {
24092410
struct sock *sk2 = inet_lookup_listener(net,
24102411
net->ipv4.tcp_death_row.hashinfo,

net/ipv4/tcp_minisocks.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ static void twsk_rcv_nxt_update(struct tcp_timewait_sock *tcptw, u32 seq,
9797
*/
9898
enum tcp_tw_status
9999
tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
100-
const struct tcphdr *th, u32 *tw_isn)
100+
const struct tcphdr *th, u32 *tw_isn,
101+
enum skb_drop_reason *drop_reason)
101102
{
102103
struct tcp_timewait_sock *tcptw = tcp_twsk((struct sock *)tw);
103104
u32 rcv_nxt = READ_ONCE(tcptw->tw_rcv_nxt);
@@ -242,8 +243,10 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
242243
return TCP_TW_SYN;
243244
}
244245

245-
if (paws_reject)
246+
if (paws_reject) {
247+
*drop_reason = SKB_DROP_REASON_TCP_RFC7323_TW_PAWS;
246248
__NET_INC_STATS(twsk_net(tw), LINUX_MIB_PAWSESTABREJECTED);
249+
}
247250

248251
if (!th->rst) {
249252
/* In this case we must reset the TIMEWAIT timer.

net/ipv6/tcp_ipv6.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1963,7 +1963,8 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
19631963
goto csum_error;
19641964
}
19651965

1966-
switch (tcp_timewait_state_process(inet_twsk(sk), skb, th, &isn)) {
1966+
switch (tcp_timewait_state_process(inet_twsk(sk), skb, th, &isn,
1967+
&drop_reason)) {
19671968
case TCP_TW_SYN:
19681969
{
19691970
struct sock *sk2;

0 commit comments

Comments
 (0)