From: Aditya Merchant <adityamerchant08@gmail.com>
To: passt-dev@passt.top
Cc: Stefano Brivio <sbrivio@redhat.com>,
David Gibson <david@gibson.dropbear.id.au>,
Paul Holzinger <pholzing@redhat.com>,
Laurent Vivier <lvivier@redhat.com>
Subject: [PATCH 2/3] conf: Forget host nameserver once it's removed from resolv.conf
Date: Fri, 4 Dec 2026 13:01:18 +0530 [thread overview]
Message-ID: <20261204073119.31027-3-adityamerchant08@gmail.com> (raw)
In-Reply-To: <20261204073119.31027-1-adityamerchant08@gmail.com>
When we follow changes to resolv.conf, and it doesn't list a nameserver
for an IP version anymore, conf_resolv_update() keeps the one we had
before, and we keep redirecting DNS queries to it.
That's not what we do at start-up, where get_dns() leaves .dns_host
unspecified if there's no nameserver for that IP version, and it's
probably not what users expect either: a nameserver might have been
removed for a reason. Clear .dns_host in that case, so that we stop
redirecting DNS queries for that IP version, until a nameserver is
listed again.
Extend the dns_host_follow test to check this. As that takes a few more
steps, keep pasta running until a file shows up, instead of for a fixed
time, which could end before the last step.
Suggested-by: Stefano Brivio <sbrivio@redhat.com>
Link: https://archives.passt.top/passt-dev/20261130013439.0a40738a@elisabeth/
Signed-off-by: Aditya Merchant <adityamerchant08@gmail.com>
---
conf.c | 14 ++++++++++++++
test/pasta_options/dns_host_follow | 10 ++++++++--
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/conf.c b/conf.c
index d3976d3..7a271ff 100644
--- a/conf.c
+++ b/conf.c
@@ -352,11 +352,20 @@ static int conf_resolv_update(struct ctx *c)
}
close(fd);
+ /* If resolv.conf doesn't list a nameserver for an IP version anymore,
+ * forget the one we had, as if we started now: we don't redirect DNS
+ * queries for that IP version until a nameserver shows up again
+ */
if (c->ip4.dns_host_resolv && found4 &&
!IN4_ARE_ADDR_EQUAL(&ns4, &c->ip4.dns_host)) {
c->ip4.dns_host = ns4;
info("Forwarding DNS queries to new host nameserver %s",
inet_ntop(AF_INET, &ns4, addr, sizeof(addr)));
+ } else if (c->ip4.dns_host_resolv && !found4 &&
+ !IN4_IS_ADDR_UNSPECIFIED(&c->ip4.dns_host)) {
+ info("Stopped forwarding DNS queries to removed nameserver %s",
+ inet_ntop(AF_INET, &c->ip4.dns_host, addr, sizeof(addr)));
+ c->ip4.dns_host = in4addr_any;
}
if (c->ip6.dns_host_resolv && found6 &&
@@ -364,6 +373,11 @@ static int conf_resolv_update(struct ctx *c)
c->ip6.dns_host = ns6;
info("Forwarding DNS queries to new host nameserver %s",
inet_ntop(AF_INET6, &ns6, addr, sizeof(addr)));
+ } else if (c->ip6.dns_host_resolv && !found6 &&
+ !IN6_IS_ADDR_UNSPECIFIED(&c->ip6.dns_host)) {
+ info("Stopped forwarding DNS queries to removed nameserver %s",
+ inet_ntop(AF_INET6, &c->ip6.dns_host, addr, sizeof(addr)));
+ c->ip6.dns_host = in6addr_any;
}
return 0;
diff --git a/test/pasta_options/dns_host_follow b/test/pasta_options/dns_host_follow
index 2d7ac6d..d8cc232 100644
--- a/test/pasta_options/dns_host_follow
+++ b/test/pasta_options/dns_host_follow
@@ -13,16 +13,22 @@ htools unshare mount grep
test Host nameserver follows changes to resolv.conf
set DIR __STATEDIR__/resolv
set LOG_FILE __STATEDIR__/resolv.log
+set DONE __STATEDIR__/resolv.done
passt unshare -rUm
passt mkdir -p __DIR__/upper __DIR__/work
passt mount -t overlay -o lowerdir=/etc,upperdir=__DIR__/upper,workdir=__DIR__/work none /etc
passt echo "nameserver 192.0.2.1" > /etc/r && mv /etc/r /etc/resolv.conf
-passt ./pasta -d -l __LOG_FILE__ --dns-forward 192.0.2.53 -- sleep 3 2>/dev/null &
+passt ./pasta -d -l __LOG_FILE__ --dns-forward 192.0.2.53 -- sh -c 'while [ ! -e __DONE__ ]; do sleep 0.1; done' 2>/dev/null &
sleep 1
passt echo "nameserver 192.0.2.2" > /etc/r && mv /etc/r /etc/resolv.conf
sleep 1
check grep -q "new host nameserver 192.0.2.2" __LOG_FILE__
-passt wait
+
+test Host nameserver removed from resolv.conf is forgotten
+passt echo "nameserver 2001:db8::1" > /etc/r && mv /etc/r /etc/resolv.conf
+sleep 1
+passt touch __DONE__ && wait
+check grep -q "removed nameserver 192.0.2.2" __LOG_FILE__
passt umount /etc
passt exit
--
2.50.1 (Apple Git-155)
next prev parent reply other threads:[~2026-12-04 7:31 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 7:31 [PATCH 0/3] DNS forwarding: follow nameserver changes in passt mode too Aditya Merchant
2026-12-04 7:31 ` [PATCH 1/3] passt.1: Say plainly which nameserver new DNS flows go to Aditya Merchant
2026-12-04 21:35 ` Jon Maloy
2026-12-04 7:31 ` Aditya Merchant [this message]
2026-12-04 22:15 ` [PATCH 2/3] conf: Forget host nameserver once it's removed from resolv.conf Jon Maloy
2026-12-04 22:36 ` Stefano Brivio
2026-12-04 7:31 ` [PATCH 3/3] conf: Follow changes to the host nameserver in passt mode, too Aditya Merchant
2026-12-04 22:31 ` [PATCH 0/3] DNS forwarding: follow nameserver changes in passt mode too Stefano Brivio
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=20261204073119.31027-3-adityamerchant08@gmail.com \
--to=adityamerchant08@gmail.com \
--cc=david@gibson.dropbear.id.au \
--cc=lvivier@redhat.com \
--cc=passt-dev@passt.top \
--cc=pholzing@redhat.com \
--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).