diff options
| -rw-r--r-- | conf.c | 14 | ||||
| -rw-r--r-- | test/pasta_options/dns_host_follow | 10 |
2 files changed, 22 insertions, 2 deletions
@@ -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 |
