Skip to content

Commit 036a05f

Browse files
tohojoAlexei Starovoitov
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 4b27480 commit 036a05f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

tools/testing/selftests/bpf/prog_tests/xdp_link.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ void serial_test_xdp_link(void)
127127
ASSERT_EQ(link_info.prog_id, id1, "link_prog_id");
128128
ASSERT_EQ(link_info.xdp.ifindex, IFINDEX_LO, "link_ifindex");
129129

130+
/* updating program under active BPF link with different type fails */
131+
err = bpf_link__update_program(link, skel1->progs.tc_handler);
132+
if (!ASSERT_ERR(err, "link_upd_invalid"))
133+
goto cleanup;
134+
130135
err = bpf_link__detach(link);
131136
if (!ASSERT_OK(err, "link_detach"))
132137
goto cleanup;

tools/testing/selftests/bpf/progs/test_xdp_link.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ int xdp_handler(struct xdp_md *xdp)
1010
{
1111
return 0;
1212
}
13+
14+
SEC("tc")
15+
int tc_handler(struct __sk_buff *skb)
16+
{
17+
return 0;
18+
}

0 commit comments

Comments
 (0)