From: Stefano Brivio <sbrivio@redhat.com>
To: Aditya Merchant <adityamerchant08@gmail.com>
Cc: passt-dev@passt.top, David Gibson <david@gibson.dropbear.id.au>,
Paul Holzinger <pholzing@redhat.com>
Subject: Re: [PATCH v2 1/2] conf: Follow changes to the host nameserver used for DNS forwarding
Date: Mon, 30 Nov 2026 01:34:40 +0100 (CET) [thread overview]
Message-ID: <20261130013439.0a40738a@elisabeth> (raw)
In-Reply-To: <20261113112114.38764-2-adityamerchant08@gmail.com>
Hi Aditya,
On Fri, 13 Nov 2026 16:51:13 +0530
Aditya Merchant <adityamerchant08@gmail.com> wrote:
> We read the host's /etc/resolv.conf once, at start, and forward queries
> sent to the --dns-forward address to the first nameserver listed there.
> If the host then joins another network, connects to a VPN, or pasta
> starts before the network is configured, that nameserver goes stale and
> name resolution in the namespace stops working until pasta restarts.
> With rootless Podman, that means stopping every container using the
> rootless network namespace.
>
> In pasta mode, if we forward DNS queries for an IP version, and the host
> nameserver for it comes from resolv.conf (no --dns-host or --dns), watch
> resolv.conf with inotify and read it again as it changes, so that new
> DNS flows go to its current first nameserver. Watch the directory, not
> the file, as NetworkManager and others replace resolv.conf by renaming
> a new file over it. If resolv.conf is a symbolic link, watch the
> directory of its target, as long as that's also called resolv.conf:
> the other usual target, systemd-resolved's stub-resolv.conf, always
> points to its local stub resolver anyway.
>
> Once sandboxed, we can't open files by path, and keeping a descriptor
> for the directory would undo the filesystem isolation: lookups of ".."
> from it reach the rest of the host filesystem. Instead, right after
> isolate_prefork() unshares our mount namespace, and before mounts become
> unbindable, take a detached copy of the directory with open_tree() and
> OPEN_TREE_CLONE: lookups from its root can't go above it, so the
> directory holding resolv.conf is all we can still see. Make that copy
> read-only, and only ever open resolv.conf from it. This needs Linux 5.12
> or later: if any step fails, or if we can't read resolv.conf through the
> copy, we don't follow changes.
>
> AppArmor resolves paths of files on a detached mount relative to their
> filesystem, so allow the usual locations of resolv.conf under /run with
> paths relative to /run, too. For SELinux, allow watching /etc, and the
> directories under /run used by NetworkManager and systemd-resolved.
>
> Flows that already exist keep their target, so a client reusing the
> same source port keeps reaching the old nameserver until its flow
> expires.
>
> The new test replaces resolv.conf on an overlay mounted on /etc, in a
> separate mount namespace, and checks that we pick up the new nameserver.
>
> Link: https://github.com/podman-container-tools/podman/issues/29130
> Link: https://archives.passt.top/passt-dev/20230121104703.3ebcc753@elisabeth/
> Signed-off-by: Aditya Merchant <adityamerchant08@gmail.com>
Applied, thanks for your patience and for the significant feature, and
welcome to the git log!
I finally had the chance to test this with a few different configurations,
with SELinux and AppArmor, it all works. I still have a few comments,
below, that might be relevant for follow-ups.
> [...]
>
> @@ -281,6 +310,216 @@ out:
> }
> }
>
> +/* Name of host's resolv.conf, or of the target of a symbolic link to it, that
> + * we follow changes to: see conf_resolv_watch()
> + */
> +#define RESOLV_NAME "resolv.conf"
> +
> +/**
> + * conf_resolv_update() - Update host nameservers from host's resolv.conf
> + * @c: Execution context
> + *
> + * Return: 0 on success, negative error code if the file can't be opened
> + *
> + * #syscalls:pasta openat
In case you extend this to passt as well, don't forget to update the
count of allowed system calls for x86_64 in README.md, that is:
-* ✅ restrictive seccomp profiles (34 syscalls allowed for _passt_, 43 for
+* ✅ restrictive seccomp profiles (35 syscalls allowed for _passt_, 43 for
_pasta_ on x86_64)
> + */
> +static int conf_resolv_update(struct ctx *c)
> +{
> + bool found4 = false, found6 = false;
> + char addr[INET6_ADDRSTRLEN];
> + struct lineread resolvconf;
> + struct in6_addr ns6;
> + struct in_addr ns4;
> + char *line;
> + int fd;
> +
> + fd = openat(c->resolv_dir_fd, RESOLV_NAME, O_RDONLY | O_CLOEXEC);
> + if (fd < 0)
> + return -errno;
> +
> + lineread_init(&resolvconf, fd);
> + while (lineread_get(&resolvconf, &line) > 0) {
> + const char *p = resolv_nameserver(line);
> +
> + if (!p)
> + continue;
> +
> + if (!found4)
> + found4 = inet_pton(AF_INET, p, &ns4) == 1;
> + if (!found6)
> + found6 = inet_pton(AF_INET6, p, &ns6) == 1;
> + }
> + close(fd);
> +
> + 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)));
> + }
> +
> + if (c->ip6.dns_host_resolv && found6 &&
> + !IN6_ARE_ADDR_EQUAL(&ns6, &c->ip6.dns_host)) {
> + c->ip6.dns_host = ns6;
> + info("Forwarding DNS queries to new host nameserver %s",
> + inet_ntop(AF_INET6, &ns6, addr, sizeof(addr)));
> + }
If we didn't find any nameserver for a given IP version, but we had one
in .dns_host, we'll keep that one instead of removing it.
It should be harmless, I think, because in the worst case we'll just
try to attempt reaching a stale and possibly unreachable DNS server,
but it might be unexpected (the user might have removed the server for
a specific reason, and expects us now to remove it as well) and also
inconsistent with what we do at start-up time.
So, I guess, we could / should clear .dns_host on !found4 or !found6.
> [...]
>
> +++ b/passt.1
> @@ -287,7 +287,10 @@ Configure the host nameserver which guest or namespace queries to the
> \fB\-\-dns-forward\fR address will be redirected to. This option can
> be specified zero to two times (once for IPv4, once for IPv6).
> By default, the first nameserver from the host's
> -\fI/etc/resolv.conf\fR.
> +\fI/etc/resolv.conf\fR. In pasta mode, on Linux 5.12 or later, this
In case you extend this to passt, don't forget to drop "In pasta
mode...".
> +default follows changes to that file: new DNS flows go to its current
> +first nameserver of the same IP version, while existing flows keep their
> +target until they expire.
The "its" makes it a bit hard to read, I think: it's not obvious that
it refers to "that file", but, if it refers to it, then it doesn't
really add much.
That is, I think something like: "[...] new DNS flows go to the first
nameserver listed for each IP version" would probably be clearer and
include all the relevant information.
--
Stefano
next prev parent reply other threads:[~2026-11-30 0:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 11:21 [PATCH v2 0/2] Follow changes to the host nameserver " Aditya Merchant
2026-11-13 11:21 ` [PATCH v2 1/2] conf: Follow changes to the host nameserver used " Aditya Merchant
2026-11-17 16:35 ` Laurent Vivier
2026-11-30 0:34 ` Stefano Brivio [this message]
2026-11-13 11:21 ` [PATCH v2 2/2] pasta: Terminate inotify buffer, skip nameless events in netns watch Aditya Merchant
2026-11-17 13:15 ` Laurent Vivier
2026-11-19 0:21 ` [PATCH v2 0/2] Follow changes to the host nameserver for DNS forwarding 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=20261130013439.0a40738a@elisabeth \
--to=sbrivio@redhat.com \
--cc=adityamerchant08@gmail.com \
--cc=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=pholzing@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).