]> git.proxmox.com Git - pve-network.git/commitdiff
sdn: dhcp: request both IPv4 and IPv6 addresses on VM start
authorStefan Lendl <s.lendl@proxmox.com>
Fri, 5 Apr 2024 13:17:55 +0000 (15:17 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 8 Apr 2024 15:57:18 +0000 (17:57 +0200)
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 <s.lendl@proxmox.com>
Reviewed-by: Stefan Hanreich <s.hanreich@proxmox.com>
Tested-by: Stefan Hanreich <s.hanreich@proxmox.com>
src/PVE/Network/SDN/Vnets.pm

index 03609b7275a068bce1f7d644e2904593bd1001f0..4542b70a658620e318b6ba0663909a7deeb93650 100644 (file)
@@ -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;
 }