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 BF8FB1FF0B3 for ; Thu, 26 Nov 2026 16:40:07 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id CF534217BA; Thu, 26 Nov 2026 16:39:41 +0100 (CET) From: Lukas Sichert To: pve-devel@lists.proxmox.com Subject: [PATCH network v3 4/7] fix #5066: evpn: prepare SNAT rules in temporary chain Date: Thu, 26 Nov 2026 16:29:02 +0100 Message-ID: <20261126153925.54600-5-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: 1795707576392 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.419 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: CBICNGIIWVWF24AHPHO6VPKSMGOTNKAC X-Message-ID-Hash: CBICNGIIWVWF24AHPHO6VPKSMGOTNKAC 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: Disabling SNAT for an existing subnet can leave its generated iptables rule active after applying the SDN configuration. Use the common SNAT rule generator for EVPN exit nodes. Instead of adding rules directly to POSTROUTING, generate them in the temporary PROXMOX-SDN-NEW chain. This allows the complete generated ruleset to be activated together and the previous ruleset to be removed separately. Update the expected network configuration accordingly. Signed-off-by: Lukas Sichert Link: https://bugzilla.proxmox.com/show_bug.cgi?id=5066 --- Notes: changes v2 -> v3: - rebased on top of master - use the common SNAT rule generator and prepare the rules in a temporary chain, instead of flushing the chain on reload changes v1 -> v2: - rebased on top of master - create the chain only for exit nodes ($is_evpn_gateway) src/PVE/Network/SDN/Zones/EvpnPlugin.pm | 31 ++++--------------- .../exitnode_snat/expected_sdn_interfaces | 16 +++++----- 2 files changed, 14 insertions(+), 33 deletions(-) diff --git a/src/PVE/Network/SDN/Zones/EvpnPlugin.pm b/src/PVE/Network/SDN/Zones/EvpnPlugin.pm index 534ac9f..c7e0948 100644 --- a/src/PVE/Network/SDN/Zones/EvpnPlugin.pm +++ b/src/PVE/Network/SDN/Zones/EvpnPlugin.pm @@ -273,31 +273,12 @@ sub generate_sdn_config { $enable_forward_v4 = 1 if $gateway; } - if ($subnet->{snat}) { - - #find outgoing interface - my ($outip, $outiface); - eval { - ($outip, $outiface) = - PVE::Network::SDN::Zones::Plugin::get_local_route_ip($checkrouteip); - }; - if ($@) { - my $msg = "interface for SNAT could not be resolved: $@"; - log_warn($msg); - next; - } - if ($outip && $outiface && $is_evpn_gateway) { - #use snat, faster than masquerade - push @iface_config, - "post-up $iptables -t nat -A POSTROUTING -s '$cidr' -o $outiface -j SNAT --to-source $outip"; - push @iface_config, - "post-down $iptables -t nat -D POSTROUTING -s '$cidr' -o $outiface -j SNAT --to-source $outip"; - #add conntrack zone once on outgoing interface - push @iface_config, - "post-up $iptables -t raw -I PREROUTING -i fwbr+ -j CT --zone 1"; - push @iface_config, - "post-down $iptables -t raw -D PREROUTING -i fwbr+ -j CT --zone 1"; - } + if ($subnet->{snat} && $is_evpn_gateway) { + my @snat_config = PVE::Network::SDN::Zones::Plugin::generate_new_snat_rules( + $checkrouteip, $iptables, $cidr, + ); + + push @iface_config, @snat_config; } } diff --git a/src/test/zones/evpn/exitnode_snat/expected_sdn_interfaces b/src/test/zones/evpn/exitnode_snat/expected_sdn_interfaces index b607231..0ad2c46 100644 --- a/src/test/zones/evpn/exitnode_snat/expected_sdn_interfaces +++ b/src/test/zones/evpn/exitnode_snat/expected_sdn_interfaces @@ -3,10 +3,10 @@ auto myvnet iface myvnet address 10.0.0.1/24 - post-up iptables -t nat -A POSTROUTING -s '10.0.0.0/24' -o vmbr0 -j SNAT --to-source 192.168.0.1 - post-down iptables -t nat -D POSTROUTING -s '10.0.0.0/24' -o vmbr0 -j SNAT --to-source 192.168.0.1 - post-up iptables -t raw -I PREROUTING -i fwbr+ -j CT --zone 1 - post-down iptables -t raw -D PREROUTING -i fwbr+ -j CT --zone 1 + post-up iptables -t nat -L PROXMOX-SDN-NEW 2>/dev/null || iptables -t nat -N PROXMOX-SDN-NEW + post-up iptables -t nat -C POSTROUTING -j PROXMOX-SDN-NEW 2>/dev/null || iptables -t nat -A POSTROUTING -j PROXMOX-SDN-NEW + post-up iptables -t nat -A PROXMOX-SDN-NEW -s '10.0.0.0/24' -o vmbr0 -j SNAT --to-source 192.168.0.1 + post-up iptables -t raw -C PREROUTING -i fwbr+ -j CT --zone 1 2>/dev/null || iptables -t raw -I PREROUTING -i fwbr+ -j CT --zone 1 bridge_ports vxlan_myvnet bridge_stp off bridge_fd 0 @@ -18,10 +18,10 @@ iface myvnet auto myvnet2 iface myvnet2 address 2a08:2142:302:3::1/64 - post-up ip6tables -t nat -A POSTROUTING -s '2a08:2142:302:3::/64' -o vmbr0 -j SNAT --to-source 2001:db8::2 - post-down ip6tables -t nat -D POSTROUTING -s '2a08:2142:302:3::/64' -o vmbr0 -j SNAT --to-source 2001:db8::2 - post-up ip6tables -t raw -I PREROUTING -i fwbr+ -j CT --zone 1 - post-down ip6tables -t raw -D PREROUTING -i fwbr+ -j CT --zone 1 + post-up ip6tables -t nat -L PROXMOX-SDN-NEW 2>/dev/null || ip6tables -t nat -N PROXMOX-SDN-NEW + post-up ip6tables -t nat -C POSTROUTING -j PROXMOX-SDN-NEW 2>/dev/null || ip6tables -t nat -A POSTROUTING -j PROXMOX-SDN-NEW + post-up ip6tables -t nat -A PROXMOX-SDN-NEW -s '2a08:2142:302:3::/64' -o vmbr0 -j SNAT --to-source 2001:db8::2 + post-up ip6tables -t raw -C PREROUTING -i fwbr+ -j CT --zone 1 2>/dev/null || ip6tables -t raw -I PREROUTING -i fwbr+ -j CT --zone 1 bridge_ports vxlan_myvnet2 bridge_stp off bridge_fd 0 -- 2.47.3