Subject: Re: [PATCH bpf-next 0/9] xdp: Support multiple programs on a single interface through chain calls

From: Jesper Dangaard Brouer <[email-masked]>
Date: Thu, 3 Oct 2019 20:49:26 +0200

On Thu, 3 Oct 2019 15:53:50 +0100
Edward Cree <[email-masked]> wrote:

> On 03/10/2019 15:33, Toke Høiland-Jørgensen wrote:
> > In all cases, the sysadmin can't (or doesn't want to) modify any of the
> > XDP programs. In fact, they may just be installed as pre-compiled .so
> > BPF files on his system. So he needs to be able to configure the call
> > chain of different programs without modifying the eBPF program source
> > code.  
>
> Perhaps I'm being dumb, but can't we solve this if we make linking work?
> I.e. myIDS.so has ids_main() function, myFirewall.so has firewall()
>  function, and sysadmin writes a little XDP prog to call these:
> 
> int main(struct xdp_md *ctx)
> {
>         int rc = firewall(ctx), rc2;
> 
>         switch(rc) {
>         case XDP_DROP:
>         case XDP_ABORTED:
>         default:
>                 return rc;
>         case XDP_PASS:
>                 return ids_main(ctx);
>         case XDP_TX:
>         case XDP_REDIRECT:
>                 rc2 = ids_main(ctx);
>                 if (rc2 == XDP_PASS)
>                         return rc;
>                 return rc2;
>         }
> }
> 
> Now he compiles this and links it against those .so files, giving him
> a new object file which he can then install.

Sorry, but I don't think this makes sense. 

We are not dealing with .so (shared-object) files.  These are BPF
ELF-object files, which is not really ELF-objects in a normal sense.
The role of libbpf is to load the BPF elements in the ELF-file, via the
BPF-syscall.  First the maps are loaded (gets back a FD from
BPF-syscall), and then program sections are "opened" and ELF-relocation
is preformed replacing map accesses with map-FD's, before loading the
BPF byte-code via BPF-syscall.

Next issue is that the program loading the BPF-ELF object will get the
map FD's, which it expect and need to query and also populate with for
example its config.  Thus, you would need to pass the FD to the
original userspace application.

-- 
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  LinkedIn: http://www.linkedin.com/in/brouer