From: Lucas Barros <lucasbarros.kam@gmail.com>
To: pve-devel@lists.proxmox.com
Cc: t.lamprecht@proxmox.com, Lucas Barros <lucasbarros.kam@gmail.com>
Subject: [PATCH common v2 3/3] fix #6357: inotify: resolv.conf: parse all search domains
Date: Sun, 15 Nov 2026 22:00:13 -0300 [thread overview]
Message-ID: <20261116010014.88737-4-lucasbarros.kam@gmail.com> (raw)
In-Reply-To: <20261116010014.88737-1-lucasbarros.kam@gmail.com>
The 'search' line of /etc/resolv.conf can list multiple domains, but
the parser only kept the first one. Writing the DNS settings of a node
with multiple search domains worked, but reading them back, for example
in the node's DNS panel in the web UI, only showed the first domain, so
saving the dialog again silently dropped the others.
Keep the whole list, with the domains separated by a single space. This
is the format the DNS API already accepts when writing.
The other users of the value: the node certificate generation in
pve-cluster appends it to the node name, so it needs to only take the
first domain before this is applied. The cloud-init code in qemu-server
and the container setup code in pve-container use it as the DNS search
list of guests without their own setting and already split it on
whitespace, so those guests now get the full list of the host.
Add a small test for the parser.
Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
---
changes since v1:
* commit message: describe all users of the value
* depends on 1/3, which keeps the node certificate on the first domain
* tested on a PVE 9 node and with 'make check' there
Users of the value, in all repos that read 'resolvconf':
* pve-manager, GET /nodes/{node}/dns: now returns the whole list
* pve-cluster, gen_pve_ssl_cert(): FQDN for CN and SAN, see 1/3
* qemu-server, Cloudinit get_dns_conf(): search list for VMs without
their own searchdomain/nameserver, split on whitespace
* pve-container, Setup::Base lookup_dns_conf(): same for containers,
used for their resolv.conf and /etc/hosts, split with split_list()
bin/pveperf in pve-manager reads /etc/resolv.conf itself and keeps
using the first domain for its DNS test.
Behavior change for guests without their own setting: they get all
search domains of the host instead of only the first. For containers
this also adds 'ct.b.example' etc. to /etc/hosts, the same as when the
container's own searchdomain has several entries (bug #5605 asked to
avoid that, Fabian answered the file can be overridden). If you would
rather keep the guest fallback on the first domain, I can do that in
qemu-server and pve-container instead.
This patch was prepared with the help of an LLM based coding assistant; I
reviewed the change and ran the tests mentioned above myself.
src/PVE/INotify.pm | 4 +--
test/Makefile | 1 +
test/resolv_conf_test.pl | 65 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 68 insertions(+), 2 deletions(-)
create mode 100755 test/resolv_conf_test.pl
diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm
index 53b4e21..4a0355e 100644
--- a/src/PVE/INotify.pm
+++ b/src/PVE/INotify.pm
@@ -609,8 +609,8 @@ sub read_etc_resolv_conf {
my $nscount = 0;
while (my $line = <$fh>) {
chomp $line;
- if ($line =~ m/^(search|domain)\s+(\S+)\s*/) {
- $res->{search} = $2;
+ if ($line =~ m/^(search|domain)\s+(\S.*)$/) {
+ $res->{search} = join(' ', split(/\s+/, $2));
} elsif ($line =~ m/^\s*nameserver\s+($PVE::Tools::IPRE)\s*/) {
$nscount++;
if ($nscount <= 3) {
diff --git a/test/Makefile b/test/Makefile
index 9caba10..416bc0c 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -19,6 +19,7 @@ TESTS = lock_file.test \
ticket_test.test \
check_pem_test.test \
split_pem_test.test \
+ resolv_conf_test.test \
all:
diff --git a/test/resolv_conf_test.pl b/test/resolv_conf_test.pl
new file mode 100755
index 0000000..87dd716
--- /dev/null
+++ b/test/resolv_conf_test.pl
@@ -0,0 +1,65 @@
+#!/usr/bin/perl
+
+use v5.36;
+
+use lib '../src';
+
+use Test::More;
+
+use PVE::INotify;
+
+my $read_tests = [
+ {
+ name => 'single search domain',
+ input => "search example.com\nnameserver 192.0.2.1\n",
+ expected => { search => 'example.com', dns1 => '192.0.2.1' },
+ },
+ {
+ name => 'multiple search domains',
+ input => "search a.example b.example c.example\nnameserver 192.0.2.1\n",
+ expected => { search => 'a.example b.example c.example', dns1 => '192.0.2.1' },
+ },
+ {
+ name => 'multiple search domains with extra whitespace',
+ input => "search\ta.example b.example \t\nnameserver 192.0.2.1\n",
+ expected => { search => 'a.example b.example', dns1 => '192.0.2.1' },
+ },
+ {
+ name => 'domain keyword',
+ input => "domain example.com\nnameserver 192.0.2.1\n",
+ expected => { search => 'example.com', dns1 => '192.0.2.1' },
+ },
+ {
+ name => 'only the first three name servers',
+ input => "nameserver 192.0.2.1\nnameserver 192.0.2.2\n"
+ . "nameserver 2001:db8::1\nnameserver 192.0.2.4\n",
+ expected => { dns1 => '192.0.2.1', dns2 => '192.0.2.2', dns3 => '2001:db8::1' },
+ },
+];
+
+for my $test ($read_tests->@*) {
+ open(my $fh, '<', \$test->{input}) or die "failed to open in-memory file - $!\n";
+ my $res = PVE::INotify::read_etc_resolv_conf('/etc/resolv.conf', $fh);
+ is_deeply($res, $test->{expected}, "read: $test->{name}");
+}
+
+{
+ my $input = "search old.example\nnameserver 192.0.2.1\noptions rotate\n";
+ open(my $fh, '<', \$input) or die "failed to open in-memory file - $!\n";
+ my $data = PVE::INotify::update_etc_resolv_conf(
+ '/etc/resolv.conf',
+ $fh,
+ { search => 'a.example b.example', dns1 => '192.0.2.2' },
+ );
+ is(
+ $data,
+ "search a.example b.example\nnameserver 192.0.2.2\noptions rotate\n",
+ 'update: write multiple search domains',
+ );
+
+ open($fh, '<', \$data) or die "failed to open in-memory file - $!\n";
+ my $res = PVE::INotify::read_etc_resolv_conf('/etc/resolv.conf', $fh);
+ is($res->{search}, 'a.example b.example', 'update: read back multiple search domains');
+}
+
+done_testing();
--
2.50.1 (Apple Git-155)
next prev parent reply other threads:[~2026-11-16 1:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-07 22:30 [PATCH common] fix #6357: inotify: resolv.conf: parse all search domains Lucas Barros
2026-11-11 23:15 ` Thomas Lamprecht
2026-11-16 1:00 ` [PATCH cluster/qemu-server/common v2 0/3] fix #6357: parse all search domains of resolv.conf Lucas Barros
2026-11-16 1:00 ` [PATCH cluster v2 1/3] setup: node certificate: only use the first search domain for the FQDN Lucas Barros
2026-11-16 1:00 ` [PATCH qemu-server v2 2/3] cloudinit: " Lucas Barros
2026-11-16 1:00 ` Lucas Barros [this message]
2026-11-16 1:48 ` [PATCH cluster/qemu-server/common v2 0/3] fix #6357: parse all search domains of resolv.conf Thomas Lamprecht
2026-11-16 13:32 ` superseded: " Lucas Barros
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=20261116010014.88737-4-lucasbarros.kam@gmail.com \
--to=lucasbarros.kam@gmail.com \
--cc=pve-devel@lists.proxmox.com \
--cc=t.lamprecht@proxmox.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.