Re: Using pinned maps within a network namespace

John McDowall <[email protected]>
Newsgroups org.kernel.vger.xdp-newbies
Message-ID <CAHQoOTaT+WzkJnGnursDidGYb7jSDusWNR+VOc=C6Pme=uLsbQ@mail.gmail.com>
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 <[email protected]> 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.