diff options
Diffstat (limited to 'bpf/bpf_obj.cpp')
| -rw-r--r-- | bpf/bpf_obj.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/bpf/bpf_obj.cpp b/bpf/bpf_obj.cpp index dde48cd..3aeff20 100644 --- a/bpf/bpf_obj.cpp +++ b/bpf/bpf_obj.cpp @@ -55,11 +55,42 @@ struct bpf_obj_ctx *bpf_obj_load(const char *obj_file, uint32_t queue_num, uint3 bpf_config_set_hash_mode(&ctx->config, hash_mode); bpf_config_set_debug_log(&ctx->config, debug_log); +#if (LIBBPF_MAJOR_VERSION > 0 || (LIBBPF_MAJOR_VERSION == 0 && LIBBPF_MINOR_VERSION >= 7)) + struct bpf_program *prog; + ctx->prog_obj = bpf_object__open_file(ctx->obj_file, NULL); + if (ctx->prog_obj == NULL) + { + printf("ERROR: Unable to open bpf object %s, %s.\n", ctx->obj_file, strerror(errno)); + goto error; + } + + prog = bpf_object__find_program_by_name(ctx->prog_obj, "bpf_tun_rss_steering"); + if (!prog) + { + printf("ERROR: Unable to get bpf program from object %s, %s.\n", ctx->obj_file, strerror(errno)); + goto error; + } + + bpf_program__set_type(prog, BPF_PROG_TYPE_SOCKET_FILTER); + if (bpf_object__load(ctx->prog_obj)) + { + printf("ERROR: Unable to load bpf object %s, %s.\n", ctx->obj_file, strerror(errno)); + goto error; + } + + ctx->prog_fd = bpf_program__fd(prog); + if (ctx->prog_fd < 0) + { + printf("ERROR: Unable to get bpf program fd from object %s, %s.\n", ctx->obj_file, strerror(errno)); + goto error; + } +#else if (bpf_prog_load(ctx->obj_file, BPF_PROG_TYPE_SOCKET_FILTER, &ctx->prog_obj, &ctx->prog_fd) < 0) { printf("ERROR: Unable to load bpf object %s, %s.\n", ctx->obj_file, strerror(errno)); goto error; } +#endif if (bpf_config_update_map(&ctx->config, ctx->prog_obj) == -1) { |
