* [pve-devel] [PATCH pve-network 1/1] fix: prevent duplicate DHCP leases for identical MAC address
[not found] <20251104122026.62228-1-philippos.g@me.com>
@ 2025-11-04 12:20 ` Philippos Giavridis via pve-devel
0 siblings, 0 replies; only message in thread
From: Philippos Giavridis via pve-devel @ 2025-11-04 12:20 UTC (permalink / raw)
To: pve-devel; +Cc: Philippos Giavridis
[-- Attachment #1: Type: message/rfc822, Size: 6912 bytes --]
From: Philippos Giavridis <philippos.g@me.com>
To: pve-devel@lists.proxmox.com
Cc: Philippos Giavridis <philippos.g@me.com>
Subject: [PATCH pve-network 1/1] fix: prevent duplicate DHCP leases for identical MAC address
Date: Tue, 4 Nov 2025 12:20:26 +0000
Message-ID: <20251104122026.62228-2-philippos.g@me.com>
When cloning a VM with the same MAC address, the SDN IPAM module
currently assigns a new IP instead of using the existing reservation.
This patch adds a check for existing MAC address mappings before
allocating a new IP address.
If such a mapping exists, the new VM receives the defined IP instead
of a new one from the DHCP pool.
Signed-off-by: Philippos Giavridis <philippos.g@me.com>
---
src/PVE/Network/SDN/Subnets.pm | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/src/PVE/Network/SDN/Subnets.pm b/src/PVE/Network/SDN/Subnets.pm
index 1f27fac..66fb721 100644
--- a/src/PVE/Network/SDN/Subnets.pm
+++ b/src/PVE/Network/SDN/Subnets.pm
@@ -235,6 +235,30 @@ sub add_next_free_ip {
#verify dns zones before ipam
verify_dns_zone($dnszone, $dns) if !$skipdns;
+ if ($mac && $ipamid) {
+ my ($zoneid) = split(/-/, $subnetid);
+ my ($existing_ip4, $existing_ip6) = PVE::Network::SDN::Ipams::get_ips_from_mac(
+ $mac, $zoneid, $zone,
+ );
+
+ my $is_ipv4 = Net::IP::ip_is_ipv4($subnet->{network});
+ my $existing_ip = $is_ipv4 ? $existing_ip4 : $existing_ip6;
+
+ if ($existing_ip) {
+ my $ip_obj = NetAddr::IP->new($existing_ip);
+ my $subnet_obj = NetAddr::IP->new($subnet->{cidr});
+
+ if ($subnet_obj->contains($ip_obj)) {
+ $ip = $existing_ip;
+
+ eval { PVE::Network::SDN::Ipams::add_cache_mac_ip($mac, $ip); };
+ warn $@ if $@;
+
+ goto DNS_SETUP;
+ }
+ }
+ }
+
if ($ipamid) {
my $ipam_cfg = PVE::Network::SDN::Ipams::config();
my $plugin_config = $ipam_cfg->{ids}->{$ipamid};
@@ -267,6 +291,7 @@ sub add_next_free_ip {
warn $@ if $@;
}
+DNS_SETUP:
eval {
my $reversednszone = get_reversedns_zone($subnetid, $subnet, $reversedns, $ip);
--
2.43.0
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-11-04 16:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20251104122026.62228-1-philippos.g@me.com>
2025-11-04 12:20 ` [pve-devel] [PATCH pve-network 1/1] fix: prevent duplicate DHCP leases for identical MAC address Philippos Giavridis via pve-devel
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.