48 return ((uint32_t)a->s6_addr[12] << 24) | ((uint32_t)a->s6_addr[13] << 16)
49 | ((uint32_t)a->s6_addr[14] << 8) | a->s6_addr[15];
75 time_t earliest_release = 0;
76 int previous_usage = -1;
79 for (i = 0; i < pool->
size; ++i)
107 if (previous_usage < 0 && common_name && ipe->
common_name
115 if (previous_usage >= 0)
117 return previous_usage;
139 msg(msglevel,
"--ifconfig-pool start IP [%s] is greater than end IP [%s]",
146 "--ifconfig-pool address range is too large [%s -> %s]. Current maximum is %d addresses, as defined by IFCONFIG_POOL_MAX variable.",
154#if defined(__GNUC__) || defined(__clang__)
155#pragma GCC diagnostic push
156#pragma GCC diagnostic ignored "-Wsign-conversion"
161 const bool duplicate_cn,
const bool ipv6_pool,
const struct in6_addr ipv6_base,
162 const int ipv6_netbits)
166 int pool_ipv4_size = -1, pool_ipv6_size = -1;
182 pool_ipv4_size = (((end | 3) + 1) - pool->
ipv4.
base) >> 2;
187 pool_ipv4_size = end - start + 1;
194 if (pool_ipv4_size < 2)
196 msg(
M_FATAL,
"IPv4 pool size is too small (%d), must be at least 2", pool_ipv4_size);
202 pool->
size = pool_ipv4_size;
218 if ((128 - ipv6_netbits) < 32)
227 uint32_t mask = (1 << (128 - ipv6_netbits)) - 1;
245 "to avoid ::0 assignment");
253 if (pool_ipv6_size < 2)
255 msg(
M_FATAL,
"IPv6 pool size is too small (%d), must be at least 2", pool_ipv6_size);
264 if (pool->
size <= 0 || pool_ipv6_size < pool->
size)
266 pool->
size = pool_ipv6_size;
272 if (pool_ipv4_size < pool_ipv6_size)
275 "NOTE: IPv4 pool size is %d, IPv6 pool size is %d. "
276 "IPv4 pool size limits the number of clients that can be "
277 "served from the pool",
278 pool_ipv4_size, pool_ipv6_size);
280 else if (pool_ipv4_size > pool_ipv6_size)
283 "WARNING: IPv4 pool size is %d, IPv6 pool size is %d. "
284 "IPv6 pool size limits the number of clients that can be "
285 "served from the pool. This is likely a MISTAKE - please check "
286 "your configuration",
287 pool_ipv4_size, pool_ipv6_size);
306 for (i = 0; i < pool->
size; ++i)
317 struct in6_addr *remote_ipv6,
const char *common_name)
361 if (pool && hand >= 0 && hand < pool->size)
383 ret = (addr - pool->
ipv4.
base) >> 2;
397 if (ret < 0 || ret >= pool->
size)
417 for (
int i = 0; i < (12); i++)
419 if (pool->
ipv6.
base.s6_addr[i] != in_addr->s6_addr[i])
429 if (ret < 0 || ret >= pool->
size)
442 if (pool->
ipv4.
enabled && hand >= 0 && hand < pool->size)
448 ret = pool->
ipv4.
base + (hand << 2);
466static struct in6_addr
469 struct in6_addr ret = IN6ADDR_ANY_INIT;
472 if (pool->ipv6.enabled && hand >= 0 && hand < pool->size)
499 for (i = 0; i < pool->
size; ++i)
505 const char *ip6_str =
"";
506 const char *ip_str =
"";
549 if (refresh_freq > 0)
592 const int buf_size = 128;
596 if (persist && persist->
file && pool)
619 if (
c ==
'#' ||
c ==
';')
664 struct in6_addr addr6;
668 msg(
M_WARN,
"pool: invalid IPv6 (%s) for CN=%s", ip6_buf, cn_buf);
675 msg(
M_WARN,
"pool: IPv6 (%s) out of pool range for CN=%s", ip6_buf, cn_buf);
693 if ((h6 >= 0) && (h != h6))
695 msg(
M_WARN,
"pool: IPv4 (%s) and IPv6 (%s) have different offsets! Relying on IPv4",
704 msg(
M_INFO,
"succeeded -> ifconfig_pool_set(hand=%d)", h);
715#if defined(__GNUC__) || defined(__clang__)
716#pragma GCC diagnostic pop
734#ifdef IFCONFIG_POOL_TEST
750 for (i = 0; i < (int)
SIZE(array); ++i)
756 snprintf(buf,
sizeof(buf),
"common-name-%d", i);
773 for (i = (
int)
SIZE(array) / 16; i < (int)
SIZE(array) / 8; ++i)
786 for (i = 0; i < (int)
SIZE(array); ++i)
792 snprintf(buf,
sizeof(buf),
"common-name-%d", i + 24);
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
Allocate a buffer of the given size under garbage collection.
bool buf_parse(struct buffer *buf, const int delim, char *line, const int size)
Extract the next token from a buffer, delimited by a given character.
char * string_alloc(const char *str, struct gc_arena *gc)
Duplicate a string, allocating memory under garbage collection.
Buffer management functions and garbage collection.
#define BSTR(buf)
Return the buffer content pointer cast to char *.
#define ALLOC_ARRAY_CLEAR(dptr, type, n)
Allocate and zero-initialise an array of n elements of the given type.
#define ALLOC_ARRAY_CLEAR_GC(dptr, type, n, gc)
Allocate and zero-initialise a garbage-collected array of n elements.
#define BLEN(buf)
Return the length of the buffer content in bytes.
static void gc_free(struct gc_arena *a)
Free all allocations in a garbage collection arena.
#define ALLOC_OBJ_CLEAR(dptr, type)
Allocate and zero-initialise memory for a single object of the given type.
#define buf_init(buf, offset)
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
static void update_time(void)
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)
static void ifconfig_pool_list(const struct ifconfig_pool *pool, struct status_output *out)
static void ifconfig_pool_entry_free(struct ifconfig_pool_entry *ipe, bool hard)
static in_addr_t ifconfig_pool_handle_to_ip_base(const struct ifconfig_pool *pool, ifconfig_pool_handle hand)
static ifconfig_pool_handle ifconfig_pool_ip_base_to_handle(const struct ifconfig_pool *pool, const in_addr_t addr)
static uint32_t in6_addr_low32(const struct in6_addr *a)
static ifconfig_pool_handle ifconfig_pool_ipv6_base_to_handle(const struct ifconfig_pool *pool, const struct in6_addr *in_addr)
bool ifconfig_pool_release(struct ifconfig_pool *pool, ifconfig_pool_handle hand, const bool hard)
struct ifconfig_pool_persist * ifconfig_pool_persist_init(const char *filename, int refresh_freq)
void ifconfig_pool_write(struct ifconfig_pool_persist *persist, const struct ifconfig_pool *pool)
static void ifconfig_pool_set(struct ifconfig_pool *pool, const char *cn, ifconfig_pool_handle h, const bool fixed)
void ifconfig_pool_persist_close(struct ifconfig_pool_persist *persist)
bool ifconfig_pool_write_trigger(struct ifconfig_pool_persist *persist)
bool ifconfig_pool_verify_range(const msglvl_t msglevel, const in_addr_t start, const in_addr_t end)
static int ifconfig_pool_find(struct ifconfig_pool *pool, const char *common_name)
void ifconfig_pool_free(struct ifconfig_pool *pool)
static void ifconfig_pool_msg(const struct ifconfig_pool *pool, int msglevel)
void ifconfig_pool_read(struct ifconfig_pool_persist *persist, struct ifconfig_pool *pool)
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)
static struct in6_addr ifconfig_pool_handle_to_ipv6_base(const struct ifconfig_pool *pool, ifconfig_pool_handle hand)
#define IFCONFIG_POOL_MAX
bool get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits, msglvl_t msglevel)
Translate an IPv6 addr or hostname from string form to in6_addr.
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.
#define GETADDR_HOST_ORDER
struct in6_addr add_in6_addr(struct in6_addr base, uint32_t add)
const char * print_in6_addr(struct in6_addr a6, unsigned int flags, struct gc_arena *gc)
const char * print_in_addr_t(in_addr_t addr, unsigned int flags, struct gc_arena *gc)
void status_reset(const struct status_output *so)
bool status_trigger(struct status_output *so)
void status_printf(struct status_output *so, const char *format,...)
bool status_read(struct status_output *so, struct buffer *buf)
struct status_output * status_open(const char *filename, const int refresh_freq, const int msglevel, const struct virtual_output *vout, const unsigned int flags)
void status_flush(struct status_output *so)
bool status_close(struct status_output *so)
static unsigned int status_rw_flags(const struct status_output *so)
#define STATUS_OUTPUT_WRITE
#define STATUS_OUTPUT_READ
Wrapper structure for dynamically allocated memory.
int len
Length in bytes of the actual content within the allocated memory.
Garbage collection arena used to keep track of dynamically allocated memory.
struct status_output * file
struct ifconfig_pool_entry * list
struct ifconfig_pool::@22 ipv6
struct ifconfig_pool::@21 ipv4