这是一个克隆存储库,我有https://github.com/vincentmli/XDPeriments/blob/master/Cookies/xdp_dns_cookies_kern.c,我试图静态初始化尾部调用程序数组Map,而不是运行用户空间eBPF加载器来填充程序数组Map,如https://github.com/vincentmli/XDPeriments/blob/master/Cookies/xdp_dns_cookies_user.c
下面是我修改的程序数组Map
https://github.com/vincentmli/XDPeriments/blob/master/Cookies/xdp_dns_cookies_kern.c#L659-L671
struct {
__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
__uint(max_entries, 3);
__uint(key_size, sizeof(uint32_t));
__uint(value_size, sizeof(uint64_t));
__array(values, int (void *));
} jmp_rate_table SEC(".maps") = {
.values = {
[DO_RATE_LIMIT_IPV6] = (void *)&xdp_do_rate_limit_ipv6,
[DO_RATE_LIMIT_IPV4] = (void *)&xdp_do_rate_limit_ipv4,
},
};
注意我必须使用gcc来编译xdp_dns_cookies_user
以加载程序https://github.com/NLnetLabs/XDPeriments/issues/6
root@vincent-pc2:/home/vincent/go/src/github.com/vincentmli/XDPeriments/Cookies# ./xdp_dns_cookies_user
libbpf: map 'jmp_rate_table': should be map-in-map.
ERROR: opening BPF object file failed
(null) successfully loaded and running on interface lo.
Press Ctrl-C to stop and unload.
^C
你可以看到libbpf指示jmp_rate_table
应该是map-in-map表,我初始化Map是错误的吗?
2条答案
按热度按时间kqlmhetl1#
结果我需要使用clang来编译https://github.com/vincentmli/XDPeriments/blob/master/Cookies/xdp_dns_cookies_user.c而不是gcc。答案在这里https://github.com/libbpf/libbpf/issues/690#issuecomment-1550548336
2ekbmq322#
尝试更改内核版本