]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
samples: bpf: get ifindex from ifname
authorMatteo Croce <mcroce@redhat.com>
Sat, 1 Dec 2018 00:23:06 +0000 (01:23 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 1 Dec 2018 06:06:41 +0000 (22:06 -0800)
Find the ifindex with if_nametoindex() instead of requiring the
numeric ifindex.

Signed-off-by: Matteo Croce <mcroce@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
samples/bpf/xdp1_user.c

index 4f3d824fc044c552a708fb8d2e604139abd37b09..0a197f86ac43a7a28b281d36efeedb5d423dd8dd 100644 (file)
@@ -15,6 +15,7 @@
 #include <unistd.h>
 #include <libgen.h>
 #include <sys/resource.h>
+#include <net/if.h>
 
 #include "bpf_util.h"
 #include "bpf/bpf.h"
@@ -59,7 +60,7 @@ static void poll_stats(int map_fd, int interval)
 static void usage(const char *prog)
 {
        fprintf(stderr,
-               "usage: %s [OPTS] IFINDEX\n\n"
+               "usage: %s [OPTS] IFACE\n\n"
                "OPTS:\n"
                "    -S    use skb-mode\n"
                "    -N    enforce native mode\n",
@@ -102,7 +103,11 @@ int main(int argc, char **argv)
                return 1;
        }
 
-       ifindex = strtoul(argv[optind], NULL, 0);
+       ifindex = if_nametoindex(argv[1]);
+       if (!ifindex) {
+               perror("if_nametoindex");
+               return 1;
+       }
 
        snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
        prog_load_attr.file = filename;