xdp: user real BPF helper functions, not a hacky forward definition

PiperOrigin-RevId: 600574627
This commit is contained in:
Kevin Krakauer
2024-01-22 14:41:45 -08:00
committed by gVisor bot
parent 7b151e25d0
commit 9db874189a
5 changed files with 50 additions and 45 deletions
+10 -9
View File
@@ -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 <linux/types.h>
// clang-format on
#include <bpf/bpf_helpers.h>
#include <linux/bpf.h>
#define section(secname) __attribute__((section(secname), used))
char __license[] section("license") = "Apache-2.0";
// Helper functions are defined positionally in <linux/bpf.h>, 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),
+10 -9
View File
@@ -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 <linux/types.h>
// clang-format on
#include <bpf/bpf_helpers.h>
#include <linux/bpf.h>
#define section(secname) __attribute__((section(secname), used))
char __license[] section("license") = "Apache-2.0";
// Helper functions are defined positionally in <linux/bpf.h>, 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),
+10 -9
View File
@@ -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 <linux/types.h>
// clang-format on
#include <bpf/bpf_endian.h>
#include <bpf/bpf_helpers.h>
#include <linux/bpf.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
@@ -23,14 +28,10 @@
char __license[] section("license") = "Apache-2.0";
// Helper functions are defined positionally in <linux/bpf.h>, 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),
+10 -9
View File
@@ -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 <linux/types.h>
// clang-format on
#include <bpf/bpf_helpers.h>
#include <linux/bpf.h>
#define section(secname) __attribute__((section(secname), used))
char __license[] section("license") = "Apache-2.0";
// Helper functions are defined positionally in <linux/bpf.h>, 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),
+10 -9
View File
@@ -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 <linux/types.h>
// clang-format on
#include <bpf/bpf_endian.h>
#include <bpf/bpf_helpers.h>
#include <linux/bpf.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
@@ -23,14 +28,10 @@
char __license[] section("license") = "Apache-2.0";
// Helper functions are defined positionally in <linux/bpf.h>, 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),