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>
14 #define family_names \
18 /* The protocol traced by inet_sock_set_state */
19 #define inet_protocol_names \
24 #define tcp_state_names \
38 #define skmem_kind_names \
42 /* enums need to be exported to user space */
45 #define EM(a) TRACE_DEFINE_ENUM(a);
46 #define EMe(a) TRACE_DEFINE_ENUM(a);
55 #define EM(a) { a, #a },
56 #define EMe(a) { a, #a }
58 #define show_family_name(val) \
59 __print_symbolic(val, family_names)
61 #define show_inet_protocol_name(val) \
62 __print_symbolic(val, inet_protocol_names)
64 #define show_tcp_state_name(val) \
65 __print_symbolic(val, tcp_state_names)
67 #define show_skmem_kind_names(val) \
68 __print_symbolic(val, skmem_kind_names)
70 TRACE_EVENT(sock_rcvqueue_full
,
72 TP_PROTO(struct sock
*sk
, struct sk_buff
*skb
),
77 __field(int, rmem_alloc
)
78 __field(unsigned int, truesize
)
79 __field(int, sk_rcvbuf
)
83 __entry
->rmem_alloc
= atomic_read(&sk
->sk_rmem_alloc
);
84 __entry
->truesize
= skb
->truesize
;
85 __entry
->sk_rcvbuf
= READ_ONCE(sk
->sk_rcvbuf
);
88 TP_printk("rmem_alloc=%d truesize=%u sk_rcvbuf=%d",
89 __entry
->rmem_alloc
, __entry
->truesize
, __entry
->sk_rcvbuf
)
92 TRACE_EVENT(sock_exceed_buf_limit
,
94 TP_PROTO(struct sock
*sk
, struct proto
*prot
, long allocated
, int kind
),
96 TP_ARGS(sk
, prot
, allocated
, kind
),
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
)
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
;
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",
124 __entry
->sysctl_mem
[0],
125 __entry
->sysctl_mem
[1],
126 __entry
->sysctl_mem
[2],
128 __entry
->sysctl_rmem
,
130 __entry
->sysctl_wmem
,
132 __entry
->wmem_queued
,
133 show_skmem_kind_names(__entry
->kind
)
137 TRACE_EVENT(inet_sock_set_state
,
139 TP_PROTO(const struct sock
*sk
, const int oldstate
, const int newstate
),
141 TP_ARGS(sk
, oldstate
, newstate
),
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)
158 struct inet_sock
*inet
= inet_sk(sk
);
159 struct in6_addr
*pin6
;
162 __entry
->skaddr
= sk
;
163 __entry
->oldstate
= oldstate
;
164 __entry
->newstate
= newstate
;
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
);
171 p32
= (__be32
*) __entry
->saddr
;
172 *p32
= inet
->inet_saddr
;
174 p32
= (__be32
*) __entry
->daddr
;
175 *p32
= inet
->inet_daddr
;
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
;
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
);
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
))
203 #endif /* _TRACE_SOCK_H */
205 /* This part must be outside protection */
206 #include <trace/define_trace.h>