Skip to content

Commit 680a752

Browse files
bastien-curutchetMartin KaFai Lau
authored andcommitted
selftests/bpf: test_tunnel: Move ip6tnl tunnel tests to test_progs
ip6tnl tunnels are tested in the test_tunnel.sh but not in the test_progs framework. Add a new test in test_progs to test ip6tnl tunnels. It uses the same network topology and the same BPF programs than the script. Remove test_ipip6() and test_ip6ip6() from the script. Signed-off-by: Bastien Curutchet (eBPF Foundation) <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Acked-by: Stanislav Fomichev <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 8d86094 commit 680a752

File tree

2 files changed

+59
-88
lines changed

2 files changed

+59
-88
lines changed

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@
118118
#define IP6GENEVE_TUNL_DEV0 "ip6geneve00"
119119
#define IP6GENEVE_TUNL_DEV1 "ip6geneve11"
120120

121+
#define IP6TNL_TUNL_DEV0 "ip6tnl00"
122+
#define IP6TNL_TUNL_DEV1 "ip6tnl11"
123+
121124
#define PING_ARGS "-i 0.01 -c 3 -w 10 -q"
122125

123126
static int config_device(void)
@@ -513,6 +516,11 @@ static void ping6_veth0(void)
513516
test_ping(AF_INET6, IP6_ADDR_VETH0);
514517
}
515518

519+
static void ping6_dev0(void)
520+
{
521+
test_ping(AF_INET6, IP6_ADDR_TUNL_DEV0);
522+
}
523+
516524
static void ping6_dev1(void)
517525
{
518526
struct nstoken *nstoken;
@@ -1046,6 +1054,55 @@ static void test_ip6geneve_tunnel(void)
10461054
test_tunnel_kern__destroy(skel);
10471055
}
10481056

1057+
enum ip6tnl_test {
1058+
IPIP6,
1059+
IP6IP6
1060+
};
1061+
1062+
static void test_ip6tnl_tunnel(enum ip6tnl_test test)
1063+
{
1064+
struct test_tunnel_kern *skel;
1065+
int set_fd, get_fd;
1066+
int err;
1067+
1068+
skel = test_tunnel_kern__open_and_load();
1069+
if (!ASSERT_OK_PTR(skel, "test_tunnel_kern__open_and_load"))
1070+
return;
1071+
1072+
err = add_ipv6_tunnel(IP6TNL_TUNL_DEV0, IP6TNL_TUNL_DEV1, "ip6tnl", "");
1073+
if (!ASSERT_OK(err, "add tunnel"))
1074+
goto done;
1075+
1076+
switch (test) {
1077+
case IPIP6:
1078+
set_fd = bpf_program__fd(skel->progs.ipip6_set_tunnel);
1079+
get_fd = bpf_program__fd(skel->progs.ipip6_get_tunnel);
1080+
break;
1081+
case IP6IP6:
1082+
set_fd = bpf_program__fd(skel->progs.ip6ip6_set_tunnel);
1083+
get_fd = bpf_program__fd(skel->progs.ip6ip6_get_tunnel);
1084+
break;
1085+
}
1086+
if (generic_attach(IP6TNL_TUNL_DEV1, get_fd, set_fd))
1087+
goto done;
1088+
1089+
ping6_veth0();
1090+
switch (test) {
1091+
case IPIP6:
1092+
ping_dev0();
1093+
ping_dev1();
1094+
break;
1095+
case IP6IP6:
1096+
ping6_dev0();
1097+
ping6_dev1();
1098+
break;
1099+
}
1100+
1101+
done:
1102+
delete_tunnel(IP6TNL_TUNL_DEV0, IP6TNL_TUNL_DEV1);
1103+
test_tunnel_kern__destroy(skel);
1104+
}
1105+
10491106
#define RUN_TEST(name, ...) \
10501107
({ \
10511108
if (test__start_subtest(#name)) { \
@@ -1075,6 +1132,8 @@ static void *test_tunnel_run_tests(void *arg)
10751132
RUN_TEST(ip6erspan_tunnel, V2);
10761133
RUN_TEST(geneve_tunnel);
10771134
RUN_TEST(ip6geneve_tunnel);
1135+
RUN_TEST(ip6tnl_tunnel, IPIP6);
1136+
RUN_TEST(ip6tnl_tunnel, IP6IP6);
10781137

10791138
return NULL;
10801139
}

tools/testing/selftests/bpf/test_tunnel.sh

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -79,28 +79,6 @@ add_ipip_tunnel()
7979
ip addr add dev $DEV 10.1.1.200/24
8080
}
8181

82-
add_ip6tnl_tunnel()
83-
{
84-
ip netns exec at_ns0 ip addr add ::11/96 dev veth0
85-
ip netns exec at_ns0 ip link set dev veth0 up
86-
ip addr add dev veth1 ::22/96
87-
ip link set dev veth1 up
88-
89-
# at_ns0 namespace
90-
ip netns exec at_ns0 \
91-
ip link add dev $DEV_NS type $TYPE \
92-
local ::11 remote ::22
93-
ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
94-
ip netns exec at_ns0 ip addr add dev $DEV_NS 1::11/96
95-
ip netns exec at_ns0 ip link set dev $DEV_NS up
96-
97-
# root namespace
98-
ip link add dev $DEV type $TYPE external
99-
ip addr add dev $DEV 10.1.1.200/24
100-
ip addr add dev $DEV 1::22/96
101-
ip link set dev $DEV up
102-
}
103-
10482
test_ipip()
10583
{
10684
TYPE=ipip
@@ -126,62 +104,6 @@ test_ipip()
126104
echo -e ${GREEN}"PASS: $TYPE"${NC}
127105
}
128106

129-
test_ipip6()
130-
{
131-
TYPE=ip6tnl
132-
DEV_NS=ipip6tnl00
133-
DEV=ipip6tnl11
134-
ret=0
135-
136-
check $TYPE
137-
config_device
138-
add_ip6tnl_tunnel
139-
ip link set dev veth1 mtu 1500
140-
attach_bpf $DEV ipip6_set_tunnel ipip6_get_tunnel
141-
# underlay
142-
ping6 $PING_ARG ::11
143-
# ip4 over ip6
144-
ping $PING_ARG 10.1.1.100
145-
check_err $?
146-
ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
147-
check_err $?
148-
cleanup
149-
150-
if [ $ret -ne 0 ]; then
151-
echo -e ${RED}"FAIL: $TYPE"${NC}
152-
return 1
153-
fi
154-
echo -e ${GREEN}"PASS: $TYPE"${NC}
155-
}
156-
157-
test_ip6ip6()
158-
{
159-
TYPE=ip6tnl
160-
DEV_NS=ip6ip6tnl00
161-
DEV=ip6ip6tnl11
162-
ret=0
163-
164-
check $TYPE
165-
config_device
166-
add_ip6tnl_tunnel
167-
ip link set dev veth1 mtu 1500
168-
attach_bpf $DEV ip6ip6_set_tunnel ip6ip6_get_tunnel
169-
# underlay
170-
ping6 $PING_ARG ::11
171-
# ip6 over ip6
172-
ping6 $PING_ARG 1::11
173-
check_err $?
174-
ip netns exec at_ns0 ping6 $PING_ARG 1::22
175-
check_err $?
176-
cleanup
177-
178-
if [ $ret -ne 0 ]; then
179-
echo -e ${RED}"FAIL: ip6$TYPE"${NC}
180-
return 1
181-
fi
182-
echo -e ${GREEN}"PASS: ip6$TYPE"${NC}
183-
}
184-
185107
attach_bpf()
186108
{
187109
DEV=$1
@@ -201,8 +123,6 @@ cleanup()
201123
ip netns delete at_ns0 2> /dev/null
202124
ip link del veth1 2> /dev/null
203125
ip link del ipip11 2> /dev/null
204-
ip link del ipip6tnl11 2> /dev/null
205-
ip link del ip6ip6tnl11 2> /dev/null
206126
}
207127

208128
cleanup_exit()
@@ -242,14 +162,6 @@ bpf_tunnel_test()
242162
test_ipip
243163
errors=$(( $errors + $? ))
244164

245-
echo "Testing IPIP6 tunnel..."
246-
test_ipip6
247-
errors=$(( $errors + $? ))
248-
249-
echo "Testing IP6IP6 tunnel..."
250-
test_ip6ip6
251-
errors=$(( $errors + $? ))
252-
253165
return $errors
254166
}
255167

0 commit comments

Comments
 (0)