2 #define TRACE_SYSTEM net
4 #if !defined(LTTNG_TRACE_NET_H) || defined(TRACE_HEADER_MULTI_READ)
5 #define LTTNG_TRACE_NET_H
7 #include <probes/lttng-tracepoint-event.h>
8 #include <linux/skbuff.h>
9 #include <linux/netdevice.h>
11 #include <linux/ipv6.h>
12 #include <linux/tcp.h>
13 #include <linux/version.h>
14 #include <lttng-endian.h>
17 #ifndef ONCE_LTTNG_NET_H
18 #define ONCE_LTTNG_NET_H
20 static inline unsigned char __has_network_hdr(struct sk_buff
*skb
)
23 * If the header is not set yet,
24 * the network header will point to the head.
26 return skb_network_header(skb
) != skb
->head
;
29 static struct lttng_event_field emptyfields
[] = {
32 /* Structures for network headers. */
34 static struct lttng_event_field ipv4fields
[] = {
37 .type
= __type_integer(uint8_t, 4, 4, 0, __BIG_ENDIAN
, 10, none
),
41 .type
= __type_integer(uint8_t, 4, 4, 0, __BIG_ENDIAN
, 10, none
),
45 .type
= __type_integer(uint8_t, 0, 0, 0, __BIG_ENDIAN
, 10, none
),
49 .type
= __type_integer(uint16_t, 0, 0, 0, __BIG_ENDIAN
, 10, none
),
53 .type
= __type_integer(uint16_t, 0, 0, 0, __BIG_ENDIAN
, 16, none
),
57 .type
= __type_integer(uint16_t, 0, 0, 0, __BIG_ENDIAN
, 10, none
),
61 .type
= __type_integer(uint8_t, 0, 0, 0, __BIG_ENDIAN
, 10, none
),
65 .type
= __type_integer(uint8_t, 0, 0, 0, __BIG_ENDIAN
, 10, none
),
69 .type
= __type_integer(uint16_t, 0, 0, 0, __BIG_ENDIAN
, 16, none
),
75 .u
.array
.elem_type
= __type_integer(uint8_t, 0, 0, 0, __BIG_ENDIAN
, 10, none
),
77 .u
.array
.elem_alignment
= lttng_alignof(uint8_t),
84 .u
.array
.elem_type
= __type_integer(uint8_t, 0, 0, 0, __BIG_ENDIAN
, 10, none
),
86 .u
.array
.elem_alignment
= lttng_alignof(uint8_t),
91 static struct lttng_event_field ipv6fields
[] = {
94 .type
= __type_integer(uint8_t, 4, 4, 0, __BIG_ENDIAN
, 10, none
),
98 .type
= __type_integer(uint8_t, 4, 4, 0, __BIG_ENDIAN
, 10, none
),
103 .atype
= atype_array
,
104 .u
.array
.elem_type
= __type_integer(uint8_t, 0, 0, 0, __BIG_ENDIAN
, 16, none
),
106 .u
.array
.elem_alignment
= lttng_alignof(uint8_t),
110 .name
= "payload_len",
111 .type
= __type_integer(uint16_t, 0, 0, 0, __BIG_ENDIAN
, 10, none
),
115 .type
= __type_integer(uint8_t, 0, 0, 0, __BIG_ENDIAN
, 10, none
),
119 .type
= __type_integer(uint8_t, 0, 0, 0, __BIG_ENDIAN
, 10, none
),
124 .atype
= atype_array
,
125 .u
.array
.elem_type
= __type_integer(uint16_t, 0, 0, 0, __BIG_ENDIAN
, 16, none
),
127 .u
.array
.elem_alignment
= lttng_alignof(uint16_t),
133 .atype
= atype_array
,
134 .u
.array
.elem_type
= __type_integer(uint16_t, 0, 0, 0, __BIG_ENDIAN
, 16, none
),
136 .u
.array
.elem_alignment
= lttng_alignof(uint16_t),
141 static struct lttng_event_field network_fields
[] = {
145 .atype
= atype_struct
,
146 .u
._struct
.nr_fields
= 0,
147 .u
._struct
.fields
= emptyfields
,
153 .atype
= atype_struct
,
154 .u
._struct
.nr_fields
= ARRAY_SIZE(ipv4fields
),
155 .u
._struct
.fields
= ipv4fields
,
161 .atype
= atype_struct
,
162 .u
._struct
.nr_fields
= ARRAY_SIZE(ipv6fields
),
163 .u
._struct
.fields
= ipv6fields
,
168 enum network_header_types
{
174 static inline unsigned char __get_network_header_type(struct sk_buff
*skb
)
176 if (__has_network_hdr(skb
)) {
177 if (skb
->protocol
== htons(ETH_P_IPV6
))
179 else if (skb
->protocol
== htons(ETH_P_IP
))
181 /* Fallthrough for other header types. */
188 LTTNG_TRACEPOINT_ENUM(net_network_header
,
190 ctf_enum_value("_unknown", NH_NONE
)
191 ctf_enum_value("_ipv4", NH_IPV4
)
192 ctf_enum_value("_ipv6", NH_IPV6
)
196 LTTNG_TRACEPOINT_EVENT(net_dev_xmit
,
198 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,40))
199 TP_PROTO(struct sk_buff
*skb
,
201 struct net_device
*dev
,
202 unsigned int skb_len
),
204 TP_ARGS(skb
, rc
, dev
, skb_len
),
206 TP_PROTO(struct sk_buff
*skb
,
213 ctf_integer_hex(void *, skbaddr
, skb
)
214 ctf_integer(int, rc
, rc
)
215 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,40))
216 ctf_integer(unsigned int, len
, skb_len
)
217 ctf_string(name
, dev
->name
)
219 ctf_integer(unsigned int, len
, skb
->len
)
220 ctf_string(name
, skb
->dev
->name
)
225 LTTNG_TRACEPOINT_EVENT_CLASS(net_dev_template
,
227 TP_PROTO(struct sk_buff
*skb
),
232 ctf_integer_hex(void *, skbaddr
, skb
)
233 ctf_integer(unsigned int, len
, skb
->len
)
234 ctf_string(name
, skb
->dev
->name
)
235 ctf_enum(net_network_header
, unsigned char,
236 network_header_type
, __get_network_header_type(skb
))
239 .atype
= atype_variant
,
240 .u
.variant
.tag_name
= "network_header_type",
241 .u
.variant
.choices
= network_fields
,
242 .u
.variant
.nr_choices
= ARRAY_SIZE(network_fields
),
246 switch (__get_network_header_type(skb
)) {
249 ctf_array_type(uint8_t, ip_hdr(skb
),
250 sizeof(struct iphdr
))
255 ctf_array_type(uint8_t, ipv6_hdr(skb
),
256 sizeof(struct ipv6hdr
))
260 /* For any other header type, there is nothing to do. */
268 LTTNG_TRACEPOINT_EVENT_INSTANCE(net_dev_template
, net_dev_queue
,
270 TP_PROTO(struct sk_buff
*skb
),
275 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(net_dev_template
,
281 TP_PROTO(struct sk_buff
*skb
),
286 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(net_dev_template
,
292 TP_PROTO(struct sk_buff
*skb
),
296 #endif /* LTTNG_TRACE_NET_H */
298 /* This part must be outside protection */
299 #include <probes/define_trace.h>