summaryrefslogtreecommitdiffstats
path: root/samples
diff options
context:
space:
mode:
authorKumar Kartikeya Dwivedi <memxor@gmail.com>2021-08-21 05:49:54 +0530
committerAlexei Starovoitov <ast@kernel.org>2021-08-24 14:48:40 -0700
commit451588764e2f3e3ab197b23c7958f750707e2a24 (patch)
tree11c70ba9f2093a55625d8d6b30329c0a2c67c6c1 /samples
parent1d930fd2cdbf5e156c32c73ea7f3d5b12bdc41d7 (diff)
downloadlinux-451588764e2f3e3ab197b23c7958f750707e2a24.tar.bz2
samples: bpf: Add BPF support for xdp_exception tracepoint
This would allow us to store stats for each XDP action, including their per-CPU counts. Consolidating this here allows all redirect samples to detect xdp_exception events. Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20210821002010.845777-7-memxor@gmail.com
Diffstat (limited to 'samples')
-rw-r--r--samples/bpf/xdp_sample.bpf.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/samples/bpf/xdp_sample.bpf.c b/samples/bpf/xdp_sample.bpf.c
index e22f2a97a988..53ab5a972405 100644
--- a/samples/bpf/xdp_sample.bpf.c
+++ b/samples/bpf/xdp_sample.bpf.c
@@ -8,6 +8,7 @@
array_map rx_cnt SEC(".maps");
array_map redir_err_cnt SEC(".maps");
+array_map exception_cnt SEC(".maps");
const volatile int nr_cpus = 0;
@@ -110,3 +111,29 @@ int BPF_PROG(tp_xdp_redirect_map, const struct net_device *dev,
{
return xdp_redirect_collect_stat(dev->ifindex, err);
}
+
+SEC("tp_btf/xdp_exception")
+int BPF_PROG(tp_xdp_exception, const struct net_device *dev,
+ const struct bpf_prog *xdp, u32 act)
+{
+ u32 cpu = bpf_get_smp_processor_id();
+ struct datarec *rec;
+ u32 key = act, idx;
+
+ if (!IN_SET(from_match, dev->ifindex))
+ return 0;
+ if (!IN_SET(to_match, dev->ifindex))
+ return 0;
+
+ if (key > XDP_REDIRECT)
+ key = XDP_REDIRECT + 1;
+
+ idx = key * nr_cpus + cpu;
+ rec = bpf_map_lookup_elem(&exception_cnt, &idx);
+ if (!rec)
+ return 0;
+ NO_TEAR_INC(rec->dropped);
+
+ return 0;
+}
+