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 778DD1FF066 for ; Tue, 24 Nov 2026 15:57:27 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 5FF592170E; Tue, 24 Nov 2026 15:57:06 +0100 (CET) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server 5/6] restore: add missing MAC addresses of the backup config Date: Tue, 24 Nov 2026 15:56:49 +0100 Message-ID: <20261124145651.335234-6-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: 1795532219956 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.182 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: MQIQCTZ2PQBTSNYWM75FP3U7KAUXKWQA X-Message-ID-Hash: MQIQCTZ2PQBTSNYWM75FP3U7KAUXKWQA 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 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 --- 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