1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/bpf.h>
3 #include <bpf/bpf_helpers.h>
4 #include "bpf_trace_helpers.h"
5 
6 struct net_device {
7 	/* Structure does not need to contain all entries,
8 	 * as "preserve_access_index" will use BTF to fix this...
9 	 */
10 	int ifindex;
11 } __attribute__((preserve_access_index));
12 
13 struct xdp_rxq_info {
14 	/* Structure does not need to contain all entries,
15 	 * as "preserve_access_index" will use BTF to fix this...
16 	 */
17 	struct net_device *dev;
18 	__u32 queue_index;
19 } __attribute__((preserve_access_index));
20 
21 struct xdp_buff {
22 	void *data;
23 	void *data_end;
24 	void *data_meta;
25 	void *data_hard_start;
26 	unsigned long handle;
27 	struct xdp_rxq_info *rxq;
28 } __attribute__((preserve_access_index));
29 
30 __u64 test_result_fentry = 0;
31 SEC("fentry/_xdp_tx_iptunnel")
32 int BPF_PROG(trace_on_entry, struct xdp_buff *xdp)
33 {
34 	test_result_fentry = xdp->rxq->dev->ifindex;
35 	return 0;
36 }
37 
38 __u64 test_result_fexit = 0;
39 SEC("fexit/_xdp_tx_iptunnel")
40 int BPF_PROG(trace_on_exit, struct xdp_buff *xdp, int ret)
41 {
42 	test_result_fexit = ret;
43 	return 0;
44 }
45