Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about mixing gobpf/bcc XDP modules and XSK maps with cgo/C AF_XDP code #203

sevagh opened this issue Sep 5, 2019 · 1 comment


Copy link

commented Sep 5, 2019

I'm trying to use AF_XDP. I use gobpf/bcc to load a piece of C XDP kernel code that uses redirect_map to an xsk map. It's pretty much an adaptation of except using gobpf/bcc to load the kernel code, instead of C code.

In the example I'm trying to copy, they attach the XDP module in C:

struct bpf_map *map;

bpf_obj = load_bpf_and_xdp_attach(&cfg);
if (!bpf_obj) {
	/* Error handling done in load_bpf_and_xdp_attach() */
/* We also need to load the xsks_map */
map = bpf_object__find_map_by_name(bpf_obj, "xsks_map");
xsks_map_fd = bpf_map__fd(map);
if (xsks_map_fd < 0) {
	fprintf(stderr, "ERROR: no xsks map found: %s\n",

I replaced this part with Go, using gobpf/bcc:

buildArgs = []string{"-w"}
module := bcc.NewModule(source, buildArgs)
fn, _ := module.Load("my_xdp_prog", C.BPF_PROG_TYPE_XDP, 1, 131072)
module.AttachXDP("veth-xdp", fn)
xskTable := bcc.NewTable(module.TableID("my_xskmap", module)

iface, _ := net.InterfaceByName(device)
ifname_c := C.CString(iface.Name)
ifindex_c :=

C.set_up_af_xdp_sock(ifindex_c, ifname_c) //described below

Up until here, everything is good, my XDP kernel program is loaded and attached, and the xskTable is valid and I can use TableIter() etc. with it.

After that, I call out to my C function set_up_af_xdp_sock(int ifindex, char *ifname) to set up the UMEM, AF_XDP socket, etc. Those are copied from the tutorial above,

I get the error:

ERROR: Can't setup AF_XDP socket "No such file or directory"

I believe I've narrowed it down to the function xsk_socket__create, specifically the line, with a combination of gdb and strace (but I'm not 100% certain).

I don't get this same error when running the example C code as-is, and the only significant difference is that:

  1. I'm loading+attaching the XDP kernel program inside Go, and then calling a C function with cgo function to set up the AF_XDP socket
  2. They're loading+attaching the XDP kernel program and setting up the AF_XDP socket all in the same C code

Thanks in advance for taking a look.


This comment has been minimized.

Copy link

commented Sep 6, 2019

I believe it's related to maps vs. tables.

@sevagh sevagh closed this Sep 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
1 participant
You can’t perform that action at this time.