[英]BPF tail call not called
In the following code BPF program tail_prog
is not getting tail called from main_prog
:在以下代码中,BPF 程序
tail_prog
没有从main_prog
调用 tail:
#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";
I observe only the print in main_prog
is printed.我观察到只打印
main_prog
中的打印。
I'm loading the BPF programs using Cilium's eBPF Go package .我正在使用Cilium 的 eBPF Go package加载 BPF 程序。 Here's the code for loading the programs and maps:
这是加载程序和地图的代码:
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)
According to this , the jump table has be initialized from user space, which is what I think the last line above is supposed to do.据此,跳转表已从用户空间初始化,这是我认为上面的最后一行应该做的。 However, I don't see any difference whether that line is there or not.
但是,我看不出那条线是否存在有任何区别。
I wasn't looking at the error returned from the Update
function: Update can't marshal key: encoding int: binary.Write: invalid type int
.我没有查看
Update
function: Update can't marshal key: encoding int: binary.Write: invalid type int
返回的错误。 Therefore, the program array map was not updated.因此,程序数组 map 没有更新。 I changed to the following:
我更改为以下内容:
err = objects.JumpTable.Update(uint32(0), uint32(objects.CopyHttpHostnameProg.FD()), ebpf.UpdateAny)
if err != nil {
println("Update", err.Error())
}
If you pass 0
as the key, the size of the key is 8 bytes, which is why you have to do uint32(0)
, which matches the map's definition.如果您将
0
作为键传递,则键的大小为 8 个字节,这就是您必须执行uint32(0)
的原因,这与映射的定义相匹配。 Now the tail calls succeed.现在尾部调用成功了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.