EBPF function file descriptors are different #554
-
I am reading an EBPF ELF file and noticed that function file descriptors are different. When reading the same ELF file and function in C, using int fd;
bpf_prog = bpf_object__find_program_by_title(bpf_obj, "xdp_abort");
fd = bpf_program__fd(bpf_prog);
printf("<=xdp_abort=>%d\n", fd);
bpf_prog = bpf_object__find_program_by_title(bpf_obj, "xdp_pass");
fd = bpf_program__fd(bpf_prog);
printf("<=xdp_pass=>%d\n", fd);
bpf_prog = bpf_object__find_program_by_title(bpf_obj, "xdp_drop");
fd = bpf_program__fd(bpf_prog);
printf("<=xdp_drop=>%d\n", fd); Output:
Whereas in GO: func readELFByCilium() error {
if err := rlimit.RemoveMemlock(); err != nil {
log.Fatal(err)
}
raw, _ := ioutil.ReadFile(file)
reader := bytes.NewReader(raw)
spec, err := ebpf.LoadCollectionSpecFromReader(reader)
if err != nil {
return fmt.Errorf("can't load xdp: %w", err)
}
xdpObj := xdpObjects{}
if err := spec.LoadAndAssign(&xdpObj, nil); err != nil {
return err
}
defer xdpObj.xdpPrograms.Close()
defer xdpObj.xdpMaps.Close()
log.Println("XdpAbortFunc=", xdpObj.XdpAbortFunc.FD())
log.Println("XdpDropFunc=", xdpObj.XdpDropFunc.FD())
log.Println("XdpPassFunc=", xdpObj.XdpPassFunc.FD())
return nil
} Output:
The ELF file looks like this:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Yes, they are different. Why do you expect |
Beta Was this translation helpful? Give feedback.
-
Thanks for the help. I figured out my actual root cause. I was first loading link, _ := netlink.LinkByName("veth-basic02")
err = netlink.LinkSetXdpFdWithFlags(link, xdpObj.XdpDropFunc.FD(), 2)
if err != nil {
panic(err)
}
err = netlink.LinkSetXdpFdWithFlags(link, xdpObj.XdpPassFunc.FD(), 2)
if err != nil {
panic(err)
} |
Beta Was this translation helpful? Give feedback.
Yes, they are different. Why do you expect
cilium/ebpf
to matchlibbpf
in this regard?