Skip to content

Commit 120391e

Browse files
JasonXingPaolo Abeni
authored andcommitted
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>
1 parent 5691276 commit 120391e

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
@@ -1936,7 +1936,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
19361936
return 0;
19371937

19381938
reset:
1939-
tcp_v4_send_reset(rsk, skb, SK_RST_REASON_NOT_SPECIFIED);
1939+
tcp_v4_send_reset(rsk, skb, sk_rst_convert_drop_reason(reason));
19401940
discard:
19411941
kfree_skb_reason(skb, reason);
19421942
/* Be careful here. If this function gets more complicated and
@@ -2287,7 +2287,10 @@ int tcp_v4_rcv(struct sk_buff *skb)
22872287
} else {
22882288
drop_reason = tcp_child_process(sk, nsk, skb);
22892289
if (drop_reason) {
2290-
tcp_v4_send_reset(nsk, skb, SK_RST_REASON_NOT_SPECIFIED);
2290+
enum sk_rst_reason rst_reason;
2291+
2292+
rst_reason = sk_rst_convert_drop_reason(drop_reason);
2293+
tcp_v4_send_reset(nsk, skb, rst_reason);
22912294
goto discard_and_relse;
22922295
}
22932296
sock_put(sk);
@@ -2366,7 +2369,7 @@ int tcp_v4_rcv(struct sk_buff *skb)
23662369
bad_packet:
23672370
__TCP_INC_STATS(net, TCP_MIB_INERRS);
23682371
} else {
2369-
tcp_v4_send_reset(NULL, skb, SK_RST_REASON_NOT_SPECIFIED);
2372+
tcp_v4_send_reset(NULL, skb, sk_rst_convert_drop_reason(drop_reason));
23702373
}
23712374

23722375
discard_it:
@@ -2418,7 +2421,7 @@ int tcp_v4_rcv(struct sk_buff *skb)
24182421
tcp_v4_timewait_ack(sk, skb);
24192422
break;
24202423
case TCP_TW_RST:
2421-
tcp_v4_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED);
2424+
tcp_v4_send_reset(sk, skb, sk_rst_convert_drop_reason(drop_reason));
24222425
inet_twsk_deschedule_put(inet_twsk(sk));
24232426
goto discard_it;
24242427
case TCP_TW_SUCCESS:;

net/ipv6/tcp_ipv6.c

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

16821682
reset:
1683-
tcp_v6_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED);
1683+
tcp_v6_send_reset(sk, skb, sk_rst_convert_drop_reason(reason));
16841684
discard:
16851685
if (opt_skb)
16861686
__kfree_skb(opt_skb);
@@ -1865,7 +1865,10 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
18651865
} else {
18661866
drop_reason = tcp_child_process(sk, nsk, skb);
18671867
if (drop_reason) {
1868-
tcp_v6_send_reset(nsk, skb, SK_RST_REASON_NOT_SPECIFIED);
1868+
enum sk_rst_reason rst_reason;
1869+
1870+
rst_reason = sk_rst_convert_drop_reason(drop_reason);
1871+
tcp_v6_send_reset(nsk, skb, rst_reason);
18691872
goto discard_and_relse;
18701873
}
18711874
sock_put(sk);
@@ -1942,7 +1945,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
19421945
bad_packet:
19431946
__TCP_INC_STATS(net, TCP_MIB_INERRS);
19441947
} else {
1945-
tcp_v6_send_reset(NULL, skb, SK_RST_REASON_NOT_SPECIFIED);
1948+
tcp_v6_send_reset(NULL, skb, sk_rst_convert_drop_reason(drop_reason));
19461949
}
19471950

19481951
discard_it:
@@ -1998,7 +2001,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
19982001
tcp_v6_timewait_ack(sk, skb);
19992002
break;
20002003
case TCP_TW_RST:
2001-
tcp_v6_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED);
2004+
tcp_v6_send_reset(sk, skb, sk_rst_convert_drop_reason(drop_reason));
20022005
inet_twsk_deschedule_put(inet_twsk(sk));
20032006
goto discard_it;
20042007
case TCP_TW_SUCCESS:

0 commit comments

Comments
 (0)