From 9168b47ccaef5093c2e752016c63f775c9367b4f Mon Sep 17 00:00:00 2001 From: Simon Sundberg Date: Mon, 29 Mar 2021 14:55:41 +0200 Subject: [PATCH] pping: Refactor init_rodata Refactor init_rodata to search for the first map with ".rodata" in its name. Should be more robust than previous solution which first tried to construct the name for the rodata map, and then find the map by name. Also remove some outcommented code that was not used. Signed-off-by: Simon Sundberg --- pping/pping.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/pping/pping.c b/pping/pping.c index 3d1b765..79e69a9 100644 --- a/pping/pping.c +++ b/pping/pping.c @@ -166,18 +166,14 @@ static int xdp_attach(struct bpf_object *obj, const char *sec, int ifindex, static int init_rodata(struct bpf_object *obj, void *src, size_t size) { - char map_name[16]; - struct bpf_map *rodata_map = NULL; + struct bpf_map *map = NULL; + bpf_object__for_each_map(map, obj) { + if (strstr(bpf_map__name(map), ".rodata")) + return bpf_map__set_initial_value(map, src, size); + } - strncpy(map_name, bpf_object__name(obj), 8); - map_name[8] = '\0'; // Ensure null-byte at truncation point - strcat(map_name, ".rodata"); - - rodata_map = bpf_object__find_map_by_name(obj, map_name); - if (!rodata_map || libbpf_get_error(rodata_map)) - return -EINVAL; - - return bpf_map__set_initial_value(rodata_map, src, size); + // No .rodata map found + return -EINVAL; } static int run_program(const char *path, char *const argv[]) @@ -461,13 +457,6 @@ int main(int argc, char *argv[]) goto cleanup; } - /* err = init_rodata(xdp_obj, &config, sizeof(config)); */ - /* if (err) { */ - /* fprintf(stderr, "Failed pushing user-configration to %s: %s\n", */ - /* PPING_XDP_OBJ, strerror(-err)); */ - /* goto cleanup; */ - /* } */ - err = bpf_object__load(xdp_obj); if (err) { fprintf(stderr, "Failed loading XDP program: %s\n",