Skip to content

Commit

Permalink
libxdp: Allow falling back to single-program attachment for loaded pr…
Browse files Browse the repository at this point in the history
…ograms

When the libxdp compatibility checks for the dispatcher fails, we can fall
back to just attaching a single program. However, the
xdp_program__attach_single() function assumes that the program had not been
loaded into the kernel yet, which is not always the case. In the fallback
case there's not really any reason to not just try anyway, so just skip the
program load if we already have an fd and try a regular program attach.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
  • Loading branch information
tohojo committed Dec 9, 2022
1 parent dc69919 commit 3d7c22a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/libxdp/libxdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1319,10 +1319,15 @@ static int xdp_program__attach_single(struct xdp_program *prog, int ifindex,
{
int err;

bpf_program__set_type(prog->bpf_prog, BPF_PROG_TYPE_XDP);
err = xdp_program__load(prog);
if (err)
return err;
if (prog->bpf_obj) {
bpf_program__set_type(prog->bpf_prog, BPF_PROG_TYPE_XDP);
err = xdp_program__load(prog);
if (err)
return err;
}

if (prog->prog_fd < 0)
return -EINVAL;

return xdp_attach_fd(xdp_program__fd(prog), -1, ifindex, mode);
}
Expand Down

0 comments on commit 3d7c22a

Please sign in to comment.