From: Philippos Giavridis via pve-devel <pve-devel@lists.proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Philippos Giavridis <philippos.g@me.com>
Subject: [pve-devel] [PATCH pve-network 1/1] fix: prevent duplicate DHCP leases for identical MAC address
Date: Tue, 4 Nov 2025 12:20:26 +0000 [thread overview]
Message-ID: <mailman.601.1762272148.362.pve-devel@lists.proxmox.com> (raw)
In-Reply-To: <20251104122026.62228-1-philippos.g@me.com>
[-- 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
parent reply other threads:[~2025-11-04 16:01 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <20251104122026.62228-1-philippos.g@me.com>]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=mailman.601.1762272148.362.pve-devel@lists.proxmox.com \
--to=pve-devel@lists.proxmox.com \
--cc=philippos.g@me.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.