From 0565f489ffa3818f17f83400d782d2bf00caa91f Mon Sep 17 00:00:00 2001 From: Stefan Hanreich Date: Wed, 17 Jul 2024 15:06:02 +0200 Subject: [PATCH] config: net: avoid duplicate ipam entries on nic update Updating the NIC of a VM when the following conditions were met: * VM is turned off * NIC is on a bridge that uses automatic dhcp * Leave bridge unchanged led to duplicate IPAM entries for the same network device. This is due to the fact that the add_next_free_cidr always ran on applying pending network changes. Now we only add a new ipam entry if either: * the value of the bridge or mac address changed * the network device has been newly added This way no duplicate IPAM entries should get created. Signed-off-by: Stefan Hanreich --- PVE/QemuServer.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 88c274d0..bf59b091 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -5254,10 +5254,11 @@ sub vmconfig_apply_pending { safe_string_ne($old_net->{macaddr}, $new_net->{macaddr}) )) { PVE::Network::SDN::Vnets::del_ips_from_mac($old_net->{bridge}, $old_net->{macaddr}, $conf->{name}); + PVE::Network::SDN::Vnets::add_next_free_cidr($new_net->{bridge}, $conf->{name}, $new_net->{macaddr}, $vmid, undef, 1); } + } else { + PVE::Network::SDN::Vnets::add_next_free_cidr($new_net->{bridge}, $conf->{name}, $new_net->{macaddr}, $vmid, undef, 1); } - #fixme: reuse ip if mac change && same bridge - PVE::Network::SDN::Vnets::add_next_free_cidr($new_net->{bridge}, $conf->{name}, $new_net->{macaddr}, $vmid, undef, 1); } }; if (my $err = $@) {