Commit edd7f4ef authored by David S. Miller's avatar David S. Miller

Merge branch 'bpf-samples-skb_mode-bug-fixes'

Jesper Dangaard Brouer says:

====================
samples/bpf: two bug fixes to XDP_FLAGS_SKB_MODE attaching

Two small bugfixes for:
 commit 3993f2cb ("samples/bpf: Add support for SKB_MODE to xdp1 and xdp_tx_iptunnel")
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents d74a32ac f76254a8
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <linux/perf_event.h> #include <linux/perf_event.h>
#include <linux/netlink.h> #include <linux/netlink.h>
#include <linux/rtnetlink.h> #include <linux/rtnetlink.h>
#include <linux/types.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/syscall.h> #include <sys/syscall.h>
...@@ -585,7 +586,7 @@ struct ksym *ksym_search(long key) ...@@ -585,7 +586,7 @@ struct ksym *ksym_search(long key)
return &syms[0]; return &syms[0];
} }
int set_link_xdp_fd(int ifindex, int fd, int flags) int set_link_xdp_fd(int ifindex, int fd, __u32 flags)
{ {
struct sockaddr_nl sa; struct sockaddr_nl sa;
int sock, seq = 0, len, ret = -1; int sock, seq = 0, len, ret = -1;
......
...@@ -47,5 +47,5 @@ struct ksym { ...@@ -47,5 +47,5 @@ struct ksym {
int load_kallsyms(void); int load_kallsyms(void);
struct ksym *ksym_search(long key); struct ksym *ksym_search(long key);
int set_link_xdp_fd(int ifindex, int fd, int flags); int set_link_xdp_fd(int ifindex, int fd, __u32 flags);
#endif #endif
...@@ -20,11 +20,11 @@ ...@@ -20,11 +20,11 @@
#include "libbpf.h" #include "libbpf.h"
static int ifindex; static int ifindex;
static int flags; static __u32 xdp_flags;
static void int_exit(int sig) static void int_exit(int sig)
{ {
set_link_xdp_fd(ifindex, -1, flags); set_link_xdp_fd(ifindex, -1, xdp_flags);
exit(0); exit(0);
} }
...@@ -75,7 +75,7 @@ int main(int argc, char **argv) ...@@ -75,7 +75,7 @@ int main(int argc, char **argv)
while ((opt = getopt(argc, argv, optstr)) != -1) { while ((opt = getopt(argc, argv, optstr)) != -1) {
switch (opt) { switch (opt) {
case 'S': case 'S':
flags |= XDP_FLAGS_SKB_MODE; xdp_flags |= XDP_FLAGS_SKB_MODE;
break; break;
default: default:
usage(basename(argv[0])); usage(basename(argv[0]));
...@@ -103,7 +103,7 @@ int main(int argc, char **argv) ...@@ -103,7 +103,7 @@ int main(int argc, char **argv)
signal(SIGINT, int_exit); signal(SIGINT, int_exit);
if (set_link_xdp_fd(ifindex, prog_fd[0], flags) < 0) { if (set_link_xdp_fd(ifindex, prog_fd[0], xdp_flags) < 0) {
printf("link set xdp fd failed\n"); printf("link set xdp fd failed\n");
return 1; return 1;
} }
......
...@@ -25,11 +25,12 @@ ...@@ -25,11 +25,12 @@
#define STATS_INTERVAL_S 2U #define STATS_INTERVAL_S 2U
static int ifindex = -1; static int ifindex = -1;
static __u32 xdp_flags = 0;
static void int_exit(int sig) static void int_exit(int sig)
{ {
if (ifindex > -1) if (ifindex > -1)
set_link_xdp_fd(ifindex, -1, 0); set_link_xdp_fd(ifindex, -1, xdp_flags);
exit(0); exit(0);
} }
...@@ -143,7 +144,6 @@ int main(int argc, char **argv) ...@@ -143,7 +144,6 @@ int main(int argc, char **argv)
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY}; struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
struct vip vip = {}; struct vip vip = {};
char filename[256]; char filename[256];
int flags = 0;
int opt; int opt;
int i; int i;
...@@ -204,7 +204,7 @@ int main(int argc, char **argv) ...@@ -204,7 +204,7 @@ int main(int argc, char **argv)
kill_after_s = atoi(optarg); kill_after_s = atoi(optarg);
break; break;
case 'S': case 'S':
flags |= XDP_FLAGS_SKB_MODE; xdp_flags |= XDP_FLAGS_SKB_MODE;
break; break;
default: default:
usage(argv[0]); usage(argv[0]);
...@@ -248,14 +248,14 @@ int main(int argc, char **argv) ...@@ -248,14 +248,14 @@ int main(int argc, char **argv)
} }
} }
if (set_link_xdp_fd(ifindex, prog_fd[0], flags) < 0) { if (set_link_xdp_fd(ifindex, prog_fd[0], xdp_flags) < 0) {
printf("link set xdp fd failed\n"); printf("link set xdp fd failed\n");
return 1; return 1;
} }
poll_stats(kill_after_s); poll_stats(kill_after_s);
set_link_xdp_fd(ifindex, -1, flags); set_link_xdp_fd(ifindex, -1, xdp_flags);
return 0; return 0;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment