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:
Sami Kerola 2017-11-12 13:35:04 +00:00
parent adda925c1e
commit 1875a13733
No known key found for this signature in database
GPG key ID: A9553245FDE9B739
12 changed files with 551 additions and 626 deletions

View file

@ -50,30 +50,30 @@
/*! \brief Add a lease to hash array.
* \param addr Binary IP to be added in leases hash.
* \param type Lease state of the IP. */
void add_lease_init(union ipaddr_t *addr
void add_lease_init(struct conf_t *state __attribute__ ((unused)), union ipaddr_t *addr
__attribute__ ((unused)), enum ltype type __attribute__ ((unused)))
{
}
void add_lease_v4(union ipaddr_t *addr, enum ltype type)
void add_lease_v4(struct conf_t *state, union ipaddr_t *addr, enum ltype type)
{
struct leases_t *l;
l = xmalloc(sizeof(struct leases_t));
copy_ipaddr(&l->ip, addr);
l->type = type;
HASH_ADD_INT(leases, ip.v4, l);
HASH_ADD_INT(state->leases, ip.v4, l);
l->ethernet = NULL;
}
void add_lease_v6(union ipaddr_t *addr, enum ltype type)
void add_lease_v6(struct conf_t *state, union ipaddr_t *addr, enum ltype type)
{
struct leases_t *l;
l = xmalloc(sizeof(struct leases_t));
copy_ipaddr(&l->ip, addr);
l->type = type;
HASH_ADD_V6(leases, ip.v6, l);
HASH_ADD_V6(state->leases, ip.v6, l);
l->ethernet = NULL;
}
@ -81,57 +81,57 @@ void add_lease_v6(union ipaddr_t *addr, enum ltype type)
* \param addr Binary IP searched from leases hash.
* \return A lease structure about requested IP, or NULL.
*/
struct leases_t *find_lease_init(union ipaddr_t *addr __attribute__ ((unused)))
struct leases_t *find_lease_init(struct conf_t *state __attribute__ ((unused)), union ipaddr_t *addr __attribute__ ((unused)))
{
return NULL;
}
struct leases_t *find_lease_v4(union ipaddr_t *addr)
struct leases_t *find_lease_v4(struct conf_t *state, union ipaddr_t *addr)
{
struct leases_t *l;
HASH_FIND_INT(leases, &addr->v4, l);
HASH_FIND_INT(state->leases, &addr->v4, l);
return l;
}
struct leases_t *find_lease_v6(union ipaddr_t *addr)
struct leases_t *find_lease_v6(struct conf_t *state, union ipaddr_t *addr)
{
struct leases_t *l;
HASH_FIND_V6(leases, &addr->v4, l);
HASH_FIND_V6(state->leases, &addr->v4, l);
return l;
}
/*! \brief Delete a lease from hash array.
* \param lease Pointer to lease hash. */
void delete_lease(struct leases_t *lease)
void delete_lease(struct conf_t *state, struct leases_t *lease)
{
free(lease->ethernet);
HASH_DEL(leases, lease);
HASH_DEL(state->leases, lease);
free(lease);
}
/*! \brief Delete all leases from hash array. */
#ifdef HASH_ITER
void delete_all_leases(void)
void delete_all_leases(struct conf_t *state)
{
struct leases_t *l, *tmp;
HASH_ITER(hh, leases, l, tmp) {
HASH_ITER(hh, state->leases, l, tmp) {
free(l->ethernet);
HASH_DEL(leases, l);
HASH_DEL(state->leases, l);
free(l);
}
}
#else
void delete_all_leases(void)
void delete_all_leases(struct conf_t *state)
{
while (leases) {
struct leases_t *l;
l = leases;
l = state->leases;
free(l->ethernet);
HASH_DEL(leases, l); /* leases advances to next on delete */
HASH_DEL(state->leases, l); /* leases advances to next on delete */
free(l);
}
}