|
6 | 6 | #define _TRACE_HANDSHAKE_H
|
7 | 7 |
|
8 | 8 | #include <linux/net.h>
|
| 9 | +#include <net/tls_prot.h> |
9 | 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) |
10 | 89 |
|
11 | 90 | DECLARE_EVENT_CLASS(handshake_event_class,
|
12 | 91 | TP_PROTO(
|
@@ -106,6 +185,47 @@ DECLARE_EVENT_CLASS(handshake_error_class,
|
106 | 185 | ), \
|
107 | 186 | TP_ARGS(net, req, sk, err))
|
108 | 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 | + |
109 | 229 |
|
110 | 230 | /*
|
111 | 231 | * Request lifetime events
|
@@ -154,6 +274,46 @@ DEFINE_HANDSHAKE_ERROR(handshake_cmd_accept_err);
|
154 | 274 | DEFINE_HANDSHAKE_FD_EVENT(handshake_cmd_done);
|
155 | 275 | DEFINE_HANDSHAKE_ERROR(handshake_cmd_done_err);
|
156 | 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 | + |
157 | 317 | #endif /* _TRACE_HANDSHAKE_H */
|
158 | 318 |
|
159 | 319 | #include <trace/define_trace.h>
|
0 commit comments