Re: Using pinned maps within a network namespace

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

 



Quentin,

You're right, my code is a little messy but it does what you
suggested, as I mentioned to Song it works on the host system just not
in the network namespace. The error from bpf_obj_pin is

errno: No such file or directory

Here is a larger code segment:

  pin_fd = bpf_create_map(BPF_MAP_TYPE_ARRAY,
                     sizeof(uint32_t), sizeof(config_data),1, 0);
        if (pin_fd < 0){
            jed_error(jed_logfile,"Failed to create map ", CONFIG_MAP_PATH);
        }

        ret = bpf_obj_pin(pin_fd,CONFIG_MAP_PATH);
        if (ret < 0) {
            jed_info(jed_logfile,"Access to %s map failed obj_pin ",
CONFIG_MAP_PATH);
            pin_fd = bpf_obj_get(CONFIG_MAP_PATH);
            if (pin_fd < 0){
             jed_error(jed_logfile,"Access to %s map failed with
obj_get ", CONFIG_MAP_PATH);
            }
        }

        key = 0;
        ret = bpf_map_update_elem(pin_fd, &key, &config_data, 0);
        if (ret < 0) {
           jed_error(jed_logfile,"bpf_map_update_elem %s ",CONFIG_MAP_PATH);
        }

Thanks for your help

Regards

John

On Wed, Sep 16, 2020 at 2:22 AM Quentin Monnet <quentin@xxxxxxxxxxxxx> wrote:
>
> On 15/09/2020 18:00, John McDowall wrote:
> > Hi everyone,
> >
> > This may be a dumb question, I have set up a simple test environment
> > with multiple network namespaces running on a ubuntu 20.04 vagrant
> > box, with the latest github libbpf.
> >
> > I want to use a pinned map, I can make /sys/fs/bpf shared by:
> >
> > $ mount mount --make-shared /sys/fs/bpf
> > $ mount --bind /sys/fs/bpf /sys/fs/bpf
> >
> > but when I try access the maps from a C program running in a namespace
> > using bpf I get
> >
> >  Access to /sys/fs/bpf/lwtconfig map failed obj_pin errno: No such
> > file or directory
> >
> > The code snippet is:
> >
> > mapfd = bpf_obj_pin(pin_fd,CONFIG_MAP_PATH);
> >         if (mapfd < 0) {
> >             jed_info(jed_logfile,"Access to %s map failed obj_pin ",
> > CONFIG_MAP_PATH);
>
> Hi, from your log message ("obj_pin") it looks like the error occurs
> when you try to pin the map, not when you try to access it. The way you
> try to pin it:
>
>         mapfd = bpf_obj_pin(pin_fd,CONFIG_MAP_PATH);
>
> looks suspicious. If I remember correctly, bpf_obj_pin() returns 0 on
> success, it does not return a fd. It does use a file descriptor to the
> map as a first argument, can you double check that this is what "pin_fd"
> contains? How did you retrieve this fd? It looks to me like "pin_fd"
> does not point to an existing map, and that the kernel fails to find the
> map to pin.
>
> Good luck,
> Quentin



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

  Powered by Linux