aboutsummaryrefslogtreecommitdiff
path: root/samples/bpf/xdp_redirect_map_user.c
diff options
context:
space:
mode:
authorJesper Dangaard Brouer <brouer@redhat.com>2017-08-29 16:38:06 +0200
committerDavid S. Miller <davem@davemloft.net>2017-08-29 10:51:29 -0700
commit306da4e685b415f5c875cef275001b5cdc182da9 (patch)
tree76ba2be2cdb8d5a01fa43270a66fdbf758837f99 /samples/bpf/xdp_redirect_map_user.c
parent59a308967589f5b3f1f42793ab49bc2e18069769 (diff)
downloadlinux-stericsson-306da4e685b415f5c875cef275001b5cdc182da9.tar.gz
samples/bpf: xdp_redirect load XDP dummy prog on TX device
For supporting XDP_REDIRECT, a device driver must (obviously) implement the "TX" function ndo_xdp_xmit(). An additional requirement is you cannot TX out a device, unless it also have a xdp bpf program attached. This dependency is caused by the driver code need to setup XDP resources before it can ndo_xdp_xmit. Update bpf samples xdp_redirect and xdp_redirect_map to automatically attach a dummy XDP program to the configured ifindex_out device. Use the XDP flag XDP_FLAGS_UPDATE_IF_NOEXIST on the dummy load, to avoid overriding an existing XDP prog on the device. Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'samples/bpf/xdp_redirect_map_user.c')
-rw-r--r--samples/bpf/xdp_redirect_map_user.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/samples/bpf/xdp_redirect_map_user.c b/samples/bpf/xdp_redirect_map_user.c
index a1ad00fdaa8a..d4d86a273fba 100644
--- a/samples/bpf/xdp_redirect_map_user.c
+++ b/samples/bpf/xdp_redirect_map_user.c
@@ -16,6 +16,7 @@
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include <libgen.h>
@@ -26,17 +27,18 @@
static int ifindex_in;
static int ifindex_out;
+static bool ifindex_out_xdp_dummy_attached = true;
static __u32 xdp_flags;
static void int_exit(int sig)
{
set_link_xdp_fd(ifindex_in, -1, xdp_flags);
+ if (ifindex_out_xdp_dummy_attached)
+ set_link_xdp_fd(ifindex_out, -1, xdp_flags);
exit(0);
}
-/* simple per-protocol drop counter
- */
static void poll_stats(int interval, int ifindex)
{
unsigned int nr_cpus = bpf_num_possible_cpus();
@@ -70,7 +72,6 @@ static void usage(const char *prog)
prog);
}
-
int main(int argc, char **argv)
{
const char *optstr = "SN";
@@ -112,14 +113,21 @@ int main(int argc, char **argv)
return 1;
}
- signal(SIGINT, int_exit);
- signal(SIGTERM, int_exit);
-
if (set_link_xdp_fd(ifindex_in, prog_fd[0], xdp_flags) < 0) {
- printf("link set xdp fd failed\n");
+ printf("ERROR: link set xdp fd failed on %d\n", ifindex_in);
return 1;
}
+ /* Loading dummy XDP prog on out-device */
+ if (set_link_xdp_fd(ifindex_out, prog_fd[1],
+ (xdp_flags | XDP_FLAGS_UPDATE_IF_NOEXIST)) < 0) {
+ printf("WARN: link set xdp fd failed on %d\n", ifindex_out);
+ ifindex_out_xdp_dummy_attached = false;
+ }
+
+ signal(SIGINT, int_exit);
+ signal(SIGTERM, int_exit);
+
printf("map[0] (vports) = %i, map[1] (map) = %i, map[2] (count) = %i\n",
map_fd[0], map_fd[1], map_fd[2]);