From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 11D391FF066 for ; Tue, 24 Nov 2026 15:57:37 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 5E4CA21733; Tue, 24 Nov 2026 15:57:09 +0100 (CET) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Subject: [PATCH pve-container 3/6] restore: add missing MAC addresses of the backup config Date: Tue, 24 Nov 2026 15:56:47 +0100 Message-ID: <20261124145651.335234-4-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261124145651.335234-1-s.hanreich@proxmox.com> References: <20261124145651.335234-1-s.hanreich@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795532219827 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.187 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: OLBYM255OKRPRZUFKHLNXFJXCZJSGFAE X-Message-ID-Hash: OLBYM255OKRPRZUFKHLNXFJXCZJSGFAE X-MailFrom: s.hanreich@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: 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 --- 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