blob: 521059d8dc0a67087527e8a9aa2338e81d86bd37 [file] [log] [blame]
Masami Hiramatsuc3fde1b2017-12-29 11:45:51 +09001/* SPDX-License-Identifier: GPL-2.0 */
Cong Wange0861012017-10-13 13:03:16 -07002#undef TRACE_SYSTEM
3#define TRACE_SYSTEM tcp
4
5#if !defined(_TRACE_TCP_H) || defined(TRACE_HEADER_MULTI_READ)
6#define _TRACE_TCP_H
7
8#include <linux/ipv6.h>
9#include <linux/tcp.h>
10#include <linux/tracepoint.h>
11#include <net/ipv6.h>
Masami Hiramatsuc3fde1b2017-12-29 11:45:51 +090012#include <net/tcp.h>
Yafang Shao61638492018-04-20 23:18:26 +080013#include <linux/sock_diag.h>
Cong Wange0861012017-10-13 13:03:16 -070014
Mat Martineau6a6b0b92017-12-21 10:29:09 -080015#define TP_STORE_V4MAPPED(__entry, saddr, daddr) \
16 do { \
17 struct in6_addr *pin6; \
18 \
19 pin6 = (struct in6_addr *)__entry->saddr_v6; \
20 ipv6_addr_set_v4mapped(saddr, pin6); \
21 pin6 = (struct in6_addr *)__entry->daddr_v6; \
22 ipv6_addr_set_v4mapped(daddr, pin6); \
23 } while (0)
24
25#if IS_ENABLED(CONFIG_IPV6)
26#define TP_STORE_ADDRS(__entry, saddr, daddr, saddr6, daddr6) \
27 do { \
28 if (sk->sk_family == AF_INET6) { \
29 struct in6_addr *pin6; \
30 \
31 pin6 = (struct in6_addr *)__entry->saddr_v6; \
32 *pin6 = saddr6; \
33 pin6 = (struct in6_addr *)__entry->daddr_v6; \
34 *pin6 = daddr6; \
35 } else { \
36 TP_STORE_V4MAPPED(__entry, saddr, daddr); \
37 } \
38 } while (0)
39#else
40#define TP_STORE_ADDRS(__entry, saddr, daddr, saddr6, daddr6) \
41 TP_STORE_V4MAPPED(__entry, saddr, daddr)
42#endif
43
Song Liuf6e37b22017-10-23 09:20:22 -070044/*
45 * tcp event with arguments sk and skb
46 *
47 * Note: this class requires a valid sk pointer; while skb pointer could
48 * be NULL.
49 */
50DECLARE_EVENT_CLASS(tcp_event_sk_skb,
Cong Wange0861012017-10-13 13:03:16 -070051
Song Liu7344e292017-10-23 09:20:23 -070052 TP_PROTO(const struct sock *sk, const struct sk_buff *skb),
Cong Wange0861012017-10-13 13:03:16 -070053
54 TP_ARGS(sk, skb),
55
56 TP_STRUCT__entry(
Song Liu7344e292017-10-23 09:20:23 -070057 __field(const void *, skbaddr)
58 __field(const void *, skaddr)
Yafang Shaoaf4325e2018-09-24 20:57:29 +080059 __field(int, state)
Cong Wange0861012017-10-13 13:03:16 -070060 __field(__u16, sport)
61 __field(__u16, dport)
Hariharan Ananthakrishnan3dd344ea2021-01-29 00:12:10 +000062 __field(__u16, family)
Cong Wange0861012017-10-13 13:03:16 -070063 __array(__u8, saddr, 4)
64 __array(__u8, daddr, 4)
65 __array(__u8, saddr_v6, 16)
66 __array(__u8, daddr_v6, 16)
67 ),
68
69 TP_fast_assign(
Cong Wange0861012017-10-13 13:03:16 -070070 struct inet_sock *inet = inet_sk(sk);
Cong Wange0861012017-10-13 13:03:16 -070071 __be32 *p32;
72
73 __entry->skbaddr = skb;
74 __entry->skaddr = sk;
Yafang Shaoaf4325e2018-09-24 20:57:29 +080075 __entry->state = sk->sk_state;
Cong Wange0861012017-10-13 13:03:16 -070076
77 __entry->sport = ntohs(inet->inet_sport);
78 __entry->dport = ntohs(inet->inet_dport);
Hariharan Ananthakrishnan3dd344ea2021-01-29 00:12:10 +000079 __entry->family = sk->sk_family;
Cong Wange0861012017-10-13 13:03:16 -070080
81 p32 = (__be32 *) __entry->saddr;
82 *p32 = inet->inet_saddr;
83
84 p32 = (__be32 *) __entry->daddr;
85 *p32 = inet->inet_daddr;
86
Mat Martineau6a6b0b92017-12-21 10:29:09 -080087 TP_STORE_ADDRS(__entry, inet->inet_saddr, inet->inet_daddr,
88 sk->sk_v6_rcv_saddr, sk->sk_v6_daddr);
Cong Wange0861012017-10-13 13:03:16 -070089 ),
90
Hariharan Ananthakrishnan3dd344ea2021-01-29 00:12:10 +000091 TP_printk("family=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c state=%s",
92 show_family_name(__entry->family),
Cong Wange0861012017-10-13 13:03:16 -070093 __entry->sport, __entry->dport, __entry->saddr, __entry->daddr,
Yafang Shaoaf4325e2018-09-24 20:57:29 +080094 __entry->saddr_v6, __entry->daddr_v6,
95 show_tcp_state_name(__entry->state))
Cong Wange0861012017-10-13 13:03:16 -070096);
97
Song Liuf6e37b22017-10-23 09:20:22 -070098DEFINE_EVENT(tcp_event_sk_skb, tcp_retransmit_skb,
99
Song Liu7344e292017-10-23 09:20:23 -0700100 TP_PROTO(const struct sock *sk, const struct sk_buff *skb),
Song Liuf6e37b22017-10-23 09:20:22 -0700101
102 TP_ARGS(sk, skb)
103);
104
Song Liuc24b14c2017-10-23 09:20:24 -0700105/*
106 * skb of trace_tcp_send_reset is the skb that caused RST. In case of
107 * active reset, skb should be NULL
108 */
109DEFINE_EVENT(tcp_event_sk_skb, tcp_send_reset,
110
111 TP_PROTO(const struct sock *sk, const struct sk_buff *skb),
112
113 TP_ARGS(sk, skb)
114);
115
Song Liu59415212017-10-23 09:20:25 -0700116/*
117 * tcp event with arguments sk
118 *
119 * Note: this class requires a valid sk pointer.
120 */
121DECLARE_EVENT_CLASS(tcp_event_sk,
122
Yafang Shao61638492018-04-20 23:18:26 +0800123 TP_PROTO(struct sock *sk),
Song Liu59415212017-10-23 09:20:25 -0700124
125 TP_ARGS(sk),
126
127 TP_STRUCT__entry(
128 __field(const void *, skaddr)
129 __field(__u16, sport)
130 __field(__u16, dport)
Hariharan Ananthakrishnan3dd344ea2021-01-29 00:12:10 +0000131 __field(__u16, family)
Song Liu59415212017-10-23 09:20:25 -0700132 __array(__u8, saddr, 4)
133 __array(__u8, daddr, 4)
134 __array(__u8, saddr_v6, 16)
135 __array(__u8, daddr_v6, 16)
Yafang Shao61638492018-04-20 23:18:26 +0800136 __field(__u64, sock_cookie)
Song Liu59415212017-10-23 09:20:25 -0700137 ),
138
139 TP_fast_assign(
140 struct inet_sock *inet = inet_sk(sk);
Song Liu59415212017-10-23 09:20:25 -0700141 __be32 *p32;
142
143 __entry->skaddr = sk;
144
145 __entry->sport = ntohs(inet->inet_sport);
146 __entry->dport = ntohs(inet->inet_dport);
Hariharan Ananthakrishnan3dd344ea2021-01-29 00:12:10 +0000147 __entry->family = sk->sk_family;
Song Liu59415212017-10-23 09:20:25 -0700148
149 p32 = (__be32 *) __entry->saddr;
150 *p32 = inet->inet_saddr;
151
152 p32 = (__be32 *) __entry->daddr;
153 *p32 = inet->inet_daddr;
154
Mat Martineau6a6b0b92017-12-21 10:29:09 -0800155 TP_STORE_ADDRS(__entry, inet->inet_saddr, inet->inet_daddr,
156 sk->sk_v6_rcv_saddr, sk->sk_v6_daddr);
Yafang Shao61638492018-04-20 23:18:26 +0800157
158 __entry->sock_cookie = sock_gen_cookie(sk);
Song Liu59415212017-10-23 09:20:25 -0700159 ),
160
Hariharan Ananthakrishnan3dd344ea2021-01-29 00:12:10 +0000161 TP_printk("family=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c sock_cookie=%llx",
162 show_family_name(__entry->family),
Song Liu59415212017-10-23 09:20:25 -0700163 __entry->sport, __entry->dport,
164 __entry->saddr, __entry->daddr,
Yafang Shao61638492018-04-20 23:18:26 +0800165 __entry->saddr_v6, __entry->daddr_v6,
166 __entry->sock_cookie)
Song Liu59415212017-10-23 09:20:25 -0700167);
168
169DEFINE_EVENT(tcp_event_sk, tcp_receive_reset,
170
Yafang Shao61638492018-04-20 23:18:26 +0800171 TP_PROTO(struct sock *sk),
Song Liu59415212017-10-23 09:20:25 -0700172
173 TP_ARGS(sk)
174);
175
Song Liue1a4aa52017-10-23 09:20:26 -0700176DEFINE_EVENT(tcp_event_sk, tcp_destroy_sock,
177
Yafang Shao61638492018-04-20 23:18:26 +0800178 TP_PROTO(struct sock *sk),
179
180 TP_ARGS(sk)
181);
182
183DEFINE_EVENT(tcp_event_sk, tcp_rcv_space_adjust,
184
185 TP_PROTO(struct sock *sk),
Song Liue1a4aa52017-10-23 09:20:26 -0700186
187 TP_ARGS(sk)
188);
189
Song Liucf34ce32017-10-30 14:41:35 -0700190TRACE_EVENT(tcp_retransmit_synack,
191
192 TP_PROTO(const struct sock *sk, const struct request_sock *req),
193
194 TP_ARGS(sk, req),
195
196 TP_STRUCT__entry(
197 __field(const void *, skaddr)
198 __field(const void *, req)
199 __field(__u16, sport)
200 __field(__u16, dport)
Hariharan Ananthakrishnan3dd344ea2021-01-29 00:12:10 +0000201 __field(__u16, family)
Song Liucf34ce32017-10-30 14:41:35 -0700202 __array(__u8, saddr, 4)
203 __array(__u8, daddr, 4)
204 __array(__u8, saddr_v6, 16)
205 __array(__u8, daddr_v6, 16)
206 ),
207
208 TP_fast_assign(
209 struct inet_request_sock *ireq = inet_rsk(req);
Song Liucf34ce32017-10-30 14:41:35 -0700210 __be32 *p32;
211
212 __entry->skaddr = sk;
213 __entry->req = req;
214
215 __entry->sport = ireq->ir_num;
216 __entry->dport = ntohs(ireq->ir_rmt_port);
Hariharan Ananthakrishnan3dd344ea2021-01-29 00:12:10 +0000217 __entry->family = sk->sk_family;
Song Liucf34ce32017-10-30 14:41:35 -0700218
219 p32 = (__be32 *) __entry->saddr;
220 *p32 = ireq->ir_loc_addr;
221
222 p32 = (__be32 *) __entry->daddr;
223 *p32 = ireq->ir_rmt_addr;
224
Mat Martineau6a6b0b92017-12-21 10:29:09 -0800225 TP_STORE_ADDRS(__entry, ireq->ir_loc_addr, ireq->ir_rmt_addr,
226 ireq->ir_v6_loc_addr, ireq->ir_v6_rmt_addr);
Song Liucf34ce32017-10-30 14:41:35 -0700227 ),
228
Hariharan Ananthakrishnan3dd344ea2021-01-29 00:12:10 +0000229 TP_printk("family=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c",
230 show_family_name(__entry->family),
Song Liucf34ce32017-10-30 14:41:35 -0700231 __entry->sport, __entry->dport,
232 __entry->saddr, __entry->daddr,
233 __entry->saddr_v6, __entry->daddr_v6)
234);
235
Masami Hiramatsuee549be2017-12-29 11:47:55 +0900236#include <trace/events/net_probe_common.h>
Masami Hiramatsuc3fde1b2017-12-29 11:45:51 +0900237
238TRACE_EVENT(tcp_probe,
239
240 TP_PROTO(struct sock *sk, struct sk_buff *skb),
241
242 TP_ARGS(sk, skb),
243
244 TP_STRUCT__entry(
245 /* sockaddr_in6 is always bigger than sockaddr_in */
246 __array(__u8, saddr, sizeof(struct sockaddr_in6))
247 __array(__u8, daddr, sizeof(struct sockaddr_in6))
248 __field(__u16, sport)
249 __field(__u16, dport)
Hariharan Ananthakrishnan3dd344ea2021-01-29 00:12:10 +0000250 __field(__u16, family)
Masami Hiramatsuc3fde1b2017-12-29 11:45:51 +0900251 __field(__u32, mark)
Yafang Shao2d68c072018-05-25 18:14:05 +0800252 __field(__u16, data_len)
Masami Hiramatsuc3fde1b2017-12-29 11:45:51 +0900253 __field(__u32, snd_nxt)
254 __field(__u32, snd_una)
255 __field(__u32, snd_cwnd)
256 __field(__u32, ssthresh)
257 __field(__u32, snd_wnd)
258 __field(__u32, srtt)
259 __field(__u32, rcv_wnd)
Yafang Shao61638492018-04-20 23:18:26 +0800260 __field(__u64, sock_cookie)
Masami Hiramatsuc3fde1b2017-12-29 11:45:51 +0900261 ),
262
263 TP_fast_assign(
Yafang Shao3d97d882018-05-29 23:27:31 +0800264 const struct tcphdr *th = (const struct tcphdr *)skb->data;
Masami Hiramatsuc3fde1b2017-12-29 11:45:51 +0900265 const struct inet_sock *inet = inet_sk(sk);
Yafang Shao3d97d882018-05-29 23:27:31 +0800266 const struct tcp_sock *tp = tcp_sk(sk);
Masami Hiramatsuc3fde1b2017-12-29 11:45:51 +0900267
268 memset(__entry->saddr, 0, sizeof(struct sockaddr_in6));
269 memset(__entry->daddr, 0, sizeof(struct sockaddr_in6));
270
271 TP_STORE_ADDR_PORTS(__entry, inet, sk);
272
273 /* For filtering use */
274 __entry->sport = ntohs(inet->inet_sport);
275 __entry->dport = ntohs(inet->inet_dport);
276 __entry->mark = skb->mark;
Hariharan Ananthakrishnan3dd344ea2021-01-29 00:12:10 +0000277 __entry->family = sk->sk_family;
Masami Hiramatsuc3fde1b2017-12-29 11:45:51 +0900278
Yafang Shao3d97d882018-05-29 23:27:31 +0800279 __entry->data_len = skb->len - __tcp_hdrlen(th);
Masami Hiramatsuc3fde1b2017-12-29 11:45:51 +0900280 __entry->snd_nxt = tp->snd_nxt;
281 __entry->snd_una = tp->snd_una;
282 __entry->snd_cwnd = tp->snd_cwnd;
283 __entry->snd_wnd = tp->snd_wnd;
284 __entry->rcv_wnd = tp->rcv_wnd;
285 __entry->ssthresh = tcp_current_ssthresh(sk);
286 __entry->srtt = tp->srtt_us >> 3;
Yafang Shao61638492018-04-20 23:18:26 +0800287 __entry->sock_cookie = sock_gen_cookie(sk);
Masami Hiramatsuc3fde1b2017-12-29 11:45:51 +0900288 ),
289
Hariharan Ananthakrishnan3dd344ea2021-01-29 00:12:10 +0000290 TP_printk("family=%s src=%pISpc dest=%pISpc mark=%#x data_len=%d snd_nxt=%#x snd_una=%#x snd_cwnd=%u ssthresh=%u snd_wnd=%u srtt=%u rcv_wnd=%u sock_cookie=%llx",
291 show_family_name(__entry->family),
Masami Hiramatsuc3fde1b2017-12-29 11:45:51 +0900292 __entry->saddr, __entry->daddr, __entry->mark,
Yafang Shao2d68c072018-05-25 18:14:05 +0800293 __entry->data_len, __entry->snd_nxt, __entry->snd_una,
Masami Hiramatsuc3fde1b2017-12-29 11:45:51 +0900294 __entry->snd_cwnd, __entry->ssthresh, __entry->snd_wnd,
Yafang Shao61638492018-04-20 23:18:26 +0800295 __entry->srtt, __entry->rcv_wnd, __entry->sock_cookie)
Masami Hiramatsuc3fde1b2017-12-29 11:45:51 +0900296);
297
Jakub Kicinski709c0312021-05-14 13:04:25 -0700298#define TP_STORE_ADDR_PORTS_SKB_V4(__entry, skb) \
299 do { \
300 const struct tcphdr *th = (const struct tcphdr *)skb->data; \
301 struct sockaddr_in *v4 = (void *)__entry->saddr; \
302 \
303 v4->sin_family = AF_INET; \
304 v4->sin_port = th->source; \
305 v4->sin_addr.s_addr = ip_hdr(skb)->saddr; \
306 v4 = (void *)__entry->daddr; \
307 v4->sin_family = AF_INET; \
308 v4->sin_port = th->dest; \
309 v4->sin_addr.s_addr = ip_hdr(skb)->daddr; \
310 } while (0)
311
312#if IS_ENABLED(CONFIG_IPV6)
313
314#define TP_STORE_ADDR_PORTS_SKB(__entry, skb) \
315 do { \
316 const struct iphdr *iph = ip_hdr(skb); \
317 \
318 if (iph->version == 6) { \
319 const struct tcphdr *th = (const struct tcphdr *)skb->data; \
320 struct sockaddr_in6 *v6 = (void *)__entry->saddr; \
321 \
322 v6->sin6_family = AF_INET6; \
323 v6->sin6_port = th->source; \
324 v6->sin6_addr = ipv6_hdr(skb)->saddr; \
325 v6 = (void *)__entry->daddr; \
326 v6->sin6_family = AF_INET6; \
327 v6->sin6_port = th->dest; \
328 v6->sin6_addr = ipv6_hdr(skb)->daddr; \
329 } else \
330 TP_STORE_ADDR_PORTS_SKB_V4(__entry, skb); \
331 } while (0)
332
333#else
334
335#define TP_STORE_ADDR_PORTS_SKB(__entry, skb) \
336 TP_STORE_ADDR_PORTS_SKB_V4(__entry, skb)
337
338#endif
339
340/*
341 * tcp event with only skb
342 */
343DECLARE_EVENT_CLASS(tcp_event_skb,
344
345 TP_PROTO(const struct sk_buff *skb),
346
347 TP_ARGS(skb),
348
349 TP_STRUCT__entry(
350 __field(const void *, skbaddr)
351 __array(__u8, saddr, sizeof(struct sockaddr_in6))
352 __array(__u8, daddr, sizeof(struct sockaddr_in6))
353 ),
354
355 TP_fast_assign(
356 __entry->skbaddr = skb;
357
358 memset(__entry->saddr, 0, sizeof(struct sockaddr_in6));
359 memset(__entry->daddr, 0, sizeof(struct sockaddr_in6));
360
361 TP_STORE_ADDR_PORTS_SKB(__entry, skb);
362 ),
363
364 TP_printk("src=%pISpc dest=%pISpc", __entry->saddr, __entry->daddr)
365);
366
367DEFINE_EVENT(tcp_event_skb, tcp_bad_csum,
368
369 TP_PROTO(const struct sk_buff *skb),
370
371 TP_ARGS(skb)
372);
373
Cong Wange0861012017-10-13 13:03:16 -0700374#endif /* _TRACE_TCP_H */
375
376/* This part must be outside protection */
377#include <trace/define_trace.h>