Skip to content

Commit e2e668b

Browse files
author
Martin KaFai Lau
committed
Merge branch 'selftests-bpf-convert-test_tc_tunnel-sh-to-test_progs'
Alexis Lothoré says: ==================== Hello, this is the v3 of test_tc_tunnel conversion into test_progs framework. This new revision: - fixes a few issues spotted by the bot reviewer - removes any test ensuring connection failure (and so depending on a timout) to keep the execution time reasonable test_tc_tunnel.sh tests a variety of tunnels based on BPF: packets are encapsulated by a BPF program on the client egress. We then check that those packets can be decapsulated on server ingress side, either thanks to kernel-based or BPF-based decapsulation. Those tests are run thanks to two veths in two dedicated namespaces. - patches 1 and 2 are preparatory patches - patch 3 introduce tc_tunnel test into test_progs - patch 4 gets rid of the test_tc_tunnel.sh script The new test has been executed both in some x86 local qemu machine, as well as in CI: # ./test_progs -a tc_tunnel #454/1 tc_tunnel/ipip_none:OK #454/2 tc_tunnel/ipip6_none:OK #454/3 tc_tunnel/ip6tnl_none:OK #454/4 tc_tunnel/sit_none:OK #454/5 tc_tunnel/vxlan_eth:OK #454/6 tc_tunnel/ip6vxlan_eth:OK #454/7 tc_tunnel/gre_none:OK #454/8 tc_tunnel/gre_eth:OK #454/9 tc_tunnel/gre_mpls:OK #454/10 tc_tunnel/ip6gre_none:OK #454/11 tc_tunnel/ip6gre_eth:OK #454/12 tc_tunnel/ip6gre_mpls:OK #454/13 tc_tunnel/udp_none:OK #454/14 tc_tunnel/udp_eth:OK #454/15 tc_tunnel/udp_mpls:OK #454/16 tc_tunnel/ip6udp_none:OK #454/17 tc_tunnel/ip6udp_eth:OK #454/18 tc_tunnel/ip6udp_mpls:OK #454 tc_tunnel:OK Summary: 1/18 PASSED, 0 SKIPPED, 0 FAILED ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Martin KaFai Lau <[email protected]>
2 parents 54c134f + 5d35916 commit e2e668b

File tree

7 files changed

+789
-468
lines changed

7 files changed

+789
-468
lines changed

tools/testing/selftests/bpf/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ TEST_FILES = xsk_prereqs.sh $(wildcard progs/btf_dump_test_case_*.c)
105105
# Order correspond to 'make run_tests' order
106106
TEST_PROGS := test_kmod.sh \
107107
test_lirc_mode2.sh \
108-
test_tc_tunnel.sh \
109108
test_tc_edt.sh \
110109
test_xdping.sh \
111110
test_bpftool_build.sh \

tools/testing/selftests/bpf/network_helpers.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,50 @@ int send_recv_data(int lfd, int fd, uint32_t total_bytes)
766766
return err;
767767
}
768768

769+
int tc_prog_attach(const char *dev, int ingress_fd, int egress_fd)
770+
{
771+
int ifindex, ret;
772+
773+
if (!ASSERT_TRUE(ingress_fd >= 0 || egress_fd >= 0,
774+
"at least one program fd is valid"))
775+
return -1;
776+
777+
ifindex = if_nametoindex(dev);
778+
if (!ASSERT_NEQ(ifindex, 0, "get ifindex"))
779+
return -1;
780+
781+
DECLARE_LIBBPF_OPTS(bpf_tc_hook, hook, .ifindex = ifindex,
782+
.attach_point = BPF_TC_INGRESS | BPF_TC_EGRESS);
783+
DECLARE_LIBBPF_OPTS(bpf_tc_opts, opts1, .handle = 1,
784+
.priority = 1, .prog_fd = ingress_fd);
785+
DECLARE_LIBBPF_OPTS(bpf_tc_opts, opts2, .handle = 1,
786+
.priority = 1, .prog_fd = egress_fd);
787+
788+
ret = bpf_tc_hook_create(&hook);
789+
if (!ASSERT_OK(ret, "create tc hook"))
790+
return ret;
791+
792+
if (ingress_fd >= 0) {
793+
hook.attach_point = BPF_TC_INGRESS;
794+
ret = bpf_tc_attach(&hook, &opts1);
795+
if (!ASSERT_OK(ret, "bpf_tc_attach")) {
796+
bpf_tc_hook_destroy(&hook);
797+
return ret;
798+
}
799+
}
800+
801+
if (egress_fd >= 0) {
802+
hook.attach_point = BPF_TC_EGRESS;
803+
ret = bpf_tc_attach(&hook, &opts2);
804+
if (!ASSERT_OK(ret, "bpf_tc_attach")) {
805+
bpf_tc_hook_destroy(&hook);
806+
return ret;
807+
}
808+
}
809+
810+
return 0;
811+
}
812+
769813
#ifdef TRAFFIC_MONITOR
770814
struct tmonitor_ctx {
771815
pcap_t *pcap;

tools/testing/selftests/bpf/network_helpers.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,22 @@ struct tmonitor_ctx;
255255

256256
typedef int (*tm_print_fn_t)(const char *format, va_list args);
257257

258+
/**
259+
* tc_prog_attach - attach BPF program(s) to an interface
260+
*
261+
* Takes file descriptors pointing to at least one, at most two BPF
262+
* programs, and attach those programs to an interface ingress, egress or
263+
* both.
264+
*
265+
* @dev: string containing the interface name
266+
* @ingress_fd: file descriptor of the program to attach to interface ingress
267+
* @egress_fd: file descriptor of the program to attach to interface egress
268+
*
269+
* Returns 0 on success, -1 if no valid file descriptor has been found, if
270+
* the interface name is invalid or if an error ocurred during attach.
271+
*/
272+
int tc_prog_attach(const char *dev, int ingress_fd, int egress_fd);
273+
258274
#ifdef TRAFFIC_MONITOR
259275
struct tmonitor_ctx *traffic_monitor_start(const char *netns, const char *test_name,
260276
const char *subtest_name);

0 commit comments

Comments
 (0)