]> git.puffer.fish Git - mirror/pve-network.git/commitdiff
sdn: dhcp: rollback allocated ips on failure
authorStefan Hanreich <s.hanreich@proxmox.com>
Fri, 5 Apr 2024 13:17:57 +0000 (15:17 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 8 Apr 2024 15:57:18 +0000 (17:57 +0200)
If DHCP is configured for IPv4 and IPv6, failing to obtain an IPv6 IP
does not roll back the allocation made for IPv4. This patch rolls back
any changes made in case of failure, so that IP allocation is actually
atomic.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Stefan Lendl <s.lendl@proxmox.com>
Tested-by: Stefan Lendl <s.lendl@proxmox.com>
Signed-off-by: Stefan Lendl <s.lendl@proxmox.com>
src/PVE/Network/SDN/Vnets.pm

index cbf0a074095999f82c829f1f2eb18bbb9bd17561..45292e32972c0a53424f8c75f7a76d5090a64f00 100644 (file)
@@ -131,7 +131,17 @@ sub add_next_free_cidr {
                last;
            }
        }
-       die "can't find any free ip" if !$ip && $subnetcount > 0;
+
+       if (!$ip && $subnetcount > 0) {
+           foreach my $version (sort keys %{$ips}) {
+               my $ip = $ips->{$version};
+               my ($subnetid, $subnet) = PVE::Network::SDN::Subnets::find_ip_subnet($ip, $subnets);
+
+               PVE::Network::SDN::Subnets::del_ip($zone, $subnetid, $subnet, $ip, $hostname, $mac, $skipdns);
+           }
+
+           die "can't find any free ip in zone $zoneid for IPv$ipversion";
+       }
     }
 }