public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Jon Maloy <jmaloy@redhat.com>
To: sbrivio@redhat.com, david@gibson.dropbear.id.au,
	jmaloy@redhat.com, passt-dev@passt.top
Subject: [PATCH] test/pasta/dhcp: Fix DHCP tests for --config-net pasta setup
Date: Sat, 20 Jun 2026 21:27:13 -0400	[thread overview]
Message-ID: <20260621012713.2007724-1-jmaloy@redhat.com> (raw)

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


                 reply	other threads:[~2026-06-21  1:27 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260621012713.2007724-1-jmaloy@redhat.com \
    --to=jmaloy@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    --cc=sbrivio@redhat.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.
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).