1 /* SPDX-License-Identifier: GPL-2.0 */ 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> 12 #include <net/tcp.h> 13 #include <linux/sock_diag.h> 14 #include <net/rstreason.h> 15 16 /* 17 * tcp event with arguments sk and skb 18 * 19 * Note: this class requires a valid sk pointer; while skb pointer could 20 * be NULL. 21 */ 22 DECLARE_EVENT_CLASS(tcp_event_sk_skb, 23 24 TP_PROTO(const struct sock *sk, const struct sk_buff *skb), 25 26 TP_ARGS(sk, skb), 27 28 TP_STRUCT__entry( 29 __field(const void *, skbaddr) 30 __field(const void *, skaddr) 31 __field(int, state) 32 __field(__u16, sport) 33 __field(__u16, dport) 34 __field(__u16, family) 35 __array(__u8, saddr, 4) 36 __array(__u8, daddr, 4) 37 __array(__u8, saddr_v6, 16) 38 __array(__u8, daddr_v6, 16) 39 ), 40 41 TP_fast_assign( 42 const struct inet_sock *inet = inet_sk(sk); 43 __be32 *p32; 44 45 __entry->skbaddr = skb; 46 __entry->skaddr = sk; 47 __entry->state = sk->sk_state; 48 49 __entry->sport = ntohs(inet->inet_sport); 50 __entry->dport = ntohs(inet->inet_dport); 51 __entry->family = sk->sk_family; 52 53 p32 = (__be32 *) __entry->saddr; 54 *p32 = inet->inet_saddr; 55 56 p32 = (__be32 *) __entry->daddr; 57 *p32 = inet->inet_daddr; 58 59 TP_STORE_ADDRS(__entry, inet->inet_saddr, inet->inet_daddr, 60 sk->sk_v6_rcv_saddr, sk->sk_v6_daddr); 61 ), 62 63 TP_printk("skbaddr=%p skaddr=%p family=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c state=%s", 64 __entry->skbaddr, __entry->skaddr, 65 show_family_name(__entry->family), 66 __entry->sport, __entry->dport, __entry->saddr, __entry->daddr, 67 __entry->saddr_v6, __entry->daddr_v6, 68 show_tcp_state_name(__entry->state)) 69 ); 70 71 DEFINE_EVENT(tcp_event_sk_skb, tcp_retransmit_skb, 72 73 TP_PROTO(const struct sock *sk, const struct sk_buff *skb), 74 75 TP_ARGS(sk, skb) 76 ); 77 78 #undef FN 79 #define FN(reason) TRACE_DEFINE_ENUM(SK_RST_REASON_##reason); 80 DEFINE_RST_REASON(FN, FN) 81 82 #undef FN 83 #undef FNe 84 #define FN(reason) { SK_RST_REASON_##reason, #reason }, 85 #define FNe(reason) { SK_RST_REASON_##reason, #reason } 86 87 /* 88 * skb of trace_tcp_send_reset is the skb that caused RST. In case of 89 * active reset, skb should be NULL 90 */ 91 TRACE_EVENT(tcp_send_reset, 92 93 TP_PROTO(const struct sock *sk, 94 const struct sk_buff *skb, 95 const enum sk_rst_reason reason), 96 97 TP_ARGS(sk, skb, reason), 98 99 TP_STRUCT__entry( 100 __field(const void *, skbaddr) 101 __field(const void *, skaddr) 102 __field(int, state) 103 __field(enum sk_rst_reason, reason) 104 __array(__u8, saddr, sizeof(struct sockaddr_in6)) 105 __array(__u8, daddr, sizeof(struct sockaddr_in6)) 106 ), 107 108 TP_fast_assign( 109 __entry->skbaddr = skb; 110 __entry->skaddr = sk; 111 /* Zero means unknown state. */ 112 __entry->state = sk ? sk->sk_state : 0; 113 114 memset(__entry->saddr, 0, sizeof(struct sockaddr_in6)); 115 memset(__entry->daddr, 0, sizeof(struct sockaddr_in6)); 116 117 if (sk && sk_fullsock(sk)) { 118 const struct inet_sock *inet = inet_sk(sk); 119 120 TP_STORE_ADDR_PORTS(__entry, inet, sk); 121 } else if (skb) { 122 const struct tcphdr *th = (const struct tcphdr *)skb->data; 123 /* 124 * We should reverse the 4-tuple of skb, so later 125 * it can print the right flow direction of rst. 126 */ 127 TP_STORE_ADDR_PORTS_SKB(skb, th, entry->daddr, entry->saddr); 128 } 129 __entry->reason = reason; 130 ), 131 132 TP_printk("skbaddr=%p skaddr=%p src=%pISpc dest=%pISpc state=%s reason=%s", 133 __entry->skbaddr, __entry->skaddr, 134 __entry->saddr, __entry->daddr, 135 __entry->state ? show_tcp_state_name(__entry->state) : "UNKNOWN", 136 __print_symbolic(__entry->reason, DEFINE_RST_REASON(FN, FNe))) 137 ); 138 139 #undef FN 140 #undef FNe 141 142 /* 143 * tcp event with arguments sk 144 * 145 * Note: this class requires a valid sk pointer. 146 */ 147 DECLARE_EVENT_CLASS(tcp_event_sk, 148 149 TP_PROTO(struct sock *sk), 150 151 TP_ARGS(sk), 152 153 TP_STRUCT__entry( 154 __field(const void *, skaddr) 155 __field(__u16, sport) 156 __field(__u16, dport) 157 __field(__u16, family) 158 __array(__u8, saddr, 4) 159 __array(__u8, daddr, 4) 160 __array(__u8, saddr_v6, 16) 161 __array(__u8, daddr_v6, 16) 162 __field(__u64, sock_cookie) 163 ), 164 165 TP_fast_assign( 166 struct inet_sock *inet = inet_sk(sk); 167 __be32 *p32; 168 169 __entry->skaddr = sk; 170 171 __entry->sport = ntohs(inet->inet_sport); 172 __entry->dport = ntohs(inet->inet_dport); 173 __entry->family = sk->sk_family; 174 175 p32 = (__be32 *) __entry->saddr; 176 *p32 = inet->inet_saddr; 177 178 p32 = (__be32 *) __entry->daddr; 179 *p32 = inet->inet_daddr; 180 181 TP_STORE_ADDRS(__entry, inet->inet_saddr, inet->inet_daddr, 182 sk->sk_v6_rcv_saddr, sk->sk_v6_daddr); 183 184 __entry->sock_cookie = sock_gen_cookie(sk); 185 ), 186 187 TP_printk("family=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c sock_cookie=%llx", 188 show_family_name(__entry->family), 189 __entry->sport, __entry->dport, 190 __entry->saddr, __entry->daddr, 191 __entry->saddr_v6, __entry->daddr_v6, 192 __entry->sock_cookie) 193 ); 194 195 DEFINE_EVENT(tcp_event_sk, tcp_receive_reset, 196 197 TP_PROTO(struct sock *sk), 198 199 TP_ARGS(sk) 200 ); 201 202 DEFINE_EVENT(tcp_event_sk, tcp_destroy_sock, 203 204 TP_PROTO(struct sock *sk), 205 206 TP_ARGS(sk) 207 ); 208 209 DEFINE_EVENT(tcp_event_sk, tcp_rcv_space_adjust, 210 211 TP_PROTO(struct sock *sk), 212 213 TP_ARGS(sk) 214 ); 215 216 TRACE_EVENT(tcp_retransmit_synack, 217 218 TP_PROTO(const struct sock *sk, const struct request_sock *req), 219 220 TP_ARGS(sk, req), 221 222 TP_STRUCT__entry( 223 __field(const void *, skaddr) 224 __field(const void *, req) 225 __field(__u16, sport) 226 __field(__u16, dport) 227 __field(__u16, family) 228 __array(__u8, saddr, 4) 229 __array(__u8, daddr, 4) 230 __array(__u8, saddr_v6, 16) 231 __array(__u8, daddr_v6, 16) 232 ), 233 234 TP_fast_assign( 235 struct inet_request_sock *ireq = inet_rsk(req); 236 __be32 *p32; 237 238 __entry->skaddr = sk; 239 __entry->req = req; 240 241 __entry->sport = ireq->ir_num; 242 __entry->dport = ntohs(ireq->ir_rmt_port); 243 __entry->family = sk->sk_family; 244 245 p32 = (__be32 *) __entry->saddr; 246 *p32 = ireq->ir_loc_addr; 247 248 p32 = (__be32 *) __entry->daddr; 249 *p32 = ireq->ir_rmt_addr; 250 251 TP_STORE_ADDRS(__entry, ireq->ir_loc_addr, ireq->ir_rmt_addr, 252 ireq->ir_v6_loc_addr, ireq->ir_v6_rmt_addr); 253 ), 254 255 TP_printk("family=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c", 256 show_family_name(__entry->family), 257 __entry->sport, __entry->dport, 258 __entry->saddr, __entry->daddr, 259 __entry->saddr_v6, __entry->daddr_v6) 260 ); 261 262 #include <trace/events/net_probe_common.h> 263 264 TRACE_EVENT(tcp_probe, 265 266 TP_PROTO(struct sock *sk, struct sk_buff *skb), 267 268 TP_ARGS(sk, skb), 269 270 TP_STRUCT__entry( 271 /* sockaddr_in6 is always bigger than sockaddr_in */ 272 __array(__u8, saddr, sizeof(struct sockaddr_in6)) 273 __array(__u8, daddr, sizeof(struct sockaddr_in6)) 274 __field(__u16, sport) 275 __field(__u16, dport) 276 __field(__u16, family) 277 __field(__u32, mark) 278 __field(__u16, data_len) 279 __field(__u32, snd_nxt) 280 __field(__u32, snd_una) 281 __field(__u32, snd_cwnd) 282 __field(__u32, ssthresh) 283 __field(__u32, snd_wnd) 284 __field(__u32, srtt) 285 __field(__u32, rcv_wnd) 286 __field(__u64, sock_cookie) 287 __field(const void *, skbaddr) 288 __field(const void *, skaddr) 289 ), 290 291 TP_fast_assign( 292 const struct tcphdr *th = (const struct tcphdr *)skb->data; 293 const struct inet_sock *inet = inet_sk(sk); 294 const struct tcp_sock *tp = tcp_sk(sk); 295 296 memset(__entry->saddr, 0, sizeof(struct sockaddr_in6)); 297 memset(__entry->daddr, 0, sizeof(struct sockaddr_in6)); 298 299 TP_STORE_ADDR_PORTS(__entry, inet, sk); 300 301 /* For filtering use */ 302 __entry->sport = ntohs(inet->inet_sport); 303 __entry->dport = ntohs(inet->inet_dport); 304 __entry->mark = skb->mark; 305 __entry->family = sk->sk_family; 306 307 __entry->data_len = skb->len - __tcp_hdrlen(th); 308 __entry->snd_nxt = tp->snd_nxt; 309 __entry->snd_una = tp->snd_una; 310 __entry->snd_cwnd = tcp_snd_cwnd(tp); 311 __entry->snd_wnd = tp->snd_wnd; 312 __entry->rcv_wnd = tp->rcv_wnd; 313 __entry->ssthresh = tcp_current_ssthresh(sk); 314 __entry->srtt = tp->srtt_us >> 3; 315 __entry->sock_cookie = sock_gen_cookie(sk); 316 317 __entry->skbaddr = skb; 318 __entry->skaddr = sk; 319 ), 320 321 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 skbaddr=%p skaddr=%p", 322 show_family_name(__entry->family), 323 __entry->saddr, __entry->daddr, __entry->mark, 324 __entry->data_len, __entry->snd_nxt, __entry->snd_una, 325 __entry->snd_cwnd, __entry->ssthresh, __entry->snd_wnd, 326 __entry->srtt, __entry->rcv_wnd, __entry->sock_cookie, 327 __entry->skbaddr, __entry->skaddr) 328 ); 329 330 /* 331 * tcp event with only skb 332 */ 333 DECLARE_EVENT_CLASS(tcp_event_skb, 334 335 TP_PROTO(const struct sk_buff *skb), 336 337 TP_ARGS(skb), 338 339 TP_STRUCT__entry( 340 __field(const void *, skbaddr) 341 __array(__u8, saddr, sizeof(struct sockaddr_in6)) 342 __array(__u8, daddr, sizeof(struct sockaddr_in6)) 343 ), 344 345 TP_fast_assign( 346 const struct tcphdr *th = (const struct tcphdr *)skb->data; 347 __entry->skbaddr = skb; 348 349 memset(__entry->saddr, 0, sizeof(struct sockaddr_in6)); 350 memset(__entry->daddr, 0, sizeof(struct sockaddr_in6)); 351 352 TP_STORE_ADDR_PORTS_SKB(skb, th, __entry->saddr, __entry->daddr); 353 ), 354 355 TP_printk("skbaddr=%p src=%pISpc dest=%pISpc", 356 __entry->skbaddr, __entry->saddr, __entry->daddr) 357 ); 358 359 DEFINE_EVENT(tcp_event_skb, tcp_bad_csum, 360 361 TP_PROTO(const struct sk_buff *skb), 362 363 TP_ARGS(skb) 364 ); 365 366 TRACE_EVENT(tcp_cong_state_set, 367 368 TP_PROTO(struct sock *sk, const u8 ca_state), 369 370 TP_ARGS(sk, ca_state), 371 372 TP_STRUCT__entry( 373 __field(const void *, skaddr) 374 __field(__u16, sport) 375 __field(__u16, dport) 376 __field(__u16, family) 377 __array(__u8, saddr, 4) 378 __array(__u8, daddr, 4) 379 __array(__u8, saddr_v6, 16) 380 __array(__u8, daddr_v6, 16) 381 __field(__u8, cong_state) 382 ), 383 384 TP_fast_assign( 385 struct inet_sock *inet = inet_sk(sk); 386 __be32 *p32; 387 388 __entry->skaddr = sk; 389 390 __entry->sport = ntohs(inet->inet_sport); 391 __entry->dport = ntohs(inet->inet_dport); 392 __entry->family = sk->sk_family; 393 394 p32 = (__be32 *) __entry->saddr; 395 *p32 = inet->inet_saddr; 396 397 p32 = (__be32 *) __entry->daddr; 398 *p32 = inet->inet_daddr; 399 400 TP_STORE_ADDRS(__entry, inet->inet_saddr, inet->inet_daddr, 401 sk->sk_v6_rcv_saddr, sk->sk_v6_daddr); 402 403 __entry->cong_state = ca_state; 404 ), 405 406 TP_printk("family=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c cong_state=%u", 407 show_family_name(__entry->family), 408 __entry->sport, __entry->dport, 409 __entry->saddr, __entry->daddr, 410 __entry->saddr_v6, __entry->daddr_v6, 411 __entry->cong_state) 412 ); 413 414 #endif /* _TRACE_TCP_H */ 415 416 /* This part must be outside protection */ 417 #include <trace/define_trace.h> 418