From 316a59e156dde4e6bb76d064e08864fbec39dfdc Mon Sep 17 00:00:00 2001 From: Tomaz Solc Date: Sat, 1 Oct 2016 09:25:51 +0200 Subject: [PATCH] dhcp-pool: Fix off-by-one error in pool size. "range" statement gives the lowest and highest IP addresses (both inclusive) in a pool. dhcp-pool did not count the highest address when calculating pool size. --- plugins/network/dhcp-pool | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/network/dhcp-pool b/plugins/network/dhcp-pool index 23ab9fc0..14874d99 100755 --- a/plugins/network/dhcp-pool +++ b/plugins/network/dhcp-pool @@ -73,7 +73,7 @@ else { # For each pool, count how many leases from that pool are currently active foreach $start (keys %pools) { $size = $pools{$start}; - $end = $start+$size; + $end = $start+$size-1; $free = $size; foreach $lease (@activeleases) { @@ -103,9 +103,12 @@ sub determine_pools { if ($line =~ /range[\s]+([\d]+\.[\d]+\.[\d]+\.[\d]+)[\s]+([\d]+\.[\d]+\.[\d]+\.[\d]+)/) { $start = string2ip($1); $end = string2ip($2); - $size = $end - $start; + defined($start) || next; defined($end) || next; + + # The range statement gives the lowest and highest IP addresses in a range. + $size = $end - $start + 1; $pools{$start} = $size; }