mirror of
https://github.com/xdp-project/bpf-examples.git
synced 2024-05-06 15:54:53 +00:00
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 <simon.sundberg@kau.se>
This commit is contained in:
@ -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",
|
||||
|
Reference in New Issue
Block a user