[pve-devel] [PATCH v3 pve-network 01/12] sdn: dhcp: get next free ip for a specific IP version

Stefan Lendl s.lendl at proxmox.com
Fri Apr 5 15:17:54 CEST 2024


Specify the IP version (4|6) for which an IP shall be requested from the IPAM.

Signed-off-by: Stefan Lendl <s.lendl at proxmox.com>
Reviewed-by: Stefan Hanreich <s.hanreich at proxmox.com>
Tested-by: Stefan Hanreich <s.hanreich at proxmox.com>
---
 src/PVE/Network/SDN/Subnets.pm | 2 +-
 src/PVE/Network/SDN/Vnets.pm   | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/PVE/Network/SDN/Subnets.pm b/src/PVE/Network/SDN/Subnets.pm
index 3b08dcd..e2c8c9c 100644
--- a/src/PVE/Network/SDN/Subnets.pm
+++ b/src/PVE/Network/SDN/Subnets.pm
@@ -206,7 +206,7 @@ sub del_subnet {
 }
 
 sub add_next_free_ip {
-    my ($zone, $subnetid, $subnet, $hostname, $mac, $vmid, $skipdns, $dhcprange) = @_;
+    my ($zone, $subnetid, $subnet, $hostname, $mac, $vmid, $skipdns, $dhcprange, $ipversion) = @_;
 
     my $cidr = undef;
     my $ip = undef;
diff --git a/src/PVE/Network/SDN/Vnets.pm b/src/PVE/Network/SDN/Vnets.pm
index 0dfdfd7..03609b7 100644
--- a/src/PVE/Network/SDN/Vnets.pm
+++ b/src/PVE/Network/SDN/Vnets.pm
@@ -95,7 +95,7 @@ sub get_subnet_from_vnet_ip {
 }
 
 sub add_next_free_cidr {
-    my ($vnetid, $hostname, $mac, $vmid, $skipdns, $dhcprange) = @_;
+    my ($vnetid, $hostname, $mac, $vmid, $skipdns, $dhcprange, $ipversion) = @_;
 
     my $vnet = PVE::Network::SDN::Vnets::get_vnet($vnetid);
     return if !$vnet;
@@ -109,7 +109,7 @@ sub add_next_free_cidr {
 
     my $ips = {};
 
-    my @ipversions = qw/ 4 6 /;
+    my @ipversions = defined($ipversion) ? ($ipversion) : qw/ 4 6 /;
     for my $ipversion (@ipversions) {
 	my $ip = undef;
 	my $subnetcount = 0;
@@ -125,7 +125,7 @@ sub add_next_free_cidr {
 	    };
 	    die $@ if $@;
 
-            if ($ip) {
+	    if ($ip) {
 		$ips->{$ipversion} = $ip;
 		last;
 	    }
-- 
2.44.0





More information about the pve-devel mailing list