summaryrefslogtreecommitdiffstats
path: root/samples/bpf/xdp_sample_user.h
diff options
context:
space:
mode:
authorKumar Kartikeya Dwivedi <memxor@gmail.com>2021-08-21 05:49:53 +0530
committerAlexei Starovoitov <ast@kernel.org>2021-08-24 14:48:40 -0700
commit1d930fd2cdbf5e156c32c73ea7f3d5b12bdc41d7 (patch)
tree06ac3ca25541b0c90b439bb4cfa4548b957022d4 /samples/bpf/xdp_sample_user.h
parent323140389405e5d5d2020b2e3e04863d12cf3e32 (diff)
downloadlinux-1d930fd2cdbf5e156c32c73ea7f3d5b12bdc41d7.tar.gz
linux-1d930fd2cdbf5e156c32c73ea7f3d5b12bdc41d7.tar.bz2
linux-1d930fd2cdbf5e156c32c73ea7f3d5b12bdc41d7.zip
samples: bpf: Add redirect tracepoint statistics support
This implements per-errno reporting (for the ones we explicitly recognize), adds some help output, and implements the stats retrieval and printing functions. 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-6-memxor@gmail.com
Diffstat (limited to 'samples/bpf/xdp_sample_user.h')
-rw-r--r--samples/bpf/xdp_sample_user.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/samples/bpf/xdp_sample_user.h b/samples/bpf/xdp_sample_user.h
index d630998df547..1935a0e2f85b 100644
--- a/samples/bpf/xdp_sample_user.h
+++ b/samples/bpf/xdp_sample_user.h
@@ -10,6 +10,10 @@
enum stats_mask {
_SAMPLE_REDIRECT_MAP = 1U << 0,
SAMPLE_RX_CNT = 1U << 1,
+ SAMPLE_REDIRECT_ERR_CNT = 1U << 2,
+ SAMPLE_REDIRECT_CNT = 1U << 7,
+ SAMPLE_REDIRECT_MAP_CNT = SAMPLE_REDIRECT_CNT | _SAMPLE_REDIRECT_MAP,
+ SAMPLE_REDIRECT_ERR_MAP_CNT = SAMPLE_REDIRECT_ERR_CNT | _SAMPLE_REDIRECT_MAP,
};
/* Exit return codes */
@@ -47,6 +51,15 @@ static inline char *safe_strncpy(char *dst, const char *src, size_t size)
}
#pragma GCC diagnostic pop
+#define __attach_tp(name) \
+ ({ \
+ if (!bpf_program__is_tracing(skel->progs.name)) \
+ return -EINVAL; \
+ skel->links.name = bpf_program__attach(skel->progs.name); \
+ if (!skel->links.name) \
+ return -errno; \
+ })
+
#define DEFINE_SAMPLE_INIT(name) \
static int sample_init(struct name *skel, int mask) \
{ \
@@ -54,6 +67,14 @@ static inline char *safe_strncpy(char *dst, const char *src, size_t size)
ret = __sample_init(mask); \
if (ret < 0) \
return ret; \
+ if (mask & SAMPLE_REDIRECT_MAP_CNT) \
+ __attach_tp(tp_xdp_redirect_map); \
+ if (mask & SAMPLE_REDIRECT_CNT) \
+ __attach_tp(tp_xdp_redirect); \
+ if (mask & SAMPLE_REDIRECT_ERR_MAP_CNT) \
+ __attach_tp(tp_xdp_redirect_map_err); \
+ if (mask & SAMPLE_REDIRECT_ERR_CNT) \
+ __attach_tp(tp_xdp_redirect_err); \
return 0; \
}