Skip to content

Commit e7d4641

Browse files
committed
tcp: add TCP_RFC7323_TW_PAWS drop reason
JIRA: https://issues.redhat.com/browse/RHEL-88890 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 c9s. 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 55f3954 commit e7d4641

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
@@ -34,6 +34,7 @@
3434
FN(TCP_OFOMERGE) \
3535
FN(TCP_RFC7323_PAWS) \
3636
FN(TCP_RFC7323_PAWS_ACK) \
37+
FN(TCP_RFC7323_TW_PAWS) \
3738
FN(TCP_RFC7323_TSECR) \
3839
FN(TCP_LISTEN_OVERFLOW) \
3940
FN(TCP_OLD_SEQUENCE) \
@@ -241,6 +242,11 @@ enum skb_drop_reason {
241242
* Corresponds to LINUX_MIB_PAWS_OLD_ACK.
242243
*/
243244
SKB_DROP_REASON_TCP_RFC7323_PAWS_ACK,
245+
/**
246+
* @SKB_DROP_REASON_TCP_RFC7323_TW_PAWS: PAWS check, socket is in
247+
* TIME_WAIT state.
248+
*/
249+
SKB_DROP_REASON_TCP_RFC7323_TW_PAWS,
244250
/**
245251
* @SKB_DROP_REASON_TCP_RFC7323_TSECR: PAWS check, invalid TSEcr.
246252
* Corresponds to LINUX_MIB_TSECRREJECTED.

include/net/tcp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ enum tcp_tw_status {
392392
enum tcp_tw_status tcp_timewait_state_process(struct inet_timewait_sock *tw,
393393
struct sk_buff *skb,
394394
const struct tcphdr *th,
395-
u32 *tw_isn);
395+
u32 *tw_isn,
396+
enum skb_drop_reason *drop_reason);
396397
struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
397398
struct request_sock *req, bool fastopen,
398399
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
@@ -2150,7 +2150,8 @@ int tcp_v4_rcv(struct sk_buff *skb)
21502150
inet_twsk_put(inet_twsk(sk));
21512151
goto csum_error;
21522152
}
2153-
switch (tcp_timewait_state_process(inet_twsk(sk), skb, th, &isn)) {
2153+
switch (tcp_timewait_state_process(inet_twsk(sk), skb, th, &isn,
2154+
&drop_reason)) {
21542155
case TCP_TW_SYN: {
21552156
struct sock *sk2 = inet_lookup_listener(net,
21562157
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
@@ -91,7 +91,8 @@ tcp_timewait_check_oow_rate_limit(struct inet_timewait_sock *tw,
9191
*/
9292
enum tcp_tw_status
9393
tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
94-
const struct tcphdr *th, u32 *tw_isn)
94+
const struct tcphdr *th, u32 *tw_isn,
95+
enum skb_drop_reason *drop_reason)
9596
{
9697
struct tcp_options_received tmp_opt;
9798
struct tcp_timewait_sock *tcptw = tcp_twsk((struct sock *)tw);
@@ -233,8 +234,10 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
233234
return TCP_TW_SYN;
234235
}
235236

236-
if (paws_reject)
237+
if (paws_reject) {
238+
*drop_reason = SKB_DROP_REASON_TCP_RFC7323_TW_PAWS;
237239
__NET_INC_STATS(twsk_net(tw), LINUX_MIB_PAWSESTABREJECTED);
240+
}
238241

239242
if (!th->rst) {
240243
/* 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
@@ -1793,7 +1793,8 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
17931793
goto csum_error;
17941794
}
17951795

1796-
switch (tcp_timewait_state_process(inet_twsk(sk), skb, th, &isn)) {
1796+
switch (tcp_timewait_state_process(inet_twsk(sk), skb, th, &isn,
1797+
&drop_reason)) {
17971798
case TCP_TW_SYN:
17981799
{
17991800
struct sock *sk2;

0 commit comments

Comments
 (0)