aboutsummaryrefslogtreecommitdiffstats
path: root/include/trace/events/cros_net.h
blob: fba9cfba0536dd03b0ee3ada9dad9b4b0dcc9bf1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/* SPDX-License-Identifier: GPL-2.0 */

#undef TRACE_SYSTEM
#define TRACE_SYSTEM cros_net

#if !defined(_TRACE_CROS_NET_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_CROS_NET_H

#include <linux/net.h>
#include <linux/if.h>
#include <linux/tracepoint.h>

// @rv: return value of the socket listen.
// @dev_if: bound device index.
// @type: socket type (%SOCK_STREAM, etc.).
// @port: the bind port.


#define CROS_NET_FILL_ADDR_PORT(sk, entry)\
	do {							\
		entry->sport = sk->__sk_common.skc_num;		\
		entry->saddr4 = sk->__sk_common.skc_rcv_saddr;	\
		entry->dport = sk->__sk_common.skc_dport;	\
		entry->daddr4 = sk->__sk_common.skc_daddr;	\
		entry->protocol = sk->sk_protocol;		\
	} while (0)
	//protocol is also avable in sk_buff
	//skb_network_header from skba
	// struct iphdr *ip_header = (struct iphdr *) (skb_network_header(skb))
#define CROS_IP_PROTOCOL_NAME(val) { IPPROTO_#val, #val }
#define CROS_SHOW_IP_PROTOCOL(val)				\
	__print_symbolic(val,					\
		{IPPROTO_UDP, "UDP"},				\
		{IPPROTO_TCP, "TCP"},				\
		{IPPROTO_ICMP, "ICMP"},				\
		{IPPROTO_RAW, "RAW"})

TRACE_EVENT(cros_ip6_finish_output2_enter,
	TP_PROTO(struct net *net, struct sock *sk, struct sk_buff *skb),
	TP_ARGS(net, sk, skb),
	TP_STRUCT__entry(
		__array(__u8, saddr, 16)
		__array(__u8, daddr, 16)
		__array(char, dev_name, IFNAMSIZ)
	),
	TP_fast_assign(
		struct ipv6hdr *ip_header = (struct ipv6hdr *)(skb_network_header(skb));
		struct net_device *dev;

		memmove(__entry->saddr, ip_header->saddr.in6_u.u6_addr8, 16);
		memmove(__entry->daddr, ip_header->daddr.in6_u.u6_addr8, 16);
		dev = ((struct dst_entry *)(skb->_skb_refdst & SKB_DST_PTRMASK))->dev;
		strscpy(__entry->dev_name, dev->name, IFNAMSIZ);
	),
	TP_printk("do_not_depend:%pI6c %pI6c %s", __entry->saddr, __entry->daddr,
		  __entry->dev_name))

TRACE_EVENT(cros_ip6_input_finish_enter,
	TP_PROTO(struct net *net, struct sock *sk, struct sk_buff *skb),
	TP_ARGS(net, sk, skb),
	TP_STRUCT__entry(
		__array(__u8, saddr, 16)
		__array(__u8, daddr, 16)
		__array(char, dev_name, IFNAMSIZ)
	),
	TP_fast_assign(
		struct ipv6hdr *ip_header = (struct ipv6hdr *)(skb_network_header(skb));
		struct net_device *dev;

		memmove(__entry->saddr, ip_header->saddr.in6_u.u6_addr8, 16);
		memmove(__entry->daddr, ip_header->daddr.in6_u.u6_addr8, 16);
		dev = skb->dev;
		strscpy(__entry->dev_name, dev->name, IFNAMSIZ);
	),
	TP_printk("do_not_depend:%pI6c %pI6c %s", __entry->saddr, __entry->daddr,
		  __entry->dev_name))

TRACE_EVENT(cros_ip_protocol_deliver_rcu_enter,
	TP_PROTO(struct net *net, struct sk_buff *skb, int protocol),
	TP_ARGS(net, skb, protocol),
	TP_STRUCT__entry(
		__field(__be32, saddr)
		__field(__be32, daddr)
		__array(char, dev_name, IFNAMSIZ)
		__field(int, dev_if)
		__field(short, source_port)
		__field(short, dest_port)
		__field(int, proto)
	),
	TP_fast_assign(
		struct iphdr *ip_header = (struct iphdr *)(skb->head + skb->network_header);
		char *transport = (char *)(skb->head + skb->transport_header);
		struct tcphdr *tcp = (struct tcphdr *)transport;
		struct udphdr *udp = (struct udphdr *)transport;
		struct net_device *dev;
		bool has_transport = skb->transport_header != (typeof(skb->transport_header))~0U;

		__entry->saddr = ip_header->saddr;
		__entry->daddr = ip_header->daddr;
		__entry->proto = ip_header->protocol;
		if (has_transport) {
			switch (ip_header->protocol) {
			case IPPROTO_TCP:
				__entry->source_port = ntohs(tcp->source);
				__entry->dest_port = ntohs(tcp->dest);
				break;
			case IPPROTO_UDP:
				__entry->source_port = ntohs(udp->source);
				__entry->dest_port = ntohs(udp->dest);
				break;
			default:
				break;
			};
		}
		dev = ((struct dst_entry *)(skb->_skb_refdst & SKB_DST_PTRMASK))->dev;
		strscpy(__entry->dev_name, dev->name, IFNAMSIZ);
		__entry->dev_if = dev->ifindex;
	),
	TP_printk("do_not_depend:%pI4 %u %pI4 %u %s %s", &__entry->saddr, __entry->source_port,
		  &__entry->daddr, __entry->dest_port, CROS_SHOW_IP_PROTOCOL(__entry->proto),
		  __entry->dev_name))

TRACE_EVENT(cros__ip_local_out_exit,
	TP_PROTO(struct net *net, struct sock *sk, struct sk_buff *skb, int rv),
	TP_ARGS(net, sk, skb, rv),
	TP_STRUCT__entry(
		__field(__be32, saddr)
		__field(__be32, daddr)
		__field(int, rv)
		__array(char, dev_name, IFNAMSIZ)
		__field(short, source_port)
		__field(short, dest_port)
		__field(int, proto)
	),
	TP_fast_assign(
		struct iphdr *ip_header = (struct iphdr *)(skb->head + skb->network_header);
		char *transport = (char *)(skb->head + skb->transport_header);
		struct tcphdr *tcp = (struct tcphdr *)transport;
		struct udphdr *udp = (struct udphdr *)transport;
		struct net_device *dev;
		bool has_transport = skb->transport_header != (typeof(skb->transport_header))~0U;

		__entry->saddr = ip_header->saddr;
		__entry->daddr = ip_header->daddr;
		__entry->rv = rv;
		__entry->proto = ip_header->protocol;
		if (has_transport) {
			switch (ip_header->protocol) {
			case IPPROTO_TCP:
				__entry->source_port = ntohs(tcp->source);
				__entry->dest_port = ntohs(tcp->dest);
				break;
			case IPPROTO_UDP:
				__entry->source_port = ntohs(udp->source);
				__entry->dest_port = ntohs(udp->dest);
				break;
			default:
				break;
			};
		}
		dev = ((struct dst_entry *)(skb->_skb_refdst & SKB_DST_PTRMASK))->dev;
		strscpy(__entry->dev_name, dev->name, IFNAMSIZ);
	),
	TP_printk("do_not_depend:%pI4 %u %pI4 %u %s %s", &__entry->saddr, __entry->source_port,
		  &__entry->daddr, __entry->dest_port, CROS_SHOW_IP_PROTOCOL(__entry->proto),
		  __entry->dev_name))

TRACE_EVENT(cros_inet_listen_exit,
	/* The tracepoint signature matches the signature of inet_listen with
	 * addition of the return value. This is done to match the expected
	 * signature of an fexit bpf program.
	 * This is done so that a BPF application can use the same
	 * handler for kernels that don't support fexit for ARM64 and those
	 * that do.
	 */
	TP_PROTO(struct socket *socket, int backlog, int rv),
	TP_ARGS(socket, backlog, rv),
	TP_STRUCT__entry(
		__field(int,	dev_if)
		__field(short, type)
		__field(__u16,	port)
	),
	TP_fast_assign(
		__entry->dev_if = socket->sk->__sk_common.skc_bound_dev_if;
		__entry->type = socket->type;
		__entry->port = socket->sk->__sk_common.skc_num;
	),
	TP_printk(
		"do_not_depend:%d %d %04d",
		__entry->dev_if,
		__entry->type,
		__entry->port)
);

TRACE_EVENT_CONDITION(cros_inet_accept_exit,
	/* The tracepoint signature matches the signature of inet_accept with
	 * addition of the return value. This is done to match the expected
	 * signature of an fexit bpf program.
	 * This is done so that a BPF application can use the same
	 * handler for kernels that don't support fexit for ARM64 and those
	 * that do.
	 */
	TP_PROTO(struct socket *sock, struct socket *newsock, int flags, bool kern, int rv),
	TP_ARGS(sock, newsock, flags, kern, rv),
	TP_CONDITION(newsock && newsock->sk),
	TP_STRUCT__entry(
	__field(__u32, saddr4)
	__field(__u32, daddr4)
	__field(__u16, sport)
	__field(__u16, dport)
	__field(__u8, protocol)
	),
	TP_fast_assign(
		struct sock *sk = newsock->sk;

		CROS_NET_FILL_ADDR_PORT(sk, __entry);
	),
	TP_printk(
		":%pI4 %d %pI4 %d",
		&__entry->saddr4,
		__entry->sport,
		&__entry->daddr4,
		__entry->dport)
);


TRACE_EVENT_CONDITION(cros_inet_sendmsg_enter,
	/* The tracepoint signature matches the signature of inet_sendmsg.
	 * This is done to match the expected signature of an fentry bpf program.
	 * This is done so that a BPF application can use the same
	 * handler for kernels that don't support fexit for ARM64 and those
	 * that do.
	 */
	TP_PROTO(struct socket *sock, struct msghdr *msg, size_t size),
	TP_ARGS(sock, msg, size),
	TP_CONDITION(sock && sock->sk),
	TP_STRUCT__entry(
		__field(__u32, saddr4)
		__field(__u32, daddr4)
		__field(__u16, sport)
		__field(__u16, dport)
		__field(__u8, protocol)
	),
	TP_fast_assign(
		struct sock *sk = sock->sk;

		CROS_NET_FILL_ADDR_PORT(sk, __entry);
	),
	TP_printk(
		"do_not_depend:%pI4:%d-%pI4:%d-prot:%d",
		&__entry->saddr4,
		__entry->sport,
		&__entry->daddr4,
		__entry->dport,
		__entry->protocol
		)
);

TRACE_EVENT_CONDITION(cros_inet_stream_connect_exit,
	/* The tracepoint signature matches the signature of inet_stream_connect
	 * with the addition of the return value. This is done to match the
	 * expected signature of an fexit bpf program.
	 * This is done so that a BPF application can use the same
	 * handler for kernels that don't support fexit for ARM64 and those
	 * that do.
	 */
	TP_PROTO(struct socket *sock, struct sockaddr *uaddr, int addr_len, int flags,
		int is_sendmsg,  int rv),
	TP_ARGS(sock, uaddr, addr_len, flags, is_sendmsg, rv),
	TP_CONDITION(sock && sock->sk),
	TP_STRUCT__entry(
		__field(int, is_sendmsg)
		__field(__u32, saddr4)
		__field(__u32, daddr4)
		__field(__u16, sport)
		__field(__u16, dport)
		__field(__u8, protocol)
	),
	TP_fast_assign(
		struct sock *sk = sock->sk;

		CROS_NET_FILL_ADDR_PORT(sk, __entry);
		__entry->is_sendmsg = is_sendmsg;
	),
	TP_printk(
		"do_not_depend: %pI4 %d %pI4 %d prot:%d issendmsg:%d",
		&__entry->saddr4,
		__entry->sport,
		&__entry->daddr4,
		__entry->dport,
		__entry->protocol,
		__entry->is_sendmsg
		)
);

TRACE_EVENT_CONDITION(cros_inet_sendpage_exit,
	/* The tracepoint signature matches the signature of inet_sendpage with
	 * addition of the return value. This is done to match the expected
	 * signature of an fexit bpf program.
	 * This is done so that a BPF application can use the same
	 * handler for kernels that don't support fexit for ARM64 and those
	 * that do.
	 */
	TP_PROTO(struct socket *sock, struct page *page, int offset, size_t size,
		int flags, int rv),
	TP_ARGS(sock, page, offset, size, flags, rv),
	TP_CONDITION(sock && sock->sk),
	TP_STRUCT__entry(
		__field(size_t, bytes_sent)
		__field(__u32, saddr4)
		__field(__u32, daddr4)
		__field(__u16, sport)
		__field(__u16, dport)
		__field(__u8, protocol)
	),
	TP_fast_assign(
		struct sock *sk = sock->sk;

		CROS_NET_FILL_ADDR_PORT(sk, __entry);
		__entry->bytes_sent = rv;
	),
	TP_printk(
		"do_not_depend:%pI4 %d %pI4 %d %zu",
		&__entry->saddr4,
		__entry->sport,
		&__entry->daddr4,
		__entry->dport,
		__entry->bytes_sent
		)
);

TRACE_EVENT_CONDITION(cros_inet_recvmsg_exit,
	/* The tracepoint signature matches the signature of inet_recvmsg with
	 * addition of the return value. This is done to match the expected
	 * signature of an fexit bpf program.
	 * This is done so that a BPF application can use the same
	 * handler for kernels that don't support fexit for ARM64 and those
	 * that do.
	 */
	TP_PROTO(struct socket *sock, struct msghdr *msg, size_t size, int flags, int rv),
	TP_ARGS(sock, msg, size, flags, rv),
	TP_CONDITION(sock && sock->sk),
	TP_STRUCT__entry(
		__field(size_t, bytes_sent)
		__field(__u32, saddr4)
		__field(__u32, daddr4)
		__field(__u16, sport)
		__field(__u16, dport)
		__field(__u8, protocol)
	),
	TP_fast_assign(
		struct sock *sk = sock->sk;

		CROS_NET_FILL_ADDR_PORT(sk, __entry);
		__entry->bytes_sent = rv;
	),
	TP_printk(
		"do_not_depend:%pI4 %d %pI4 %d %zu prot:%d",
		&__entry->saddr4,
		__entry->sport,
		&__entry->daddr4,
		__entry->dport,
		__entry->bytes_sent,
		__entry->protocol
		)
);

TRACE_EVENT_CONDITION(cros_inet_release_enter,
	TP_PROTO(struct socket *sock),
	TP_ARGS(sock),
	TP_CONDITION(sock && sock->sk),
	TP_STRUCT__entry(
		__field(__u32, saddr4)
		__field(__u32, daddr4)
		__field(__u16, sport)
		__field(__u16, dport)
		__field(__u8, protocol)
	),
	TP_fast_assign(
		struct sock *sk = sock->sk;

		CROS_NET_FILL_ADDR_PORT(sk, __entry);
	),
	TP_printk("do_not_depend:%pI4 %d %pI4 %d",
	&__entry->saddr4, __entry->sport, &__entry->daddr4, __entry->dport));
#endif // _TRACE_CROS_NET_H
/* This part must be outside protection */
#include <trace/define_trace.h>