From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 9E491A02F7 for ; Wed, 8 Nov 2023 12:35:56 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 87B276A21 for ; Wed, 8 Nov 2023 12:35:56 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 8 Nov 2023 12:35:56 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id C960147396; Wed, 8 Nov 2023 12:35:55 +0100 (CET) From: Stefan Lendl To: pve-devel@lists.proxmox.com Date: Wed, 8 Nov 2023 12:35:35 +0100 Message-ID: <20231108113535.3905405-3-s.lendl@proxmox.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231108113535.3905405-1-s.lendl@proxmox.com> References: <20231108113535.3905405-1-s.lendl@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.070 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH pve-network 2/2] Create a cluster-wide firewall for SDN subnets X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Nov 2023 11:35:56 -0000 Upon creation of a subnet, we create a cluster-wide firewall alias. Signed-off-by: Stefan Lendl --- Notes: Creates the alias directly when the Subnet is created. Other SDN objects are created upon 'Apply': commit_config(). Although, IPAM creates the subnet right away as well. This should not be an issue but is inconsistent. src/PVE/Network/SDN/Subnets.pm | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/PVE/Network/SDN/Subnets.pm b/src/PVE/Network/SDN/Subnets.pm index 6bb42e5..fe67abd 100644 --- a/src/PVE/Network/SDN/Subnets.pm +++ b/src/PVE/Network/SDN/Subnets.pm @@ -6,6 +6,7 @@ use warnings; use Net::Subnet qw(subnet_matcher); use Net::IP; use NetAddr::IP qw(:lower); +use PVE::API2::Firewall::Aliases; use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file); use PVE::Network::SDN::Dns; @@ -161,6 +162,13 @@ sub del_dns_ptr_record { $plugin->del_ptr_record($plugin_config, $reversezone, $ip); } +sub get_fw_alias_name { + my ($subnet) = @_; + my $cidr = $subnet->{cidr}; + $cidr =~ tr/.\//-/; + return "$subnet->{zone}_$subnet->{vnet}_$cidr"; +} + sub add_subnet { my ($zone, $subnetid, $subnet) = @_; @@ -170,6 +178,13 @@ sub add_subnet { my $plugin_config = $ipam_cfg->{ids}->{$ipam}; my $plugin = PVE::Network::SDN::Ipams::Plugin->lookup($plugin_config->{type}); $plugin->add_subnet($plugin_config, $subnetid, $subnet); + + my $param = { + name => get_fw_alias_name($subnet), + cidr => $subnet->{cidr}, + comment => "Automatically created Alias from SDN => Zone: $subnet->{zone}, VNet: $subnet->{vnet}, Subnet: $subnet->{cidr}" + }; + PVE::API2::Firewall::ClusterAliases->create_alias($param); } sub del_subnet { @@ -181,6 +196,9 @@ sub del_subnet { my $plugin_config = $ipam_cfg->{ids}->{$ipam}; my $plugin = PVE::Network::SDN::Ipams::Plugin->lookup($plugin_config->{type}); $plugin->del_subnet($plugin_config, $subnetid, $subnet); + + my $param = { name => get_fw_alias_name($subnet) }; + PVE::API2::Firewall::ClusterAliases->remove_alias($param); } sub next_free_ip { -- 2.41.0