From f8bf204e4830e92bd24386ad1d7f16e5a0fd58fe Mon Sep 17 00:00:00 2001 From: Sylvain Baubeau Date: Mon, 9 Sep 2019 10:06:23 +0200 Subject: [PATCH] Move header files in the same folder than Go files --- Documentation/pinning.md | 2 +- LICENSE-bpf.txt | 2 +- README.md | 2 +- elf/{include => }/bpf.h | 0 elf/{include => }/bpf_map.h | 0 elf/elf.go | 6 +++--- elf/{include => }/libbpf.h | 0 elf/module.go | 8 ++++---- elf/{lib => }/netlink.c | 7 ++++--- elf/netlink.h | 9 +++++++++ elf/{lib => }/nlattr.c | 3 ++- elf/{include => }/nlattr.h | 0 elf/table.go | 2 +- tests/dummy.c | 4 ++-- 14 files changed, 28 insertions(+), 17 deletions(-) rename elf/{include => }/bpf.h (100%) rename elf/{include => }/bpf_map.h (100%) rename elf/{include => }/libbpf.h (100%) rename elf/{lib => }/netlink.c (97%) create mode 100644 elf/netlink.h rename elf/{lib => }/nlattr.c (99%) rename elf/{include => }/nlattr.h (100%) diff --git a/Documentation/pinning.md b/Documentation/pinning.md index 5f8237d2..554ee25c 100644 --- a/Documentation/pinning.md +++ b/Documentation/pinning.md @@ -15,7 +15,7 @@ where objects are shared via Unix domain sockets. ## Different pinning options `C.bpf_map_def.pinning` (defined in -[bpf.h](https://github.com/iovisor/gobpf/blob/446e57e0e24e/elf/include/bpf.h#L616)) +[bpf.h](https://github.com/iovisor/gobpf/blob/81109c30cbe2/elf/bpf.h#L616)) can be set to one the following pinning options. * `PIN_NONE` : object is not pinned diff --git a/LICENSE-bpf.txt b/LICENSE-bpf.txt index 9d7d80e6..bb7b276a 100644 --- a/LICENSE-bpf.txt +++ b/LICENSE-bpf.txt @@ -1,4 +1,4 @@ -The file at /elf/include/bpf.h is a copy of the Linux kernel file +The file at /elf/bpf.h is a copy of the Linux kernel file /include/uapi/linux/bpf.h, retrieved from version 4.17, Git commit 36f9814, available at https://raw.githubusercontent.com/torvalds/linux/36f9814a494a874d5a0f44843544b4b2539022db/include/uapi/linux/bpf.h. diff --git a/README.md b/README.md index d15595c9..6f45276e 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ sections (`SEC("...")`). The following are currently supported: * `uretprobe/...` * `xdp/...` -Map definitions must correspond to `bpf_map_def` from [the elf package](https://github.com/iovisor/gobpf/blob/master/elf/include/bpf_map.h). +Map definitions must correspond to `bpf_map_def` from [the elf package](https://github.com/iovisor/gobpf/blob/master/elf/bpf_map.h). Otherwise, you will encounter an error like `only one map with size 280 bytes allowed per section (check bpf_map_def)`. The [Cilium](https://github.com/cilium/cilium) BPF docs contain helpful info diff --git a/elf/include/bpf.h b/elf/bpf.h similarity index 100% rename from elf/include/bpf.h rename to elf/bpf.h diff --git a/elf/include/bpf_map.h b/elf/bpf_map.h similarity index 100% rename from elf/include/bpf_map.h rename to elf/bpf_map.h diff --git a/elf/elf.go b/elf/elf.go index b7dc4140..fe14d694 100644 --- a/elf/elf.go +++ b/elf/elf.go @@ -49,8 +49,8 @@ import ( #include #include #include -#include "include/bpf.h" -#include "include/bpf_map.h" +#include "bpf.h" +#include "bpf_map.h" #include #include #include @@ -265,7 +265,7 @@ const ( // Object pin settings should correspond to those of other projects, e.g.: // https://git.kernel.org/pub/scm/linux/kernel/git/shemminger/iproute2.git/tree/include/bpf_elf.h#n25 - // Also it should be self-consistent with `elf/include/bpf.h` in the same repository. + // Also it should be self-consistent with `elf/bpf.h` in the same repository. PIN_NONE = 0 PIN_OBJECT_NS = 1 PIN_GLOBAL_NS = 2 diff --git a/elf/include/libbpf.h b/elf/libbpf.h similarity index 100% rename from elf/include/libbpf.h rename to elf/libbpf.h diff --git a/elf/module.go b/elf/module.go index 6e055447..ca6e59ae 100644 --- a/elf/module.go +++ b/elf/module.go @@ -38,8 +38,8 @@ import ( #include #include #include -#include "include/bpf.h" -#include "include/libbpf.h" +#include "bpf.h" +#include "libbpf.h" #include #include #include @@ -51,8 +51,8 @@ import ( #include #include -#include "lib/nlattr.c" -#include "lib/netlink.c" +#include "netlink.h" +#include "nlattr.h" static int perf_event_open_tracepoint(int tracepoint_id, int pid, int cpu, int group_fd, unsigned long flags) diff --git a/elf/lib/netlink.c b/elf/netlink.c similarity index 97% rename from elf/lib/netlink.c rename to elf/netlink.c index a89549b9..8ad26ad3 100644 --- a/elf/lib/netlink.c +++ b/elf/netlink.c @@ -1,7 +1,9 @@ // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) /* Copyright (c) 2018 Facebook */ +#include #include +#include #include #include #include @@ -9,9 +11,8 @@ #include #include -#include "include/bpf.h" -#include "include/libbpf.h" -#include "include/nlattr.h" +#include "libbpf.h" +#include "nlattr.h" #ifndef SOL_NETLINK #define SOL_NETLINK 270 diff --git a/elf/netlink.h b/elf/netlink.h new file mode 100644 index 00000000..244077c1 --- /dev/null +++ b/elf/netlink.h @@ -0,0 +1,9 @@ +#ifndef __NETLINK_H +#define __NETLINK_H + +#include "bpf.h" + +int libbpf_netlink_open(__u32 *nl_pid); +int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags); + +#endif diff --git a/elf/lib/nlattr.c b/elf/nlattr.c similarity index 99% rename from elf/lib/nlattr.c rename to elf/nlattr.c index 511a1045..77f1d1c3 100644 --- a/elf/lib/nlattr.c +++ b/elf/nlattr.c @@ -7,7 +7,8 @@ */ #include -#include "include/nlattr.h" +#include "nlattr.h" +#include "libbpf.h" #include #include #include diff --git a/elf/include/nlattr.h b/elf/nlattr.h similarity index 100% rename from elf/include/nlattr.h rename to elf/nlattr.h diff --git a/elf/table.go b/elf/table.go index 5aa2df68..d90e0f75 100644 --- a/elf/table.go +++ b/elf/table.go @@ -25,7 +25,7 @@ import ( ) /* -#include "include/bpf.h" +#include "bpf.h" #include extern __u64 ptr_to_u64(void *); diff --git a/tests/dummy.c b/tests/dummy.c index 12a4841e..8c6e8f39 100644 --- a/tests/dummy.c +++ b/tests/dummy.c @@ -2,8 +2,8 @@ * Compiled with './build' */ -#include "../elf/include/bpf.h" -#include "../elf/include/bpf_map.h" +#include "../elf/bpf.h" +#include "../elf/bpf_map.h" #define SEC(NAME) __attribute__((section(NAME), used))