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 5E35D1FF0C2 for ; Thu, 22 Oct 2026 14:49:06 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 4FF27218E0; Thu, 22 Oct 2026 14:48:07 +0200 (CEST) From: Arthur Bied-Charreton To: pve-devel@lists.proxmox.com Subject: [PATCH pve-network v4 15/27] apply: add option to handle dangling references on VNet deletion Date: Thu, 22 Oct 2026 14:46:56 +0200 Message-ID: <20261022124708.429069-16-a.bied-charreton@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261022124708.429069-1-a.bied-charreton@proxmox.com> References: <20261022124708.429069-1-a.bied-charreton@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1792673237544 X-SPAM-LEVEL: Spam detection results: 1 AWL -1.781 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) 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 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 URIBL_DBL_SPAM 5 Contains a spam URL listed in the Spamhaus DBL blocklist [sdn.pm] Message-ID-Hash: X6LNOVMEW7OX7BNHN37JS2BDD2FNLYEP X-Message-ID-Hash: X6LNOVMEW7OX7BNHN37JS2BDD2FNLYEP X-MailFrom: a.bied-charreton@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 | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/PVE/API2/Network/SDN.pm b/src/PVE/API2/Network/SDN.pm index e3c8d9d..88d9d78 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::References; use PVE::JSONSchema qw(get_standard_option); use PVE::RESTHandler; use PVE::RPCEnvironment; @@ -302,6 +304,16 @@ __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.', + }, }, }, returns => { @@ -315,13 +327,35 @@ __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; + my $ref_log = []; + 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::References::update_vnet_ipset_refs( + $removed, + $dangling_refs, + sub { push $ref_log->@*, $_[0] }, + ); + }; + 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(); @@ -336,6 +370,10 @@ __PACKAGE__->register_method({ my $regenerate_frr = ($previous_config_has_frr || $new_config_has_frr) ? 1 : 0; my $code = sub { + # the rewrite has to happen under the SDN lock and before the config is committed, + # which is before there is a task, so the record is only logged here. + print("$_\n") for $ref_log->@*; + $rpcenv->{type} = 'priv'; # to start tasks in background PVE::Cluster::check_cfs_quorum(); my $nodelist = PVE::Cluster::get_nodelist(); -- 2.47.3