Commit f1b73577 authored by Martin KaFai Lau's avatar Martin KaFai Lau Committed by Daniel Borkmann

selftests/bpf: Avoid pinning bpf prog in the tc_redirect_peer_l3 test

This patch removes the need to pin prog in the tc_redirect_peer_l3
test by directly using the bpf_tc_hook_create() and bpf_tc_attach().
The clsact qdisc will go away together with the test netns, so
no need to do bpf_tc_hook_destroy().
Signed-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarStanislav Fomichev <sdf@google.com>
Link: https://lore.kernel.org/bpf/20221129070900.3142427-4-martin.lau@linux.dev
parent 57d0863f
...@@ -1032,6 +1032,8 @@ static int tun_relay_loop(int src_fd, int target_fd) ...@@ -1032,6 +1032,8 @@ static int tun_relay_loop(int src_fd, int target_fd)
static void test_tc_redirect_peer_l3(struct netns_setup_result *setup_result) static void test_tc_redirect_peer_l3(struct netns_setup_result *setup_result)
{ {
LIBBPF_OPTS(bpf_tc_hook, qdisc_tun_fwd);
LIBBPF_OPTS(bpf_tc_hook, qdisc_veth_dst_fwd);
struct test_tc_peer *skel = NULL; struct test_tc_peer *skel = NULL;
struct nstoken *nstoken = NULL; struct nstoken *nstoken = NULL;
int err; int err;
...@@ -1086,31 +1088,21 @@ static void test_tc_redirect_peer_l3(struct netns_setup_result *setup_result) ...@@ -1086,31 +1088,21 @@ static void test_tc_redirect_peer_l3(struct netns_setup_result *setup_result)
if (!ASSERT_OK(err, "test_tc_peer__load")) if (!ASSERT_OK(err, "test_tc_peer__load"))
goto fail; goto fail;
err = bpf_program__pin(skel->progs.tc_src_l3, SRC_PROG_PIN_FILE);
if (!ASSERT_OK(err, "pin " SRC_PROG_PIN_FILE))
goto fail;
err = bpf_program__pin(skel->progs.tc_dst_l3, DST_PROG_PIN_FILE);
if (!ASSERT_OK(err, "pin " DST_PROG_PIN_FILE))
goto fail;
err = bpf_program__pin(skel->progs.tc_chk, CHK_PROG_PIN_FILE);
if (!ASSERT_OK(err, "pin " CHK_PROG_PIN_FILE))
goto fail;
/* Load "tc_src_l3" to the tun_fwd interface to redirect packets /* Load "tc_src_l3" to the tun_fwd interface to redirect packets
* towards dst, and "tc_dst" to redirect packets * towards dst, and "tc_dst" to redirect packets
* and "tc_chk" on veth_dst_fwd to drop non-redirected packets. * and "tc_chk" on veth_dst_fwd to drop non-redirected packets.
*/ */
SYS("tc qdisc add dev tun_fwd clsact"); /* tc qdisc add dev tun_fwd clsact */
SYS("tc filter add dev tun_fwd ingress bpf da object-pinned " QDISC_CLSACT_CREATE(&qdisc_tun_fwd, ifindex);
SRC_PROG_PIN_FILE); /* tc filter add dev tun_fwd ingress bpf da tc_src_l3 */
XGRESS_FILTER_ADD(&qdisc_tun_fwd, BPF_TC_INGRESS, skel->progs.tc_src_l3, 0);
SYS("tc qdisc add dev veth_dst_fwd clsact"); /* tc qdisc add dev veth_dst_fwd clsact */
SYS("tc filter add dev veth_dst_fwd ingress bpf da object-pinned " QDISC_CLSACT_CREATE(&qdisc_veth_dst_fwd, setup_result->ifindex_veth_dst_fwd);
DST_PROG_PIN_FILE); /* tc filter add dev veth_dst_fwd ingress bpf da tc_dst_l3 */
SYS("tc filter add dev veth_dst_fwd egress bpf da object-pinned " XGRESS_FILTER_ADD(&qdisc_veth_dst_fwd, BPF_TC_INGRESS, skel->progs.tc_dst_l3, 0);
CHK_PROG_PIN_FILE); /* tc filter add dev veth_dst_fwd egress bpf da tc_chk */
XGRESS_FILTER_ADD(&qdisc_veth_dst_fwd, BPF_TC_EGRESS, skel->progs.tc_chk, 0);
/* Setup route and neigh tables */ /* Setup route and neigh tables */
SYS("ip -netns " NS_SRC " addr add dev tun_src " IP4_TUN_SRC "/24"); SYS("ip -netns " NS_SRC " addr add dev tun_src " IP4_TUN_SRC "/24");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment