[英]ebpf bpf_get_socket_uid error : invalid relo for insn[0].code 0x85
我在內核源代碼中構建了一個 ebpf 演示。 演示代碼如下:
cgroup_kern.c
#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
#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。 當我制作時,收到警告:
/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[0].code 0x85 的無效 relo
任何建議將不勝感激。
我猜你從相同的內核源 (4.15) 中檢索了bpf_helpers.h
。 不幸的是,該文件在 4.15 中缺少幾個幫助程序聲明。 這已在 5.1 中通過提交f2bb538
:
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
添加正確的定義來修復錯誤:
static unsigned int (*bpf_get_socket_uid)(void *ctx) =
(void *) BPF_FUNC_get_socket_uid;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.