Fix: move "user" attribute from field to type
[lttng-modules.git] / instrumentation / events / lttng-module / net.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #undef TRACE_SYSTEM
3 #define TRACE_SYSTEM net
4
5 #if !defined(LTTNG_TRACE_NET_H) || defined(TRACE_HEADER_MULTI_READ)
6 #define LTTNG_TRACE_NET_H
7
8 #include <probes/lttng-tracepoint-event.h>
9 #include <linux/skbuff.h>
10 #include <linux/netdevice.h>
11 #include <linux/ip.h>
12 #include <linux/ipv6.h>
13 #include <linux/tcp.h>
14 #include <lttng-kernel-version.h>
15 #include <lttng-endian.h>
16 #include <net/sock.h>
17
18 #ifndef ONCE_LTTNG_NET_H
19 #define ONCE_LTTNG_NET_H
20
21 static inline unsigned char __has_network_hdr(struct sk_buff *skb)
22 {
23 /*
24 * If the header is not set yet, the network header will point
25 * to the head.
26 */
27 return skb_network_header(skb) != skb->head;
28 }
29
30 static struct lttng_event_field emptyfields[] = {
31 };
32
33 /* Structures for transport headers. */
34
35 static struct lttng_event_field tcpfields[] = {
36 [0] = {
37 .name = "source_port",
38 .type = __type_integer(uint16_t, 0, 0, 0,
39 __BIG_ENDIAN, 0, 10, none),
40 },
41 [1] = {
42 .name = "dest_port",
43 .type = __type_integer(uint16_t, 0, 0, 0,
44 __BIG_ENDIAN, 0, 10, none),
45 },
46 [2] = {
47 .name = "seq",
48 .type = __type_integer(uint32_t, 0, 0, 0,
49 __BIG_ENDIAN, 0, 10, none),
50 },
51 [3] = {
52 .name = "ack_seq",
53 .type = __type_integer(uint32_t, 0, 0, 0,
54 __BIG_ENDIAN, 0, 10, none),
55 },
56 [4] = {
57 .name = "data_offset",
58 .type = __type_integer(uint8_t, 4, 4, 0,
59 __BIG_ENDIAN, 0, 10, none),
60 },
61 [5] = {
62 .name = "reserved",
63 .type = __type_integer(uint8_t, 3, 1, 0,
64 __BIG_ENDIAN, 0, 10, none),
65 },
66 [6] = {
67 .name = "flags",
68 .type = __type_integer(uint8_t, 9, 1, 0,
69 __BIG_ENDIAN, 0, 16, none),
70 },
71 [7] = {
72 .name = "window_size",
73 .type = __type_integer(uint16_t, 0, 0, 0,
74 __BIG_ENDIAN, 0, 10, none),
75 },
76 [8] = {
77 .name = "checksum",
78 .type = __type_integer(uint16_t, 0, 0, 0,
79 __BIG_ENDIAN, 0, 16, none),
80 },
81 [9] = {
82 .name = "urg_ptr",
83 .type = __type_integer(uint16_t, 0, 0, 0,
84 __BIG_ENDIAN, 0, 10, none),
85 },
86 };
87
88 static struct lttng_event_field transport_fields[] = {
89 [0] = {
90 .name = "unknown",
91 .type = {
92 .atype = atype_struct,
93 .u._struct.nr_fields = ARRAY_SIZE(emptyfields),
94 .u._struct.fields = emptyfields,
95 },
96 },
97 [1] = {
98 .name = "tcp",
99 .type = {
100 .atype = atype_struct,
101 .u._struct.nr_fields = ARRAY_SIZE(tcpfields),
102 .u._struct.fields = tcpfields,
103 },
104 },
105 };
106
107 enum transport_header_types {
108 TH_NONE = 0,
109 TH_TCP = 1,
110 };
111
112 static inline enum transport_header_types __get_transport_header_type(struct sk_buff *skb)
113 {
114 if (__has_network_hdr(skb)) {
115 /*
116 * When both transport and network headers are set,
117 * transport header is greater than network header,
118 * otherwise it points to head.
119 */
120 if (skb->transport_header > skb->network_header) {
121 /*
122 * Get the transport protocol from the network
123 * header's data. This method works both for
124 * sent and received packets.
125 */
126 if ((skb->protocol == htons(ETH_P_IP) &&
127 ip_hdr(skb)->protocol == IPPROTO_TCP) ||
128 (skb->protocol == htons(ETH_P_IPV6) &&
129 ipv6_hdr(skb)->nexthdr == IPPROTO_TCP))
130 return TH_TCP;
131 }
132 /* Fallthrough for other cases where header is not TCP. */
133 }
134 return TH_NONE;
135 }
136
137 static struct lttng_enum_entry proto_transport_enum_entries[] = {
138 [0] = {
139 .start = { .value = 0, .signedness = 0, },
140 .end = { .value = IPPROTO_TCP - 1, .signedness = 0, },
141 .string = "_unknown",
142 },
143 [1] = {
144 .start = { .value = IPPROTO_TCP, .signedness = 0, },
145 .end = { .value = IPPROTO_TCP, .signedness = 0, },
146 .string = "_tcp",
147 },
148 [2] = {
149 .start = { .value = IPPROTO_TCP + 1, .signedness = 0, },
150 .end = { .value = 255, .signedness = 0, },
151 .string = "_unknown",
152 },
153 };
154
155 static const struct lttng_enum_desc proto_transport_header_type = {
156 .name = "proto_transport_header_type",
157 .entries = proto_transport_enum_entries,
158 .nr_entries = ARRAY_SIZE(proto_transport_enum_entries),
159 };
160
161 static struct lttng_enum_entry transport_enum_entries[] = {
162 [0] = {
163 .start = { .value = TH_NONE, .signedness = 0, },
164 .end = { .value = TH_NONE, .signedness = 0, },
165 .string = "_unknown",
166 },
167 [1] = {
168 .start = { .value = TH_TCP, .signedness = 0, },
169 .end = { .value = TH_TCP, .signedness = 0, },
170 .string = "_tcp",
171 },
172 };
173
174 static const struct lttng_enum_desc transport_header_type = {
175 .name = "transport_header_type",
176 .entries = transport_enum_entries,
177 .nr_entries = ARRAY_SIZE(transport_enum_entries),
178 };
179
180 /* Structures for network headers. */
181
182 static struct lttng_event_field ipv4fields[] = {
183 [0] = {
184 .name = "version",
185 .type = __type_integer(uint8_t, 4, 4, 0,
186 __BIG_ENDIAN, 0, 10, none),
187 },
188 [1] = {
189 .name = "ihl",
190 .type = __type_integer(uint8_t, 4, 4, 0,
191 __BIG_ENDIAN, 0, 10, none),
192 },
193 [2] = {
194 .name = "tos",
195 .type = __type_integer(uint8_t, 0, 0, 0,
196 __BIG_ENDIAN, 0, 10, none),
197 },
198 [3] = {
199 .name = "tot_len",
200 .type = __type_integer(uint16_t, 0, 0, 0,
201 __BIG_ENDIAN, 0, 10, none),
202 },
203 [4] = {
204 .name = "id",
205 .type = __type_integer(uint16_t, 0, 0, 0,
206 __BIG_ENDIAN, 0, 16, none),
207 },
208 [5] = {
209 .name = "frag_off",
210 .type = __type_integer(uint16_t, 0, 0, 0,
211 __BIG_ENDIAN, 0, 10, none),
212 },
213 [6] = {
214 .name = "ttl",
215 .type = __type_integer(uint8_t, 0, 0, 0,
216 __BIG_ENDIAN, 0, 10, none),
217 },
218 [7] = {
219 .name = "protocol",
220 .type = {
221 .atype = atype_enum,
222 .u.basic.enumeration.desc =
223 &proto_transport_header_type,
224 .u.basic.enumeration.container_type = {
225 .size = 8,
226 .alignment = 8,
227 .signedness = 0,
228 .reverse_byte_order =
229 __BIG_ENDIAN != __BYTE_ORDER,
230 .base = 10,
231 .user = 0,
232 .encoding = lttng_encode_none,
233 },
234 },
235 },
236 [8] = {
237 .name = "checksum",
238 .type = __type_integer(uint16_t, 0, 0, 0,
239 __BIG_ENDIAN, 0, 16, none),
240 },
241 [9] = {
242 .name = "saddr",
243 .type = {
244 .atype = atype_array,
245 .u.array.elem_type =
246 __type_integer(uint8_t, 0, 0, 0,
247 __BIG_ENDIAN, 0, 10, none),
248 .u.array.length = 4,
249 .u.array.elem_alignment = lttng_alignof(uint8_t),
250 },
251 },
252 [10] = {
253 .name = "daddr",
254 .type = {
255 .atype = atype_array,
256 .u.array.elem_type =
257 __type_integer(uint8_t, 0, 0, 0,
258 __BIG_ENDIAN, 0, 10, none),
259 .u.array.length = 4,
260 .u.array.elem_alignment = lttng_alignof(uint8_t),
261 },
262 },
263 [11] = {
264 .name = "transport_header_type",
265 .type = {
266 .atype = atype_enum,
267 .u.basic.enumeration.desc = &transport_header_type,
268 .u.basic.enumeration.container_type = {
269 .size = 8,
270 .alignment = 8,
271 .signedness = 0,
272 .reverse_byte_order = 0,
273 .base = 10,
274 .user = 0,
275 .encoding = lttng_encode_none,
276 },
277 },
278 },
279 [12] = {
280 .name = "transport_header",
281 .type = {
282 .atype = atype_variant,
283 .u.variant.tag_name = "transport_header_type",
284 .u.variant.choices = transport_fields,
285 .u.variant.nr_choices = ARRAY_SIZE(transport_fields),
286 },
287 },
288 };
289
290 static struct lttng_event_field ipv6fields[] = {
291 [0] = {
292 .name = "version",
293 .type = __type_integer(uint8_t, 4, 4, 0,
294 __BIG_ENDIAN, 0, 10, none),
295 },
296 [1] = {
297 .name = "prio",
298 .type = __type_integer(uint8_t, 4, 4, 0,
299 __BIG_ENDIAN, 0, 10, none),
300 },
301 [2] = {
302 .name = "flow_lbl",
303 .type = {
304 .atype = atype_array,
305 .u.array.elem_type =
306 __type_integer(uint8_t, 0, 0, 0,
307 __BIG_ENDIAN, 0, 16, none),
308 .u.array.length = 3,
309 .u.array.elem_alignment = lttng_alignof(uint8_t),
310 },
311 },
312 [3] = {
313 .name = "payload_len",
314 .type = __type_integer(uint16_t, 0, 0, 0,
315 __BIG_ENDIAN, 0, 10, none),
316 },
317 [4] = {
318 .name = "nexthdr",
319 .type = {
320 .atype = atype_enum,
321 .u.basic.enumeration.desc =
322 &proto_transport_header_type,
323 .u.basic.enumeration.container_type = {
324 .size = 8,
325 .alignment = 8,
326 .signedness = 0,
327 .reverse_byte_order =
328 __BIG_ENDIAN != __BYTE_ORDER,
329 .base = 10,
330 .user = 0,
331 .encoding = lttng_encode_none,
332 },
333 },
334 },
335 [5] = {
336 .name = "hop_limit",
337 .type = __type_integer(uint8_t, 0, 0, 0,
338 __BIG_ENDIAN, 0, 10, none),
339 },
340 [6] = {
341 .name = "saddr",
342 .type = {
343 .atype = atype_array,
344 .u.array.elem_type =
345 __type_integer(uint16_t, 0, 0, 0,
346 __BIG_ENDIAN, 0, 16, none),
347 .u.array.length = 8,
348 .u.array.elem_alignment = lttng_alignof(uint16_t),
349 },
350 },
351 [7] = {
352 .name = "daddr",
353 .type = {
354 .atype = atype_array,
355 .u.array.elem_type =
356 __type_integer(uint16_t, 0, 0, 0,
357 __BIG_ENDIAN, 0, 16, none),
358 .u.array.length = 8,
359 .u.array.elem_alignment = lttng_alignof(uint16_t),
360 },
361 },
362 [8] = {
363 .name = "transport_header_type",
364 .type = {
365 .atype = atype_enum,
366 .u.basic.enumeration.desc = &transport_header_type,
367 .u.basic.enumeration.container_type = {
368 .size = 8,
369 .alignment = 8,
370 .signedness = 0,
371 .reverse_byte_order = 0,
372 .base = 10,
373 .user = 0,
374 .encoding = lttng_encode_none,
375 },
376 },
377 },
378 [9] = {
379 .name = "transport_header",
380 .type = {
381 .atype = atype_variant,
382 .u.variant.tag_name = "transport_header_type",
383 .u.variant.choices = transport_fields,
384 .u.variant.nr_choices = ARRAY_SIZE(transport_fields),
385 },
386 },
387 };
388
389 static struct lttng_event_field network_fields[] = {
390 [0] = {
391 .name = "unknown",
392 .type = {
393 .atype = atype_struct,
394 .u._struct.nr_fields = 0,
395 .u._struct.fields = emptyfields,
396 },
397 },
398 [1] = {
399 .name = "ipv4",
400 .type = {
401 .atype = atype_struct,
402 .u._struct.nr_fields = ARRAY_SIZE(ipv4fields),
403 .u._struct.fields = ipv4fields,
404 },
405 },
406 [2] = {
407 .name = "ipv6",
408 .type = {
409 .atype = atype_struct,
410 .u._struct.nr_fields = ARRAY_SIZE(ipv6fields),
411 .u._struct.fields = ipv6fields,
412 },
413 },
414 };
415
416 enum network_header_types {
417 NH_NONE,
418 NH_IPV4,
419 NH_IPV6,
420 };
421
422 static inline unsigned char __get_network_header_type(struct sk_buff *skb)
423 {
424 if (__has_network_hdr(skb)) {
425 if (skb->protocol == htons(ETH_P_IPV6))
426 return NH_IPV6;
427 else if (skb->protocol == htons(ETH_P_IP))
428 return NH_IPV4;
429 /* Fallthrough for other header types. */
430 }
431 return NH_NONE;
432 }
433
434 #endif
435
436 LTTNG_TRACEPOINT_ENUM(net_network_header,
437 TP_ENUM_VALUES(
438 ctf_enum_value("_unknown", NH_NONE)
439 ctf_enum_value("_ipv4", NH_IPV4)
440 ctf_enum_value("_ipv6", NH_IPV6)
441 )
442 )
443
444 LTTNG_TRACEPOINT_EVENT(net_dev_xmit,
445
446 TP_PROTO(struct sk_buff *skb,
447 int rc,
448 struct net_device *dev,
449 unsigned int skb_len),
450
451 TP_ARGS(skb, rc, dev, skb_len),
452
453 TP_FIELDS(
454 ctf_integer_hex(void *, skbaddr, skb)
455 ctf_integer(int, rc, rc)
456 ctf_integer(unsigned int, len, skb_len)
457 ctf_string(name, dev->name)
458 )
459 )
460
461 LTTNG_TRACEPOINT_EVENT_CLASS(net_dev_template,
462
463 TP_PROTO(struct sk_buff *skb),
464
465 TP_ARGS(skb),
466
467 TP_FIELDS(
468 ctf_integer_hex(void *, skbaddr, skb)
469 ctf_integer(unsigned int, len, skb->len)
470 ctf_string(name, skb->dev->name)
471 ctf_enum(net_network_header, unsigned char,
472 network_header_type, __get_network_header_type(skb))
473 ctf_custom_field(
474 ctf_custom_type(
475 .atype = atype_variant,
476 .u.variant.tag_name = "network_header_type",
477 .u.variant.choices = network_fields,
478 .u.variant.nr_choices =
479 ARRAY_SIZE(network_fields),
480 ),
481 network_header,
482 ctf_custom_code(
483 bool has_network_header = false;
484
485 /* Copy the network header. */
486 switch (__get_network_header_type(skb)) {
487 case NH_IPV4: {
488 ctf_align(uint16_t)
489 ctf_array_type(uint8_t, ip_hdr(skb),
490 sizeof(struct iphdr))
491 has_network_header = true;
492 break;
493 }
494 case NH_IPV6: {
495 ctf_align(uint16_t)
496 ctf_array_type(uint8_t, ipv6_hdr(skb),
497 sizeof(struct ipv6hdr))
498 has_network_header = true;
499 break;
500 }
501 default:
502 /*
503 * For any other network header
504 * type, there is nothing to do.
505 */
506 break;
507 }
508
509 if (has_network_header) {
510 enum transport_header_types th_type =
511 __get_transport_header_type(skb);
512
513 /* Transport header type field. */
514 ctf_integer_type(unsigned char, th_type)
515
516 /* Copy the transport header. */
517 if (th_type == TH_TCP) {
518 ctf_align(uint32_t)
519 ctf_array_type(uint8_t, tcp_hdr(skb),
520 sizeof(struct tcphdr))
521 }
522 /*
523 * For any other transport header type,
524 * there is nothing to do.
525 */
526 }
527 )
528 )
529 )
530 )
531
532 LTTNG_TRACEPOINT_EVENT_INSTANCE(net_dev_template, net_dev_queue,
533
534 TP_PROTO(struct sk_buff *skb),
535
536 TP_ARGS(skb)
537 )
538
539 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(net_dev_template,
540
541 netif_receive_skb,
542
543 net_if_receive_skb,
544
545 TP_PROTO(struct sk_buff *skb),
546
547 TP_ARGS(skb)
548 )
549
550 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(net_dev_template,
551
552 netif_rx,
553
554 net_if_rx,
555
556 TP_PROTO(struct sk_buff *skb),
557
558 TP_ARGS(skb)
559 )
560
561 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,14,0))
562
563 /* Trace events for the receive entry points */
564 LTTNG_TRACEPOINT_EVENT_CLASS(net_dev_receive_entry_template,
565
566 TP_PROTO(const struct sk_buff *skb),
567
568 TP_ARGS(skb),
569
570 TP_FIELDS(
571 ctf_integer_hex(const void *, skbaddr, skb)
572 )
573 )
574
575 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(net_dev_receive_entry_template,
576
577 napi_gro_frags_entry,
578
579 net_napi_gro_frags_entry,
580
581 TP_PROTO(const struct sk_buff *skb),
582
583 TP_ARGS(skb)
584 )
585
586 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(net_dev_receive_entry_template,
587
588 napi_gro_receive_entry,
589
590 net_napi_gro_receive_entry,
591
592 TP_PROTO(const struct sk_buff *skb),
593
594 TP_ARGS(skb)
595 )
596
597 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(net_dev_receive_entry_template,
598
599 netif_receive_skb_entry,
600
601 net_if_receive_skb_entry,
602
603 TP_PROTO(const struct sk_buff *skb),
604
605 TP_ARGS(skb)
606 )
607
608 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(net_dev_receive_entry_template,
609
610 netif_rx_entry,
611
612 net_if_rx_entry,
613
614 TP_PROTO(const struct sk_buff *skb),
615
616 TP_ARGS(skb)
617 )
618
619 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(net_dev_receive_entry_template,
620
621 netif_rx_ni_entry,
622
623 net_if_rx_ni_entry,
624
625 TP_PROTO(const struct sk_buff *skb),
626
627 TP_ARGS(skb)
628 )
629
630 #endif /* kernel > 3.14 */
631
632 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,19,0))
633
634 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(net_dev_receive_entry_template,
635
636 netif_receive_skb_list_entry,
637
638 net_if_receive_skb_list_entry,
639
640 TP_PROTO(const struct sk_buff *skb),
641
642 TP_ARGS(skb)
643 )
644
645 #endif /* kernel > 4.19 */
646
647 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,0,0))
648
649 /* Trace events for the receive exit points */
650 LTTNG_TRACEPOINT_EVENT_CLASS(net_dev_receive_exit_template,
651
652 TP_PROTO(int ret),
653
654 TP_ARGS(ret),
655
656 TP_FIELDS(
657 ctf_integer(int, ret, ret)
658 )
659 )
660
661 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(net_dev_receive_exit_template,
662
663 napi_gro_frags_exit,
664
665 net_napi_gro_frags_exit,
666
667 TP_PROTO(int ret),
668
669 TP_ARGS(ret)
670 )
671
672 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(net_dev_receive_exit_template,
673
674 napi_gro_receive_exit,
675
676 net_napi_gro_receive_exit,
677
678 TP_PROTO(int ret),
679
680 TP_ARGS(ret)
681 )
682
683 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(net_dev_receive_exit_template,
684
685 netif_receive_skb_exit,
686
687 net_if_receive_skb_exit,
688
689 TP_PROTO(int ret),
690
691 TP_ARGS(ret)
692 )
693
694 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(net_dev_receive_exit_template,
695
696 netif_rx_exit,
697
698 net_if_rx_exit,
699
700 TP_PROTO(int ret),
701
702 TP_ARGS(ret)
703 )
704
705 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(net_dev_receive_exit_template,
706
707 netif_rx_ni_exit,
708
709 net_if_rx_ni_exit,
710
711 TP_PROTO(int ret),
712
713 TP_ARGS(ret)
714 )
715
716 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(net_dev_receive_exit_template,
717
718 netif_receive_skb_list_exit,
719
720 net_if_receive_skb_list_exit,
721
722 TP_PROTO(int ret),
723
724 TP_ARGS(ret)
725 )
726
727 #endif /* kernel > 5.0.0 */
728
729 #endif /* LTTNG_TRACE_NET_H */
730
731 /* This part must be outside protection */
732 #include <probes/define_trace.h>
This page took 0.061864 seconds and 4 git commands to generate.