summaryrefslogtreecommitdiffstats
path: root/include/trace/events/handshake.h
blob: bdd8a03cf5ba164baa57da14a228857c3044fd3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/* SPDX-License-Identifier: GPL-2.0 */
#undef TRACE_SYSTEM
#define TRACE_SYSTEM handshake

#if !defined(_TRACE_HANDSHAKE_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_HANDSHAKE_H

#include <linux/net.h>
#include <net/tls_prot.h>
#include <linux/tracepoint.h>
#include <trace/events/net_probe_common.h>

#define TLS_RECORD_TYPE_LIST \
	record_type(CHANGE_CIPHER_SPEC) \
	record_type(ALERT) \
	record_type(HANDSHAKE) \
	record_type(DATA) \
	record_type(HEARTBEAT) \
	record_type(TLS12_CID) \
	record_type_end(ACK)

#undef record_type
#undef record_type_end
#define record_type(x)		TRACE_DEFINE_ENUM(TLS_RECORD_TYPE_##x);
#define record_type_end(x)	TRACE_DEFINE_ENUM(TLS_RECORD_TYPE_##x);

TLS_RECORD_TYPE_LIST

#undef record_type
#undef record_type_end
#define record_type(x)		{ TLS_RECORD_TYPE_##x, #x },
#define record_type_end(x)	{ TLS_RECORD_TYPE_##x, #x }

#define show_tls_content_type(type) \
	__print_symbolic(type, TLS_RECORD_TYPE_LIST)

TRACE_DEFINE_ENUM(TLS_ALERT_LEVEL_WARNING);
TRACE_DEFINE_ENUM(TLS_ALERT_LEVEL_FATAL);

#define show_tls_alert_level(level) \
	__print_symbolic(level, \
		{ TLS_ALERT_LEVEL_WARNING,	"Warning" }, \
		{ TLS_ALERT_LEVEL_FATAL,	"Fatal" })

#define TLS_ALERT_DESCRIPTION_LIST \
	alert_description(CLOSE_NOTIFY) \
	alert_description(UNEXPECTED_MESSAGE) \
	alert_description(BAD_RECORD_MAC) \
	alert_description(RECORD_OVERFLOW) \
	alert_description(HANDSHAKE_FAILURE) \
	alert_description(BAD_CERTIFICATE) \
	alert_description(UNSUPPORTED_CERTIFICATE) \
	alert_description(CERTIFICATE_REVOKED) \
	alert_description(CERTIFICATE_EXPIRED) \
	alert_description(CERTIFICATE_UNKNOWN) \
	alert_description(ILLEGAL_PARAMETER) \
	alert_description(UNKNOWN_CA) \
	alert_description(ACCESS_DENIED) \
	alert_description(DECODE_ERROR) \
	alert_description(DECRYPT_ERROR) \
	alert_description(TOO_MANY_CIDS_REQUESTED) \
	alert_description(PROTOCOL_VERSION) \
	alert_description(INSUFFICIENT_SECURITY) \
	alert_description(INTERNAL_ERROR) \
	alert_description(INAPPROPRIATE_FALLBACK) \
	alert_description(USER_CANCELED) \
	alert_description(MISSING_EXTENSION) \
	alert_description(UNSUPPORTED_EXTENSION) \
	alert_description(UNRECOGNIZED_NAME) \
	alert_description(BAD_CERTIFICATE_STATUS_RESPONSE) \
	alert_description(UNKNOWN_PSK_IDENTITY) \
	alert_description(CERTIFICATE_REQUIRED) \
	alert_description_end(NO_APPLICATION_PROTOCOL)

#undef alert_description
#undef alert_description_end
#define alert_description(x)		TRACE_DEFINE_ENUM(TLS_ALERT_DESC_##x);
#define alert_description_end(x)	TRACE_DEFINE_ENUM(TLS_ALERT_DESC_##x);

TLS_ALERT_DESCRIPTION_LIST

#undef alert_description
#undef alert_description_end
#define alert_description(x)		{ TLS_ALERT_DESC_##x, #x },
#define alert_description_end(x)	{ TLS_ALERT_DESC_##x, #x }

#define show_tls_alert_description(desc) \
	__print_symbolic(desc, TLS_ALERT_DESCRIPTION_LIST)

DECLARE_EVENT_CLASS(handshake_event_class,
	TP_PROTO(
		const struct net *net,
		const struct handshake_req *req,
		const struct sock *sk
	),
	TP_ARGS(net, req, sk),
	TP_STRUCT__entry(
		__field(const void *, req)
		__field(const void *, sk)
		__field(unsigned int, netns_ino)
	),
	TP_fast_assign(
		__entry->req = req;
		__entry->sk = sk;
		__entry->netns_ino = net->ns.inum;
	),
	TP_printk("req=%p sk=%p",
		__entry->req, __entry->sk
	)
);
#define DEFINE_HANDSHAKE_EVENT(name)				\
	DEFINE_EVENT(handshake_event_class, name,		\
		TP_PROTO(					\
			const struct net *net,			\
			const struct handshake_req *req,	\
			const struct sock *sk			\
		),						\
		TP_ARGS(net, req, sk))

DECLARE_EVENT_CLASS(handshake_fd_class,
	TP_PROTO(
		const struct net *net,
		const struct handshake_req *req,
		const struct sock *sk,
		int fd
	),
	TP_ARGS(net, req, sk, fd),
	TP_STRUCT__entry(
		__field(const void *, req)
		__field(const void *, sk)
		__field(int, fd)
		__field(unsigned int, netns_ino)
	),
	TP_fast_assign(
		__entry->req = req;
		__entry->sk = req->hr_sk;
		__entry->fd = fd;
		__entry->netns_ino = net->ns.inum;
	),
	TP_printk("req=%p sk=%p fd=%d",
		__entry->req, __entry->sk, __entry->fd
	)
);
#define DEFINE_HANDSHAKE_FD_EVENT(name)				\
	DEFINE_EVENT(handshake_fd_class, name,			\
		TP_PROTO(					\
			const struct net *net,			\
			const struct handshake_req *req,	\
			const struct sock *sk,			\
			int fd					\
		),						\
		TP_ARGS(net, req, sk, fd))

DECLARE_EVENT_CLASS(handshake_error_class,
	TP_PROTO(
		const struct net *net,
		const struct handshake_req *req,
		const struct sock *sk,
		int err
	),
	TP_ARGS(net, req, sk, err),
	TP_STRUCT__entry(
		__field(const void *, req)
		__field(const void *, sk)
		__field(int, err)
		__field(unsigned int, netns_ino)
	),
	TP_fast_assign(
		__entry->req = req;
		__entry->sk = sk;
		__entry->err = err;
		__entry->netns_ino = net->ns.inum;
	),
	TP_printk("req=%p sk=%p err=%d",
		__entry->req, __entry->sk, __entry->err
	)
);
#define DEFINE_HANDSHAKE_ERROR(name)				\
	DEFINE_EVENT(handshake_error_class, name,		\
		TP_PROTO(					\
			const struct net *net,			\
			const struct handshake_req *req,	\
			const struct sock *sk,			\
			int err					\
		),						\
		TP_ARGS(net, req, sk, err))

DECLARE_EVENT_CLASS(handshake_alert_class,
	TP_PROTO(
		const struct sock *sk,
		unsigned char level,
		unsigned char description
	),
	TP_ARGS(sk, level, description),
	TP_STRUCT__entry(
		/* sockaddr_in6 is always bigger than sockaddr_in */
		__array(__u8, saddr, sizeof(struct sockaddr_in6))
		__array(__u8, daddr, sizeof(struct sockaddr_in6))
		__field(unsigned int, netns_ino)
		__field(unsigned long, level)
		__field(unsigned long, description)
	),
	TP_fast_assign(
		const struct inet_sock *inet = inet_sk(sk);

		memset(__entry->saddr, 0, sizeof(struct sockaddr_in6));
		memset(__entry->daddr, 0, sizeof(struct sockaddr_in6));
		TP_STORE_ADDR_PORTS(__entry, inet, sk);

		__entry->netns_ino = sock_net(sk)->ns.inum;
		__entry->level = level;
		__entry->description = description;
	),
	TP_printk("src=%pISpc dest=%pISpc %s: %s",
		__entry->saddr, __entry->daddr,
		show_tls_alert_level(__entry->level),
		show_tls_alert_description(__entry->description)
	)
);
#define DEFINE_HANDSHAKE_ALERT(name)				\
	DEFINE_EVENT(handshake_alert_class, name,		\
		TP_PROTO(					\
			const struct sock *sk,			\
			unsigned char level,			\
			unsigned char description		\
		),						\
		TP_ARGS(sk, level, description))


/*
 * Request lifetime events
 */

DEFINE_HANDSHAKE_EVENT(handshake_submit);
DEFINE_HANDSHAKE_ERROR(handshake_submit_err);
DEFINE_HANDSHAKE_EVENT(handshake_cancel);
DEFINE_HANDSHAKE_EVENT(handshake_cancel_none);
DEFINE_HANDSHAKE_EVENT(handshake_cancel_busy);
DEFINE_HANDSHAKE_EVENT(handshake_destruct);


TRACE_EVENT(handshake_complete,
	TP_PROTO(
		const struct net *net,
		const struct handshake_req *req,
		const struct sock *sk,
		int status
	),
	TP_ARGS(net, req, sk, status),
	TP_STRUCT__entry(
		__field(const void *, req)
		__field(const void *, sk)
		__field(int, status)
		__field(unsigned int, netns_ino)
	),
	TP_fast_assign(
		__entry->req = req;
		__entry->sk = sk;
		__entry->status = status;
		__entry->netns_ino = net->ns.inum;
	),
	TP_printk("req=%p sk=%p status=%d",
		__entry->req, __entry->sk, __entry->status
	)
);

/*
 * Netlink events
 */

DEFINE_HANDSHAKE_ERROR(handshake_notify_err);
DEFINE_HANDSHAKE_FD_EVENT(handshake_cmd_accept);
DEFINE_HANDSHAKE_ERROR(handshake_cmd_accept_err);
DEFINE_HANDSHAKE_FD_EVENT(handshake_cmd_done);
DEFINE_HANDSHAKE_ERROR(handshake_cmd_done_err);

/*
 * TLS Record events
 */

TRACE_EVENT(tls_contenttype,
	TP_PROTO(
		const struct sock *sk,
		unsigned char type
	),
	TP_ARGS(sk, type),
	TP_STRUCT__entry(
		/* sockaddr_in6 is always bigger than sockaddr_in */
		__array(__u8, saddr, sizeof(struct sockaddr_in6))
		__array(__u8, daddr, sizeof(struct sockaddr_in6))
		__field(unsigned int, netns_ino)
		__field(unsigned long, type)
	),
	TP_fast_assign(
		const struct inet_sock *inet = inet_sk(sk);

		memset(__entry->saddr, 0, sizeof(struct sockaddr_in6));
		memset(__entry->daddr, 0, sizeof(struct sockaddr_in6));
		TP_STORE_ADDR_PORTS(__entry, inet, sk);

		__entry->netns_ino = sock_net(sk)->ns.inum;
		__entry->type = type;
	),
	TP_printk("src=%pISpc dest=%pISpc %s",
		__entry->saddr, __entry->daddr,
		show_tls_content_type(__entry->type)
	)
);

/*
 * TLS Alert events
 */

DEFINE_HANDSHAKE_ALERT(tls_alert_send);
DEFINE_HANDSHAKE_ALERT(tls_alert_recv);

#endif /* _TRACE_HANDSHAKE_H */

#include <trace/define_trace.h>