1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/if_link.h>
3 #include <test_progs.h>
7 void test_xdp_info(void)
9 __u32 len
= sizeof(struct bpf_prog_info
), duration
= 0, prog_id
;
10 const char *file
= "./xdp_dummy.o";
11 struct bpf_prog_info info
= {};
12 struct bpf_object
*obj
;
15 /* Get prog_id for XDP_ATTACHED_NONE mode */
17 err
= bpf_get_link_xdp_id(IFINDEX_LO
, &prog_id
, 0);
18 if (CHECK(err
, "get_xdp_none", "errno=%d\n", errno
))
20 if (CHECK(prog_id
, "prog_id_none", "unexpected prog_id=%u\n", prog_id
))
23 err
= bpf_get_link_xdp_id(IFINDEX_LO
, &prog_id
, XDP_FLAGS_SKB_MODE
);
24 if (CHECK(err
, "get_xdp_none_skb", "errno=%d\n", errno
))
26 if (CHECK(prog_id
, "prog_id_none_skb", "unexpected prog_id=%u\n",
32 err
= bpf_prog_load(file
, BPF_PROG_TYPE_XDP
, &obj
, &prog_fd
);
36 err
= bpf_obj_get_info_by_fd(prog_fd
, &info
, &len
);
37 if (CHECK(err
, "get_prog_info", "errno=%d\n", errno
))
40 err
= bpf_set_link_xdp_fd(IFINDEX_LO
, prog_fd
, XDP_FLAGS_SKB_MODE
);
41 if (CHECK(err
, "set_xdp_skb", "errno=%d\n", errno
))
44 /* Get prog_id for single prog mode */
46 err
= bpf_get_link_xdp_id(IFINDEX_LO
, &prog_id
, 0);
47 if (CHECK(err
, "get_xdp", "errno=%d\n", errno
))
49 if (CHECK(prog_id
!= info
.id
, "prog_id", "prog_id not available\n"))
52 err
= bpf_get_link_xdp_id(IFINDEX_LO
, &prog_id
, XDP_FLAGS_SKB_MODE
);
53 if (CHECK(err
, "get_xdp_skb", "errno=%d\n", errno
))
55 if (CHECK(prog_id
!= info
.id
, "prog_id_skb", "prog_id not available\n"))
58 err
= bpf_get_link_xdp_id(IFINDEX_LO
, &prog_id
, XDP_FLAGS_DRV_MODE
);
59 if (CHECK(err
, "get_xdp_drv", "errno=%d\n", errno
))
61 if (CHECK(prog_id
, "prog_id_drv", "unexpected prog_id=%u\n", prog_id
))
65 bpf_set_link_xdp_fd(IFINDEX_LO
, -1, 0);
67 bpf_object__close(obj
);