diff --git a/libbpf b/libbpf index f0bcba6..a032540 160000 --- a/libbpf +++ b/libbpf @@ -1 +1 @@ -Subproject commit f0bcba631dec4540fc6ab2cd0a0923a111cf4cf2 +Subproject commit a0325403afa8a3eca0d3a3e43f43784dc6b47511 diff --git a/src/tc_classify_kern.c b/src/tc_classify_kern.c index 9b88bf9..5162256 100644 --- a/src/tc_classify_kern.c +++ b/src/tc_classify_kern.c @@ -271,7 +271,7 @@ bool special_minor_classid(struct __sk_buff *skb, /* Quick manual reload command: tc filter replace dev ixgbe2 prio 0xC000 handle 1 egress bpf da obj tc_classify_kern.o sec tc_classify */ -SEC("tc_classify") +SEC("tc") int tc_cls_prog(struct __sk_buff *skb) { __u32 cpu = bpf_get_smp_processor_id(); diff --git a/src/tc_queue_mapping_kern.c b/src/tc_queue_mapping_kern.c index d80ea91..349f142 100644 --- a/src/tc_queue_mapping_kern.c +++ b/src/tc_queue_mapping_kern.c @@ -31,10 +31,7 @@ #define TC_H_MAJOR(x) TC_H_MAJ(x) #define TC_H_MINOR(x) TC_H_MIN(x) -/* Quick replace/reload command: - * tc filter replace dev ixgbe2 egress prio 0xC000 handle 1 bpf da obj tc_queue_mapping_kern.o sec tc_qmap2cpu - */ -SEC("tc_qmap2cpu") +SEC("tc") int tc_cls_prog(struct __sk_buff *skb) { __u32 cpu = bpf_get_smp_processor_id(); @@ -96,7 +93,7 @@ int tc_cls_prog(struct __sk_buff *skb) #define barrier() __asm__ __volatile__("": : :"memory") -SEC("tc_test_invalid_value") +SEC("tc") int tc_cls_prog_test(struct __sk_buff *skb) { /* Kernel should not allow this to take effect */ diff --git a/src/xdp_iphash_to_cpu_kern.c b/src/xdp_iphash_to_cpu_kern.c index 7a9090d..30fb4df 100644 --- a/src/xdp_iphash_to_cpu_kern.c +++ b/src/xdp_iphash_to_cpu_kern.c @@ -218,7 +218,7 @@ __u32 handle_eth_protocol(struct xdp_md *ctx, __u16 eth_proto, __u32 l3_offset, return XDP_PASS; } -SEC("xdp_prog") +SEC("xdp") int xdp_program(struct xdp_md *ctx) { void *data_end = (void *)(long)ctx->data_end; @@ -242,4 +242,3 @@ int xdp_program(struct xdp_md *ctx) } char _license[] SEC("license") = "GPL"; - diff --git a/src/xdp_iphash_to_cpu_user.c b/src/xdp_iphash_to_cpu_user.c index c0ff462..f5fde4a 100644 --- a/src/xdp_iphash_to_cpu_user.c +++ b/src/xdp_iphash_to_cpu_user.c @@ -227,7 +227,7 @@ static void remove_xdp_program(int ifindex, const char *ifname, __u32 xdp_flags) ifindex, ifname); } if (ifindex > -1) { - bpf_set_link_xdp_fd(ifindex, -1, xdp_flags); + bpf_xdp_attach(ifindex, -1, xdp_flags, NULL); if (bpf_map_update_elem(ifindex_type_map_fd, &ifindex, &dir, 0) < 0) { fprintf(stderr, "ERR: Clear ifindex type failed \n"); @@ -268,13 +268,7 @@ static inline bool IS_ERR_OR_NULL(const void *ptr) int bpf_prog_load_xattr_maps(const struct bpf_prog_load_attr_maps *attr, struct bpf_object **pobj, int *prog_fd) { - struct bpf_object_open_attr open_attr = { - .file = attr->file, - .prog_type = attr->prog_type, - }; struct bpf_program *prog, *first_prog = NULL; - enum bpf_attach_type expected_attach_type; - enum bpf_prog_type prog_type; struct bpf_object *obj; struct bpf_map *map; int err; @@ -286,50 +280,24 @@ int bpf_prog_load_xattr_maps(const struct bpf_prog_load_attr_maps *attr, return -EINVAL; - obj = bpf_object__open_xattr(&open_attr); + obj = bpf_object__open_file(attr->file, NULL); if (IS_ERR_OR_NULL(obj)) return -ENOENT; bpf_object__for_each_program(prog, obj) { - /* - * If type is not specified, try to guess it based on - * section name. - */ - prog_type = attr->prog_type; -#if 0 /* Use internal libbpf variables */ - prog->prog_ifindex = attr->ifindex; -#endif - expected_attach_type = attr->expected_attach_type; -#if 0 /* Use internal libbpf variables */ - if (prog_type == BPF_PROG_TYPE_UNSPEC) { - err = bpf_program__identify_section(prog, &prog_type, - &expected_attach_type); - if (err < 0) { - bpf_object__close(obj); - return -EINVAL; - } - } -#endif - - bpf_program__set_type(prog, prog_type); - bpf_program__set_expected_attach_type(prog, - expected_attach_type); - - if (!first_prog) + if (!first_prog) { first_prog = prog; + break; + } } /* Reset attr->pinned_maps.map_fd to identify successful file load */ for (i = 0; i < attr->nr_pinned_maps; i++) attr->pinned_maps[i].map_fd = -1; - bpf_map__for_each(map, obj) { + bpf_object__for_each_map(map, obj) { const char* mapname = bpf_map__name(map); -#if 0 /* Use internal libbpf variables */ - if (!bpf_map__is_offload_neutral(map)) - map->map_ifindex = attr->ifindex; -#endif for (i = 0; i < attr->nr_pinned_maps; i++) { struct bpf_pinned_map *pin_map = &attr->pinned_maps[i]; int fd; @@ -369,7 +337,7 @@ int bpf_prog_load_xattr_maps(const struct bpf_prog_load_attr_maps *attr, } /* Pin the maps that were not loaded via pinned filename */ - bpf_map__for_each(map, obj) { + bpf_object__for_each_map(map, obj) { const char* mapname = bpf_map__name(map); for (i = 0; i < attr->nr_pinned_maps; i++) { @@ -618,7 +586,7 @@ int main(int argc, char **argv) fprintf(stderr, "ERR: create ifindex direction type failed \n"); return (EXIT_FAIL_BPF); } - if ((err = bpf_set_link_xdp_fd(ifindex, prog_fd, xdp_flags)) < 0) { + if ((err = bpf_xdp_attach(ifindex, prog_fd, xdp_flags, NULL)) < 0) { fprintf(stderr, "ERR: link set xdp fd failed (err:%d)\n", err); return EXIT_FAIL_XDP; } diff --git a/src/xdp_pass_user.c b/src/xdp_pass_user.c index a7ffbb4..7f78f9e 100644 --- a/src/xdp_pass_user.c +++ b/src/xdp_pass_user.c @@ -59,7 +59,7 @@ static int xdp_unload(int ifindex_unload) { int err; - if ((err = bpf_set_link_xdp_fd(ifindex, -1, xdp_flags)) < 0) { + if ((err = bpf_xdp_attach(ifindex, -1, xdp_flags, NULL)) < 0) { fprintf(stderr, "ERR: link set xdp unload failed (err=%d):%s\n", err, strerror(-err)); return EXIT_FAIL_XDP; @@ -76,10 +76,7 @@ int main(int argc, char **argv) bool unload = false; char filename[256]; int longindex = 0; - - struct bpf_prog_load_attr prog_load_attr = { - .prog_type = BPF_PROG_TYPE_XDP, - }; + int ret = EXIT_FAIL; /* Parse commands line args */ while ((opt = getopt_long(argc, argv, "FhSrmzd:s:a:", @@ -129,30 +126,36 @@ int main(int argc, char **argv) return xdp_unload(ifindex); snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); - prog_load_attr.file = filename; - if (bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd)) - return EXIT_FAIL; + obj = bpf_object__open_file(filename, NULL); + if (!obj) + return EXIT_FAIL; - if (!prog_fd) { + if (bpf_object__load(obj)) { fprintf(stderr, "ERR: load_bpf_file: %s\n", strerror(errno)); - return EXIT_FAIL; - } + goto out; + } - if ((err = bpf_set_link_xdp_fd(ifindex, prog_fd, xdp_flags)) < 0) { + prog_fd = bpf_program__fd(bpf_object__find_program_by_name(obj, "xdp_prog")); + if ((err = bpf_xdp_attach(ifindex, prog_fd, xdp_flags, NULL)) < 0) { fprintf(stderr, "ERR: link set xdp fd failed (err=%d):%s\n", err, strerror(-err)); - return EXIT_FAIL_XDP; + ret = EXIT_FAIL_XDP; + goto out; } err = bpf_obj_get_info_by_fd(prog_fd, &info, &info_len); if (err) { fprintf(stderr, "ERR: can't get prog info - %s\n", strerror(errno)); - return err; + goto out; } printf("Success: Load XDP prog id=%d on device:%s ifindex:%d\n", info.id, ifname, ifindex); - return EXIT_OK; + ret = EXIT_OK; + +out: + bpf_object__close(obj); + return ret; }