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 E9AB51FF0B3 for ; Thu, 26 Nov 2026 16:40:17 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 4E266217BC; Thu, 26 Nov 2026 16:39:42 +0100 (CET) From: Lukas Sichert To: pve-devel@lists.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 Message-ID: <20261126153925.54600-4-l.sichert@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261126153925.54600-1-l.sichert@proxmox.com> References: <20261126153925.54600-1-l.sichert@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795707575987 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.423 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: 6Q6ZHGAQXPPRICRA2PDYAMNLOKPJOHGU X-Message-ID-Hash: 6Q6ZHGAQXPPRICRA2PDYAMNLOKPJOHGU X-MailFrom: l.sichert@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 CC: Lukas Sichert X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 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