Skip to content

Commit 8ea5cff

Browse files
committed
tcp: support rstreason for passive reset
JIRA: https://issues.redhat.com/browse/RHEL-48648 Upstream Status: linux.git commit 120391e Author: Jason Xing <kernelxing@tencent.com> Date: Thu Apr 25 11:13:37 2024 +0800 tcp: support rstreason for passive reset Reuse the dropreason logic to show the exact reason of tcp reset, so we can finally display the corresponding item in enum sk_reset_reason instead of reinventing new reset reasons. This patch replaces all the prior NOT_SPECIFIED reasons. Signed-off-by: Jason Xing <kernelxing@tencent.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Antoine Tenart <atenart@redhat.com>
1 parent aef83a5 commit 8ea5cff

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

include/net/rstreason.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,19 @@ enum sk_rst_reason {
103103
*/
104104
SK_RST_REASON_MAX,
105105
};
106+
107+
/* Convert skb drop reasons to enum sk_rst_reason type */
108+
static inline enum sk_rst_reason
109+
sk_rst_convert_drop_reason(enum skb_drop_reason reason)
110+
{
111+
switch (reason) {
112+
case SKB_DROP_REASON_NOT_SPECIFIED:
113+
return SK_RST_REASON_NOT_SPECIFIED;
114+
case SKB_DROP_REASON_NO_SOCKET:
115+
return SK_RST_REASON_NO_SOCKET;
116+
default:
117+
/* If we don't have our own corresponding reason */
118+
return SK_RST_REASON_NOT_SPECIFIED;
119+
}
120+
}
106121
#endif

net/ipv4/tcp_ipv4.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
16891689
return 0;
16901690

16911691
reset:
1692-
tcp_v4_send_reset(rsk, skb, SK_RST_REASON_NOT_SPECIFIED);
1692+
tcp_v4_send_reset(rsk, skb, sk_rst_convert_drop_reason(reason));
16931693
discard:
16941694
kfree_skb_reason(skb, reason);
16951695
/* Be careful here. If this function gets more complicated and
@@ -2032,7 +2032,10 @@ int tcp_v4_rcv(struct sk_buff *skb)
20322032
} else {
20332033
drop_reason = tcp_child_process(sk, nsk, skb);
20342034
if (drop_reason) {
2035-
tcp_v4_send_reset(nsk, skb, SK_RST_REASON_NOT_SPECIFIED);
2035+
enum sk_rst_reason rst_reason;
2036+
2037+
rst_reason = sk_rst_convert_drop_reason(drop_reason);
2038+
tcp_v4_send_reset(nsk, skb, rst_reason);
20362039
goto discard_and_relse;
20372040
}
20382041
sock_put(sk);
@@ -2106,7 +2109,7 @@ int tcp_v4_rcv(struct sk_buff *skb)
21062109
bad_packet:
21072110
__TCP_INC_STATS(net, TCP_MIB_INERRS);
21082111
} else {
2109-
tcp_v4_send_reset(NULL, skb, SK_RST_REASON_NOT_SPECIFIED);
2112+
tcp_v4_send_reset(NULL, skb, sk_rst_convert_drop_reason(drop_reason));
21102113
}
21112114

21122115
discard_it:
@@ -2157,7 +2160,7 @@ int tcp_v4_rcv(struct sk_buff *skb)
21572160
tcp_v4_timewait_ack(sk, skb);
21582161
break;
21592162
case TCP_TW_RST:
2160-
tcp_v4_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED);
2163+
tcp_v4_send_reset(sk, skb, sk_rst_convert_drop_reason(drop_reason));
21612164
inet_twsk_deschedule_put(inet_twsk(sk));
21622165
goto discard_it;
21632166
case TCP_TW_SUCCESS:;

net/ipv6/tcp_ipv6.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
15121512
return 0;
15131513

15141514
reset:
1515-
tcp_v6_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED);
1515+
tcp_v6_send_reset(sk, skb, sk_rst_convert_drop_reason(reason));
15161516
discard:
15171517
if (opt_skb)
15181518
__kfree_skb(opt_skb);
@@ -1693,7 +1693,10 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
16931693
} else {
16941694
drop_reason = tcp_child_process(sk, nsk, skb);
16951695
if (drop_reason) {
1696-
tcp_v6_send_reset(nsk, skb, SK_RST_REASON_NOT_SPECIFIED);
1696+
enum sk_rst_reason rst_reason;
1697+
1698+
rst_reason = sk_rst_convert_drop_reason(drop_reason);
1699+
tcp_v6_send_reset(nsk, skb, rst_reason);
16971700
goto discard_and_relse;
16981701
}
16991702
sock_put(sk);
@@ -1763,7 +1766,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
17631766
bad_packet:
17641767
__TCP_INC_STATS(net, TCP_MIB_INERRS);
17651768
} else {
1766-
tcp_v6_send_reset(NULL, skb, SK_RST_REASON_NOT_SPECIFIED);
1769+
tcp_v6_send_reset(NULL, skb, sk_rst_convert_drop_reason(drop_reason));
17671770
}
17681771

17691772
discard_it:
@@ -1818,7 +1821,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
18181821
tcp_v6_timewait_ack(sk, skb);
18191822
break;
18201823
case TCP_TW_RST:
1821-
tcp_v6_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED);
1824+
tcp_v6_send_reset(sk, skb, sk_rst_convert_drop_reason(drop_reason));
18221825
inet_twsk_deschedule_put(inet_twsk(sk));
18231826
goto discard_it;
18241827
case TCP_TW_SUCCESS:

0 commit comments

Comments
 (0)