mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-18 00:37:01 +00:00
getdata & analyze: fix first_ip and last_ip arithmetics
There were too clever tricks done with first and last. Earlier the aim was to minimize '<=' and '>=' by fiddling with the numbers at the time when they were saved. While the program logic seemed to work there were some off by one mistakes, resulting to a count error. Even worse there is not even that many of such comparisons, so that one cannot really even justify added complexity. I really hope this patch is last this kind fix ever needed. Reported-by: Cheer Xiao <xiaqqaix@gmail.com> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
83e12457bc
commit
822ca33804
3 changed files with 29 additions and 27 deletions
|
|
@ -76,6 +76,8 @@ int do_counting(void)
|
|||
/* rewind */ ;
|
||||
if (l == NULL)
|
||||
l = leases;
|
||||
/* last_ip + 1 make comparison to small bit quicker as it results to
|
||||
* be 'smaller than' not 'smaller or equal to' */
|
||||
r_end = range_p->last_ip + 1;
|
||||
for (; l != NULL && l->ip < r_end; l = l->hh.next) {
|
||||
if (l->ip < range_p->first_ip) {
|
||||
|
|
@ -112,7 +114,7 @@ int do_counting(void)
|
|||
|
||||
/* Size of range, shared net & all networks */
|
||||
block_size =
|
||||
(unsigned int)(range_p->last_ip - range_p->first_ip - 1);
|
||||
(unsigned int)(range_p->last_ip - range_p->first_ip + 1);
|
||||
if (range_p->shared_net) {
|
||||
range_p->shared_net->available += block_size;
|
||||
}
|
||||
|
|
@ -129,7 +131,7 @@ int do_counting(void)
|
|||
range_p = ranges;
|
||||
for (k = 0; k < num_ranges; k++) {
|
||||
shared_networks->available +=
|
||||
range_p->last_ip - range_p->first_ip - 1;
|
||||
range_p->last_ip - range_p->first_ip + 1;
|
||||
shared_networks->used += range_p->count;
|
||||
shared_networks->touched += range_p->touched;
|
||||
shared_networks->backups += range_p->backups;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue