* [PATCH common/manager v3 0/2] fix #6357: show all search domains in the node DNS settings
@ 2026-11-16 13:31 Lucas Barros
2026-11-16 13:31 ` [PATCH common v3 1/2] inotify: resolv.conf: add reader that keeps the whole search list Lucas Barros
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Lucas Barros @ 2026-11-16 13:31 UTC (permalink / raw)
To: pve-devel; +Cc: t.lamprecht, Lucas Barros
The DNS settings of a node only show the first domain of the 'search'
line of resolv.conf, so saving the dialog again drops the others.
As suggested by Thomas, v3 keeps the 'resolvconf' parser as it is, as
PVE and PMG use its value to build the FQDN of the node certificate and
more. It adds a new reader that keeps the whole search list, and only
the node DNS API uses it.
* 1/2 pve-common: new reader, and a test for both readers
* 2/2 pve-manager: GET /nodes/{node}/dns uses the new reader, needs
the bumped pve-common
The obsolete 'domain' directive only takes one domain (resolv.conf(5)),
so both readers only use its first word.
changes since v2:
* new approach: keep the old parser, add a new reader for the DNS API
* 'domain' only uses its first word, with a regression test
* dropped the pve-cluster and qemu-server patches, they are not needed
anymore
Tested on a PVE 9 node (libpve-common-perl 9.2.8, pve-manager 9.2.26,
files patched in place) with three search domains set via resolvectl:
* GET .../dns returns all three; a PUT with that value writes all
three and GET returns them again
* the node certificate ('pvecm updatecerts --force') and the cloud-init
DNS fallback of a VM still only use the first domain, as before
* 'domain a.example b.example' is read as 'a.example' by both readers
'make check' in pve-common passes before and after (17 new checks; if
'domain' is parsed as a list, 2 of them fail), proxmox-perltidy reports
no changes.
The cloud-init 'fqdn' issue from v2 2/3 (a VM with several entries in
its own 'searchdomain') is not related to this anymore, I can send it
on its own.
v2: https://lore.proxmox.com/pve-devel/20261116010014.88737-1-lucasbarros.kam@gmail.com/
v1: https://lore.proxmox.com/pve-devel/20261107223019.21361-1-lucasbarros.kam@gmail.com/
This series was prepared with the help of an LLM based coding
assistant; I reviewed the changes and ran the tests mentioned above
myself.
common:
Lucas Barros (1):
inotify: resolv.conf: add reader that keeps the whole search list
src/PVE/INotify.pm | 29 ++++++++++--
test/Makefile | 1 +
test/resolv_conf_test.pl | 97 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 124 insertions(+), 3 deletions(-)
create mode 100755 test/resolv_conf_test.pl
manager:
Lucas Barros (1):
fix #6357: api: node dns: return all search domains
PVE/API2/Nodes.pm | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--
2.50.1 (Apple Git-155)
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH common v3 1/2] inotify: resolv.conf: add reader that keeps the whole search list 2026-11-16 13:31 [PATCH common/manager v3 0/2] fix #6357: show all search domains in the node DNS settings Lucas Barros @ 2026-11-16 13:31 ` Lucas Barros 2026-11-16 13:31 ` [PATCH manager v3 2/2] fix #6357: api: node dns: return all search domains Lucas Barros 2026-11-18 1:42 ` partially-applied: [PATCH common/manager v3 0/2] fix #6357: show all search domains in the node DNS settings Thomas Lamprecht 2 siblings, 0 replies; 4+ messages in thread From: Lucas Barros @ 2026-11-16 13:31 UTC (permalink / raw) To: pve-devel; +Cc: t.lamprecht, Lucas Barros The 'resolvconf' parser only keeps the first domain of the 'search' directive. Some users rely on that, for example to build the FQDN of the node certificate, both in PVE and PMG, so it stays as it is. Add read_resolv_conf_with_search_list(), which returns all domains of the 'search' directive, separated by a single space, for the node DNS API. As resolv.conf(5) documents that the obsolete 'domain' directive only takes one domain, only its first word is used in both readers. Add a test for both readers. Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com> --- changes since v2: * keep read_file('resolvconf') as it was and add a new reader for the node DNS API, as PMG uses the old one too (node certificate, get_host_dns_info(), pmg-smtp-filter) * only use the first word of the obsolete 'domain' directive, as documented in resolv.conf(5), with a regression test for it This patch was prepared with the help of an LLM based coding assistant; I reviewed the change and ran the tests from the cover letter myself. src/PVE/INotify.pm | 29 ++++++++++-- test/Makefile | 1 + test/resolv_conf_test.pl | 97 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 3 deletions(-) create mode 100755 test/resolv_conf_test.pl diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm index 53b4e21..ea9b069 100644 --- a/src/PVE/INotify.pm +++ b/src/PVE/INotify.pm @@ -601,15 +601,17 @@ sub write_etc_hosts { register_file('etchosts', "/etc/hosts", \&read_etc_hosts, \&write_etc_hosts); -sub read_etc_resolv_conf { - my ($filename, $fh) = @_; +my sub parse_resolv_conf { + my ($fh, $all_search_domains) = @_; my $res = {}; my $nscount = 0; while (my $line = <$fh>) { chomp $line; - if ($line =~ m/^(search|domain)\s+(\S+)\s*/) { + if ($all_search_domains && $line =~ m/^search\s+(\S.*)$/) { + $res->{search} = join(' ', split(/\s+/, $1)); + } elsif ($line =~ m/^(search|domain)\s+(\S+)\s*/) { $res->{search} = $2; } elsif ($line =~ m/^\s*nameserver\s+($PVE::Tools::IPRE)\s*/) { $nscount++; @@ -622,6 +624,27 @@ sub read_etc_resolv_conf { return $res; } +# only returns the first search domain, as callers use it to build an FQDN +sub read_etc_resolv_conf { + my ($filename, $fh) = @_; + + return parse_resolv_conf($fh, 0); +} + +# like read_file('resolvconf'), but returns all domains of a 'search' directive, separated by a +# single space. the obsolete 'domain' directive only takes one domain, see resolv.conf(5). +sub read_resolv_conf_with_search_list { + my ($filename) = @_; + + $filename //= '/etc/resolv.conf'; + + open(my $fh, '<', $filename) or return undef; + my $res = parse_resolv_conf($fh, 1); + close($fh); + + return $res; +} + sub update_etc_resolv_conf { my ($filename, $fh, $resolv, @args) = @_; 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..00b7f68 --- /dev/null +++ b/test/resolv_conf_test.pl @@ -0,0 +1,97 @@ +#!/usr/bin/perl + +use v5.36; + +use lib '../src'; + +use File::Temp; +use Test::More; + +use PVE::INotify; + +my $tests = [ + { + name => 'single search domain', + input => "search example.com\nnameserver 192.0.2.1\n", + first => { search => 'example.com', dns1 => '192.0.2.1' }, + list => { 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", + first => { search => 'a.example', dns1 => '192.0.2.1' }, + list => { 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", + first => { search => 'a.example', dns1 => '192.0.2.1' }, + list => { search => 'a.example b.example', dns1 => '192.0.2.1' }, + }, + { + name => 'domain directive', + input => "domain example.com\nnameserver 192.0.2.1\n", + first => { search => 'example.com', dns1 => '192.0.2.1' }, + list => { search => 'example.com', dns1 => '192.0.2.1' }, + }, + { + name => 'domain directive with trailing words', + input => "domain a.example b.example\nnameserver 192.0.2.1\n", + first => { search => 'a.example', dns1 => '192.0.2.1' }, + list => { search => 'a.example', dns1 => '192.0.2.1' }, + }, + { + name => 'last of search and domain wins', + input => "search a.example b.example\ndomain c.example d.example\n", + first => { search => 'c.example' }, + list => { search => 'c.example' }, + }, + { + 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", + first => { dns1 => '192.0.2.1', dns2 => '192.0.2.2', dns3 => '2001:db8::1' }, + list => { dns1 => '192.0.2.1', dns2 => '192.0.2.2', dns3 => '2001:db8::1' }, + }, +]; + +for my $test ($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->{first}, "first search domain: $test->{name}"); + + my $tmp = File::Temp->new(); + print $tmp $test->{input}; + close($tmp); + $res = PVE::INotify::read_resolv_conf_with_search_list($tmp->filename); + is_deeply($res, $test->{list}, "search list: $test->{name}"); +} + +is( + PVE::INotify::read_resolv_conf_with_search_list('/nonexistent/resolv.conf'), + undef, + 'search list: missing file', +); + +{ + 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', + ); + + my $tmp = File::Temp->new(); + print $tmp $data; + close($tmp); + my $res = PVE::INotify::read_resolv_conf_with_search_list($tmp->filename); + is($res->{search}, 'a.example b.example', 'update: read back multiple search domains'); +} + +done_testing(); -- 2.50.1 (Apple Git-155) ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH manager v3 2/2] fix #6357: api: node dns: return all search domains 2026-11-16 13:31 [PATCH common/manager v3 0/2] fix #6357: show all search domains in the node DNS settings Lucas Barros 2026-11-16 13:31 ` [PATCH common v3 1/2] inotify: resolv.conf: add reader that keeps the whole search list Lucas Barros @ 2026-11-16 13:31 ` Lucas Barros 2026-11-18 1:42 ` partially-applied: [PATCH common/manager v3 0/2] fix #6357: show all search domains in the node DNS settings Thomas Lamprecht 2 siblings, 0 replies; 4+ messages in thread From: Lucas Barros @ 2026-11-16 13:31 UTC (permalink / raw) To: pve-devel; +Cc: t.lamprecht, Lucas Barros The DNS settings of a node with multiple search domains could be written, 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. Use the new reader from pve-common that keeps the whole search list. The other users of the 'resolvconf' file, like the node certificate or the guest DNS fallback, keep getting only the first domain. Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com> --- changes since v2: * new in v3: only the node DNS API switches to the whole search list * needs 1/2, so the libpve-common-perl dependency has to be bumped This patch was prepared with the help of an LLM based coding assistant; I reviewed the change and ran the tests from the cover letter myself. PVE/API2/Nodes.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm index 1e2a96f1..7f0b029d 100644 --- a/PVE/API2/Nodes.pm +++ b/PVE/API2/Nodes.pm @@ -1621,7 +1621,7 @@ __PACKAGE__->register_method({ code => sub { my ($param) = @_; - my $res = PVE::INotify::read_file('resolvconf'); + my $res = PVE::INotify::read_resolv_conf_with_search_list(); return $res; }, -- 2.50.1 (Apple Git-155) ^ permalink raw reply related [flat|nested] 4+ messages in thread
* partially-applied: [PATCH common/manager v3 0/2] fix #6357: show all search domains in the node DNS settings 2026-11-16 13:31 [PATCH common/manager v3 0/2] fix #6357: show all search domains in the node DNS settings Lucas Barros 2026-11-16 13:31 ` [PATCH common v3 1/2] inotify: resolv.conf: add reader that keeps the whole search list Lucas Barros 2026-11-16 13:31 ` [PATCH manager v3 2/2] fix #6357: api: node dns: return all search domains Lucas Barros @ 2026-11-18 1:42 ` Thomas Lamprecht 2 siblings, 0 replies; 4+ messages in thread From: Thomas Lamprecht @ 2026-11-18 1:42 UTC (permalink / raw) To: pve-devel, Lucas Barros On Mon, 16 Nov 2026 10:31:06 -0300, Lucas Barros wrote: > The DNS settings of a node only show the first domain of the 'search' > line of resolv.conf, so saving the dialog again drops the others. > > As suggested by Thomas, v3 keeps the 'resolvconf' parser as it is, as > PVE and PMG use its value to build the FQDN of the node certificate and > more. It adds a new reader that keeps the whole search list, and only > the node DNS API uses it. > > [...] Applied the common part for now: [common] [1/1] inotify: resolv.conf: add reader that keeps the whole search list https://git.proxmox.com/?p=pve-common.git;a=commitdiff;h=9fb3e39d89414858fd3b7a57d07cec4c8a7c894e ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-18 1:43 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-16 13:31 [PATCH common/manager v3 0/2] fix #6357: show all search domains in the node DNS settings Lucas Barros 2026-11-16 13:31 ` [PATCH common v3 1/2] inotify: resolv.conf: add reader that keeps the whole search list Lucas Barros 2026-11-16 13:31 ` [PATCH manager v3 2/2] fix #6357: api: node dns: return all search domains Lucas Barros 2026-11-18 1:42 ` partially-applied: [PATCH common/manager v3 0/2] fix #6357: show all search domains in the node DNS settings Thomas Lamprecht
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox