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 /* enums need to be exported to user space */
41 #define EM(a) TRACE_DEFINE_ENUM(a);
42 #define EMe(a) TRACE_DEFINE_ENUM(a);
50 #define EM(a) { a, #a },
51 #define EMe(a) { a, #a }
53 #define show_family_name(val) \
54 __print_symbolic(val, family_names)
56 #define show_inet_protocol_name(val) \
57 __print_symbolic(val, inet_protocol_names)
59 #define show_tcp_state_name(val) \
60 __print_symbolic(val, tcp_state_names)
62 TRACE_EVENT(sock_rcvqueue_full
,
64 TP_PROTO(struct sock
*sk
, struct sk_buff
*skb
),
69 __field(int, rmem_alloc
)
70 __field(unsigned int, truesize
)
71 __field(int, sk_rcvbuf
)
75 __entry
->rmem_alloc
= atomic_read(&sk
->sk_rmem_alloc
);
76 __entry
->truesize
= skb
->truesize
;
77 __entry
->sk_rcvbuf
= sk
->sk_rcvbuf
;
80 TP_printk("rmem_alloc=%d truesize=%u sk_rcvbuf=%d",
81 __entry
->rmem_alloc
, __entry
->truesize
, __entry
->sk_rcvbuf
)
84 TRACE_EVENT(sock_exceed_buf_limit
,
86 TP_PROTO(struct sock
*sk
, struct proto
*prot
, long allocated
),
88 TP_ARGS(sk
, prot
, allocated
),
91 __array(char, name
, 32)
92 __field(long *, sysctl_mem
)
93 __field(long, allocated
)
94 __field(int, sysctl_rmem
)
95 __field(int, rmem_alloc
)
99 strncpy(__entry
->name
, prot
->name
, 32);
100 __entry
->sysctl_mem
= prot
->sysctl_mem
;
101 __entry
->allocated
= allocated
;
102 __entry
->sysctl_rmem
= sk_get_rmem0(sk
, prot
);
103 __entry
->rmem_alloc
= atomic_read(&sk
->sk_rmem_alloc
);
106 TP_printk("proto:%s sysctl_mem=%ld,%ld,%ld allocated=%ld "
107 "sysctl_rmem=%d rmem_alloc=%d",
109 __entry
->sysctl_mem
[0],
110 __entry
->sysctl_mem
[1],
111 __entry
->sysctl_mem
[2],
113 __entry
->sysctl_rmem
,
117 TRACE_EVENT(inet_sock_set_state
,
119 TP_PROTO(const struct sock
*sk
, const int oldstate
, const int newstate
),
121 TP_ARGS(sk
, oldstate
, newstate
),
124 __field(const void *, skaddr
)
125 __field(int, oldstate
)
126 __field(int, newstate
)
127 __field(__u16
, sport
)
128 __field(__u16
, dport
)
129 __field(__u16
, family
)
130 __field(__u8
, protocol
)
131 __array(__u8
, saddr
, 4)
132 __array(__u8
, daddr
, 4)
133 __array(__u8
, saddr_v6
, 16)
134 __array(__u8
, daddr_v6
, 16)
138 struct inet_sock
*inet
= inet_sk(sk
);
139 struct in6_addr
*pin6
;
142 __entry
->skaddr
= sk
;
143 __entry
->oldstate
= oldstate
;
144 __entry
->newstate
= newstate
;
146 __entry
->family
= sk
->sk_family
;
147 __entry
->protocol
= sk
->sk_protocol
;
148 __entry
->sport
= ntohs(inet
->inet_sport
);
149 __entry
->dport
= ntohs(inet
->inet_dport
);
151 p32
= (__be32
*) __entry
->saddr
;
152 *p32
= inet
->inet_saddr
;
154 p32
= (__be32
*) __entry
->daddr
;
155 *p32
= inet
->inet_daddr
;
157 #if IS_ENABLED(CONFIG_IPV6)
158 if (sk
->sk_family
== AF_INET6
) {
159 pin6
= (struct in6_addr
*)__entry
->saddr_v6
;
160 *pin6
= sk
->sk_v6_rcv_saddr
;
161 pin6
= (struct in6_addr
*)__entry
->daddr_v6
;
162 *pin6
= sk
->sk_v6_daddr
;
166 pin6
= (struct in6_addr
*)__entry
->saddr_v6
;
167 ipv6_addr_set_v4mapped(inet
->inet_saddr
, pin6
);
168 pin6
= (struct in6_addr
*)__entry
->daddr_v6
;
169 ipv6_addr_set_v4mapped(inet
->inet_daddr
, pin6
);
173 TP_printk("family=%s protocol=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c oldstate=%s newstate=%s",
174 show_family_name(__entry
->family
),
175 show_inet_protocol_name(__entry
->protocol
),
176 __entry
->sport
, __entry
->dport
,
177 __entry
->saddr
, __entry
->daddr
,
178 __entry
->saddr_v6
, __entry
->daddr_v6
,
179 show_tcp_state_name(__entry
->oldstate
),
180 show_tcp_state_name(__entry
->newstate
))
183 #endif /* _TRACE_SOCK_H */
185 /* This part must be outside protection */
186 #include <trace/define_trace.h>