From: Yuya Kusakabe <yuya.kusakabe@gmail.com>
To: David Ahern <dsahern@kernel.org>,
Ido Schimmel <idosch@nvidia.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Justin Iurman <justin.iurman@gmail.com>,
Alexander Aring <alex.aring@gmail.com>,
Steffen Klassert <steffen.klassert@secunet.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
Nikolay Aleksandrov <razor@blackwall.org>,
Eyal Birger <eyal.birger@gmail.com>,
Nicolas Dichtel <nicolas.dichtel@6wind.com>,
Xin Long <lucien.xin@gmail.com>, Shuah Khan <shuah@kernel.org>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org,
Yuya Kusakabe <yuya.kusakabe@gmail.com>
Subject: [PATCH net 4/4] selftests: net: add lwtunnel route save and restore test
Date: Wed, 23 Sep 2026 09:36:59 +0900 [thread overview]
Message-ID: <20260923-lwt-encap-noflag-v1-4-8de7ab6c86e9@gmail.com> (raw)
In-Reply-To: <20260923-lwt-encap-noflag-v1-0-8de7ab6c86e9@gmail.com>
Add an encap route, save it with "ip route save", delete it and send
the dump back with "ip route restore". The restored route must match
the original one. The test covers the rpl, ioam6 and xfrm encaps and
the ip encap with geneve, vxlan and erspan options. A case is skipped
when the kernel or iproute2 does not support its encap.
Assisted-by: LLM
Signed-off-by: Yuya Kusakabe <yuya.kusakabe@gmail.com>
---
tools/testing/selftests/net/Makefile | 1 +
tools/testing/selftests/net/lwt_save_restore.sh | 116 ++++++++++++++++++++++++
2 files changed, 117 insertions(+)
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index 3ee3378f8b26..496aed9ca57b 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -62,6 +62,7 @@ TEST_PROGS := \
l2tp.sh \
link_netns.py \
lwt_dst_cache_ref_loop.sh \
+ lwt_save_restore.sh \
macvlan_mcast_shared_mac.sh \
msg_zerocopy.sh \
nat6to4.sh \
diff --git a/tools/testing/selftests/net/lwt_save_restore.sh b/tools/testing/selftests/net/lwt_save_restore.sh
new file mode 100755
index 000000000000..9666386c622d
--- /dev/null
+++ b/tools/testing/selftests/net/lwt_save_restore.sh
@@ -0,0 +1,116 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Check that routes with a lightweight tunnel encap survive "ip route save"
+# followed by "ip route restore", which sends the dumped RTA_ENCAP back to
+# the kernel unchanged.
+
+# shellcheck disable=SC1091,SC2034,SC2154,SC2317
+source lib.sh
+
+ALL_TESTS="
+ save_restore_rpl
+ save_restore_ioam6
+ save_restore_xfrm
+ save_restore_geneve_opts
+ save_restore_vxlan_opts
+ save_restore_erspan_opts
+"
+
+setup_prepare()
+{
+ setup_ns NS
+ defer cleanup_all_ns
+
+ ip -n "$NS" link add name dummy0 up type dummy
+}
+
+# save_restore <description> <prefix> <ip route add arguments>
+#
+# The description starts with the encap type.
+save_restore()
+{
+ local desc=$1; shift
+ local prefix=$1
+ local encap=${desc%% *}
+ local before after dump out rc
+ local family=-4
+
+ [[ $prefix == *:* ]] && family=-6
+
+ RET=0
+
+ if ! ip route help 2>&1 | grep "^ENCAPTYPE" | grep -qw "$encap"; then
+ log_test_skip "$desc" "iproute2 lacks the encap"
+ return
+ fi
+
+ out=$(ip -n "$NS" "$family" route add "$@" 2>&1)
+ rc=$?
+ if ((rc)) && [[ $out == *"encapsulation type"* ||
+ $out == *CONFIG_LWTUNNEL* ]]; then
+ log_test_skip "$desc" "kernel lacks the encap"
+ return
+ fi
+ check_err "$rc" "Failed to add route: $out"
+
+ dump=$(mktemp)
+ defer rm -f "$dump"
+
+ before=$(ip -n "$NS" "$family" route show "$prefix")
+ ip -n "$NS" "$family" route save "$prefix" > "$dump"
+ check_err $? "Failed to save route"
+
+ ip -n "$NS" "$family" route del "$prefix"
+ ip -n "$NS" "$family" route restore < "$dump"
+ check_err $? "Failed to restore route"
+
+ after=$(ip -n "$NS" "$family" route show "$prefix")
+ [ "$before" = "$after" ]
+ check_err $? "Restored route differs from the saved one"
+
+ log_test "encap $desc route save and restore"
+}
+
+save_restore_rpl()
+{
+ save_restore rpl 2001:db8:1::/64 \
+ encap rpl segs 2001:db8::2 dev dummy0
+}
+
+save_restore_ioam6()
+{
+ save_restore ioam6 2001:db8:2::/64 \
+ encap ioam6 trace prealloc type 0x800000 ns 1 size 12 dev dummy0
+}
+
+save_restore_xfrm()
+{
+ # iproute2 takes every argument after "encap xfrm" as an xfrm one
+ save_restore xfrm 2001:db8:3::/64 dev dummy0 encap xfrm if_id 1
+}
+
+save_restore_geneve_opts()
+{
+ save_restore "ip geneve_opts" 192.0.2.0/26 \
+ encap ip id 1 dst 198.51.100.2 geneve_opts 0:0:12121212 \
+ dev dummy0
+}
+
+save_restore_vxlan_opts()
+{
+ save_restore "ip vxlan_opts" 192.0.2.64/26 \
+ encap ip id 1 dst 198.51.100.2 vxlan_opts 456 dev dummy0
+}
+
+save_restore_erspan_opts()
+{
+ save_restore "ip erspan_opts" 192.0.2.128/26 \
+ encap ip id 1 dst 198.51.100.2 erspan_opts 1:123:0:0 dev dummy0
+}
+
+trap defer_scopes_cleanup EXIT
+setup_prepare
+tests_run
+
+exit "$EXIT_STATUS"
--
2.50.1
next prev parent reply other threads:[~2026-09-23 0:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 0:36 [PATCH net 0/4] net: lwtunnel: accept encap attributes without NLA_F_NESTED Yuya Kusakabe
2026-09-23 0:36 ` [PATCH net 1/4] net: lwtunnel: accept RTA_ENCAP " Yuya Kusakabe
2026-09-27 1:24 ` netdev-bot+sashiko
2026-09-23 0:36 ` [PATCH net 2/4] xfrm: " Yuya Kusakabe
2026-09-23 0:36 ` [PATCH net 3/4] net: ip_tunnel: accept tunnel options " Yuya Kusakabe
2026-09-27 1:25 ` netdev-bot+sashiko
2026-09-23 0:36 ` Yuya Kusakabe [this message]
2026-09-27 1:25 ` [PATCH net 4/4] selftests: net: add lwtunnel route save and restore test netdev-bot+sashiko
2026-09-23 11:29 ` [PATCH net 0/4] net: lwtunnel: accept encap attributes without NLA_F_NESTED Ido Schimmel
2026-09-23 11:59 ` Yuya Kusakabe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260923-lwt-encap-noflag-v1-4-8de7ab6c86e9@gmail.com \
--to=yuya.kusakabe@gmail.com \
--cc=alex.aring@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=eyal.birger@gmail.com \
--cc=herbert@gondor.apana.org.au \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=justin.iurman@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=lucien.xin@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=nicolas.dichtel@6wind.com \
--cc=pabeni@redhat.com \
--cc=razor@blackwall.org \
--cc=shuah@kernel.org \
--cc=steffen.klassert@secunet.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox