]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
tcp: add tracepoint trace_tcp_receive_reset
authorSong Liu <songliubraving@fb.com>
Mon, 23 Oct 2017 16:20:25 +0000 (09:20 -0700)
committerDavid S. Miller <davem@davemloft.net>
Tue, 24 Oct 2017 00:21:25 +0000 (01:21 +0100)
New tracepoint trace_tcp_receive_reset is added and called from
tcp_reset(). This tracepoint is define with a new class tcp_event_sk.

Signed-off-by: Song Liu <songliubraving@fb.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/trace/events/tcp.h
net/ipv4/tcp_input.c

index 3e57e1ae1c6b0c30e65a95f9d9ee7db0353a6df7..c83c71187719d20a738df151e130d3691661409a 100644 (file)
@@ -88,6 +88,72 @@ DEFINE_EVENT(tcp_event_sk_skb, tcp_send_reset,
        TP_ARGS(sk, skb)
 );
 
+/*
+ * tcp event with arguments sk
+ *
+ * Note: this class requires a valid sk pointer.
+ */
+DECLARE_EVENT_CLASS(tcp_event_sk,
+
+       TP_PROTO(const struct sock *sk),
+
+       TP_ARGS(sk),
+
+       TP_STRUCT__entry(
+               __field(const void *, skaddr)
+               __field(__u16, sport)
+               __field(__u16, dport)
+               __array(__u8, saddr, 4)
+               __array(__u8, daddr, 4)
+               __array(__u8, saddr_v6, 16)
+               __array(__u8, daddr_v6, 16)
+       ),
+
+       TP_fast_assign(
+               struct inet_sock *inet = inet_sk(sk);
+               struct in6_addr *pin6;
+               __be32 *p32;
+
+               __entry->skaddr = sk;
+
+               __entry->sport = ntohs(inet->inet_sport);
+               __entry->dport = ntohs(inet->inet_dport);
+
+               p32 = (__be32 *) __entry->saddr;
+               *p32 = inet->inet_saddr;
+
+               p32 = (__be32 *) __entry->daddr;
+               *p32 =  inet->inet_daddr;
+
+#if IS_ENABLED(CONFIG_IPV6)
+               if (sk->sk_family == AF_INET6) {
+                       pin6 = (struct in6_addr *)__entry->saddr_v6;
+                       *pin6 = sk->sk_v6_rcv_saddr;
+                       pin6 = (struct in6_addr *)__entry->daddr_v6;
+                       *pin6 = sk->sk_v6_daddr;
+               } else
+#endif
+               {
+                       pin6 = (struct in6_addr *)__entry->saddr_v6;
+                       ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
+                       pin6 = (struct in6_addr *)__entry->daddr_v6;
+                       ipv6_addr_set_v4mapped(inet->inet_daddr, pin6);
+               }
+       ),
+
+       TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c",
+                 __entry->sport, __entry->dport,
+                 __entry->saddr, __entry->daddr,
+                 __entry->saddr_v6, __entry->daddr_v6)
+);
+
+DEFINE_EVENT(tcp_event_sk, tcp_receive_reset,
+
+       TP_PROTO(const struct sock *sk),
+
+       TP_ARGS(sk)
+);
+
 #endif /* _TRACE_TCP_H */
 
 /* This part must be outside protection */
index ab3f1289824545f0bdf7691a70336ee8fab5cd9e..c5e64d4b5839a9340322f89649cde63d7571d0e0 100644 (file)
@@ -75,6 +75,7 @@
 #include <linux/ipsec.h>
 #include <asm/unaligned.h>
 #include <linux/errqueue.h>
+#include <trace/events/tcp.h>
 
 int sysctl_tcp_fack __read_mostly;
 int sysctl_tcp_max_reordering __read_mostly = 300;
@@ -4010,6 +4011,8 @@ static inline bool tcp_sequence(const struct tcp_sock *tp, u32 seq, u32 end_seq)
 /* When we get a reset we do this. */
 void tcp_reset(struct sock *sk)
 {
+       trace_tcp_receive_reset(sk);
+
        /* We want the right error as BSD sees it (and indeed as we do). */
        switch (sk->sk_state) {
        case TCP_SYN_SENT: