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>
14 #define TP_STORE_V4MAPPED(__entry, saddr, daddr) \
16 struct in6_addr *pin6; \
18 pin6 = (struct in6_addr *)__entry->saddr_v6; \
19 ipv6_addr_set_v4mapped(saddr, pin6); \
20 pin6 = (struct in6_addr *)__entry->daddr_v6; \
21 ipv6_addr_set_v4mapped(daddr, pin6); \
24 #if IS_ENABLED(CONFIG_IPV6)
25 #define TP_STORE_ADDRS(__entry, saddr, daddr, saddr6, daddr6) \
27 if (sk->sk_family == AF_INET6) { \
28 struct in6_addr *pin6; \
30 pin6 = (struct in6_addr *)__entry->saddr_v6; \
32 pin6 = (struct in6_addr *)__entry->daddr_v6; \
35 TP_STORE_V4MAPPED(__entry, saddr, daddr); \
39 #define TP_STORE_ADDRS(__entry, saddr, daddr, saddr6, daddr6) \
40 TP_STORE_V4MAPPED(__entry, saddr, daddr)
44 * tcp event with arguments sk and skb
46 * Note: this class requires a valid sk pointer; while skb pointer could
49 DECLARE_EVENT_CLASS(tcp_event_sk_skb
,
51 TP_PROTO(const struct sock
*sk
, const struct sk_buff
*skb
),
56 __field(const void *, skbaddr
)
57 __field(const void *, skaddr
)
60 __array(__u8
, saddr
, 4)
61 __array(__u8
, daddr
, 4)
62 __array(__u8
, saddr_v6
, 16)
63 __array(__u8
, daddr_v6
, 16)
67 struct inet_sock
*inet
= inet_sk(sk
);
70 __entry
->skbaddr
= skb
;
73 __entry
->sport
= ntohs(inet
->inet_sport
);
74 __entry
->dport
= ntohs(inet
->inet_dport
);
76 p32
= (__be32
*) __entry
->saddr
;
77 *p32
= inet
->inet_saddr
;
79 p32
= (__be32
*) __entry
->daddr
;
80 *p32
= inet
->inet_daddr
;
82 TP_STORE_ADDRS(__entry
, inet
->inet_saddr
, inet
->inet_daddr
,
83 sk
->sk_v6_rcv_saddr
, sk
->sk_v6_daddr
);
86 TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c",
87 __entry
->sport
, __entry
->dport
, __entry
->saddr
, __entry
->daddr
,
88 __entry
->saddr_v6
, __entry
->daddr_v6
)
91 DEFINE_EVENT(tcp_event_sk_skb
, tcp_retransmit_skb
,
93 TP_PROTO(const struct sock
*sk
, const struct sk_buff
*skb
),
99 * skb of trace_tcp_send_reset is the skb that caused RST. In case of
100 * active reset, skb should be NULL
102 DEFINE_EVENT(tcp_event_sk_skb
, tcp_send_reset
,
104 TP_PROTO(const struct sock
*sk
, const struct sk_buff
*skb
),
110 * tcp event with arguments sk
112 * Note: this class requires a valid sk pointer.
114 DECLARE_EVENT_CLASS(tcp_event_sk
,
116 TP_PROTO(const struct sock
*sk
),
121 __field(const void *, skaddr
)
122 __field(__u16
, sport
)
123 __field(__u16
, dport
)
124 __array(__u8
, saddr
, 4)
125 __array(__u8
, daddr
, 4)
126 __array(__u8
, saddr_v6
, 16)
127 __array(__u8
, daddr_v6
, 16)
131 struct inet_sock
*inet
= inet_sk(sk
);
134 __entry
->skaddr
= sk
;
136 __entry
->sport
= ntohs(inet
->inet_sport
);
137 __entry
->dport
= ntohs(inet
->inet_dport
);
139 p32
= (__be32
*) __entry
->saddr
;
140 *p32
= inet
->inet_saddr
;
142 p32
= (__be32
*) __entry
->daddr
;
143 *p32
= inet
->inet_daddr
;
145 TP_STORE_ADDRS(__entry
, inet
->inet_saddr
, inet
->inet_daddr
,
146 sk
->sk_v6_rcv_saddr
, sk
->sk_v6_daddr
);
149 TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c",
150 __entry
->sport
, __entry
->dport
,
151 __entry
->saddr
, __entry
->daddr
,
152 __entry
->saddr_v6
, __entry
->daddr_v6
)
155 DEFINE_EVENT(tcp_event_sk
, tcp_receive_reset
,
157 TP_PROTO(const struct sock
*sk
),
162 DEFINE_EVENT(tcp_event_sk
, tcp_destroy_sock
,
164 TP_PROTO(const struct sock
*sk
),
169 TRACE_EVENT(tcp_set_state
,
171 TP_PROTO(const struct sock
*sk
, const int oldstate
, const int newstate
),
173 TP_ARGS(sk
, oldstate
, newstate
),
176 __field(const void *, skaddr
)
177 __field(int, oldstate
)
178 __field(int, newstate
)
179 __field(__u16
, sport
)
180 __field(__u16
, dport
)
181 __array(__u8
, saddr
, 4)
182 __array(__u8
, daddr
, 4)
183 __array(__u8
, saddr_v6
, 16)
184 __array(__u8
, daddr_v6
, 16)
188 struct inet_sock
*inet
= inet_sk(sk
);
191 __entry
->skaddr
= sk
;
192 __entry
->oldstate
= oldstate
;
193 __entry
->newstate
= newstate
;
195 __entry
->sport
= ntohs(inet
->inet_sport
);
196 __entry
->dport
= ntohs(inet
->inet_dport
);
198 p32
= (__be32
*) __entry
->saddr
;
199 *p32
= inet
->inet_saddr
;
201 p32
= (__be32
*) __entry
->daddr
;
202 *p32
= inet
->inet_daddr
;
204 TP_STORE_ADDRS(__entry
, inet
->inet_saddr
, inet
->inet_daddr
,
205 sk
->sk_v6_rcv_saddr
, sk
->sk_v6_daddr
);
208 TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c oldstate=%s newstate=%s",
209 __entry
->sport
, __entry
->dport
,
210 __entry
->saddr
, __entry
->daddr
,
211 __entry
->saddr_v6
, __entry
->daddr_v6
,
212 show_tcp_state_name(__entry
->oldstate
),
213 show_tcp_state_name(__entry
->newstate
))
216 TRACE_EVENT(tcp_retransmit_synack
,
218 TP_PROTO(const struct sock
*sk
, const struct request_sock
*req
),
223 __field(const void *, skaddr
)
224 __field(const void *, req
)
225 __field(__u16
, sport
)
226 __field(__u16
, dport
)
227 __array(__u8
, saddr
, 4)
228 __array(__u8
, daddr
, 4)
229 __array(__u8
, saddr_v6
, 16)
230 __array(__u8
, daddr_v6
, 16)
234 struct inet_request_sock
*ireq
= inet_rsk(req
);
237 __entry
->skaddr
= sk
;
240 __entry
->sport
= ireq
->ir_num
;
241 __entry
->dport
= ntohs(ireq
->ir_rmt_port
);
243 p32
= (__be32
*) __entry
->saddr
;
244 *p32
= ireq
->ir_loc_addr
;
246 p32
= (__be32
*) __entry
->daddr
;
247 *p32
= ireq
->ir_rmt_addr
;
249 TP_STORE_ADDRS(__entry
, ireq
->ir_loc_addr
, ireq
->ir_rmt_addr
,
250 ireq
->ir_v6_loc_addr
, ireq
->ir_v6_rmt_addr
);
253 TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c",
254 __entry
->sport
, __entry
->dport
,
255 __entry
->saddr
, __entry
->daddr
,
256 __entry
->saddr_v6
, __entry
->daddr_v6
)
259 #include <trace/events/net_probe_common.h>
261 TRACE_EVENT(tcp_probe
,
263 TP_PROTO(struct sock
*sk
, struct sk_buff
*skb
),
268 /* sockaddr_in6 is always bigger than sockaddr_in */
269 __array(__u8
, saddr
, sizeof(struct sockaddr_in6
))
270 __array(__u8
, daddr
, sizeof(struct sockaddr_in6
))
271 __field(__u16
, sport
)
272 __field(__u16
, dport
)
274 __field(__u16
, length
)
275 __field(__u32
, snd_nxt
)
276 __field(__u32
, snd_una
)
277 __field(__u32
, snd_cwnd
)
278 __field(__u32
, ssthresh
)
279 __field(__u32
, snd_wnd
)
281 __field(__u32
, rcv_wnd
)
285 const struct tcp_sock
*tp
= tcp_sk(sk
);
286 const struct inet_sock
*inet
= inet_sk(sk
);
288 memset(__entry
->saddr
, 0, sizeof(struct sockaddr_in6
));
289 memset(__entry
->daddr
, 0, sizeof(struct sockaddr_in6
));
291 TP_STORE_ADDR_PORTS(__entry
, inet
, sk
);
293 /* For filtering use */
294 __entry
->sport
= ntohs(inet
->inet_sport
);
295 __entry
->dport
= ntohs(inet
->inet_dport
);
296 __entry
->mark
= skb
->mark
;
298 __entry
->length
= skb
->len
;
299 __entry
->snd_nxt
= tp
->snd_nxt
;
300 __entry
->snd_una
= tp
->snd_una
;
301 __entry
->snd_cwnd
= tp
->snd_cwnd
;
302 __entry
->snd_wnd
= tp
->snd_wnd
;
303 __entry
->rcv_wnd
= tp
->rcv_wnd
;
304 __entry
->ssthresh
= tcp_current_ssthresh(sk
);
305 __entry
->srtt
= tp
->srtt_us
>> 3;
308 TP_printk("src=%pISpc dest=%pISpc mark=%#x length=%d snd_nxt=%#x "
309 "snd_una=%#x snd_cwnd=%u ssthresh=%u snd_wnd=%u srtt=%u "
311 __entry
->saddr
, __entry
->daddr
, __entry
->mark
,
312 __entry
->length
, __entry
->snd_nxt
, __entry
->snd_una
,
313 __entry
->snd_cwnd
, __entry
->ssthresh
, __entry
->snd_wnd
,
314 __entry
->srtt
, __entry
->rcv_wnd
)
317 #endif /* _TRACE_TCP_H */
319 /* This part must be outside protection */
320 #include <trace/define_trace.h>