NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.43k stars 13.64k forks source link

iproute: attaching xdp program not working if built without libbpf #217468

Closed kaseiwang closed 2 months ago

kaseiwang commented 1 year ago

Describe the bug

iproute can not attach xdp programs without libbpf.

Steps To Reproduce

I writen a tiny xdp program (gist) to connect the cloudflare warp vpn with wireguard kernel module. When I tried to attach this xdp program , ip link reported an error.

reproduce (copy wgcf_bpf_helper.c from gist):

~/working/nixos-xdp/ok ❯ ls
shell.nix  wgcf_bpf_helper.c

~/working/nixos-xdp/err ❯ cat shell.nix
with import <nixpkgs> {};

mkShell {
  packages = [
    clang llvm llvmPackages.stdenv glibc_multi libbpf
    iproute
  ];
}

~/working/nixos-xdp/err ❯ clang -O2 -target bpf -c wgcf_bpf_helper.c -o wgcf_bpf
clang-11: warning: argument unused during compilation: '--gcc-toolchain=/nix/store/9pgq84sf921xh97gjj2wh7a7clrcrh4m-gcc-12.2.0' [-Wunused-command-line-argument]

~/working/nixos-xdp/err ❯ sudo ip link set dev wlo1 xdp object wgcf_bpf section wg-cf-xdp-ingress
ELF contains non-{map,call} related relo data in entry 0 pointing to section 8! Compiler bug?!
Error fetching program/map!

Expected behavior

If rebuild iproute with libbpf, it works:

~/working/nixos-xdp/ok ❯ cat shell.nix
with import <nixpkgs> {};

mkShell {
  packages = [
    clang llvm llvmPackages.stdenv glibc_multi libbpf
    (iproute.overrideDerivation (oldAttrs: {
      nativeBuildInputs = [ bison flex pkg-config libbpf ];
    }))
  ];
}

~/working/nixos-xdp/ok ❯ clang -O2 -target bpf -c wgcf_bpf_helper.c -o wgcf_bpf
clang-11: warning: argument unused during compilation: '--gcc-toolchain=/nix/store/9pgq84sf921xh97gjj2wh7a7clrcrh4m-gcc-12.2.0' [-Wunused-command-line-argument]

~/working/nixos-xdp/ok ❯ sudo ip link set dev wlo1 xdp object wgcf_bpf section wg-cf-xdp-ingress

Additional context

I am not sure if this is an upstream bug. The upstream code looks like it should works with or without libbpf.

FYI, archlinux and debian does build iproute with libbpf.

Notify maintainers

@primeos

Metadata

~ ❯ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.12-zen1, NixOS, 23.05 (Stoat), 23.05.20230218.5f4e07d`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.13.2`
 - channels(kasei): `"nixpkgs"`
 - nixpkgs: `/nix/store/z6hqic45nv80ymdbf6hx4xlh3s4s193i-source`
LostAttractor commented 2 months ago

Closed by #321962