]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
libbpf: Remove use of deprecated APIs
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 31 Aug 2022 09:59:52 +0000 (11:59 +0200)
committerDominique Martinet <asmadeus@codewreck.org>
Wed, 5 Oct 2022 22:31:23 +0000 (07:31 +0900)
src/core/bpf-lsm.c
src/core/bpf-socket-bind.c
src/core/bpf/restrict_fs/restrict-fs.bpf.c
src/core/bpf/socket_bind/socket-bind.bpf.c
src/core/restrict-ifaces.c
src/shared/bpf-dlopen.c
src/shared/bpf-dlopen.h

index f3b9339558269938096afb88bd9441493b90b117..33c9322e7ed86553a746b504fa2a753affb3fe6e 100644 (file)
@@ -65,14 +65,14 @@ static int prepare_restrict_fs_bpf(struct restrict_fs_bpf **ret_obj) {
                 return log_error_errno(errno, "bpf-lsm: Failed to open BPF object: %m");
 
         /* TODO Maybe choose a number based on runtime information? */
-        r = sym_bpf_map__resize(obj->maps.cgroup_hash, CGROUP_HASH_SIZE_MAX);
+        r = sym_bpf_map__set_max_entries(obj->maps.cgroup_hash, CGROUP_HASH_SIZE_MAX);
         assert(r <= 0);
         if (r < 0)
                 return log_error_errno(r, "bpf-lsm: Failed to resize BPF map '%s': %m",
                                        sym_bpf_map__name(obj->maps.cgroup_hash));
 
         /* Dummy map to satisfy the verifier */
-        inner_map_fd = sym_bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(uint32_t), sizeof(uint32_t), 128, 0);
+        inner_map_fd = sym_bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(uint32_t), sizeof(uint32_t), 128U, NULL);
         if (inner_map_fd < 0)
                 return log_error_errno(errno, "bpf-lsm: Failed to create BPF map: %m");
 
@@ -202,12 +202,13 @@ int lsm_bpf_unit_restrict_filesystems(Unit *u, const Set *filesystems, bool allo
                 return log_unit_error_errno(u, SYNTHETIC_ERRNO(EINVAL),
                                             "bpf-lsm: BPF LSM object is not installed, has setup failed?");
 
-        int inner_map_fd = sym_bpf_create_map(
+        int inner_map_fd = sym_bpf_map_create(
                         BPF_MAP_TYPE_HASH,
+                        NULL,
                         sizeof(uint32_t),
                         sizeof(uint32_t),
-                        128, /* Should be enough for all filesystem types */
-                        0);
+                        128U, /* Should be enough for all filesystem types */
+                        NULL);
         if (inner_map_fd < 0)
                 return log_unit_error_errno(u, errno, "bpf-lsm: Failed to create inner BPF map: %m");
 
index 30e5b2f3927f2076657a90b43d0a1231f436557b..790813bdbe45133973075817b9d55b088dcb8054 100644 (file)
@@ -79,11 +79,11 @@ static int prepare_socket_bind_bpf(
         if (!obj)
                 return log_unit_full_errno(u, u ? LOG_ERR : LOG_DEBUG, errno, "bpf-socket-bind: Failed to open BPF object: %m");
 
-        if (sym_bpf_map__resize(obj->maps.sd_bind_allow, MAX(allow_count, 1u)) != 0)
+        if (sym_bpf_map__set_max_entries(obj->maps.sd_bind_allow, MAX(allow_count, 1u)) != 0)
                 return log_unit_full_errno(u, u ? LOG_ERR : LOG_WARNING, errno,
                                            "bpf-socket-bind: Failed to resize BPF map '%s': %m", sym_bpf_map__name(obj->maps.sd_bind_allow));
 
-        if (sym_bpf_map__resize(obj->maps.sd_bind_deny, MAX(deny_count, 1u)) != 0)
+        if (sym_bpf_map__set_max_entries(obj->maps.sd_bind_deny, MAX(deny_count, 1u)) != 0)
                 return log_unit_full_errno(u, u ? LOG_ERR : LOG_WARNING, errno,
                                            "bpf-socket-bind: Failed to resize BPF map '%s': %m", sym_bpf_map__name(obj->maps.sd_bind_deny));
 
@@ -120,7 +120,7 @@ int bpf_socket_bind_supported(void) {
         if (!cgroup_bpf_supported())
                 return false;
 
-        if (!sym_bpf_probe_prog_type(BPF_PROG_TYPE_CGROUP_SOCK_ADDR, /*ifindex=*/0)) {
+        if (!sym_libbpf_probe_bpf_prog_type(BPF_PROG_TYPE_CGROUP_SOCK_ADDR, /*opts=*/NULL)) {
                 log_debug("bpf-socket-bind: BPF program type cgroup_sock_addr is not supported");
                 return false;
         }
index 99940bedfd8ca484af2063603ebf80fbafb8a88f..522a029785df52faf177c8ce8a4e23b37ad759a3 100644 (file)
@@ -28,7 +28,7 @@ struct file {
 } __attribute__((preserve_access_index));
 
 /*
- * max_entries is set from user space with the bpf_map__resize helper.
+ * max_entries is set from user space with the bpf_map__set_max_entries helper.
  * */
 struct {
         __uint(type, BPF_MAP_TYPE_HASH_OF_MAPS);
index 8004400e6ca1cfca4671d8ad8e6a020dcb870748..b7972a887a4c8948bc1e62512e952839bbd6a23a 100644 (file)
@@ -18,7 +18,7 @@
 #include <stdbool.h>
 
 /*
- * max_entries is set from user space with bpf_map__resize helper.
+ * max_entries is set from user space with bpf_map__set_max_entries helper.
  */
 struct socket_bind_map_t {
         __uint(type, BPF_MAP_TYPE_ARRAY);
index a0ecaff814b9a54dd80e7bbdb26e31f27c7e67db..c0daa38a03f62e110393f826e7face60078dcd92 100644 (file)
@@ -36,7 +36,7 @@ static int prepare_restrict_ifaces_bpf(
         if (!obj)
                 return log_unit_full_errno(u, u ? LOG_ERR : LOG_DEBUG, errno, "restrict-interfaces: Failed to open BPF object: %m");
 
-        r = sym_bpf_map__resize(obj->maps.sd_restrictif, MAX(set_size(restrict_network_interfaces), 1u));
+        r = sym_bpf_map__set_max_entries(obj->maps.sd_restrictif, MAX(set_size(restrict_network_interfaces), 1u));
         if (r != 0)
                 return log_unit_full_errno(u, u ? LOG_ERR : LOG_WARNING, r,
                                 "restrict-interfaces: Failed to resize BPF map '%s': %m",
@@ -83,7 +83,7 @@ int restrict_network_interfaces_supported(void) {
         if (!cgroup_bpf_supported())
                 return (supported = false);
 
-        if (!sym_bpf_probe_prog_type(BPF_PROG_TYPE_CGROUP_SKB, /*ifindex=*/0)) {
+        if (!sym_libbpf_probe_bpf_prog_type(BPF_PROG_TYPE_CGROUP_SKB, /*opts=*/NULL)) {
                 log_debug("restrict-interfaces: BPF program type cgroup_skb is not supported");
                 return (supported = false);
         }
index d8e778794c2ada375147e89f448476623a310fc0..07c237cc2f106408fcdbe398c4b81ed9d5fe8f42 100644 (file)
@@ -13,8 +13,8 @@ int (*sym_bpf_link__fd)(const struct bpf_link *);
 int (*sym_bpf_link__destroy)(struct bpf_link *);
 int (*sym_bpf_map__fd)(const struct bpf_map *);
 const char* (*sym_bpf_map__name)(const struct bpf_map *);
-int (*sym_bpf_create_map)(enum bpf_map_type,  int key_size, int value_size, int max_entries, __u32 map_flags);
-int (*sym_bpf_map__resize)(struct bpf_map *, __u32);
+int (*sym_bpf_map_create)(enum bpf_map_type,  const char *, __u32, __u32, __u32, const struct bpf_map_create_opts *);
+int (*sym_bpf_map__set_max_entries)(struct bpf_map *, __u32);
 int (*sym_bpf_map_update_elem)(int, const void *, const void *, __u64);
 int (*sym_bpf_map_delete_elem)(int, const void *);
 int (*sym_bpf_map__set_inner_map_fd)(struct bpf_map *, int);
@@ -23,7 +23,7 @@ int (*sym_bpf_object__load_skeleton)(struct bpf_object_skeleton *);
 int (*sym_bpf_object__attach_skeleton)(struct bpf_object_skeleton *);
 void (*sym_bpf_object__detach_skeleton)(struct bpf_object_skeleton *);
 void (*sym_bpf_object__destroy_skeleton)(struct bpf_object_skeleton *);
-bool (*sym_bpf_probe_prog_type)(enum bpf_prog_type, __u32);
+bool (*sym_libbpf_probe_bpf_prog_type)(enum bpf_prog_type, const void *);
 const char* (*sym_bpf_program__name)(const struct bpf_program *);
 libbpf_print_fn_t (*sym_libbpf_set_print)(libbpf_print_fn_t);
 long (*sym_libbpf_get_error)(const void *);
@@ -51,8 +51,8 @@ int dlopen_bpf(void) {
                         DLSYM_ARG(bpf_link__fd),
                         DLSYM_ARG(bpf_map__fd),
                         DLSYM_ARG(bpf_map__name),
-                        DLSYM_ARG(bpf_create_map),
-                        DLSYM_ARG(bpf_map__resize),
+                        DLSYM_ARG(bpf_map_create),
+                        DLSYM_ARG(bpf_map__set_max_entries),
                         DLSYM_ARG(bpf_map_update_elem),
                         DLSYM_ARG(bpf_map_delete_elem),
                         DLSYM_ARG(bpf_map__set_inner_map_fd),
@@ -61,10 +61,10 @@ int dlopen_bpf(void) {
                         DLSYM_ARG(bpf_object__attach_skeleton),
                         DLSYM_ARG(bpf_object__detach_skeleton),
                         DLSYM_ARG(bpf_object__destroy_skeleton),
-                        DLSYM_ARG(bpf_probe_prog_type),
                         DLSYM_ARG(bpf_program__attach_cgroup),
                         DLSYM_ARG(bpf_program__attach_lsm),
                         DLSYM_ARG(bpf_program__name),
+                        DLSYM_ARG(libbpf_probe_bpf_prog_type),
                         DLSYM_ARG(libbpf_set_print),
                         DLSYM_ARG(libbpf_get_error));
         if (r < 0)
index f0d40325d90a3b183cf3d15cc74bf24a516f30b3..16b23ef6c511bdcde73dbf0adf067f6fd9cddf14 100644 (file)
@@ -12,8 +12,8 @@ extern int (*sym_bpf_link__fd)(const struct bpf_link *);
 extern int (*sym_bpf_link__destroy)(struct bpf_link *);
 extern int (*sym_bpf_map__fd)(const struct bpf_map *);
 extern const char* (*sym_bpf_map__name)(const struct bpf_map *);
-extern int (*sym_bpf_create_map)(enum bpf_map_type, int key_size, int value_size, int max_entries, __u32 map_flags);
-extern int (*sym_bpf_map__resize)(struct bpf_map *, __u32);
+extern int (*sym_bpf_map_create)(enum bpf_map_type,  const char *, __u32, __u32, __u32, const struct bpf_map_create_opts *);
+extern int (*sym_bpf_map__set_max_entries)(struct bpf_map *, __u32);
 extern int (*sym_bpf_map_update_elem)(int, const void *, const void *, __u64);
 extern int (*sym_bpf_map_delete_elem)(int, const void *);
 extern int (*sym_bpf_map__set_inner_map_fd)(struct bpf_map *, int);
@@ -24,8 +24,8 @@ extern int (*sym_bpf_object__load_skeleton)(struct bpf_object_skeleton *);
 extern int (*sym_bpf_object__attach_skeleton)(struct bpf_object_skeleton *);
 extern void (*sym_bpf_object__detach_skeleton)(struct bpf_object_skeleton *);
 extern void (*sym_bpf_object__destroy_skeleton)(struct bpf_object_skeleton *);
-extern bool (*sym_bpf_probe_prog_type)(enum bpf_prog_type, __u32);
 extern const char* (*sym_bpf_program__name)(const struct bpf_program *);
+extern bool (*sym_libbpf_probe_bpf_prog_type)(enum bpf_prog_type, const void *);
 extern libbpf_print_fn_t (*sym_libbpf_set_print)(libbpf_print_fn_t);
 extern long (*sym_libbpf_get_error)(const void *);