2 * ltt/probes/net-extended-trace.c
4 * Net tracepoint extended probes.
6 * These probes record many header fields from TCP and UDP messages. Here are
7 * the consequences of this:
8 * 1) it allows analyzing network traffic to provide some pcap-like
9 * functionality within LTTng
10 * 2) it allows offline synchronization of a group of concurrent traces
11 * recorded on different nodes
12 * 3) it increases tracing overhead
14 * You can leave out these probes or not activate them if you are not
15 * especially interested in the details of network traffic and do not wish to
16 * synchronize distributed traces.
18 * (C) Copyright 2009 - Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
20 * Dual LGPL v2.1/GPL v2 license.
23 #include <linux/in_route.h>
25 #include <linux/module.h>
26 #include <linux/tcp.h>
27 #include <linux/udp.h>
28 #include <net/route.h>
29 #include <trace/net.h>
31 #include "../ltt-type-serializer.h"
33 void probe_net_dev_xmit_extended(void *_data
, struct sk_buff
*skb
);
35 DEFINE_MARKER_TP(net
, dev_xmit_extended
, net_dev_xmit
,
36 probe_net_dev_xmit_extended
, "skb 0x%lX network_protocol #n2u%hu "
37 "transport_protocol #1u%u saddr #n4u%lu daddr #n4u%lu "
38 "tot_len #n2u%hu ihl #1u%u source #n2u%hu dest #n2u%hu seq #n4u%lu "
39 "ack_seq #n4u%lu doff #1u%u ack #1u%u rst #1u%u syn #1u%u fin #1u%u");
41 notrace
void probe_net_dev_xmit_extended(void *_data
, struct sk_buff
*skb
)
43 struct marker
*marker
;
44 struct serialize_l214421224411111 data
;
45 struct iphdr
*iph
= ip_hdr(skb
);
46 struct tcphdr
*th
= tcp_hdr(skb
);
48 data
.f1
= (unsigned long)skb
;
49 data
.f2
= skb
->protocol
;
51 if (ntohs(skb
->protocol
) == ETH_P_IP
) {
52 data
.f3
= ip_hdr(skb
)->protocol
;
55 data
.f6
= iph
->tot_len
;
58 if (data
.f3
== IPPROTO_TCP
) {
62 data
.f11
= th
->ack_seq
;
71 marker
= &GET_MARKER(net
, dev_xmit_extended
);
72 ltt_specialized_trace(marker
, marker
->single
.probe_private
,
73 &data
, serialize_sizeof(data
), sizeof(long));
76 void probe_tcpv4_rcv_extended(void *_data
, struct sk_buff
*skb
);
78 DEFINE_MARKER_TP(net
, tcpv4_rcv_extended
, net_tcpv4_rcv
,
79 probe_tcpv4_rcv_extended
, "skb 0x%lX saddr #n4u%lu daddr #n4u%lu "
80 "tot_len #n2u%hu ihl #1u%u source #n2u%hu dest #n2u%hu seq #n4u%lu "
81 "ack_seq #n4u%lu doff #1u%u ack #1u%u rst #1u%u syn #1u%u fin #1u%u");
83 notrace
void probe_tcpv4_rcv_extended(void *_data
, struct sk_buff
*skb
)
85 struct marker
*marker
;
86 struct serialize_l4421224411111 data
;
87 struct iphdr
*iph
= ip_hdr(skb
);
88 struct tcphdr
*th
= tcp_hdr(skb
);
90 data
.f1
= (unsigned long)skb
;
93 data
.f4
= iph
->tot_len
;
98 data
.f9
= th
->ack_seq
;
105 marker
= &GET_MARKER(net
, tcpv4_rcv_extended
);
106 ltt_specialized_trace(marker
, marker
->single
.probe_private
,
107 &data
, serialize_sizeof(data
), sizeof(long));
110 void probe_udpv4_rcv_extended(void *_data
, struct sk_buff
*skb
);
112 DEFINE_MARKER_TP(net
, udpv4_rcv_extended
, net_udpv4_rcv
,
113 probe_udpv4_rcv_extended
, "skb 0x%lX saddr #n4u%lu daddr #n4u%lu "
114 "unicast #1u%u ulen #n2u%hu source #n2u%hu dest #n2u%hu "
115 "data_start #8u%lx");
117 notrace
void probe_udpv4_rcv_extended(void *_data
, struct sk_buff
*skb
)
119 struct marker
*marker
;
120 struct serialize_l4412228 data
;
121 struct iphdr
*iph
= ip_hdr(skb
);
122 struct rtable
*rt
= skb_rtable(skb
);
123 struct udphdr
*uh
= udp_hdr(skb
);
125 data
.f1
= (unsigned long)skb
;
126 data
.f2
= iph
->saddr
;
127 data
.f3
= iph
->daddr
;
128 data
.f4
= rt
->rt_flags
& (RTCF_BROADCAST
| RTCF_MULTICAST
) ? 0 : 1;
130 data
.f6
= uh
->source
;
132 /* UDP header has not been pulled from skb->data, read the first 8
133 * bytes of UDP data if they are not in a fragment*/
135 if (skb_headlen(skb
) >= sizeof(struct udphdr
) + 8)
136 data
.f8
= *(unsigned long long *)(skb
->data
+ sizeof(*uh
));
137 else if (skb_headlen(skb
) >= sizeof(struct udphdr
))
138 memcpy(&data
.f8
, skb
->data
+ sizeof(struct udphdr
),
139 skb_headlen(skb
) - sizeof(struct udphdr
));
141 marker
= &GET_MARKER(net
, udpv4_rcv_extended
);
142 ltt_specialized_trace(marker
, marker
->single
.probe_private
,
143 &data
, serialize_sizeof(data
), sizeof(unsigned long long));
146 MODULE_LICENSE("GPL and additional rights");
147 MODULE_AUTHOR("Benjamin Poirier");
148 MODULE_DESCRIPTION("Net Tracepoint Extended Probes");