From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id C76CA1FF0E1 for ; Mon, 16 Nov 2026 02:00:59 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id E0CDF21700; Mon, 16 Nov 2026 02:00:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794790830; x=1795395630; darn=lists.proxmox.com; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=qNaCj5NiI4EPWgY87DVsgJf0y7AOU/la9VBsP7+dmTM=; b=TH2I6LHznGRoH5kJBlBs+qLXM3ihiCTFjvIMrxCpkAGs8643yuYZftXa2ggNsYg4lt tVTx47KDfLM/phRwILsv2nwRIt79wwgAS5GGe14cmMDBpyh9oBJnE/MCHnsC1FHY/ImZ RLJtl86vVSWL9AzbewAzWwCXSYqz6S9ybfFQj76ctq4MhoU4ABd5GETe9iBkDv8Fef6e kGPEQ7+1w8B+9MaTnujFPV7TnIzaQbowmoFb9v7FQXL3bcX4bOIeWg6oodjDbU5tSviT wyYtkZlZX4MIfQrTZLyWB9XEQxGH1yVquWETt1lO0m6UM3eeZWf9MehL9JgBCuhYW/wL vOlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794790830; x=1795395630; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=qNaCj5NiI4EPWgY87DVsgJf0y7AOU/la9VBsP7+dmTM=; b=eO/BzgrHAS+zt+gHSVLWh71lXhHQ7CBvB+wObgiU6PoAsg0fDnhSz9Pn4F6XquRUIF xTyrp8c0UIKZqqZV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 lpWxDOFyOS0ft/n9MRsNCmD03V2B/lJVEn2Iec/Su X-Received: by 2002:a05:6122:e44a:b0:5ea:e196:272b with SMTP id 71dfb90a1353d-5ee34ad0625mr2757220e0c.19.1794790829199; Sun, 15 Nov 2026 17:00:29 -0800 (PST) From: Lucas Barros To: pve-devel@lists.proxmox.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 Message-ID: <20261116010014.88737-4-lucasbarros.kam@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20261116010014.88737-1-lucasbarros.kam@gmail.com> References: <20261116010014.88737-1-lucasbarros.kam@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.075 Adjusted score from AWL reputation of From: address DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain DMARC_PASS -0.1 DMARC pass policy FREEMAIL_FROM 0.001 Sender email is commonly abused enduser mail provider POISEN_SPAM_PILL 0.1 Meta: its spam POISEN_SPAM_PILL_1 0.1 random spam to be learned in bayes POISEN_SPAM_PILL_3 0.1 random spam to be learned in bayes RCVD_IN_DNSWL_NONE -0.0001 Sender listed at https://www.dnswl.org/, no trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: YINFFOCBDNW743WJT2EXMWN4SO6QA5JG X-Message-ID-Hash: YINFFOCBDNW743WJT2EXMWN4SO6QA5JG X-MailFrom: lucasbarros.kam@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: t.lamprecht@proxmox.com, Lucas Barros X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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)