From: menglong8.dong@gmail.com
To: edumazet@google.com, kuba@kernel.org
Cc: davem@davemloft.net, pabeni@redhat.com, yoshfuji@linux-ipv6.org,
dsahern@kernel.org, imagedong@tencent.com, kafai@fb.com,
asml.silence@gmail.com, keescook@chromium.org,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH net-next 3/9] net: tcp: use the drop reasons stored in tcp_skb_cb
Date: Sat, 29 Oct 2022 21:09:51 +0800 [thread overview]
Message-ID: <20221029130957.1292060-4-imagedong@tencent.com> (raw)
In-Reply-To: <20221029130957.1292060-1-imagedong@tencent.com>
From: Menglong Dong <imagedong@tencent.com>
The drop reasons for skb can be stored in tcp_skb_cb in some function
when it needs to be dropped. The following functions will do it in the
latter commits:
tcp_rcv_state_process
tcp_conn_request
tcp_rcv_state_process
tcp_timewait_state_process
tcp_rcv_synsent_state_process
Now, we initialize the drop_reason in tcp_skb_cb to
SKB_DROP_REASON_NOT_SPECIFIED. try_kfree_skb() should be used if any code
path makes the drop_reason to SKB_NOT_DROPPED_YET. Don't try to set it
to SKB_NOT_DROPPED_YET if the skb has any posibility to be dropped later.
Signed-off-by: Menglong Dong <imagedong@tencent.com>
---
net/ipv4/tcp_ipv4.c | 15 +++++++++++++--
net/ipv6/tcp_ipv6.c | 20 ++++++++++++++++----
2 files changed, 29 insertions(+), 6 deletions(-)
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 87d440f47a70..a85bc7483c5a 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1693,6 +1693,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
goto discard;
if (nsk != sk) {
if (tcp_child_process(sk, nsk, skb)) {
+ reason = TCP_SKB_CB(skb)->drop_reason;
rsk = nsk;
goto reset;
}
@@ -1702,6 +1703,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
sock_rps_save_rxhash(sk, skb);
if (tcp_rcv_state_process(sk, skb)) {
+ reason = TCP_SKB_CB(skb)->drop_reason;
rsk = sk;
goto reset;
}
@@ -1945,6 +1947,7 @@ int tcp_v4_rcv(struct sk_buff *skb)
int ret;
drop_reason = SKB_DROP_REASON_NOT_SPECIFIED;
+ TCP_SKB_DR(skb, NOT_SPECIFIED);
if (skb->pkt_type != PACKET_HOST)
goto discard_it;
@@ -2050,6 +2053,7 @@ int tcp_v4_rcv(struct sk_buff *skb)
reqsk_put(req);
tcp_v4_restore_cb(skb);
} else if (tcp_child_process(sk, nsk, skb)) {
+ drop_reason = TCP_SKB_CB(skb)->drop_reason;
tcp_v4_send_reset(nsk, skb);
goto discard_and_relse;
} else {
@@ -2136,6 +2140,11 @@ int tcp_v4_rcv(struct sk_buff *skb)
kfree_skb_reason(skb, drop_reason);
return 0;
+free_it:
+ drop_reason = TCP_SKB_CB(skb)->drop_reason;
+ try_kfree_skb(skb, drop_reason);
+ return 0;
+
discard_and_relse:
sk_drops_add(sk, skb);
if (refcounted)
@@ -2171,6 +2180,8 @@ int tcp_v4_rcv(struct sk_buff *skb)
refcounted = false;
goto process;
}
+ /* TCP_FLAGS or NO_SOCKET? */
+ TCP_SKB_DR(skb, TCP_FLAGS);
}
/* to ACK */
fallthrough;
@@ -2180,10 +2191,10 @@ int tcp_v4_rcv(struct sk_buff *skb)
case TCP_TW_RST:
tcp_v4_send_reset(sk, skb);
inet_twsk_deschedule_put(inet_twsk(sk));
- goto discard_it;
+ goto free_it;
case TCP_TW_SUCCESS:;
}
- goto discard_it;
+ goto free_it;
}
static struct timewait_sock_ops tcp_timewait_sock_ops = {
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index f676be14e6b6..2c2048832714 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -1515,8 +1515,10 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
goto discard;
if (nsk != sk) {
- if (tcp_child_process(sk, nsk, skb))
+ if (tcp_child_process(sk, nsk, skb)) {
+ reason = TCP_SKB_CB(skb)->drop_reason;
goto reset;
+ }
if (opt_skb)
__kfree_skb(opt_skb);
return 0;
@@ -1524,8 +1526,10 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
} else
sock_rps_save_rxhash(sk, skb);
- if (tcp_rcv_state_process(sk, skb))
+ if (tcp_rcv_state_process(sk, skb)) {
+ reason = TCP_SKB_CB(skb)->drop_reason;
goto reset;
+ }
if (opt_skb)
goto ipv6_pktoptions;
return 0;
@@ -1615,6 +1619,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
struct net *net = dev_net(skb->dev);
drop_reason = SKB_DROP_REASON_NOT_SPECIFIED;
+ TCP_SKB_DR(skb, NOT_SPECIFIED);
if (skb->pkt_type != PACKET_HOST)
goto discard_it;
@@ -1711,6 +1716,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
reqsk_put(req);
tcp_v6_restore_cb(skb);
} else if (tcp_child_process(sk, nsk, skb)) {
+ drop_reason = TCP_SKB_CB(skb)->drop_reason;
tcp_v6_send_reset(nsk, skb);
goto discard_and_relse;
} else {
@@ -1792,6 +1798,11 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
kfree_skb_reason(skb, drop_reason);
return 0;
+free_it:
+ drop_reason = TCP_SKB_CB(skb)->drop_reason;
+ try_kfree_skb(skb, drop_reason);
+ return 0;
+
discard_and_relse:
sk_drops_add(sk, skb);
if (refcounted)
@@ -1832,6 +1843,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
refcounted = false;
goto process;
}
+ TCP_SKB_DR(skb, TCP_FLAGS);
}
/* to ACK */
fallthrough;
@@ -1841,11 +1853,11 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
case TCP_TW_RST:
tcp_v6_send_reset(sk, skb);
inet_twsk_deschedule_put(inet_twsk(sk));
- goto discard_it;
+ goto free_it;
case TCP_TW_SUCCESS:
;
}
- goto discard_it;
+ goto free_it;
}
void tcp_v6_early_demux(struct sk_buff *skb)
--
2.37.2
next prev parent reply other threads:[~2022-10-29 13:11 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-29 13:09 [PATCH net-next 0/9] net: tcp: add skb drop reasons to tcp state process menglong8.dong
2022-10-29 13:09 ` [PATCH net-next 1/9] net: skb: introduce try_kfree_skb() menglong8.dong
2022-10-29 15:30 ` Eric Dumazet
2022-10-31 2:35 ` Menglong Dong
2022-10-29 13:09 ` [PATCH net-next 2/9] net: tcp: add 'drop_reason' field to struct tcp_skb_cb menglong8.dong
2022-10-29 15:23 ` Eric Dumazet
2022-10-31 3:08 ` Menglong Dong
2022-10-29 13:09 ` menglong8.dong [this message]
2022-10-29 13:09 ` [PATCH net-next 4/9] net: tcp: store drop reasons in tcp_rcv_synsent_state_process() menglong8.dong
2022-10-29 13:09 ` [PATCH net-next 5/9] net: tcp: store drop reasons in tcp_timewait_state_process() menglong8.dong
2022-10-29 13:09 ` [PATCH net-next 6/9] net: tcp: store drop reasons in tcp_conn_request() menglong8.dong
2022-10-29 13:09 ` [PATCH net-next 7/9] net: tcp: store drop reasons in tcp_rcv_state_process() menglong8.dong
2022-10-29 13:09 ` [PATCH net-next 8/9] net: tcp: store drop reasons in route_req menglong8.dong
2022-10-29 13:09 ` [PATCH net-next 9/9] net: tcp: use LINUX_MIB_TCPABORTONLINGER in tcp_rcv_state_process() 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=20221029130957.1292060-4-imagedong@tencent.com \
--to=menglong8.dong@gmail.com \
--cc=asml.silence@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=imagedong@tencent.com \
--cc=kafai@fb.com \
--cc=keescook@chromium.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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
all inboxes | Powered by JetHome®