Skip to contentSkip to conversation

selftests/net: add test for IPv4-in-IPv6 tunneling

PATCH Superseded Linus Heckemann 3 participants 3 messages Feb 9 – Feb 11

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 selftests/net: add test for IPv4-in-IPv6 tunneling

commit 81c734dae203 ("ip6_tunnel: use skb_vlan_inet_prepare() in __ip6_tnl_rcv()") was fine in and of itself, but its backport to 6.12 (and 6.6) broke IPv4-in-IPv6 tunneling, see [1]. This adds a self-test for basic IPv4-in-IPv6 and IPv6-in-IPv6 functionality.

[1]: https://lore.kernel.org/all/CAA2RiuSnH_2xc+-W6EnFEG00XjS-dszMq61JEvRjcGS31CBw=g@mail.gmail.com/

--
Thanks for the review, Hangbin!

---
 tools/testing/selftests/net/Makefile      |  1 +
 tools/testing/selftests/net/ip6_tunnel.sh | 43 +++++++++++++++++++++++
 2 files changed, 44 insertions(+)
 create mode 100644 tools/testing/selftests/net/ip6_tunnel.sh
tools/testing/selftests/net/Makefile +1 -0
index 45c4ea381bc36..5037a344ad826 100644
@@ -43,6 +43,7 @@ TEST_PROGS := \
 	io_uring_zerocopy_tx.sh \
 	ioam6.sh \
 	ip6_gre_headroom.sh \
+	ip6_tunnel.sh \
 	ip_defrag.sh \
 	ip_local_port_range.sh \
 	ipv6_flowlabel.sh \
tools/testing/selftests/net/ip6_tunnel.sh new file +43 -0

43 lines not on this page · raw message

Signature · 1 line
2.52.0
#1 lore raw

Hi Linus,

For the subject, please also provide the target repo. e.g. [PATCH v2 net-next]

Quoted 60 lines · Linus Heckemann

commit 81c734dae203 ("ip6_tunnel: use skb_vlan_inet_prepare() in __ip6_tnl_rcv()") was fine in and of itself, but its backport to 6.12 (and 6.6) broke IPv4-in-IPv6 tunneling, see [1]. This adds a self-test for basic IPv4-in-IPv6 and IPv6-in-IPv6 functionality.

[1]: https://lore.kernel.org/all/CAA2RiuSnH_2xc+-W6EnFEG00XjS-dszMq61JEvRjcGS31CBw=g@mail.gmail.com/

--
Thanks for the review, Hangbin!

---
 tools/testing/selftests/net/Makefile      |  1 +
 tools/testing/selftests/net/ip6_tunnel.sh | 43 +++++++++++++++++++++++
 2 files changed, 44 insertions(+)
 create mode 100644 tools/testing/selftests/net/ip6_tunnel.sh
tools/testing/selftests/net/Makefile +1 -0
index 45c4ea381bc36..5037a344ad826 100644
@@ -43,6 +43,7 @@ TEST_PROGS := \
 	io_uring_zerocopy_tx.sh \
 	ioam6.sh \
 	ip6_gre_headroom.sh \
+	ip6_tunnel.sh \
 	ip_defrag.sh \
 	ip_local_port_range.sh \
 	ipv6_flowlabel.sh \
tools/testing/selftests/net/ip6_tunnel.sh new file +27 -0
new file mode 100644
index 0000000000000..4886618fd2689
@@ -0,0 +1,43 @@
+#!/bin/bash
+# Test that IPv4-over-IPv6 tunneling works.
+
+source lib.sh
+
+setup_prepare() {
+  ip link add transport1 type veth peer name transport2
+
+  setup_ns ns1
+  ip link set transport1 netns $ns1
+  ip -n $ns1 address add 2001:db8::1/64 dev transport1 nodad
+  ip -n $ns1 address add 2001:db8::3/64 dev transport1 nodad
+  ip -n $ns1 link set transport1 up
+  ip -n $ns1 link add link transport1 name tunnel4 type ip6tnl mode ipip6 local 2001:db8::1 remote 2001:db8::2
+  ip -n $ns1 address add 172.0.0.1/32 peer 172.0.0.2/32 dev tunnel4
+  ip -n $ns1 link set tunnel4 up
+  ip -n $ns1 link add link transport1 name tunnel6 type ip6tnl mode ip6ip6 local 2001:db8::3 remote 2001:db8::4
+  ip -n $ns1 address add 2001:db8:6::1/64 dev tunnel6
+  ip -n $ns1 link set tunnel6 up
+
+  setup_ns ns2
+  ip link set transport2 netns $ns2
+  ip -n $ns2 address add 2001:db8::2/64 dev transport2 nodad
+  ip -n $ns2 address add 2001:db8::4/64 dev transport2 nodad
+  ip -n $ns2 link set transport2 up
+  ip -n $ns2 link add link transport2 name tunnel4 type ip6tnl mode ipip6 local 2001:db8::2 remote 2001:db8::1
+  ip -n $ns2 address add 172.0.0.2/32 peer 172.0.0.1/32 dev tunnel4

tools/testing/selftests/net/ip6_tunnel.sh line 37

Quoted 10 lines
tools/testing/selftests/net/ip6_tunnel.sh new file +10 -0
+  ip -n $ns2 link set tunnel4 up
+  ip -n $ns2 link add link transport2 name tunnel6 type ip6tnl mode ip6ip6 local 2001:db8::4 remote 2001:db8::3
+  ip -n $ns2 address add 2001:db8:6::2/64 dev tunnel6
+  ip -n $ns2 link set tunnel6 up
+}
+
+cleanup() {
+  cleanup_all_ns
+  # in case the namespaces haven't been set up yet
+  ip link delete transport1 || true

Maybe
ip link delete transport1 &> /dev/null || true

since this cmd usually would fail and report
Cannot find device "transport1"

tools/testing/selftests/net/ip6_tunnel.sh line 38

Quoted 1 line
tools/testing/selftests/net/ip6_tunnel.sh new file +1 -0
+}

You forgot to add set -e,

tools/testing/selftests/net/ip6_tunnel.sh line 43

Quoted 5 lines
tools/testing/selftests/net/ip6_tunnel.sh new file +5 -0
+
+trap cleanup EXIT
+setup_prepare
+ip netns exec $ns1 ping -W1 -c1 172.0.0.2
+ip netns exec $ns1 ping -W1 -c1 2001:db8:6::2

So if the first ping failed, and the second ping pass, the total test will still return 0.

Thanks
Hangbin

maintainer
#2 lore raw
In reply to Linus Heckemann
Quoted 6 lines · On Mon, 9 Feb 2026 20:00:09 +0100 Linus Heckemann wrote:

commit 81c734dae203 ("ip6_tunnel: use skb_vlan_inet_prepare() in __ip6_tnl_rcv()") was fine in and of itself, but its backport to 6.12 (and 6.6) broke IPv4-in-IPv6 tunneling, see [1]. This adds a self-test for basic IPv4-in-IPv6 and IPv6-in-IPv6 functionality.

[1]: https://lore.kernel.org/all/CAA2RiuSnH_2xc+-W6EnFEG00XjS-dszMq61JEvRjcGS31CBw=g@mail.gmail.com/

Missing your Signed-off-by: ...

Is this the output you expect (ignore the first two numbers, they are just output timing within our infra):

TAP version 13
1..1

# overriding timeout to 7200
# selftests: net: ip6_tunnel.sh
# Warning: file ip6_tunnel.sh is not executable
# 1.17 [+1.17] PING 172.0.0.2 (172.0.0.2) 56(84) bytes of data.
# 1.18 [+0.00] 64 bytes from 172.0.0.2: icmp_seq=1 ttl=64 time=2.31 ms
# 1.18 [+0.00] 
# 1.18 [+0.00] --- 172.0.0.2 ping statistics ---
# 1.19 [+0.00] 1 packets transmitted, 1 received, 0% packet loss, time 0ms
# 1.19 [+0.00] rtt min/avg/max/mdev = 2.311/2.311/2.311/0.000 ms
# 1.24 [+0.05] PING 2001:db8:6::2 (2001:db8:6::2) 56 data bytes
# 1.24 [+0.00] 64 bytes from 2001:db8:6::2: icmp_seq=1 ttl=64 time=0.368 ms
# 1.25 [+0.00] 
# 1.25 [+0.00] --- 2001:db8:6::2 ping statistics ---
# 1.25 [+0.00] 1 packets transmitted, 1 received, 0% packet loss, time 0ms
# 1.25 [+0.00] rtt min/avg/max/mdev = 0.368/0.368/0.368/0.000 ms
# 1.58 [+0.33] Cannot find device "transport1"
ok 1 selftests: net: ip6_tunnel.sh

Tests don't usually print raw ping output to stdout, plus the
Cannot find device "transport1"
looks a bit off?

Signature · 1 line
pw-bot: cr