C语言 如何静态初始化eBPF尾调用程序数组Map

ebdffaop  于 2023-05-22  发布在  其他
关注(0)|答案(2)|浏览(123)

这是一个克隆存储库,我有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是错误的吗?

kqlmhetl

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

2ekbmq32

2ekbmq322#

尝试更改内核版本

相关问题