Skip to content

Commit 5941521

Browse files
liu-song-6davem330
authored andcommitted
tcp: add tracepoint trace_tcp_receive_reset
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>
1 parent c24b14c commit 5941521

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

include/trace/events/tcp.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,72 @@ DEFINE_EVENT(tcp_event_sk_skb, tcp_send_reset,
8888
TP_ARGS(sk, skb)
8989
);
9090

91+
/*
92+
* tcp event with arguments sk
93+
*
94+
* Note: this class requires a valid sk pointer.
95+
*/
96+
DECLARE_EVENT_CLASS(tcp_event_sk,
97+
98+
TP_PROTO(const struct sock *sk),
99+
100+
TP_ARGS(sk),
101+
102+
TP_STRUCT__entry(
103+
__field(const void *, skaddr)
104+
__field(__u16, sport)
105+
__field(__u16, dport)
106+
__array(__u8, saddr, 4)
107+
__array(__u8, daddr, 4)
108+
__array(__u8, saddr_v6, 16)
109+
__array(__u8, daddr_v6, 16)
110+
),
111+
112+
TP_fast_assign(
113+
struct inet_sock *inet = inet_sk(sk);
114+
struct in6_addr *pin6;
115+
__be32 *p32;
116+
117+
__entry->skaddr = sk;
118+
119+
__entry->sport = ntohs(inet->inet_sport);
120+
__entry->dport = ntohs(inet->inet_dport);
121+
122+
p32 = (__be32 *) __entry->saddr;
123+
*p32 = inet->inet_saddr;
124+
125+
p32 = (__be32 *) __entry->daddr;
126+
*p32 = inet->inet_daddr;
127+
128+
#if IS_ENABLED(CONFIG_IPV6)
129+
if (sk->sk_family == AF_INET6) {
130+
pin6 = (struct in6_addr *)__entry->saddr_v6;
131+
*pin6 = sk->sk_v6_rcv_saddr;
132+
pin6 = (struct in6_addr *)__entry->daddr_v6;
133+
*pin6 = sk->sk_v6_daddr;
134+
} else
135+
#endif
136+
{
137+
pin6 = (struct in6_addr *)__entry->saddr_v6;
138+
ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
139+
pin6 = (struct in6_addr *)__entry->daddr_v6;
140+
ipv6_addr_set_v4mapped(inet->inet_daddr, pin6);
141+
}
142+
),
143+
144+
TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c",
145+
__entry->sport, __entry->dport,
146+
__entry->saddr, __entry->daddr,
147+
__entry->saddr_v6, __entry->daddr_v6)
148+
);
149+
150+
DEFINE_EVENT(tcp_event_sk, tcp_receive_reset,
151+
152+
TP_PROTO(const struct sock *sk),
153+
154+
TP_ARGS(sk)
155+
);
156+
91157
#endif /* _TRACE_TCP_H */
92158

93159
/* This part must be outside protection */

net/ipv4/tcp_input.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
#include <linux/ipsec.h>
7676
#include <asm/unaligned.h>
7777
#include <linux/errqueue.h>
78+
#include <trace/events/tcp.h>
7879

7980
int sysctl_tcp_fack __read_mostly;
8081
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)
40104011
/* When we get a reset we do this. */
40114012
void tcp_reset(struct sock *sk)
40124013
{
4014+
trace_tcp_receive_reset(sk);
4015+
40134016
/* We want the right error as BSD sees it (and indeed as we do). */
40144017
switch (sk->sk_state) {
40154018
case TCP_SYN_SENT:

0 commit comments

Comments
 (0)