xref: /openbmc/linux/include/trace/events/sock.h (revision 9dae47aba0a055f761176d9297371d5bb24289ec)
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 /* The protocol traced by sock_set_state */
15 #define inet_protocol_names		\
16 		EM(IPPROTO_TCP)			\
17 		EM(IPPROTO_DCCP)		\
18 		EMe(IPPROTO_SCTP)
19 
20 #define tcp_state_names			\
21 		EM(TCP_ESTABLISHED)		\
22 		EM(TCP_SYN_SENT)		\
23 		EM(TCP_SYN_RECV)		\
24 		EM(TCP_FIN_WAIT1)		\
25 		EM(TCP_FIN_WAIT2)		\
26 		EM(TCP_TIME_WAIT)		\
27 		EM(TCP_CLOSE)			\
28 		EM(TCP_CLOSE_WAIT)		\
29 		EM(TCP_LAST_ACK)		\
30 		EM(TCP_LISTEN)			\
31 		EM(TCP_CLOSING)			\
32 		EMe(TCP_NEW_SYN_RECV)
33 
34 /* enums need to be exported to user space */
35 #undef EM
36 #undef EMe
37 #define EM(a)       TRACE_DEFINE_ENUM(a);
38 #define EMe(a)      TRACE_DEFINE_ENUM(a);
39 
40 inet_protocol_names
41 tcp_state_names
42 
43 #undef EM
44 #undef EMe
45 #define EM(a)       { a, #a },
46 #define EMe(a)      { a, #a }
47 
48 #define show_inet_protocol_name(val)    \
49 	__print_symbolic(val, inet_protocol_names)
50 
51 #define show_tcp_state_name(val)        \
52 	__print_symbolic(val, tcp_state_names)
53 
54 TRACE_EVENT(sock_rcvqueue_full,
55 
56 	TP_PROTO(struct sock *sk, struct sk_buff *skb),
57 
58 	TP_ARGS(sk, skb),
59 
60 	TP_STRUCT__entry(
61 		__field(int, rmem_alloc)
62 		__field(unsigned int, truesize)
63 		__field(int, sk_rcvbuf)
64 	),
65 
66 	TP_fast_assign(
67 		__entry->rmem_alloc = atomic_read(&sk->sk_rmem_alloc);
68 		__entry->truesize   = skb->truesize;
69 		__entry->sk_rcvbuf  = sk->sk_rcvbuf;
70 	),
71 
72 	TP_printk("rmem_alloc=%d truesize=%u sk_rcvbuf=%d",
73 		__entry->rmem_alloc, __entry->truesize, __entry->sk_rcvbuf)
74 );
75 
76 TRACE_EVENT(sock_exceed_buf_limit,
77 
78 	TP_PROTO(struct sock *sk, struct proto *prot, long allocated),
79 
80 	TP_ARGS(sk, prot, allocated),
81 
82 	TP_STRUCT__entry(
83 		__array(char, name, 32)
84 		__field(long *, sysctl_mem)
85 		__field(long, allocated)
86 		__field(int, sysctl_rmem)
87 		__field(int, rmem_alloc)
88 	),
89 
90 	TP_fast_assign(
91 		strncpy(__entry->name, prot->name, 32);
92 		__entry->sysctl_mem = prot->sysctl_mem;
93 		__entry->allocated = allocated;
94 		__entry->sysctl_rmem = sk_get_rmem0(sk, prot);
95 		__entry->rmem_alloc = atomic_read(&sk->sk_rmem_alloc);
96 	),
97 
98 	TP_printk("proto:%s sysctl_mem=%ld,%ld,%ld allocated=%ld "
99 		"sysctl_rmem=%d rmem_alloc=%d",
100 		__entry->name,
101 		__entry->sysctl_mem[0],
102 		__entry->sysctl_mem[1],
103 		__entry->sysctl_mem[2],
104 		__entry->allocated,
105 		__entry->sysctl_rmem,
106 		__entry->rmem_alloc)
107 );
108 
109 TRACE_EVENT(inet_sock_set_state,
110 
111 	TP_PROTO(const struct sock *sk, const int oldstate, const int newstate),
112 
113 	TP_ARGS(sk, oldstate, newstate),
114 
115 	TP_STRUCT__entry(
116 		__field(const void *, skaddr)
117 		__field(int, oldstate)
118 		__field(int, newstate)
119 		__field(__u16, sport)
120 		__field(__u16, dport)
121 		__field(__u8, protocol)
122 		__array(__u8, saddr, 4)
123 		__array(__u8, daddr, 4)
124 		__array(__u8, saddr_v6, 16)
125 		__array(__u8, daddr_v6, 16)
126 	),
127 
128 	TP_fast_assign(
129 		struct inet_sock *inet = inet_sk(sk);
130 		struct in6_addr *pin6;
131 		__be32 *p32;
132 
133 		__entry->skaddr = sk;
134 		__entry->oldstate = oldstate;
135 		__entry->newstate = newstate;
136 
137 		__entry->protocol = sk->sk_protocol;
138 		__entry->sport = ntohs(inet->inet_sport);
139 		__entry->dport = ntohs(inet->inet_dport);
140 
141 		p32 = (__be32 *) __entry->saddr;
142 		*p32 = inet->inet_saddr;
143 
144 		p32 = (__be32 *) __entry->daddr;
145 		*p32 =  inet->inet_daddr;
146 
147 #if IS_ENABLED(CONFIG_IPV6)
148 		if (sk->sk_family == AF_INET6) {
149 			pin6 = (struct in6_addr *)__entry->saddr_v6;
150 			*pin6 = sk->sk_v6_rcv_saddr;
151 			pin6 = (struct in6_addr *)__entry->daddr_v6;
152 			*pin6 = sk->sk_v6_daddr;
153 		} else
154 #endif
155 		{
156 			pin6 = (struct in6_addr *)__entry->saddr_v6;
157 			ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
158 			pin6 = (struct in6_addr *)__entry->daddr_v6;
159 			ipv6_addr_set_v4mapped(inet->inet_daddr, pin6);
160 		}
161 	),
162 
163 	TP_printk("protocol=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c oldstate=%s newstate=%s",
164 			show_inet_protocol_name(__entry->protocol),
165 			__entry->sport, __entry->dport,
166 			__entry->saddr, __entry->daddr,
167 			__entry->saddr_v6, __entry->daddr_v6,
168 			show_tcp_state_name(__entry->oldstate),
169 			show_tcp_state_name(__entry->newstate))
170 );
171 
172 #endif /* _TRACE_SOCK_H */
173 
174 /* This part must be outside protection */
175 #include <trace/define_trace.h>
176