libbpf: Expose bpf_core_{add,free}_cands() to bpftool
authorMauricio Vásquez <mauricio@kinvolk.io>
Tue, 15 Feb 2022 22:58:51 +0000 (17:58 -0500)
committerAndrii Nakryiko <andrii@kernel.org>
Wed, 16 Feb 2022 18:05:45 +0000 (10:05 -0800)
Expose bpf_core_add_cands() and bpf_core_free_cands() to handle
candidates list.

Signed-off-by: Mauricio Vásquez <mauricio@kinvolk.io>
Signed-off-by: Rafael David Tinoco <rafael.tinoco@aquasec.com>
Signed-off-by: Lorenzo Fontana <lorenzo.fontana@elastic.co>
Signed-off-by: Leonardo Di Donato <leonardo.didonato@elastic.co>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20220215225856.671072-3-mauricio@kinvolk.io
tools/lib/bpf/libbpf.c
tools/lib/bpf/libbpf_internal.h

index d3c457fb045e1dd8c24164bb0ede4626121552d3..ad43b6ce825e652ca3b48033db30ae2a3e864086 100644 (file)
@@ -5192,18 +5192,21 @@ size_t bpf_core_essential_name_len(const char *name)
        return n;
 }
 
-static void bpf_core_free_cands(struct bpf_core_cand_list *cands)
+void bpf_core_free_cands(struct bpf_core_cand_list *cands)
 {
+       if (!cands)
+               return;
+
        free(cands->cands);
        free(cands);
 }
 
-static int bpf_core_add_cands(struct bpf_core_cand *local_cand,
-                             size_t local_essent_len,
-                             const struct btf *targ_btf,
-                             const char *targ_btf_name,
-                             int targ_start_id,
-                             struct bpf_core_cand_list *cands)
+int bpf_core_add_cands(struct bpf_core_cand *local_cand,
+                      size_t local_essent_len,
+                      const struct btf *targ_btf,
+                      const char *targ_btf_name,
+                      int targ_start_id,
+                      struct bpf_core_cand_list *cands)
 {
        struct bpf_core_cand *new_cands, *cand;
        const struct btf_type *t, *local_t;
index bc86b82e90d1c3a589e2d62c8a947579ea86687e..4fda8bdf0a0dcb434702299f4fed45e98fa97230 100644 (file)
@@ -529,4 +529,13 @@ static inline int ensure_good_fd(int fd)
        return fd;
 }
 
+/* The following two functions are exposed to bpftool */
+int bpf_core_add_cands(struct bpf_core_cand *local_cand,
+                      size_t local_essent_len,
+                      const struct btf *targ_btf,
+                      const char *targ_btf_name,
+                      int targ_start_id,
+                      struct bpf_core_cand_list *cands);
+void bpf_core_free_cands(struct bpf_core_cand_list *cands);
+
 #endif /* __LIBBPF_LIBBPF_INTERNAL_H */