Skip to content

Commit

Permalink
bpf: fix samples to add fake KBUILD_MODNAME
Browse files Browse the repository at this point in the history
Some of the sample files are causing issues when they are loaded with tc
and cls_bpf, meaning tc bails out while trying to parse the resulting ELF
file as program/map/etc sections are not present, which can be easily
spotted with readelf(1).

Currently, BPF samples are including some of the kernel headers and mid
term we should change them to refrain from this, really. When dynamic
debugging is enabled, we bail out due to undeclared KBUILD_MODNAME, which
is easily overlooked in the build as clang spills this along with other
noisy warnings from various header includes, and llc still generates an
ELF file with mentioned characteristics. For just playing around with BPF
examples, this can be a bit of a hurdle to take.

Just add a fake KBUILD_MODNAME as a band-aid to fix the issue, same is
done in xdp*_kern samples already.

Fixes: 65d472f ("samples/bpf: add 'pointer to packet' tests")
Fixes: 6afb1e2 ("samples/bpf: Add tunnel set/get tests.")
Fixes: a3f7461 ("cgroup: bpf: Add an example to do cgroup checking in BPF")
Reported-by: Chandrasekar Kannan <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Acked-by: Alexei Starovoitov <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
borkmann authored and davem330 committed Oct 29, 2016
1 parent e4cabca commit 96a8eb1
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions samples/bpf/parse_ldabs.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*/
#define KBUILD_MODNAME "foo"
#include <linux/ip.h>
#include <linux/ipv6.h>
#include <linux/in.h>
Expand Down
1 change: 1 addition & 0 deletions samples/bpf/parse_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*/
#define KBUILD_MODNAME "foo"
#include <linux/ip.h>
#include <linux/ipv6.h>
#include <linux/in.h>
Expand Down
1 change: 1 addition & 0 deletions samples/bpf/parse_varlen.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*/
#define KBUILD_MODNAME "foo"
#include <linux/if_ether.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
Expand Down
1 change: 1 addition & 0 deletions samples/bpf/tcbpf1_kern.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define KBUILD_MODNAME "foo"
#include <uapi/linux/bpf.h>
#include <uapi/linux/if_ether.h>
#include <uapi/linux/if_packet.h>
Expand Down
1 change: 1 addition & 0 deletions samples/bpf/tcbpf2_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*/
#define KBUILD_MODNAME "foo"
#include <uapi/linux/bpf.h>
#include <uapi/linux/if_ether.h>
#include <uapi/linux/if_packet.h>
Expand Down
1 change: 1 addition & 0 deletions samples/bpf/test_cgrp2_tc_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*/
#define KBUILD_MODNAME "foo"
#include <uapi/linux/if_ether.h>
#include <uapi/linux/in6.h>
#include <uapi/linux/ipv6.h>
Expand Down

0 comments on commit 96a8eb1

Please sign in to comment.