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