From: menglong8.dong@gmail.com
To: edumazet@google.com
Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net,
yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org,
pabeni@redhat.com, imagedong@tencent.com, kafai@fb.com,
talalahmad@google.com, keescook@chromium.org,
dongli.zhang@oracle.com, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org, Jiang Biao <benbjiang@tencent.com>,
Hao Peng <flyingpeng@tencent.com>
Subject: [PATCH net-next v2 8/9] net: tcp: add skb drop reasons to tcp tw code path
Date: Tue, 17 May 2022 16:10:07 +0800 [thread overview]
Message-ID: <20220517081008.294325-9-imagedong@tencent.com> (raw)
In-Reply-To: <20220517081008.294325-1-imagedong@tencent.com>
From: Menglong Dong <imagedong@tencent.com>
In order to get the reasons of skb drops, add a function argument of
type 'enum skb_drop_reason *reason' to tcp_timewait_state_process().
In the origin code, all packets to time-wait socket are treated as
dropping with kfree_skb(), which can make users confused. Therefore,
we use consume_skb() for the skbs that are 'good'. We can check the
value of 'reason' to decide use kfree_skb() or consume_skb().
The new reason 'TIMEWAIT' is added for the case that the skb is dropped
as the socket in time-wait state.
Reviewed-by: Jiang Biao <benbjiang@tencent.com>
Reviewed-by: Hao Peng <flyingpeng@tencent.com>
Signed-off-by: Menglong Dong <imagedong@tencent.com>
---
v2:
- skb is not freed on TCP_TW_ACK and 'ret' is not initizalized, fix
it (Eric Dumazet)
---
include/linux/skbuff.h | 5 +++++
include/net/tcp.h | 7 ++++---
net/ipv4/tcp_ipv4.c | 9 ++++++++-
net/ipv4/tcp_minisocks.c | 24 ++++++++++++++++++++----
net/ipv6/tcp_ipv6.c | 9 ++++++++-
5 files changed, 45 insertions(+), 9 deletions(-)
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 4578bbab5a3e..8d18fc5a5af6 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -560,6 +560,10 @@ struct sk_buff;
* SKB_DROP_REASON_TCP_REQQFULLDROP
* request queue of the listen socket is full, corresponding to
* LINUX_MIB_TCPREQQFULLDROP
+ *
+ * SKB_DROP_REASON_TIMEWAIT
+ * socket is in time-wait state and all packet that received will
+ * be treated as 'drop', except a good 'SYN' packet
*/
#define __DEFINE_SKB_DROP_REASON(FN) \
FN(NOT_SPECIFIED) \
@@ -631,6 +635,7 @@ struct sk_buff;
FN(TCP_ABORTONDATA) \
FN(LISTENOVERFLOWS) \
FN(TCP_REQQFULLDROP) \
+ FN(TIMEWAIT) \
FN(MAX)
/* The reason of skb drop, which is used in kfree_skb_reason().
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 082dd0627e2e..88217b8d95ac 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -380,9 +380,10 @@ enum tcp_tw_status {
};
-enum tcp_tw_status tcp_timewait_state_process(struct inet_timewait_sock *tw,
- struct sk_buff *skb,
- const struct tcphdr *th);
+enum tcp_tw_status
+tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
+ const struct tcphdr *th,
+ enum skb_drop_reason *reason);
struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
struct request_sock *req, bool fastopen,
bool *lost_race);
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 708f92b03f42..3c163b54b0f8 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -2134,7 +2134,8 @@ int tcp_v4_rcv(struct sk_buff *skb)
inet_twsk_put(inet_twsk(sk));
goto csum_error;
}
- switch (tcp_timewait_state_process(inet_twsk(sk), skb, th)) {
+ switch (tcp_timewait_state_process(inet_twsk(sk), skb, th,
+ &drop_reason)) {
case TCP_TW_SYN: {
struct sock *sk2 = inet_lookup_listener(dev_net(skb->dev),
&tcp_hashinfo, skb,
@@ -2150,11 +2151,17 @@ int tcp_v4_rcv(struct sk_buff *skb)
refcounted = false;
goto process;
}
+ /* TCP_FLAGS or NO_SOCKET? */
+ SKB_DR_SET(drop_reason, TCP_FLAGS);
}
/* to ACK */
fallthrough;
case TCP_TW_ACK:
tcp_v4_timewait_ack(sk, skb);
+ if (!drop_reason) {
+ consume_skb(skb);
+ return 0;
+ }
break;
case TCP_TW_RST:
tcp_v4_send_reset(sk, skb);
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index 1a21018f6f64..329724118b7f 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -83,13 +83,15 @@ tcp_timewait_check_oow_rate_limit(struct inet_timewait_sock *tw,
*/
enum tcp_tw_status
tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
- const struct tcphdr *th)
+ const struct tcphdr *th,
+ enum skb_drop_reason *reason)
{
struct tcp_options_received tmp_opt;
struct tcp_timewait_sock *tcptw = tcp_twsk((struct sock *)tw);
bool paws_reject = false;
tmp_opt.saw_tstamp = 0;
+ *reason = SKB_DROP_REASON_NOT_SPECIFIED;
if (th->doff > (sizeof(*th) >> 2) && tcptw->tw_ts_recent_stamp) {
tcp_parse_options(twsk_net(tw), skb, &tmp_opt, 0, NULL);
@@ -113,11 +115,16 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
return tcp_timewait_check_oow_rate_limit(
tw, skb, LINUX_MIB_TCPACKSKIPPEDFINWAIT2);
- if (th->rst)
+ if (th->rst) {
+ SKB_DR_SET(*reason, TCP_RESET);
goto kill;
+ }
- if (th->syn && !before(TCP_SKB_CB(skb)->seq, tcptw->tw_rcv_nxt))
+ if (th->syn && !before(TCP_SKB_CB(skb)->seq,
+ tcptw->tw_rcv_nxt)) {
+ SKB_DR_SET(*reason, TCP_FLAGS);
return TCP_TW_RST;
+ }
/* Dup ACK? */
if (!th->ack ||
@@ -143,6 +150,9 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
}
inet_twsk_reschedule(tw, TCP_TIMEWAIT_LEN);
+
+ /* skb should be free normally on this case. */
+ *reason = SKB_NOT_DROPPED_YET;
return TCP_TW_ACK;
}
@@ -174,6 +184,7 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
* protocol bug yet.
*/
if (twsk_net(tw)->ipv4.sysctl_tcp_rfc1337 == 0) {
+ SKB_DR_SET(*reason, TCP_RESET);
kill:
inet_twsk_deschedule_put(tw);
return TCP_TW_SUCCESS;
@@ -216,11 +227,14 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
if (isn == 0)
isn++;
TCP_SKB_CB(skb)->tcp_tw_isn = isn;
+ *reason = SKB_NOT_DROPPED_YET;
return TCP_TW_SYN;
}
- if (paws_reject)
+ if (paws_reject) {
+ SKB_DR_SET(*reason, TCP_RFC7323_PAWS);
__NET_INC_STATS(twsk_net(tw), LINUX_MIB_PAWSESTABREJECTED);
+ }
if (!th->rst) {
/* In this case we must reset the TIMEWAIT timer.
@@ -232,9 +246,11 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
if (paws_reject || th->ack)
inet_twsk_reschedule(tw, TCP_TIMEWAIT_LEN);
+ SKB_DR_OR(*reason, TIMEWAIT);
return tcp_timewait_check_oow_rate_limit(
tw, skb, LINUX_MIB_TCPACKSKIPPEDTIMEWAIT);
}
+ SKB_DR_SET(*reason, TCP_RESET);
inet_twsk_put(tw);
return TCP_TW_SUCCESS;
}
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 27c51991bd54..132b27763229 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -1772,6 +1772,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
}
discard_it:
+ SKB_DR_OR(drop_reason, NOT_SPECIFIED);
kfree_skb_reason(skb, drop_reason);
return 0;
@@ -1795,7 +1796,8 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
goto csum_error;
}
- switch (tcp_timewait_state_process(inet_twsk(sk), skb, th)) {
+ switch (tcp_timewait_state_process(inet_twsk(sk), skb, th,
+ &drop_reason)) {
case TCP_TW_SYN:
{
struct sock *sk2;
@@ -1815,11 +1817,16 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
refcounted = false;
goto process;
}
+ SKB_DR_SET(drop_reason, TCP_FLAGS);
}
/* to ACK */
fallthrough;
case TCP_TW_ACK:
tcp_v6_timewait_ack(sk, skb);
+ if (!drop_reason) {
+ consume_skb(skb);
+ return 0;
+ }
break;
case TCP_TW_RST:
tcp_v6_send_reset(sk, skb);
--
2.36.1
next prev parent reply other threads:[~2022-05-17 8:14 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-17 8:09 [PATCH net-next v2 0/9] net: tcp: add skb drop reasons to tcp state change menglong8.dong
2022-05-17 8:10 ` [PATCH net-next v2 1/9] net: skb: introduce __DEFINE_SKB_DROP_REASON() to simply the code menglong8.dong
2022-05-18 1:14 ` Jakub Kicinski
2022-05-18 2:15 ` Menglong Dong
2022-05-17 8:10 ` [PATCH net-next v2 2/9] net: skb: introduce __skb_queue_purge_reason() menglong8.dong
2022-05-17 8:10 ` [PATCH net-next v2 3/9] net: sock: introduce sk_stream_kill_queues_reason() menglong8.dong
2022-05-17 8:10 ` [PATCH net-next v2 4/9] net: inet: add skb drop reason to inet_csk_destroy_sock() menglong8.dong
2022-05-17 8:10 ` [PATCH net-next v2 5/9] net: tcp: make tcp_rcv_synsent_state_process() return drop reasons menglong8.dong
2022-05-17 8:10 ` [PATCH net-next v2 6/9] net: tcp: make tcp_rcv_state_process() return drop reason menglong8.dong
2022-05-17 8:10 ` [PATCH net-next v2 7/9] net: tcp: add skb drop reasons to tcp connect requesting menglong8.dong
2022-05-17 8:10 ` menglong8.dong [this message]
2022-05-17 8:10 ` [PATCH net-next v2 9/9] net: tcp: add skb drop reasons to route_req() menglong8.dong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220517081008.294325-9-imagedong@tencent.com \
--to=menglong8.dong@gmail.com \
--cc=benbjiang@tencent.com \
--cc=davem@davemloft.net \
--cc=dongli.zhang@oracle.com \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=flyingpeng@tencent.com \
--cc=imagedong@tencent.com \
--cc=kafai@fb.com \
--cc=keescook@chromium.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rostedt@goodmis.org \
--cc=talalahmad@google.com \
--cc=yoshfuji@linux-ipv6.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).