all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-network 3/4] subnet: dhcp: only accept single ips and normalize them
Date: Fri,  7 Mar 2025 13:50:55 +0100	[thread overview]
Message-ID: <20250307125056.169575-3-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20250307125056.169575-1-s.hanreich@proxmox.com>

Net::IP accepts a myriad of different IP objects from ranges to
prefixes to singular IPs. We check if the object consists only of a
singular IP and normalize the IP if it has size 1 (since then it
could still be a /32 prefix or a range consisting of one IP).
Otherwise we would theoretically accept any valid Net::IP object here.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
 src/PVE/Network/SDN/SubnetPlugin.pm | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/PVE/Network/SDN/SubnetPlugin.pm b/src/PVE/Network/SDN/SubnetPlugin.pm
index 8733018..c842450 100644
--- a/src/PVE/Network/SDN/SubnetPlugin.pm
+++ b/src/PVE/Network/SDN/SubnetPlugin.pm
@@ -88,9 +88,13 @@ sub validate_dhcp_ranges {
 
 	my $start_ip = Net::IP->new($dhcp_start);
 	raise_param_exc({ 'dhcp-range' => "start-address is not a valid IP $dhcp_start" }) if !$start_ip;
+	raise_param_exc({ 'dhcp-range' => "start-address must be a singular IP" }) if $start_ip->size() != 1;
+	$dhcp_range->{'start-address'} = $start_ip->ip();
 
 	my $end_ip = Net::IP->new($dhcp_end);
 	raise_param_exc({ 'dhcp-range' => "end-address is not a valid IP $dhcp_end" }) if !$end_ip;
+	raise_param_exc({ 'dhcp-range' => "end-address must be a singular IP" }) if $end_ip->size() != 1;
+	$dhcp_range->{'end-address'} = $end_ip->ip();
 
 	if ($start_ip->bincomp('gt', $end_ip)) {
 	    raise_param_exc({ 'dhcp-range' => "start-address $dhcp_start must be smaller than end-address $dhcp_end" })
-- 
2.39.5


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


  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 ` Stefan Hanreich [this message]
2025-03-07 12:50 ` [pve-devel] [PATCH pve-network 4/4] subnet: dhcp: do not allow overlapping dhcp ranges Stefan Hanreich
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-3-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 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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal