From: Yingjie Wang <x-professor@outlook.com>
To: "netdev@vger.kernel.org" <netdev@vger.kernel.org>
Cc: Yingjie Wang <x-professor@outlook.com>,
"dsahern@kernel.org" <dsahern@kernel.org>,
"idosch@nvidia.com" <idosch@nvidia.com>,
"davem@davemloft.net" <davem@davemloft.net>,
"edumazet@kernel.org" <edumazet@kernel.org>,
"kuba@kernel.org" <kuba@kernel.org>,
"pabeni@redhat.com" <pabeni@redhat.com>,
"horms@kernel.org" <horms@kernel.org>,
"herbert@gondor.apana.org.au" <herbert@gondor.apana.org.au>,
"shuah@kernel.org" <shuah@kernel.org>,
"linux-kselftest@vger.kernel.org"
<linux-kselftest@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCH net 2/2] selftests: net: test devinet inheritance after failed writes
Date: Thu, 29 Oct 2026 14:30:37 +0000 [thread overview]
Message-ID: <8910b7d6fd3f4ed7e7bddd746e759d660d05f1c0.1793283257.git.x-professor@outlook.com> (raw)
In-Reply-To: <cover.1793283257.git.x-professor@outlook.com>
A failed per-device IPv4 sysctl write must not mark the setting as
explicitly configured. Otherwise, later conf/default updates stop
propagating to that device.
Add a test which rejects an invalid lo/arp_ignore write and then checks
that lo inherits a new default. Keep loopback unconfigured because adding
its address marks all devconf settings as explicit. Also verify the
complementary case: a valid same-value write marks the setting as explicit
and prevents inheritance.
Before each case, change the default to a value different from the current
lo value and require lo to inherit it. This avoids depending on init_net
defaults and skips the test if inherited state has already disabled
propagation.
The failed-write case fails on the base kernel. Both cases pass with the
preceding fix.
Signed-off-by: Yingjie Wang <x-professor@outlook.com>
---
tools/testing/selftests/net/Makefile | 1 +
tools/testing/selftests/net/devinet_conf.sh | 101 ++++++++++++++++++++
2 files changed, 102 insertions(+)
create mode 100755 tools/testing/selftests/net/devinet_conf.sh
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index df215e1a62621..f551bd40bab80 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -26,6 +26,7 @@ TEST_PROGS := \
cmsg_so_priority.sh \
cmsg_time.sh \
cork_fragsize.py \
+ devinet_conf.sh \
double_udp_encap.sh \
drop_monitor_tests.sh \
ecmp_rehash.sh \
diff --git a/tools/testing/selftests/net/devinet_conf.sh b/tools/testing/selftests/net/devinet_conf.sh
new file mode 100755
index 0000000000000..54655dc2b0bd8
--- /dev/null
+++ b/tools/testing/selftests/net/devinet_conf.sh
@@ -0,0 +1,101 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+source lib.sh
+
+cleanup()
+{
+ cleanup_all_ns
+}
+
+trap cleanup EXIT
+
+prepare_inheritance()
+{
+ local ns=$1
+ local result=$2
+ local current
+ local probe
+ local value
+
+ if ! current=$(ip netns exec "$ns" \
+ sysctl -n net.ipv4.conf.lo.arp_ignore); then
+ echo "ERROR: failed to read lo/arp_ignore in $ns"
+ return "$ksft_fail"
+ fi
+ if ((current == 0)); then
+ probe=1
+ else
+ probe=0
+ fi
+
+ if ! ip netns exec "$ns" sysctl -qw \
+ net.ipv4.conf.default.arp_ignore="$probe"; then
+ echo "ERROR: failed to update default/arp_ignore in $ns"
+ return "$ksft_fail"
+ fi
+ if ! value=$(ip netns exec "$ns" \
+ sysctl -n net.ipv4.conf.lo.arp_ignore); then
+ echo "ERROR: failed to read lo/arp_ignore in $ns"
+ return "$ksft_fail"
+ fi
+ if ((value != probe)); then
+ echo "SKIP: lo/arp_ignore does not inherit conf/default in $ns"
+ return "$ksft_skip"
+ fi
+
+ printf -v "$result" '%d' "$probe"
+}
+
+# Adding the loopback address marks all devconf settings as explicit.
+# Leave it unconfigured so default inheritance remains active.
+failed_ns="failed-$(mktemp -u XXXXXX)"
+if ! ip netns add "$failed_ns"; then
+ echo "Failed to create network namespace $failed_ns"
+ exit "$ksft_skip"
+fi
+NS_LIST+=("$failed_ns")
+
+explicit_ns="explicit-$(mktemp -u XXXXXX)"
+if ! ip netns add "$explicit_ns"; then
+ echo "Failed to create network namespace $explicit_ns"
+ exit "$ksft_skip"
+fi
+NS_LIST+=("$explicit_ns")
+
+prepare_inheritance "$failed_ns" failed_value
+ret=$?
+((ret == 0)) || exit "$ret"
+prepare_inheritance "$explicit_ns" explicit_value
+ret=$?
+((ret == 0)) || exit "$ret"
+failed_next=$((!failed_value))
+explicit_next=$((!explicit_value))
+
+RET=0
+ip netns exec "$failed_ns" sh -c \
+ 'printf x > /proc/sys/net/ipv4/conf/lo/arp_ignore' 2>/dev/null
+check_fail $? "invalid arp_ignore write was accepted"
+ip netns exec "$failed_ns" sysctl -qw \
+ net.ipv4.conf.default.arp_ignore="$failed_next"
+check_err $? "failed to update default arp_ignore"
+value=$(ip netns exec "$failed_ns" sysctl -n net.ipv4.conf.lo.arp_ignore)
+check_err $? "failed to read lo arp_ignore"
+check_err "$((value != failed_next))" \
+ "failed write prevented lo from inheriting arp_ignore"
+log_test "Failed devinet write preserves inheritance"
+
+RET=0
+ip netns exec "$explicit_ns" sysctl -qw \
+ net.ipv4.conf.lo.arp_ignore="$explicit_value"
+check_err $? "failed to explicitly set lo arp_ignore"
+ip netns exec "$explicit_ns" sysctl -qw \
+ net.ipv4.conf.default.arp_ignore="$explicit_next"
+check_err $? "failed to update default arp_ignore"
+value=$(ip netns exec "$explicit_ns" sysctl -n net.ipv4.conf.lo.arp_ignore)
+check_err $? "failed to read lo arp_ignore"
+check_err "$((value != explicit_value))" \
+ "explicit lo arp_ignore unexpectedly inherited the default"
+log_test "Valid same-value devinet write prevents inheritance"
+
+exit "$EXIT_STATUS"
--
2.43.0
next prev parent reply other threads:[~2026-10-29 14:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 14:30 [PATCH net 0/2] ipv4: preserve devinet inheritance after unparsed writes Yingjie Wang
2026-10-29 14:30 ` [PATCH net 1/2] ipv4: devinet: update inheritance state only after parsed writes Yingjie Wang
2026-10-29 19:58 ` Ido Schimmel
2026-10-30 11:45 ` Yingjie Wang
2026-10-29 14:30 ` Yingjie Wang [this message]
2026-10-29 14:34 ` [PATCH net 0/2] ipv4: preserve devinet inheritance after unparsed writes netdev-bot+sinfo
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=8910b7d6fd3f4ed7e7bddd746e759d660d05f1c0.1793283257.git.x-professor@outlook.com \
--to=x-professor@outlook.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
/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
all inboxes | Powered by JetHome®