1 /* SPDX-License-Identifier: GPL-2.0 */
3 #define TRACE_SYSTEM sock
5 #if !defined(_TRACE_SOCK_H) || defined(TRACE_HEADER_MULTI_READ)
10 #include <linux/tracepoint.h>
11 #include <linux/ipv6.h>
12 #include <linux/tcp.h>
13 #include <trace/events/net_probe_common.h>
15 #define family_names \
19 /* The protocol traced by inet_sock_set_state */
20 #define inet_protocol_names \
26 #define tcp_state_names \
40 #define skmem_kind_names \
44 /* enums need to be exported to user space */
47 #define EM(a) TRACE_DEFINE_ENUM(a);
48 #define EMe(a) TRACE_DEFINE_ENUM(a);
57 #define EM(a) { a, #a },
58 #define EMe(a) { a, #a }
60 #define show_family_name(val) \
61 __print_symbolic(val, family_names)
63 #define show_inet_protocol_name(val) \
64 __print_symbolic(val, inet_protocol_names)
66 #define show_tcp_state_name(val) \
67 __print_symbolic(val, tcp_state_names)
69 #define show_skmem_kind_names(val) \
70 __print_symbolic(val, skmem_kind_names)
72 TRACE_EVENT(sock_rcvqueue_full
,
74 TP_PROTO(struct sock
*sk
, struct sk_buff
*skb
),
79 __field(int, rmem_alloc
)
80 __field(unsigned int, truesize
)
81 __field(int, sk_rcvbuf
)
85 __entry
->rmem_alloc
= atomic_read(&sk
->sk_rmem_alloc
);
86 __entry
->truesize
= skb
->truesize
;
87 __entry
->sk_rcvbuf
= READ_ONCE(sk
->sk_rcvbuf
);
90 TP_printk("rmem_alloc=%d truesize=%u sk_rcvbuf=%d",
91 __entry
->rmem_alloc
, __entry
->truesize
, __entry
->sk_rcvbuf
)
94 TRACE_EVENT(sock_exceed_buf_limit
,
96 TP_PROTO(struct sock
*sk
, struct proto
*prot
, long allocated
, int kind
),
98 TP_ARGS(sk
, prot
, allocated
, kind
),
101 __array(char, name
, 32)
102 __array(long, sysctl_mem
, 3)
103 __field(long, allocated
)
104 __field(int, sysctl_rmem
)
105 __field(int, rmem_alloc
)
106 __field(int, sysctl_wmem
)
107 __field(int, wmem_alloc
)
108 __field(int, wmem_queued
)
113 strscpy(__entry
->name
, prot
->name
, 32);
114 __entry
->sysctl_mem
[0] = READ_ONCE(prot
->sysctl_mem
[0]);
115 __entry
->sysctl_mem
[1] = READ_ONCE(prot
->sysctl_mem
[1]);
116 __entry
->sysctl_mem
[2] = READ_ONCE(prot
->sysctl_mem
[2]);
117 __entry
->allocated
= allocated
;
118 __entry
->sysctl_rmem
= sk_get_rmem0(sk
, prot
);
119 __entry
->rmem_alloc
= atomic_read(&sk
->sk_rmem_alloc
);
120 __entry
->sysctl_wmem
= sk_get_wmem0(sk
, prot
);
121 __entry
->wmem_alloc
= refcount_read(&sk
->sk_wmem_alloc
);
122 __entry
->wmem_queued
= READ_ONCE(sk
->sk_wmem_queued
);
123 __entry
->kind
= kind
;
126 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",
128 __entry
->sysctl_mem
[0],
129 __entry
->sysctl_mem
[1],
130 __entry
->sysctl_mem
[2],
132 __entry
->sysctl_rmem
,
134 __entry
->sysctl_wmem
,
136 __entry
->wmem_queued
,
137 show_skmem_kind_names(__entry
->kind
)
141 TRACE_EVENT(inet_sock_set_state
,
143 TP_PROTO(const struct sock
*sk
, const int oldstate
, const int newstate
),
145 TP_ARGS(sk
, oldstate
, newstate
),
148 __field(const void *, skaddr
)
149 __field(int, oldstate
)
150 __field(int, newstate
)
151 __field(__u16
, sport
)
152 __field(__u16
, dport
)
153 __field(__u16
, family
)
154 __field(__u16
, protocol
)
155 __array(__u8
, saddr
, 4)
156 __array(__u8
, daddr
, 4)
157 __array(__u8
, saddr_v6
, 16)
158 __array(__u8
, daddr_v6
, 16)
162 const struct inet_sock
*inet
= inet_sk(sk
);
165 __entry
->skaddr
= sk
;
166 __entry
->oldstate
= oldstate
;
167 __entry
->newstate
= newstate
;
169 __entry
->family
= sk
->sk_family
;
170 __entry
->protocol
= sk
->sk_protocol
;
171 __entry
->sport
= ntohs(inet
->inet_sport
);
172 __entry
->dport
= ntohs(inet
->inet_dport
);
174 p32
= (__be32
*) __entry
->saddr
;
175 *p32
= inet
->inet_saddr
;
177 p32
= (__be32
*) __entry
->daddr
;
178 *p32
= inet
->inet_daddr
;
180 TP_STORE_ADDRS(__entry
, inet
->inet_saddr
, inet
->inet_daddr
,
181 sk
->sk_v6_rcv_saddr
, sk
->sk_v6_daddr
);
184 TP_printk("family=%s protocol=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c oldstate=%s newstate=%s",
185 show_family_name(__entry
->family
),
186 show_inet_protocol_name(__entry
->protocol
),
187 __entry
->sport
, __entry
->dport
,
188 __entry
->saddr
, __entry
->daddr
,
189 __entry
->saddr_v6
, __entry
->daddr_v6
,
190 show_tcp_state_name(__entry
->oldstate
),
191 show_tcp_state_name(__entry
->newstate
))
194 TRACE_EVENT(inet_sk_error_report
,
196 TP_PROTO(const struct sock
*sk
),
202 __field(__u16
, sport
)
203 __field(__u16
, dport
)
204 __field(__u16
, family
)
205 __field(__u16
, protocol
)
206 __array(__u8
, saddr
, 4)
207 __array(__u8
, daddr
, 4)
208 __array(__u8
, saddr_v6
, 16)
209 __array(__u8
, daddr_v6
, 16)
213 const struct inet_sock
*inet
= inet_sk(sk
);
216 __entry
->error
= sk
->sk_err
;
217 __entry
->family
= sk
->sk_family
;
218 __entry
->protocol
= sk
->sk_protocol
;
219 __entry
->sport
= ntohs(inet
->inet_sport
);
220 __entry
->dport
= ntohs(inet
->inet_dport
);
222 p32
= (__be32
*) __entry
->saddr
;
223 *p32
= inet
->inet_saddr
;
225 p32
= (__be32
*) __entry
->daddr
;
226 *p32
= inet
->inet_daddr
;
228 TP_STORE_ADDRS(__entry
, inet
->inet_saddr
, inet
->inet_daddr
,
229 sk
->sk_v6_rcv_saddr
, sk
->sk_v6_daddr
);
232 TP_printk("family=%s protocol=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c error=%d",
233 show_family_name(__entry
->family
),
234 show_inet_protocol_name(__entry
->protocol
),
235 __entry
->sport
, __entry
->dport
,
236 __entry
->saddr
, __entry
->daddr
,
237 __entry
->saddr_v6
, __entry
->daddr_v6
,
241 TRACE_EVENT(sk_data_ready
,
243 TP_PROTO(const struct sock
*sk
),
248 __field(const void *, skaddr
)
249 __field(__u16
, family
)
250 __field(__u16
, protocol
)
251 __field(unsigned long, ip
)
255 __entry
->skaddr
= sk
;
256 __entry
->family
= sk
->sk_family
;
257 __entry
->protocol
= sk
->sk_protocol
;
258 __entry
->ip
= _RET_IP_
;
261 TP_printk("family=%u protocol=%u func=%ps",
262 __entry
->family
, __entry
->protocol
, (void *)__entry
->ip
)
266 * sock send/recv msg length
268 DECLARE_EVENT_CLASS(sock_msg_length
,
270 TP_PROTO(struct sock
*sk
, int ret
, int flags
),
272 TP_ARGS(sk
, ret
, flags
),
276 __field(__u16
, family
)
277 __field(__u16
, protocol
)
284 __entry
->family
= sk
->sk_family
;
285 __entry
->protocol
= sk
->sk_protocol
;
287 __entry
->flags
= flags
;
290 TP_printk("sk address = %p, family = %s protocol = %s, length = %d, error = %d, flags = 0x%x",
291 __entry
->sk
, show_family_name(__entry
->family
),
292 show_inet_protocol_name(__entry
->protocol
),
293 !(__entry
->flags
& MSG_PEEK
) ?
294 (__entry
->ret
> 0 ? __entry
->ret
: 0) : 0,
295 __entry
->ret
< 0 ? __entry
->ret
: 0,
299 DEFINE_EVENT(sock_msg_length
, sock_send_length
,
300 TP_PROTO(struct sock
*sk
, int ret
, int flags
),
302 TP_ARGS(sk
, ret
, flags
)
305 DEFINE_EVENT(sock_msg_length
, sock_recv_length
,
306 TP_PROTO(struct sock
*sk
, int ret
, int flags
),
308 TP_ARGS(sk
, ret
, flags
)
310 #endif /* _TRACE_SOCK_H */
312 /* This part must be outside protection */
313 #include <trace/define_trace.h>