]>
Commit | Line | Data |
---|---|---|
c3fde1bd | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
e086101b CW |
2 | #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> | |
c3fde1bd | 12 | #include <net/tcp.h> |
6163849d | 13 | #include <linux/sock_diag.h> |
e086101b | 14 | |
6a6b0b99 MM |
15 | #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 | ||
f6e37b25 SL |
44 | /* |
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 | */ | |
50 | DECLARE_EVENT_CLASS(tcp_event_sk_skb, | |
e086101b | 51 | |
7344e29f | 52 | TP_PROTO(const struct sock *sk, const struct sk_buff *skb), |
e086101b CW |
53 | |
54 | TP_ARGS(sk, skb), | |
55 | ||
56 | TP_STRUCT__entry( | |
7344e29f SL |
57 | __field(const void *, skbaddr) |
58 | __field(const void *, skaddr) | |
af4325ec | 59 | __field(int, state) |
e086101b CW |
60 | __field(__u16, sport) |
61 | __field(__u16, dport) | |
3dd344ea | 62 | __field(__u16, family) |
e086101b CW |
63 | __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( | |
e086101b | 70 | struct inet_sock *inet = inet_sk(sk); |
e086101b CW |
71 | __be32 *p32; |
72 | ||
73 | __entry->skbaddr = skb; | |
74 | __entry->skaddr = sk; | |
af4325ec | 75 | __entry->state = sk->sk_state; |
e086101b CW |
76 | |
77 | __entry->sport = ntohs(inet->inet_sport); | |
78 | __entry->dport = ntohs(inet->inet_dport); | |
3dd344ea | 79 | __entry->family = sk->sk_family; |
e086101b CW |
80 | |
81 | p32 = (__be32 *) __entry->saddr; | |
82 | *p32 = inet->inet_saddr; | |
83 | ||
84 | p32 = (__be32 *) __entry->daddr; | |
85 | *p32 = inet->inet_daddr; | |
86 | ||
6a6b0b99 MM |
87 | TP_STORE_ADDRS(__entry, inet->inet_saddr, inet->inet_daddr, |
88 | sk->sk_v6_rcv_saddr, sk->sk_v6_daddr); | |
e086101b CW |
89 | ), |
90 | ||
3dd344ea HA |
91 | TP_printk("family=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c state=%s", |
92 | show_family_name(__entry->family), | |
e086101b | 93 | __entry->sport, __entry->dport, __entry->saddr, __entry->daddr, |
af4325ec YS |
94 | __entry->saddr_v6, __entry->daddr_v6, |
95 | show_tcp_state_name(__entry->state)) | |
e086101b CW |
96 | ); |
97 | ||
f6e37b25 SL |
98 | DEFINE_EVENT(tcp_event_sk_skb, tcp_retransmit_skb, |
99 | ||
7344e29f | 100 | TP_PROTO(const struct sock *sk, const struct sk_buff *skb), |
f6e37b25 SL |
101 | |
102 | TP_ARGS(sk, skb) | |
103 | ); | |
104 | ||
c24b14c4 SL |
105 | /* |
106 | * skb of trace_tcp_send_reset is the skb that caused RST. In case of | |
107 | * active reset, skb should be NULL | |
108 | */ | |
109 | DEFINE_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 | ||
5941521c SL |
116 | /* |
117 | * tcp event with arguments sk | |
118 | * | |
119 | * Note: this class requires a valid sk pointer. | |
120 | */ | |
121 | DECLARE_EVENT_CLASS(tcp_event_sk, | |
122 | ||
6163849d | 123 | TP_PROTO(struct sock *sk), |
5941521c SL |
124 | |
125 | TP_ARGS(sk), | |
126 | ||
127 | TP_STRUCT__entry( | |
128 | __field(const void *, skaddr) | |
129 | __field(__u16, sport) | |
130 | __field(__u16, dport) | |
3dd344ea | 131 | __field(__u16, family) |
5941521c SL |
132 | __array(__u8, saddr, 4) |
133 | __array(__u8, daddr, 4) | |
134 | __array(__u8, saddr_v6, 16) | |
135 | __array(__u8, daddr_v6, 16) | |
6163849d | 136 | __field(__u64, sock_cookie) |
5941521c SL |
137 | ), |
138 | ||
139 | TP_fast_assign( | |
140 | struct inet_sock *inet = inet_sk(sk); | |
5941521c SL |
141 | __be32 *p32; |
142 | ||
143 | __entry->skaddr = sk; | |
144 | ||
145 | __entry->sport = ntohs(inet->inet_sport); | |
146 | __entry->dport = ntohs(inet->inet_dport); | |
3dd344ea | 147 | __entry->family = sk->sk_family; |
5941521c SL |
148 | |
149 | p32 = (__be32 *) __entry->saddr; | |
150 | *p32 = inet->inet_saddr; | |
151 | ||
152 | p32 = (__be32 *) __entry->daddr; | |
153 | *p32 = inet->inet_daddr; | |
154 | ||
6a6b0b99 MM |
155 | TP_STORE_ADDRS(__entry, inet->inet_saddr, inet->inet_daddr, |
156 | sk->sk_v6_rcv_saddr, sk->sk_v6_daddr); | |
6163849d YS |
157 | |
158 | __entry->sock_cookie = sock_gen_cookie(sk); | |
5941521c SL |
159 | ), |
160 | ||
3dd344ea HA |
161 | 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), | |
5941521c SL |
163 | __entry->sport, __entry->dport, |
164 | __entry->saddr, __entry->daddr, | |
6163849d YS |
165 | __entry->saddr_v6, __entry->daddr_v6, |
166 | __entry->sock_cookie) | |
5941521c SL |
167 | ); |
168 | ||
169 | DEFINE_EVENT(tcp_event_sk, tcp_receive_reset, | |
170 | ||
6163849d | 171 | TP_PROTO(struct sock *sk), |
5941521c SL |
172 | |
173 | TP_ARGS(sk) | |
174 | ); | |
175 | ||
e1a4aa50 SL |
176 | DEFINE_EVENT(tcp_event_sk, tcp_destroy_sock, |
177 | ||
6163849d YS |
178 | TP_PROTO(struct sock *sk), |
179 | ||
180 | TP_ARGS(sk) | |
181 | ); | |
182 | ||
183 | DEFINE_EVENT(tcp_event_sk, tcp_rcv_space_adjust, | |
184 | ||
185 | TP_PROTO(struct sock *sk), | |
e1a4aa50 SL |
186 | |
187 | TP_ARGS(sk) | |
188 | ); | |
189 | ||
cf34ce3d SL |
190 | TRACE_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) | |
3dd344ea | 201 | __field(__u16, family) |
cf34ce3d SL |
202 | __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); | |
cf34ce3d SL |
210 | __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); | |
3dd344ea | 217 | __entry->family = sk->sk_family; |
cf34ce3d SL |
218 | |
219 | p32 = (__be32 *) __entry->saddr; | |
220 | *p32 = ireq->ir_loc_addr; | |
221 | ||
222 | p32 = (__be32 *) __entry->daddr; | |
223 | *p32 = ireq->ir_rmt_addr; | |
224 | ||
6a6b0b99 MM |
225 | TP_STORE_ADDRS(__entry, ireq->ir_loc_addr, ireq->ir_rmt_addr, |
226 | ireq->ir_v6_loc_addr, ireq->ir_v6_rmt_addr); | |
cf34ce3d SL |
227 | ), |
228 | ||
3dd344ea HA |
229 | TP_printk("family=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c", |
230 | show_family_name(__entry->family), | |
cf34ce3d SL |
231 | __entry->sport, __entry->dport, |
232 | __entry->saddr, __entry->daddr, | |
233 | __entry->saddr_v6, __entry->daddr_v6) | |
234 | ); | |
235 | ||
ee549be6 | 236 | #include <trace/events/net_probe_common.h> |
c3fde1bd MH |
237 | |
238 | TRACE_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) | |
3dd344ea | 250 | __field(__u16, family) |
c3fde1bd | 251 | __field(__u32, mark) |
2d68c074 | 252 | __field(__u16, data_len) |
c3fde1bd MH |
253 | __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) | |
6163849d | 260 | __field(__u64, sock_cookie) |
c3fde1bd MH |
261 | ), |
262 | ||
263 | TP_fast_assign( | |
3d97d88e | 264 | const struct tcphdr *th = (const struct tcphdr *)skb->data; |
c3fde1bd | 265 | const struct inet_sock *inet = inet_sk(sk); |
3d97d88e | 266 | const struct tcp_sock *tp = tcp_sk(sk); |
c3fde1bd MH |
267 | |
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; | |
3dd344ea | 277 | __entry->family = sk->sk_family; |
c3fde1bd | 278 | |
3d97d88e | 279 | __entry->data_len = skb->len - __tcp_hdrlen(th); |
c3fde1bd MH |
280 | __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; | |
6163849d | 287 | __entry->sock_cookie = sock_gen_cookie(sk); |
c3fde1bd MH |
288 | ), |
289 | ||
3dd344ea HA |
290 | 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), | |
c3fde1bd | 292 | __entry->saddr, __entry->daddr, __entry->mark, |
2d68c074 | 293 | __entry->data_len, __entry->snd_nxt, __entry->snd_una, |
c3fde1bd | 294 | __entry->snd_cwnd, __entry->ssthresh, __entry->snd_wnd, |
6163849d | 295 | __entry->srtt, __entry->rcv_wnd, __entry->sock_cookie) |
c3fde1bd MH |
296 | ); |
297 | ||
709c0314 JK |
298 | #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 | */ | |
343 | DECLARE_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 | ||
367 | DEFINE_EVENT(tcp_event_skb, tcp_bad_csum, | |
368 | ||
369 | TP_PROTO(const struct sk_buff *skb), | |
370 | ||
371 | TP_ARGS(skb) | |
372 | ); | |
373 | ||
e086101b CW |
374 | #endif /* _TRACE_TCP_H */ |
375 | ||
376 | /* This part must be outside protection */ | |
377 | #include <trace/define_trace.h> |