From: Stefan Lendl Date: Fri, 5 Apr 2024 13:17:55 +0000 (+0200) Subject: sdn: dhcp: request both IPv4 and IPv6 addresses on VM start X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=5fd3da139b06f549847daacc34bae4baf4800dd9;p=mirror%2Fpve-network.git sdn: dhcp: request both IPv4 and IPv6 addresses on VM start If previously an IP was allocated in the IPAM, but a new subnet added for the other IP version, we need to allocate an IP in the new subnet. Signed-off-by: Stefan Lendl Reviewed-by: Stefan Hanreich Tested-by: Stefan Hanreich --- diff --git a/src/PVE/Network/SDN/Vnets.pm b/src/PVE/Network/SDN/Vnets.pm index 03609b7..4542b70 100644 --- a/src/PVE/Network/SDN/Vnets.pm +++ b/src/PVE/Network/SDN/Vnets.pm @@ -196,12 +196,10 @@ sub add_dhcp_mapping { return if !$zone->{ipam} || !$zone->{dhcp}; my ($ip4, $ip6) = PVE::Network::SDN::Vnets::get_ips_from_mac($vnetid, $mac); - if ( ! ($ip4 || $ip6) ) { - print "No IP found for MAC: $mac for VMID:$vmid\n"; - add_next_free_cidr($vnetid, $name, $mac, "$vmid", undef, 1); - ($ip4, $ip6) = PVE::Network::SDN::Vnets::get_ips_from_mac($vnetid, $mac); - print "got new IP from IPAM: $ip4 $ip6\n"; - } + add_next_free_cidr($vnetid, $name, $mac, "$vmid", undef, 1, 4) if ! $ip4; + add_next_free_cidr($vnetid, $name, $mac, "$vmid", undef, 1, 6) if ! $ip6; + + ($ip4, $ip6) = PVE::Network::SDN::Vnets::get_ips_from_mac($vnetid, $mac); PVE::Network::SDN::Dhcp::add_mapping($vnetid, $mac, $ip4, $ip6) if $ip4 || $ip6; }