From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-network 4/4] subnet: dhcp: do not allow overlapping dhcp ranges
Date: Fri, 7 Mar 2025 13:50:56 +0100 [thread overview]
Message-ID: <20250307125056.169575-4-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20250307125056.169575-1-s.hanreich@proxmox.com>
Check for overlapping DHCP ranges and reject them if there are any
overlaps. If we can be certain that there are no overlapping DHCP
ranges this saves us from running into errors later in IPAM modules
where overlapping DHCP ranges are not allowed.
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
src/PVE/Network/SDN/SubnetPlugin.pm | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/PVE/Network/SDN/SubnetPlugin.pm b/src/PVE/Network/SDN/SubnetPlugin.pm
index c842450..b911d69 100644
--- a/src/PVE/Network/SDN/SubnetPlugin.pm
+++ b/src/PVE/Network/SDN/SubnetPlugin.pm
@@ -3,7 +3,7 @@ package PVE::Network::SDN::SubnetPlugin;
use strict;
use warnings;
-use Net::IP;
+use Net::IP qw($IP_NO_OVERLAP);
use Net::Subnet qw(subnet_matcher);
use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file);
@@ -82,6 +82,8 @@ sub validate_dhcp_ranges {
my $dhcp_ranges = PVE::Network::SDN::Subnets::get_dhcp_ranges($subnet);
+ my $validated_ranges = [];
+
foreach my $dhcp_range (@$dhcp_ranges) {
my $dhcp_start = $dhcp_range->{'start-address'};
my $dhcp_end = $dhcp_range->{'end-address'};
@@ -102,6 +104,15 @@ sub validate_dhcp_ranges {
raise_param_exc({ 'dhcp-range' => "start-address $dhcp_start is not in subnet $cidr" }) if !$subnet_matcher->($dhcp_start);
raise_param_exc({ 'dhcp-range' => "end-address $dhcp_end is not in subnet $cidr" }) if !$subnet_matcher->($dhcp_end);
+
+ my $ip_range = Net::IP->new("$dhcp_range->{'start-address'} - $dhcp_range->{'end-address'}");
+ for my $other_range (@$validated_ranges) {
+ if ($ip_range->overlaps($other_range) != $Net::IP::IP_NO_OVERLAP) {
+ raise_param_exc({ 'dhcp-range' => "dhcp ranges must not overlap" });
+ }
+ }
+
+ push @$validated_ranges, $ip_range;
}
}
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-03-07 12:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-07 12:50 [pve-devel] [PATCH pve-network 1/4] subnet: dhcp: improve Net::IP usage Stefan Hanreich
2025-03-07 12:50 ` [pve-devel] [PATCH pve-network 2/4] subnet: dhcp: fix typo in error message Stefan Hanreich
2025-03-07 12:50 ` [pve-devel] [PATCH pve-network 3/4] subnet: dhcp: only accept single ips and normalize them Stefan Hanreich
2025-03-07 12:50 ` Stefan Hanreich [this message]
2025-04-07 15:37 ` [pve-devel] [PATCH pve-network 1/4] subnet: dhcp: improve Net::IP usage Hannes Duerr
2025-04-07 16:42 ` [pve-devel] applied: " Thomas Lamprecht
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=20250307125056.169575-4-s.hanreich@proxmox.com \
--to=s.hanreich@proxmox.com \
--cc=pve-devel@lists.proxmox.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal