Version 2.6

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2008-05-10 00:00:00 +02:00
parent 8904b5b82c
commit 4f000e7ab6
14 changed files with 374 additions and 268 deletions

View file

@ -46,6 +46,21 @@ prepare_data (void)
}
num_leases = k;
/* Delete touched IPs that are in use */
j = 0;
for (i = 0; i < num_touches; i++)
{
if (bsearch
(&touches[i], leases, num_leases, sizeof (long int),
&intcomp) == NULL)
{
touches[j] = touches[i];
j++;
}
}
num_touches = j;
qsort (touches, (size_t) num_touches, sizeof (long int), &intcomp);
/* Sort ranges */
qsort (ranges, (size_t) num_ranges, sizeof (struct range_t), &rangecomp);
@ -57,41 +72,73 @@ int
do_counting (void)
{
struct range_t *range_p;
unsigned int i, block_size;
unsigned int i, j, k, block_size;
i = j = 0;
range_p = ranges;
for (i = 0; i < num_leases; i++)
for (k = 0; k < num_ranges; k++)
{
/* IP with in range */
if (range_p->first_ip < leases[i] && range_p->last_ip > leases[i])
/* Count IPs in use */
for (; range_p->last_ip > leases[i] && i < num_leases; i++)
{
if (range_p->first_ip > leases[i])
{
continue;
}
/* IP with in range */
range_p->count++;
if (range_p->shared_net)
{
range_p->shared_net->used++;
}
shared_networks->used++;
}
/* IP out of range */
if (range_p->last_ip < leases[i])
{
range_p++;
/* Break loop before trying to access memorory that is
* not allocated. */
if (range_p - ranges > num_ranges)
{
break;
}
block_size = range_p->last_ip - range_p->first_ip - 1;
if (range_p->shared_net)
{
range_p->shared_net->available += block_size;
}
shared_networks->available += block_size;
i--;
}
/* Count touched IPs */
for (; range_p->last_ip > touches[j] && j < num_touches; j++)
{
if (range_p->first_ip > touches[j])
{
continue;
}
/* IP with in range */
range_p->touched++;
if (range_p->shared_net)
{
range_p->shared_net->touched++;
}
}
/* Size of range, shared net & all networks */
block_size = range_p->last_ip - range_p->first_ip - 1;
if (range_p->shared_net)
{
range_p->shared_net->available += block_size;
}
/* Reverse so that not even a one IP will be missed. */
i--;
j--;
range_p++;
}
/* During count of other shared networks default network and
* all networks got mixed to gether semantically. This fixes
* the problem, but is not elegant. TODO: fix semantics of all
* and default share_network. */
shared_networks->available = 0;
shared_networks->used = 0;
shared_networks->touched = 0;
range_p = ranges;
for (k = 0; k < num_ranges; k++)
{
shared_networks->available += range_p->last_ip - range_p->first_ip - 1;
shared_networks->used += range_p->count;
shared_networks->touched += range_p->touched;
range_p++;
}
return 0;
}