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 A5F78988AD for ; Mon, 13 Nov 2023 11:05:10 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8903910A8B for ; Mon, 13 Nov 2023 11:04:39 +0100 (CET) Received: from bastionodiso.odiso.net (bastionodiso.odiso.net [185.151.191.93]) (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 ; Mon, 13 Nov 2023 11:04:34 +0100 (CET) Received: from kvmformation3.odiso.net (formationkvm3.odiso.net [10.3.94.12]) by bastionodiso.odiso.net (Postfix) with ESMTP id 3BF99D9AF; Mon, 13 Nov 2023 11:04:22 +0100 (CET) Received: by kvmformation3.odiso.net (Postfix, from userid 0) id 3A2DE13AB36; Mon, 13 Nov 2023 11:04:22 +0100 (CET) From: Alexandre Derumier To: pve-devel@lists.proxmox.com Date: Mon, 13 Nov 2023 11:04:16 +0100 Message-Id: <20231113100419.3317478-13-aderumier@odiso.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231113100419.3317478-1-aderumier@odiso.com> References: <20231113100419.3317478-1-aderumier@odiso.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.028 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 HEADER_FROM_DIFFERENT_DOMAINS 0.249 From and EnvelopeFrom 2nd level mail domains are different KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods SPF_NONE 0.001 SPF: sender does not publish an SPF Record T_SCC_BODY_TEXT_LINE -0.01 - T_SPF_HELO_TEMPERROR 0.01 SPF: test of HELO record failed (temperror) Subject: [pve-devel] [RFC pve-network 6/9] vnets: rename del|add|update_cidr to ip 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: Mon, 13 Nov 2023 10:05:10 -0000 Signed-off-by: Alexandre Derumier --- src/PVE/Network/SDN/Subnets.pm | 4 +--- src/PVE/Network/SDN/Vnets.pm | 27 ++++++++++++--------------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/PVE/Network/SDN/Subnets.pm b/src/PVE/Network/SDN/Subnets.pm index b2125a1..905ec77 100644 --- a/src/PVE/Network/SDN/Subnets.pm +++ b/src/PVE/Network/SDN/Subnets.pm @@ -93,14 +93,12 @@ sub get_subnet { } sub find_ip_subnet { - my ($ip, $mask, $subnets) = @_; + my ($ip, $subnets) = @_; my $subnet = undef; my $subnetid = undef; foreach my $id (sort keys %{$subnets}) { - - next if $mask ne $subnets->{$id}->{mask}; my $cidr = $subnets->{$id}->{cidr}; my $subnet_matcher = subnet_matcher($cidr); next if !$subnet_matcher->($ip); diff --git a/src/PVE/Network/SDN/Vnets.pm b/src/PVE/Network/SDN/Vnets.pm index 9ba1a1e..2f42da6 100644 --- a/src/PVE/Network/SDN/Vnets.pm +++ b/src/PVE/Network/SDN/Vnets.pm @@ -80,18 +80,15 @@ sub get_subnets { return $subnets; } -sub get_subnet_from_vnet_cidr { - my ($vnetid, $cidr) = @_; +sub get_subnet_from_vnet_ip { + my ($vnetid, $ip) = @_; my $subnets = PVE::Network::SDN::Vnets::get_subnets($vnetid, 1); my $vnet = PVE::Network::SDN::Vnets::get_vnet($vnetid); my $zoneid = $vnet->{zone}; my $zone = PVE::Network::SDN::Zones::get_zone($zoneid); - my ($ip, $mask) = split(/\//, $cidr); - die "ip address is not in cidr format" if !$mask; - - my ($subnetid, $subnet) = PVE::Network::SDN::Subnets::find_ip_subnet($ip, $mask, $subnets); + my ($subnetid, $subnet) = PVE::Network::SDN::Subnets::find_ip_subnet($ip, $subnets); return ($zone, $subnetid, $subnet, $ip); } @@ -128,30 +125,30 @@ sub add_next_free_cidr { } } -sub add_cidr { - my ($vnetid, $cidr, $hostname, $mac, $description, $skipdns) = @_; +sub add_ip { + my ($vnetid, $ip, $hostname, $mac, $description, $skipdns) = @_; return if !$vnetid; - my ($zone, $subnetid, $subnet, $ip) = PVE::Network::SDN::Vnets::get_subnet_from_vnet_cidr($vnetid, $cidr); + my ($zone, $subnetid, $subnet) = PVE::Network::SDN::Vnets::get_subnet_from_vnet_ip($vnetid, $ip); PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip, $hostname, $mac, $description, undef, $skipdns); } -sub update_cidr { - my ($vnetid, $cidr, $hostname, $oldhostname, $mac, $description, $skipdns) = @_; +sub update_ip { + my ($vnetid, $ip, $hostname, $oldhostname, $mac, $description, $skipdns) = @_; return if !$vnetid; - my ($zone, $subnetid, $subnet, $ip) = PVE::Network::SDN::Vnets::get_subnet_from_vnet_cidr($vnetid, $cidr); + my ($zone, $subnetid, $subnet) = PVE::Network::SDN::Vnets::get_subnet_from_vnet_ip($vnetid, $ip); PVE::Network::SDN::Subnets::update_ip($zone, $subnetid, $subnet, $ip, $hostname, $oldhostname, $mac, $description, $skipdns); } -sub del_cidr { - my ($vnetid, $cidr, $hostname, $skipdns) = @_; +sub del_ip { + my ($vnetid, $ip, $hostname, $skipdns) = @_; return if !$vnetid; - my ($zone, $subnetid, $subnet, $ip) = PVE::Network::SDN::Vnets::get_subnet_from_vnet_cidr($vnetid, $cidr); + my ($zone, $subnetid, $subnet) = PVE::Network::SDN::Vnets::get_subnet_from_vnet_ip($vnetid, $ip); PVE::Network::SDN::Subnets::del_ip($zone, $subnetid, $subnet, $ip, $hostname, $skipdns); } -- 2.39.2