Merge tag 'net-6.16-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
[linux-2.6-block.git] / include / trace / events / sock.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
3847ce32
SM
2#undef TRACE_SYSTEM
3#define TRACE_SYSTEM sock
4
5#if !defined(_TRACE_SOCK_H) || defined(TRACE_HEADER_MULTI_READ)
6#define _TRACE_SOCK_H
7
8#include <net/sock.h>
563e0bb0 9#include <net/ipv6.h>
3847ce32 10#include <linux/tracepoint.h>
563e0bb0
YS
11#include <linux/ipv6.h>
12#include <linux/tcp.h>
a24c855a 13#include <trace/events/net_probe_common.h>
563e0bb0 14
0c3b34d8
YS
15#define family_names \
16 EM(AF_INET) \
17 EMe(AF_INET6)
18
19/* The protocol traced by inet_sock_set_state */
563e0bb0
YS
20#define inet_protocol_names \
21 EM(IPPROTO_TCP) \
faf391c3
MM
22 EM(IPPROTO_SCTP) \
23 EMe(IPPROTO_MPTCP)
563e0bb0
YS
24
25#define tcp_state_names \
26 EM(TCP_ESTABLISHED) \
27 EM(TCP_SYN_SENT) \
28 EM(TCP_SYN_RECV) \
29 EM(TCP_FIN_WAIT1) \
30 EM(TCP_FIN_WAIT2) \
31 EM(TCP_TIME_WAIT) \
32 EM(TCP_CLOSE) \
33 EM(TCP_CLOSE_WAIT) \
34 EM(TCP_LAST_ACK) \
35 EM(TCP_LISTEN) \
36 EM(TCP_CLOSING) \
37 EMe(TCP_NEW_SYN_RECV)
38
d6f19938
YS
39#define skmem_kind_names \
40 EM(SK_MEM_SEND) \
41 EMe(SK_MEM_RECV)
42
563e0bb0
YS
43/* enums need to be exported to user space */
44#undef EM
45#undef EMe
46#define EM(a) TRACE_DEFINE_ENUM(a);
47#define EMe(a) TRACE_DEFINE_ENUM(a);
48
0c3b34d8 49family_names
563e0bb0
YS
50inet_protocol_names
51tcp_state_names
d6f19938 52skmem_kind_names
563e0bb0
YS
53
54#undef EM
55#undef EMe
56#define EM(a) { a, #a },
57#define EMe(a) { a, #a }
58
0c3b34d8
YS
59#define show_family_name(val) \
60 __print_symbolic(val, family_names)
61
563e0bb0
YS
62#define show_inet_protocol_name(val) \
63 __print_symbolic(val, inet_protocol_names)
64
65#define show_tcp_state_name(val) \
66 __print_symbolic(val, tcp_state_names)
3847ce32 67
d6f19938
YS
68#define show_skmem_kind_names(val) \
69 __print_symbolic(val, skmem_kind_names)
70
3847ce32
SM
71TRACE_EVENT(sock_rcvqueue_full,
72
73 TP_PROTO(struct sock *sk, struct sk_buff *skb),
74
75 TP_ARGS(sk, skb),
76
77 TP_STRUCT__entry(
78 __field(int, rmem_alloc)
79 __field(unsigned int, truesize)
80 __field(int, sk_rcvbuf)
81 ),
82
83 TP_fast_assign(
84 __entry->rmem_alloc = atomic_read(&sk->sk_rmem_alloc);
85 __entry->truesize = skb->truesize;
ebb3b78d 86 __entry->sk_rcvbuf = READ_ONCE(sk->sk_rcvbuf);
3847ce32
SM
87 ),
88
89 TP_printk("rmem_alloc=%d truesize=%u sk_rcvbuf=%d",
90 __entry->rmem_alloc, __entry->truesize, __entry->sk_rcvbuf)
91);
92
93TRACE_EVENT(sock_exceed_buf_limit,
94
d6f19938 95 TP_PROTO(struct sock *sk, struct proto *prot, long allocated, int kind),
3847ce32 96
d6f19938 97 TP_ARGS(sk, prot, allocated, kind),
3847ce32
SM
98
99 TP_STRUCT__entry(
100 __array(char, name, 32)
820b8963 101 __array(long, sysctl_mem, 3)
3847ce32
SM
102 __field(long, allocated)
103 __field(int, sysctl_rmem)
104 __field(int, rmem_alloc)
d6f19938
YS
105 __field(int, sysctl_wmem)
106 __field(int, wmem_alloc)
107 __field(int, wmem_queued)
108 __field(int, kind)
3847ce32
SM
109 ),
110
111 TP_fast_assign(
386f4a73 112 strscpy(__entry->name, prot->name, 32);
820b8963
SRG
113 __entry->sysctl_mem[0] = READ_ONCE(prot->sysctl_mem[0]);
114 __entry->sysctl_mem[1] = READ_ONCE(prot->sysctl_mem[1]);
115 __entry->sysctl_mem[2] = READ_ONCE(prot->sysctl_mem[2]);
3847ce32 116 __entry->allocated = allocated;
a3dcaf17 117 __entry->sysctl_rmem = sk_get_rmem0(sk, prot);
3847ce32 118 __entry->rmem_alloc = atomic_read(&sk->sk_rmem_alloc);
d6f19938
YS
119 __entry->sysctl_wmem = sk_get_wmem0(sk, prot);
120 __entry->wmem_alloc = refcount_read(&sk->sk_wmem_alloc);
ab4e846a 121 __entry->wmem_queued = READ_ONCE(sk->sk_wmem_queued);
d6f19938 122 __entry->kind = kind;
3847ce32
SM
123 ),
124
d6f19938 125 TP_printk("proto:%s sysctl_mem=%ld,%ld,%ld allocated=%ld sysctl_rmem=%d rmem_alloc=%d sysctl_wmem=%d wmem_alloc=%d wmem_queued=%d kind=%s",
3847ce32
SM
126 __entry->name,
127 __entry->sysctl_mem[0],
128 __entry->sysctl_mem[1],
129 __entry->sysctl_mem[2],
130 __entry->allocated,
131 __entry->sysctl_rmem,
d6f19938
YS
132 __entry->rmem_alloc,
133 __entry->sysctl_wmem,
134 __entry->wmem_alloc,
135 __entry->wmem_queued,
136 show_skmem_kind_names(__entry->kind)
137 )
3847ce32
SM
138);
139
563e0bb0
YS
140TRACE_EVENT(inet_sock_set_state,
141
142 TP_PROTO(const struct sock *sk, const int oldstate, const int newstate),
143
144 TP_ARGS(sk, oldstate, newstate),
145
146 TP_STRUCT__entry(
147 __field(const void *, skaddr)
148 __field(int, oldstate)
149 __field(int, newstate)
150 __field(__u16, sport)
151 __field(__u16, dport)
0c3b34d8 152 __field(__u16, family)
bf976514 153 __field(__u16, protocol)
563e0bb0
YS
154 __array(__u8, saddr, 4)
155 __array(__u8, daddr, 4)
156 __array(__u8, saddr_v6, 16)
157 __array(__u8, daddr_v6, 16)
158 ),
159
160 TP_fast_assign(
abc17a11 161 const struct inet_sock *inet = inet_sk(sk);
563e0bb0
YS
162 __be32 *p32;
163
164 __entry->skaddr = sk;
165 __entry->oldstate = oldstate;
166 __entry->newstate = newstate;
167
0c3b34d8 168 __entry->family = sk->sk_family;
563e0bb0
YS
169 __entry->protocol = sk->sk_protocol;
170 __entry->sport = ntohs(inet->inet_sport);
171 __entry->dport = ntohs(inet->inet_dport);
172
173 p32 = (__be32 *) __entry->saddr;
174 *p32 = inet->inet_saddr;
175
176 p32 = (__be32 *) __entry->daddr;
177 *p32 = inet->inet_daddr;
178
646700ce
JX
179 TP_STORE_ADDRS(__entry, inet->inet_saddr, inet->inet_daddr,
180 sk->sk_v6_rcv_saddr, sk->sk_v6_daddr);
563e0bb0
YS
181 ),
182
0c3b34d8
YS
183 TP_printk("family=%s protocol=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c oldstate=%s newstate=%s",
184 show_family_name(__entry->family),
563e0bb0
YS
185 show_inet_protocol_name(__entry->protocol),
186 __entry->sport, __entry->dport,
187 __entry->saddr, __entry->daddr,
188 __entry->saddr_v6, __entry->daddr_v6,
189 show_tcp_state_name(__entry->oldstate),
190 show_tcp_state_name(__entry->newstate))
191);
192
e6a3e443
AA
193TRACE_EVENT(inet_sk_error_report,
194
195 TP_PROTO(const struct sock *sk),
196
197 TP_ARGS(sk),
198
199 TP_STRUCT__entry(
200 __field(int, error)
201 __field(__u16, sport)
202 __field(__u16, dport)
203 __field(__u16, family)
204 __field(__u16, protocol)
205 __array(__u8, saddr, 4)
206 __array(__u8, daddr, 4)
207 __array(__u8, saddr_v6, 16)
208 __array(__u8, daddr_v6, 16)
209 ),
210
211 TP_fast_assign(
abc17a11 212 const struct inet_sock *inet = inet_sk(sk);
e6a3e443
AA
213 __be32 *p32;
214
215 __entry->error = sk->sk_err;
216 __entry->family = sk->sk_family;
217 __entry->protocol = sk->sk_protocol;
218 __entry->sport = ntohs(inet->inet_sport);
219 __entry->dport = ntohs(inet->inet_dport);
220
221 p32 = (__be32 *) __entry->saddr;
222 *p32 = inet->inet_saddr;
223
224 p32 = (__be32 *) __entry->daddr;
225 *p32 = inet->inet_daddr;
226
a24c855a
JX
227 TP_STORE_ADDRS(__entry, inet->inet_saddr, inet->inet_daddr,
228 sk->sk_v6_rcv_saddr, sk->sk_v6_daddr);
e6a3e443
AA
229 ),
230
231 TP_printk("family=%s protocol=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c error=%d",
232 show_family_name(__entry->family),
233 show_inet_protocol_name(__entry->protocol),
234 __entry->sport, __entry->dport,
235 __entry->saddr, __entry->daddr,
236 __entry->saddr_v6, __entry->daddr_v6,
237 __entry->error)
238);
239
40e0b090
PY
240TRACE_EVENT(sk_data_ready,
241
242 TP_PROTO(const struct sock *sk),
243
244 TP_ARGS(sk),
245
246 TP_STRUCT__entry(
247 __field(const void *, skaddr)
248 __field(__u16, family)
249 __field(__u16, protocol)
250 __field(unsigned long, ip)
251 ),
252
253 TP_fast_assign(
254 __entry->skaddr = sk;
255 __entry->family = sk->sk_family;
256 __entry->protocol = sk->sk_protocol;
257 __entry->ip = _RET_IP_;
258 ),
259
260 TP_printk("family=%u protocol=%u func=%ps",
261 __entry->family, __entry->protocol, (void *)__entry->ip)
262);
263
6e6eda44
YC
264/*
265 * sock send/recv msg length
266 */
267DECLARE_EVENT_CLASS(sock_msg_length,
268
269 TP_PROTO(struct sock *sk, int ret, int flags),
270
271 TP_ARGS(sk, ret, flags),
272
273 TP_STRUCT__entry(
274 __field(void *, sk)
275 __field(__u16, family)
276 __field(__u16, protocol)
277 __field(int, ret)
278 __field(int, flags)
279 ),
280
281 TP_fast_assign(
282 __entry->sk = sk;
283 __entry->family = sk->sk_family;
284 __entry->protocol = sk->sk_protocol;
285 __entry->ret = ret;
286 __entry->flags = flags;
287 ),
288
289 TP_printk("sk address = %p, family = %s protocol = %s, length = %d, error = %d, flags = 0x%x",
290 __entry->sk, show_family_name(__entry->family),
291 show_inet_protocol_name(__entry->protocol),
292 !(__entry->flags & MSG_PEEK) ?
293 (__entry->ret > 0 ? __entry->ret : 0) : 0,
294 __entry->ret < 0 ? __entry->ret : 0,
295 __entry->flags)
296);
297
298DEFINE_EVENT(sock_msg_length, sock_send_length,
299 TP_PROTO(struct sock *sk, int ret, int flags),
300
301 TP_ARGS(sk, ret, flags)
302);
303
304DEFINE_EVENT(sock_msg_length, sock_recv_length,
305 TP_PROTO(struct sock *sk, int ret, int flags),
306
307 TP_ARGS(sk, ret, flags)
308);
3847ce32
SM
309#endif /* _TRACE_SOCK_H */
310
311/* This part must be outside protection */
312#include <trace/define_trace.h>