首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ebpf bpf_get_socket_uid错误: insn[0].code 0x85的relo无效

ebpf bpf_get_socket_uid错误: insn[0].code 0x85的relo无效
EN

Stack Overflow用户
提问于 2020-10-31 22:13:09
回答 1查看 120关注 0票数 1

我在内核源代码中构建了一个ebpf演示。演示代码如下:

cgroup_kern.c

代码语言:javascript
复制
#include <uapi/linux/bpf.h>
#include <uapi/linux/if_ether.h>
#include <uapi/linux/if_packet.h>
#include <uapi/linux/ip.h>
#include "bpf_helpers.h"

#include <bpf_helpers.h>
#include <linux/bpf.h>


struct bpf_map_def SEC("maps") my_map = {
        .type = BPF_MAP_TYPE_ARRAY,
        .key_size = sizeof(u32),
        .value_size = sizeof(long),
        .max_entries = 256,
};

SEC("cgroupskb/ingress/stats")
int bpf_cgroup_ingress(struct __sk_buff* skb) {
        uint32_t sock_uid = bpf_get_socket_uid(skb);
        return 0;
}

cgroup_user.c

代码语言:javascript
复制
#include <stdio.h>
#include <assert.h>
#include <linux/bpf.h>
#include "libbpf.h"
#include "bpf_load.h"
#include "sock_example.h"
#include <unistd.h>
#include <arpa/inet.h>

int main(int ac, char **argv)
{
        char filename[256];
        FILE *f;
        int i, sock;

        snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);

        if (load_bpf_file(filename)) {
                printf("%s", bpf_log_buf);
                return 1;
        }
        return 0;
}

然后,我为我的cgroup ebpf演示添加了一些Makefile。当我做的时候,得到了一个警告:

代码语言:javascript
复制
/usr/src/linux-source-4.15.0/linux-source-4.15.0/samples/bpf/cgroup_kern.c:20:22: warning: implicit declaration of function 'bpf_get_socket_uid' is invalid in C99 [-Wimplicit-function-declaration]
        uint32_t sock_uid = bpf_get_socket_uid(skb);

当我想要附加我的ebpf演示:无效的insn.code 0x85的relo

任何建议都将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2020-11-01 01:07:05

我猜你是从相同的内核源代码(4.15)中检索到bpf_helpers.h的。不幸的是,在4.15中,该文件缺少几个助手声明。此问题已在5.1版本的commit f2bb538中修复

代码语言:javascript
复制
commit f2bb53887eb3e8f859ac7cfc09d1a3801492c009
Author: Willem de Bruijn <willemb@google.com>
Date:   Wed Feb 27 11:08:06 2019 -0500

    bpf: add missing entries to bpf_helpers.h
    
    This header defines the BPF functions enumerated in uapi/linux.bpf.h
    in a callable format. Expand to include all registered functions.
    
    Signed-off-by: Willem de Bruijn <willemb@google.com>
    Acked-by: Song Liu <songliubraving@fb.com>
    Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>

您应该能够简单地通过向bpf_helpers.h添加适当的定义来修复错误

代码语言:javascript
复制
static unsigned int (*bpf_get_socket_uid)(void *ctx) =
    (void *) BPF_FUNC_get_socket_uid;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64622620

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档