diff options
author | David Ahern <dsahern@kernel.org> | 2022-03-07 08:52:21 -0700 |
---|---|---|
committer | David Ahern <dsahern@kernel.org> | 2022-03-07 08:52:21 -0700 |
commit | 76fa0e4610e8d58dfd2ff618fc95631b10fbea1e (patch) | |
tree | fa551bc8fc6892f61d5f311602c96a4e6bf40fec | |
parent | 5e17b715295f76709f4088ae5374ae1cadcc2029 (diff) | |
parent | d9977eafa719c029fba8c14de5b46dc1c851c68f (diff) | |
download | iproute2-76fa0e4610e8d58dfd2ff618fc95631b10fbea1e.tar.gz |
Merge branch 'libbpf-fixups' into next
Signed-off-by: David Ahern <dsahern@kernel.org>
-rw-r--r-- | include/bpf_util.h | 2 | ||||
-rw-r--r-- | lib/bpf_glue.c | 15 | ||||
-rw-r--r-- | lib/bpf_legacy.c | 19 | ||||
-rw-r--r-- | lib/bpf_libbpf.c | 24 |
4 files changed, 29 insertions, 31 deletions
diff --git a/include/bpf_util.h b/include/bpf_util.h index 53acc4106..abb962755 100644 --- a/include/bpf_util.h +++ b/include/bpf_util.h @@ -287,6 +287,8 @@ int bpf_program_attach(int prog_fd, int target_fd, enum bpf_attach_type type); int bpf_dump_prog_info(FILE *f, uint32_t id); +int bpf(int cmd, union bpf_attr *attr, unsigned int size); + #ifdef HAVE_ELF int bpf_send_map_fds(const char *path, const char *obj); int bpf_recv_map_fds(const char *path, int *fds, struct bpf_map_aux *aux, diff --git a/lib/bpf_glue.c b/lib/bpf_glue.c index 70d001840..c1cf351b7 100644 --- a/lib/bpf_glue.c +++ b/lib/bpf_glue.c @@ -4,22 +4,23 @@ * Authors: Hangbin Liu <haliu@redhat.com> * */ +#include <sys/syscall.h> #include <limits.h> +#include <unistd.h> #include "bpf_util.h" #ifdef HAVE_LIBBPF #include <bpf/bpf.h> #endif -int bpf_program_load(enum bpf_prog_type type, const struct bpf_insn *insns, - size_t size_insns, const char *license, char *log, - size_t size_log) +int bpf(int cmd, union bpf_attr *attr, unsigned int size) { -#ifdef HAVE_LIBBPF - return bpf_load_program(type, insns, size_insns / sizeof(struct bpf_insn), - license, 0, log, size_log); +#ifdef __NR_bpf + return syscall(__NR_bpf, cmd, attr, size); #else - return bpf_prog_load_dev(type, insns, size_insns, license, 0, log, size_log); + fprintf(stderr, "No bpf syscall, kernel headers too old?\n"); + errno = ENOSYS; + return -1; #endif } diff --git a/lib/bpf_legacy.c b/lib/bpf_legacy.c index 6e3891c9f..9bf7c1c49 100644 --- a/lib/bpf_legacy.c +++ b/lib/bpf_legacy.c @@ -33,7 +33,6 @@ #include <sys/un.h> #include <sys/vfs.h> #include <sys/mount.h> -#include <sys/syscall.h> #include <sys/sendfile.h> #include <sys/resource.h> @@ -134,17 +133,6 @@ static inline __u64 bpf_ptr_to_u64(const void *ptr) return (__u64)(unsigned long)ptr; } -static int bpf(int cmd, union bpf_attr *attr, unsigned int size) -{ -#ifdef __NR_bpf - return syscall(__NR_bpf, cmd, attr, size); -#else - fprintf(stderr, "No bpf syscall, kernel headers too old?\n"); - errno = ENOSYS; - return -1; -#endif -} - static int bpf_map_update(int fd, const void *key, const void *value, uint64_t flags) { @@ -1126,6 +1114,13 @@ int bpf_prog_load_dev(enum bpf_prog_type type, const struct bpf_insn *insns, return bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); } +int bpf_program_load(enum bpf_prog_type type, const struct bpf_insn *insns, + size_t size_insns, const char *license, char *log, + size_t size_log) +{ + return bpf_prog_load_dev(type, insns, size_insns, license, 0, log, size_log); +} + #ifdef HAVE_ELF struct bpf_elf_prog { enum bpf_prog_type type; diff --git a/lib/bpf_libbpf.c b/lib/bpf_libbpf.c index 921716aec..f4f98caa1 100644 --- a/lib/bpf_libbpf.c +++ b/lib/bpf_libbpf.c @@ -54,18 +54,18 @@ static const char *get_bpf_program__section_name(const struct bpf_program *prog) static int create_map(const char *name, struct bpf_elf_map *map, __u32 ifindex, int inner_fd) { - struct bpf_create_map_attr map_attr = {}; - - map_attr.name = name; - map_attr.map_type = map->type; - map_attr.map_flags = map->flags; - map_attr.key_size = map->size_key; - map_attr.value_size = map->size_value; - map_attr.max_entries = map->max_elem; - map_attr.map_ifindex = ifindex; - map_attr.inner_map_fd = inner_fd; - - return bpf_create_map_xattr(&map_attr); + union bpf_attr attr = {}; + + attr.map_type = map->type; + strlcpy(attr.map_name, name, sizeof(attr.map_name)); + attr.map_flags = map->flags; + attr.key_size = map->size_key; + attr.value_size = map->size_value; + attr.max_entries = map->max_elem; + attr.map_ifindex = ifindex; + attr.inner_map_fd = inner_fd; + + return bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); } static int create_map_in_map(struct bpf_object *obj, struct bpf_map *map, |