From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-container 1/6] setup: do not read datacenter.cfg inside the container's root
Date: Tue, 24 Nov 2026 15:56:45 +0100 [thread overview]
Message-ID: <20261124145651.335234-2-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20261124145651.335234-1-s.hanreich@proxmox.com>
For a network device without 'hwaddr', parse_lxc_network() generates a
random MAC address with the prefix configured in datacenter.cfg. The
setup code parses the network devices from within the root of the
container, where pmxcfs cannot be reached. Starting a container with
such a device thus fails in the pre-start hook:
Transport endpoint is not connected
error in setup task PVE::LXC::Setup::pre_start_hook
The setup code never uses the MAC address, so parse the network devices
there without generating one, which avoids reading datacenter.cfg.
Other code paths rely on the generated MAC address, so add a flag to
parse_lxc_network() for opting out of it, and set it in the setup code.
This is needed even with the generated MAC addresses persisted on
start: hotplugging a network device into a running container sets up
all of its network devices, and the others can still lack a MAC
address, for example if the container was started before.
Also make the setup tests reject any read from pmxcfs, instead of
answering reads of datacenter.cfg, so that they catch such reads.
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
src/PVE/LXC.pm | 2 +-
src/PVE/LXC/Config.pm | 4 ++--
src/PVE/LXC/Setup/Alpine.pm | 2 +-
src/PVE/LXC/Setup/Base.pm | 2 +-
src/PVE/LXC/Setup/CentOS.pm | 4 ++--
src/PVE/LXC/Setup/Debian.pm | 2 +-
src/PVE/LXC/Setup/Gentoo.pm | 2 +-
src/PVE/LXC/Setup/SUSE.pm | 2 +-
src/test/run_setup_tests.pl | 3 +--
9 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index fa498e0..53464de 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -960,7 +960,7 @@ sub get_primary_ips {
# return data from net0
return undef if !defined($conf->{net0});
- my $net = PVE::LXC::Config->parse_lxc_network($conf->{net0});
+ my $net = PVE::LXC::Config->parse_lxc_network($conf->{net0}, 1);
my $ipv4 = $net->{ip};
if ($ipv4) {
diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm
index d6f1eeb..a12b975 100644
--- a/src/PVE/LXC/Config.pm
+++ b/src/PVE/LXC/Config.pm
@@ -1616,14 +1616,14 @@ sub print_lxc_network {
}
sub parse_lxc_network {
- my ($class, $data) = @_;
+ my ($class, $data, $disable_mac_autogen) = @_;
return {} if !$data;
my $res = PVE::JSONSchema::parse_property_string($netconf_desc, $data);
$res->{type} = 'veth';
- if (!$res->{hwaddr}) {
+ if (!$res->{hwaddr} && !$disable_mac_autogen) {
my $dc = PVE::Cluster::cfs_read_file('datacenter.cfg');
$res->{hwaddr} = PVE::Tools::random_ether_addr($dc->{mac_prefix});
}
diff --git a/src/PVE/LXC/Setup/Alpine.pm b/src/PVE/LXC/Setup/Alpine.pm
index ade9e1d..4fbb3ee 100644
--- a/src/PVE/LXC/Setup/Alpine.pm
+++ b/src/PVE/LXC/Setup/Alpine.pm
@@ -91,7 +91,7 @@ sub setup_network {
my $netstring = $value;
# check for dhcp6:
- my $d = PVE::LXC::Config->parse_lxc_network($netstring);
+ my $d = PVE::LXC::Config->parse_lxc_network($netstring, 1);
if (defined($d->{ip6}) && ($d->{ip6} eq 'dhcp' || $d->{ip6} eq 'auto')) {
$d->{ip6} = 'manual';
$netstring = PVE::LXC::Config->print_lxc_network($d);
diff --git a/src/PVE/LXC/Setup/Base.pm b/src/PVE/LXC/Setup/Base.pm
index bb75690..20c8688 100644
--- a/src/PVE/LXC/Setup/Base.pm
+++ b/src/PVE/LXC/Setup/Base.pm
@@ -257,7 +257,7 @@ sub setup_systemd_networkd {
foreach my $k (keys %$conf) {
next if $k !~ m/^net(\d+)$/;
- my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k});
+ my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k}, 1);
next if !$d->{name};
my $filename = "/etc/systemd/network/$d->{name}.network";
diff --git a/src/PVE/LXC/Setup/CentOS.pm b/src/PVE/LXC/Setup/CentOS.pm
index 7e8140b..a487948 100644
--- a/src/PVE/LXC/Setup/CentOS.pm
+++ b/src/PVE/LXC/Setup/CentOS.pm
@@ -208,7 +208,7 @@ sub setup_network_with_networkmanager {
foreach my $k (keys %$conf) {
next if $k !~ m/^net(\d+)$/;
- my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k});
+ my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k}, 1);
next if !$d->{name};
my $filename = "/etc/NetworkManager/system-connections/$d->{name}.nmconnection";
@@ -295,7 +295,7 @@ sub setup_network_with_network_scripts {
foreach my $k (keys %$conf) {
next if $k !~ m/^net(\d+)$/;
- my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k});
+ my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k}, 1);
next if !$d->{name};
$has_ipv4 = 1 if defined($d->{ip});
$has_ipv6 = 1 if defined($d->{ip6});
diff --git a/src/PVE/LXC/Setup/Debian.pm b/src/PVE/LXC/Setup/Debian.pm
index 81941d7..ccf0e46 100644
--- a/src/PVE/LXC/Setup/Debian.pm
+++ b/src/PVE/LXC/Setup/Debian.pm
@@ -254,7 +254,7 @@ sub setup_network {
foreach my $k (keys %$conf) {
next if $k !~ m/^net(\d+)$/;
my $ind = $1;
- my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k});
+ my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k}, 1);
if ($d->{name}) {
my $net = {};
my $cidr;
diff --git a/src/PVE/LXC/Setup/Gentoo.pm b/src/PVE/LXC/Setup/Gentoo.pm
index 6034f27..238ebcf 100644
--- a/src/PVE/LXC/Setup/Gentoo.pm
+++ b/src/PVE/LXC/Setup/Gentoo.pm
@@ -83,7 +83,7 @@ sub setup_network {
foreach my $k (keys %$conf) {
next if $k !~ m/^net(\d+)$/;
- my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k});
+ my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k}, 1);
my $name = $d->{name};
next if !$name;
diff --git a/src/PVE/LXC/Setup/SUSE.pm b/src/PVE/LXC/Setup/SUSE.pm
index dfe1798..5496f81 100644
--- a/src/PVE/LXC/Setup/SUSE.pm
+++ b/src/PVE/LXC/Setup/SUSE.pm
@@ -76,7 +76,7 @@ sub setup_network {
foreach my $k (keys %$conf) {
next if $k !~ m/^net(\d+)$/;
- my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k});
+ my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k}, 1);
next if !$d->{name};
my $filename = "/etc/sysconfig/network/ifcfg-$d->{name}";
diff --git a/src/test/run_setup_tests.pl b/src/test/run_setup_tests.pl
index b269ffe..84fa21e 100755
--- a/src/test/run_setup_tests.pl
+++ b/src/test/run_setup_tests.pl
@@ -113,11 +113,10 @@ sub run_test {
print "TEST $testdir => OK\n";
}
+# the setup code runs inside the container's root, where pmxcfs is not reachable
my $cluster_module = Test::MockModule->new("PVE::Cluster");
$cluster_module->mock(
cfs_read_file => sub {
- my ($filename) = @_;
- return {} if $filename eq 'datacenter.cfg';
die "illegal access to pmxcfs in test!\n";
},
cfs_write_file => sub {
--
2.47.3
next prev parent reply other threads:[~2026-11-24 14:57 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 14:56 [PATCH container/manager/qemu-server 0/6] persist auto-generated MAC addresses of guest network devices Stefan Hanreich
2026-11-24 14:56 ` Stefan Hanreich [this message]
2026-11-24 14:56 ` [PATCH pve-container 2/6] start: persist a MAC address for network devices without one Stefan Hanreich
2026-11-24 18:06 ` Dominik Csapak
2026-11-24 14:56 ` [PATCH pve-container 3/6] restore: add missing MAC addresses of the backup config Stefan Hanreich
2026-11-24 14:56 ` [PATCH qemu-server 4/6] start: persist a MAC address for network devices without one Stefan Hanreich
2026-11-24 18:06 ` Dominik Csapak
2026-11-24 14:56 ` [PATCH qemu-server 5/6] restore: add missing MAC addresses of the backup config Stefan Hanreich
2026-11-24 14:56 ` [PATCH pve-manager 6/6] ui: lxc: network: handle network devices without a MAC address Stefan Hanreich
2026-11-24 18:06 ` [PATCH container/manager/qemu-server 0/6] persist auto-generated MAC addresses of guest network devices Dominik Csapak
2026-11-24 18:38 ` Dominik Csapak
2026-11-24 19:09 ` Stefan Hanreich
2026-11-24 23:45 ` applied: " Thomas Lamprecht
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=20261124145651.335234-2-s.hanreich@proxmox.com \
--to=s.hanreich@proxmox.com \
--cc=pve-devel@lists.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox