From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 0350E1FF0B3 for ; Fri, 25 Sep 2026 11:43:53 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 10C6421815; Fri, 25 Sep 2026 11:42:39 +0200 (CEST) From: Arthur Bied-Charreton To: pve-devel@lists.proxmox.com subject: SPAM: [PATCH pve-network v3 08/16] apply: add option to handle dangling references on VNet deletion Date: Fri, 25 Sep 2026 11:42:22 +0200 Message-ID: <20260925094230.844917-9-a.bied-charreton@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260925094230.844917-1-a.bied-charreton@proxmox.com> References: <20260925094230.844917-1-a.bied-charreton@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 5 AWL -2.120 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) KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods POISEN_SPAM_PILL 0.1 Meta: its spam POISEN_SPAM_PILL_1 0.1 random spam to be learned in bayes POISEN_SPAM_PILL_3 0.1 random spam to be learned in bayes RDNS_NONE 1.274 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record URIBL_DBL_SPAM 5 Contains a spam URL listed in the Spamhaus DBL blocklist [sdn.pm] Message-ID-Hash: IQSYW62XES6KH5WD4QNMFBHRVDXCNUIA X-Message-ID-Hash: IQSYW62XES6KH5WD4QNMFBHRVDXCNUIA X-MailFrom: abied-charreton@jett.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 X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: For each VNet, 4 IPSets are auto-generated (-all, -gateway, -no-gateway and -dhcp) [0]. Therefore, deleting a VNet can lead to rules referencing non-existing IPSets, which the firewall fails to parse and ignores. Add a 'dangling-ipset-references' option for PUT /cluster/sdn allowing to 'drop' rules referencing now-deleted IPSets, 'disable' them, or 'keep' them as they are. [0] https://pve.proxmox.com/wiki/Software-Defined_Network#pvesdn_firewall_integration Signed-off-by: Arthur Bied-Charreton --- src/PVE/API2/Network/SDN.pm | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/PVE/API2/Network/SDN.pm b/src/PVE/API2/Network/SDN.pm index e3c8d9d..e304299 100644 --- a/src/PVE/API2/Network/SDN.pm +++ b/src/PVE/API2/Network/SDN.pm @@ -8,6 +8,8 @@ use JSON qw(from_json); use PVE::Cluster qw(cfs_lock_file cfs_read_file cfs_write_file); use PVE::Exception qw(raise_param_exc); +use PVE::Firewall; +use PVE::Firewall::Helpers; use PVE::JSONSchema qw(get_standard_option); use PVE::RESTHandler; use PVE::RPCEnvironment; @@ -302,6 +304,18 @@ __PACKAGE__->register_method({ description => 'When lock-token has been provided and configuration successfully committed, release the lock automatically afterwards', }, + 'dangling-ipset-references' => { + type => 'string', + enum => ['keep', 'disable', 'drop'], + optional => 1, + default => 'keep', + description => + 'If the applied SDN changes delete one or more VNets, handle the firewall ' + . 'rules referencing their auto-generated IPSets. Use \'disable\' to disable ' + . 'those rules, or \'drop\' to remove them entirely. Kept as they are, they ' + . 'reference an IPSet that no longer exists and are dropped from the ' + . 'generated ruleset.', + }, }, }, returns => { @@ -315,6 +329,7 @@ __PACKAGE__->register_method({ my $lock_token = extract_param($param, 'lock-token'); my $release_lock = extract_param($param, 'release-lock'); + my $dangling_refs = extract_param($param, 'dangling-ipset-references') // 'keep'; my $previous_config_has_frr; my $new_config_has_frr; @@ -322,6 +337,23 @@ __PACKAGE__->register_method({ PVE::Network::SDN::lock_sdn_config( sub { $previous_config_has_frr = PVE::Network::SDN::running_config_has_frr(); + + if ($dangling_refs ne 'keep') { + my $running = PVE::Network::SDN::running_config() // {}; + my $vnets = PVE::Network::SDN::Vnets::config() // {}; + my $removed = + [grep { !$vnets->{ids}->{$_} } keys $running->{vnets}->{ids}->%*]; + + if ($removed->@*) { + eval { + PVE::Firewall::Helpers::update_vnet_ipset_refs( + $removed, $dangling_refs, + ); + }; + warn "could not update references to VNet IPSets: $@" if $@; + } + } + PVE::Network::SDN::commit_config(); $new_config_has_frr = PVE::Network::SDN::running_config_has_frr(); -- 2.47.3