diff options
author | Lennart Poettering <lennart@poettering.net> | 2024-03-01 17:31:06 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2024-04-06 16:08:23 +0200 |
commit | 0f716ace4106ca396a7b697e2fd3f74b98987110 (patch) | |
tree | d16ab4e205e186aedb64270421eee4693239250d | |
parent | namespace-util: add new helper is_our_namespace() (diff) | |
download | systemd-0f716ace4106ca396a7b697e2fd3f74b98987110.tar.xz systemd-0f716ace4106ca396a7b697e2fd3f74b98987110.zip |
bpf-dlopen: pick up more symbols from libbpf
-rw-r--r-- | src/shared/bpf-compat.h | 1 | ||||
-rw-r--r-- | src/shared/bpf-dlopen.c | 64 | ||||
-rw-r--r-- | src/shared/bpf-dlopen.h | 30 |
3 files changed, 69 insertions, 26 deletions
diff --git a/src/shared/bpf-compat.h b/src/shared/bpf-compat.h index 9ccb7d8205..5a7945cb9b 100644 --- a/src/shared/bpf-compat.h +++ b/src/shared/bpf-compat.h @@ -26,6 +26,7 @@ struct bpf_map_create_opts; * When removing this file move these back to bpf-dlopen.h */ extern int (*sym_bpf_map_create)(enum bpf_map_type, const char *, __u32, __u32, __u32, const struct bpf_map_create_opts *); extern int (*sym_libbpf_probe_bpf_prog_type)(enum bpf_prog_type, const void *); +extern struct bpf_map* (*sym_bpf_object__next_map)(const struct bpf_object *obj, const struct bpf_map *map); /* compat symbols removed in libbpf 1.0 */ extern int (*sym_bpf_create_map)(enum bpf_map_type, int key_size, int value_size, int max_entries, __u32 map_flags); diff --git a/src/shared/bpf-dlopen.c b/src/shared/bpf-dlopen.c index 6d59001b2c..de3e40516e 100644 --- a/src/shared/bpf-dlopen.c +++ b/src/shared/bpf-dlopen.c @@ -18,28 +18,41 @@ #define MODERN_LIBBPF 0 #endif -DLSYM_FUNCTION(bpf_program__attach_cgroup); -DLSYM_FUNCTION(bpf_program__attach_lsm); -DLSYM_FUNCTION(bpf_link__fd); DLSYM_FUNCTION(bpf_link__destroy); +DLSYM_FUNCTION(bpf_link__fd); +DLSYM_FUNCTION(bpf_link__open); +DLSYM_FUNCTION(bpf_link__pin); DLSYM_FUNCTION(bpf_map__fd); DLSYM_FUNCTION(bpf_map__name); +DLSYM_FUNCTION(bpf_map__set_inner_map_fd); DLSYM_FUNCTION(bpf_map__set_max_entries); -DLSYM_FUNCTION(bpf_map_update_elem); +DLSYM_FUNCTION(bpf_map__set_pin_path); DLSYM_FUNCTION(bpf_map_delete_elem); -DLSYM_FUNCTION(bpf_map__set_inner_map_fd); -DLSYM_FUNCTION(bpf_object__open_skeleton); -DLSYM_FUNCTION(bpf_object__load_skeleton); +DLSYM_FUNCTION(bpf_map_get_fd_by_id); +DLSYM_FUNCTION(bpf_map_lookup_elem); +DLSYM_FUNCTION(bpf_map_update_elem); DLSYM_FUNCTION(bpf_object__attach_skeleton); -DLSYM_FUNCTION(bpf_object__detach_skeleton); DLSYM_FUNCTION(bpf_object__destroy_skeleton); +DLSYM_FUNCTION(bpf_object__detach_skeleton); +DLSYM_FUNCTION(bpf_object__load_skeleton); +DLSYM_FUNCTION(bpf_object__name); +DLSYM_FUNCTION(bpf_object__open_skeleton); +DLSYM_FUNCTION(bpf_object__pin_maps); +DLSYM_FUNCTION(bpf_program__attach); +DLSYM_FUNCTION(bpf_program__attach_cgroup); +DLSYM_FUNCTION(bpf_program__attach_lsm); DLSYM_FUNCTION(bpf_program__name); -DLSYM_FUNCTION(libbpf_set_print); DLSYM_FUNCTION(libbpf_get_error); +DLSYM_FUNCTION(libbpf_set_print); +DLSYM_FUNCTION(ring_buffer__epoll_fd); +DLSYM_FUNCTION(ring_buffer__free); +DLSYM_FUNCTION(ring_buffer__new); +DLSYM_FUNCTION(ring_buffer__poll); /* new symbols available from libbpf 0.7.0 */ int (*sym_bpf_map_create)(enum bpf_map_type, const char *, __u32, __u32, __u32, const struct bpf_map_create_opts *); int (*sym_libbpf_probe_bpf_prog_type)(enum bpf_prog_type, const void *); +struct bpf_map* (*sym_bpf_object__next_map)(const struct bpf_object *obj, const struct bpf_map *map); /* compat symbols removed in libbpf 1.0 */ int (*sym_bpf_create_map)(enum bpf_map_type, int key_size, int value_size, int max_entries, __u32 map_flags); @@ -90,6 +103,8 @@ int dlopen_bpf(void) { DLSYM_ARG(bpf_probe_prog_type) #endif ); + + /* NB: we don't try to load bpf_object__next_map() on old versions */ } else { log_debug("Loaded 'libbpf.so.1' via dlopen()"); @@ -98,11 +113,13 @@ int dlopen_bpf(void) { dl, LOG_DEBUG, #if MODERN_LIBBPF DLSYM_ARG(bpf_map_create), - DLSYM_ARG(libbpf_probe_bpf_prog_type) + DLSYM_ARG(libbpf_probe_bpf_prog_type), + DLSYM_ARG(bpf_object__next_map) #else /* These symbols did not exist in old libbpf, hence we cannot type check them */ DLSYM_ARG_FORCE(bpf_map_create), - DLSYM_ARG_FORCE(libbpf_probe_bpf_prog_type) + DLSYM_ARG_FORCE(libbpf_probe_bpf_prog_type), + DLSYM_ARG_FORCE(bpf_object__next_map) #endif ); } @@ -113,28 +130,41 @@ int dlopen_bpf(void) { dl, LOG_DEBUG, DLSYM_ARG(bpf_link__destroy), DLSYM_ARG(bpf_link__fd), + DLSYM_ARG(bpf_link__open), + DLSYM_ARG(bpf_link__pin), DLSYM_ARG(bpf_map__fd), DLSYM_ARG(bpf_map__name), + DLSYM_ARG(bpf_map__set_inner_map_fd), DLSYM_ARG(bpf_map__set_max_entries), - DLSYM_ARG(bpf_map_update_elem), + DLSYM_ARG(bpf_map__set_pin_path), DLSYM_ARG(bpf_map_delete_elem), - DLSYM_ARG(bpf_map__set_inner_map_fd), - DLSYM_ARG(bpf_object__open_skeleton), - DLSYM_ARG(bpf_object__load_skeleton), + DLSYM_ARG(bpf_map_get_fd_by_id), + DLSYM_ARG(bpf_map_lookup_elem), + DLSYM_ARG(bpf_map_update_elem), DLSYM_ARG(bpf_object__attach_skeleton), - DLSYM_ARG(bpf_object__detach_skeleton), DLSYM_ARG(bpf_object__destroy_skeleton), + DLSYM_ARG(bpf_object__detach_skeleton), + DLSYM_ARG(bpf_object__load_skeleton), + DLSYM_ARG(bpf_object__name), + DLSYM_ARG(bpf_object__open_skeleton), + DLSYM_ARG(bpf_object__pin_maps), #if MODERN_LIBBPF + DLSYM_ARG(bpf_program__attach), DLSYM_ARG(bpf_program__attach_cgroup), DLSYM_ARG(bpf_program__attach_lsm), #else /* libbpf added a "const" to function parameters where it should not have, ignore this type incompatibility */ + DLSYM_ARG_FORCE(bpf_program__attach), DLSYM_ARG_FORCE(bpf_program__attach_cgroup), DLSYM_ARG_FORCE(bpf_program__attach_lsm), #endif DLSYM_ARG(bpf_program__name), + DLSYM_ARG(libbpf_get_error), DLSYM_ARG(libbpf_set_print), - DLSYM_ARG(libbpf_get_error)); + DLSYM_ARG(ring_buffer__epoll_fd), + DLSYM_ARG(ring_buffer__free), + DLSYM_ARG(ring_buffer__new), + DLSYM_ARG(ring_buffer__poll)); if (r < 0) return r; diff --git a/src/shared/bpf-dlopen.h b/src/shared/bpf-dlopen.h index 859405e3c6..6deca829f1 100644 --- a/src/shared/bpf-dlopen.h +++ b/src/shared/bpf-dlopen.h @@ -9,26 +9,38 @@ #include "bpf-compat.h" #include "dlfcn-util.h" -DLSYM_PROTOTYPE(bpf_program__attach_cgroup); -DLSYM_PROTOTYPE(bpf_program__attach_lsm); -DLSYM_PROTOTYPE(bpf_link__fd); DLSYM_PROTOTYPE(bpf_link__destroy); +DLSYM_PROTOTYPE(bpf_link__fd); +DLSYM_PROTOTYPE(bpf_link__open); +DLSYM_PROTOTYPE(bpf_link__pin); DLSYM_PROTOTYPE(bpf_map__fd); DLSYM_PROTOTYPE(bpf_map__name); +DLSYM_PROTOTYPE(bpf_map__set_inner_map_fd); DLSYM_PROTOTYPE(bpf_map__set_max_entries); -DLSYM_PROTOTYPE(bpf_map_update_elem); +DLSYM_PROTOTYPE(bpf_map__set_pin_path); DLSYM_PROTOTYPE(bpf_map_delete_elem); -DLSYM_PROTOTYPE(bpf_map__set_inner_map_fd); +DLSYM_PROTOTYPE(bpf_map_get_fd_by_id); +DLSYM_PROTOTYPE(bpf_map_lookup_elem); +DLSYM_PROTOTYPE(bpf_map_update_elem); /* The *_skeleton APIs are autogenerated by bpftool, the targets can be found * in ./build/src/core/bpf/socket_bind/socket-bind.skel.h */ -DLSYM_PROTOTYPE(bpf_object__open_skeleton); -DLSYM_PROTOTYPE(bpf_object__load_skeleton); DLSYM_PROTOTYPE(bpf_object__attach_skeleton); -DLSYM_PROTOTYPE(bpf_object__detach_skeleton); DLSYM_PROTOTYPE(bpf_object__destroy_skeleton); +DLSYM_PROTOTYPE(bpf_object__detach_skeleton); +DLSYM_PROTOTYPE(bpf_object__load_skeleton); +DLSYM_PROTOTYPE(bpf_object__name); +DLSYM_PROTOTYPE(bpf_object__open_skeleton); +DLSYM_PROTOTYPE(bpf_object__pin_maps); +DLSYM_PROTOTYPE(bpf_program__attach); +DLSYM_PROTOTYPE(bpf_program__attach_cgroup); +DLSYM_PROTOTYPE(bpf_program__attach_lsm); DLSYM_PROTOTYPE(bpf_program__name); -DLSYM_PROTOTYPE(libbpf_set_print); DLSYM_PROTOTYPE(libbpf_get_error); +DLSYM_PROTOTYPE(libbpf_set_print); +DLSYM_PROTOTYPE(ring_buffer__epoll_fd); +DLSYM_PROTOTYPE(ring_buffer__free); +DLSYM_PROTOTYPE(ring_buffer__new); +DLSYM_PROTOTYPE(ring_buffer__poll); #endif |