2020-01-15 21:15:39 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include <linux/bpf.h>
|
2020-03-01 07:11:12 +08:00
|
|
|
#include <bpf/bpf_tracing.h>
|
2020-01-20 21:06:45 +08:00
|
|
|
#include <bpf/bpf_helpers.h>
|
2020-01-15 21:15:39 +08:00
|
|
|
|
2020-03-06 16:59:23 +08:00
|
|
|
char _license[] SEC("license") = "GPL";
|
|
|
|
|
2020-01-15 21:15:39 +08:00
|
|
|
struct net_device {
|
|
|
|
/* Structure does not need to contain all entries,
|
|
|
|
* as "preserve_access_index" will use BTF to fix this...
|
|
|
|
*/
|
|
|
|
int ifindex;
|
|
|
|
} __attribute__((preserve_access_index));
|
|
|
|
|
|
|
|
struct xdp_rxq_info {
|
|
|
|
/* Structure does not need to contain all entries,
|
|
|
|
* as "preserve_access_index" will use BTF to fix this...
|
|
|
|
*/
|
|
|
|
struct net_device *dev;
|
|
|
|
__u32 queue_index;
|
|
|
|
} __attribute__((preserve_access_index));
|
|
|
|
|
|
|
|
struct xdp_buff {
|
|
|
|
void *data;
|
|
|
|
void *data_end;
|
|
|
|
void *data_meta;
|
|
|
|
void *data_hard_start;
|
|
|
|
unsigned long handle;
|
|
|
|
struct xdp_rxq_info *rxq;
|
|
|
|
} __attribute__((preserve_access_index));
|
|
|
|
|
2020-03-06 16:59:23 +08:00
|
|
|
struct meta {
|
|
|
|
int ifindex;
|
|
|
|
int pkt_len;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct {
|
|
|
|
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
|
|
|
|
__uint(key_size, sizeof(int));
|
|
|
|
__uint(value_size, sizeof(int));
|
|
|
|
} perf_buf_map SEC(".maps");
|
|
|
|
|
2020-01-15 21:15:39 +08:00
|
|
|
__u64 test_result_fentry = 0;
|
2020-02-20 21:26:45 +08:00
|
|
|
SEC("fentry/FUNC")
|
2020-01-15 21:15:39 +08:00
|
|
|
int BPF_PROG(trace_on_entry, struct xdp_buff *xdp)
|
|
|
|
{
|
2020-03-06 16:59:23 +08:00
|
|
|
struct meta meta;
|
|
|
|
void *data_end = (void *)(long)xdp->data_end;
|
|
|
|
void *data = (void *)(long)xdp->data;
|
|
|
|
|
|
|
|
meta.ifindex = xdp->rxq->dev->ifindex;
|
|
|
|
meta.pkt_len = data_end - data;
|
|
|
|
bpf_xdp_output(xdp, &perf_buf_map,
|
|
|
|
((__u64) meta.pkt_len << 32) |
|
|
|
|
BPF_F_CURRENT_CPU,
|
|
|
|
&meta, sizeof(meta));
|
|
|
|
|
2020-01-15 21:15:39 +08:00
|
|
|
test_result_fentry = xdp->rxq->dev->ifindex;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
__u64 test_result_fexit = 0;
|
2020-02-20 21:26:45 +08:00
|
|
|
SEC("fexit/FUNC")
|
2020-01-15 21:15:39 +08:00
|
|
|
int BPF_PROG(trace_on_exit, struct xdp_buff *xdp, int ret)
|
|
|
|
{
|
|
|
|
test_result_fexit = ret;
|
|
|
|
return 0;
|
|
|
|
}
|