1

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

Qeole
  • 8,284
  • 1
  • 24
  • 52
binaryBigInt
  • 1,526
  • 2
  • 18
  • 44
  • 1
    The internals of `struct bpf_object` are intentionally kept hidden to the application calling libbpf indeed. Reusing maps sound like the good approach here, I gave a few pointers [here](https://stackoverflow.com/a/60227624/3716552). – Qeole Mar 05 '20 at 09:21
  • @Qeole I just noticed that it doesn't matter whether I load the map! I just do `load_bpf_and_xdp_attach(cfg);` in the distributor and don't load anything in the user-programs processes. I don't understand how this works but somehow the sockets now where to find the xsks-map? – binaryBigInt Mar 05 '20 at 10:10
  • Linking to [the answer on the multi-process setup](https://stackoverflow.com/a/60658171/3716552) – Qeole Mar 12 '20 at 16:28

0 Answers0