introduce dropreasons in tcp receive path
Subsystems (3)
v4 cover introduce dropreasons in tcp receive path
From: Jason Xing <[email protected]>
As title said, we're going to refine the NOT_SPECIFIED reason in the tcp v4/6 receive fast path.
This serie is another one of the v2 patchset[1] which are here split into six patches. Besides, this patch is made on top of the previous serie[2] I submitted some time ago.
v4:
Already got rid of @acceptable in tcp_rcv_state_process(), so I need to remove *TCP_CONNREQNOTACCEPTABLE related codes which I wrote in the v3 series.
v3:
1. Split that patch into some smaller ones as suggested by Eric.
v2:
1. change the title of 2/2 patch.
2. fix some warnings checkpatch tool showed before.
3. use return value instead of adding more parameters suggested by Eric. Jason Xing (6):
tcp: introduce another three dropreasons in receive path
tcp: add more specific possible drop reasons in
tcp_rcv_synsent_state_process()
tcp: add dropreasons in tcp_rcv_state_process()
tcp: make the dropreason really work when calling
tcp_rcv_state_process()
tcp: make dropreason in tcp_child_process() work
tcp: get rid of NOT_SEPCIFIED reason in tcp_v4/6_do_rcv
include/net/dropreason-core.h | 15 ++++++++++++++- include/net/tcp.h | 4 ++-- net/ipv4/tcp_input.c | 25 +++++++++++++++++-------- net/ipv4/tcp_ipv4.c | 20 ++++++++++++-------- net/ipv4/tcp_minisocks.c | 9 +++++---- net/ipv6/tcp_ipv6.c | 20 ++++++++++++-------- 6 files changed, 62 insertions(+), 31 deletions(-)
Signature · 1 line
2.37.3
PATCH v4 1/6 tcp: introduce another three dropreasons in receive path
From: Jason Xing <[email protected]>
Soon later patches can use these relatively more accurate reasons to recognise and find out the cause.
--- include/net/dropreason-core.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
include/net/dropreason-core.h +14 -1
@@ -31,6 +31,7 @@ FN(TCP_AOFAILURE) \ FN(SOCKET_BACKLOG) \ FN(TCP_FLAGS) \ + FN(TCP_ABORTONDATA) \ FN(TCP_ZEROWINDOW) \ FN(TCP_OLD_DATA) \ FN(TCP_OVERWINDOW) \
@@ -38,6 +39,7 @@ FN(TCP_RFC7323_PAWS) \ FN(TCP_OLD_SEQUENCE) \ FN(TCP_INVALID_SEQUENCE) \ + FN(TCP_INVALID_ACK_SEQUENCE) \ FN(TCP_RESET) \ FN(TCP_INVALID_SYN) \ FN(TCP_CLOSE) \
@@ -207,6 +209,11 @@ enum skb_drop_reason {SKB_DROP_REASON_SOCKET_BACKLOG ,/** @SKB_DROP_REASON_TCP_FLAGS: TCP flags invalid */ SKB_DROP_REASON_TCP_FLAGS , +/** +* @SKB_DROP_REASON_TCP_ABORTONDATA: abort on data, corresponding to +* LINUX_MIB_TCPABORTONDATA +*/ + SKB_DROP_REASON_TCP_ABORTONDATA,/** * @SKB_DROP_REASON_TCP_ZEROWINDOW: TCP receive window size is zero, * see LINUX_MIB_TCPZEROWINDOWDROP
@@ -231,13 +238,19 @@ enum skb_drop_reason {SKB_DROP_REASON_TCP_OFOMERGE ,/** * @SKB_DROP_REASON_TCP_RFC7323_PAWS: PAWS check, corresponding to -* LINUX_MIB_PAWSESTABREJECTED +* LINUX_MIB_PAWSESTABREJECTED, LINUX_MIB_PAWSACTIVEREJECTED */ SKB_DROP_REASON_TCP_RFC7323_PAWS ,/** @SKB_DROP_REASON_TCP_OLD_SEQUENCE: Old SEQ field (duplicate packet) */ SKB_DROP_REASON_TCP_OLD_SEQUENCE ,/** @SKB_DROP_REASON_TCP_INVALID_SEQUENCE: Not acceptable SEQ field */ SKB_DROP_REASON_TCP_INVALID_SEQUENCE , +/** +* @SKB_DROP_REASON_TCP_INVALID_ACK_SEQUENCE: Not acceptable ACK SEQ +* field. because of ack sequence is not in the window between snd_una +* and snd_nxt +*/ +SKB_DROP_REASON_TCP_INVALID_ACK_SEQUENCE ,/** @SKB_DROP_REASON_TCP_RESET: Invalid RST packet */ SKB_DROP_REASON_TCP_RESET,/**
Signature · 1 line
2.37.3
Re: [PATCH net-next v4 1/6] tcp: introduce another three dropreasons in receive path
include/net/dropreason-core.h line 34
Quoted 9 lines · Jason Xing
include/net/dropreason-core.h +1
-0@@ -31,6 +31,7 @@ FN(TCP_AOFAILURE) \ FN(SOCKET_BACKLOG) \ FN(TCP_FLAGS) \ + FN(TCP_ABORTONDATA) \
for readability, how about TCP_ABORT_ON_DATA (yes, I know the MIB entry is LINUX_MIB_TCPABORTONDATA; we can improve readability with new changes).
Re: [PATCH net-next v4 1/6] tcp: introduce another three dropreasons in receive path
Quoted 14 lines · David Ahern
include/net/dropreason-core.h line 34
Quoted 9 lines · Jason Xing
include/net/dropreason-core.h +1
-0@@ -31,6 +31,7 @@ FN(TCP_AOFAILURE) \ FN(SOCKET_BACKLOG) \ FN(TCP_FLAGS) \ + FN(TCP_ABORTONDATA) \for readability, how about
TCP_ABORT_ON_DATA(yes, I know the MIB entry isLINUX_MIB_TCPABORTONDATA; we can improve readability with new changes).
Thanks for the review. Will do it :)
Quoted 2 lines
PATCH v4 2/6 tcp: add more specific possible drop reasons in tcp_rcv_synsent_state_process()
In reply to Jason XingFrom: Jason Xing <[email protected]>
This patch does two things:
1) add two more new reasons
2) only change the return value(1) to various drop reason values for the future use
For now, we still cannot trace those two reasons. We'll implement the full function in the subsequent patch in this serie.
--- net/ipv4/tcp_input.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv4/tcp_input.c +4 -1
@@ -6361,6 +6361,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,inet_csk_reset_xmit_timer (sk,ICSK_TIME_RETRANS ,TCP_TIMEOUT_MIN ,TCP_RTO_MAX ); +SKB_DR_SET (reason,TCP_INVALID_ACK_SEQUENCE ); goto reset_and_undo; }
@@ -6369,6 +6370,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, tcp_time_stamp_ts(tp))) {NET_INC_STATS (sock_net (sk),LINUX_MIB_PAWSACTIVEREJECTED ); +SKB_DR_SET (reason,TCP_RFC7323_PAWS ); goto reset_and_undo; }
@@ -6572,7 +6574,8 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, reset_and_undo:tcp_clear_options (&tp->rx_opt); tp->rx_opt.mss_clamp = saved_clamp; -return 1 ; +/* we can reuse/return @reason to its caller to handle the exception */ +return reason; }static void tcp_rcv_synrecv_state_fastopen (struct sock *sk)
Signature · 1 line
2.37.3
PATCH v4 3/6 tcp: add dropreasons in tcp_rcv_state_process()
In reply to Jason XingFrom: Jason Xing <[email protected]>
In this patch, I equipped this function with more dropreasons, but it still doesn't work yet, which I will do later.
--- include/net/tcp.h | 2 +- net/ipv4/tcp_input.c | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-)
include/net/tcp.h +1 -1
@@ -348,7 +348,7 @@ void tcp_wfree(struct sk_buff *skb);void tcp_write_timer_handler (struct sock *sk);void tcp_delack_timer_handler (struct sock *sk);int tcp_ioctl (struct sock *sk,int cmd,int *karg); -int tcp_rcv_state_process (struct sock *sk,struct sk_buff *skb); +enum skb_drop_reason tcp_rcv_state_process (struct sock *sk,struct sk_buff *skb);void tcp_rcv_established (struct sock *sk,struct sk_buff *skb);void tcp_rcv_space_adjust (struct sock *sk);int tcp_twsk_unique (struct sock *sk,struct sock *sktw,void *twp);
net/ipv4/tcp_input.c +13 -7
@@ -6619,7 +6619,8 @@ static void tcp_rcv_synrecv_state_fastopen(struct sock *sk)* address independent. */ -int tcp_rcv_state_process (struct sock *sk,struct sk_buff *skb) +enum skb_drop_reason +tcp_rcv_state_process (struct sock *sk,struct sk_buff *skb) {struct tcp_sock *tp =tcp_sk (sk);struct inet_connection_sock *icsk =inet_csk (sk);
@@ -6635,7 +6636,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb)case TCP_LISTEN :if (th->ack) -return 1 ; +return SKB_DROP_REASON_TCP_FLAGS ;if (th->rst) {SKB_DR_SET (reason,TCP_RESET );
@@ -6704,8 +6705,13 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) FLAG_NO_CHALLENGE_ACK);if ((int )reason <=0 ) { -if (sk->sk_state ==TCP_SYN_RECV ) -return 1 ;/* send one RST */ +if (sk->sk_state ==TCP_SYN_RECV ) { +/* send one RST */ +if (!reason) +return SKB_DROP_REASON_TCP_OLD_ACK ; +else +return -reason; + }/* accept old ack during closing */ if ((int )reason <0 ) {tcp_send_challenge_ack (sk);
@@ -6781,7 +6787,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb)if (READ_ONCE (tp->linger2) <0 ) {tcp_done (sk);NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPABORTONDATA ); -return 1 ; +return SKB_DROP_REASON_TCP_ABORTONDATA ; }if (TCP_SKB_CB (skb)->end_seq !=TCP_SKB_CB (skb)->seq &&after (TCP_SKB_CB (skb)->end_seq - th->fin, tp->rcv_nxt)) {
@@ -6790,7 +6796,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb)tcp_fastopen_active_disable (sk);tcp_done (sk);NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPABORTONDATA ); -return 1 ; +return SKB_DROP_REASON_TCP_ABORTONDATA ; } tmo =tcp_fin_time (sk);
@@ -6855,7 +6861,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) after(TCP_SKB_CB(skb)->end_seq - th->fin, tp->rcv_nxt)) {NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPABORTONDATA );tcp_reset (sk, skb); -return 1 ; +return SKB_DROP_REASON_TCP_ABORTONDATA ; } } fallthrough;
Signature · 1 line
2.37.3
PATCH v4 4/6 tcp: make the dropreason really work when calling tcp_rcv_state_process()
In reply to Jason XingFrom: Jason Xing <[email protected]>
Update three callers including both ipv4 and ipv6 and let the dropreason mechanism work in reality.
--- include/net/tcp.h | 2 +- net/ipv4/tcp_ipv4.c | 3 ++- net/ipv4/tcp_minisocks.c | 9 +++++---- net/ipv6/tcp_ipv6.c | 3 ++- 4 files changed, 10 insertions(+), 7 deletions(-)
include/net/tcp.h +1 -1
@@ -396,7 +396,7 @@ enum tcp_tw_status tcp_timewait_state_process(struct inet_timewait_sock *tw,struct sock *tcp_check_req (struct sock *sk,struct sk_buff *skb,struct request_sock *req,bool fastopen,bool *lost_race); -int tcp_child_process (struct sock *parent,struct sock *child, +enum skb_drop_reason tcp_child_process (struct sock *parent,struct sock *child,struct sk_buff *skb);void tcp_enter_loss (struct sock *sk);void tcp_cwnd_reduction (struct sock *sk,int newly_acked_sacked,int newly_lost,int flag);
net/ipv4/tcp_ipv4.c +2 -1
@@ -1926,7 +1926,8 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb) }else sock_rps_save_rxhash (sk, skb); -if (tcp_rcv_state_process (sk, skb)) { + reason =tcp_rcv_state_process (sk, skb); +if (reason) { rsk = sk; goto reset; }
net/ipv4/tcp_minisocks.c +5 -4
@@ -911,11 +911,12 @@ EXPORT_SYMBOL(tcp_check_req);* be created. */ -int tcp_child_process (struct sock *parent,struct sock *child, +enum skb_drop_reason +tcp_child_process (struct sock *parent,struct sock *child,struct sk_buff *skb) __releases(&((child)->sk_lock.slock)) { -int ret =0 ; +enum skb_drop_reason reason =SKB_NOT_DROPPED_YET ;int state = child->sk_state;/* record sk_napi_id and sk_rx_queue_mapping of child. */
@@ -923,7 +924,7 @@ int tcp_child_process(struct sock *parent, struct sock *child,tcp_segs_in (tcp_sk (child), skb);if (!sock_owned_by_user (child)) { - ret =tcp_rcv_state_process (child, skb); + reason =tcp_rcv_state_process (child, skb);/* Wakeup parent, send SIGIO */ if (state ==TCP_SYN_RECV && child->sk_state != state) parent->sk_data_ready (parent);
@@ -937,6 +938,6 @@ int tcp_child_process(struct sock *parent, struct sock *child,bh_unlock_sock (child);sock_put (child); -return ret; +return reason; }EXPORT_SYMBOL (tcp_child_process);
net/ipv6/tcp_ipv6.c +2 -1
@@ -1669,7 +1669,8 @@ 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)) + reason =tcp_rcv_state_process (sk, skb); +if (reason) goto reset;if (opt_skb) goto ipv6_pktoptions;
Signature · 1 line
2.37.3
PATCH v4 5/6 tcp: make dropreason in tcp_child_process() work
In reply to Jason XingFrom: Jason Xing <[email protected]>
It's time to let it work right now. We've already prepared for this:)
--- net/ipv4/tcp_ipv4.c | 16 ++++++++++------ net/ipv6/tcp_ipv6.c | 16 ++++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-)
net/ipv4/tcp_ipv4.c +10 -6
@@ -1917,7 +1917,8 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)if (!nsk)return 0 ;if (nsk != sk) { -if (tcp_child_process (sk, nsk, skb)) { + reason =tcp_child_process (sk, nsk, skb); +if (reason) { rsk = nsk; goto reset; }
@@ -2276,12 +2277,15 @@ int tcp_v4_rcv(struct sk_buff *skb)if (nsk == sk) {reqsk_put (req);tcp_v4_restore_cb (skb); - }else if (tcp_child_process (sk, nsk, skb)) { -tcp_v4_send_reset (nsk, skb); - goto discard_and_relse; }else { -sock_put (sk); -return 0 ; + drop_reason =tcp_child_process (sk, nsk, skb); +if (drop_reason) { +tcp_v4_send_reset (nsk, skb); + goto discard_and_relse; + }else { +sock_put (sk); +return 0 ; + } } }
net/ipv6/tcp_ipv6.c +10 -6
@@ -1660,7 +1660,8 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb) }if (nsk != sk) { -if (tcp_child_process (sk, nsk, skb)) + reason =tcp_child_process (sk, nsk, skb); +if (reason) goto reset;if (opt_skb)__kfree_skb (opt_skb);
@@ -1860,12 +1861,15 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)if (nsk == sk) {reqsk_put (req);tcp_v6_restore_cb (skb); - }else if (tcp_child_process (sk, nsk, skb)) { -tcp_v6_send_reset (nsk, skb); - goto discard_and_relse; }else { -sock_put (sk); -return 0 ; + drop_reason =tcp_child_process (sk, nsk, skb); +if (drop_reason) { +tcp_v6_send_reset (nsk, skb); + goto discard_and_relse; + }else { +sock_put (sk); +return 0 ; + } } }
Signature · 1 line
2.37.3
PATCH v4 6/6 tcp: get rid of NOT_SEPCIFIED reason in tcp_v4/6_do_rcv
In reply to Jason XingFrom: Jason Xing <[email protected]>
Finally we can drop this obscure reason in receive path because we replaced with many other more accurate reasons before.
--- net/ipv4/tcp_ipv4.c | 1 - net/ipv6/tcp_ipv6.c | 1 - 2 files changed, 2 deletions(-)
net/ipv4/tcp_ipv4.c +0 -1
@@ -1907,7 +1907,6 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)return 0 ; } - reason =SKB_DROP_REASON_NOT_SPECIFIED ;if (tcp_checksum_complete (skb)) goto csum_err;
net/ipv6/tcp_ipv6.c +0 -1
@@ -1623,7 +1623,6 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)if (np->rxopt.all) opt_skb =skb_clone_and_charge_r (skb, sk); - reason =SKB_DROP_REASON_NOT_SPECIFIED ;if (sk->sk_state ==TCP_ESTABLISHED ) {/* Fast path */ struct dst_entry *dst;
Signature · 1 line
2.37.3
Jakub Kicinski
maintainerQuoted 6 lines · On Tue, 13 Feb 2024 22:05:02 +0800 Jason Xing wrote:
As title said, we're going to refine the
NOT_SPECIFIEDreason in the tcp v4/6 receive fast path.This serie is another one of the v2 patchset[1] which are here split into six patches. Besides, this patch is made on top of the previous serie[2] I submitted some time ago.
Please do not post two similar sets at the same time.
Quoted 10 lines · Jakub Kicinski
Quoted 6 lines · On Tue, 13 Feb 2024 22:05:02 +0800 Jason Xing wrote:
As title said, we're going to refine the
NOT_SPECIFIEDreason in the tcp v4/6 receive fast path.This serie is another one of the v2 patchset[1] which are here split into six patches. Besides, this patch is made on top of the previous serie[2] I submitted some time ago.
Please do not post two similar sets at the same time.
Okay, I will merge them into one series.
Thanks,
Jason