Skip to content

Commit 0427141

Browse files
mrprekuba-moo
authored andcommitted
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>
1 parent 709894c commit 0427141

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
@@ -427,7 +427,8 @@ enum tcp_tw_status {
427427
enum tcp_tw_status tcp_timewait_state_process(struct inet_timewait_sock *tw,
428428
struct sk_buff *skb,
429429
const struct tcphdr *th,
430-
u32 *tw_isn);
430+
u32 *tw_isn,
431+
enum skb_drop_reason *drop_reason);
431432
struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
432433
struct request_sock *req, bool fastopen,
433434
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
@@ -2417,7 +2417,8 @@ int tcp_v4_rcv(struct sk_buff *skb)
24172417
goto csum_error;
24182418
}
24192419

2420-
tw_status = tcp_timewait_state_process(inet_twsk(sk), skb, th, &isn);
2420+
tw_status = tcp_timewait_state_process(inet_twsk(sk), skb, th, &isn,
2421+
&drop_reason);
24212422
switch (tw_status) {
24222423
case TCP_TW_SYN: {
24232424
struct sock *sk2 = inet_lookup_listener(net,

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);
@@ -245,8 +246,10 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
245246
return TCP_TW_SYN;
246247
}
247248

248-
if (paws_reject)
249+
if (paws_reject) {
250+
*drop_reason = SKB_DROP_REASON_TCP_RFC7323_TW_PAWS;
249251
__NET_INC_STATS(twsk_net(tw), LINUX_MIB_PAWSESTABREJECTED);
252+
}
250253

251254
if (!th->rst) {
252255
/* 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
@@ -1970,7 +1970,8 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
19701970
goto csum_error;
19711971
}
19721972

1973-
tw_status = tcp_timewait_state_process(inet_twsk(sk), skb, th, &isn);
1973+
tw_status = tcp_timewait_state_process(inet_twsk(sk), skb, th, &isn,
1974+
&drop_reason);
19741975
switch (tw_status) {
19751976
case TCP_TW_SYN:
19761977
{

0 commit comments

Comments
 (0)