From: Gabriel Goller <g.goller@proxmox.com>
To: Proxmox Backup Server development discussion
<pbs-devel@lists.proxmox.com>, Stefan Lendl <s.lendl@proxmox.com>
Subject: Re: [pbs-devel] [PATCH pve-network] sdn: validate dhcp-range in API
Date: Wed, 22 Nov 2023 14:07:55 +0100 [thread overview]
Message-ID: <8c8af953-e45c-4f67-b8d0-173f352c7cda@proxmox.com> (raw)
In-Reply-To: <20231122130040.269759-2-s.lendl@proxmox.com>
wrong mailing list :)
On 11/22/23 14:00, Stefan Lendl wrote:
> * start- and end-addresses must be valid IPs
> * must both be in the subnet's CIDR
> * and start needs to smaller (or equal) to end
>
> Signed-off-by: Stefan Lendl <s.lendl@proxmox.com>
> ---
> src/PVE/Network/SDN/SubnetPlugin.pm | 28 ++++++++++++++++++++++++++++
> 1 file changed, 28 insertions(+)
>
> diff --git a/src/PVE/Network/SDN/SubnetPlugin.pm b/src/PVE/Network/SDN/SubnetPlugin.pm
> index 37b6b2b..049f7e1 100644
> --- a/src/PVE/Network/SDN/SubnetPlugin.pm
> +++ b/src/PVE/Network/SDN/SubnetPlugin.pm
> @@ -74,6 +74,33 @@ my $dhcp_range_fmt = {
>
> PVE::JSONSchema::register_format('pve-sdn-dhcp-range', $dhcp_range_fmt);
>
> +sub validate_dhcp_ranges {
> + my ($subnet) = @_;
> +
> + my $cidr = $subnet->{cidr};
> + my $subnet_matcher = subnet_matcher($cidr);
> +
> + my $dhcp_ranges = PVE::Network::SDN::Subnets::get_dhcp_ranges($subnet);
> +
> + foreach my $dhcp_range (@$dhcp_ranges) {
> + my $dhcp_start = $dhcp_range->{'start-address'};
> + my $dhcp_end = $dhcp_range->{'end-address'};
> +
> + my $start_ip = new Net::IP($dhcp_start);
> + raise_param_exc({ 'dhcp-range' => "start-adress is not a valid IP $dhcp_start" }) if !$start_ip;
> +
> + my $end_ip = new Net::IP($dhcp_end);
> + raise_param_exc({ 'dhcp-range' => "end-adress is not a valid IP $dhcp_end" }) if !$end_ip;
> +
> + if (Net::IP::ip_bincomp($end_ip->binip(), 'lt', $start_ip->binip()) == 1) {
> + raise_param_exc({ 'dhcp-range' => "start-address $dhcp_start must be smaller than end-address $dhcp_end" })
> + }
> +
> + 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);
> + }
> +}
> +
> sub properties {
> return {
> vnet => {
> @@ -156,6 +183,7 @@ sub on_update_hook {
> #for /32 pointopoint, we allow gateway outside the subnet
> raise_param_exc({ gateway => "$gateway is not in subnet $cidr"}) if $gateway && !$subnet_matcher->($gateway) && !$pointopoint;
>
> + validate_dhcp_ranges($subnet);
>
> if ($ipam) {
> PVE::Network::SDN::Subnets::add_subnet($zone, $subnetid, $subnet);
next prev parent reply other threads:[~2023-11-22 13:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-22 13:00 Stefan Lendl
2023-11-22 13:07 ` Gabriel Goller [this message]
2023-11-22 13:39 ` [pbs-devel] applied: " Thomas Lamprecht
2023-11-22 16:28 ` [pbs-devel] [pve-devel] " DERUMIER, Alexandre
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=8c8af953-e45c-4f67-b8d0-173f352c7cda@proxmox.com \
--to=g.goller@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
--cc=s.lendl@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