[pve-devel] [PATCH pve-network 16/38] ipam : pveplugin : fix find_next_free_ip

Alexandre Derumier aderumier at odiso.com
Sun Nov 8 15:19:18 CET 2020


skip network && broadcast address
---
 PVE/Network/SDN/Ipams/PVEPlugin.pm | 11 ++++++-----
 debian/control                     |  1 +
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/PVE/Network/SDN/Ipams/PVEPlugin.pm b/PVE/Network/SDN/Ipams/PVEPlugin.pm
index 99af0ed..741a680 100644
--- a/PVE/Network/SDN/Ipams/PVEPlugin.pm
+++ b/PVE/Network/SDN/Ipams/PVEPlugin.pm
@@ -6,7 +6,7 @@ use PVE::INotify;
 use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_register_file cfs_lock_file);
 use PVE::Tools;
 use JSON;
-use Net::IP;
+use NetAddr::IP;
 use Digest::SHA;
 
 use base('PVE::Network::SDN::Ipams::Plugin');
@@ -93,12 +93,13 @@ sub add_next_freeip {
 
 	my $db = read_db();
 	my $s = $db->{subnets}->{$cidr};
-
-	my $iplist = new Net::IP($cidr);
+	my $iplist = new NetAddr::IP($cidr);
+	my $broadcast = $iplist->broadcast();
 
 	while(1) {
-	    my $ip = $iplist->ip();
-	    ++$iplist;
+	    $iplist++;
+	    last if $iplist eq $broadcast;
+	    my $ip = $iplist->addr();
 	    next if defined($s->{ips}->{$ip});
 	    $freeip = $ip;
 	    last;
diff --git a/debian/control b/debian/control
index c54f8bc..b2e3614 100644
--- a/debian/control
+++ b/debian/control
@@ -18,6 +18,7 @@ Depends: libpve-common-perl (>= 5.0-45),
          pve-cluster (>= 5.0-32),
          libnet-subnet-perl,
          libnet-ip-perl,
+         libnetaddr-ip-perl,
          ${misc:Depends},
          ${perl:Depends},
 Recommends: frr-pythontools, ifupdown2
-- 
2.20.1





More information about the pve-devel mailing list