* [PATCH container/manager/qemu-server 0/6] persist auto-generated MAC addresses of guest network devices
@ 2026-11-24 14:56 Stefan Hanreich
2026-11-24 14:56 ` [PATCH pve-container 1/6] setup: do not read datacenter.cfg inside the container's root Stefan Hanreich
` (7 more replies)
0 siblings, 8 replies; 13+ messages in thread
From: Stefan Hanreich @ 2026-11-24 14:56 UTC (permalink / raw)
To: pve-devel
A guest network device without a MAC address is valid for qemu-server
and pve-container, which generate a random one each time they parse the
device. The API always stores one, but manual edits and restored
backups can lack it, as can containers created with pve-container
3.0-8 to 3.0-10.
Since libpve-cluster-perl 9.1.11, such a container fails to start, as
the setup code reads datacenter.cfg from pmxcfs for the random MAC
address, from within the container's root:
Transport endpoint is not connected
error in setup task PVE::LXC::Setup::pre_start_hook
Without a persisted MAC address, the guest, the SDN DHCP mapping and
cloud-init each use a different random address. So persist a generated
MAC address when starting a guest, and when restoring a backup without
'unique', for containers and VMs. Starting such a guest now writes a
MAC address into the config.
Resuming or live-migrating a VM is intentionally left out, as the VM
already runs with the auto-generated MAC address. It needs a cold start
for this fix to apply.
The last patch keeps the container network panel working for devices
without a MAC address.
pve-container:
Stefan Hanreich (3):
setup: do not read datacenter.cfg inside the container's root
start: persist a MAC address for network devices without one
restore: add missing MAC addresses of the backup config
src/PVE/LXC.pm | 7 ++++-
src/PVE/LXC/Config.pm | 23 ++++++++++++++--
src/PVE/LXC/Create.pm | 3 +++
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/config_tests.pl | 53 +++++++++++++++++++++++++++++++++++++
src/test/run_setup_tests.pl | 3 +--
11 files changed, 91 insertions(+), 12 deletions(-)
qemu-server:
Stefan Hanreich (2):
start: persist a MAC address for network devices without one
restore: add missing MAC addresses of the backup config
src/PVE/QemuServer.pm | 11 +++++++
src/PVE/QemuServer/Network.pm | 30 ++++++++++++++++++
src/test/Makefile | 5 ++-
src/test/run_network_tests.pl | 38 +++++++++++++++++++++++
src/test/run_qemu_restore_config_tests.pl | 18 +++++++++++
5 files changed, 101 insertions(+), 1 deletion(-)
create mode 100755 src/test/run_network_tests.pl
pve-manager:
Stefan Hanreich (1):
ui: lxc: network: handle network devices without a MAC address
www/manager6/lxc/Network.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Summary over all repositories:
17 files changed, 193 insertions(+), 14 deletions(-)
--
Generated by murpp 0.12.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH pve-container 1/6] setup: do not read datacenter.cfg inside the container's root
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
2026-11-24 14:56 ` [PATCH pve-container 2/6] start: persist a MAC address for network devices without one Stefan Hanreich
` (6 subsequent siblings)
7 siblings, 0 replies; 13+ messages in thread
From: Stefan Hanreich @ 2026-11-24 14:56 UTC (permalink / raw)
To: pve-devel
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
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH pve-container 2/6] start: persist a MAC address for network devices without one
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 ` [PATCH pve-container 1/6] setup: do not read datacenter.cfg inside the container's root Stefan Hanreich
@ 2026-11-24 14:56 ` 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
` (5 subsequent siblings)
7 siblings, 1 reply; 13+ messages in thread
From: Stefan Hanreich @ 2026-11-24 14:56 UTC (permalink / raw)
To: pve-devel
The API always sets 'hwaddr' for a network device, but manual edits or
restored backups can lack it. For such a device, parse_lxc_network()
returns a new random MAC address on each call, so every user of the
config sees a different one:
- LXC gets none, so the kernel assigns a random address to the end of
the veth pair inside the container.
- The SDN DHCP mapping gets an address that nothing else uses.
Generate the missing MAC addresses when starting the container and
write them to the config, as already done with the pending changes.
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
src/PVE/LXC.pm | 5 +++++
src/PVE/LXC/Config.pm | 19 +++++++++++++++++++
src/test/config_tests.pl | 30 ++++++++++++++++++++++++++++++
3 files changed, 54 insertions(+)
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 53464de..1829d2b 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -3185,6 +3185,11 @@ sub vm_start {
$conf = PVE::LXC::Config->load_config($vmid); # update/reload
}
+ # without a persisted MAC address, every user of the config would see a different random one
+ if (PVE::LXC::Config->add_missing_hwaddrs($conf)) {
+ PVE::LXC::Config->write_config($vmid, $conf);
+ }
+
update_lxc_config($vmid, $conf);
eval {
diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm
index a12b975..da15194 100644
--- a/src/PVE/LXC/Config.pm
+++ b/src/PVE/LXC/Config.pm
@@ -1631,6 +1631,25 @@ sub parse_lxc_network {
return $res;
}
+# Returns whether a MAC address was added to a network device.
+sub add_missing_hwaddrs {
+ my ($class, $conf) = @_;
+
+ my $added;
+ for my $opt (sort keys %$conf) {
+ next if $opt !~ m/^net\d+$/;
+ my $net = $class->parse_lxc_network($conf->{$opt}, 1);
+ next if $net->{hwaddr};
+
+ my $dc = PVE::Cluster::cfs_read_file('datacenter.cfg');
+ $net->{hwaddr} = PVE::Tools::random_ether_addr($dc->{mac_prefix});
+ $conf->{$opt} = $class->print_lxc_network($net);
+ $added = 1;
+ }
+
+ return $added;
+}
+
sub parse_features {
my ($class, $data) = @_;
return {} if !$data;
diff --git a/src/test/config_tests.pl b/src/test/config_tests.pl
index 685ba9d..182c4bf 100755
--- a/src/test/config_tests.pl
+++ b/src/test/config_tests.pl
@@ -6,6 +6,7 @@ use warnings;
use lib qw(..);
use Test::More;
+use Test::MockModule;
use PVE::LXC::Config;
use PVE::LXC::Create;
@@ -212,4 +213,33 @@ subtest 'meta property' => sub {
ok(!exists(PVE::LXC::Config->json_config_properties({})->{meta}), 'meta cannot be set');
};
+subtest 'missing MAC addresses of network devices are added' => sub {
+ my $cluster_module = Test::MockModule->new('PVE::Cluster');
+ $cluster_module->mock(
+ cfs_read_file => sub {
+ my ($filename) = @_;
+ die "unexpected read of $filename\n" if $filename ne 'datacenter.cfg';
+ return { mac_prefix => 'BC:24:11' };
+ },
+ );
+
+ my $with_hwaddr = 'name=eth0,bridge=vmbr0,hwaddr=BC:24:11:00:00:01,type=veth';
+ my $conf = {
+ hostname => 'ct100',
+ net0 => $with_hwaddr,
+ net1 => 'name=eth1,bridge=vmbr0,type=veth',
+ };
+
+ ok(PVE::LXC::Config->add_missing_hwaddrs($conf), 'reports the added MAC address');
+ is($conf->{net0}, $with_hwaddr, 'existing MAC address is kept');
+ my $net1 = PVE::LXC::Config->parse_lxc_network($conf->{net1}, 1);
+ like($net1->{hwaddr}, qr/^BC:24:11(?::[0-9A-F]{2}){3}$/i, 'MAC address uses the prefix');
+ is($net1->{name}, 'eth1', 'other properties are kept');
+ is($conf->{hostname}, 'ct100', 'other options are kept');
+
+ my $net1_string = $conf->{net1};
+ ok(!PVE::LXC::Config->add_missing_hwaddrs($conf), 'reports nothing if all are set');
+ is($conf->{net1}, $net1_string, 'added MAC address stays');
+};
+
done_testing();
--
2.47.3
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH pve-container 3/6] restore: add missing MAC addresses of the backup config
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 ` [PATCH pve-container 1/6] setup: do not read datacenter.cfg inside the container's root Stefan Hanreich
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 14:56 ` Stefan Hanreich
2026-11-24 14:56 ` [PATCH qemu-server 4/6] start: persist a MAC address for network devices without one Stefan Hanreich
` (4 subsequent siblings)
7 siblings, 0 replies; 13+ messages in thread
From: Stefan Hanreich @ 2026-11-24 14:56 UTC (permalink / raw)
To: pve-devel
A restore without 'unique' takes over the network devices of the backup
config as they are, so a device without 'hwaddr' stays without one
until the container is started.
Add the missing MAC addresses when merging the backup config, so that
the restored config is complete right away. Existing ones are kept, as
without 'unique' the restored container should have the same addresses
as the backed up one.
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
src/PVE/LXC/Create.pm | 3 +++
src/test/config_tests.pl | 23 +++++++++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/src/PVE/LXC/Create.pm b/src/PVE/LXC/Create.pm
index c39e8ca..4a62a37 100644
--- a/src/PVE/LXC/Create.pm
+++ b/src/PVE/LXC/Create.pm
@@ -607,6 +607,9 @@ sub sanitize_and_merge_config {
}
$conf->{$key} = $oldconf->{$key} if !defined($conf->{$key});
}
+
+ # a backup can have network devices without a MAC address
+ PVE::LXC::Config->add_missing_hwaddrs($conf);
}
sub restore_configuration_from_etc_vzdump {
diff --git a/src/test/config_tests.pl b/src/test/config_tests.pl
index 182c4bf..868ea84 100755
--- a/src/test/config_tests.pl
+++ b/src/test/config_tests.pl
@@ -191,6 +191,29 @@ subtest 'restore does not take over pending changes of the backup' => sub {
}
};
+subtest 'restore adds missing MAC addresses of the backup' => sub {
+ PVE::RPCEnvironment::get()->set_user('root@pam');
+
+ my $cluster_module = Test::MockModule->new('PVE::Cluster');
+ $cluster_module->mock(
+ cfs_read_file => sub {
+ my ($filename) = @_;
+ die "unexpected read of $filename\n" if $filename ne 'datacenter.cfg';
+ return { mac_prefix => 'BC:24:11' };
+ },
+ );
+
+ my $with_hwaddr = 'name=eth0,bridge=vmbr0,hwaddr=BC:24:11:00:00:01,type=veth';
+ my $raw = "hostname: ct100\nnet0: $with_hwaddr\nnet1: name=eth1,bridge=vmbr0,type=veth\n";
+ my $backup = PVE::LXC::Config::parse_pct_config('/lxc/100.conf', $raw);
+
+ my $conf = {};
+ PVE::LXC::Create::sanitize_and_merge_config($conf, $backup, 0, 0);
+ is($conf->{net0}, $with_hwaddr, 'MAC address of the backup is kept');
+ my $net1 = PVE::LXC::Config->parse_lxc_network($conf->{net1}, 1);
+ like($net1->{hwaddr}, qr/^BC:24:11(?::[0-9A-F]{2}){3}$/i, 'missing MAC address is added');
+};
+
subtest 'meta property' => sub {
like(PVE::LXC::Config->new_meta_info_string(), qr/^ctime=\d+$/, 'creation time is set');
--
2.47.3
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH qemu-server 4/6] start: persist a MAC address for network devices without one
2026-11-24 14:56 [PATCH container/manager/qemu-server 0/6] persist auto-generated MAC addresses of guest network devices Stefan Hanreich
` (2 preceding siblings ...)
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 ` 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
` (3 subsequent siblings)
7 siblings, 1 reply; 13+ messages in thread
From: Stefan Hanreich @ 2026-11-24 14:56 UTC (permalink / raw)
To: pve-devel
The API always sets 'macaddr' for a network device, but manual edits or
restored backups can lack it. For such a device, parse_net() returns a
new random MAC address on each call, so every user of the config sees
a different one.
Generate the missing MAC addresses when starting the VM and write them
to its config, like the pending changes there, so that all of them use
the same address. Starting such a VM thus changes its config once.
Skip this when the VM is migrated or resumed from its state, as it then
already runs with a MAC address, which a new one would not match.
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
src/PVE/QemuServer.pm | 8 ++++++++
src/PVE/QemuServer/Network.pm | 30 +++++++++++++++++++++++++++
src/test/Makefile | 5 ++++-
src/test/run_network_tests.pl | 38 +++++++++++++++++++++++++++++++++++
4 files changed, 80 insertions(+), 1 deletion(-)
create mode 100755 src/test/run_network_tests.pl
diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index ecbaa27f..1e4fe203 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -5490,6 +5490,14 @@ sub vm_start_nolock {
$conf = PVE::QemuConfig->load_config($vmid); # update/reload
}
+ # without a persisted MAC address, every user of the config would see a different random one,
+ # but a VM migrated or resumed from its state already runs with one
+ if (!$statefile && !$resume && !$migratedfrom) {
+ if (PVE::QemuServer::Network::add_missing_macs($conf)) {
+ PVE::QemuConfig->write_config($vmid, $conf);
+ }
+ }
+
# don't regenerate the ISO if the VM is started as part of a live migration
# this way we can reuse the old ISO with the correct config
if (!$migratedfrom) {
diff --git a/src/PVE/QemuServer/Network.pm b/src/PVE/QemuServer/Network.pm
index 01b21f86..beaf2aca 100644
--- a/src/PVE/QemuServer/Network.pm
+++ b/src/PVE/QemuServer/Network.pm
@@ -272,6 +272,36 @@ sub add_random_macs {
}
}
+# Returns the network device with a generated MAC address if it has none.
+sub add_missing_mac {
+ my ($value) = @_;
+
+ my $net = parse_net($value, 1);
+ return $value if !$net || defined($net->{macaddr});
+
+ my $dc = PVE::Cluster::cfs_read_file('datacenter.cfg');
+ $net->{macaddr} = PVE::Tools::random_ether_addr($dc->{mac_prefix});
+
+ return print_net($net);
+}
+
+# Returns whether a MAC address was added to a network device.
+sub add_missing_macs {
+ my ($conf) = @_;
+
+ my $added;
+ for my $opt (sort keys %$conf) {
+ next if $opt !~ m/^net\d+$/;
+ my $value = add_missing_mac($conf->{$opt});
+ next if $value eq $conf->{$opt};
+
+ $conf->{$opt} = $value;
+ $added = 1;
+ }
+
+ return $added;
+}
+
sub add_nets_bridge_fdb {
my ($conf, $vmid) = @_;
diff --git a/src/test/Makefile b/src/test/Makefile
index 0d47205d..2d3a55da 100644
--- a/src/test/Makefile
+++ b/src/test/Makefile
@@ -1,6 +1,6 @@
all: test
-test: test_snapshot test_cfg_to_cmd test_cfg_to_cmd_aarch64 test_hotplug test_hotplug_aarch64 test_pci_addr_conflicts test_pci_reservation test_qemu_img_convert test_migration test_restore_config test_parse_config test_memory test_agent test_raw_config_write test_api test_api_cloudinit_dump test_mtunnel test_guest_identity
+test: test_snapshot test_cfg_to_cmd test_cfg_to_cmd_aarch64 test_hotplug test_hotplug_aarch64 test_pci_addr_conflicts test_pci_reservation test_qemu_img_convert test_migration test_restore_config test_parse_config test_memory test_agent test_raw_config_write test_api test_api_cloudinit_dump test_mtunnel test_guest_identity test_network
test_snapshot: run_snapshot_tests.pl
./run_snapshot_tests.pl
@@ -51,6 +51,9 @@ test_agent: run_agent_tests.pl
test_raw_config_write: run_raw_config_write_tests.pl
./run_raw_config_write_tests.pl
+test_network: run_network_tests.pl
+ ./run_network_tests.pl
+
test_api: run_api_tests.pl
./run_api_tests.pl
diff --git a/src/test/run_network_tests.pl b/src/test/run_network_tests.pl
new file mode 100755
index 00000000..c9eeede7
--- /dev/null
+++ b/src/test/run_network_tests.pl
@@ -0,0 +1,38 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use lib qw(..);
+
+use Test::MockModule;
+use Test::More;
+
+use PVE::QemuServer::Network;
+
+my $cluster_module = Test::MockModule->new('PVE::Cluster');
+$cluster_module->mock(
+ cfs_read_file => sub {
+ my ($filename) = @_;
+ die "unexpected read of $filename\n" if $filename ne 'datacenter.cfg';
+ return { mac_prefix => 'BC:24:11' };
+ },
+);
+
+subtest 'missing MAC addresses of network devices are added' => sub {
+ my $with_mac = 'virtio=BC:24:11:00:00:01,bridge=vmbr0';
+ my $conf = { name => 'vm100', net0 => $with_mac, net1 => 'virtio,bridge=vmbr0,firewall=1' };
+
+ ok(PVE::QemuServer::Network::add_missing_macs($conf), 'reports the added MAC address');
+ is($conf->{net0}, $with_mac, 'existing MAC address is kept');
+ my $net1 = PVE::QemuServer::Network::parse_net($conf->{net1}, 1);
+ like($net1->{macaddr}, qr/^BC:24:11(?::[0-9A-F]{2}){3}$/i, 'MAC address uses the prefix');
+ is($net1->{firewall}, 1, 'other properties are kept');
+ is($conf->{name}, 'vm100', 'other options are kept');
+
+ my $net1_string = $conf->{net1};
+ ok(!PVE::QemuServer::Network::add_missing_macs($conf), 'reports nothing if all are set');
+ is($conf->{net1}, $net1_string, 'added MAC address stays');
+};
+
+done_testing();
--
2.47.3
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH qemu-server 5/6] restore: add missing MAC addresses of the backup config
2026-11-24 14:56 [PATCH container/manager/qemu-server 0/6] persist auto-generated MAC addresses of guest network devices Stefan Hanreich
` (3 preceding siblings ...)
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 14:56 ` Stefan Hanreich
2026-11-24 14:56 ` [PATCH pve-manager 6/6] ui: lxc: network: handle network devices without a MAC address Stefan Hanreich
` (2 subsequent siblings)
7 siblings, 0 replies; 13+ messages in thread
From: Stefan Hanreich @ 2026-11-24 14:56 UTC (permalink / raw)
To: pve-devel
A restore without 'unique' takes over the network devices of the backup
config as they are, so a device without a MAC address stays without one
until the VM is started.
Add the missing MAC addresses when restoring the config, so that the
restored config is complete right away. Existing ones are kept, as
without 'unique' the restored VM should have the same addresses as the
backed up one.
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
src/PVE/QemuServer.pm | 3 +++
src/test/run_qemu_restore_config_tests.pl | 18 ++++++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index 1e4fe203..7e940e33 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -6692,6 +6692,9 @@ sub restore_update_config_line {
$net->{macaddr} = PVE::Tools::random_ether_addr($dc->{mac_prefix}) if $net->{macaddr};
$netstr = PVE::QemuServer::Network::print_net($net);
$res .= "$id: $netstr\n";
+ } elsif ($line =~ m/^(net\d+):\s*(\S+)\s*$/) {
+ # a backup can have network devices without a MAC address
+ $res .= "$1: " . PVE::QemuServer::Network::add_missing_mac($2) . "\n";
} elsif ($line =~ m/^((ide|scsi|virtio|sata|efidisk|tpmstate)\d+):\s*(\S+)\s*$/) {
my $virtdev = $1;
my $value = $3;
diff --git a/src/test/run_qemu_restore_config_tests.pl b/src/test/run_qemu_restore_config_tests.pl
index 851f0a0d..3ab81fab 100755
--- a/src/test/run_qemu_restore_config_tests.pl
+++ b/src/test/run_qemu_restore_config_tests.pl
@@ -77,6 +77,24 @@ dir_glob_foreach(
},
);
+subtest 'missing MAC addresses of the backup are added' => sub {
+ my $restore_line = sub {
+ my ($line, $unique) = @_;
+ return PVE::QemuServer::restore_update_config_line({ netcount => 0 }, {}, $line,
+ $unique);
+ };
+
+ my $with_mac = "net0: virtio=BC:24:11:00:00:01,bridge=vmbr0,firewall=1\n";
+ is($restore_line->($with_mac, 0), $with_mac, 'line with a MAC address is kept');
+
+ my $restored = $restore_line->("net1: virtio,bridge=vmbr0,firewall=1\n", 0);
+ my ($net1) = $restored =~ m/^net1: (.*)\n\z/;
+ my $net = PVE::QemuServer::Network::parse_net($net1, 1);
+ like($net->{macaddr}, qr/^[0-9A-F]{2}(?::[0-9A-F]{2}){5}$/i,
+ 'missing MAC address is added');
+ is($net->{firewall}, 1, 'other properties are kept');
+};
+
# Restores through the create API and the restore paths for PBS, backup providers, VMA and legacy
# tar archives, against the fake cluster filesystem. Storage, archive tools and other external
# effects are mocked. The backups have no disks, so that no volumes get allocated.
--
2.47.3
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH pve-manager 6/6] ui: lxc: network: handle network devices without a MAC address
2026-11-24 14:56 [PATCH container/manager/qemu-server 0/6] persist auto-generated MAC addresses of guest network devices Stefan Hanreich
` (4 preceding siblings ...)
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 ` 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 23:45 ` applied: " Thomas Lamprecht
7 siblings, 0 replies; 13+ messages in thread
From: Stefan Hanreich @ 2026-11-24 14:56 UTC (permalink / raw)
To: pve-devel
A container network device can lack 'hwaddr', for example after a
manual edit of the config, as pve-container generates a MAC address
then. Looking up the IP addresses of such a device threw an error on
the missing value, which aborted listing the network devices.
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
www/manager6/lxc/Network.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/www/manager6/lxc/Network.js b/www/manager6/lxc/Network.js
index e56d47c0..1dbaa672 100644
--- a/www/manager6/lxc/Network.js
+++ b/www/manager6/lxc/Network.js
@@ -392,7 +392,7 @@ Ext.define(
let net = structuredClone(config);
net.id = key;
- let iface = interfaces[config.hwaddr.toLowerCase()];
+ let iface = interfaces[config.hwaddr?.toLowerCase()];
if (iface) {
net.name = iface.name;
net.ip = [];
--
2.47.3
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH pve-container 2/6] start: persist a MAC address for network devices without one
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
0 siblings, 0 replies; 13+ messages in thread
From: Dominik Csapak @ 2026-11-24 18:06 UTC (permalink / raw)
To: Stefan Hanreich, pve-devel
(minor) comment inline:
On 11/24/26 3:57 PM, Stefan Hanreich wrote:
> The API always sets 'hwaddr' for a network device, but manual edits or
> restored backups can lack it. For such a device, parse_lxc_network()
> returns a new random MAC address on each call, so every user of the
> config sees a different one:
>
> - LXC gets none, so the kernel assigns a random address to the end of
> the veth pair inside the container.
> - The SDN DHCP mapping gets an address that nothing else uses.
>
> Generate the missing MAC addresses when starting the container and
> write them to the config, as already done with the pending changes.
>
> Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
> ---
> src/PVE/LXC.pm | 5 +++++
> src/PVE/LXC/Config.pm | 19 +++++++++++++++++++
> src/test/config_tests.pl | 30 ++++++++++++++++++++++++++++++
> 3 files changed, 54 insertions(+)
>
> diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
> index 53464de..1829d2b 100644
> --- a/src/PVE/LXC.pm
> +++ b/src/PVE/LXC.pm
> @@ -3185,6 +3185,11 @@ sub vm_start {
> $conf = PVE::LXC::Config->load_config($vmid); # update/reload
> }
>
> + # without a persisted MAC address, every user of the config would see a different random one
> + if (PVE::LXC::Config->add_missing_hwaddrs($conf)) {
> + PVE::LXC::Config->write_config($vmid, $conf);
> + }
> +
> update_lxc_config($vmid, $conf);
>
> eval {
> diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm
> index a12b975..da15194 100644
> --- a/src/PVE/LXC/Config.pm
> +++ b/src/PVE/LXC/Config.pm
> @@ -1631,6 +1631,25 @@ sub parse_lxc_network {
> return $res;
> }
>
> +# Returns whether a MAC address was added to a network device.
> +sub add_missing_hwaddrs {
> + my ($class, $conf) = @_;
> +
> + my $added;
> + for my $opt (sort keys %$conf) {
> + next if $opt !~ m/^net\d+$/;
> + my $net = $class->parse_lxc_network($conf->{$opt}, 1);
> + next if $net->{hwaddr};
> +
> + my $dc = PVE::Cluster::cfs_read_file('datacenter.cfg');
> + $net->{hwaddr} = PVE::Tools::random_ether_addr($dc->{mac_prefix});
> + $conf->{$opt} = $class->print_lxc_network($net);
> + $added = 1;
> + }
> +
> + return $added;
> +}
> +
we already have the code to generate a hwaddr inside parse, so wouldn't
it be easier to do
my $net = parse();
my $printed = print($net);
if ($printed ne $conf->{$opt}) {
$added = 1;
$conf->{$opt} = $printed;
}
?
that way we'd only have one place to generate the hwaddr
but imo no blocker and could be fixed up later too
similar to what is done on the qemu side
> sub parse_features {
> my ($class, $data) = @_;
> return {} if !$data;
> diff --git a/src/test/config_tests.pl b/src/test/config_tests.pl
> index 685ba9d..182c4bf 100755
> --- a/src/test/config_tests.pl
> +++ b/src/test/config_tests.pl
> @@ -6,6 +6,7 @@ use warnings;
> use lib qw(..);
>
> use Test::More;
> +use Test::MockModule;
>
> use PVE::LXC::Config;
> use PVE::LXC::Create;
> @@ -212,4 +213,33 @@ subtest 'meta property' => sub {
> ok(!exists(PVE::LXC::Config->json_config_properties({})->{meta}), 'meta cannot be set');
> };
>
> +subtest 'missing MAC addresses of network devices are added' => sub {
> + my $cluster_module = Test::MockModule->new('PVE::Cluster');
> + $cluster_module->mock(
> + cfs_read_file => sub {
> + my ($filename) = @_;
> + die "unexpected read of $filename\n" if $filename ne 'datacenter.cfg';
> + return { mac_prefix => 'BC:24:11' };
> + },
> + );
> +
> + my $with_hwaddr = 'name=eth0,bridge=vmbr0,hwaddr=BC:24:11:00:00:01,type=veth';
> + my $conf = {
> + hostname => 'ct100',
> + net0 => $with_hwaddr,
> + net1 => 'name=eth1,bridge=vmbr0,type=veth',
> + };
> +
> + ok(PVE::LXC::Config->add_missing_hwaddrs($conf), 'reports the added MAC address');
> + is($conf->{net0}, $with_hwaddr, 'existing MAC address is kept');
> + my $net1 = PVE::LXC::Config->parse_lxc_network($conf->{net1}, 1);
> + like($net1->{hwaddr}, qr/^BC:24:11(?::[0-9A-F]{2}){3}$/i, 'MAC address uses the prefix');
> + is($net1->{name}, 'eth1', 'other properties are kept');
> + is($conf->{hostname}, 'ct100', 'other options are kept');
> +
> + my $net1_string = $conf->{net1};
> + ok(!PVE::LXC::Config->add_missing_hwaddrs($conf), 'reports nothing if all are set');
> + is($conf->{net1}, $net1_string, 'added MAC address stays');
> +};
> +
> done_testing();
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH qemu-server 4/6] start: persist a MAC address for network devices without one
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
0 siblings, 0 replies; 13+ messages in thread
From: Dominik Csapak @ 2026-11-24 18:06 UTC (permalink / raw)
To: Stefan Hanreich, pve-devel
(minor) comment inline
On 11/24/26 3:57 PM, Stefan Hanreich wrote:
> The API always sets 'macaddr' for a network device, but manual edits or
> restored backups can lack it. For such a device, parse_net() returns a
> new random MAC address on each call, so every user of the config sees
> a different one.
>
> Generate the missing MAC addresses when starting the VM and write them
> to its config, like the pending changes there, so that all of them use
> the same address. Starting such a VM thus changes its config once.
>
> Skip this when the VM is migrated or resumed from its state, as it then
> already runs with a MAC address, which a new one would not match.
>
> Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
> ---
> src/PVE/QemuServer.pm | 8 ++++++++
> src/PVE/QemuServer/Network.pm | 30 +++++++++++++++++++++++++++
> src/test/Makefile | 5 ++++-
> src/test/run_network_tests.pl | 38 +++++++++++++++++++++++++++++++++++
> 4 files changed, 80 insertions(+), 1 deletion(-)
> create mode 100755 src/test/run_network_tests.pl
>
> diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
> index ecbaa27f..1e4fe203 100644
> --- a/src/PVE/QemuServer.pm
> +++ b/src/PVE/QemuServer.pm
> @@ -5490,6 +5490,14 @@ sub vm_start_nolock {
> $conf = PVE::QemuConfig->load_config($vmid); # update/reload
> }
>
> + # without a persisted MAC address, every user of the config would see a different random one,
> + # but a VM migrated or resumed from its state already runs with one
> + if (!$statefile && !$resume && !$migratedfrom) {
> + if (PVE::QemuServer::Network::add_missing_macs($conf)) {
> + PVE::QemuConfig->write_config($vmid, $conf);
> + }
> + }
> +
> # don't regenerate the ISO if the VM is started as part of a live migration
> # this way we can reuse the old ISO with the correct config
> if (!$migratedfrom) {
> diff --git a/src/PVE/QemuServer/Network.pm b/src/PVE/QemuServer/Network.pm
> index 01b21f86..beaf2aca 100644
> --- a/src/PVE/QemuServer/Network.pm
> +++ b/src/PVE/QemuServer/Network.pm
> @@ -272,6 +272,36 @@ sub add_random_macs {
> }
> }
>
> +# Returns the network device with a generated MAC address if it has none.
> +sub add_missing_mac {
> + my ($value) = @_;
> +
> + my $net = parse_net($value, 1);
> + return $value if !$net || defined($net->{macaddr});
> +
> + my $dc = PVE::Cluster::cfs_read_file('datacenter.cfg');
> + $net->{macaddr} = PVE::Tools::random_ether_addr($dc->{mac_prefix});
> +
> + return print_net($net);
> +}
> +
> +# Returns whether a MAC address was added to a network device.
> +sub add_missing_macs {
> + my ($conf) = @_;
> +
> + my $added;
> + for my $opt (sort keys %$conf) {
> + next if $opt !~ m/^net\d+$/;
> + my $value = add_missing_mac($conf->{$opt});
> + next if $value eq $conf->{$opt};
> +
> + $conf->{$opt} = $value;
> + $added = 1;
> + }
> +
> + return $added;
> +}
> +
this is very similar to 'add_random_macs' just above the context,
so this could probably be reused or unified
(could be cleaned up afterwards though)
> sub add_nets_bridge_fdb {
> my ($conf, $vmid) = @_;
>
> diff --git a/src/test/Makefile b/src/test/Makefile
> index 0d47205d..2d3a55da 100644
> --- a/src/test/Makefile
> +++ b/src/test/Makefile
> @@ -1,6 +1,6 @@
> all: test
>
> -test: test_snapshot test_cfg_to_cmd test_cfg_to_cmd_aarch64 test_hotplug test_hotplug_aarch64 test_pci_addr_conflicts test_pci_reservation test_qemu_img_convert test_migration test_restore_config test_parse_config test_memory test_agent test_raw_config_write test_api test_api_cloudinit_dump test_mtunnel test_guest_identity
> +test: test_snapshot test_cfg_to_cmd test_cfg_to_cmd_aarch64 test_hotplug test_hotplug_aarch64 test_pci_addr_conflicts test_pci_reservation test_qemu_img_convert test_migration test_restore_config test_parse_config test_memory test_agent test_raw_config_write test_api test_api_cloudinit_dump test_mtunnel test_guest_identity test_network
>
> test_snapshot: run_snapshot_tests.pl
> ./run_snapshot_tests.pl
> @@ -51,6 +51,9 @@ test_agent: run_agent_tests.pl
> test_raw_config_write: run_raw_config_write_tests.pl
> ./run_raw_config_write_tests.pl
>
> +test_network: run_network_tests.pl
> + ./run_network_tests.pl
> +
> test_api: run_api_tests.pl
> ./run_api_tests.pl
>
> diff --git a/src/test/run_network_tests.pl b/src/test/run_network_tests.pl
> new file mode 100755
> index 00000000..c9eeede7
> --- /dev/null
> +++ b/src/test/run_network_tests.pl
> @@ -0,0 +1,38 @@
> +#!/usr/bin/perl
> +
> +use strict;
> +use warnings;
> +
> +use lib qw(..);
> +
> +use Test::MockModule;
> +use Test::More;
> +
> +use PVE::QemuServer::Network;
> +
> +my $cluster_module = Test::MockModule->new('PVE::Cluster');
> +$cluster_module->mock(
> + cfs_read_file => sub {
> + my ($filename) = @_;
> + die "unexpected read of $filename\n" if $filename ne 'datacenter.cfg';
> + return { mac_prefix => 'BC:24:11' };
> + },
> +);
> +
> +subtest 'missing MAC addresses of network devices are added' => sub {
> + my $with_mac = 'virtio=BC:24:11:00:00:01,bridge=vmbr0';
> + my $conf = { name => 'vm100', net0 => $with_mac, net1 => 'virtio,bridge=vmbr0,firewall=1' };
> +
> + ok(PVE::QemuServer::Network::add_missing_macs($conf), 'reports the added MAC address');
> + is($conf->{net0}, $with_mac, 'existing MAC address is kept');
> + my $net1 = PVE::QemuServer::Network::parse_net($conf->{net1}, 1);
> + like($net1->{macaddr}, qr/^BC:24:11(?::[0-9A-F]{2}){3}$/i, 'MAC address uses the prefix');
> + is($net1->{firewall}, 1, 'other properties are kept');
> + is($conf->{name}, 'vm100', 'other options are kept');
> +
> + my $net1_string = $conf->{net1};
> + ok(!PVE::QemuServer::Network::add_missing_macs($conf), 'reports nothing if all are set');
> + is($conf->{net1}, $net1_string, 'added MAC address stays');
> +};
> +
> +done_testing();
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH container/manager/qemu-server 0/6] persist auto-generated MAC addresses of guest network devices
2026-11-24 14:56 [PATCH container/manager/qemu-server 0/6] persist auto-generated MAC addresses of guest network devices Stefan Hanreich
` (5 preceding siblings ...)
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 ` Dominik Csapak
2026-11-24 18:38 ` Dominik Csapak
2026-11-24 19:09 ` Stefan Hanreich
2026-11-24 23:45 ` applied: " Thomas Lamprecht
7 siblings, 2 replies; 13+ messages in thread
From: Dominik Csapak @ 2026-11-24 18:06 UTC (permalink / raw)
To: Stefan Hanreich, pve-devel
tested through with most container types, and some vms:
* starting generated a hwaddr as expected
* as did restore
* gui for containers now didn't fail
* starting such a vm got assigned an ip from the dhcp dnsmasq ipam
* the cloudinit config contained the correct hwaddress
(couldn't easily test the hotplug path, since that would require quite a
bit of downgrades on my side)
one thing i noticed is that editing a qemu vm with such config
still yielded:
```
Unable to parse network options
```
but that could be fixed in a follow up
code wise looks fine to me, some minor comments on one container and
qemu patch (see the individual mails)
otherwise:
Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
Tested-by: Dominik Csapak <d.csapak@proxmox.com>
On 11/24/26 3:57 PM, Stefan Hanreich wrote:
> A guest network device without a MAC address is valid for qemu-server
> and pve-container, which generate a random one each time they parse the
> device. The API always stores one, but manual edits and restored
> backups can lack it, as can containers created with pve-container
> 3.0-8 to 3.0-10.
>
> Since libpve-cluster-perl 9.1.11, such a container fails to start, as
> the setup code reads datacenter.cfg from pmxcfs for the random MAC
> address, from within the container's root:
>
> Transport endpoint is not connected
> error in setup task PVE::LXC::Setup::pre_start_hook
>
> Without a persisted MAC address, the guest, the SDN DHCP mapping and
> cloud-init each use a different random address. So persist a generated
> MAC address when starting a guest, and when restoring a backup without
> 'unique', for containers and VMs. Starting such a guest now writes a
> MAC address into the config.
>
> Resuming or live-migrating a VM is intentionally left out, as the VM
> already runs with the auto-generated MAC address. It needs a cold start
> for this fix to apply.
>
> The last patch keeps the container network panel working for devices
> without a MAC address.
>
>
> pve-container:
>
> Stefan Hanreich (3):
> setup: do not read datacenter.cfg inside the container's root
> start: persist a MAC address for network devices without one
> restore: add missing MAC addresses of the backup config
>
> src/PVE/LXC.pm | 7 ++++-
> src/PVE/LXC/Config.pm | 23 ++++++++++++++--
> src/PVE/LXC/Create.pm | 3 +++
> 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/config_tests.pl | 53 +++++++++++++++++++++++++++++++++++++
> src/test/run_setup_tests.pl | 3 +--
> 11 files changed, 91 insertions(+), 12 deletions(-)
>
>
> qemu-server:
>
> Stefan Hanreich (2):
> start: persist a MAC address for network devices without one
> restore: add missing MAC addresses of the backup config
>
> src/PVE/QemuServer.pm | 11 +++++++
> src/PVE/QemuServer/Network.pm | 30 ++++++++++++++++++
> src/test/Makefile | 5 ++-
> src/test/run_network_tests.pl | 38 +++++++++++++++++++++++
> src/test/run_qemu_restore_config_tests.pl | 18 +++++++++++
> 5 files changed, 101 insertions(+), 1 deletion(-)
> create mode 100755 src/test/run_network_tests.pl
>
>
> pve-manager:
>
> Stefan Hanreich (1):
> ui: lxc: network: handle network devices without a MAC address
>
> www/manager6/lxc/Network.js | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>
> Summary over all repositories:
> 17 files changed, 193 insertions(+), 14 deletions(-)
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH container/manager/qemu-server 0/6] persist auto-generated MAC addresses of guest network devices
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
1 sibling, 0 replies; 13+ messages in thread
From: Dominik Csapak @ 2026-11-24 18:38 UTC (permalink / raw)
To: Stefan Hanreich, pve-devel
On 11/24/26 7:06 PM, Dominik Csapak wrote:
> tested through with most container types, and some vms:
> * starting generated a hwaddr as expected
> * as did restore
> * gui for containers now didn't fail
> * starting such a vm got assigned an ip from the dhcp dnsmasq ipam
> * the cloudinit config contained the correct hwaddress
>
> (couldn't easily test the hotplug path, since that would require quite a
> bit of downgrades on my side)
>
> one thing i noticed is that editing a qemu vm with such config
> still yielded:
>
> ```
> Unable to parse network options
> ```
>
> but that could be fixed in a follow up
btw, this is fixed by my recent patch
for the parseQemuNetwork parser to allow unknown fields:
https://lore.proxmox.com/pve-devel/20261119092930.830046-5-d.csapak@proxmox.com/
(just so we avoid duplicate work)
>
> code wise looks fine to me, some minor comments on one container and
> qemu patch (see the individual mails)
>
> otherwise:
>
> Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
> Tested-by: Dominik Csapak <d.csapak@proxmox.com>
>
> On 11/24/26 3:57 PM, Stefan Hanreich wrote:
>> A guest network device without a MAC address is valid for qemu-server
>> and pve-container, which generate a random one each time they parse the
>> device. The API always stores one, but manual edits and restored
>> backups can lack it, as can containers created with pve-container
>> 3.0-8 to 3.0-10.
>>
>> Since libpve-cluster-perl 9.1.11, such a container fails to start, as
>> the setup code reads datacenter.cfg from pmxcfs for the random MAC
>> address, from within the container's root:
>>
>> Transport endpoint is not connected
>> error in setup task PVE::LXC::Setup::pre_start_hook
>>
>> Without a persisted MAC address, the guest, the SDN DHCP mapping and
>> cloud-init each use a different random address. So persist a generated
>> MAC address when starting a guest, and when restoring a backup without
>> 'unique', for containers and VMs. Starting such a guest now writes a
>> MAC address into the config.
>>
>> Resuming or live-migrating a VM is intentionally left out, as the VM
>> already runs with the auto-generated MAC address. It needs a cold start
>> for this fix to apply.
>>
>> The last patch keeps the container network panel working for devices
>> without a MAC address.
>>
>>
>> pve-container:
>>
>> Stefan Hanreich (3):
>> setup: do not read datacenter.cfg inside the container's root
>> start: persist a MAC address for network devices without one
>> restore: add missing MAC addresses of the backup config
>>
>> src/PVE/LXC.pm | 7 ++++-
>> src/PVE/LXC/Config.pm | 23 ++++++++++++++--
>> src/PVE/LXC/Create.pm | 3 +++
>> 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/config_tests.pl | 53 +++++++++++++++++++++++++++++++++++++
>> src/test/run_setup_tests.pl | 3 +--
>> 11 files changed, 91 insertions(+), 12 deletions(-)
>>
>>
>> qemu-server:
>>
>> Stefan Hanreich (2):
>> start: persist a MAC address for network devices without one
>> restore: add missing MAC addresses of the backup config
>>
>> src/PVE/QemuServer.pm | 11 +++++++
>> src/PVE/QemuServer/Network.pm | 30 ++++++++++++++++++
>> src/test/Makefile | 5 ++-
>> src/test/run_network_tests.pl | 38 +++++++++++++++++++++++
>> src/test/run_qemu_restore_config_tests.pl | 18 +++++++++++
>> 5 files changed, 101 insertions(+), 1 deletion(-)
>> create mode 100755 src/test/run_network_tests.pl
>>
>>
>> pve-manager:
>>
>> Stefan Hanreich (1):
>> ui: lxc: network: handle network devices without a MAC address
>>
>> www/manager6/lxc/Network.js | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>>
>> Summary over all repositories:
>> 17 files changed, 193 insertions(+), 14 deletions(-)
>>
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH container/manager/qemu-server 0/6] persist auto-generated MAC addresses of guest network devices
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
1 sibling, 0 replies; 13+ messages in thread
From: Stefan Hanreich @ 2026-11-24 19:09 UTC (permalink / raw)
To: Dominik Csapak, pve-devel
thanks for looking at this!
On 11/24/26 7:06 PM, Dominik Csapak wrote:
> code wise looks fine to me, some minor comments on one container and
> qemu patch (see the individual mails)
agree, I'll send a follow-up when the dust has settled!
^ permalink raw reply [flat|nested] 13+ messages in thread
* applied: [PATCH container/manager/qemu-server 0/6] persist auto-generated MAC addresses of guest network devices
2026-11-24 14:56 [PATCH container/manager/qemu-server 0/6] persist auto-generated MAC addresses of guest network devices Stefan Hanreich
` (6 preceding siblings ...)
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 23:45 ` Thomas Lamprecht
7 siblings, 0 replies; 13+ messages in thread
From: Thomas Lamprecht @ 2026-11-24 23:45 UTC (permalink / raw)
To: pve-devel, Stefan Hanreich
On Tue, 24 Nov 2026 15:56:44 +0100, Stefan Hanreich wrote:
> A guest network device without a MAC address is valid for qemu-server
> and pve-container, which generate a random one each time they parse the
> device. The API always stores one, but manual edits and restored
> backups can lack it, as can containers created with pve-container
> 3.0-8 to 3.0-10.
>
> Since libpve-cluster-perl 9.1.11, such a container fails to start, as
> the setup code reads datacenter.cfg from pmxcfs for the random MAC
> address, from within the container's root:
>
> [...]
Applied, thanks! I made some changes, please cross-check that they hold
up.
Folded into your patches:
- container: make add_missing_hwaddrs() skip a network device that does
not parse or is empty, instead of failing on it. Otherwise, restoring
a backup with such a netN line would abort after the extraction.
- qemu-server: skip templates when adding missing MAC addresses on
start. vzdump "starts" a template to back it up, but without its
network devices, so writing a MAC address into its config made no
sense.
Added as separate commits, for restart migration of containers:
- after a failed migration, start the container again with its current
config. The old one still had the migrate lock, which the new MAC
address write could then put back into the config again.
- keep the pending changes that stopping the container applied, instead
of writing the old config back, which made them pending again.
[pve-container] applied to pve-container.git (master)
[1/3] setup: do not read datacenter.cfg inside the container's root
https://git.proxmox.com/?p=pve-container.git;a=commitdiff;h=904e71b9477843dd9727dcff10fab6e3e70caae2
[2/3] start: persist a MAC address for network devices without one
https://git.proxmox.com/?p=pve-container.git;a=commitdiff;h=c520dd6f7bd415fe9f204db06ca2289e5fda1c19
[3/3] restore: add missing MAC addresses of the backup config
https://git.proxmox.com/?p=pve-container.git;a=commitdiff;h=de82290683368c40db7ea5cc62acc24bcdadab15
[pve-manager] applied to pve-manager.git (master)
[1/1] ui: lxc: network: handle network devices without a MAC address
https://git.proxmox.com/?p=pve-manager.git;a=commitdiff;h=7bdaea774e30e2de86e6d8da5092af37e373e907
[qemu-server] applied to qemu-server.git (master)
[1/2] start: persist a MAC address for network devices without one
https://git.proxmox.com/?p=qemu-server.git;a=commitdiff;h=3413b049edb68940531f36a505cf7f46343b53f0
[2/2] restore: add missing MAC addresses of the backup config
https://git.proxmox.com/?p=qemu-server.git;a=commitdiff;h=985bab4af222f5dd37c1ec26c61338ea2f8801f5
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2026-11-24 23:49 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH pve-container 1/6] setup: do not read datacenter.cfg inside the container's root Stefan Hanreich
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
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.