From 27b54a086b527322c6c192c0654e5bd7f9334fc5 Mon Sep 17 00:00:00 2001 From: Stefan Hanreich Date: Fri, 5 Apr 2024 15:17:57 +0200 Subject: [PATCH] sdn: dhcp: rollback allocated ips on failure 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 Reviewed-by: Stefan Lendl Tested-by: Stefan Lendl Signed-off-by: Stefan Lendl --- src/PVE/Network/SDN/Vnets.pm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/PVE/Network/SDN/Vnets.pm b/src/PVE/Network/SDN/Vnets.pm index cbf0a07..45292e3 100644 --- a/src/PVE/Network/SDN/Vnets.pm +++ b/src/PVE/Network/SDN/Vnets.pm @@ -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"; + } } } -- 2.39.5