[pve-devel] [PATCH v4 pve-network 06/33] subnet: vnet: refactor IPAM related methods

Stefan Lendl s.lendl at proxmox.com
Fri Nov 17 15:13:04 CET 2023


Stefan Hanreich <s.hanreich at proxmox.com> writes:

> @@ -230,10 +227,28 @@ sub next_free_ip {
>  	my $plugin_config = $ipam_cfg->{ids}->{$ipamid};
>  	my $plugin = PVE::Network::SDN::Ipams::Plugin->lookup($plugin_config->{type});
>  	eval {
> -	    $cidr = $plugin->add_next_freeip($plugin_config, $subnetid, $subnet, $hostname, $mac, $description);
> -	    ($ip, undef) = split(/\//, $cidr);
> +	    if ($dhcprange) {
> +		my $data = {
> +		    mac => $mac,
> +		    hostname => $hostname,
> +		    vmid => $vmid,
> +		};
> +
> +		my $dhcp_ranges = PVE::Network::SDN::Subnets::get_dhcp_ranges($subnet);
> +
> +		foreach my $range (@$dhcp_ranges) {
> +		    $ip = $plugin->add_range_next_freeip($plugin_config, $subnet, $range, $data);
> +	            next if !$ip;

If an IP was found, the loop will just start again.
This should be (tested):

last if $ip;


> +		}
> +	    } else {
> +		$ip = $plugin->add_next_freeip($plugin_config, $subnetid, $subnet, $hostname, $mac, $vmid);
> +	    }
>  	};
> +
>  	die $@ if $@;
> +
> +	eval { PVE::Network::SDN::Ipams::add_cache_mac_ip($mac, $ip); };
> +	warn $@ if $@;
>      }
>  
>      eval {





More information about the pve-devel mailing list