[PATCH net-next 2/9] net: tcp: add 'drop_reason' field to struct tcp_skb_cb

From: menglong8 . dong
Date: Sat Oct 29 2022 - 09:11:27 EST


From: Menglong Dong <imagedong@xxxxxxxxxxx>

Because of the long call chain on processing skb in TCP protocol, it's
hard to pass the drop reason to the code where the skb is freed.

Therefore, we can store the drop reason to skb->cb, and pass it to
kfree_skb_reason(). I'm lucky, the struct tcp_skb_cb still has 4 bytes
spare space for this purpose.

Signed-off-by: Menglong Dong <imagedong@xxxxxxxxxxx>
---
include/net/tcp.h | 3 +++
1 file changed, 3 insertions(+)

diff --git a/include/net/tcp.h b/include/net/tcp.h
index 14d45661a84d..0b6e39ca83b4 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -888,6 +888,7 @@ struct tcp_skb_cb {
has_rxtstamp:1, /* SKB has a RX timestamp */
unused:5;
__u32 ack_seq; /* Sequence number ACK'd */
+ enum skb_drop_reason drop_reason; /* Why skb is dropped */
union {
struct {
#define TCPCB_DELIVERED_CE_MASK ((1U<<20) - 1)
@@ -912,6 +913,8 @@ struct tcp_skb_cb {
};

#define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
+#define TCP_SKB_DR(__skb, reason) \
+ (TCP_SKB_CB(__skb)->drop_reason = SKB_DROP_REASON_##reason)

extern const struct inet_connection_sock_af_ops ipv4_specific;

--
2.37.2