Loading...
1/* SPDX-License-Identifier: GPL-2.0 */
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>
9#include <net/ipv6.h>
10#include <linux/tracepoint.h>
11#include <linux/ipv6.h>
12#include <linux/tcp.h>
13
14#define family_names \
15 EM(AF_INET) \
16 EMe(AF_INET6)
17
18/* The protocol traced by inet_sock_set_state */
19#define inet_protocol_names \
20 EM(IPPROTO_TCP) \
21 EM(IPPROTO_DCCP) \
22 EMe(IPPROTO_SCTP)
23
24#define tcp_state_names \
25 EM(TCP_ESTABLISHED) \
26 EM(TCP_SYN_SENT) \
27 EM(TCP_SYN_RECV) \
28 EM(TCP_FIN_WAIT1) \
29 EM(TCP_FIN_WAIT2) \
30 EM(TCP_TIME_WAIT) \
31 EM(TCP_CLOSE) \
32 EM(TCP_CLOSE_WAIT) \
33 EM(TCP_LAST_ACK) \
34 EM(TCP_LISTEN) \
35 EM(TCP_CLOSING) \
36 EMe(TCP_NEW_SYN_RECV)
37
38#define skmem_kind_names \
39 EM(SK_MEM_SEND) \
40 EMe(SK_MEM_RECV)
41
42/* enums need to be exported to user space */
43#undef EM
44#undef EMe
45#define EM(a) TRACE_DEFINE_ENUM(a);
46#define EMe(a) TRACE_DEFINE_ENUM(a);
47
48family_names
49inet_protocol_names
50tcp_state_names
51skmem_kind_names
52
53#undef EM
54#undef EMe
55#define EM(a) { a, #a },
56#define EMe(a) { a, #a }
57
58#define show_family_name(val) \
59 __print_symbolic(val, family_names)
60
61#define show_inet_protocol_name(val) \
62 __print_symbolic(val, inet_protocol_names)
63
64#define show_tcp_state_name(val) \
65 __print_symbolic(val, tcp_state_names)
66
67#define show_skmem_kind_names(val) \
68 __print_symbolic(val, skmem_kind_names)
69
70TRACE_EVENT(sock_rcvqueue_full,
71
72 TP_PROTO(struct sock *sk, struct sk_buff *skb),
73
74 TP_ARGS(sk, skb),
75
76 TP_STRUCT__entry(
77 __field(int, rmem_alloc)
78 __field(unsigned int, truesize)
79 __field(int, sk_rcvbuf)
80 ),
81
82 TP_fast_assign(
83 __entry->rmem_alloc = atomic_read(&sk->sk_rmem_alloc);
84 __entry->truesize = skb->truesize;
85 __entry->sk_rcvbuf = READ_ONCE(sk->sk_rcvbuf);
86 ),
87
88 TP_printk("rmem_alloc=%d truesize=%u sk_rcvbuf=%d",
89 __entry->rmem_alloc, __entry->truesize, __entry->sk_rcvbuf)
90);
91
92TRACE_EVENT(sock_exceed_buf_limit,
93
94 TP_PROTO(struct sock *sk, struct proto *prot, long allocated, int kind),
95
96 TP_ARGS(sk, prot, allocated, kind),
97
98 TP_STRUCT__entry(
99 __array(char, name, 32)
100 __field(long *, sysctl_mem)
101 __field(long, allocated)
102 __field(int, sysctl_rmem)
103 __field(int, rmem_alloc)
104 __field(int, sysctl_wmem)
105 __field(int, wmem_alloc)
106 __field(int, wmem_queued)
107 __field(int, kind)
108 ),
109
110 TP_fast_assign(
111 strncpy(__entry->name, prot->name, 32);
112 __entry->sysctl_mem = prot->sysctl_mem;
113 __entry->allocated = allocated;
114 __entry->sysctl_rmem = sk_get_rmem0(sk, prot);
115 __entry->rmem_alloc = atomic_read(&sk->sk_rmem_alloc);
116 __entry->sysctl_wmem = sk_get_wmem0(sk, prot);
117 __entry->wmem_alloc = refcount_read(&sk->sk_wmem_alloc);
118 __entry->wmem_queued = READ_ONCE(sk->sk_wmem_queued);
119 __entry->kind = kind;
120 ),
121
122 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",
123 __entry->name,
124 __entry->sysctl_mem[0],
125 __entry->sysctl_mem[1],
126 __entry->sysctl_mem[2],
127 __entry->allocated,
128 __entry->sysctl_rmem,
129 __entry->rmem_alloc,
130 __entry->sysctl_wmem,
131 __entry->wmem_alloc,
132 __entry->wmem_queued,
133 show_skmem_kind_names(__entry->kind)
134 )
135);
136
137TRACE_EVENT(inet_sock_set_state,
138
139 TP_PROTO(const struct sock *sk, const int oldstate, const int newstate),
140
141 TP_ARGS(sk, oldstate, newstate),
142
143 TP_STRUCT__entry(
144 __field(const void *, skaddr)
145 __field(int, oldstate)
146 __field(int, newstate)
147 __field(__u16, sport)
148 __field(__u16, dport)
149 __field(__u16, family)
150 __field(__u8, protocol)
151 __array(__u8, saddr, 4)
152 __array(__u8, daddr, 4)
153 __array(__u8, saddr_v6, 16)
154 __array(__u8, daddr_v6, 16)
155 ),
156
157 TP_fast_assign(
158 struct inet_sock *inet = inet_sk(sk);
159 struct in6_addr *pin6;
160 __be32 *p32;
161
162 __entry->skaddr = sk;
163 __entry->oldstate = oldstate;
164 __entry->newstate = newstate;
165
166 __entry->family = sk->sk_family;
167 __entry->protocol = sk->sk_protocol;
168 __entry->sport = ntohs(inet->inet_sport);
169 __entry->dport = ntohs(inet->inet_dport);
170
171 p32 = (__be32 *) __entry->saddr;
172 *p32 = inet->inet_saddr;
173
174 p32 = (__be32 *) __entry->daddr;
175 *p32 = inet->inet_daddr;
176
177#if IS_ENABLED(CONFIG_IPV6)
178 if (sk->sk_family == AF_INET6) {
179 pin6 = (struct in6_addr *)__entry->saddr_v6;
180 *pin6 = sk->sk_v6_rcv_saddr;
181 pin6 = (struct in6_addr *)__entry->daddr_v6;
182 *pin6 = sk->sk_v6_daddr;
183 } else
184#endif
185 {
186 pin6 = (struct in6_addr *)__entry->saddr_v6;
187 ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
188 pin6 = (struct in6_addr *)__entry->daddr_v6;
189 ipv6_addr_set_v4mapped(inet->inet_daddr, pin6);
190 }
191 ),
192
193 TP_printk("family=%s protocol=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c oldstate=%s newstate=%s",
194 show_family_name(__entry->family),
195 show_inet_protocol_name(__entry->protocol),
196 __entry->sport, __entry->dport,
197 __entry->saddr, __entry->daddr,
198 __entry->saddr_v6, __entry->daddr_v6,
199 show_tcp_state_name(__entry->oldstate),
200 show_tcp_state_name(__entry->newstate))
201);
202
203#endif /* _TRACE_SOCK_H */
204
205/* This part must be outside protection */
206#include <trace/define_trace.h>
1/* SPDX-License-Identifier: GPL-2.0 */
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>
9#include <net/ipv6.h>
10#include <linux/tracepoint.h>
11#include <linux/ipv6.h>
12#include <linux/tcp.h>
13
14#define family_names \
15 EM(AF_INET) \
16 EMe(AF_INET6)
17
18/* The protocol traced by inet_sock_set_state */
19#define inet_protocol_names \
20 EM(IPPROTO_TCP) \
21 EM(IPPROTO_DCCP) \
22 EM(IPPROTO_SCTP) \
23 EMe(IPPROTO_MPTCP)
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
39#define skmem_kind_names \
40 EM(SK_MEM_SEND) \
41 EMe(SK_MEM_RECV)
42
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
49family_names
50inet_protocol_names
51tcp_state_names
52skmem_kind_names
53
54#undef EM
55#undef EMe
56#define EM(a) { a, #a },
57#define EMe(a) { a, #a }
58
59#define show_family_name(val) \
60 __print_symbolic(val, family_names)
61
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)
67
68#define show_skmem_kind_names(val) \
69 __print_symbolic(val, skmem_kind_names)
70
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;
86 __entry->sk_rcvbuf = READ_ONCE(sk->sk_rcvbuf);
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
95 TP_PROTO(struct sock *sk, struct proto *prot, long allocated, int kind),
96
97 TP_ARGS(sk, prot, allocated, kind),
98
99 TP_STRUCT__entry(
100 __array(char, name, 32)
101 __field(long *, sysctl_mem)
102 __field(long, allocated)
103 __field(int, sysctl_rmem)
104 __field(int, rmem_alloc)
105 __field(int, sysctl_wmem)
106 __field(int, wmem_alloc)
107 __field(int, wmem_queued)
108 __field(int, kind)
109 ),
110
111 TP_fast_assign(
112 strncpy(__entry->name, prot->name, 32);
113 __entry->sysctl_mem = prot->sysctl_mem;
114 __entry->allocated = allocated;
115 __entry->sysctl_rmem = sk_get_rmem0(sk, prot);
116 __entry->rmem_alloc = atomic_read(&sk->sk_rmem_alloc);
117 __entry->sysctl_wmem = sk_get_wmem0(sk, prot);
118 __entry->wmem_alloc = refcount_read(&sk->sk_wmem_alloc);
119 __entry->wmem_queued = READ_ONCE(sk->sk_wmem_queued);
120 __entry->kind = kind;
121 ),
122
123 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",
124 __entry->name,
125 __entry->sysctl_mem[0],
126 __entry->sysctl_mem[1],
127 __entry->sysctl_mem[2],
128 __entry->allocated,
129 __entry->sysctl_rmem,
130 __entry->rmem_alloc,
131 __entry->sysctl_wmem,
132 __entry->wmem_alloc,
133 __entry->wmem_queued,
134 show_skmem_kind_names(__entry->kind)
135 )
136);
137
138TRACE_EVENT(inet_sock_set_state,
139
140 TP_PROTO(const struct sock *sk, const int oldstate, const int newstate),
141
142 TP_ARGS(sk, oldstate, newstate),
143
144 TP_STRUCT__entry(
145 __field(const void *, skaddr)
146 __field(int, oldstate)
147 __field(int, newstate)
148 __field(__u16, sport)
149 __field(__u16, dport)
150 __field(__u16, family)
151 __field(__u16, protocol)
152 __array(__u8, saddr, 4)
153 __array(__u8, daddr, 4)
154 __array(__u8, saddr_v6, 16)
155 __array(__u8, daddr_v6, 16)
156 ),
157
158 TP_fast_assign(
159 struct inet_sock *inet = inet_sk(sk);
160 struct in6_addr *pin6;
161 __be32 *p32;
162
163 __entry->skaddr = sk;
164 __entry->oldstate = oldstate;
165 __entry->newstate = newstate;
166
167 __entry->family = sk->sk_family;
168 __entry->protocol = sk->sk_protocol;
169 __entry->sport = ntohs(inet->inet_sport);
170 __entry->dport = ntohs(inet->inet_dport);
171
172 p32 = (__be32 *) __entry->saddr;
173 *p32 = inet->inet_saddr;
174
175 p32 = (__be32 *) __entry->daddr;
176 *p32 = inet->inet_daddr;
177
178#if IS_ENABLED(CONFIG_IPV6)
179 if (sk->sk_family == AF_INET6) {
180 pin6 = (struct in6_addr *)__entry->saddr_v6;
181 *pin6 = sk->sk_v6_rcv_saddr;
182 pin6 = (struct in6_addr *)__entry->daddr_v6;
183 *pin6 = sk->sk_v6_daddr;
184 } else
185#endif
186 {
187 pin6 = (struct in6_addr *)__entry->saddr_v6;
188 ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
189 pin6 = (struct in6_addr *)__entry->daddr_v6;
190 ipv6_addr_set_v4mapped(inet->inet_daddr, pin6);
191 }
192 ),
193
194 TP_printk("family=%s protocol=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c oldstate=%s newstate=%s",
195 show_family_name(__entry->family),
196 show_inet_protocol_name(__entry->protocol),
197 __entry->sport, __entry->dport,
198 __entry->saddr, __entry->daddr,
199 __entry->saddr_v6, __entry->daddr_v6,
200 show_tcp_state_name(__entry->oldstate),
201 show_tcp_state_name(__entry->newstate))
202);
203
204TRACE_EVENT(inet_sk_error_report,
205
206 TP_PROTO(const struct sock *sk),
207
208 TP_ARGS(sk),
209
210 TP_STRUCT__entry(
211 __field(int, error)
212 __field(__u16, sport)
213 __field(__u16, dport)
214 __field(__u16, family)
215 __field(__u16, protocol)
216 __array(__u8, saddr, 4)
217 __array(__u8, daddr, 4)
218 __array(__u8, saddr_v6, 16)
219 __array(__u8, daddr_v6, 16)
220 ),
221
222 TP_fast_assign(
223 struct inet_sock *inet = inet_sk(sk);
224 struct in6_addr *pin6;
225 __be32 *p32;
226
227 __entry->error = sk->sk_err;
228 __entry->family = sk->sk_family;
229 __entry->protocol = sk->sk_protocol;
230 __entry->sport = ntohs(inet->inet_sport);
231 __entry->dport = ntohs(inet->inet_dport);
232
233 p32 = (__be32 *) __entry->saddr;
234 *p32 = inet->inet_saddr;
235
236 p32 = (__be32 *) __entry->daddr;
237 *p32 = inet->inet_daddr;
238
239#if IS_ENABLED(CONFIG_IPV6)
240 if (sk->sk_family == AF_INET6) {
241 pin6 = (struct in6_addr *)__entry->saddr_v6;
242 *pin6 = sk->sk_v6_rcv_saddr;
243 pin6 = (struct in6_addr *)__entry->daddr_v6;
244 *pin6 = sk->sk_v6_daddr;
245 } else
246#endif
247 {
248 pin6 = (struct in6_addr *)__entry->saddr_v6;
249 ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
250 pin6 = (struct in6_addr *)__entry->daddr_v6;
251 ipv6_addr_set_v4mapped(inet->inet_daddr, pin6);
252 }
253 ),
254
255 TP_printk("family=%s protocol=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c error=%d",
256 show_family_name(__entry->family),
257 show_inet_protocol_name(__entry->protocol),
258 __entry->sport, __entry->dport,
259 __entry->saddr, __entry->daddr,
260 __entry->saddr_v6, __entry->daddr_v6,
261 __entry->error)
262);
263
264#endif /* _TRACE_SOCK_H */
265
266/* This part must be outside protection */
267#include <trace/define_trace.h>