rstreason: make it work in trace world
authorJason Xing <kernelxing@tencent.com>
Thu, 25 Apr 2024 03:13:40 +0000 (11:13 +0800)
committerPaolo Abeni <pabeni@redhat.com>
Fri, 26 Apr 2024 13:34:01 +0000 (15:34 +0200)
At last, we should let it work by introducing this reset reason in
trace world.

One of the possible expected outputs is:
... tcp_send_reset: skbaddr=xxx skaddr=xxx src=xxx dest=xxx
state=TCP_ESTABLISHED reason=NOT_SPECIFIED

Signed-off-by: Jason Xing <kernelxing@tencent.com>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
include/trace/events/tcp.h
net/ipv4/tcp_ipv4.c
net/ipv4/tcp_output.c
net/ipv6/tcp_ipv6.c

index 5c04a61a11c2c85e3474d51f0c3bf46dc36e091e..49b5ee091cf6a91339f821a3764b353652b911c8 100644 (file)
@@ -11,6 +11,7 @@
 #include <net/ipv6.h>
 #include <net/tcp.h>
 #include <linux/sock_diag.h>
+#include <net/rstreason.h>
 
 /*
  * tcp event with arguments sk and skb
@@ -74,20 +75,32 @@ DEFINE_EVENT(tcp_event_sk_skb, tcp_retransmit_skb,
        TP_ARGS(sk, skb)
 );
 
+#undef FN
+#define FN(reason)     TRACE_DEFINE_ENUM(SK_RST_REASON_##reason);
+DEFINE_RST_REASON(FN, FN)
+
+#undef FN
+#undef FNe
+#define FN(reason)     { SK_RST_REASON_##reason, #reason },
+#define FNe(reason)    { SK_RST_REASON_##reason, #reason }
+
 /*
  * skb of trace_tcp_send_reset is the skb that caused RST. In case of
  * active reset, skb should be NULL
  */
 TRACE_EVENT(tcp_send_reset,
 
-       TP_PROTO(const struct sock *sk, const struct sk_buff *skb),
+       TP_PROTO(const struct sock *sk,
+                const struct sk_buff *skb,
+                const enum sk_rst_reason reason),
 
-       TP_ARGS(sk, skb),
+       TP_ARGS(sk, skb, reason),
 
        TP_STRUCT__entry(
                __field(const void *, skbaddr)
                __field(const void *, skaddr)
                __field(int, state)
+               __field(enum sk_rst_reason, reason)
                __array(__u8, saddr, sizeof(struct sockaddr_in6))
                __array(__u8, daddr, sizeof(struct sockaddr_in6))
        ),
@@ -113,14 +126,19 @@ TRACE_EVENT(tcp_send_reset,
                         */
                        TP_STORE_ADDR_PORTS_SKB(skb, th, entry->daddr, entry->saddr);
                }
+               __entry->reason = reason;
        ),
 
-       TP_printk("skbaddr=%p skaddr=%p src=%pISpc dest=%pISpc state=%s",
+       TP_printk("skbaddr=%p skaddr=%p src=%pISpc dest=%pISpc state=%s reason=%s",
                  __entry->skbaddr, __entry->skaddr,
                  __entry->saddr, __entry->daddr,
-                 __entry->state ? show_tcp_state_name(__entry->state) : "UNKNOWN")
+                 __entry->state ? show_tcp_state_name(__entry->state) : "UNKNOWN",
+                 __print_symbolic(__entry->reason, DEFINE_RST_REASON(FN, FNe)))
 );
 
+#undef FN
+#undef FNe
+
 /*
  * tcp event with arguments sk
  *
index 621879ba916d8d95b76f281ce6376871de250692..0427deca3e0eb9239558aa124a41a1525df62a04 100644 (file)
@@ -871,7 +871,7 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb,
        if (sk)
                arg.bound_dev_if = sk->sk_bound_dev_if;
 
-       trace_tcp_send_reset(sk, skb);
+       trace_tcp_send_reset(sk, skb, reason);
 
        BUILD_BUG_ON(offsetof(struct sock, sk_bound_dev_if) !=
                     offsetof(struct inet_timewait_sock, tw_bound_dev_if));
index 41c352bf3394f9c4a471468f2813a52bb7a594f1..ece4726c875100ffb5140be290df40e7b7d835a6 100644 (file)
@@ -3641,7 +3641,7 @@ void tcp_send_active_reset(struct sock *sk, gfp_t priority,
        /* skb of trace_tcp_send_reset() keeps the skb that caused RST,
         * skb here is different to the troublesome skb, so use NULL
         */
-       trace_tcp_send_reset(sk, NULL);
+       trace_tcp_send_reset(sk, NULL, SK_RST_REASON_NOT_SPECIFIED);
 }
 
 /* Send a crossed SYN-ACK during socket establishment.
index 317d7a6e6b01d9058b1b6d003d56b918066dddcb..77958adf2e165c3684f1e8e9d56f8e8e0b520538 100644 (file)
@@ -1133,7 +1133,7 @@ static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb,
                        label = ip6_flowlabel(ipv6h);
        }
 
-       trace_tcp_send_reset(sk, skb);
+       trace_tcp_send_reset(sk, skb, reason);
 
        tcp_v6_send_response(sk, skb, seq, ack_seq, 0, 0, 0, oif, 1,
                             ipv6_get_dsfield(ipv6h), label, priority, txhash,