Re: libbpf and persistent maps

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 21 Aug 2018 15:55:20 -0400, Justin Azoff wrote:
> Hi!
> 
> I'm working on a library to try to encapsulate some of the things that
> Eric Leblond did for suricata so that arbitrary tools can drop flows
> inside bpf.
> 
> Is anyone else working with persistent maps and libbpf?
> 
> I started with the examples from the prototype-kernel repository and
> have updated some of the bits to use libbpf and bpf_prog_load instead
> of the (older?) code in bpf_load.c
> 
> I tried using bpf_prog_load+bpf_object__pin to make persistent maps,
> but noticed it is missing some functionality that is present in
> bpf_load.c
> 
> The load_maps function in bpf_load.c supports the fixup_map callback
> that it uses like so:
> 
>     for (i = 0; i < nr_maps; i++) {
>         if (fixup_map) {
>             fixup_map(&maps[i], i);
>             /* Allow userspace to assign map FD prior to creation */
>             if (maps[i].fd != -1) {
>                 map_fd[i] = maps[i].fd;
>                 continue;
>             }
>         }
> 
> This is used by pre_load_maps_via_fs in xdp_ddos01_blacklist_user.c
> 
> With libbpf there doesn't appear to be a way to skip creating maps
> when loading an object if a pinned version of that map already exists.
> You currently end up with duplicate maps.
> 
> I would like to add this functionality to libbpf.  I see two ways of doing this:
> 
> * Adding a callback param to bpf_prog_load_attr similar to bpf_load
> * Adding a char *persistent_path param to bpf_prog_load_attr
> 
> The persistent_path would be used inside bpf_object__create_maps in
> the same way that bpf_object__pin uses it so that a map can loaded if
> it already exists or otherwise created and (maybe?) automatically
> pinned in one operation.
> 
> If a 'persistent' flag could be added to bpf_map_def that could also
> be useful, but I'm not sure if that structure is something that can be
> easily changed.

Could bpf_map__reuse_fd() be of any help?  (Present in Linus's tree for
now, will be there in upcoming -rc1.)  You'll need to
bpf_object__open() and bpf_object__load() separately, and set the FDs
between the two.



[Index of Archives]     [Linux Networking Development]     [Fedora Linux Users]     [Linux SCTP]     [DCCP]     [Gimp]     [Yosemite Campsites]

  Powered by Linux