mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-18 00:37:01 +00:00
all files: replace global variables with runtime config state structure
Earlier variables magically appeared to scope of functions that took void as argument. One could figure out perhaps they were globals, but programs that do that are unnessarily hard to follow. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
adda925c1e
commit
1875a13733
12 changed files with 551 additions and 626 deletions
|
|
@ -47,28 +47,27 @@
|
|||
|
||||
/*! \brief Prepare data for analysis. The function will sort leases and
|
||||
* ranges. */
|
||||
void prepare_data(void)
|
||||
void prepare_data(struct conf_t *state)
|
||||
{
|
||||
/* Sort leases */
|
||||
HASH_SORT(leases, leasecomp);
|
||||
HASH_SORT(state->leases, leasecomp);
|
||||
/* Sort ranges */
|
||||
qsort(ranges, (size_t)num_ranges, sizeof(struct range_t), &rangecomp);
|
||||
qsort(state->ranges, state->num_ranges, sizeof(struct range_t), &rangecomp);
|
||||
}
|
||||
|
||||
/*! \brief Perform counting. Join leases with ranges, and update counters. */
|
||||
void do_counting(void)
|
||||
void do_counting(struct conf_t *state)
|
||||
{
|
||||
struct range_t *restrict range_p;
|
||||
const struct leases_t *restrict l = leases;
|
||||
struct range_t *restrict range_p = state->ranges;
|
||||
const struct leases_t *restrict l = state->leases;
|
||||
unsigned long i, k, block_size;
|
||||
|
||||
/* Walk through ranges */
|
||||
range_p = ranges;
|
||||
for (i = 0; i < num_ranges; i++) {
|
||||
for (i = 0; i < state->num_ranges; i++) {
|
||||
while (l != NULL && ipcomp(&range_p->first_ip, &l->ip) < 0)
|
||||
l = l->hh.prev; /* rewind */
|
||||
if (l == NULL)
|
||||
l = leases;
|
||||
l = state->leases;
|
||||
for (; l != NULL && ipcomp(&l->ip, &range_p->last_ip) <= 0; l = l->hh.next) {
|
||||
if (ipcomp(&l->ip, &range_p->first_ip) < 0)
|
||||
continue; /* cannot happen? */
|
||||
|
|
@ -107,15 +106,15 @@ void do_counting(void)
|
|||
/* FIXME: During count of other shared networks default network
|
||||
* and all networks got mixed together semantically. The below
|
||||
* fixes the problem, but is not elegant. */
|
||||
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 += get_range_size(range_p);
|
||||
shared_networks->used += range_p->count;
|
||||
shared_networks->touched += range_p->touched;
|
||||
shared_networks->backups += range_p->backups;
|
||||
state->shared_networks->available = 0;
|
||||
state->shared_networks->used = 0;
|
||||
state->shared_networks->touched = 0;
|
||||
range_p = state->ranges;
|
||||
for (k = 0; k < state->num_ranges; k++) {
|
||||
state->shared_networks->available += get_range_size(range_p);
|
||||
state->shared_networks->used += range_p->count;
|
||||
state->shared_networks->touched += range_p->touched;
|
||||
state->shared_networks->backups += range_p->backups;
|
||||
range_p++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue