1 #undef TRACE_SYSTEM 2 #define TRACE_SYSTEM tcp 3 4 #if !defined(_TRACE_TCP_H) || defined(TRACE_HEADER_MULTI_READ) 5 #define _TRACE_TCP_H 6 7 #include <linux/ipv6.h> 8 #include <linux/tcp.h> 9 #include <linux/tracepoint.h> 10 #include <net/ipv6.h> 11 12 #define tcp_state_name(state) { state, #state } 13 #define show_tcp_state_name(val) \ 14 __print_symbolic(val, \ 15 tcp_state_name(TCP_ESTABLISHED), \ 16 tcp_state_name(TCP_SYN_SENT), \ 17 tcp_state_name(TCP_SYN_RECV), \ 18 tcp_state_name(TCP_FIN_WAIT1), \ 19 tcp_state_name(TCP_FIN_WAIT2), \ 20 tcp_state_name(TCP_TIME_WAIT), \ 21 tcp_state_name(TCP_CLOSE), \ 22 tcp_state_name(TCP_CLOSE_WAIT), \ 23 tcp_state_name(TCP_LAST_ACK), \ 24 tcp_state_name(TCP_LISTEN), \ 25 tcp_state_name(TCP_CLOSING), \ 26 tcp_state_name(TCP_NEW_SYN_RECV)) 27 28 /* 29 * tcp event with arguments sk and skb 30 * 31 * Note: this class requires a valid sk pointer; while skb pointer could 32 * be NULL. 33 */ 34 DECLARE_EVENT_CLASS(tcp_event_sk_skb, 35 36 TP_PROTO(const struct sock *sk, const struct sk_buff *skb), 37 38 TP_ARGS(sk, skb), 39 40 TP_STRUCT__entry( 41 __field(const void *, skbaddr) 42 __field(const void *, skaddr) 43 __field(__u16, sport) 44 __field(__u16, dport) 45 __array(__u8, saddr, 4) 46 __array(__u8, daddr, 4) 47 __array(__u8, saddr_v6, 16) 48 __array(__u8, daddr_v6, 16) 49 ), 50 51 TP_fast_assign( 52 struct inet_sock *inet = inet_sk(sk); 53 struct in6_addr *pin6; 54 __be32 *p32; 55 56 __entry->skbaddr = skb; 57 __entry->skaddr = sk; 58 59 __entry->sport = ntohs(inet->inet_sport); 60 __entry->dport = ntohs(inet->inet_dport); 61 62 p32 = (__be32 *) __entry->saddr; 63 *p32 = inet->inet_saddr; 64 65 p32 = (__be32 *) __entry->daddr; 66 *p32 = inet->inet_daddr; 67 68 #if IS_ENABLED(CONFIG_IPV6) 69 if (sk->sk_family == AF_INET6) { 70 pin6 = (struct in6_addr *)__entry->saddr_v6; 71 *pin6 = sk->sk_v6_rcv_saddr; 72 pin6 = (struct in6_addr *)__entry->daddr_v6; 73 *pin6 = sk->sk_v6_daddr; 74 } else 75 #endif 76 { 77 pin6 = (struct in6_addr *)__entry->saddr_v6; 78 ipv6_addr_set_v4mapped(inet->inet_saddr, pin6); 79 pin6 = (struct in6_addr *)__entry->daddr_v6; 80 ipv6_addr_set_v4mapped(inet->inet_daddr, pin6); 81 } 82 ), 83 84 TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c", 85 __entry->sport, __entry->dport, __entry->saddr, __entry->daddr, 86 __entry->saddr_v6, __entry->daddr_v6) 87 ); 88 89 DEFINE_EVENT(tcp_event_sk_skb, tcp_retransmit_skb, 90 91 TP_PROTO(const struct sock *sk, const struct sk_buff *skb), 92 93 TP_ARGS(sk, skb) 94 ); 95 96 /* 97 * skb of trace_tcp_send_reset is the skb that caused RST. In case of 98 * active reset, skb should be NULL 99 */ 100 DEFINE_EVENT(tcp_event_sk_skb, tcp_send_reset, 101 102 TP_PROTO(const struct sock *sk, const struct sk_buff *skb), 103 104 TP_ARGS(sk, skb) 105 ); 106 107 /* 108 * tcp event with arguments sk 109 * 110 * Note: this class requires a valid sk pointer. 111 */ 112 DECLARE_EVENT_CLASS(tcp_event_sk, 113 114 TP_PROTO(const struct sock *sk), 115 116 TP_ARGS(sk), 117 118 TP_STRUCT__entry( 119 __field(const void *, skaddr) 120 __field(__u16, sport) 121 __field(__u16, dport) 122 __array(__u8, saddr, 4) 123 __array(__u8, daddr, 4) 124 __array(__u8, saddr_v6, 16) 125 __array(__u8, daddr_v6, 16) 126 ), 127 128 TP_fast_assign( 129 struct inet_sock *inet = inet_sk(sk); 130 struct in6_addr *pin6; 131 __be32 *p32; 132 133 __entry->skaddr = sk; 134 135 __entry->sport = ntohs(inet->inet_sport); 136 __entry->dport = ntohs(inet->inet_dport); 137 138 p32 = (__be32 *) __entry->saddr; 139 *p32 = inet->inet_saddr; 140 141 p32 = (__be32 *) __entry->daddr; 142 *p32 = inet->inet_daddr; 143 144 #if IS_ENABLED(CONFIG_IPV6) 145 if (sk->sk_family == AF_INET6) { 146 pin6 = (struct in6_addr *)__entry->saddr_v6; 147 *pin6 = sk->sk_v6_rcv_saddr; 148 pin6 = (struct in6_addr *)__entry->daddr_v6; 149 *pin6 = sk->sk_v6_daddr; 150 } else 151 #endif 152 { 153 pin6 = (struct in6_addr *)__entry->saddr_v6; 154 ipv6_addr_set_v4mapped(inet->inet_saddr, pin6); 155 pin6 = (struct in6_addr *)__entry->daddr_v6; 156 ipv6_addr_set_v4mapped(inet->inet_daddr, pin6); 157 } 158 ), 159 160 TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c", 161 __entry->sport, __entry->dport, 162 __entry->saddr, __entry->daddr, 163 __entry->saddr_v6, __entry->daddr_v6) 164 ); 165 166 DEFINE_EVENT(tcp_event_sk, tcp_receive_reset, 167 168 TP_PROTO(const struct sock *sk), 169 170 TP_ARGS(sk) 171 ); 172 173 DEFINE_EVENT(tcp_event_sk, tcp_destroy_sock, 174 175 TP_PROTO(const struct sock *sk), 176 177 TP_ARGS(sk) 178 ); 179 180 TRACE_EVENT(tcp_set_state, 181 182 TP_PROTO(const struct sock *sk, const int oldstate, const int newstate), 183 184 TP_ARGS(sk, oldstate, newstate), 185 186 TP_STRUCT__entry( 187 __field(const void *, skaddr) 188 __field(int, oldstate) 189 __field(int, newstate) 190 __field(__u16, sport) 191 __field(__u16, dport) 192 __array(__u8, saddr, 4) 193 __array(__u8, daddr, 4) 194 __array(__u8, saddr_v6, 16) 195 __array(__u8, daddr_v6, 16) 196 ), 197 198 TP_fast_assign( 199 struct inet_sock *inet = inet_sk(sk); 200 struct in6_addr *pin6; 201 __be32 *p32; 202 203 __entry->skaddr = sk; 204 __entry->oldstate = oldstate; 205 __entry->newstate = newstate; 206 207 __entry->sport = ntohs(inet->inet_sport); 208 __entry->dport = ntohs(inet->inet_dport); 209 210 p32 = (__be32 *) __entry->saddr; 211 *p32 = inet->inet_saddr; 212 213 p32 = (__be32 *) __entry->daddr; 214 *p32 = inet->inet_daddr; 215 216 #if IS_ENABLED(CONFIG_IPV6) 217 if (sk->sk_family == AF_INET6) { 218 pin6 = (struct in6_addr *)__entry->saddr_v6; 219 *pin6 = sk->sk_v6_rcv_saddr; 220 pin6 = (struct in6_addr *)__entry->daddr_v6; 221 *pin6 = sk->sk_v6_daddr; 222 } else 223 #endif 224 { 225 pin6 = (struct in6_addr *)__entry->saddr_v6; 226 ipv6_addr_set_v4mapped(inet->inet_saddr, pin6); 227 pin6 = (struct in6_addr *)__entry->daddr_v6; 228 ipv6_addr_set_v4mapped(inet->inet_daddr, pin6); 229 } 230 ), 231 232 TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c oldstate=%s newstate=%s", 233 __entry->sport, __entry->dport, 234 __entry->saddr, __entry->daddr, 235 __entry->saddr_v6, __entry->daddr_v6, 236 show_tcp_state_name(__entry->oldstate), 237 show_tcp_state_name(__entry->newstate)) 238 ); 239 240 TRACE_EVENT(tcp_retransmit_synack, 241 242 TP_PROTO(const struct sock *sk, const struct request_sock *req), 243 244 TP_ARGS(sk, req), 245 246 TP_STRUCT__entry( 247 __field(const void *, skaddr) 248 __field(const void *, req) 249 __field(__u16, sport) 250 __field(__u16, dport) 251 __array(__u8, saddr, 4) 252 __array(__u8, daddr, 4) 253 __array(__u8, saddr_v6, 16) 254 __array(__u8, daddr_v6, 16) 255 ), 256 257 TP_fast_assign( 258 struct inet_request_sock *ireq = inet_rsk(req); 259 struct in6_addr *pin6; 260 __be32 *p32; 261 262 __entry->skaddr = sk; 263 __entry->req = req; 264 265 __entry->sport = ireq->ir_num; 266 __entry->dport = ntohs(ireq->ir_rmt_port); 267 268 p32 = (__be32 *) __entry->saddr; 269 *p32 = ireq->ir_loc_addr; 270 271 p32 = (__be32 *) __entry->daddr; 272 *p32 = ireq->ir_rmt_addr; 273 274 #if IS_ENABLED(CONFIG_IPV6) 275 if (sk->sk_family == AF_INET6) { 276 pin6 = (struct in6_addr *)__entry->saddr_v6; 277 *pin6 = ireq->ir_v6_loc_addr; 278 pin6 = (struct in6_addr *)__entry->daddr_v6; 279 *pin6 = ireq->ir_v6_rmt_addr; 280 } else 281 #endif 282 { 283 pin6 = (struct in6_addr *)__entry->saddr_v6; 284 ipv6_addr_set_v4mapped(ireq->ir_loc_addr, pin6); 285 pin6 = (struct in6_addr *)__entry->daddr_v6; 286 ipv6_addr_set_v4mapped(ireq->ir_rmt_addr, pin6); 287 } 288 ), 289 290 TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c", 291 __entry->sport, __entry->dport, 292 __entry->saddr, __entry->daddr, 293 __entry->saddr_v6, __entry->daddr_v6) 294 ); 295 296 #endif /* _TRACE_TCP_H */ 297 298 /* This part must be outside protection */ 299 #include <trace/define_trace.h> 300