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 14 #define TP_STORE_V4MAPPED(__entry, saddr, daddr) \ 15 do { \ 16 struct in6_addr *pin6; \ 17 \ 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); \ 22 } while (0) 23 24 #if IS_ENABLED(CONFIG_IPV6) 25 #define TP_STORE_ADDRS(__entry, saddr, daddr, saddr6, daddr6) \ 26 do { \ 27 if (sk->sk_family == AF_INET6) { \ 28 struct in6_addr *pin6; \ 29 \ 30 pin6 = (struct in6_addr *)__entry->saddr_v6; \ 31 *pin6 = saddr6; \ 32 pin6 = (struct in6_addr *)__entry->daddr_v6; \ 33 *pin6 = daddr6; \ 34 } else { \ 35 TP_STORE_V4MAPPED(__entry, saddr, daddr); \ 36 } \ 37 } while (0) 38 #else 39 #define TP_STORE_ADDRS(__entry, saddr, daddr, saddr6, daddr6) \ 40 TP_STORE_V4MAPPED(__entry, saddr, daddr) 41 #endif 42 43 /* 44 * tcp event with arguments sk and skb 45 * 46 * Note: this class requires a valid sk pointer; while skb pointer could 47 * be NULL. 48 */ 49 DECLARE_EVENT_CLASS(tcp_event_sk_skb, 50 51 TP_PROTO(const struct sock *sk, const struct sk_buff *skb), 52 53 TP_ARGS(sk, skb), 54 55 TP_STRUCT__entry( 56 __field(const void *, skbaddr) 57 __field(const void *, skaddr) 58 __field(__u16, sport) 59 __field(__u16, dport) 60 __array(__u8, saddr, 4) 61 __array(__u8, daddr, 4) 62 __array(__u8, saddr_v6, 16) 63 __array(__u8, daddr_v6, 16) 64 ), 65 66 TP_fast_assign( 67 struct inet_sock *inet = inet_sk(sk); 68 __be32 *p32; 69 70 __entry->skbaddr = skb; 71 __entry->skaddr = sk; 72 73 __entry->sport = ntohs(inet->inet_sport); 74 __entry->dport = ntohs(inet->inet_dport); 75 76 p32 = (__be32 *) __entry->saddr; 77 *p32 = inet->inet_saddr; 78 79 p32 = (__be32 *) __entry->daddr; 80 *p32 = inet->inet_daddr; 81 82 TP_STORE_ADDRS(__entry, inet->inet_saddr, inet->inet_daddr, 83 sk->sk_v6_rcv_saddr, sk->sk_v6_daddr); 84 ), 85 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) 89 ); 90 91 DEFINE_EVENT(tcp_event_sk_skb, tcp_retransmit_skb, 92 93 TP_PROTO(const struct sock *sk, const struct sk_buff *skb), 94 95 TP_ARGS(sk, skb) 96 ); 97 98 /* 99 * skb of trace_tcp_send_reset is the skb that caused RST. In case of 100 * active reset, skb should be NULL 101 */ 102 DEFINE_EVENT(tcp_event_sk_skb, tcp_send_reset, 103 104 TP_PROTO(const struct sock *sk, const struct sk_buff *skb), 105 106 TP_ARGS(sk, skb) 107 ); 108 109 /* 110 * tcp event with arguments sk 111 * 112 * Note: this class requires a valid sk pointer. 113 */ 114 DECLARE_EVENT_CLASS(tcp_event_sk, 115 116 TP_PROTO(const struct sock *sk), 117 118 TP_ARGS(sk), 119 120 TP_STRUCT__entry( 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) 128 ), 129 130 TP_fast_assign( 131 struct inet_sock *inet = inet_sk(sk); 132 __be32 *p32; 133 134 __entry->skaddr = sk; 135 136 __entry->sport = ntohs(inet->inet_sport); 137 __entry->dport = ntohs(inet->inet_dport); 138 139 p32 = (__be32 *) __entry->saddr; 140 *p32 = inet->inet_saddr; 141 142 p32 = (__be32 *) __entry->daddr; 143 *p32 = inet->inet_daddr; 144 145 TP_STORE_ADDRS(__entry, inet->inet_saddr, inet->inet_daddr, 146 sk->sk_v6_rcv_saddr, sk->sk_v6_daddr); 147 ), 148 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) 153 ); 154 155 DEFINE_EVENT(tcp_event_sk, tcp_receive_reset, 156 157 TP_PROTO(const struct sock *sk), 158 159 TP_ARGS(sk) 160 ); 161 162 DEFINE_EVENT(tcp_event_sk, tcp_destroy_sock, 163 164 TP_PROTO(const struct sock *sk), 165 166 TP_ARGS(sk) 167 ); 168 169 TRACE_EVENT(tcp_set_state, 170 171 TP_PROTO(const struct sock *sk, const int oldstate, const int newstate), 172 173 TP_ARGS(sk, oldstate, newstate), 174 175 TP_STRUCT__entry( 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) 185 ), 186 187 TP_fast_assign( 188 struct inet_sock *inet = inet_sk(sk); 189 __be32 *p32; 190 191 __entry->skaddr = sk; 192 __entry->oldstate = oldstate; 193 __entry->newstate = newstate; 194 195 __entry->sport = ntohs(inet->inet_sport); 196 __entry->dport = ntohs(inet->inet_dport); 197 198 p32 = (__be32 *) __entry->saddr; 199 *p32 = inet->inet_saddr; 200 201 p32 = (__be32 *) __entry->daddr; 202 *p32 = inet->inet_daddr; 203 204 TP_STORE_ADDRS(__entry, inet->inet_saddr, inet->inet_daddr, 205 sk->sk_v6_rcv_saddr, sk->sk_v6_daddr); 206 ), 207 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)) 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 __array(__u8, saddr, 4) 228 __array(__u8, daddr, 4) 229 __array(__u8, saddr_v6, 16) 230 __array(__u8, daddr_v6, 16) 231 ), 232 233 TP_fast_assign( 234 struct inet_request_sock *ireq = inet_rsk(req); 235 __be32 *p32; 236 237 __entry->skaddr = sk; 238 __entry->req = req; 239 240 __entry->sport = ireq->ir_num; 241 __entry->dport = ntohs(ireq->ir_rmt_port); 242 243 p32 = (__be32 *) __entry->saddr; 244 *p32 = ireq->ir_loc_addr; 245 246 p32 = (__be32 *) __entry->daddr; 247 *p32 = ireq->ir_rmt_addr; 248 249 TP_STORE_ADDRS(__entry, ireq->ir_loc_addr, ireq->ir_rmt_addr, 250 ireq->ir_v6_loc_addr, ireq->ir_v6_rmt_addr); 251 ), 252 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) 257 ); 258 259 #include <trace/events/net_probe_common.h> 260 261 TRACE_EVENT(tcp_probe, 262 263 TP_PROTO(struct sock *sk, struct sk_buff *skb), 264 265 TP_ARGS(sk, skb), 266 267 TP_STRUCT__entry( 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) 273 __field(__u32, mark) 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) 280 __field(__u32, srtt) 281 __field(__u32, rcv_wnd) 282 ), 283 284 TP_fast_assign( 285 const struct tcp_sock *tp = tcp_sk(sk); 286 const struct inet_sock *inet = inet_sk(sk); 287 288 memset(__entry->saddr, 0, sizeof(struct sockaddr_in6)); 289 memset(__entry->daddr, 0, sizeof(struct sockaddr_in6)); 290 291 TP_STORE_ADDR_PORTS(__entry, inet, sk); 292 293 /* For filtering use */ 294 __entry->sport = ntohs(inet->inet_sport); 295 __entry->dport = ntohs(inet->inet_dport); 296 __entry->mark = skb->mark; 297 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; 306 ), 307 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 " 310 "rcv_wnd=%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) 315 ); 316 317 #endif /* _TRACE_TCP_H */ 318 319 /* This part must be outside protection */ 320 #include <trace/define_trace.h> 321