aboutsummaryrefslogtreecommitdiffstats
path: root/lease.c
diff options
context:
space:
mode:
Diffstat (limited to 'lease.c')
-rw-r--r--lease.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/lease.c b/lease.c
index a54298d..9613475 100644
--- a/lease.c
+++ b/lease.c
@@ -25,7 +25,7 @@
#define TIME_T_MAX (((time_t)1 << (sizeof(time_t) * CHAR_BIT - 2)) - 1) * 2 + 1
-static struct ip_pool pool;
+static struct ipns ipns;
static time_t gexpires = TIME_T_MAX;
static bool synchronized;
@@ -60,7 +60,7 @@ void leases_init(char *fname, struct mnl_socket *nlsock)
synchronized = false;
leases_ht = kh_init(leaseht);
- ipp_init(&pool);
+ ipp_init(&ipns);
nlh = mnl_nlmsg_put_header(buf);
nlh->nlmsg_type = RTM_GETROUTE;
@@ -87,7 +87,7 @@ void leases_free()
}
kh_destroy(leaseht, leases_ht);
- ipp_free(&pool);
+ ipp_free(&ipns);
}
struct wg_dynamic_lease *new_lease(wg_key pubkey, uint32_t leasetime,
@@ -106,21 +106,21 @@ struct wg_dynamic_lease *new_lease(wg_key pubkey, uint32_t leasetime,
if (!lease)
fatal("malloc()");
- if (wants_ipv4 && !pool.total_ipv4)
+ if (wants_ipv4 && !ipns.total_ipv4)
return NULL; /* no ipv4 addresses available */
- if (wants_ipv6 && !pool.totalh_ipv6 && !pool.totall_ipv6)
+ if (wants_ipv6 && !ipns.totalh_ipv6 && !ipns.totall_ipv6)
return NULL; /* no ipv6 addresses available */
if (wants_ipv4) {
if (!ipv4) {
- index = random_bounded(pool.total_ipv4);
+ index = random_bounded(ipns.total_ipv4);
debug("new_lease(v4): %u of %u\n", index,
- pool.total_ipv4);
+ ipns.total_ipv4);
- ipp_addnth_v4(&pool, &lease->ipv4, index);
+ ipp_addnth_v4(&ipns, &lease->ipv4, index);
} else {
- if (ipp_add_v4(&pool, ipv4, 32))
+ if (ipp_add_v4(&ipns, ipv4, 32))
return NULL;
memcpy(&lease->ipv4, ipv4, sizeof *ipv4);
@@ -129,21 +129,21 @@ struct wg_dynamic_lease *new_lease(wg_key pubkey, uint32_t leasetime,
if (wants_ipv6) {
if (!ipv6) {
- if (pool.totalh_ipv6 > 0) {
+ if (ipns.totalh_ipv6 > 0) {
index_l = random_u64();
- index_h = random_bounded(pool.totalh_ipv6);
+ index_h = random_bounded(ipns.totalh_ipv6);
} else {
- index_l = random_bounded(pool.totall_ipv6);
+ index_l = random_bounded(ipns.totall_ipv6);
index_h = 0;
}
debug("new_lease(v6): %u:%ju of %u:%ju\n", index_h,
- index_l, pool.totalh_ipv6, pool.totall_ipv6);
- ipp_addnth_v6(&pool, &lease->ipv6, index_l, index_h);
+ index_l, ipns.totalh_ipv6, ipns.totall_ipv6);
+ ipp_addnth_v6(&ipns, &lease->ipv6, index_l, index_h);
} else {
- if (ipp_add_v6(&pool, ipv6, 128)) {
+ if (ipp_add_v6(&ipns, ipv6, 128)) {
if (!ipv4 || ipv4->s_addr)
- ipp_del_v4(&pool, ipv4, 32);
+ ipp_del_v4(&ipns, ipv4, 32);
return NULL;
}
@@ -223,10 +223,10 @@ int leases_refresh()
time_t expires = (*pp)->start_mono + (*pp)->leasetime;
if (cur_time >= expires) {
if (ipv4->s_addr)
- ipp_del_v4(&pool, ipv4, 32);
+ ipp_del_v4(&ipns, ipv4, 32);
if (!IN6_IS_ADDR_UNSPECIFIED(ipv6))
- ipp_del_v6(&pool, ipv6, 128);
+ ipp_del_v6(&ipns, ipv6, 128);
tmp = *pp;
*pp = (*pp)->next;
@@ -315,18 +315,18 @@ static int process_nlpacket_cb(const struct nlmsghdr *nlh, void *data)
if (nlh->nlmsg_type == RTM_NEWROUTE) {
if (rm->rtm_family == AF_INET) {
- if (ipp_addpool_v4(&pool, addr, rm->rtm_dst_len))
+ if (ipp_addpool_v4(&ipns, addr, rm->rtm_dst_len))
die("ipp_addpool_v4()\n");
} else if (rm->rtm_family == AF_INET6) {
- if (ipp_addpool_v6(&pool, addr, rm->rtm_dst_len))
+ if (ipp_addpool_v6(&ipns, addr, rm->rtm_dst_len))
die("ipp_addpool_v6()\n");
}
} else if (nlh->nlmsg_type == RTM_DELROUTE) {
if (rm->rtm_family == AF_INET) {
- if (ipp_removepool_v4(&pool, addr) && synchronized)
+ if (ipp_removepool_v4(&ipns, addr) && synchronized)
die("ipp_removepool_v4()\n");
} else if (rm->rtm_family == AF_INET6) {
- if (ipp_removepool_v6(&pool, addr) && synchronized)
+ if (ipp_removepool_v6(&ipns, addr) && synchronized)
die("ipp_removepool_v6()\n");
}
}