Closed ErvinsK closed 4 years ago
Hey! )
Could you please provide some samples of the eBPF program / golang part? It is really hard to say why it is empty without code :)
Hi!
Sure - they are dumb simple:
package main
import (
"fmt"
"os"
"github.com/dropbox/goebpf"
)
func main() {
fmt.Println("XDP prog dump")
bpf := goebpf.NewDefaultEbpfSystem()
err := bpf.LoadElf("xdp-example.o")
if err != nil {
fatalError("LoadElf() failed: %v", err)
}
fmt.Println("\nPrograms:")
for _, prog := range bpf.GetPrograms() {
fmt.Printf("\t%s: %v, size %d, license \"%s\"\n",
prog.GetName(), prog.GetType(), prog.GetSize(), prog.GetLicense(),
)
}
}
#include <linux/bpf.h>
#define SEC(NAME) __attribute__((section(NAME), used))
SEC("prog")
int xdp_prog_simple(struct xdp_md *ctx)
{
return XDP_DROP;
}
char _license[] SEC("license") = "GPL";
That's simple! )
The problem is in SEC("prog")
- the library uses section name to distinguish between program types, it is a bit different than kernel examples.
So if you check examples you'll find that:
SEC("xdp")
int xdp_dump(struct xdp_md *ctx) {
// ...
}
https://github.com/dropbox/goebpf/blob/master/examples/xdp/xdp_dump/ebpf_prog/xdp_dump.c#L74
Simply rename section to xdp
and it will definitely work! )
Yep, it works! Thank you for a prompt resolution! I'm feeling a bit embarrassed for such a simple error but eBPF is tricky to master.
Loading elf files run smoothly without any errors but afterwards it returns empty maps and empty programs (with GetMaps() and GetPrograms()) :( However, eBPF/XDP programs run fine if loaded for example with ip tool. llvm-objdump also show all code and objects! Trying to understand what is the problem? Any help appreciated!