bpf/selftests: Add check for updating XDP bpf_link with wrong program type
authorToke Høiland-Jørgensen <toke@redhat.com>
Fri, 7 Jan 2022 22:11:15 +0000 (23:11 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 11 Jan 2022 17:44:06 +0000 (09:44 -0800)
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>
tools/testing/selftests/bpf/prog_tests/xdp_link.c
tools/testing/selftests/bpf/progs/test_xdp_link.c

index eec0bf8..b2b357f 100644 (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;
index ee7d6ac..64ff32e 100644 (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;
+}