xref: /openbmc/linux/include/trace/events/tcp.h (revision cf34ce3d)
1e086101bSCong Wang #undef TRACE_SYSTEM
2e086101bSCong Wang #define TRACE_SYSTEM tcp
3e086101bSCong Wang 
4e086101bSCong Wang #if !defined(_TRACE_TCP_H) || defined(TRACE_HEADER_MULTI_READ)
5e086101bSCong Wang #define _TRACE_TCP_H
6e086101bSCong Wang 
7e086101bSCong Wang #include <linux/ipv6.h>
8e086101bSCong Wang #include <linux/tcp.h>
9e086101bSCong Wang #include <linux/tracepoint.h>
10e086101bSCong Wang #include <net/ipv6.h>
11e086101bSCong Wang 
12e8fce239SSong Liu #define tcp_state_name(state)	{ state, #state }
13e8fce239SSong Liu #define show_tcp_state_name(val)			\
14e8fce239SSong Liu 	__print_symbolic(val,				\
15e8fce239SSong Liu 		tcp_state_name(TCP_ESTABLISHED),	\
16e8fce239SSong Liu 		tcp_state_name(TCP_SYN_SENT),		\
17e8fce239SSong Liu 		tcp_state_name(TCP_SYN_RECV),		\
18e8fce239SSong Liu 		tcp_state_name(TCP_FIN_WAIT1),		\
19e8fce239SSong Liu 		tcp_state_name(TCP_FIN_WAIT2),		\
20e8fce239SSong Liu 		tcp_state_name(TCP_TIME_WAIT),		\
21e8fce239SSong Liu 		tcp_state_name(TCP_CLOSE),		\
22e8fce239SSong Liu 		tcp_state_name(TCP_CLOSE_WAIT),		\
23e8fce239SSong Liu 		tcp_state_name(TCP_LAST_ACK),		\
24e8fce239SSong Liu 		tcp_state_name(TCP_LISTEN),		\
25e8fce239SSong Liu 		tcp_state_name(TCP_CLOSING),		\
26e8fce239SSong Liu 		tcp_state_name(TCP_NEW_SYN_RECV))
27e8fce239SSong Liu 
28f6e37b25SSong Liu /*
29f6e37b25SSong Liu  * tcp event with arguments sk and skb
30f6e37b25SSong Liu  *
31f6e37b25SSong Liu  * Note: this class requires a valid sk pointer; while skb pointer could
32f6e37b25SSong Liu  *       be NULL.
33f6e37b25SSong Liu  */
34f6e37b25SSong Liu DECLARE_EVENT_CLASS(tcp_event_sk_skb,
35e086101bSCong Wang 
367344e29fSSong Liu 	TP_PROTO(const struct sock *sk, const struct sk_buff *skb),
37e086101bSCong Wang 
38e086101bSCong Wang 	TP_ARGS(sk, skb),
39e086101bSCong Wang 
40e086101bSCong Wang 	TP_STRUCT__entry(
417344e29fSSong Liu 		__field(const void *, skbaddr)
427344e29fSSong Liu 		__field(const void *, skaddr)
43e086101bSCong Wang 		__field(__u16, sport)
44e086101bSCong Wang 		__field(__u16, dport)
45e086101bSCong Wang 		__array(__u8, saddr, 4)
46e086101bSCong Wang 		__array(__u8, daddr, 4)
47e086101bSCong Wang 		__array(__u8, saddr_v6, 16)
48e086101bSCong Wang 		__array(__u8, daddr_v6, 16)
49e086101bSCong Wang 	),
50e086101bSCong Wang 
51e086101bSCong Wang 	TP_fast_assign(
52e086101bSCong Wang 		struct inet_sock *inet = inet_sk(sk);
53e086101bSCong Wang 		struct in6_addr *pin6;
54e086101bSCong Wang 		__be32 *p32;
55e086101bSCong Wang 
56e086101bSCong Wang 		__entry->skbaddr = skb;
57e086101bSCong Wang 		__entry->skaddr = sk;
58e086101bSCong Wang 
59e086101bSCong Wang 		__entry->sport = ntohs(inet->inet_sport);
60e086101bSCong Wang 		__entry->dport = ntohs(inet->inet_dport);
61e086101bSCong Wang 
62e086101bSCong Wang 		p32 = (__be32 *) __entry->saddr;
63e086101bSCong Wang 		*p32 = inet->inet_saddr;
64e086101bSCong Wang 
65e086101bSCong Wang 		p32 = (__be32 *) __entry->daddr;
66e086101bSCong Wang 		*p32 =  inet->inet_daddr;
67e086101bSCong Wang 
6889005678SDavid Ahern #if IS_ENABLED(CONFIG_IPV6)
6989005678SDavid Ahern 		if (sk->sk_family == AF_INET6) {
70e086101bSCong Wang 			pin6 = (struct in6_addr *)__entry->saddr_v6;
71386fd5daSDavid Ahern 			*pin6 = sk->sk_v6_rcv_saddr;
72e086101bSCong Wang 			pin6 = (struct in6_addr *)__entry->daddr_v6;
73386fd5daSDavid Ahern 			*pin6 = sk->sk_v6_daddr;
7489005678SDavid Ahern 		} else
7589005678SDavid Ahern #endif
7689005678SDavid Ahern 		{
77e086101bSCong Wang 			pin6 = (struct in6_addr *)__entry->saddr_v6;
78e086101bSCong Wang 			ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
79e086101bSCong Wang 			pin6 = (struct in6_addr *)__entry->daddr_v6;
80e086101bSCong Wang 			ipv6_addr_set_v4mapped(inet->inet_daddr, pin6);
81e086101bSCong Wang 		}
82e086101bSCong Wang 	),
83e086101bSCong Wang 
84fb6ff75eSDavid Ahern 	TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c",
85e086101bSCong Wang 		  __entry->sport, __entry->dport, __entry->saddr, __entry->daddr,
86e086101bSCong Wang 		  __entry->saddr_v6, __entry->daddr_v6)
87e086101bSCong Wang );
88e086101bSCong Wang 
89f6e37b25SSong Liu DEFINE_EVENT(tcp_event_sk_skb, tcp_retransmit_skb,
90f6e37b25SSong Liu 
917344e29fSSong Liu 	TP_PROTO(const struct sock *sk, const struct sk_buff *skb),
92f6e37b25SSong Liu 
93f6e37b25SSong Liu 	TP_ARGS(sk, skb)
94f6e37b25SSong Liu );
95f6e37b25SSong Liu 
96c24b14c4SSong Liu /*
97c24b14c4SSong Liu  * skb of trace_tcp_send_reset is the skb that caused RST. In case of
98c24b14c4SSong Liu  * active reset, skb should be NULL
99c24b14c4SSong Liu  */
100c24b14c4SSong Liu DEFINE_EVENT(tcp_event_sk_skb, tcp_send_reset,
101c24b14c4SSong Liu 
102c24b14c4SSong Liu 	TP_PROTO(const struct sock *sk, const struct sk_buff *skb),
103c24b14c4SSong Liu 
104c24b14c4SSong Liu 	TP_ARGS(sk, skb)
105c24b14c4SSong Liu );
106c24b14c4SSong Liu 
1075941521cSSong Liu /*
1085941521cSSong Liu  * tcp event with arguments sk
1095941521cSSong Liu  *
1105941521cSSong Liu  * Note: this class requires a valid sk pointer.
1115941521cSSong Liu  */
1125941521cSSong Liu DECLARE_EVENT_CLASS(tcp_event_sk,
1135941521cSSong Liu 
1145941521cSSong Liu 	TP_PROTO(const struct sock *sk),
1155941521cSSong Liu 
1165941521cSSong Liu 	TP_ARGS(sk),
1175941521cSSong Liu 
1185941521cSSong Liu 	TP_STRUCT__entry(
1195941521cSSong Liu 		__field(const void *, skaddr)
1205941521cSSong Liu 		__field(__u16, sport)
1215941521cSSong Liu 		__field(__u16, dport)
1225941521cSSong Liu 		__array(__u8, saddr, 4)
1235941521cSSong Liu 		__array(__u8, daddr, 4)
1245941521cSSong Liu 		__array(__u8, saddr_v6, 16)
1255941521cSSong Liu 		__array(__u8, daddr_v6, 16)
1265941521cSSong Liu 	),
1275941521cSSong Liu 
1285941521cSSong Liu 	TP_fast_assign(
1295941521cSSong Liu 		struct inet_sock *inet = inet_sk(sk);
1305941521cSSong Liu 		struct in6_addr *pin6;
1315941521cSSong Liu 		__be32 *p32;
1325941521cSSong Liu 
1335941521cSSong Liu 		__entry->skaddr = sk;
1345941521cSSong Liu 
1355941521cSSong Liu 		__entry->sport = ntohs(inet->inet_sport);
1365941521cSSong Liu 		__entry->dport = ntohs(inet->inet_dport);
1375941521cSSong Liu 
1385941521cSSong Liu 		p32 = (__be32 *) __entry->saddr;
1395941521cSSong Liu 		*p32 = inet->inet_saddr;
1405941521cSSong Liu 
1415941521cSSong Liu 		p32 = (__be32 *) __entry->daddr;
1425941521cSSong Liu 		*p32 =  inet->inet_daddr;
1435941521cSSong Liu 
1445941521cSSong Liu #if IS_ENABLED(CONFIG_IPV6)
1455941521cSSong Liu 		if (sk->sk_family == AF_INET6) {
1465941521cSSong Liu 			pin6 = (struct in6_addr *)__entry->saddr_v6;
1475941521cSSong Liu 			*pin6 = sk->sk_v6_rcv_saddr;
1485941521cSSong Liu 			pin6 = (struct in6_addr *)__entry->daddr_v6;
1495941521cSSong Liu 			*pin6 = sk->sk_v6_daddr;
1505941521cSSong Liu 		} else
1515941521cSSong Liu #endif
1525941521cSSong Liu 		{
1535941521cSSong Liu 			pin6 = (struct in6_addr *)__entry->saddr_v6;
1545941521cSSong Liu 			ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
1555941521cSSong Liu 			pin6 = (struct in6_addr *)__entry->daddr_v6;
1565941521cSSong Liu 			ipv6_addr_set_v4mapped(inet->inet_daddr, pin6);
1575941521cSSong Liu 		}
1585941521cSSong Liu 	),
1595941521cSSong Liu 
1605941521cSSong Liu 	TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c",
1615941521cSSong Liu 		  __entry->sport, __entry->dport,
1625941521cSSong Liu 		  __entry->saddr, __entry->daddr,
1635941521cSSong Liu 		  __entry->saddr_v6, __entry->daddr_v6)
1645941521cSSong Liu );
1655941521cSSong Liu 
1665941521cSSong Liu DEFINE_EVENT(tcp_event_sk, tcp_receive_reset,
1675941521cSSong Liu 
1685941521cSSong Liu 	TP_PROTO(const struct sock *sk),
1695941521cSSong Liu 
1705941521cSSong Liu 	TP_ARGS(sk)
1715941521cSSong Liu );
1725941521cSSong Liu 
173e1a4aa50SSong Liu DEFINE_EVENT(tcp_event_sk, tcp_destroy_sock,
174e1a4aa50SSong Liu 
175e1a4aa50SSong Liu 	TP_PROTO(const struct sock *sk),
176e1a4aa50SSong Liu 
177e1a4aa50SSong Liu 	TP_ARGS(sk)
178e1a4aa50SSong Liu );
179e1a4aa50SSong Liu 
180e8fce239SSong Liu TRACE_EVENT(tcp_set_state,
181e8fce239SSong Liu 
182e8fce239SSong Liu 	TP_PROTO(const struct sock *sk, const int oldstate, const int newstate),
183e8fce239SSong Liu 
184e8fce239SSong Liu 	TP_ARGS(sk, oldstate, newstate),
185e8fce239SSong Liu 
186e8fce239SSong Liu 	TP_STRUCT__entry(
187e8fce239SSong Liu 		__field(const void *, skaddr)
188e8fce239SSong Liu 		__field(int, oldstate)
189e8fce239SSong Liu 		__field(int, newstate)
190e8fce239SSong Liu 		__field(__u16, sport)
191e8fce239SSong Liu 		__field(__u16, dport)
192e8fce239SSong Liu 		__array(__u8, saddr, 4)
193e8fce239SSong Liu 		__array(__u8, daddr, 4)
194e8fce239SSong Liu 		__array(__u8, saddr_v6, 16)
195e8fce239SSong Liu 		__array(__u8, daddr_v6, 16)
196e8fce239SSong Liu 	),
197e8fce239SSong Liu 
198e8fce239SSong Liu 	TP_fast_assign(
199e8fce239SSong Liu 		struct inet_sock *inet = inet_sk(sk);
200e8fce239SSong Liu 		struct in6_addr *pin6;
201e8fce239SSong Liu 		__be32 *p32;
202e8fce239SSong Liu 
203e8fce239SSong Liu 		__entry->skaddr = sk;
204e8fce239SSong Liu 		__entry->oldstate = oldstate;
205e8fce239SSong Liu 		__entry->newstate = newstate;
206e8fce239SSong Liu 
207e8fce239SSong Liu 		__entry->sport = ntohs(inet->inet_sport);
208e8fce239SSong Liu 		__entry->dport = ntohs(inet->inet_dport);
209e8fce239SSong Liu 
210e8fce239SSong Liu 		p32 = (__be32 *) __entry->saddr;
211e8fce239SSong Liu 		*p32 = inet->inet_saddr;
212e8fce239SSong Liu 
213e8fce239SSong Liu 		p32 = (__be32 *) __entry->daddr;
214e8fce239SSong Liu 		*p32 =  inet->inet_daddr;
215e8fce239SSong Liu 
216e8fce239SSong Liu #if IS_ENABLED(CONFIG_IPV6)
217e8fce239SSong Liu 		if (sk->sk_family == AF_INET6) {
218e8fce239SSong Liu 			pin6 = (struct in6_addr *)__entry->saddr_v6;
219e8fce239SSong Liu 			*pin6 = sk->sk_v6_rcv_saddr;
220e8fce239SSong Liu 			pin6 = (struct in6_addr *)__entry->daddr_v6;
221e8fce239SSong Liu 			*pin6 = sk->sk_v6_daddr;
222e8fce239SSong Liu 		} else
223e8fce239SSong Liu #endif
224e8fce239SSong Liu 		{
225e8fce239SSong Liu 			pin6 = (struct in6_addr *)__entry->saddr_v6;
226e8fce239SSong Liu 			ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
227e8fce239SSong Liu 			pin6 = (struct in6_addr *)__entry->daddr_v6;
228e8fce239SSong Liu 			ipv6_addr_set_v4mapped(inet->inet_daddr, pin6);
229e8fce239SSong Liu 		}
230e8fce239SSong Liu 	),
231e8fce239SSong Liu 
232e8fce239SSong Liu 	TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c oldstate=%s newstate=%s",
233e8fce239SSong Liu 		  __entry->sport, __entry->dport,
234e8fce239SSong Liu 		  __entry->saddr, __entry->daddr,
235e8fce239SSong Liu 		  __entry->saddr_v6, __entry->daddr_v6,
236e8fce239SSong Liu 		  show_tcp_state_name(__entry->oldstate),
237e8fce239SSong Liu 		  show_tcp_state_name(__entry->newstate))
238e8fce239SSong Liu );
239e8fce239SSong Liu 
240cf34ce3dSSong Liu TRACE_EVENT(tcp_retransmit_synack,
241cf34ce3dSSong Liu 
242cf34ce3dSSong Liu 	TP_PROTO(const struct sock *sk, const struct request_sock *req),
243cf34ce3dSSong Liu 
244cf34ce3dSSong Liu 	TP_ARGS(sk, req),
245cf34ce3dSSong Liu 
246cf34ce3dSSong Liu 	TP_STRUCT__entry(
247cf34ce3dSSong Liu 		__field(const void *, skaddr)
248cf34ce3dSSong Liu 		__field(const void *, req)
249cf34ce3dSSong Liu 		__field(__u16, sport)
250cf34ce3dSSong Liu 		__field(__u16, dport)
251cf34ce3dSSong Liu 		__array(__u8, saddr, 4)
252cf34ce3dSSong Liu 		__array(__u8, daddr, 4)
253cf34ce3dSSong Liu 		__array(__u8, saddr_v6, 16)
254cf34ce3dSSong Liu 		__array(__u8, daddr_v6, 16)
255cf34ce3dSSong Liu 	),
256cf34ce3dSSong Liu 
257cf34ce3dSSong Liu 	TP_fast_assign(
258cf34ce3dSSong Liu 		struct inet_request_sock *ireq = inet_rsk(req);
259cf34ce3dSSong Liu 		struct in6_addr *pin6;
260cf34ce3dSSong Liu 		__be32 *p32;
261cf34ce3dSSong Liu 
262cf34ce3dSSong Liu 		__entry->skaddr = sk;
263cf34ce3dSSong Liu 		__entry->req = req;
264cf34ce3dSSong Liu 
265cf34ce3dSSong Liu 		__entry->sport = ireq->ir_num;
266cf34ce3dSSong Liu 		__entry->dport = ntohs(ireq->ir_rmt_port);
267cf34ce3dSSong Liu 
268cf34ce3dSSong Liu 		p32 = (__be32 *) __entry->saddr;
269cf34ce3dSSong Liu 		*p32 = ireq->ir_loc_addr;
270cf34ce3dSSong Liu 
271cf34ce3dSSong Liu 		p32 = (__be32 *) __entry->daddr;
272cf34ce3dSSong Liu 		*p32 = ireq->ir_rmt_addr;
273cf34ce3dSSong Liu 
274cf34ce3dSSong Liu #if IS_ENABLED(CONFIG_IPV6)
275cf34ce3dSSong Liu 		if (sk->sk_family == AF_INET6) {
276cf34ce3dSSong Liu 			pin6 = (struct in6_addr *)__entry->saddr_v6;
277cf34ce3dSSong Liu 			*pin6 = ireq->ir_v6_loc_addr;
278cf34ce3dSSong Liu 			pin6 = (struct in6_addr *)__entry->daddr_v6;
279cf34ce3dSSong Liu 			*pin6 = ireq->ir_v6_rmt_addr;
280cf34ce3dSSong Liu 		} else
281cf34ce3dSSong Liu #endif
282cf34ce3dSSong Liu 		{
283cf34ce3dSSong Liu 			pin6 = (struct in6_addr *)__entry->saddr_v6;
284cf34ce3dSSong Liu 			ipv6_addr_set_v4mapped(ireq->ir_loc_addr, pin6);
285cf34ce3dSSong Liu 			pin6 = (struct in6_addr *)__entry->daddr_v6;
286cf34ce3dSSong Liu 			ipv6_addr_set_v4mapped(ireq->ir_rmt_addr, pin6);
287cf34ce3dSSong Liu 		}
288cf34ce3dSSong Liu 	),
289cf34ce3dSSong Liu 
290cf34ce3dSSong Liu 	TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c",
291cf34ce3dSSong Liu 		  __entry->sport, __entry->dport,
292cf34ce3dSSong Liu 		  __entry->saddr, __entry->daddr,
293cf34ce3dSSong Liu 		  __entry->saddr_v6, __entry->daddr_v6)
294cf34ce3dSSong Liu );
295cf34ce3dSSong Liu 
296e086101bSCong Wang #endif /* _TRACE_TCP_H */
297e086101bSCong Wang 
298e086101bSCong Wang /* This part must be outside protection */
299e086101bSCong Wang #include <trace/define_trace.h>
300