net_dev_xmit_extended probe : cleanup unused data
[lttng-modules.git] / probes / net-extended-trace.c
CommitLineData
1c8284eb
MD
1/*
2 * ltt/probes/net-extended-trace.c
3 *
4 * Net tracepoint extended probes.
5 *
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
13 *
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.
17 *
18 * Dual LGPL v2.1/GPL v2 license.
19 */
20
21#include <linux/in_route.h>
22#include <linux/ip.h>
23#include <linux/module.h>
24#include <linux/tcp.h>
25#include <linux/udp.h>
26#include <net/route.h>
27#include <trace/net.h>
28
29#include "../ltt-type-serializer.h"
30
31void probe_net_dev_xmit_extended(void *_data, struct sk_buff *skb);
32
33DEFINE_MARKER_TP(net, dev_xmit_extended, net_dev_xmit,
34 probe_net_dev_xmit_extended, "skb 0x%lX network_protocol #n2u%hu "
35 "transport_protocol #1u%u saddr #n4u%lu daddr #n4u%lu "
36 "tot_len #n2u%hu ihl #1u%u source #n2u%hu dest #n2u%hu seq #n4u%lu "
37 "ack_seq #n4u%lu doff #1u%u ack #1u%u rst #1u%u syn #1u%u fin #1u%u");
38
39notrace void probe_net_dev_xmit_extended(void *_data, struct sk_buff *skb)
40{
41 struct marker *marker;
42 struct serialize_l214421224411111 data;
43 struct iphdr *iph = ip_hdr(skb);
44 struct tcphdr *th = tcp_hdr(skb);
8fad657c
JD
45 struct udphdr *uh = udp_hdr(skb);
46
47 memset(&data, 0, sizeof(struct serialize_l214421224411111));
1c8284eb
MD
48
49 data.f1 = (unsigned long)skb;
50 data.f2 = skb->protocol;
51
52 if (ntohs(skb->protocol) == ETH_P_IP) {
53 data.f3 = ip_hdr(skb)->protocol;
54 data.f4 = iph->saddr;
55 data.f5 = iph->daddr;
56 data.f6 = iph->tot_len;
57 data.f7 = iph->ihl;
58
59 if (data.f3 == IPPROTO_TCP) {
60 data.f8 = th->source;
61 data.f9 = th->dest;
62 data.f10 = th->seq;
63 data.f11 = th->ack_seq;
64 data.f12 = th->doff;
65 data.f13 = th->ack;
66 data.f14 = th->rst;
67 data.f15 = th->syn;
68 data.f16 = th->fin;
8fad657c
JD
69 } else if (data.f3 == IPPROTO_UDP) {
70 data.f8 = uh->source;
71 data.f9 = uh->dest;
1c8284eb
MD
72 }
73 }
74
75 marker = &GET_MARKER(net, dev_xmit_extended);
76 ltt_specialized_trace(marker, marker->single.probe_private,
77 &data, serialize_sizeof(data), sizeof(long));
78}
79
80void probe_tcpv4_rcv_extended(void *_data, struct sk_buff *skb);
81
82DEFINE_MARKER_TP(net, tcpv4_rcv_extended, net_tcpv4_rcv,
83 probe_tcpv4_rcv_extended, "skb 0x%lX saddr #n4u%lu daddr #n4u%lu "
84 "tot_len #n2u%hu ihl #1u%u source #n2u%hu dest #n2u%hu seq #n4u%lu "
85 "ack_seq #n4u%lu doff #1u%u ack #1u%u rst #1u%u syn #1u%u fin #1u%u");
86
87notrace void probe_tcpv4_rcv_extended(void *_data, struct sk_buff *skb)
88{
89 struct marker *marker;
90 struct serialize_l4421224411111 data;
91 struct iphdr *iph = ip_hdr(skb);
92 struct tcphdr *th = tcp_hdr(skb);
93
94 data.f1 = (unsigned long)skb;
95 data.f2 = iph->saddr;
96 data.f3 = iph->daddr;
97 data.f4 = iph->tot_len;
98 data.f5 = iph->ihl;
99 data.f6 = th->source;
100 data.f7 = th->dest;
101 data.f8 = th->seq;
102 data.f9 = th->ack_seq;
103 data.f10 = th->doff;
104 data.f11 = th->ack;
105 data.f12 = th->rst;
106 data.f13 = th->syn;
107 data.f14 = th->fin;
108
109 marker = &GET_MARKER(net, tcpv4_rcv_extended);
110 ltt_specialized_trace(marker, marker->single.probe_private,
111 &data, serialize_sizeof(data), sizeof(long));
112}
113
114void probe_udpv4_rcv_extended(void *_data, struct sk_buff *skb);
115
116DEFINE_MARKER_TP(net, udpv4_rcv_extended, net_udpv4_rcv,
117 probe_udpv4_rcv_extended, "skb 0x%lX saddr #n4u%lu daddr #n4u%lu "
118 "unicast #1u%u ulen #n2u%hu source #n2u%hu dest #n2u%hu "
119 "data_start #8u%lx");
120
121notrace void probe_udpv4_rcv_extended(void *_data, struct sk_buff *skb)
122{
123 struct marker *marker;
124 struct serialize_l4412228 data;
125 struct iphdr *iph = ip_hdr(skb);
126 struct rtable *rt = skb_rtable(skb);
127 struct udphdr *uh = udp_hdr(skb);
128
129 data.f1 = (unsigned long)skb;
130 data.f2 = iph->saddr;
131 data.f3 = iph->daddr;
132 data.f4 = rt->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST) ? 0 : 1;
133 data.f5 = uh->len;
134 data.f6 = uh->source;
135 data.f7 = uh->dest;
136 /* UDP header has not been pulled from skb->data, read the first 8
137 * bytes of UDP data if they are not in a fragment*/
138 data.f8 = 0;
139 if (skb_headlen(skb) >= sizeof(struct udphdr) + 8)
140 data.f8 = *(unsigned long long *)(skb->data + sizeof(*uh));
141 else if (skb_headlen(skb) >= sizeof(struct udphdr))
142 memcpy(&data.f8, skb->data + sizeof(struct udphdr),
143 skb_headlen(skb) - sizeof(struct udphdr));
144
145 marker = &GET_MARKER(net, udpv4_rcv_extended);
146 ltt_specialized_trace(marker, marker->single.probe_private,
147 &data, serialize_sizeof(data), sizeof(unsigned long long));
148}
149
150MODULE_LICENSE("GPL and additional rights");
151MODULE_AUTHOR("Benjamin Poirier");
152MODULE_DESCRIPTION("Net Tracepoint Extended Probes");
This page took 0.027576 seconds and 4 git commands to generate.