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 2928A1FF066 for ; Tue, 24 Nov 2026 18:58:22 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 6551C21788; Tue, 24 Nov 2026 18:57:33 +0100 (CET) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox-firewall 4/7] firewall: guest: handle network devices without a MAC address Date: Tue, 24 Nov 2026 18:57:14 +0100 Message-ID: <20261124175718.512428-5-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: 1795543046796 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.175 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: JLTQ4XWCTNR67IFDQSDD5D2WPIB53XCS X-Message-ID-Hash: JLTQ4XWCTNR67IFDQSDD5D2WPIB53XCS 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 guest network device can lack a MAC address, for example after a manual edit of the config. qemu-server and pve-container then use a random one, which the firewall cannot know. Such a guest failed the parsing of its network config, and with it the whole firewall update. Leave the device out of the MAC filter, so that the filter drops its traffic, like it drops the traffic from any other unknown MAC address. If none of the devices of a guest has a MAC address, there is no set to match against, so drop all traffic of the guest instead of skipping the filter. Likewise, leave the link-local address out of the default IP filter, which then drops traffic from link-local addresses of the device. pve-firewall effectively behaves the same, as it builds the filters from a random MAC address that does not match the one of the guest. This requires the version of proxmox-ve-config in which the MAC address of a network device is optional. Signed-off-by: Stefan Hanreich --- proxmox-firewall/src/firewall.rs | 38 +++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/proxmox-firewall/src/firewall.rs b/proxmox-firewall/src/firewall.rs index 5689bdd..1fe35a2 100644 --- a/proxmox-firewall/src/firewall.rs +++ b/proxmox-firewall/src/firewall.rs @@ -671,16 +671,28 @@ impl Firewall { if config.macfilter() { log::debug!("setting macfilter for guest #{vmid}"); - let mac_address_set: Vec = config + let firewall_devices: Vec<_> = config .network_config() .network_devices() .iter() .filter(|(_, device)| device.has_firewall()) - .map(|(index, device)| { - Expression::concat([ - Expression::from(config.iface_name_by_index(*index)), - Expression::from(device.mac_address().to_string()), - ]) + .collect(); + + let mac_address_set: Vec = firewall_devices + .iter() + .filter_map(|(index, device)| { + let Some(mac_address) = device.mac_address() else { + log::warn!( + "guest #{vmid}: net{index} has no MAC address, the MAC filter drops \ + its traffic" + ); + return None; + }; + + Some(Expression::concat([ + Expression::from(config.iface_name_by_index(**index)), + Expression::from(mac_address.to_string()), + ])) }) .collect(); @@ -717,6 +729,11 @@ impl Firewall { commands.push(Add::rule(macfilter_rule)); commands.push(Add::rule(macfilter_arp_rule)); + } else if !firewall_devices.is_empty() { + commands.push(Add::rule(AddRule::from_statement( + chain_out.clone(), + Statement::make_drop(), + ))); } } @@ -885,10 +902,11 @@ impl Firewall { let ipset_name = IpsetName::new(IpsetScope::Guest, ipfilter_name); let mut ipset = Ipset::new(ipset_name); - let cidr = - Ipv6Cidr::from(network_device.mac_address().eui64_link_local_address()); - - ipset.push(IpsetEntry::from(Cidr::from(cidr))); + // without a MAC address, the filter drops traffic from link-local addresses + if let Some(mac_address) = network_device.mac_address() { + let cidr = Ipv6Cidr::from(mac_address.eui64_link_local_address()); + ipset.push(IpsetEntry::from(Cidr::from(cidr))); + } if let Some(ip_address) = network_device.ip() { ipset.push(IpsetEntry::from(Cidr::from(Ipv4Cidr::from( -- 2.47.3