diff --git a/runsc/sandbox/bpf/af_xdp.ebpf.c b/runsc/sandbox/bpf/af_xdp.ebpf.c index 7f3b46093..f01e837da 100644 --- a/runsc/sandbox/bpf/af_xdp.ebpf.c +++ b/runsc/sandbox/bpf/af_xdp.ebpf.c @@ -12,20 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. +// clang-format off +// Contains types needed by later headers. +#include +// clang-format on +#include #include #define section(secname) __attribute__((section(secname), used)) char __license[] section("license") = "Apache-2.0"; -// Helper functions are defined positionally in , and their -// signatures are scattered throughout the kernel. They can be found via the -// defining macro BPF_CALL_[0-5]. -// TODO(b/240191988): Use vmlinux instead of this. -static int (*bpf_redirect_map)(void *bpf_map, __u32 iface_index, - __u64 flags) = (void *)51; - -struct bpf_map_def { +// Note: bpf_helpers.h includes a struct definition for bpf_map_def in some, but +// not all, environments. Define our own equivalent struct to avoid issues with +// multiple declarations. +struct gvisor_bpf_map_def { unsigned int type; unsigned int key_size; unsigned int value_size; @@ -34,7 +35,7 @@ struct bpf_map_def { }; // A map of RX queue number to AF_XDP socket. We only ever use one key: 0. -struct bpf_map_def section("maps") sock_map = { +struct gvisor_bpf_map_def section("maps") sock_map = { .type = BPF_MAP_TYPE_XSKMAP, // Note: "XSK" means AF_XDP socket. .key_size = sizeof(int), .value_size = sizeof(int), diff --git a/runsc/sandbox/bpf/tunnel_veth.ebpf.c b/runsc/sandbox/bpf/tunnel_veth.ebpf.c index a6013206c..27184ea36 100644 --- a/runsc/sandbox/bpf/tunnel_veth.ebpf.c +++ b/runsc/sandbox/bpf/tunnel_veth.ebpf.c @@ -12,20 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. +// clang-format off +// Contains types needed by later headers. +#include +// clang-format on +#include #include #define section(secname) __attribute__((section(secname), used)) char __license[] section("license") = "Apache-2.0"; -// Helper functions are defined positionally in , and their -// signatures are scattered throughout the kernel. They can be found via the -// defining macro BPF_CALL_[0-5]. -// TODO(b/240191988): Use vmlinux instead of this. -static int (*bpf_redirect_map)(void *bpf_map, __u32 iface_index, - __u64 flags) = (void *)51; - -struct bpf_map_def { +// Note: bpf_helpers.h includes a struct definition for bpf_map_def in some, but +// not all, environments. Define our own equivalent struct to avoid issues with +// multiple declarations. +struct gvisor_bpf_map_def { unsigned int type; unsigned int key_size; unsigned int value_size; @@ -33,7 +34,7 @@ struct bpf_map_def { unsigned int map_flags; }; -struct bpf_map_def section("maps") dev_map = { +struct gvisor_bpf_map_def section("maps") dev_map = { .type = BPF_MAP_TYPE_DEVMAP, .key_size = sizeof(__u32), .value_size = sizeof(__u32), diff --git a/tools/xdp/cmd/bpf/redirect_host.ebpf.c b/tools/xdp/cmd/bpf/redirect_host.ebpf.c index 484b92339..1e67ebab0 100644 --- a/tools/xdp/cmd/bpf/redirect_host.ebpf.c +++ b/tools/xdp/cmd/bpf/redirect_host.ebpf.c @@ -12,7 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +// clang-format off +// Contains types needed by later headers. +#include +// clang-format on #include +#include #include #include #include @@ -23,14 +28,10 @@ char __license[] section("license") = "Apache-2.0"; -// Helper functions are defined positionally in , and their -// signatures are scattered throughout the kernel. They can be found via the -// defining macro BPF_CALL_[0-5]. -// TODO(b/240191988): Use vmlinux instead of this. -static int (*bpf_redirect_map)(void *bpf_map, __u32 iface_index, - __u64 flags) = (void *)51; - -struct bpf_map_def { +// Note: bpf_helpers.h includes a struct definition for bpf_map_def in some, but +// not all, environments. Define our own equivalent struct to avoid issues with +// multiple declarations. +struct gvisor_bpf_map_def { unsigned int type; unsigned int key_size; unsigned int value_size; @@ -38,7 +39,7 @@ struct bpf_map_def { unsigned int map_flags; }; -struct bpf_map_def section("maps") sock_map = { +struct gvisor_bpf_map_def section("maps") sock_map = { .type = BPF_MAP_TYPE_XSKMAP, // Note: "XSK" means AF_XDP socket. .key_size = sizeof(__u32), .value_size = sizeof(__u32), diff --git a/tools/xdp/cmd/bpf/tcpdump.ebpf.c b/tools/xdp/cmd/bpf/tcpdump.ebpf.c index 06ac23112..697fbb747 100644 --- a/tools/xdp/cmd/bpf/tcpdump.ebpf.c +++ b/tools/xdp/cmd/bpf/tcpdump.ebpf.c @@ -12,20 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. +// clang-format off +// Contains types needed by later headers. +#include +// clang-format on +#include #include #define section(secname) __attribute__((section(secname), used)) char __license[] section("license") = "Apache-2.0"; -// Helper functions are defined positionally in , and their -// signatures are scattered throughout the kernel. They can be found via the -// defining macro BPF_CALL_[0-5]. -// TODO(b/240191988): Use vmlinux instead of this. -static int (*bpf_redirect_map)(void *bpf_map, __u32 iface_index, - __u64 flags) = (void *)51; - -struct bpf_map_def { +// Note: bpf_helpers.h includes a struct definition for bpf_map_def in some, but +// not all, environments. Define our own equivalent struct to avoid issues with +// multiple declarations. +struct gvisor_bpf_map_def { unsigned int type; unsigned int key_size; unsigned int value_size; @@ -34,7 +35,7 @@ struct bpf_map_def { }; // A map of RX queue number to AF_XDP socket. We only ever use one key: 0. -struct bpf_map_def section("maps") sock_map = { +struct gvisor_bpf_map_def section("maps") sock_map = { .type = BPF_MAP_TYPE_XSKMAP, // Note: "XSK" means AF_XDP socket. .key_size = sizeof(int), .value_size = sizeof(int), diff --git a/tools/xdp/cmd/bpf/tunnel_host.ebpf.c b/tools/xdp/cmd/bpf/tunnel_host.ebpf.c index 29b00c61f..c01733a55 100644 --- a/tools/xdp/cmd/bpf/tunnel_host.ebpf.c +++ b/tools/xdp/cmd/bpf/tunnel_host.ebpf.c @@ -12,7 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +// clang-format off +// Contains types needed by later headers. +#include +// clang-format on #include +#include #include #include #include @@ -23,14 +28,10 @@ char __license[] section("license") = "Apache-2.0"; -// Helper functions are defined positionally in , and their -// signatures are scattered throughout the kernel. They can be found via the -// defining macro BPF_CALL_[0-5]. -// TODO(b/240191988): Use vmlinux instead of this. -static int (*bpf_redirect_map)(void *bpf_map, __u32 iface_index, - __u64 flags) = (void *)51; - -struct bpf_map_def { +// Note: bpf_helpers.h includes a struct definition for bpf_map_def in some, but +// not all, environments. Define our own equivalent struct to avoid issues with +// multiple declarations. +struct gvisor_bpf_map_def { unsigned int type; unsigned int key_size; unsigned int value_size; @@ -38,7 +39,7 @@ struct bpf_map_def { unsigned int map_flags; }; -struct bpf_map_def section("maps") dev_map = { +struct gvisor_bpf_map_def section("maps") dev_map = { .type = BPF_MAP_TYPE_DEVMAP, .key_size = sizeof(__u32), .value_size = sizeof(__u32),