Subject: Re: [PATCH iproute2] libbpf: fix attach of prog with multiple sections

From: Hangbin Liu <[email-masked]>
Date: Fri, 23 Jul 2021 12:41:30 +0800

On Wed, Jul 21, 2021 at 04:47:14PM +0200, Martynas Pumputis wrote:
> > > diff --git a/lib/bpf_libbpf.c b/lib/bpf_libbpf.c
> > > index d05737a4..f76b90d2 100644
> > > --- a/lib/bpf_libbpf.c
> > > +++ b/lib/bpf_libbpf.c
> > > @@ -267,10 +267,12 @@ static int load_bpf_object(struct bpf_cfg_in *cfg)
> > >          }
> > > 
> > >          bpf_object__for_each_program(p, obj) {
> > > +               bool prog_to_attach = !prog && cfg->section &&
> > > +                       !strcmp(get_bpf_program__section_name(p), cfg->section);
> > 
> > This is still problematic, because one section can have multiple BPF
> > programs. I.e., it's possible two define two or more XDP BPF programs
> > all with SEC("xdp") and libbpf works just fine with that. I suggest
> > moving users to specify the program name (i.e., C function name
> > representing the BPF program). All the xdp_mycustom_suffix namings are
> > a hack and will be rejected by libbpf 1.0, so it would be great to get
> > a head start on fixing this early on.
> 
> Thanks for bringing this up. Currently, there is no way to specify a
> function name with "tc exec bpf" (only a section name via the "sec" arg). So
> probably, we should just add another arg to specify the function name.

How about add a "prog" arg to load specified program name and mark
"sec" as not recommended? To keep backwards compatibility we just load the
first program in the section.

Thanks
Hangbin