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 3BBF81FF066 for ; Tue, 24 Nov 2026 18:57:47 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 6DFDB216DE; Tue, 24 Nov 2026 18:57:31 +0100 (CET) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox-ve-rs 3/7] ve-config: guest: accept network devices without a MAC address Date: Tue, 24 Nov 2026 18:57:13 +0100 Message-ID: <20261124175718.512428-4-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261124175718.512428-1-s.hanreich@proxmox.com> References: <20261124175718.512428-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: 1795543046737 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.178 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: KK7EBOWQ3HXXHHHNIU3WCBSPM7M6OMHT X-Message-ID-Hash: KK7EBOWQ3HXXHHHNIU3WCBSPM7M6OMHT 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: qemu-server and pve-container accept network devices without a MAC address and generate a random one each time they parse the device. The API always stores a MAC address, but a manual edit or a restored backup can lack it. proxmox-firewall failed to parse such a config, and with it the whole firewall configuration of the node, if the guest had a firewall config. Make the MAC address optional for both guest types, and return an Option from mac_address(), so that users have to decide how to handle a device without one. Also take the model as default key, as qemu-server does, so that a device like 'virtio,bridge=vmbr0' without a MAC address can be parsed. As unknown models are accepted, a bare unknown word now parses as a network device as well, so test an invalid value with a property that neither guest type has instead. Signed-off-by: Stefan Hanreich --- proxmox-ve-config/src/guest/vm.rs | 56 ++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/proxmox-ve-config/src/guest/vm.rs b/proxmox-ve-config/src/guest/vm.rs index e809c2e0..ec6cbc91 100644 --- a/proxmox-ve-config/src/guest/vm.rs +++ b/proxmox-ve-config/src/guest/vm.rs @@ -77,7 +77,7 @@ impl FromStr for NetworkDeviceModel { pub struct QemuNetworkDevice { model: NetworkDeviceModel, #[serde(rename = "macaddr")] - mac_address: MacAddress, + mac_address: Option, firewall: Option, } @@ -93,7 +93,7 @@ impl ApiType for QemuNetworkDevice { ), ( "macaddr", - false, + true, &StringSchema::new("mac address for this network device").schema(), ), ( @@ -104,6 +104,7 @@ impl ApiType for QemuNetworkDevice { ]), ) .additional_properties(true) + .default_key("model") .key_alias_info(KeyAliasInfo::new( "model", &sorted!([ @@ -207,7 +208,7 @@ pub struct LxcNetworkDevice { #[serde(rename = "type", default = "default_lxc_network_device_model")] ty: NetworkDeviceModel, #[serde(rename = "hwaddr")] - mac_address: MacAddress, + mac_address: Option, // never read, requiring it tells container network devices apart from QEMU ones #[serde(rename = "name")] _name: String, @@ -228,7 +229,7 @@ impl ApiType for LxcNetworkDevice { ), ( "hwaddr", - false, + true, &StringSchema::new("mac address for this network device").schema(), ), ( @@ -276,8 +277,8 @@ impl NetworkDevice { } } - /// Returns the MAC address of the network device - pub fn mac_address(&self) -> MacAddress { + /// Returns the MAC address of the network device, if set in the configuration. + pub fn mac_address(&self) -> Option { match self { NetworkDevice::Qemu(qemu_network_device) => qemu_network_device.mac_address, NetworkDevice::Lxc(lxc_network_device) => lxc_network_device.mac_address, @@ -469,7 +470,7 @@ mod tests { network_device, NetworkDevice::Qemu(QemuNetworkDevice { model: NetworkDeviceModel::VirtIO, - mac_address: MacAddress::new([0xAA, 0xAA, 0xAA, 0x17, 0x19, 0x81]), + mac_address: Some(MacAddress::new([0xAA, 0xAA, 0xAA, 0x17, 0x19, 0x81])), firewall: Some(true), }) ); @@ -482,7 +483,7 @@ mod tests { network_device, NetworkDevice::Qemu(QemuNetworkDevice { model: NetworkDeviceModel::VirtIO, - mac_address: MacAddress::new([0xAA, 0xAA, 0xAA, 0x17, 0x19, 0x81]), + mac_address: Some(MacAddress::new([0xAA, 0xAA, 0xAA, 0x17, 0x19, 0x81])), firewall: None, }) ); @@ -497,7 +498,7 @@ mod tests { network_device, NetworkDevice::Qemu(QemuNetworkDevice { model: NetworkDeviceModel::VirtIO, - mac_address: MacAddress::new([0xAA, 0xAA, 0xAA, 0x17, 0x19, 0x81]), + mac_address: Some(MacAddress::new([0xAA, 0xAA, 0xAA, 0x17, 0x19, 0x81])), firewall: Some(true), }) ); @@ -514,16 +515,33 @@ mod tests { NetworkDevice::Lxc(LxcNetworkDevice { ty: NetworkDeviceModel::Veth, _name: "eth0".to_string(), - mac_address: MacAddress::new([0xAA, 0xAA, 0xAA, 0xE2, 0x3E, 0x24]), + mac_address: Some(MacAddress::new([0xAA, 0xAA, 0xAA, 0xE2, 0x3E, 0x24])), firewall: Some(false), ip: Some(LxcIpv4Addr::Dhcp), ip6: None, }) ); - "model=virtio" - .parse::() - .expect_err("invalid network configuration"); + network_device = "virtio,bridge=public" + .parse() + .expect("valid network configuration"); + + assert_eq!( + network_device, + NetworkDevice::Qemu(QemuNetworkDevice { + model: NetworkDeviceModel::VirtIO, + mac_address: None, + firewall: None, + }) + ); + + network_device = "model=virtio".parse().expect("valid network configuration"); + assert_eq!(network_device.mac_address(), None); + + network_device = "name=eth0,bridge=public" + .parse() + .expect("valid network configuration"); + assert_eq!(network_device.mac_address(), None); network_device = "name=eth0,bridge=public,firewall=1,hwaddr=AA:AA:AA:E2:3E:25" .parse() @@ -534,7 +552,7 @@ mod tests { NetworkDevice::Lxc(LxcNetworkDevice { ty: NetworkDeviceModel::Veth, _name: "eth0".to_string(), - mac_address: MacAddress::new([0xAA, 0xAA, 0xAA, 0xE2, 0x3E, 0x25]), + mac_address: Some(MacAddress::new([0xAA, 0xAA, 0xAA, 0xE2, 0x3E, 0x25])), firewall: Some(true), ip: None, ip6: None, @@ -629,7 +647,7 @@ vmgenid: 706fbe99-d28b-4047-a9cd-3677c859ca8a" network_config.network_devices()[&0], NetworkDevice::Qemu(QemuNetworkDevice { model: NetworkDeviceModel::VirtIO, - mac_address: MacAddress::new([0xAA, 0xBB, 0xCC, 0xF2, 0xFE, 0x75]), + mac_address: Some(MacAddress::new([0xAA, 0xBB, 0xCC, 0xF2, 0xFE, 0x75])), firewall: None, }) ); @@ -658,7 +676,7 @@ unprivileged: 1" NetworkDevice::Lxc(LxcNetworkDevice { ty: NetworkDeviceModel::Veth, _name: "eth0".to_string(), - mac_address: MacAddress::new([0xBC, 0x24, 0x11, 0x47, 0x83, 0x11]), + mac_address: Some(MacAddress::new([0xBC, 0x24, 0x11, 0x47, 0x83, 0x11])), firewall: Some(true), ip: Some(LxcIpv4Addr::Dhcp), ip6: Some(LxcIpv6Addr::Auto), @@ -670,7 +688,7 @@ unprivileged: 1" NetworkDevice::Lxc(LxcNetworkDevice { ty: NetworkDeviceModel::Veth, _name: "eth0".to_string(), - mac_address: MacAddress::new([0xBC, 0x24, 0x11, 0x47, 0x83, 0x12]), + mac_address: Some(MacAddress::new([0xBC, 0x24, 0x11, 0x47, 0x83, 0x12])), firewall: Some(false), ip: Some(LxcIpv4Addr::Ip( Ipv4Cidr::from_str("123.123.123.123/24").expect("valid ipv4") @@ -684,7 +702,7 @@ unprivileged: 1" NetworkDevice::Lxc(LxcNetworkDevice { ty: NetworkDeviceModel::Veth, _name: "eth0".to_string(), - mac_address: MacAddress::new([0xBC, 0x24, 0x11, 0x47, 0x83, 0x13]), + mac_address: Some(MacAddress::new([0xBC, 0x24, 0x11, 0x47, 0x83, 0x13])), firewall: Some(true), ip: None, ip6: Some(LxcIpv6Addr::Ip( @@ -717,7 +735,7 @@ unprivileged: 1" assert_eq!(network_config.ignored_keys(), ["net32"]); // a network device key with an invalid value is still an error - NetworkConfig::parse("net0: foo".as_bytes()).expect_err("invalid network device"); + NetworkConfig::parse("net0: foo=bar".as_bytes()).expect_err("invalid network device"); // which definition the guest uses depends on its validation of the values NetworkConfig::parse( -- 2.47.3