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 C73941FF0BC for ; Mon, 16 Nov 2026 13:27:01 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 9D37021712; Mon, 16 Nov 2026 13:26:58 +0100 (CET) Content-Type: text/plain; charset=UTF-8 Date: Mon, 16 Nov 2026 13:26:52 +0100 Message-Id: Subject: Re: [PATCH container] fix #7388: prefer container DNS config over host-managed DHCP From: "Elias Huhsovitz" To: "Filip Schauer" , Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: aerc 0.20.0 References: <20260311112057.48653-1-f.schauer@proxmox.com> In-Reply-To: <20260311112057.48653-1-f.schauer@proxmox.com> X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794832012918 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.416 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium 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: 4TVMHLDDGJP742CUJFNAEUT2TAEL4EPL X-Message-ID-Hash: 4TVMHLDDGJP742CUJFNAEUT2TAEL4EPL X-MailFrom: e.huhsovitz@proxmox.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 X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: I like general approach you took here. I think passing a custom dhclient config via `dhclient -cf `, makes future maintenance easier, should similar problems arise. Some comments inline. On Wed Mar 11, 2026 at 12:20 PM CET, Filip Schauer wrote: > For host-managed container network interfaces using DHCP, dhclient may > overwrite /etc/resolv.conf with DNS information supplied by the DHCP > server, causing any explicitly configured nameserver/searchdomain to be > silently ignored. > > Fix this with a custom dhclient.conf that ensures the container config > takes precedence over any DNS settings offered by the DHCP server. > > Signed-off-by: Filip Schauer > --- > src/PVE/LXC.pm | 46 +++++++++++++++++++++++++++++++++++++++------- > 1 file changed, 39 insertions(+), 7 deletions(-) > > diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm > index 9633451..c4d4a11 100644 > --- a/src/PVE/LXC.pm > +++ b/src/PVE/LXC.pm > @@ -5,7 +5,7 @@ use warnings; > =20 > use Cwd qw(); > use Errno qw(ELOOP ENOTDIR EROFS ECONNREFUSED EEXIST); > -use Fcntl qw(O_RDONLY O_WRONLY O_NOFOLLOW O_DIRECTORY O_CREAT :mode); > +use Fcntl qw(O_RDONLY O_WRONLY O_NOFOLLOW O_DIRECTORY O_CREAT SEEK_SET := mode); > use File::Basename; > use File::Path; > use File::Spec; > @@ -1324,12 +1324,42 @@ sub get_interfaces { > } > =20 > sub manage_dhclient { > - my ($action, $vmid, $ipversion, $eth, $rootdir) =3D @_; > + my ($action, $vmid, $conf, $ipversion, $eth, $rootdir) =3D @_; > =20 > File::Path::make_path("/var/lib/lxc/$vmid/hook") if $action eq 'star= t'; > my $pidfile =3D "/var/lib/lxc/$vmid/hook/dhclient$ipversion-$eth.pid= "; > my $leasefile =3D "/var/lib/lxc/$vmid/hook/dhclient$ipversion-$eth.l= eases"; > my $scriptfile =3D '/usr/share/lxc/hooks/dhclient-script'; > + > + # Copied from /etc/dhcp/dhclient.conf in isc-dhcp-client Debian pack= age > + my $config =3D > + "option rfc3442-classless-static-routes code 121 =3D array of un= signed integer 8;\n" > + . "send host-name =3D gethostname();\n" > + . "request subnet-mask, broadcast-address, time-offset, routers,= " > + . "domain-name, domain-name-servers, domain-search, host-name, " > + . "dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sn= tp-servers, " > + . "netbios-name-servers, netbios-scope, interface-mtu, " > + . "rfc3442-classless-static-routes, ntp-servers;\n"; > + > + if ($ipversion =3D=3D 6) { > + if (my @nameservers =3D grep { /$IPV6RE/ } PVE::Tools::split_lis= t($conf->{nameserver})) { nit: The regex $IPV6RE is not anchored > + $config .=3D "supersede dhcp6.name-servers " . join(", ", @n= ameservers) . ";\n"; > + } > + } elsif (my @nameservers =3D grep { /$IPV4RE/ } PVE::Tools::split_li= st($conf->{nameserver})) { > + $config .=3D "supersede domain-name-servers " . join(", ", @name= servers) . ";\n"; > + } > + > + if (my @searchdomains =3D PVE::Tools::split_list($conf->{searchdomai= n})) { > + $config .=3D "supersede " . (($ipversion =3D=3D 6) ? "dhcp6." : = "") . "domain-search "; > + $config .=3D join(", ", map { "\"$_\"" } @searchdomains) . ";\n"= ; > + } > + > + open(my $configfh, '+>', undef) or die "failed to create dhclient co= nfig: $!"; > + print $configfh $config; > + $configfh->flush(); > + sysseek($configfh, 0, SEEK_SET); Isn't this redundant? fileno() shouldnt care about the current offset. > + my $configfile =3D "/proc/$$/fd/" . fileno($configfh); Theoretically fileno, can fail (return -1), according to: https://perldoc.perl.org/functions/fileno So we should check for this, instead of concatinating a faulty string, e.g. /proc/whatever/fd/-1 > + > PVE::Tools::run_command([ > 'lxc-attach', > '-n', > @@ -1351,6 +1381,8 @@ sub manage_dhclient { > "ROOTFS=3D$rootdir", > '-sf', > $scriptfile, > + '-cf', > + $configfile, > $eth, > ]); I am operating under the assumption that you did not intend for a behaviour change outside of fixing bug #7388: Now we always pass the newly defined config file. If no config file is supplied to dhclient via `-cf` then the default /etc/dhcp/dhclient.conf is used. This is the current status status quo. If a user has a custom /etc/dhcp/dhclient.conf and upgrades to to this patch, it might silenty override his container dhcp configuration. IMO the patch is only safe for stock proxmox setups where /etc/dhcp/dhclient.conf hasn't been tempered with too much. My idea for a fix would be to: Read the current /etc/dhcp/dhclient.conf and adapt it accordingly with the necesarry `supersede` statements. Additionally this config is generated even when manage_dhclient is called with $action=3D'stop', which seems unnecessary. > } > @@ -1411,10 +1443,10 @@ sub update_ipconfig { > my $is_real_ip =3D ($newip && $newip !~ /^(?:auto|dhcp|manual)$/= ); > if ($change_ip) { > if ($newnet->{'host-managed'} && $newip && $newip eq 'dhcp')= { > - manage_dhclient('start', $vmid, $ipversion, $eth, $rootd= ir); > + manage_dhclient('start', $vmid, $conf, $ipversion, $eth,= $rootdir); > } > if ($optdata->{'host-managed'} && $oldip && $oldip eq 'dhcp'= ) { > - manage_dhclient('stop', $vmid, $ipversion, $eth, $rootdi= r); > + manage_dhclient('stop', $vmid, $conf, $ipversion, $eth, = $rootdir); > } > =20 > if ($is_real_ip) { > @@ -1425,7 +1457,7 @@ sub update_ipconfig { > } > } > } elsif ($optdata->{'host-managed'} && !$newnet->{'host-managed'= }) { > - manage_dhclient('stop', $vmid, $ipversion, $eth, $rootdir); > + manage_dhclient('stop', $vmid, $conf, $ipversion, $eth, $roo= tdir); > } > =20 > # step 2: replace gateway > @@ -3227,12 +3259,12 @@ sub vm_start { > my $rootdir =3D "/proc/$pid/root"; > =20 > for my $eth (@managed_dhcpv4_interfaces) { > - eval { manage_dhclient('start', $vmid, 4, $eth, $rootdir) }; > + eval { manage_dhclient('start', $vmid, $conf, 4, $eth, $rootdir)= }; > PVE::RESTEnvironment::log_warn("DHCP failed - $@") if $@; > } > =20 > for my $eth (@managed_dhcpv6_interfaces) { > - eval { manage_dhclient('start', $vmid, 6, $eth, $rootdir) }; > + eval { manage_dhclient('start', $vmid, $conf, 6, $eth, $rootdir)= }; > PVE::RESTEnvironment::log_warn("DHCP failed - $@") if $@; > } > =20