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