xdp-project / xdp-tutorial

XDP tutorial
2.33k stars 562 forks source link

Share bpf map between different XDP programs running on different interfaces #344

Open NirGeller18 opened 1 year ago

NirGeller18 commented 1 year ago

Hi there,

I need to share 1 bpf map between 2 different XDP programs loaded on 2 different interfaces. I understand how a map can be shared with a userspace program, but how can one XDP program gain access to a map that was created previously by a different XDP program?

I need to invoke bpf_map_lookup_elem() in the context of one program and get data that was updated by another. Can this be done? is there a working example?

Thanks a lot,

Nir.

tohojo commented 1 year ago

Just create both XDP programs in the same source file, that way they can share the reference to the map. Note that you'll have to do any needed cross-CPU synchronisation yourself, either using atomics or locking (depending on what you're using the map for).