在下面的代码中,BPF程序tail_prog不是从main_prog调用的尾
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
struct bpf_map_def SEC("maps") jump_table = {
.type = BPF_MAP_TYPE_PROG_ARRAY,
.key_size = sizeof(__u32),
.value_size = sizeof(__u32),
.max_entries = 8,
};
SEC("xdp")
int main_prog(struct xdp_md *ctx) {
bpf_printk("Making tail call");
bpf_tail_call(ctx, &jump_table, 0);
return XDP_PASS;
}
SEC("xdp_1")
int tail_prog(struct xdp_md *ctx) {
bpf_printk("Inside tail call");
return XDP_PASS;
}
char _license[] SEC("license") = "GPL";我只观察到main_prog中的打印是打印的。
我正在使用纤毛eBPF围棋包加载BPF程序。下面是加载程序和地图的代码:
type BpfObjects struct {
MainProg *ebpf.Program `ebpf:"main_prog"`
TailProg *ebpf.Program `ebpf:"tail_prog"`
JumpTable *ebpf.Map `ebpf:"jump_table"`
}
var objects BpfObjects
spec, err := ebpf.LoadCollectionSpec("prog.o")
if err != nil {
log.Fatalln("ebpf.LoadCollectionSpec", err)
}
if err := spec.LoadAndAssign(&objects, nil); err != nil {
log.Fatalln("ebpf.LoadAndAssign", err)
}
objects.JumpTable.Update(0, objects.TailProg.FD(), ebpf.UpdateAny)根据这,跳转表已经从用户空间初始化,这就是我认为上面最后一行应该做的。然而,我看不出这条线是否有任何区别。
发布于 2022-01-27 22:37:23
我没有查看Update函数:Update can't marshal key: encoding int: binary.Write: invalid type int返回的错误。因此,程序数组映射没有更新。我改做了以下几点:
err = objects.JumpTable.Update(uint32(0), uint32(objects.CopyHttpHostnameProg.FD()), ebpf.UpdateAny)
if err != nil {
println("Update", err.Error())
}如果将0作为键传递,则键的大小为8个字节,这就是为什么必须执行与映射定义匹配的uint32(0)。现在尾巴的叫声成功了。
https://stackoverflow.com/questions/70886166
复制相似问题