ebpf bpf_load_program

Posted dream397

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ebpf bpf_load_program相关的知识,希望对你有一定的参考价值。


size_t insns_cnt = sizeof(prog) / sizeof(struct bpf_insn);
prog_fd = bpf_load_program(BPF_PROG_TYPE_SOCKET_FILTER, prog, insns_cnt,
                   "GPL", 0, bpf_log_buf, BPF_LOG_BUF_SIZE);

int
bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns, size_t insns_cnt, const char *license, __u32 kern_version, char *log_buf, size_t log_buf_sz) { struct bpf_load_program_attr load_attr; memset(&load_attr, 0, sizeof(struct bpf_load_program_attr)); load_attr.prog_type = type; load_attr.expected_attach_type = 0; load_attr.name = NULL; load_attr.insns = insns; load_attr.insns_cnt = insns_cnt; load_attr.license = license; load_attr.kern_version = kern_version; return bpf_load_program_xattr(&load_attr, log_buf, log_buf_sz); }

 

int load_bpf_file(char *path)
{
        return do_load_bpf_file(path, NULL);
}

int load_bpf_file_fixup_map(const char *path, fixup_map_cb fixup_map)
{
            return do_load_bpf_file(path, fixup_map);
}
do_load_bpf_file
   ret = load_and_attach(shname, data->d_buf,data->d_size);
load_and_attach  parses prog section and maps prog
load_and_attach(const char *event, struct bpf_insn *prog, int size)
     load_elf_maps_section
         load_maps
             bpf_create_map_node
     fd = bpf_load_program(prog_type, prog, insns_cnt, license, kern_version, bpf_log_buf, BPF_LOG_BUF_SIZE);

 

以上是关于ebpf bpf_load_program的主要内容,如果未能解决你的问题,请参考以下文章

Linux eBPF和XDP高速处理数据包;使用EBPF编写XDP网络过滤器;高性能ACL

与使用空间共享 ebpf 函数参数或至少访问参数

ebpf sock sk_filter实现

XDP/eBPF — eBPF

XDP/eBPF — eBPF

微软发布新的开源项目,Windows上支持Linux工具eBPF