Skip to content

Commit 302347b

Browse files
borkmannJean-Michel Hautbois
authored and
Jean-Michel Hautbois
committed
selftests/bpf: Extend tcx tests to cover late tcx_entry release
Add a test case which replaces an active ingress qdisc while keeping the miniq in-tact during the transition period to the new clsact qdisc. # ./vmtest.sh -- ./test_progs -t tc_link [...] ./test_progs -t tc_link [ 3.412871] bpf_testmod: loading out-of-tree module taints kernel. [ 3.413343] bpf_testmod: module verification failed: signature and/or required key missing - tainting kernel torvalds#332 tc_links_after:OK torvalds#333 tc_links_append:OK torvalds#334 tc_links_basic:OK torvalds#335 tc_links_before:OK torvalds#336 tc_links_chain_classic:OK torvalds#337 tc_links_chain_mixed:OK torvalds#338 tc_links_dev_chain0:OK torvalds#339 tc_links_dev_cleanup:OK torvalds#340 tc_links_dev_mixed:OK torvalds#341 tc_links_ingress:OK torvalds#342 tc_links_invalid:OK torvalds#343 tc_links_prepend:OK torvalds#344 tc_links_replace:OK torvalds#345 tc_links_revision:OK Summary: 14/0 PASSED, 0 SKIPPED, 0 FAILED Signed-off-by: Daniel Borkmann <[email protected]> Cc: Martin KaFai Lau <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin KaFai Lau <[email protected]>
1 parent 7d976a4 commit 302347b

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

tools/testing/selftests/bpf/config

+3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ CONFIG_MPLS=y
5858
CONFIG_MPLS_IPTUNNEL=y
5959
CONFIG_MPLS_ROUTING=y
6060
CONFIG_MPTCP=y
61+
CONFIG_NET_ACT_SKBMOD=y
62+
CONFIG_NET_CLS=y
6163
CONFIG_NET_CLS_ACT=y
6264
CONFIG_NET_CLS_BPF=y
6365
CONFIG_NET_CLS_FLOWER=y
66+
CONFIG_NET_CLS_MATCHALL=y
6467
CONFIG_NET_FOU=y
6568
CONFIG_NET_FOU_IP_TUNNELS=y
6669
CONFIG_NET_IPGRE=y

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

+61
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#define ping_cmd "ping -q -c1 -w1 127.0.0.1 > /dev/null"
1010

1111
#include "test_tc_link.skel.h"
12+
13+
#include "netlink_helpers.h"
1214
#include "tc_helpers.h"
1315

1416
void serial_test_tc_links_basic(void)
@@ -1787,6 +1789,65 @@ void serial_test_tc_links_ingress(void)
17871789
test_tc_links_ingress(BPF_TCX_INGRESS, false, false);
17881790
}
17891791

1792+
struct qdisc_req {
1793+
struct nlmsghdr n;
1794+
struct tcmsg t;
1795+
char buf[1024];
1796+
};
1797+
1798+
static int qdisc_replace(int ifindex, const char *kind, bool block)
1799+
{
1800+
struct rtnl_handle rth = { .fd = -1 };
1801+
struct qdisc_req req;
1802+
int err;
1803+
1804+
err = rtnl_open(&rth, 0);
1805+
if (!ASSERT_OK(err, "open_rtnetlink"))
1806+
return err;
1807+
1808+
memset(&req, 0, sizeof(req));
1809+
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg));
1810+
req.n.nlmsg_flags = NLM_F_CREATE | NLM_F_REPLACE | NLM_F_REQUEST;
1811+
req.n.nlmsg_type = RTM_NEWQDISC;
1812+
req.t.tcm_family = AF_UNSPEC;
1813+
req.t.tcm_ifindex = ifindex;
1814+
req.t.tcm_parent = 0xfffffff1;
1815+
1816+
addattr_l(&req.n, sizeof(req), TCA_KIND, kind, strlen(kind) + 1);
1817+
if (block)
1818+
addattr32(&req.n, sizeof(req), TCA_INGRESS_BLOCK, 1);
1819+
1820+
err = rtnl_talk(&rth, &req.n, NULL);
1821+
ASSERT_OK(err, "talk_rtnetlink");
1822+
rtnl_close(&rth);
1823+
return err;
1824+
}
1825+
1826+
void serial_test_tc_links_dev_chain0(void)
1827+
{
1828+
int err, ifindex;
1829+
1830+
ASSERT_OK(system("ip link add dev foo type veth peer name bar"), "add veth");
1831+
ifindex = if_nametoindex("foo");
1832+
ASSERT_NEQ(ifindex, 0, "non_zero_ifindex");
1833+
err = qdisc_replace(ifindex, "ingress", true);
1834+
if (!ASSERT_OK(err, "attaching ingress"))
1835+
goto cleanup;
1836+
ASSERT_OK(system("tc filter add block 1 matchall action skbmod swap mac"), "add block");
1837+
err = qdisc_replace(ifindex, "clsact", false);
1838+
if (!ASSERT_OK(err, "attaching clsact"))
1839+
goto cleanup;
1840+
/* Heuristic: kern_sync_rcu() alone does not work; a wait-time of ~5s
1841+
* triggered the issue without the fix reliably 100% of the time.
1842+
*/
1843+
sleep(5);
1844+
ASSERT_OK(system("tc filter add dev foo ingress matchall action skbmod swap mac"), "add filter");
1845+
cleanup:
1846+
ASSERT_OK(system("ip link del dev foo"), "del veth");
1847+
ASSERT_EQ(if_nametoindex("foo"), 0, "foo removed");
1848+
ASSERT_EQ(if_nametoindex("bar"), 0, "bar removed");
1849+
}
1850+
17901851
static void test_tc_links_dev_mixed(int target)
17911852
{
17921853
LIBBPF_OPTS(bpf_tc_opts, tc_opts, .handle = 1, .priority = 1);

0 commit comments

Comments
 (0)