public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH] test/pasta/dhcp: Fix DHCP tests for --config-net pasta setup
@ 2026-06-21  1:27 Jon Maloy
  0 siblings, 0 replies; only message in thread
From: Jon Maloy @ 2026-06-21  1:27 UTC (permalink / raw)
  To: sbrivio, david, jmaloy, passt-dev

setup_pasta() now passes --config-net, which pre-configures the
namespace interface via NDP/SLAAC before dhclient runs. This caused
several issues:

- dhclient -6 using the host's dhclient-script failed inside user
  namespaces (NetworkManager hooks, resolv.conf writes), causing
  infinite SOLICIT/REPLY loops. Add a minimal dhclient-script that
  applies leases with 'ip addr replace' and exits cleanly.

- The DHCPv6 address check filtered for prefixlen == 128, but
  --config-net already configures the address with /64 via SLAAC,
  and 'ip -6 addr replace' cannot change the prefix length of an
  existing address. Match by scope == "global" instead.

- Copy dhclient to STATEDIR and use explicit lease files to avoid
  conflicts with the host's dhclient state.

- Quote variable expansions in test comparisons to prevent failures
  on empty values.

Signed-off-by: Jon Maloy <jmaloy@redhat.com>
---
 test/lib/dhclient-script | 17 +++++++++++++++++
 test/pasta/dhcp          | 14 ++++++++------
 2 files changed, 25 insertions(+), 6 deletions(-)
 create mode 100755 test/lib/dhclient-script

diff --git a/test/lib/dhclient-script b/test/lib/dhclient-script
new file mode 100755
index 00000000..c6f4c0fc
--- /dev/null
+++ b/test/lib/dhclient-script
@@ -0,0 +1,17 @@
+#!/bin/sh
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Minimal dhclient-script for pasta tests. The host's dhclient-script
+# fails inside user namespaces (NetworkManager hooks, resolv.conf
+# writes, etc.), so we use this stripped-down version instead.
+# Based on the guest script in test/passt.mbuto.
+
+[ -n "${new_interface_mtu}" ]       && ip link set dev ${interface} mtu ${new_interface_mtu}
+
+[ -n "${new_ip_address}" ]          && ip addr replace ${new_ip_address}/${new_subnet_mask} dev ${interface}
+[ -n "${new_routers}" ]             && for r in ${new_routers}; do ip route replace default via ${r} dev ${interface}; done
+
+[ -n "${new_ip6_address}" ]         && ip -6 addr replace ${new_ip6_address}/${new_ip6_prefixlen:-128} dev ${interface} nodad
+
+exit 0
diff --git a/test/pasta/dhcp b/test/pasta/dhcp
index 366935ff..5d7e78b6 100644
--- a/test/pasta/dhcp
+++ b/test/pasta/dhcp
@@ -19,30 +19,32 @@ nsout	IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifnam
 check	[ -n "__IFNAME__" ]
 
 test	DHCP: address
-ns	/sbin/dhclient -4 --no-pid __IFNAME__
+ns	cp /sbin/dhclient __STATEDIR__/dhclient
+ns	__STATEDIR__/dhclient -4 --no-pid -lf __STATEDIR__/dhclient4.leases __IFNAME__
+sleep	1
 nsout	ADDR ip -j -4 addr show|jq -rM '.[] | select(.ifname == "__IFNAME__").addr_info[0].local'
 hout	HOST_ADDR ip -j -4 addr show|jq -rM '.[] | select(.ifname == "__IFNAME__").addr_info[0].local'
-check	[ __ADDR__ = __HOST_ADDR__ ]
+check	[ "__ADDR__" = "__HOST_ADDR__" ]
 
 test	DHCP: route
 nsout	GW ip -j -4 route show|jq -rM '.[] | select(.dst == "default").gateway'
 hout	HOST_GW ip -j -4 route show|jq -rM '[.[] | select(.dst == "default").gateway] | .[0]'
-check	[ __GW__ = __HOST_GW__ ]
+check	[ "__GW__" = "__HOST_GW__" ]
 
 test	DHCP: MTU
 nsout	MTU ip -j link show | jq -rM '.[] | select(.ifname == "__IFNAME__").mtu'
 check	[ __MTU__ = 65520 ]
 
 test	DHCPv6: address
-ns	/sbin/dhclient -6 --no-pid __IFNAME__
+ns	__STATEDIR__/dhclient -6 -sf __BASEPATH__/lib/dhclient-script --no-pid -lf __STATEDIR__/dhclient6.leases __IFNAME__
 # Wait for DAD to complete
 ns	while ip -j -6 addr show tentative | jq -e '.[].addr_info'; do sleep 0.1; done
 hout	HOST_IFNAME6 ip -j -6 route show|jq -rM '[.[] | select(.dst == "default").dev] | .[0]'
-nsout	ADDR6 ip -j -6 addr show|jq -rM '[.[] | select(.ifname == "__IFNAME__").addr_info[] | select(.prefixlen == 128).local] | .[0]'
+nsout	ADDR6 ip -j -6 addr show|jq -rM '[.[] | select(.ifname == "__IFNAME__").addr_info[] | select(.scope == "global").local] | .[0]'
 hout	HOST_ADDR6 ip -j -6 addr show|jq -rM '[.[] | select(.ifname == "__HOST_IFNAME6__").addr_info[] | select(.scope != "host" and .scope != "link" and .deprecated != true).local] | join(" ")'
 check	echo "__HOST_ADDR6__" | grep -wq "__ADDR6__"
 
 test	DHCPv6: route
 nsout	GW6 ip -j -6 route show|jq -rM '.[] | select(.dst == "default").gateway'
 hout	HOST_GW6 ip -j -6 route show|jq -rM '[.[] | select(.dst == "default").gateway] | .[0]'
-check	[ __GW6__ = __HOST_GW6__ ]
+check	[ "__GW6__" = "__HOST_GW6__" ]
-- 
2.52.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-06-21  1:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-21  1:27 [PATCH] test/pasta/dhcp: Fix DHCP tests for --config-net pasta setup Jon Maloy

Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).