As far as I understand there can only be one AF-XDP kernel program per network interface. I want to distribute packet processing from multiple multicast-addresses from a single network interface to several processes. I have written a "loader"-program which creates the processes (works fine so far).
My problem now is to load the kernel program only once via load_bpf_and_xdp_attach
in the loader-program but to distribute access to the xsks-map to multiple processes.
load_bpf_and_xdp_attach
returns a pointer to a struct bpf_object*
. This pointer is then needed by bpf_object__find_map_by_name
to gain access to the bpf_map
file descriptor.
My idea was to write the content of bpf_object
into shared memory thus distributing it to the processes. But unfortunately, the struct bpf_object
is defined in libbpf.c
. Because of this I am not able to do this:
void insert_bpf_obj_into_shrd_mem(int shmid, struct bpf_object *bpf_obj) {
uint8_t *shm_data = shmat(shmid, NULL, 0);
if(shm_data == -1) {
fprintf(stderr, "Failed to obtain `shared memory` with id %d: %s\n", shmid, strerror(errno));
exit(1);
}
memcpy(shm_data, bpf_obj, sizeof(struct bpf_object));
shmdt(shm_data);
}
This to me looks like, libbpf
doesn't want anyone to know about bpf_object
.
Any ideas how I can accomplish my initial idea?
In case every process loads its own version of the kernel program, I end up with (amount of processes)
-xsks maps and I don't think this is sensible.
Edit: I know there is a way to reuse maps but...seems kind of intricate