/* set initial prog attachment */
err = bpf_xdp_attach(IFINDEX_LO, prog_fd1, XDP_FLAGS_REPLACE, &opts); if (!ASSERT_OK(err, "fd_attach")) goto cleanup;
/* validate prog ID */
err = bpf_xdp_query_id(IFINDEX_LO, 0, &id0); if (!ASSERT_OK(err, "id1_check_err") || !ASSERT_EQ(id0, id1, "id1_check_val")) goto cleanup;
/* BPF link is not allowed to replace prog attachment */
link = bpf_program__attach_xdp(skel1->progs.xdp_handler, IFINDEX_LO); if (!ASSERT_ERR_PTR(link, "link_attach_should_fail")) {
bpf_link__destroy(link); /* best-effort detach prog */
opts.old_prog_fd = prog_fd1;
bpf_xdp_detach(IFINDEX_LO, XDP_FLAGS_REPLACE, &opts); goto cleanup;
}
/* detach BPF program */
opts.old_prog_fd = prog_fd1;
err = bpf_xdp_detach(IFINDEX_LO, XDP_FLAGS_REPLACE, &opts); if (!ASSERT_OK(err, "prog_detach")) goto cleanup;
/* now BPF link should attach successfully */
link = bpf_program__attach_xdp(skel1->progs.xdp_handler, IFINDEX_LO); if (!ASSERT_OK_PTR(link, "link_attach")) goto cleanup;
skel1->links.xdp_handler = link;
/* validate prog ID */
err = bpf_xdp_query_id(IFINDEX_LO, 0, &id0); if (!ASSERT_OK(err, "id1_check_err") || !ASSERT_EQ(id0, id1, "id1_check_val")) goto cleanup;
/* BPF prog attach is not allowed to replace BPF link */
opts.old_prog_fd = prog_fd1;
err = bpf_xdp_attach(IFINDEX_LO, prog_fd2, XDP_FLAGS_REPLACE, &opts); if (!ASSERT_ERR(err, "prog_attach_fail")) goto cleanup;
/* Can't force-update when BPF link is active */
err = bpf_xdp_attach(IFINDEX_LO, prog_fd2, 0, NULL); if (!ASSERT_ERR(err, "prog_update_fail")) goto cleanup;
/* Can't force-detach when BPF link is active */
err = bpf_xdp_detach(IFINDEX_LO, 0, NULL); if (!ASSERT_ERR(err, "prog_detach_fail")) goto cleanup;
/* BPF link is not allowed to replace another BPF link */
link = bpf_program__attach_xdp(skel2->progs.xdp_handler, IFINDEX_LO); if (!ASSERT_ERR_PTR(link, "link_attach_should_fail")) {
bpf_link__destroy(link); goto cleanup;
}
/* new link attach should succeed */
link = bpf_program__attach_xdp(skel2->progs.xdp_handler, IFINDEX_LO); if (!ASSERT_OK_PTR(link, "link_attach")) goto cleanup;
skel2->links.xdp_handler = link;
/* updating program under active BPF link works as expected */
err = bpf_link__update_program(link, skel1->progs.xdp_handler); if (!ASSERT_OK(err, "link_upd")) goto cleanup;
/* updating program under active BPF link with different type fails */
err = bpf_link__update_program(link, skel1->progs.tc_handler); if (!ASSERT_ERR(err, "link_upd_invalid")) goto cleanup;
err = bpf_link__detach(link); if (!ASSERT_OK(err, "link_detach")) goto cleanup;
ASSERT_OK(err, "link_info");
ASSERT_EQ(link_info.prog_id, id1, "link_prog_id"); /* ifindex should be zeroed out */
ASSERT_EQ(link_info.xdp.ifindex, 0, "link_ifindex");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.