public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Lukas Sichert <l.sichert@proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Lukas Sichert <l.sichert@proxmox.com>
Subject: [PATCH network v3 3/7] fix #5066: zones: add helper to activate prepared SNAT rules
Date: Thu, 26 Nov 2026 16:29:01 +0100	[thread overview]
Message-ID: <20261126153925.54600-4-l.sichert@proxmox.com> (raw)
In-Reply-To: <20261126153925.54600-1-l.sichert@proxmox.com>

Add a helper that activates the SNAT rules prepared in PROXMOX-SDN-NEW
by the post-up hooks that generate_new_snat_rules() emits. It has to run
after the network configuration with these hooks was applied, as only
then the new chain is populated.

If an active PROXMOX-SDN chain exists, remove its POSTROUTING jump,
flush it, and delete it. The temporary chain is already linked from
POSTROUTING at this point, so generated SNAT remains available while
the old chain is removed.

Finally, rename PROXMOX-SDN-NEW to PROXMOX-SDN, making the prepared
ruleset the active SDN SNAT chain.

Signed-off-by: Lukas Sichert <l.sichert@proxmox.com>
Link: https://bugzilla.proxmox.com/show_bug.cgi?id=5066
---

Notes:
    new in v3

 src/PVE/Network/SDN/Zones.pm | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/src/PVE/Network/SDN/Zones.pm b/src/PVE/Network/SDN/Zones.pm
index 6981c27..0133c8a 100644
--- a/src/PVE/Network/SDN/Zones.pm
+++ b/src/PVE/Network/SDN/Zones.pm
@@ -278,6 +278,33 @@ sub generate_etc_network_config {
     return $raw_network_config;
 }
 
+sub apply_new_snat_rules {
+    for my $iptables (qw(iptables ip6tables)) {
+        eval {
+            # PROXMOX-SDN-NEW is now populated with the new SNAT rules, so the jump to
+            # PROXMOX-SDN can safely be removed.
+            eval {
+                run_command([$iptables, '-t', 'nat', '-C', 'POSTROUTING', '-j', 'PROXMOX-SDN']);
+            };
+            if (!$@) {
+                run_command([$iptables, '-t', 'nat', '-D', 'POSTROUTING', '-j', 'PROXMOX-SDN']);
+            }
+
+            eval { run_command([$iptables, '-t', 'nat', '-S', 'PROXMOX-SDN']); };
+            if (!$@) {
+                run_command([$iptables, '-t', 'nat', '-F', 'PROXMOX-SDN']);
+                run_command([$iptables, '-t', 'nat', '-X', 'PROXMOX-SDN']);
+            }
+
+            eval { run_command([$iptables, '-t', 'nat', '-S', 'PROXMOX-SDN-NEW']); };
+            if (!$@) {
+                run_command([$iptables, '-t', 'nat', '-E', 'PROXMOX-SDN-NEW', 'PROXMOX-SDN']);
+            }
+        };
+        log_warn("failed to apply new $iptables SNAT rules: $@") if $@;
+    }
+}
+
 sub read_etc_network_config_version {
     my $versionstr = PVE::Tools::file_read_firstline($local_network_sdn_file);
 
-- 
2.47.3





  parent reply	other threads:[~2026-11-26 15:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 15:28 [PATCH manager/network v3 0/7] fix #5066: make generated snat rules flushable Lukas Sichert
2026-11-26 15:28 ` [PATCH network v3 1/7] style: zones: use fully qualified JSONSchema calls for standard options Lukas Sichert
2026-11-26 15:29 ` [PATCH network v3 2/7] fix #5066: zones: factor out SNAT rule generation Lukas Sichert
2026-11-26 15:29 ` Lukas Sichert [this message]
2026-11-26 15:29 ` [PATCH network v3 4/7] fix #5066: evpn: prepare SNAT rules in temporary chain Lukas Sichert
2026-11-26 15:29 ` [PATCH network v3 5/7] fix #5066: simple zone: " Lukas Sichert
2026-11-26 15:29 ` [PATCH network v3 6/7] fix #5066: zones: add test for generating and applying SNAT rules Lukas Sichert
2026-11-26 15:29 ` [PATCH manager v3 7/7] fix #5066: network: activate prepared SDN " Lukas Sichert

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=20261126153925.54600-4-l.sichert@proxmox.com \
    --to=l.sichert@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