Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update libbpf submodule to v1.0 #10

Merged
merged 1 commit into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libbpf
Submodule libbpf updated 119 files
2 changes: 1 addition & 1 deletion src/tc_classify_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 2 additions & 5 deletions src/tc_queue_mapping_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 */
Expand Down
3 changes: 1 addition & 2 deletions src/xdp_iphash_to_cpu_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -242,4 +242,3 @@ int xdp_program(struct xdp_md *ctx)
}

char _license[] SEC("license") = "GPL";

48 changes: 8 additions & 40 deletions src/xdp_iphash_to_cpu_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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;
}
Expand Down
33 changes: 18 additions & 15 deletions src/xdp_pass_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:",
Expand Down Expand Up @@ -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;
}