1 /* SPDX-License-Identifier: GPL-2.0 */
3 #define TRACE_SYSTEM tcp
5 #if !defined(_TRACE_TCP_H) || defined(TRACE_HEADER_MULTI_READ)
8 #include <linux/ipv6.h>
10 #include <linux/tracepoint.h>
13 #include <linux/sock_diag.h>
15 #define TP_STORE_V4MAPPED(__entry, saddr, daddr) \
17 struct in6_addr *pin6; \
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); \
25 #if IS_ENABLED(CONFIG_IPV6)
26 #define TP_STORE_ADDRS(__entry, saddr, daddr, saddr6, daddr6) \
28 if (sk->sk_family == AF_INET6) { \
29 struct in6_addr *pin6; \
31 pin6 = (struct in6_addr *)__entry->saddr_v6; \
33 pin6 = (struct in6_addr *)__entry->daddr_v6; \
36 TP_STORE_V4MAPPED(__entry, saddr, daddr); \
40 #define TP_STORE_ADDRS(__entry, saddr, daddr, saddr6, daddr6) \
41 TP_STORE_V4MAPPED(__entry, saddr, daddr)
45 * tcp event with arguments sk and skb
47 * Note: this class requires a valid sk pointer; while skb pointer could
50 DECLARE_EVENT_CLASS(tcp_event_sk_skb,
52 TP_PROTO(const struct sock *sk, const struct sk_buff *skb),
57 __field(const void *, skbaddr)
58 __field(const void *, skaddr)
62 __field(__u16, family)
63 __array(__u8, saddr, 4)
64 __array(__u8, daddr, 4)
65 __array(__u8, saddr_v6, 16)
66 __array(__u8, daddr_v6, 16)
70 const struct inet_sock *inet = inet_sk(sk);
73 __entry->skbaddr = skb;
75 __entry->state = sk->sk_state;
77 __entry->sport = ntohs(inet->inet_sport);
78 __entry->dport = ntohs(inet->inet_dport);
79 __entry->family = sk->sk_family;
81 p32 = (__be32 *) __entry->saddr;
82 *p32 = inet->inet_saddr;
84 p32 = (__be32 *) __entry->daddr;
85 *p32 = inet->inet_daddr;
87 TP_STORE_ADDRS(__entry, inet->inet_saddr, inet->inet_daddr,
88 sk->sk_v6_rcv_saddr, sk->sk_v6_daddr);
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),
93 __entry->sport, __entry->dport, __entry->saddr, __entry->daddr,
94 __entry->saddr_v6, __entry->daddr_v6,
95 show_tcp_state_name(__entry->state))
98 DEFINE_EVENT(tcp_event_sk_skb, tcp_retransmit_skb,
100 TP_PROTO(const struct sock *sk, const struct sk_buff *skb),
106 * skb of trace_tcp_send_reset is the skb that caused RST. In case of
107 * active reset, skb should be NULL
109 DEFINE_EVENT(tcp_event_sk_skb, tcp_send_reset,
111 TP_PROTO(const struct sock *sk, const struct sk_buff *skb),
117 * tcp event with arguments sk
119 * Note: this class requires a valid sk pointer.
121 DECLARE_EVENT_CLASS(tcp_event_sk,
123 TP_PROTO(struct sock *sk),
128 __field(const void *, skaddr)
129 __field(__u16, sport)
130 __field(__u16, dport)
131 __field(__u16, family)
132 __array(__u8, saddr, 4)
133 __array(__u8, daddr, 4)
134 __array(__u8, saddr_v6, 16)
135 __array(__u8, daddr_v6, 16)
136 __field(__u64, sock_cookie)
140 struct inet_sock *inet = inet_sk(sk);
143 __entry->skaddr = sk;
145 __entry->sport = ntohs(inet->inet_sport);
146 __entry->dport = ntohs(inet->inet_dport);
147 __entry->family = sk->sk_family;
149 p32 = (__be32 *) __entry->saddr;
150 *p32 = inet->inet_saddr;
152 p32 = (__be32 *) __entry->daddr;
153 *p32 = inet->inet_daddr;
155 TP_STORE_ADDRS(__entry, inet->inet_saddr, inet->inet_daddr,
156 sk->sk_v6_rcv_saddr, sk->sk_v6_daddr);
158 __entry->sock_cookie = sock_gen_cookie(sk);
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),
163 __entry->sport, __entry->dport,
164 __entry->saddr, __entry->daddr,
165 __entry->saddr_v6, __entry->daddr_v6,
166 __entry->sock_cookie)
169 DEFINE_EVENT(tcp_event_sk, tcp_receive_reset,
171 TP_PROTO(struct sock *sk),
176 DEFINE_EVENT(tcp_event_sk, tcp_destroy_sock,
178 TP_PROTO(struct sock *sk),
183 DEFINE_EVENT(tcp_event_sk, tcp_rcv_space_adjust,
185 TP_PROTO(struct sock *sk),
190 TRACE_EVENT(tcp_retransmit_synack,
192 TP_PROTO(const struct sock *sk, const struct request_sock *req),
197 __field(const void *, skaddr)
198 __field(const void *, req)
199 __field(__u16, sport)
200 __field(__u16, dport)
201 __field(__u16, family)
202 __array(__u8, saddr, 4)
203 __array(__u8, daddr, 4)
204 __array(__u8, saddr_v6, 16)
205 __array(__u8, daddr_v6, 16)
209 struct inet_request_sock *ireq = inet_rsk(req);
212 __entry->skaddr = sk;
215 __entry->sport = ireq->ir_num;
216 __entry->dport = ntohs(ireq->ir_rmt_port);
217 __entry->family = sk->sk_family;
219 p32 = (__be32 *) __entry->saddr;
220 *p32 = ireq->ir_loc_addr;
222 p32 = (__be32 *) __entry->daddr;
223 *p32 = ireq->ir_rmt_addr;
225 TP_STORE_ADDRS(__entry, ireq->ir_loc_addr, ireq->ir_rmt_addr,
226 ireq->ir_v6_loc_addr, ireq->ir_v6_rmt_addr);
229 TP_printk("family=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c",
230 show_family_name(__entry->family),
231 __entry->sport, __entry->dport,
232 __entry->saddr, __entry->daddr,
233 __entry->saddr_v6, __entry->daddr_v6)
236 #include <trace/events/net_probe_common.h>
238 TRACE_EVENT(tcp_probe,
240 TP_PROTO(struct sock *sk, struct sk_buff *skb),
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)
250 __field(__u16, family)
252 __field(__u16, data_len)
253 __field(__u32, snd_nxt)
254 __field(__u32, snd_una)
255 __field(__u32, snd_cwnd)
256 __field(__u32, ssthresh)
257 __field(__u32, snd_wnd)
259 __field(__u32, rcv_wnd)
260 __field(__u64, sock_cookie)
264 const struct tcphdr *th = (const struct tcphdr *)skb->data;
265 const struct inet_sock *inet = inet_sk(sk);
266 const struct tcp_sock *tp = tcp_sk(sk);
268 memset(__entry->saddr, 0, sizeof(struct sockaddr_in6));
269 memset(__entry->daddr, 0, sizeof(struct sockaddr_in6));
271 TP_STORE_ADDR_PORTS(__entry, inet, sk);
273 /* For filtering use */
274 __entry->sport = ntohs(inet->inet_sport);
275 __entry->dport = ntohs(inet->inet_dport);
276 __entry->mark = skb->mark;
277 __entry->family = sk->sk_family;
279 __entry->data_len = skb->len - __tcp_hdrlen(th);
280 __entry->snd_nxt = tp->snd_nxt;
281 __entry->snd_una = tp->snd_una;
282 __entry->snd_cwnd = tcp_snd_cwnd(tp);
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;
287 __entry->sock_cookie = sock_gen_cookie(sk);
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),
292 __entry->saddr, __entry->daddr, __entry->mark,
293 __entry->data_len, __entry->snd_nxt, __entry->snd_una,
294 __entry->snd_cwnd, __entry->ssthresh, __entry->snd_wnd,
295 __entry->srtt, __entry->rcv_wnd, __entry->sock_cookie)
298 #define TP_STORE_ADDR_PORTS_SKB_V4(__entry, skb) \
300 const struct tcphdr *th = (const struct tcphdr *)skb->data; \
301 struct sockaddr_in *v4 = (void *)__entry->saddr; \
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; \
312 #if IS_ENABLED(CONFIG_IPV6)
314 #define TP_STORE_ADDR_PORTS_SKB(__entry, skb) \
316 const struct iphdr *iph = ip_hdr(skb); \
318 if (iph->version == 6) { \
319 const struct tcphdr *th = (const struct tcphdr *)skb->data; \
320 struct sockaddr_in6 *v6 = (void *)__entry->saddr; \
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; \
330 TP_STORE_ADDR_PORTS_SKB_V4(__entry, skb); \
335 #define TP_STORE_ADDR_PORTS_SKB(__entry, skb) \
336 TP_STORE_ADDR_PORTS_SKB_V4(__entry, skb)
341 * tcp event with only skb
343 DECLARE_EVENT_CLASS(tcp_event_skb,
345 TP_PROTO(const struct sk_buff *skb),
350 __field(const void *, skbaddr)
351 __array(__u8, saddr, sizeof(struct sockaddr_in6))
352 __array(__u8, daddr, sizeof(struct sockaddr_in6))
356 __entry->skbaddr = skb;
358 memset(__entry->saddr, 0, sizeof(struct sockaddr_in6));
359 memset(__entry->daddr, 0, sizeof(struct sockaddr_in6));
361 TP_STORE_ADDR_PORTS_SKB(__entry, skb);
364 TP_printk("src=%pISpc dest=%pISpc", __entry->saddr, __entry->daddr)
367 DEFINE_EVENT(tcp_event_skb, tcp_bad_csum,
369 TP_PROTO(const struct sk_buff *skb),
374 TRACE_EVENT(tcp_cong_state_set,
376 TP_PROTO(struct sock *sk, const u8 ca_state),
378 TP_ARGS(sk, ca_state),
381 __field(const void *, skaddr)
382 __field(__u16, sport)
383 __field(__u16, dport)
384 __field(__u16, family)
385 __array(__u8, saddr, 4)
386 __array(__u8, daddr, 4)
387 __array(__u8, saddr_v6, 16)
388 __array(__u8, daddr_v6, 16)
389 __field(__u8, cong_state)
393 struct inet_sock *inet = inet_sk(sk);
396 __entry->skaddr = sk;
398 __entry->sport = ntohs(inet->inet_sport);
399 __entry->dport = ntohs(inet->inet_dport);
400 __entry->family = sk->sk_family;
402 p32 = (__be32 *) __entry->saddr;
403 *p32 = inet->inet_saddr;
405 p32 = (__be32 *) __entry->daddr;
406 *p32 = inet->inet_daddr;
408 TP_STORE_ADDRS(__entry, inet->inet_saddr, inet->inet_daddr,
409 sk->sk_v6_rcv_saddr, sk->sk_v6_daddr);
411 __entry->cong_state = ca_state;
414 TP_printk("family=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c cong_state=%u",
415 show_family_name(__entry->family),
416 __entry->sport, __entry->dport,
417 __entry->saddr, __entry->daddr,
418 __entry->saddr_v6, __entry->daddr_v6,
422 #endif /* _TRACE_TCP_H */
424 /* This part must be outside protection */
425 #include <trace/define_trace.h>