Enable Netdev XDP tutorial for Ubuntu 17.04
PATCH 1/1 Enable Netdev XDP tutorial for Ubuntu 17.04
This patch resolves build issues when compiling the samples on
Ubuntu 17.04 with the distro 4.10 kernel and the linux-headers package installed. This permits running the samples using distro packages without needing to rebuild the kernel from source.
Tested on a 17.04 VM using virtio_net.
---
I haven't tried the patched version of this on a built from
source kernel yet, so it might break that.
kernel/samples/bpf/Makefile | 18 ++++-------------- kernel/samples/bpf/libbpf.h | 2 +- kernel/samples/bpf/xdp_ddos01_blacklist_cmdline.c | 3 +-- 3 files changed, 6 insertions(+), 17 deletions(-)
kernel/samples/bpf/Makefile +4 -14
@@ -49,17 +49,7 @@ KERNEL=$(kbuilddir) CFLAGS := -O2 -Wall # Local copy of kernel/tools/lib/ -CFLAGS += -I./tools/lib -#CFLAGS += -I$(KERNEL)/tools/lib -# -# Local copy of uapi/linux/bpf.h kept under ./tools/include -# needed due to enum dependency in bpf_helpers.h -CFLAGS += -I./tools/include -CFLAGS += -I$(KERNEL)/tools/include -#CFLAGS += -I$(KERNEL)/tools/perf -CFLAGS += -I$(KERNEL)/usr/include -# Strange dependency to "selftests" due to "bpf_util.h" -#CFLAGS += -I$(KERNEL)/tools/testing/selftests/bpf/ +USER_CFLAGS := $(CFLAGS) -I./tools/lib LDFLAGS= -lelf
@@ -151,7 +141,7 @@ $(OBJECT_LIBBPF): %.o: %.c $(CC) $(CFLAGS) -o $@ -c $< $(OBJECT_LOADBPF): bpf_load.c - $(CC) $(CFLAGS) -o $@ -c $< + $(CC) $(USER_CFLAGS) -o $@ -c $< # Compiling of eBPF restricted-C code with LLVM # clang option -S generated output file with suffix .ll
@@ -168,7 +158,7 @@ $(KERN_OBJECTS): %.o: %.c $(LLC) -march=bpf -filetype=obj -o $@ ${@:.o=.ll} $(TARGETS): %: %_user.c $(OBJECTS) Makefile - $(CC) $(CFLAGS) $(OBJECTS) $(LDFLAGS) -o $@ $< + $(CC) $(USER_CFLAGS) $(OBJECTS) $(LDFLAGS) -o $@ $< $(CMDLINE_TOOLS): %: %.c $(OBJECTS) Makefile $(COMMON_H) - $(CC) -g $(CFLAGS) $(OBJECTS) $(LDFLAGS) -o $@ $< + $(CC) -g $(USER_CFLAGS) $(OBJECTS) $(LDFLAGS) -o $@ $<
kernel/samples/bpf/libbpf.h +1 -1
@@ -9,7 +9,7 @@* construct of -I$(KERNEL)/tools/lib/ this include find * tools/lib/bpf/bpf.h which defines the userspace API */ -#include <bpf/bpf.h> +#include "bpf/bpf.h" struct bpf_insn ;
kernel/samples/bpf/xdp_ddos01_blacklist_cmdline.c +1 -2
@@ -13,7 +13,6 @@ static const char *__doc__=#include <string.h> #include <unistd.h> #include <locale.h> -#include <linux/bitops.h> #include <sys/resource.h> #include <getopt.h>
@@ -212,7 +211,7 @@ static void blacklist_print_proto(int key, __u64 count)printf ("\n\t\"%s\" : %llu" , xdp_proto_filter_names[key], count); } -static void blacklist_print_port (int key,u32 val,int countfds[]) +static void blacklist_print_port (int key,__u32 val,int countfds[]) {int i;__u64 count;
Signature · 1 line
2.7.4
Quoted 6 lines · Jay Vosburgh
This patch resolves build issues when compiling the samples on
Ubuntu 17.04 with the distro 4.10 kernel and the linux-headers package installed. This permits running the samples using distro packages without needing to rebuild the kernel from source.Tested on a 17.04 VM using
virtio_net.
This is a good goal and I like where you are going with this.
Unfortunately with this patch applied I cannot build against a locally installed and running kernel.
$ make
gcc -O2 -Wall -o tools/lib/bpf/bpf.o -c tools/lib/bpf/bpf.c
tools/lib/bpf/bpf.c: In function ‘bpf_create_map’:
tools/lib/bpf/bpf.c:67:6: error: ‘union bpf_attr’ has no member named ‘map_flags’
attr.map_flags = map_flags;
^
Makefile:141: recipe for target 'tools/lib/bpf/bpf.o' failed
make: *** [tools/lib/bpf/bpf.o] Error 1The build deps are not ideal in this Makefile, so I'm wondering if your build was successful because you had tools/lib/bpf/bpf.o left over from a successful build.
This patch on top of yours does work for me. Can you add this on top and let me know if your build still works?
kernel/samples/bpf/Makefile +2 -2
@@ -49,7 +49,7 @@ KERNEL=$(kbuilddir) CFLAGS := -O2 -Wall # Local copy of kernel/tools/lib/ -USER_CFLAGS := $(CFLAGS) -I./tools/lib +USER_CFLAGS := $(CFLAGS) -I./tools/lib -I./tools/include/uapi/ LDFLAGS= -lelf
@@ -138,7 +138,7 @@ verify_llvm_target_bpf: verify_cmds # The fake-minimal-libbpf $(OBJECT_LIBBPF): %.o: %.c - $(CC) $(CFLAGS) -o $@ -c $< + $(CC) $(USER_CFLAGS) -o $@ -c $< $(OBJECT_LOADBPF): bpf_load.c $(CC) $(USER_CFLAGS) -o $@ -c $<
Quoted 91 lines
Signed-off-by Jay Vosburgh <[email protected]>---
I haven't tried the patched version of this on a built from
source kernel yet, so it might break that.kernel/samples/bpf/Makefile | 18 ++++-------------- kernel/samples/bpf/libbpf.h | 2 +- kernel/samples/bpf/xdp_ddos01_blacklist_cmdline.c | 3 +-- 3 files changed, 6 insertions(+), 17 deletions(-)kernel/samples/bpf/Makefile +4
-14@@ -49,17 +49,7 @@ KERNEL=$(kbuilddir) CFLAGS := -O2 -Wall # Local copy of kernel/tools/lib/ -CFLAGS += -I./tools/lib -#CFLAGS += -I$(KERNEL)/tools/lib -# -# Local copy of uapi/linux/bpf.h kept under ./tools/include -# needed due to enum dependency in bpf_helpers.h -CFLAGS += -I./tools/include -CFLAGS += -I$(KERNEL)/tools/include -#CFLAGS += -I$(KERNEL)/tools/perf -CFLAGS += -I$(KERNEL)/usr/include -# Strange dependency to "selftests" due to "bpf_util.h" -#CFLAGS += -I$(KERNEL)/tools/testing/selftests/bpf/ +USER_CFLAGS := $(CFLAGS) -I./tools/lib LDFLAGS= -lelf@@ -151,7 +141,7 @@ $(OBJECT_LIBBPF): %.o: %.c $(CC) $(CFLAGS) -o $@ -c $< $(OBJECT_LOADBPF): bpf_load.c - $(CC) $(CFLAGS) -o $@ -c $< + $(CC) $(USER_CFLAGS) -o $@ -c $< # Compiling of eBPF restricted-C code with LLVM # clang option -S generated output file with suffix .ll@@ -168,7 +158,7 @@ $(KERN_OBJECTS): %.o: %.c $(LLC) -march=bpf -filetype=obj -o $@ ${@:.o=.ll} $(TARGETS): %: %_user.c $(OBJECTS) Makefile - $(CC) $(CFLAGS) $(OBJECTS) $(LDFLAGS) -o $@ $< + $(CC) $(USER_CFLAGS) $(OBJECTS) $(LDFLAGS) -o $@ $< $(CMDLINE_TOOLS): %: %.c $(OBJECTS) Makefile $(COMMON_H) - $(CC) -g $(CFLAGS) $(OBJECTS) $(LDFLAGS) -o $@ $< + $(CC) -g $(USER_CFLAGS) $(OBJECTS) $(LDFLAGS) -o $@ $<kernel/samples/bpf/libbpf.h +1
-1@@ -9,7 +9,7 @@* construct of -I$(KERNEL)/tools/lib/ this include find * tools/lib/bpf/bpf.h which defines the userspace API */ -#include <bpf/bpf.h> +#include "bpf/bpf.h" struct bpf_insn ;kernel/samples/bpf/xdp_ddos01_blacklist_cmdline.c +1
-2@@ -13,7 +13,6 @@ static const char *__doc__=#include <string.h> #include <unistd.h> #include <locale.h> -#include <linux/bitops.h> #include <sys/resource.h> #include <getopt.h> @@ -212,7 +211,7 @@ static void blacklist_print_proto(int key, __u64 count)printf ("\n\t\"%s\" : %llu" , xdp_proto_filter_names[key], count); } -static void blacklist_print_port (int key,u32 val,int countfds[]) +static void blacklist_print_port (int key,__u32 val,int countfds[]) {int i;__u64 count;Signature · 1 line
2.7.4
Quoted 13 lines · Andy Gospodarek
Quoted 6 lines · Jay Vosburgh
This patch resolves build issues when compiling the samples on
Ubuntu 17.04 with the distro 4.10 kernel and the linux-headers package installed. This permits running the samples using distro packages without needing to rebuild the kernel from source.Tested on a 17.04 VM using
virtio_net.This is a good goal and I like where you are going with this.
Unfortunately with this patch applied I cannot build against a locally installed and running kernel.
Quoted 8 lines
$ make
gcc -O2 -Wall -o tools/lib/bpf/bpf.o -c tools/lib/bpf/bpf.c
tools/lib/bpf/bpf.c: In function ‘bpf_create_map’:
tools/lib/bpf/bpf.c:67:6: error: ‘union bpf_attr’ has no member named ‘map_flags’
attr.map_flags = map_flags;
^
Makefile:141: recipe for target 'tools/lib/bpf/bpf.o' failed
make: *** [tools/lib/bpf/bpf.o] Error 1 FWIW, I saw this error when originally trying to compile on the
Ubuntu 16.04 user space, because the glibc headers are too old to have this field in bpf_attr.
Quoted 3 lines
The build deps are not ideal in this
Makefile, so I'm wondering if your build was successful because you hadtools/lib/bpf/bpf.oleft over from a successful build.
"make clean" looks like it erases that bpf.o, so I don't think
this was it.
Also, I just noticed that make clean isn't getting the command
line program itself:
kernel/samples/bpf/Makefile +1 -0
@@ -96,6 +96,7 @@ clean: rm -f $(TARGETS) rm -f $(KERN_OBJECTS) rm -f $(USER_OBJECTS) + rm -f $(CMDLINE_TOOLS) dependencies: verify_llvm_target_bpf linux-src-devel-headers
Quoted 2 lines
This patch on top of yours does work for me. Can you add this on top and let me know if your build still works?
With your patch applied, on my system it still builds fine. -J
Quoted 106 lines
kernel/samples/bpf/Makefile +0
-0@@ -49,7 +49,7 @@ KERNEL=$(kbuilddir)CFLAGS := -O2 -Wall
# Local copy of
kernel/tools/lib/kernel/samples/bpf/Makefile +1
-1-USER_CFLAGS := $(CFLAGS) -I./tools/lib +USER_CFLAGS := $(CFLAGS) -I./tools/lib -I./tools/include/uapi/LDFLAGS= -lelf
kernel/samples/bpf/Makefile +0
-0@@ -138,7 +138,7 @@ verify_llvm_target_bpf: verify_cmds # The fake-minimal-libbpf$(OBJECT_LIBBPF): %.o: %.c
kernel/samples/bpf/Makefile +1
-1- $(CC) $(CFLAGS) -o $@ -c $< + $(CC) $(USER_CFLAGS) -o $@ -c $<$(OBJECT_LOADBPF):
bpf_load.c$(CC) $(USER_CFLAGS) -o $@ -c $<Quoted 83 lines
Signed-off-by Jay Vosburgh <[email protected]>---
I haven't tried the patched version of this on a built from
source kernel yet, so it might break that.kernel/samples/bpf/Makefile | 18 ++++-------------- kernel/samples/bpf/libbpf.h | 2 +- kernel/samples/bpf/xdp_ddos01_blacklist_cmdline.c | 3 +-- 3 files changed, 6 insertions(+), 17 deletions(-)kernel/samples/bpf/Makefile +4
-14@@ -49,17 +49,7 @@ KERNEL=$(kbuilddir) CFLAGS := -O2 -Wall # Local copy of kernel/tools/lib/ -CFLAGS += -I./tools/lib -#CFLAGS += -I$(KERNEL)/tools/lib -# -# Local copy of uapi/linux/bpf.h kept under ./tools/include -# needed due to enum dependency in bpf_helpers.h -CFLAGS += -I./tools/include -CFLAGS += -I$(KERNEL)/tools/include -#CFLAGS += -I$(KERNEL)/tools/perf -CFLAGS += -I$(KERNEL)/usr/include -# Strange dependency to "selftests" due to "bpf_util.h" -#CFLAGS += -I$(KERNEL)/tools/testing/selftests/bpf/ +USER_CFLAGS := $(CFLAGS) -I./tools/lib LDFLAGS= -lelf@@ -151,7 +141,7 @@ $(OBJECT_LIBBPF): %.o: %.c $(CC) $(CFLAGS) -o $@ -c $< $(OBJECT_LOADBPF): bpf_load.c - $(CC) $(CFLAGS) -o $@ -c $< + $(CC) $(USER_CFLAGS) -o $@ -c $< # Compiling of eBPF restricted-C code with LLVM # clang option -S generated output file with suffix .ll@@ -168,7 +158,7 @@ $(KERN_OBJECTS): %.o: %.c $(LLC) -march=bpf -filetype=obj -o $@ ${@:.o=.ll} $(TARGETS): %: %_user.c $(OBJECTS) Makefile - $(CC) $(CFLAGS) $(OBJECTS) $(LDFLAGS) -o $@ $< + $(CC) $(USER_CFLAGS) $(OBJECTS) $(LDFLAGS) -o $@ $< $(CMDLINE_TOOLS): %: %.c $(OBJECTS) Makefile $(COMMON_H) - $(CC) -g $(CFLAGS) $(OBJECTS) $(LDFLAGS) -o $@ $< + $(CC) -g $(USER_CFLAGS) $(OBJECTS) $(LDFLAGS) -o $@ $<kernel/samples/bpf/libbpf.h +1
-1@@ -9,7 +9,7 @@* construct of -I$(KERNEL)/tools/lib/ this include find * tools/lib/bpf/bpf.h which defines the userspace API */ -#include <bpf/bpf.h> +#include "bpf/bpf.h" struct bpf_insn ;kernel/samples/bpf/xdp_ddos01_blacklist_cmdline.c +0
-1@@ -13,7 +13,6 @@ static const char *__doc__=#include <string.h> #include <unistd.h> #include <locale.h> -#include <linux/bitops.h> #include <sys/resource.h> #include <getopt.h> @@ -212,7 +211,7 @@ static void blacklist_print_proto(int key, __u64 count)printf ("\n\t\"%s\" : %llu" , xdp_proto_filter_names[key], count); }
Quoted 8 lines
Quoted 8 lines
kernel/samples/bpf/xdp_ddos01_blacklist_cmdline.c +1
-1-static void blacklist_print_port (int key,u32 val,int countfds[]) +static void blacklist_print_port (int key,__u32 val,int countfds[]) {int i;__u64 count;Signature · 1 line
2.7.4
---
-Jay Vosburgh, [email protected]
Quoted 6 lines · Jay Vosburgh
This patch resolves build issues when compiling the samples on
Ubuntu 17.04 with the distro 4.10 kernel and the linux-headers package
installed. This permits running the samples using distro packages without needing to rebuild the kernel from source.
Quoted 7 lines
Tested on a 17.04 VM using
virtio_net.Signed-off-by Jay Vosburgh <[email protected]>---
I haven't tried the patched version of this on a built from
source kernel yet, so it might break that.
I was able to build on a recent Debian testing by simply inserting the following line into samples/bpf/Makefile to force it to use the kernel's UAPI instead of the installed headers:
HOSTCFLAGS += -I$(srctree)/include/uapi/ -D__EXPORTED_HEADERS__
johannes
Quoted 12 lines · Johannes Berg
Quoted 11 lines · Jay Vosburgh
This patch resolves build issues when compiling the samples on
Ubuntu 17.04 with the distro 4.10 kernel and the linux-headers package
installed. This permits running the samples using distro packages without needing to rebuild the kernel from source.Tested on a 17.04 VM using
virtio_net.Signed-off-by Jay Vosburgh <[email protected]>---
Quoted 8 lines
Quoted 2 lines
I haven't tried the patched version of this on a built from
source kernel yet, so it might break that.I was able to build on a recent Debian testing by simply inserting the following line into
samples/bpf/Makefileto force it to use the kernel's UAPI instead of the installed headers:HOSTCFLAGS += -I$(srctree)/include/uapi/ -D__EXPORTED_HEADERS__
Getting back to this after a couple of weeks...
The above changes didn't make any difference for me, but it
turns out all of the various Makefile hacks I did previously aren't needed for Ubuntu 17.04, the following lets the examples build and run fine:
kernel/samples/bpf/xdp_ddos01_blacklist_cmdline.c +1 -2
@@ -13,7 +13,6 @@ static const char *__doc__=#include <string.h> #include <unistd.h> #include <locale.h> -#include <linux/bitops.h> #include <sys/resource.h> #include <getopt.h>
@@ -212,7 +211,7 @@ static void blacklist_print_proto(int key, __u64 count)printf ("\n\t\"%s\" : %llu" , xdp_proto_filter_names[key], count); } -static void blacklist_print_port (int key,u32 val,int countfds[]) +static void blacklist_print_port (int key,__u32 val,int countfds[]) {int i;__u64 count;
-J
---
-Jay Vosburgh, [email protected]
Quoted 35 lines · On Fri, 21 Apr 2017 13:58:42 -0700 Jay Vosburgh <[email protected]>…
Quoted 12 lines · Johannes Berg
Quoted 11 lines · Jay Vosburgh
This patch resolves build issues when compiling the samples on
Ubuntu 17.04 with the distro 4.10 kernel and the linux-headers package
installed. This permits running the samples using distro packages without needing to rebuild the kernel from source.Tested on a 17.04 VM using
virtio_net.Signed-off-by Jay Vosburgh <[email protected]>---
Quoted 8 lines
Quoted 2 lines
I haven't tried the patched version of this on a built from
source kernel yet, so it might break that.I was able to build on a recent Debian testing by simply inserting the following line into
samples/bpf/Makefileto force it to use the kernel's UAPI instead of the installed headers:HOSTCFLAGS += -I$(srctree)/include/uapi/ -D__EXPORTED_HEADERS__
Getting back to this after a couple of weeks...
The above changes didn't make any difference for me, but it
turns out all of the variousMakefilehacks I did previously aren't needed for Ubuntu 17.04, the following lets the examples build and run fine:kernel/samples/bpf/xdp_ddos01_blacklist_cmdline.c +0
-0
kernel/samples/bpf/xdp_ddos01_blacklist_cmdline.c static const char *__doc__= · line 16
Quoted 4 lines
kernel/samples/bpf/xdp_ddos01_blacklist_cmdline.c +0
-1@@ -13,7 +13,6 @@ static const char *__doc__=#include <string.h> #include <unistd.h> #include <locale.h> -#include <linux/bitops.h>
This include was added by Andy in commit 888606b5accb ("samples/bpf:xdp_ddos01 add support for port blacklisting").
To Andy, are you okay with this change/patch?
Quoted 12 lines
kernel/samples/bpf/xdp_ddos01_blacklist_cmdline.c +1
-1#include <sys/resource.h> #include <getopt.h> @@ -212,7 +211,7 @@ static void blacklist_print_proto(int key, __u64 count)printf ("\n\t\"%s\" : %llu" , xdp_proto_filter_names[key], count); } -static void blacklist_print_port (int key,u32 val,int countfds[]) +static void blacklist_print_port (int key,__u32 val,int countfds[]) {int i;__u64 count;
Signature · 4 lines
Best regards, Jesper Dangaard Brouer MSc.CS, Principal Kernel Engineer at Red Hat LinkedIn: http://www.linkedin.com/in/brouer
Jesper Dangaard Brouer
AppliedHi Jay,
Quoted 20 lines · On Tue, 25 Apr 2017 10:35:37 +0200 Jesper Dangaard Brouer <[email protected]>…
Quoted 12 lines
Getting back to this after a couple of weeks...
The above changes didn't make any difference for me, but it
turns out all of the variousMakefilehacks I did previously aren't needed for Ubuntu 17.04, the following lets the examples build and run fine:kernel/samples/bpf/xdp_ddos01_blacklist_cmdline.c +0
-0kernel/samples/bpf/xdp_ddos01_blacklist_cmdline.c static const char *__doc__= · line 16
Quoted 4 lines
kernel/samples/bpf/xdp_ddos01_blacklist_cmdline.c +0
-1@@ -13,7 +13,6 @@ static const char *__doc__=#include <string.h> #include <unistd.h> #include <locale.h> -#include <linux/bitops.h> This include was added by Andy in commit
888606b5accb("samples/bpf:xdp_ddos01add support for port blacklisting").
Quoted 1 line
To Andy, are you okay with this change/patch?
I've applied this and gave you author credit for the fix:
https://github.com/netoptimizer/prototype-kernel/commit/7e879ecd6a96
Quoted 6 lines
Quoted 6 lines
kernel/samples/bpf/xdp_ddos01_blacklist_cmdline.c +0
-0#include <sys/resource.h> #include <getopt.h> @@ -212,7 +211,7 @@ static void blacklist_print_proto(int key, __u64 count)printf ("\n\t\"%s\" : %llu" , xdp_proto_filter_names[key], count); }
Quoted 6 lines
kernel/samples/bpf/xdp_ddos01_blacklist_cmdline.c static void blacklist_print_proto(int key, __u64 count) · line 217
Quoted 6 lines
kernel/samples/bpf/xdp_ddos01_blacklist_cmdline.c +1
-1-static void blacklist_print_port (int key,u32 val,int countfds[]) +static void blacklist_print_port (int key,__u32 val,int countfds[]) {int i;__u64 count;
Applied
Signature · 4 lines
Best regards, Jesper Dangaard Brouer MSc.CS, Principal Kernel Engineer at Red Hat LinkedIn: http://www.linkedin.com/in/brouer