public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH proxmox-firewall 1/1] guest: do not try to create map entries if there are no devices
Date: Tue,  8 Apr 2025 15:41:35 +0200	[thread overview]
Message-ID: <20250408134135.242922-1-s.hanreich@proxmox.com> (raw)

When the firewall was enabled for a guest, but disabled for all
interfaces of a guest, the firewall tried to add an empty list to the
guest map, which is an invalid nftables statement.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
 proxmox-firewall/src/firewall.rs | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/proxmox-firewall/src/firewall.rs b/proxmox-firewall/src/firewall.rs
index e1c9351..086b96c 100644
--- a/proxmox-firewall/src/firewall.rs
+++ b/proxmox-firewall/src/firewall.rs
@@ -955,7 +955,7 @@ impl Firewall {
         let network_devices = config.network_config().network_devices();
 
         if !network_devices.is_empty() {
-            let map_elements = network_devices
+            let map_elements: Vec<(Expression, MapValue)> = network_devices
                 .iter()
                 .filter(|(_, device)| device.has_firewall())
                 .map(|(index, _)| {
@@ -965,12 +965,15 @@ impl Firewall {
                             target: chain.name().to_string(),
                         }),
                     )
-                });
+                })
+                .collect();
 
-            commands.push(Add::element(AddElement::map_from_expressions(
-                Self::guest_vmap(direction),
-                map_elements,
-            )));
+            if !map_elements.is_empty() {
+                commands.push(Add::element(AddElement::map_from_expressions(
+                    Self::guest_vmap(direction),
+                    map_elements,
+                )));
+            }
         }
 
         self.create_log_rule(
-- 
2.39.5


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


             reply	other threads:[~2025-04-08 13:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-08 13:41 Stefan Hanreich [this message]
2025-04-08 13:54 ` [pve-devel] applied: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250408134135.242922-1-s.hanreich@proxmox.com \
    --to=s.hanreich@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal