bpf/selftests: Add check for updating XDP bpf_link with wrong program type

Add a check to the xdp_link selftest that the kernel rejects replacing an
XDP program with a different program type on link update.

v2:
- Split this out into its own patch.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Link: https://lore.kernel.org/r/20220107221115.326171-3-toke@redhat.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
Toke Høiland-Jørgensen 2022-01-07 23:11:15 +01:00 committed by Alexei Starovoitov
parent 4b27480dca
commit 036a05f50b
2 changed files with 11 additions and 0 deletions

View File

@ -127,6 +127,11 @@ void serial_test_xdp_link(void)
ASSERT_EQ(link_info.prog_id, id1, "link_prog_id");
ASSERT_EQ(link_info.xdp.ifindex, IFINDEX_LO, "link_ifindex");
/* 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;

View File

@ -10,3 +10,9 @@ int xdp_handler(struct xdp_md *xdp)
{
return 0;
}
SEC("tc")
int tc_handler(struct __sk_buff *skb)
{
return 0;
}