aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorAditya Merchant <adityamerchant08@gmail.com>2026-12-04 13:01:18 +0530
committerStefano Brivio <sbrivio@redhat.com>2026-12-04 22:54:33 +0100
commit08e09ec2bc76e667559abef6e06a8e1429a615fb (patch)
tree06b6f561a8a7e90717fefd9520f2abd4586996c9
parent955fd3e7b900a66c2ba0cafb5b1bfa45286452c3 (diff)
downloadpasst-08e09ec2bc76e667559abef6e06a8e1429a615fb.tar
passt-08e09ec2bc76e667559abef6e06a8e1429a615fb.tar.gz
passt-08e09ec2bc76e667559abef6e06a8e1429a615fb.tar.bz2
passt-08e09ec2bc76e667559abef6e06a8e1429a615fb.tar.lz
passt-08e09ec2bc76e667559abef6e06a8e1429a615fb.tar.xz
passt-08e09ec2bc76e667559abef6e06a8e1429a615fb.tar.zst
passt-08e09ec2bc76e667559abef6e06a8e1429a615fb.zip
conf: Forget host nameserver once it's removed from resolv.conf
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> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--conf.c14
-rw-r--r--test/pasta_options/dns_host_follow10
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