[Devel] [PATCH RHEL9 COMMIT] tcp: add drop reasons to tcp_rcv_state_process()

Konstantin Khorenko khorenko at virtuozzo.com
Mon Jan 16 20:56:52 MSK 2023


The commit is pushed to "branch-rh9-5.14.0-162.6.1.vz9.18.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-162.6.1.vz9.18.2
------>
commit 8d9e7837ba90205e12b66bce22f2076fc6388c67
Author: Eric Dumazet <edumazet at google.com>
Date:   Tue Jan 3 17:39:37 2023 +0200

    tcp: add drop reasons to tcp_rcv_state_process()
    
    Add basic support for drop reasons in tcp_rcv_state_process()
    
    Signed-off-by: Eric Dumazet <edumazet at google.com>
    Signed-off-by: David S. Miller <davem at davemloft.net>
    Acked-by: Nikolay Borisov <nborisov at suse.com>
    Signed-off-by: Nikolay Borisov <nikolay.borisov at virtuozzo.com>
    
    ======
    Patchset description:
    ms/net: Annotate skb free sites with reason
    
    This series backports most of the patches that add a reason to skb free sites.
    
    https://jira.sw.ru/browse/PSBM-143302
    
    Feature: net: improve verbosity of dropped packets reporting
---
 include/linux/skbuff.h     |  3 +++
 include/trace/events/skb.h |  7 +++++--
 net/ipv4/tcp_input.c       | 22 +++++++++++++++++-----
 3 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index dc38a214eee4..217dce9f6f0f 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -385,6 +385,9 @@ enum skb_drop_reason {
 	SKB_DROP_REASON_TCP_INVALID_SEQUENCE, /* Not acceptable SEQ field */
 	SKB_DROP_REASON_TCP_RESET,      /* Invalid RST packet */
 	SKB_DROP_REASON_TCP_INVALID_SYN, /* Incoming packet has unexpected SYN flag */
+	SKB_DROP_REASON_TCP_CLOSE,      /* TCP socket in CLOSE state */
+	SKB_DROP_REASON_TCP_FASTOPEN,   /* dropped by FASTOPEN request socket */
+	SKB_DROP_REASON_TCP_OLD_ACK,    /* TCP ACK is old, but in window */
 	SKB_DROP_REASON_IP_OUTNOROUTES, /* route lookup failed */
 	SKB_DROP_REASON_BPF_CGROUP_EGRESS,      /* dropped by
 						 * BPF_PROG_TYPE_CGROUP_SKB
diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h
index bb704d7ea8c9..a726a70f7596 100644
--- a/include/trace/events/skb.h
+++ b/include/trace/events/skb.h
@@ -40,8 +40,11 @@
 	EM(SKB_DROP_REASON_TCP_RFC7323_PAWS, TCP_RFC7323_PAWS)  \
 	EM(SKB_DROP_REASON_TCP_INVALID_SEQUENCE,                \
 	   TCP_INVALID_SEQUENCE)                                \
-	   EM(SKB_DROP_REASON_TCP_RESET, TCP_RESET)                \
-	   EM(SKB_DROP_REASON_TCP_INVALID_SYN, TCP_INVALID_SYN)    \
+	EM(SKB_DROP_REASON_TCP_RESET, TCP_RESET)                \
+	EM(SKB_DROP_REASON_TCP_INVALID_SYN, TCP_INVALID_SYN)    \
+	EM(SKB_DROP_REASON_TCP_CLOSE, TCP_CLOSE)                \
+	EM(SKB_DROP_REASON_TCP_FASTOPEN, TCP_FASTOPEN)          \
+	EM(SKB_DROP_REASON_TCP_OLD_ACK, TCP_OLD_ACK)            \
 	EM(SKB_DROP_REASON_IP_OUTNOROUTES, IP_OUTNOROUTES)      \
 	EM(SKB_DROP_REASON_BPF_CGROUP_EGRESS,                   \
 	   BPF_CGROUP_EGRESS)                                   \
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 9db35e8fe894..fad3792f71f4 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -6374,21 +6374,27 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb)
 	struct request_sock *req;
 	int queued = 0;
 	bool acceptable;
+	SKB_DR(reason);
 
 	switch (sk->sk_state) {
 	case TCP_CLOSE:
+		SKB_DR_SET(reason, TCP_CLOSE);
 		goto discard;
 
 	case TCP_LISTEN:
 		if (th->ack)
 			return 1;
 
-		if (th->rst)
+		if (th->rst) {
+			SKB_DR_SET(reason, TCP_RESET);
 			goto discard;
+		}
 
 		if (th->syn) {
-			if (th->fin)
+			if (th->fin) {
+				SKB_DR_SET(reason, TCP_FLAGS);
 				goto discard;
+			}
 			/* It is possible that we process SYN packets from backlog,
 			 * so we need to make sure to disable BH and RCU right there.
 			 */
@@ -6403,6 +6409,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb)
 			consume_skb(skb);
 			return 0;
 		}
+		SKB_DR_SET(reason, TCP_FLAGS);
 		goto discard;
 
 	case TCP_SYN_SENT:
@@ -6429,12 +6436,16 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb)
 		WARN_ON_ONCE(sk->sk_state != TCP_SYN_RECV &&
 		    sk->sk_state != TCP_FIN_WAIT1);
 
-		if (!tcp_check_req(sk, skb, req, true, &req_stolen))
+		if (!tcp_check_req(sk, skb, req, true, &req_stolen)) {
+			SKB_DR_SET(reason, TCP_FASTOPEN);
 			goto discard;
+		}
 	}
 
-	if (!th->ack && !th->rst && !th->syn)
+	if (!th->ack && !th->rst && !th->syn) {
+		SKB_DR_SET(reason, TCP_FLAGS);
 		goto discard;
+	}
 
 	if (!tcp_validate_incoming(sk, skb, th, 0))
 		return 0;
@@ -6448,6 +6459,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb)
 		if (sk->sk_state == TCP_SYN_RECV)
 			return 1;	/* send one RST */
 		tcp_send_challenge_ack(sk, skb);
+		SKB_DR_SET(reason, TCP_OLD_ACK);
 		goto discard;
 	}
 	switch (sk->sk_state) {
@@ -6608,7 +6620,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb)
 
 	if (!queued) {
 discard:
-		tcp_drop(sk, skb);
+		tcp_drop_reason(sk, skb, reason);
 	}
 	return 0;
 }


More information about the Devel mailing list