Go to the documentation of this file.
61 time_t earliest_release = 0;
62 int previous_usage = -1;
65 for (i = 0; i < pool->
size; ++i)
93 if (previous_usage < 0
104 if (previous_usage >= 0)
106 return previous_usage;
128 msg(msglevel,
"--ifconfig-pool start IP [%s] is greater than end IP [%s]",
135 msg(msglevel,
"--ifconfig-pool address range is too large [%s -> %s]. Current maximum is %d addresses, as defined by IFCONFIG_POOL_MAX variable.",
148 const bool ipv6_pool,
const struct in6_addr ipv6_base,
149 const int ipv6_netbits )
153 int pool_ipv4_size = -1, pool_ipv6_size = -1;
169 pool_ipv4_size = (((end | 3) + 1) - pool->
ipv4.
base) >> 2;
174 pool_ipv4_size = end - start + 1;
181 if (pool_ipv4_size < 2)
183 msg(
M_FATAL,
"IPv4 pool size is too small (%d), must be at least 2",
190 pool->
size = pool_ipv4_size;
202 uint32_t
base = (ipv6_base.s6_addr[12] << 24)
203 | (ipv6_base.s6_addr[13] << 16)
204 | (ipv6_base.s6_addr[14] << 8)
205 | ipv6_base.s6_addr[15];
209 if ((128 - ipv6_netbits) < 32)
218 uint32_t mask = (1 << (128 - ipv6_netbits) ) - 1;
236 "to avoid ::0 assignment");
241 pool_ipv6_size = ipv6_netbits >= 112
242 ? (1 << (128 - ipv6_netbits)) -
base
245 if (pool_ipv6_size < 2)
247 msg(
M_FATAL,
"IPv6 pool size is too small (%d), must be at least 2",
258 if (pool->
size <= 0 || pool_ipv6_size < pool->
size)
260 pool->
size = pool_ipv6_size;
266 if (pool_ipv4_size < pool_ipv6_size)
268 msg(
M_INFO,
"NOTE: IPv4 pool size is %d, IPv6 pool size is %d. "
269 "IPv4 pool size limits the number of clients that can be "
270 "served from the pool", pool_ipv4_size, pool_ipv6_size);
272 else if (pool_ipv4_size > pool_ipv6_size)
274 msg(
M_WARN,
"WARNING: IPv4 pool size is %d, IPv6 pool size is %d. "
275 "IPv6 pool size limits the number of clients that can be "
276 "served from the pool. This is likely a MISTAKE - please check "
277 "your configuration", pool_ipv4_size, pool_ipv6_size);
296 for (i = 0; i < pool->
size; ++i)
328 in_addr_t b = pool->
ipv4.
base + (i << 2);
361 if (pool && hand >= 0 && hand < pool->size)
383 ret = (addr - pool->
ipv4.
base) >> 2;
397 if (ret < 0 || ret >= pool->
size)
407 const struct in6_addr *in_addr)
418 for (
int i = 0; i < (12); i++)
420 if (pool->
ipv6.
base.s6_addr[i] != in_addr->s6_addr[i])
426 base = (pool->
ipv6.
base.s6_addr[12] << 24)
427 | (pool->
ipv6.
base.s6_addr[13] << 16)
428 | (pool->
ipv6.
base.s6_addr[14] << 8)
431 addr = (in_addr->s6_addr[12] << 24)
432 | (in_addr->s6_addr[13] << 16)
433 | (in_addr->s6_addr[14] << 8)
434 | in_addr->s6_addr[15];
437 if (ret < 0 || ret >= pool->
size)
450 if (pool->
ipv4.
enabled && hand >= 0 && hand < pool->size)
456 ret = pool->
ipv4.
base + (hand << 2);
474 static struct in6_addr
477 struct in6_addr ret = IN6ADDR_ANY_INIT;
480 if (pool->ipv6.enabled && hand >= 0 && hand < pool->size)
507 for (i = 0; i < pool->
size; ++i)
512 const char *ip6_str =
"";
513 const char *ip_str =
"";
558 if (refresh_freq > 0)
600 const int buf_size = 128;
604 if (persist && persist->
file && pool)
608 char *cn_buf, *ip_buf, *ip6_buf;
627 if (c ==
'#' || c ==
';')
644 if (!
buf_parse(&in,
',', cn_buf, buf_size)
645 || !
buf_parse(&in,
',', ip_buf, buf_size))
652 if (strlen(ip_buf) > 0)
660 msg(
M_WARN,
"pool: invalid IPv4 (%s) for CN=%s", ip_buf,
669 "pool: IPv4 (%s) out of pool range for CN=%s",
675 if (
buf_parse(&in,
',', ip6_buf, buf_size) && strlen(ip6_buf) > 0)
677 struct in6_addr addr6;
681 msg(
M_WARN,
"pool: invalid IPv6 (%s) for CN=%s", ip6_buf,
690 "pool: IPv6 (%s) out of pool range for CN=%s",
709 if ((h6 >= 0) && (h != h6))
712 "pool: IPv4 (%s) and IPv6 (%s) have different offsets! Relying on IPv4",
721 msg(
M_INFO,
"succeeded -> ifconfig_pool_set(hand=%d)", h);
747 #ifdef IFCONFIG_POOL_TEST
752 ifconfig_pool_test(in_addr_t start, in_addr_t end)
763 for (i = 0; i < (int)
SIZE(array); ++i)
767 in_addr_t local, remote;
769 snprintf(buf,
sizeof(buf),
"common-name-%d", i);
789 for (i = (
int)
SIZE(array) / 16; i < (int)
SIZE(array) / 8; ++i)
802 for (i = 0; i < (int)
SIZE(array); ++i)
806 in_addr_t local, remote;
808 snprintf(buf,
sizeof(buf),
"common-name-%d", i+24);
struct status_output * status_open(const char *filename, const int refresh_freq, const int msglevel, const struct virtual_output *vout, const unsigned int flags)
bool status_trigger(struct status_output *so)
#define IFCONFIG_POOL_MAX
#define ALLOC_ARRAY_CLEAR(dptr, type, n)
static struct gc_arena gc_new(void)
static unsigned int status_rw_flags(const struct status_output *so)
struct status_output * file
#define buf_init(buf, offset)
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
static int ifconfig_pool_find(struct ifconfig_pool *pool, const char *common_name)
bool status_read(struct status_output *so, struct buffer *buf)
#define STATUS_OUTPUT_WRITE
struct ifconfig_pool_persist * ifconfig_pool_persist_init(const char *filename, int refresh_freq)
in_addr_t getaddr(unsigned int flags, const char *hostname, int resolve_retry_seconds, bool *succeeded, struct signal_info *sig_info)
Translate an IPv4 addr or hostname from string form to in_addr_t.
char * string_alloc(const char *str, struct gc_arena *gc)
const char * print_in6_addr(struct in6_addr a6, unsigned int flags, struct gc_arena *gc)
void status_reset(struct status_output *so)
static void update_time(void)
#define ALLOC_ARRAY_CLEAR_GC(dptr, type, n, gc)
struct ifconfig_pool_entry * list
void status_printf(struct status_output *so, const char *format,...)
struct ifconfig_pool::@10 ipv4
static in_addr_t ifconfig_pool_handle_to_ip_base(const struct ifconfig_pool *pool, ifconfig_pool_handle hand)
void ifconfig_pool_write(struct ifconfig_pool_persist *persist, const struct ifconfig_pool *pool)
Wrapper structure for dynamically allocated memory.
static ifconfig_pool_handle ifconfig_pool_ipv6_base_to_handle(const struct ifconfig_pool *pool, const struct in6_addr *in_addr)
const char * print_in_addr_t(in_addr_t addr, unsigned int flags, struct gc_arena *gc)
static void ifconfig_pool_msg(const struct ifconfig_pool *pool, int msglevel)
bool status_close(struct status_output *so)
Garbage collection arena used to keep track of dynamically allocated memory.
bool ifconfig_pool_write_trigger(struct ifconfig_pool_persist *persist)
static ifconfig_pool_handle ifconfig_pool_ip_base_to_handle(const struct ifconfig_pool *pool, const in_addr_t addr)
ifconfig_pool_handle ifconfig_pool_acquire(struct ifconfig_pool *pool, in_addr_t *local, in_addr_t *remote, struct in6_addr *remote_ipv6, const char *common_name)
void ifconfig_pool_persist_close(struct ifconfig_pool_persist *persist)
void status_flush(struct status_output *so)
void ifconfig_pool_free(struct ifconfig_pool *pool)
bool get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits, int msglevel)
Translate an IPv6 addr or hostname from string form to in6_addr.
#define GETADDR_HOST_ORDER
static void ifconfig_pool_set(struct ifconfig_pool *pool, const char *cn, ifconfig_pool_handle h, const bool fixed)
static void gc_free(struct gc_arena *a)
static struct in6_addr ifconfig_pool_handle_to_ipv6_base(const struct ifconfig_pool *pool, ifconfig_pool_handle hand)
#define ALLOC_OBJ_CLEAR(dptr, type)
static void ifconfig_pool_entry_free(struct ifconfig_pool_entry *ipe, bool hard)
static void ifconfig_pool_list(const struct ifconfig_pool *pool, struct status_output *out)
bool ifconfig_pool_verify_range(const int msglevel, const in_addr_t start, const in_addr_t end)
struct in6_addr add_in6_addr(struct in6_addr base, uint32_t add)
bool ifconfig_pool_release(struct ifconfig_pool *pool, ifconfig_pool_handle hand, const bool hard)
struct ifconfig_pool * ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start, in_addr_t end, const bool duplicate_cn, const bool ipv6_pool, const struct in6_addr ipv6_base, const int ipv6_netbits)
void ifconfig_pool_read(struct ifconfig_pool_persist *persist, struct ifconfig_pool *pool)
#define STATUS_OUTPUT_READ
struct ifconfig_pool::@11 ipv6
bool buf_parse(struct buffer *buf, const int delim, char *line, const int size)