* [PATCH manager/network v3 0/7] fix #5066: make generated snat rules flushable
@ 2026-11-26 15:28 Lukas Sichert
2026-11-26 15:28 ` [PATCH network v3 1/7] style: zones: use fully qualified JSONSchema calls for standard options Lukas Sichert
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: Lukas Sichert @ 2026-11-26 15:28 UTC (permalink / raw)
To: pve-devel; +Cc: Lukas Sichert
Disabling SNAT for an existing subnet can leave its iptables rule
active. This happens because 'ifreload -a' does not execute down hooks
when reloading an existing interface [1].
Move generated Simple (including dedicated VRF) and EVPN SNAT rules from
POSTROUTING into a dedicated chain. Post-up hooks prepare the complete
new ruleset in PROXMOX-SDN-NEW while the existing PROXMOX-SDN chain
remains active. After ifreload, replace the old chain with the prepared
one. This removes stale rules without affecting unrelated POSTROUTING
rules or leaving a window during which SNAT does not work.
At boot, networking.service prepares the temporary chain directly with
the post-up commands in /etc/network/interfaces.d/sdn. Therefore, also
activate it from pve-sdn-commit when no SDN changes are pending.
Maintainer Note:
This series requires a version bump of pve-network and a dependency bump
on it in pve-manager, as that calls the new apply_new_snat_rules().
Notes:
- Rules generated by an older version sit directly in POSTROUTING and
cannot be told apart from user-set rules, so they are not flushed with
the new chain and are only gone after a reboot.
- A manual ifreload populates PROXMOX-SDN-NEW without switching it over.
This may leave stale rules, which are cleaned up with the next SDN
apply or reboot.
[1] https://manpages.debian.org/testing/ifupdown2/ifreload.8.en.html
Link: https://bugzilla.proxmox.com/show_bug.cgi?id=5066
changes from v2 to v3 (thanks @Stefan):
- prepare rules in a temporary chain before replacing the active chain,
avoiding an interruption of SNAT
- share SNAT rule generation between Simple and EVPN zones
- activate rules generated during boot
- also handle zones with a dedicated VRF, which masquerade on their
uplinks
changes from v1 to v2 (thanks @Stefan):
- rebase on top of master
- create chain only when '$is_evpn_gateway' is true
- add Links to commits
network:
Lukas Sichert (6):
style: zones: use fully qualified JSONSchema calls for standard
options
fix #5066: zones: factor out SNAT rule generation
fix #5066: zones: add helper to activate prepared SNAT rules
fix #5066: evpn: prepare SNAT rules in temporary chain
fix #5066: simple zone: prepare SNAT rules in temporary chain
fix #5066: zones: add test for generating and applying SNAT rules
src/PVE/Network/SDN/Zones.pm | 39 +++-
src/PVE/Network/SDN/Zones/EvpnPlugin.pm | 31 +--
src/PVE/Network/SDN/Zones/Plugin.pm | 58 ++++-
src/PVE/Network/SDN/Zones/SimplePlugin.pm | 44 +---
src/test/Makefile | 5 +-
src/test/run_test_apply_snat.pl | 209 ++++++++++++++++++
.../exitnode_snat/expected_sdn_interfaces | 16 +-
.../simple/ipv4snat/expected_sdn_interfaces | 8 +-
.../simple/ipv6snat/expected_sdn_interfaces | 8 +-
.../simple/vrf_snat/expected_sdn_interfaces | 35 ++-
10 files changed, 348 insertions(+), 105 deletions(-)
create mode 100755 src/test/run_test_apply_snat.pl
manager:
Lukas Sichert (1):
fix #5066: network: activate prepared SDN SNAT rules
PVE/API2/Network.pm | 1 +
bin/pve-sdn-commit | 6 ++++++
2 files changed, 7 insertions(+)
Summary over all repositories:
12 files changed, 355 insertions(+), 105 deletions(-)
--
Generated by murpp 0.12.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH network v3 1/7] style: zones: use fully qualified JSONSchema calls for standard options
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 ` Lukas Sichert
2026-11-26 15:29 ` [PATCH network v3 2/7] fix #5066: zones: factor out SNAT rule generation Lukas Sichert
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Lukas Sichert @ 2026-11-26 15:28 UTC (permalink / raw)
To: pve-devel; +Cc: Lukas Sichert
Drop the redundant get_standard_option import and call the helper
through PVE::JSONSchema directly. Reorder the remaining module imports
alphabetically.
Signed-off-by: Lukas Sichert <l.sichert@proxmox.com>
---
Notes:
new in v3
src/PVE/Network/SDN/Zones.pm | 12 ++++++------
src/PVE/Network/SDN/Zones/Plugin.pm | 11 +++++------
2 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/src/PVE/Network/SDN/Zones.pm b/src/PVE/Network/SDN/Zones.pm
index e4116d7..6981c27 100644
--- a/src/PVE/Network/SDN/Zones.pm
+++ b/src/PVE/Network/SDN/Zones.pm
@@ -6,25 +6,25 @@ use warnings;
use JSON;
use Storable qw(dclone);
-use PVE::Exception qw(raise_param_exc);
-use PVE::Tools qw(extract_param dir_glob_regex run_command);
use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file);
+use PVE::Exception qw(raise_param_exc);
use PVE::IPRoute2;
use PVE::Network;
use PVE::RESTEnvironment qw(log_warn);
+use PVE::Tools qw(extract_param dir_glob_regex run_command);
use PVE::Network::SDN::Controllers;
use PVE::Network::SDN::Dns;
use PVE::Network::SDN::Fabrics;
use PVE::Network::SDN::Ipams;
use PVE::Network::SDN::Vnets;
-use PVE::Network::SDN::Zones::VlanPlugin;
-use PVE::Network::SDN::Zones::QinQPlugin;
-use PVE::Network::SDN::Zones::VxlanPlugin;
use PVE::Network::SDN::Zones::EvpnPlugin;
use PVE::Network::SDN::Zones::FaucetPlugin;
-use PVE::Network::SDN::Zones::SimplePlugin;
use PVE::Network::SDN::Zones::Plugin;
+use PVE::Network::SDN::Zones::QinQPlugin;
+use PVE::Network::SDN::Zones::SimplePlugin;
+use PVE::Network::SDN::Zones::VlanPlugin;
+use PVE::Network::SDN::Zones::VxlanPlugin;
PVE::Network::SDN::Zones::VlanPlugin->register();
PVE::Network::SDN::Zones::QinQPlugin->register();
diff --git a/src/PVE/Network/SDN/Zones/Plugin.pm b/src/PVE/Network/SDN/Zones/Plugin.pm
index 3fa2ab5..795ec9f 100644
--- a/src/PVE/Network/SDN/Zones/Plugin.pm
+++ b/src/PVE/Network/SDN/Zones/Plugin.pm
@@ -1,17 +1,16 @@
package PVE::Network::SDN::Zones::Plugin;
+use Net::IP qw(ip_get_version);
use strict;
use warnings;
-use PVE::Tools qw(run_command);
-use Net::IP qw(ip_get_version);
-use PVE::JSONSchema;
use PVE::Cluster;
+use PVE::JSONSchema;
use PVE::Network;
use PVE::Network::SDN::Formats;
use PVE::RS::SDN;
+use PVE::Tools qw(run_command);
-use PVE::JSONSchema qw(get_standard_option);
use base qw(PVE::SectionConfig);
PVE::Cluster::cfs_register_file(
@@ -105,7 +104,7 @@ my $defaultData = {
format => 'pve-configid',
type => 'string',
},
- nodes => get_standard_option('pve-node-list', { optional => 1 }),
+ nodes => PVE::JSONSchema::get_standard_option('pve-node-list', { optional => 1 }),
route => {
type => 'array',
optional => 1,
@@ -117,7 +116,7 @@ my $defaultData = {
format => 'pve-sdn-static-route',
},
},
- zone => get_standard_option(
+ zone => PVE::JSONSchema::get_standard_option(
'pve-sdn-zone-id',
{
completion => \&PVE::Network::SDN::Zones::complete_sdn_zone,
--
2.47.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH network v3 2/7] fix #5066: zones: factor out SNAT rule generation
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 ` Lukas Sichert
2026-11-26 15:29 ` [PATCH network v3 3/7] fix #5066: zones: add helper to activate prepared SNAT rules Lukas Sichert
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Lukas Sichert @ 2026-11-26 15:29 UTC (permalink / raw)
To: pve-devel; +Cc: Lukas Sichert
Both the Simple and EVPN zone plugins need to generate the same set of
SNAT and conntrack rules. Move their generation into a common helper so
that both plugins use the same setup sequence.
Create a temporary PROXMOX-SDN-NEW chain and add a jump to it from
POSTROUTING. Check whether the temporary chain and its POSTROUTING jump
already exist before creating them. The temporary chain allows the
complete set of newly generated rules to be prepared before replacing
the currently active PROXMOX-SDN chain.
Zones with a dedicated VRF pass their uplinks to the helper, which then
masquerades on each of them. Without uplinks, the SNAT rule is built
from the route to the outside, as before.
Only add the conntrack zone rule for the firewall bridges if it does not
exist yet. Reloading runs post-up without post-down, so the plain insert
added another copy on each run. Drop the post-down rule as well: the
ifreload path does not use it, and a manual post-down could remove the
rule that is shared by all SNAT subnets.
Signed-off-by: Lukas Sichert <l.sichert@proxmox.com>
Link: https://bugzilla.proxmox.com/show_bug.cgi?id=5066
---
Notes:
changes v2 -> v3:
- rebased on top of master
- replaces "snat: add config generation helpers": the helper now
prepares the rules in a temporary chain and takes optional uplinks
for the masquerade rules of dedicated-VRF zones
- add the conntrack zone rule only once
changes v1 -> v2:
- rebased on top of master
src/PVE/Network/SDN/Zones/Plugin.pm | 47 +++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/src/PVE/Network/SDN/Zones/Plugin.pm b/src/PVE/Network/SDN/Zones/Plugin.pm
index 795ec9f..93ed142 100644
--- a/src/PVE/Network/SDN/Zones/Plugin.pm
+++ b/src/PVE/Network/SDN/Zones/Plugin.pm
@@ -8,6 +8,7 @@ use PVE::Cluster;
use PVE::JSONSchema;
use PVE::Network;
use PVE::Network::SDN::Formats;
+use PVE::RESTEnvironment qw(log_warn);
use PVE::RS::SDN;
use PVE::Tools qw(run_command);
@@ -431,6 +432,52 @@ sub get_vrf_member_interfaces {
return sort grep { ($ifaces->{$_}->{vrf} // '') eq $vrf } keys %$ifaces;
}
+sub generate_new_snat_rules {
+ my ($checkrouteip, $iptables, $cidr, $uplinks) = @_;
+
+ my @snat_rules = ();
+
+ # Create the temporary chain only if it does not exist.
+ push @snat_rules,
+ "post-up $iptables -t nat -L PROXMOX-SDN-NEW 2>/dev/null"
+ . " || $iptables -t nat -N PROXMOX-SDN-NEW";
+
+ # Add the jump only if the exact jump does not already exist.
+ push @snat_rules,
+ "post-up $iptables -t nat -C POSTROUTING -j PROXMOX-SDN-NEW 2>/dev/null"
+ . " || $iptables -t nat -A POSTROUTING -j PROXMOX-SDN-NEW";
+
+ if ($uplinks && @$uplinks) {
+ # the routing table picks the uplink per connection (e.g. with ECMP), and its address may
+ # be dynamic, so let each uplink masquerade with its own address
+ for my $uplink (@$uplinks) {
+ push @snat_rules,
+ "post-up $iptables -t nat -A PROXMOX-SDN-NEW -s '$cidr' -o $uplink -j MASQUERADE";
+ }
+ } else {
+ #find outgoing interface
+ my ($outip, $outiface);
+ eval { ($outip, $outiface) = get_local_route_ip($checkrouteip); };
+ if ($@) {
+ log_warn("interface for SNAT could not be resolved: $@");
+ }
+
+ if ($outip && $outiface) {
+ #use snat, faster than masquerade
+ push @snat_rules,
+ "post-up $iptables -t nat -A PROXMOX-SDN-NEW -s '$cidr' -o $outiface -j SNAT --to-source $outip";
+ }
+ }
+
+ # Add the conntrack zone rule only once. Reloading re-runs post-up without post-down, and
+ # the rule is shared by all SNAT subnets, so it is not removed together with a single one.
+ push @snat_rules,
+ "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";
+
+ return @snat_rules;
+}
+
sub find_local_ip_interface_peers {
my ($peers, $iface) = @_;
--
2.47.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH network v3 3/7] fix #5066: zones: add helper to activate prepared SNAT rules
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
2026-11-26 15:29 ` [PATCH network v3 4/7] fix #5066: evpn: prepare SNAT rules in temporary chain Lukas Sichert
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Lukas Sichert @ 2026-11-26 15:29 UTC (permalink / raw)
To: pve-devel; +Cc: Lukas Sichert
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH network v3 4/7] fix #5066: evpn: prepare SNAT rules in temporary chain
2026-11-26 15:28 [PATCH manager/network v3 0/7] fix #5066: make generated snat rules flushable Lukas Sichert
` (2 preceding siblings ...)
2026-11-26 15:29 ` [PATCH network v3 3/7] fix #5066: zones: add helper to activate prepared SNAT rules Lukas Sichert
@ 2026-11-26 15:29 ` Lukas Sichert
2026-11-26 15:29 ` [PATCH network v3 5/7] fix #5066: simple zone: " Lukas Sichert
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Lukas Sichert @ 2026-11-26 15:29 UTC (permalink / raw)
To: pve-devel; +Cc: Lukas Sichert
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 <l.sichert@proxmox.com>
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH network v3 5/7] fix #5066: simple zone: prepare SNAT rules in temporary chain
2026-11-26 15:28 [PATCH manager/network v3 0/7] fix #5066: make generated snat rules flushable Lukas Sichert
` (3 preceding siblings ...)
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 ` 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
6 siblings, 0 replies; 8+ messages in thread
From: Lukas Sichert @ 2026-11-26 15:29 UTC (permalink / raw)
To: pve-devel; +Cc: Lukas Sichert
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 Simple Zones, including zones
with a dedicated VRF. 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 <l.sichert@proxmox.com>
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
- also handle zones with a dedicated VRF
changes v1 -> v2:
- rebased on top of master
src/PVE/Network/SDN/Zones/SimplePlugin.pm | 44 +++++--------------
.../simple/ipv4snat/expected_sdn_interfaces | 8 ++--
.../simple/ipv6snat/expected_sdn_interfaces | 8 ++--
.../simple/vrf_snat/expected_sdn_interfaces | 35 +++++++--------
4 files changed, 36 insertions(+), 59 deletions(-)
diff --git a/src/PVE/Network/SDN/Zones/SimplePlugin.pm b/src/PVE/Network/SDN/Zones/SimplePlugin.pm
index 3e866ac..016a186 100644
--- a/src/PVE/Network/SDN/Zones/SimplePlugin.pm
+++ b/src/PVE/Network/SDN/Zones/SimplePlugin.pm
@@ -154,40 +154,18 @@ sub generate_sdn_config {
log_warn("no uplink in vrf_$zone_id, not adding SNAT for subnet $cidr");
next;
}
- # the routing table picks the uplink per connection (e.g. with ECMP), and its
- # address may be dynamic, so let each uplink masquerade with its own address
- for my $uplink (@uplinks) {
- push @iface_config,
- "post-up $iptables -t nat -A POSTROUTING -s '$cidr' -o $uplink -j MASQUERADE";
- push @iface_config,
- "post-down $iptables -t nat -D POSTROUTING -s '$cidr' -o $uplink -j MASQUERADE";
- }
- 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";
+
+ my @snat_config = PVE::Network::SDN::Zones::Plugin::generate_new_snat_rules(
+ $checkrouteip, $iptables, $cidr, \@uplinks,
+ );
+
+ push @iface_config, @snat_config;
} elsif ($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) {
- #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";
- }
+ 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/simple/ipv4snat/expected_sdn_interfaces b/src/test/zones/simple/ipv4snat/expected_sdn_interfaces
index 69d7986..03de88d 100644
--- a/src/test/zones/simple/ipv4snat/expected_sdn_interfaces
+++ b/src/test/zones/simple/ipv4snat/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 none
bridge_stp off
bridge_fd 0
diff --git a/src/test/zones/simple/ipv6snat/expected_sdn_interfaces b/src/test/zones/simple/ipv6snat/expected_sdn_interfaces
index 5f6d40b..d3e1fdf 100644
--- a/src/test/zones/simple/ipv6snat/expected_sdn_interfaces
+++ b/src/test/zones/simple/ipv6snat/expected_sdn_interfaces
@@ -3,10 +3,10 @@
auto myvnet
iface myvnet
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 none
bridge_stp off
bridge_fd 0
diff --git a/src/test/zones/simple/vrf_snat/expected_sdn_interfaces b/src/test/zones/simple/vrf_snat/expected_sdn_interfaces
index 2a9804c..2eab64a 100644
--- a/src/test/zones/simple/vrf_snat/expected_sdn_interfaces
+++ b/src/test/zones/simple/vrf_snat/expected_sdn_interfaces
@@ -3,15 +3,15 @@
auto vneta
iface vneta
address 10.0.0.1/24
- post-up iptables -t nat -A POSTROUTING -s '10.0.0.0/24' -o eth1 -j MASQUERADE
- post-down iptables -t nat -D POSTROUTING -s '10.0.0.0/24' -o eth1 -j MASQUERADE
- 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 eth1 -j MASQUERADE
+ 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
address 2001:db8:a::1/64
- post-up ip6tables -t nat -A POSTROUTING -s '2001:db8:a::/64' -o eth1 -j MASQUERADE
- post-down ip6tables -t nat -D POSTROUTING -s '2001:db8:a::/64' -o eth1 -j MASQUERADE
- 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 '2001:db8:a::/64' -o eth1 -j MASQUERADE
+ 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 none
bridge_stp off
bridge_fd 0
@@ -22,10 +22,10 @@ iface vneta
auto vnetb
iface vnetb
address 10.0.0.1/24
- post-up iptables -t nat -A POSTROUTING -s '10.0.0.0/24' -o eth2 -j MASQUERADE
- post-down iptables -t nat -D POSTROUTING -s '10.0.0.0/24' -o eth2 -j MASQUERADE
- 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 eth2 -j MASQUERADE
+ 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 none
bridge_stp off
bridge_fd 0
@@ -44,12 +44,11 @@ iface vnetc
auto vnetd
iface vnetd
address 10.0.0.1/24
- post-up iptables -t nat -A POSTROUTING -s '10.0.0.0/24' -o eth3 -j MASQUERADE
- post-down iptables -t nat -D POSTROUTING -s '10.0.0.0/24' -o eth3 -j MASQUERADE
- post-up iptables -t nat -A POSTROUTING -s '10.0.0.0/24' -o eth4 -j MASQUERADE
- post-down iptables -t nat -D POSTROUTING -s '10.0.0.0/24' -o eth4 -j MASQUERADE
- 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 eth3 -j MASQUERADE
+ post-up iptables -t nat -A PROXMOX-SDN-NEW -s '10.0.0.0/24' -o eth4 -j MASQUERADE
+ 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 none
bridge_stp off
bridge_fd 0
--
2.47.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH network v3 6/7] fix #5066: zones: add test for generating and applying SNAT rules
2026-11-26 15:28 [PATCH manager/network v3 0/7] fix #5066: make generated snat rules flushable Lukas Sichert
` (4 preceding siblings ...)
2026-11-26 15:29 ` [PATCH network v3 5/7] fix #5066: simple zone: " Lukas Sichert
@ 2026-11-26 15:29 ` Lukas Sichert
2026-11-26 15:29 ` [PATCH manager v3 7/7] fix #5066: network: activate prepared SDN " Lukas Sichert
6 siblings, 0 replies; 8+ messages in thread
From: Lukas Sichert @ 2026-11-26 15:29 UTC (permalink / raw)
To: pve-devel; +Cc: Lukas Sichert
The zone tests only compare the generated interfaces file, so nothing
checks how the post-up hooks and the activation of the prepared rules
work together.
Run both against a fake iptables and check the rules after the first
apply, after applying again, and after SNAT was disabled for all
subnets. This includes zones with a dedicated VRF, which masquerade on
each of their uplinks.
Signed-off-by: Lukas Sichert <l.sichert@proxmox.com>
Link: https://bugzilla.proxmox.com/show_bug.cgi?id=5066
---
Notes:
new in v3
src/test/Makefile | 5 +-
src/test/run_test_apply_snat.pl | 209 ++++++++++++++++++++++++++++++++
2 files changed, 213 insertions(+), 1 deletion(-)
create mode 100755 src/test/run_test_apply_snat.pl
diff --git a/src/test/Makefile b/src/test/Makefile
index d9160f3..adb8866 100644
--- a/src/test/Makefile
+++ b/src/test/Makefile
@@ -1,6 +1,6 @@
all: test
-test: test_zones test_zone_host_vrf test_static_routes test_ct_zones test_fabric_host_vrf test_fabric_zone_wireguard test_ipams test_dns test_subnets test_vnets_blackbox test_running_config test_api_index
+test: test_zones test_zone_host_vrf test_static_routes test_ct_zones test_fabric_host_vrf test_fabric_zone_wireguard test_ipams test_dns test_subnets test_vnets_blackbox test_running_config test_api_index test_apply_snat
test_zones: run_test_zones.pl
./run_test_zones.pl
@@ -38,4 +38,7 @@ test_running_config: run_test_running_config.pl
test_api_index: run_test_api_index.pl
./run_test_api_index.pl
+test_apply_snat: run_test_apply_snat.pl
+ ./run_test_apply_snat.pl
+
clean:
diff --git a/src/test/run_test_apply_snat.pl b/src/test/run_test_apply_snat.pl
new file mode 100755
index 0000000..d69c4fd
--- /dev/null
+++ b/src/test/run_test_apply_snat.pl
@@ -0,0 +1,209 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use lib qw(..);
+
+use Net::IP;
+use Test::More;
+use Test::MockModule;
+use Test::Differences;
+use Text::ParseWords qw(shellwords);
+
+use PVE::Network::SDN;
+use PVE::Network::SDN::Zones;
+use PVE::INotify;
+
+sub read_sdn_config {
+ my ($file) = @_;
+
+ # Read structure back in again
+ open my $in, '<', $file or die $!;
+ my $sdn_config;
+ {
+ local $/; # slurp mode
+ $sdn_config = eval <$in>;
+ }
+ close $in;
+
+ return $sdn_config;
+}
+
+# state of the mocked iptables: $tables->{$bin}->{$table}->{$chain} = [rules]
+my $tables;
+
+sub mock_run_command {
+ my ($cmd) = @_;
+
+ # hooks run through a shell, which handles the redirection
+ my @args = grep { $_ ne '2>/dev/null' } @$cmd;
+
+ my ($bin, undef, $table, $op, $chain, @rule) = @args;
+ my $chains = $tables->{$bin}->{$table};
+ my $rules = $chains->{$chain};
+ my $rule = "@rule";
+
+ die "no chain/target/match by that name\n" if !$rules && $op ne '-N';
+
+ if ($op eq '-N') {
+ die "chain already exists\n" if $rules;
+ $chains->{$chain} = [];
+ } elsif ($op eq '-A') {
+ push @$rules, $rule;
+ } elsif ($op eq '-I') {
+ unshift @$rules, $rule;
+ } elsif ($op eq '-C' || $op eq '-D') {
+ my ($idx) = grep { $rules->[$_] eq $rule } 0 .. $#$rules;
+ die "no matching rule\n" if !defined($idx);
+ splice(@$rules, $idx, 1) if $op eq '-D';
+ } elsif ($op eq '-F') {
+ @$rules = ();
+ } elsif ($op eq '-X') {
+ die "chain is not empty or still in use\n"
+ if @$rules || grep { $_ eq "-j $chain" } map { @$_ } values %$chains;
+ delete $chains->{$chain};
+ } elsif ($op eq '-E') {
+ $chains->{$rule} = delete $chains->{$chain};
+ for my $list (values %$chains) {
+ s/^-j \Q$chain\E$/-j $rule/ for @$list;
+ }
+ } elsif ($op ne '-L' && $op ne '-S') {
+ die "unsupported operation $op\n";
+ }
+}
+
+# runs the iptables post-up hooks like ifupdown2 does, 'a || b' only runs b if a failed
+sub split_post_up_hooks {
+ my ($interfaces) = @_;
+
+ for my $line (split(/\n/, $interfaces)) {
+ next if $line !~ m/^\s*post-up (ip6?tables .*)/;
+
+ my ($cmd_a, $cmd_b) = split(/ \|\| /, $1, 2);
+ eval { mock_run_command([shellwords($cmd_a)]) };
+ mock_run_command([shellwords($cmd_b)]) if $@ && defined($cmd_b);
+ die $@ if $@ && !defined($cmd_b);
+ }
+}
+
+sub get_iptables {
+ my %state;
+
+ foreach my $bin (qw(iptables ip6tables)) {
+ my $nat = $tables->{$bin}->{nat};
+ $state{$bin} = {
+ chains => [sort grep { /^PROXMOX/ } keys %$nat],
+ jumps => $nat->{POSTROUTING},
+ snat => [sort map { s/^-s (\S+) .*/$1/r } @{ $nat->{'PROXMOX-SDN'} // [] }],
+ ct_rules => scalar(@{ $tables->{$bin}->{raw}->{PREROUTING} }),
+ };
+ }
+
+ return \%state;
+}
+
+my $mocked_zones;
+$mocked_zones = Test::MockModule->new('PVE::Network::SDN::Zones');
+$mocked_zones->mock(run_command => \&mock_run_command);
+
+my @tests = sort glob('./zones/*/*snat');
+
+foreach my $name (@tests) {
+
+ my $sdn_config = read_sdn_config("./$name/sdn_config");
+
+ open(my $fh1, '<', "./$name/interfaces") or die "can't read interfaces file - $!";
+ my $interfaces_config = PVE::INotify::__read_etc_network_interfaces($fh1, undef, undef);
+ close $fh1;
+
+ my $pve_common_inotify;
+ $pve_common_inotify = Test::MockModule->new('PVE::INotify');
+ $pve_common_inotify->mock(
+ nodename => sub {
+ return 'localhost';
+ },
+ read_file => sub {
+ # HACK this assumes we are always calling PVE::INotify::read_file('interfaces');
+ return $interfaces_config;
+ },
+ );
+
+ my $pve_sdn_zones_plugin;
+ $pve_sdn_zones_plugin = Test::MockModule->new('PVE::Network::SDN::Zones::Plugin');
+ $pve_sdn_zones_plugin->mock(
+ get_local_route_ip => sub {
+ my ($targetip) = @_;
+ my $outiface = "vmbr0";
+ my $outip = $interfaces_config->{ifaces}->{$outiface}->{address};
+ if (Net::IP::ip_is_ipv6($targetip)) {
+ $outip = $interfaces_config->{ifaces}->{$outiface}->{address6};
+ }
+ return ($outip, $outiface);
+ },
+ );
+
+ my $sdn_module = Test::MockModule->new("PVE::Network::SDN");
+ $sdn_module->mock(
+ running_config => sub {
+ return $sdn_config;
+ },
+ );
+
+ foreach my $bin (qw(iptables ip6tables)) {
+ $tables->{$bin} = { nat => { POSTROUTING => [] }, raw => { PREROUTING => [] } };
+ }
+
+ my $bring_up_interfaces = sub {
+ split_post_up_hooks(PVE::Network::SDN::generate_raw_etc_network_config($sdn_config));
+ };
+
+ my $apply_sdn = sub {
+ $bring_up_interfaces->();
+ PVE::Network::SDN::Zones::apply_new_snat_rules();
+
+ return get_iptables();
+ };
+
+ # every SNAT subnet must show up in the chain of the matching binary (iptables/ip6tables)
+ my $expected = { iptables => [], ip6tables => [] };
+ for my $id (sort keys $sdn_config->{subnets}->{ids}->%*) {
+ next if !$sdn_config->{subnets}->{ids}->{$id}->{snat};
+
+ my ($zone, $network, $mask) = split(/-/, $id);
+ my $bin = Net::IP::ip_is_ipv6($network) ? 'ip6tables' : 'iptables';
+
+ # zones with a dedicated VRF masquerade on each uplink, others use a single SNAT rule
+ my $rules = 1;
+ if ($sdn_config->{zones}->{ids}->{$zone}->{'dedicated-vrf'}) {
+ my $ifaces = $interfaces_config->{ifaces};
+ $rules = grep { ($ifaces->{$_}->{vrf} // '') eq "vrf_$zone" } keys $ifaces->%*;
+ }
+
+ push $expected->{$bin}->@*, ("$network/$mask") x $rules;
+ }
+
+ my $active = {};
+ foreach my $bin (qw(iptables ip6tables)) {
+ my @snat = sort $expected->{$bin}->@*;
+ $active->{$bin} = {
+ chains => @snat ? ['PROXMOX-SDN'] : [],
+ jumps => @snat ? ['-j PROXMOX-SDN'] : [],
+ snat => \@snat,
+ ct_rules => @snat ? 1 : 0,
+ };
+ }
+
+ eq_or_diff($apply_sdn->(), $active, "$name: SNAT rules are active after the first apply");
+ eq_or_diff($apply_sdn->(), $active, "$name: applying again does not duplicate any rule");
+
+ # check that no new chain is prepared if no subnet with SNAT exists anymore
+ delete $_->{snat} for values $sdn_config->{subnets}->{ids}->%*;
+ my $disabled = {};
+ foreach my $bin (qw(iptables ip6tables)) {
+ $disabled->{$bin} = { %{ $active->{$bin} }, chains => [], jumps => [], snat => [] };
+ }
+ eq_or_diff($apply_sdn->(), $disabled, "$name: SNAT chain is removed if SNAT is disabled");
+}
+
+done_testing();
--
2.47.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH manager v3 7/7] fix #5066: network: activate prepared SDN SNAT rules
2026-11-26 15:28 [PATCH manager/network v3 0/7] fix #5066: make generated snat rules flushable Lukas Sichert
` (5 preceding siblings ...)
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 ` Lukas Sichert
6 siblings, 0 replies; 8+ messages in thread
From: Lukas Sichert @ 2026-11-26 15:29 UTC (permalink / raw)
To: pve-devel; +Cc: Lukas Sichert
After reloading the network configuration, activate the SNAT rules
prepared by the generated post-up hooks by replacing the active
PROXMOX-SDN chain with PROXMOX-SDN-NEW. Skip this if the reload failed,
as the post-up hooks may not have prepared the new chain then, and the
active chain keeps working.
During boot, networking.service executes the same post-up hooks without
going through the network reload API. In that case pve-sdn-commit may
find no pending SDN changes and exit early. Activate the prepared chain
before that early exit as well.
Signed-off-by: Lukas Sichert <l.sichert@proxmox.com>
Link: https://bugzilla.proxmox.com/show_bug.cgi?id=5066
---
Notes:
changes v2 -> v3:
- rebased on top of master
- replaces "flush PROXMOX-SDN iptables chain at reload": activate the
prepared chain after ifreload instead of flushing before it
- also activate it from pve-sdn-commit when no changes are pending
changes v1 -> v2:
- rebased on top of master
PVE/API2/Network.pm | 1 +
bin/pve-sdn-commit | 6 ++++++
2 files changed, 7 insertions(+)
diff --git a/PVE/API2/Network.pm b/PVE/API2/Network.pm
index bff98791..b3f477f4 100644
--- a/PVE/API2/Network.pm
+++ b/PVE/API2/Network.pm
@@ -1019,6 +1019,7 @@ __PACKAGE__->register_method({
my $ifreload_err = $@;
if ($have_sdn) {
+ PVE::Network::SDN::Zones::apply_new_snat_rules() if !$ifreload_err;
apply_vrf_ct_zones();
eval { warn_vrf_zones_with_legacy_firewall() };
warn $@ if $@;
diff --git a/bin/pve-sdn-commit b/bin/pve-sdn-commit
index 30d10689..fc1b3ff3 100644
--- a/bin/pve-sdn-commit
+++ b/bin/pve-sdn-commit
@@ -117,6 +117,11 @@ sub sdn_changed {
}
if (!sdn_changed()) {
+ # At boot, networking.service executes the generated post-up hooks and
+ # populates PROXMOX-SDN-NEW. Activate the prepared chain even when there
+ # are no pending SDN changes.
+ PVE::Network::SDN::Zones::apply_new_snat_rules();
+
print "No changes to SDN configuration detected, skipping reload\n";
apply_vrf_ct_zones();
exit 0;
@@ -146,6 +151,7 @@ my $err = sub {
eval { PVE::Tools::run_command(['ifreload', '-a'], errfunc => $err) };
my $ifreload_err = $@;
+PVE::Network::SDN::Zones::apply_new_snat_rules() if !$ifreload_err;
apply_vrf_ct_zones();
# needs the zone VRFs created by ifreload, because dnsmasq is started inside
--
2.47.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-11-26 15:40 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH network v3 3/7] fix #5066: zones: add helper to activate prepared SNAT rules Lukas Sichert
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox