xref: /openbmc/linux/include/trace/events/handshake.h (revision b470985c)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #undef TRACE_SYSTEM
3 #define TRACE_SYSTEM handshake
4 
5 #if !defined(_TRACE_HANDSHAKE_H) || defined(TRACE_HEADER_MULTI_READ)
6 #define _TRACE_HANDSHAKE_H
7 
8 #include <linux/net.h>
9 #include <net/tls_prot.h>
10 #include <linux/tracepoint.h>
11 #include <trace/events/net_probe_common.h>
12 
13 #define TLS_RECORD_TYPE_LIST \
14 	record_type(CHANGE_CIPHER_SPEC) \
15 	record_type(ALERT) \
16 	record_type(HANDSHAKE) \
17 	record_type(DATA) \
18 	record_type(HEARTBEAT) \
19 	record_type(TLS12_CID) \
20 	record_type_end(ACK)
21 
22 #undef record_type
23 #undef record_type_end
24 #define record_type(x)		TRACE_DEFINE_ENUM(TLS_RECORD_TYPE_##x);
25 #define record_type_end(x)	TRACE_DEFINE_ENUM(TLS_RECORD_TYPE_##x);
26 
27 TLS_RECORD_TYPE_LIST
28 
29 #undef record_type
30 #undef record_type_end
31 #define record_type(x)		{ TLS_RECORD_TYPE_##x, #x },
32 #define record_type_end(x)	{ TLS_RECORD_TYPE_##x, #x }
33 
34 #define show_tls_content_type(type) \
35 	__print_symbolic(type, TLS_RECORD_TYPE_LIST)
36 
37 TRACE_DEFINE_ENUM(TLS_ALERT_LEVEL_WARNING);
38 TRACE_DEFINE_ENUM(TLS_ALERT_LEVEL_FATAL);
39 
40 #define show_tls_alert_level(level) \
41 	__print_symbolic(level, \
42 		{ TLS_ALERT_LEVEL_WARNING,	"Warning" }, \
43 		{ TLS_ALERT_LEVEL_FATAL,	"Fatal" })
44 
45 #define TLS_ALERT_DESCRIPTION_LIST \
46 	alert_description(CLOSE_NOTIFY) \
47 	alert_description(UNEXPECTED_MESSAGE) \
48 	alert_description(BAD_RECORD_MAC) \
49 	alert_description(RECORD_OVERFLOW) \
50 	alert_description(HANDSHAKE_FAILURE) \
51 	alert_description(BAD_CERTIFICATE) \
52 	alert_description(UNSUPPORTED_CERTIFICATE) \
53 	alert_description(CERTIFICATE_REVOKED) \
54 	alert_description(CERTIFICATE_EXPIRED) \
55 	alert_description(CERTIFICATE_UNKNOWN) \
56 	alert_description(ILLEGAL_PARAMETER) \
57 	alert_description(UNKNOWN_CA) \
58 	alert_description(ACCESS_DENIED) \
59 	alert_description(DECODE_ERROR) \
60 	alert_description(DECRYPT_ERROR) \
61 	alert_description(TOO_MANY_CIDS_REQUESTED) \
62 	alert_description(PROTOCOL_VERSION) \
63 	alert_description(INSUFFICIENT_SECURITY) \
64 	alert_description(INTERNAL_ERROR) \
65 	alert_description(INAPPROPRIATE_FALLBACK) \
66 	alert_description(USER_CANCELED) \
67 	alert_description(MISSING_EXTENSION) \
68 	alert_description(UNSUPPORTED_EXTENSION) \
69 	alert_description(UNRECOGNIZED_NAME) \
70 	alert_description(BAD_CERTIFICATE_STATUS_RESPONSE) \
71 	alert_description(UNKNOWN_PSK_IDENTITY) \
72 	alert_description(CERTIFICATE_REQUIRED) \
73 	alert_description_end(NO_APPLICATION_PROTOCOL)
74 
75 #undef alert_description
76 #undef alert_description_end
77 #define alert_description(x)		TRACE_DEFINE_ENUM(TLS_ALERT_DESC_##x);
78 #define alert_description_end(x)	TRACE_DEFINE_ENUM(TLS_ALERT_DESC_##x);
79 
80 TLS_ALERT_DESCRIPTION_LIST
81 
82 #undef alert_description
83 #undef alert_description_end
84 #define alert_description(x)		{ TLS_ALERT_DESC_##x, #x },
85 #define alert_description_end(x)	{ TLS_ALERT_DESC_##x, #x }
86 
87 #define show_tls_alert_description(desc) \
88 	__print_symbolic(desc, TLS_ALERT_DESCRIPTION_LIST)
89 
90 DECLARE_EVENT_CLASS(handshake_event_class,
91 	TP_PROTO(
92 		const struct net *net,
93 		const struct handshake_req *req,
94 		const struct sock *sk
95 	),
96 	TP_ARGS(net, req, sk),
97 	TP_STRUCT__entry(
98 		__field(const void *, req)
99 		__field(const void *, sk)
100 		__field(unsigned int, netns_ino)
101 	),
102 	TP_fast_assign(
103 		__entry->req = req;
104 		__entry->sk = sk;
105 		__entry->netns_ino = net->ns.inum;
106 	),
107 	TP_printk("req=%p sk=%p",
108 		__entry->req, __entry->sk
109 	)
110 );
111 #define DEFINE_HANDSHAKE_EVENT(name)				\
112 	DEFINE_EVENT(handshake_event_class, name,		\
113 		TP_PROTO(					\
114 			const struct net *net,			\
115 			const struct handshake_req *req,	\
116 			const struct sock *sk			\
117 		),						\
118 		TP_ARGS(net, req, sk))
119 
120 DECLARE_EVENT_CLASS(handshake_fd_class,
121 	TP_PROTO(
122 		const struct net *net,
123 		const struct handshake_req *req,
124 		const struct sock *sk,
125 		int fd
126 	),
127 	TP_ARGS(net, req, sk, fd),
128 	TP_STRUCT__entry(
129 		__field(const void *, req)
130 		__field(const void *, sk)
131 		__field(int, fd)
132 		__field(unsigned int, netns_ino)
133 	),
134 	TP_fast_assign(
135 		__entry->req = req;
136 		__entry->sk = req->hr_sk;
137 		__entry->fd = fd;
138 		__entry->netns_ino = net->ns.inum;
139 	),
140 	TP_printk("req=%p sk=%p fd=%d",
141 		__entry->req, __entry->sk, __entry->fd
142 	)
143 );
144 #define DEFINE_HANDSHAKE_FD_EVENT(name)				\
145 	DEFINE_EVENT(handshake_fd_class, name,			\
146 		TP_PROTO(					\
147 			const struct net *net,			\
148 			const struct handshake_req *req,	\
149 			const struct sock *sk,			\
150 			int fd					\
151 		),						\
152 		TP_ARGS(net, req, sk, fd))
153 
154 DECLARE_EVENT_CLASS(handshake_error_class,
155 	TP_PROTO(
156 		const struct net *net,
157 		const struct handshake_req *req,
158 		const struct sock *sk,
159 		int err
160 	),
161 	TP_ARGS(net, req, sk, err),
162 	TP_STRUCT__entry(
163 		__field(const void *, req)
164 		__field(const void *, sk)
165 		__field(int, err)
166 		__field(unsigned int, netns_ino)
167 	),
168 	TP_fast_assign(
169 		__entry->req = req;
170 		__entry->sk = sk;
171 		__entry->err = err;
172 		__entry->netns_ino = net->ns.inum;
173 	),
174 	TP_printk("req=%p sk=%p err=%d",
175 		__entry->req, __entry->sk, __entry->err
176 	)
177 );
178 #define DEFINE_HANDSHAKE_ERROR(name)				\
179 	DEFINE_EVENT(handshake_error_class, name,		\
180 		TP_PROTO(					\
181 			const struct net *net,			\
182 			const struct handshake_req *req,	\
183 			const struct sock *sk,			\
184 			int err					\
185 		),						\
186 		TP_ARGS(net, req, sk, err))
187 
188 DECLARE_EVENT_CLASS(handshake_alert_class,
189 	TP_PROTO(
190 		const struct sock *sk,
191 		unsigned char level,
192 		unsigned char description
193 	),
194 	TP_ARGS(sk, level, description),
195 	TP_STRUCT__entry(
196 		/* sockaddr_in6 is always bigger than sockaddr_in */
197 		__array(__u8, saddr, sizeof(struct sockaddr_in6))
198 		__array(__u8, daddr, sizeof(struct sockaddr_in6))
199 		__field(unsigned int, netns_ino)
200 		__field(unsigned long, level)
201 		__field(unsigned long, description)
202 	),
203 	TP_fast_assign(
204 		const struct inet_sock *inet = inet_sk(sk);
205 
206 		memset(__entry->saddr, 0, sizeof(struct sockaddr_in6));
207 		memset(__entry->daddr, 0, sizeof(struct sockaddr_in6));
208 		TP_STORE_ADDR_PORTS(__entry, inet, sk);
209 
210 		__entry->netns_ino = sock_net(sk)->ns.inum;
211 		__entry->level = level;
212 		__entry->description = description;
213 	),
214 	TP_printk("src=%pISpc dest=%pISpc %s: %s",
215 		__entry->saddr, __entry->daddr,
216 		show_tls_alert_level(__entry->level),
217 		show_tls_alert_description(__entry->description)
218 	)
219 );
220 #define DEFINE_HANDSHAKE_ALERT(name)				\
221 	DEFINE_EVENT(handshake_alert_class, name,		\
222 		TP_PROTO(					\
223 			const struct sock *sk,			\
224 			unsigned char level,			\
225 			unsigned char description		\
226 		),						\
227 		TP_ARGS(sk, level, description))
228 
229 
230 /*
231  * Request lifetime events
232  */
233 
234 DEFINE_HANDSHAKE_EVENT(handshake_submit);
235 DEFINE_HANDSHAKE_ERROR(handshake_submit_err);
236 DEFINE_HANDSHAKE_EVENT(handshake_cancel);
237 DEFINE_HANDSHAKE_EVENT(handshake_cancel_none);
238 DEFINE_HANDSHAKE_EVENT(handshake_cancel_busy);
239 DEFINE_HANDSHAKE_EVENT(handshake_destruct);
240 
241 
242 TRACE_EVENT(handshake_complete,
243 	TP_PROTO(
244 		const struct net *net,
245 		const struct handshake_req *req,
246 		const struct sock *sk,
247 		int status
248 	),
249 	TP_ARGS(net, req, sk, status),
250 	TP_STRUCT__entry(
251 		__field(const void *, req)
252 		__field(const void *, sk)
253 		__field(int, status)
254 		__field(unsigned int, netns_ino)
255 	),
256 	TP_fast_assign(
257 		__entry->req = req;
258 		__entry->sk = sk;
259 		__entry->status = status;
260 		__entry->netns_ino = net->ns.inum;
261 	),
262 	TP_printk("req=%p sk=%p status=%d",
263 		__entry->req, __entry->sk, __entry->status
264 	)
265 );
266 
267 /*
268  * Netlink events
269  */
270 
271 DEFINE_HANDSHAKE_ERROR(handshake_notify_err);
272 DEFINE_HANDSHAKE_FD_EVENT(handshake_cmd_accept);
273 DEFINE_HANDSHAKE_ERROR(handshake_cmd_accept_err);
274 DEFINE_HANDSHAKE_FD_EVENT(handshake_cmd_done);
275 DEFINE_HANDSHAKE_ERROR(handshake_cmd_done_err);
276 
277 /*
278  * TLS Record events
279  */
280 
281 TRACE_EVENT(tls_contenttype,
282 	TP_PROTO(
283 		const struct sock *sk,
284 		unsigned char type
285 	),
286 	TP_ARGS(sk, type),
287 	TP_STRUCT__entry(
288 		/* sockaddr_in6 is always bigger than sockaddr_in */
289 		__array(__u8, saddr, sizeof(struct sockaddr_in6))
290 		__array(__u8, daddr, sizeof(struct sockaddr_in6))
291 		__field(unsigned int, netns_ino)
292 		__field(unsigned long, type)
293 	),
294 	TP_fast_assign(
295 		const struct inet_sock *inet = inet_sk(sk);
296 
297 		memset(__entry->saddr, 0, sizeof(struct sockaddr_in6));
298 		memset(__entry->daddr, 0, sizeof(struct sockaddr_in6));
299 		TP_STORE_ADDR_PORTS(__entry, inet, sk);
300 
301 		__entry->netns_ino = sock_net(sk)->ns.inum;
302 		__entry->type = type;
303 	),
304 	TP_printk("src=%pISpc dest=%pISpc %s",
305 		__entry->saddr, __entry->daddr,
306 		show_tls_content_type(__entry->type)
307 	)
308 );
309 
310 /*
311  * TLS Alert events
312  */
313 
314 DEFINE_HANDSHAKE_ALERT(tls_alert_send);
315 DEFINE_HANDSHAKE_ALERT(tls_alert_recv);
316 
317 #endif /* _TRACE_HANDSHAKE_H */
318 
319 #include <trace/define_trace.h>
320