OpenVPN
pool.c
Go to the documentation of this file.
1/*
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single TCP/UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
6 * packet compression.
7 *
8 * Copyright (C) 2002-2026 OpenVPN Inc <sales@openvpn.net>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include "syshead.h"
28
29#include "pool.h"
30#include "buffer.h"
31#include "error.h"
32#include "socket_util.h"
33#include "otime.h"
34#include "resolve.h"
35
36#include "memdbg.h"
37
40
41static struct in6_addr ifconfig_pool_handle_to_ipv6_base(const struct ifconfig_pool *pool,
43
44/* Return the last 32 bits of an IPv6 address in host byte order */
45static inline uint32_t
46in6_addr_low32(const struct in6_addr *a)
47{
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];
50}
51
52static void
54{
55 ipe->in_use = false;
56 if (hard && ipe->common_name)
57 {
58 free(ipe->common_name);
59 ipe->common_name = NULL;
60 }
61 if (hard)
62 {
63 ipe->last_release = 0;
64 }
65 else
66 {
67 ipe->last_release = now;
68 }
69}
70
71static int
72ifconfig_pool_find(struct ifconfig_pool *pool, const char *common_name)
73{
74 int i;
75 time_t earliest_release = 0;
76 int previous_usage = -1;
77 int new_usage = -1;
78
79 for (i = 0; i < pool->size; ++i)
80 {
81 const struct ifconfig_pool_entry *ipe = &pool->list[i];
82 if (!ipe->in_use)
83 {
84 /*
85 * If duplicate_cn mode, take first available IP address
86 */
87 if (pool->duplicate_cn)
88 {
89 new_usage = i;
90 break;
91 }
92
93 /*
94 * Keep track of the unused IP address entry which
95 * was released earliest.
96 */
97 if ((new_usage == -1 || ipe->last_release < earliest_release) && !ipe->fixed)
98 {
99 earliest_release = ipe->last_release;
100 new_usage = i;
101 }
102
103 /*
104 * Keep track of a possible allocation to us
105 * from an earlier session.
106 */
107 if (previous_usage < 0 && common_name && ipe->common_name
108 && !strcmp(common_name, ipe->common_name))
109 {
110 previous_usage = i;
111 }
112 }
113 }
114
115 if (previous_usage >= 0)
116 {
117 return previous_usage;
118 }
119
120 if (new_usage >= 0)
121 {
122 return new_usage;
123 }
124
125 return -1;
126}
127
128/*
129 * Verify start/end range
130 */
131bool
132ifconfig_pool_verify_range(const msglvl_t msglevel, const in_addr_t start, const in_addr_t end)
133{
134 struct gc_arena gc = gc_new();
135 bool ret = true;
136
137 if (start > end)
138 {
139 msg(msglevel, "--ifconfig-pool start IP [%s] is greater than end IP [%s]",
140 print_in_addr_t(start, 0, &gc), print_in_addr_t(end, 0, &gc));
141 ret = false;
142 }
143 if (end - start >= IFCONFIG_POOL_MAX)
144 {
145 msg(msglevel,
146 "--ifconfig-pool address range is too large [%s -> %s]. Current maximum is %d addresses, as defined by IFCONFIG_POOL_MAX variable.",
147 print_in_addr_t(start, 0, &gc), print_in_addr_t(end, 0, &gc), IFCONFIG_POOL_MAX);
148 ret = false;
149 }
150 gc_free(&gc);
151 return ret;
152}
153
154#if defined(__GNUC__) || defined(__clang__)
155#pragma GCC diagnostic push
156#pragma GCC diagnostic ignored "-Wsign-conversion"
157#endif
158
159struct ifconfig_pool *
160ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start, in_addr_t end,
161 const bool duplicate_cn, const bool ipv6_pool, const struct in6_addr ipv6_base,
162 const int ipv6_netbits)
163{
164 struct gc_arena gc = gc_new();
165 struct ifconfig_pool *pool = NULL;
166 int pool_ipv4_size = -1, pool_ipv6_size = -1;
167
168 ASSERT(start <= end && end - start < IFCONFIG_POOL_MAX);
169 ALLOC_OBJ_CLEAR(pool, struct ifconfig_pool);
170
172
173 pool->ipv4.enabled = ipv4_pool;
174
175 if (pool->ipv4.enabled)
176 {
177 pool->ipv4.type = type;
178 switch (pool->ipv4.type)
179 {
181 pool->ipv4.base = start & ~3u;
182 pool_ipv4_size = (((end | 3) + 1) - pool->ipv4.base) >> 2;
183 break;
184
186 pool->ipv4.base = start;
187 pool_ipv4_size = end - start + 1;
188 break;
189
190 default:
191 ASSERT(0);
192 }
193
194 if (pool_ipv4_size < 2)
195 {
196 msg(M_FATAL, "IPv4 pool size is too small (%d), must be at least 2", pool_ipv4_size);
197 }
198
199 msg(D_IFCONFIG_POOL, "IFCONFIG POOL IPv4: base=%s size=%d",
200 print_in_addr_t(pool->ipv4.base, 0, &gc), pool_ipv4_size);
201
202 pool->size = pool_ipv4_size;
203 }
204
205 /* IPv6 pools are always "INDIV" type */
206 pool->ipv6.enabled = ipv6_pool;
207
208 if (pool->ipv6.enabled)
209 {
210 /* the host portion of the address will always be contained in the last
211 * 4 bytes, therefore we can just extract that and use it as base in
212 * integer form
213 */
214 uint32_t base = in6_addr_low32(&ipv6_base);
215 /* some bits of the last 4 bytes may still be part of the network
216 * portion of the address, therefore we need to set them to 0
217 */
218 if ((128 - ipv6_netbits) < 32)
219 {
220 /* extract only the bits that are really part of the host portion of
221 * the address.
222 *
223 * Example: if we have netbits=31, the first bit has to be zero'd,
224 * the following operation first computes mask=0x3fffff and then
225 * uses mask to extract the wanted bits from base
226 */
227 uint32_t mask = (1 << (128 - ipv6_netbits)) - 1;
228 base &= mask;
229 }
230
231 pool->ipv6.base = ipv6_base;
232
233 /* if a pool starts at a base address that has all-zero in the
234 * host part, that first IPv6 address must not be assigned to
235 * clients because it is not usable (subnet anycast address).
236 * Start with 1, then.
237 *
238 * NOTE: this will also (mis-)fire for something like
239 * ifconfig-ipv6-pool 2001:db8:0:1:1234::0/64
240 * as we only check the rightmost 32 bits of the host part. So be it.
241 */
242 if (base == 0)
243 {
244 msg(D_IFCONFIG_POOL, "IFCONFIG POOL IPv6: incrementing pool start "
245 "to avoid ::0 assignment");
246 base++;
247 pool->ipv6.base.s6_addr[15]++;
248 }
249
250 pool_ipv6_size =
251 ipv6_netbits >= 112 ? (1 << (128 - ipv6_netbits)) - base : IFCONFIG_POOL_MAX;
252
253 if (pool_ipv6_size < 2)
254 {
255 msg(M_FATAL, "IPv6 pool size is too small (%d), must be at least 2", pool_ipv6_size);
256 }
257
258 msg(D_IFCONFIG_POOL, "IFCONFIG POOL IPv6: base=%s size=%d netbits=%d",
259 print_in6_addr(pool->ipv6.base, 0, &gc), pool_ipv6_size, ipv6_netbits);
260
261 /* if there is no v4 pool, or the v6 pool is smaller, use
262 * v6 pool size as "unified pool size"
263 */
264 if (pool->size <= 0 || pool_ipv6_size < pool->size)
265 {
266 pool->size = pool_ipv6_size;
267 }
268 }
269
270 if (pool->ipv4.enabled && pool->ipv6.enabled)
271 {
272 if (pool_ipv4_size < pool_ipv6_size)
273 {
274 msg(M_INFO,
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);
279 }
280 else if (pool_ipv4_size > pool_ipv6_size)
281 {
282 msg(M_WARN,
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);
288 }
289 }
290
291 ASSERT(pool->size > 0);
292
293 ALLOC_ARRAY_CLEAR(pool->list, struct ifconfig_pool_entry, pool->size);
294
295 gc_free(&gc);
296 return pool;
297}
298
299void
301{
302 if (pool)
303 {
304 int i;
305
306 for (i = 0; i < pool->size; ++i)
307 {
308 ifconfig_pool_entry_free(&pool->list[i], true);
309 }
310 free(pool->list);
311 free(pool);
312 }
313}
314
317 struct in6_addr *remote_ipv6, const char *common_name)
318{
319 int i;
320
321 i = ifconfig_pool_find(pool, common_name);
322 if (i >= 0)
323 {
324 struct ifconfig_pool_entry *ipe = &pool->list[i];
325 ASSERT(!ipe->in_use);
326 ifconfig_pool_entry_free(ipe, true);
327 ipe->in_use = true;
328 if (common_name)
329 {
331 }
332
333 if (pool->ipv4.enabled && local && remote)
334 {
336 if (pool->ipv4.type == IFCONFIG_POOL_30NET)
337 {
338 *local = b + 1;
339 *remote = b + 2;
340 }
341 else
342 {
343 *local = 0;
344 *remote = b;
345 }
346 }
347
348 if (pool->ipv6.enabled && remote_ipv6)
349 {
350 *remote_ipv6 = ifconfig_pool_handle_to_ipv6_base(pool, i);
351 }
352 }
353 return i;
354}
355
356bool
357ifconfig_pool_release(struct ifconfig_pool *pool, ifconfig_pool_handle hand, const bool hard)
358{
359 bool ret = false;
360
361 if (pool && hand >= 0 && hand < pool->size)
362 {
363 ifconfig_pool_entry_free(&pool->list[hand], hard);
364 ret = true;
365 }
366 return ret;
367}
368
369/*
370 * private access functions
371 */
372
373/* currently handling IPv4 logic only */
376{
377 ifconfig_pool_handle ret = -1;
378
379 switch (pool->ipv4.type)
380 {
382 {
383 ret = (addr - pool->ipv4.base) >> 2;
384 break;
385 }
386
388 {
389 ret = (addr - pool->ipv4.base);
390 break;
391 }
392
393 default:
394 ASSERT(0);
395 }
396
397 if (ret < 0 || ret >= pool->size)
398 {
399 ret = -1;
400 }
401
402 return ret;
403}
404
406ifconfig_pool_ipv6_base_to_handle(const struct ifconfig_pool *pool, const struct in6_addr *in_addr)
407{
409 uint32_t base, addr;
410
411 /* IPv6 pool is always IFCONFIG_POOL_INDIV.
412 *
413 * We assume the offset can't be larger than 2^32-1, therefore we compute
414 * the difference only among the last 4 bytes like if they were two 32bit
415 * long integers. The rest of the address must match.
416 */
417 for (int i = 0; i < (12); i++)
418 {
419 if (pool->ipv6.base.s6_addr[i] != in_addr->s6_addr[i])
420 {
421 return -1;
422 }
423 }
424
425 base = in6_addr_low32(&pool->ipv6.base);
426 addr = in6_addr_low32(in_addr);
427
428 ret = addr - base;
429 if (ret < 0 || ret >= pool->size)
430 {
431 ret = -1;
432 }
433
434 return ret;
435}
436
437static in_addr_t
439{
440 in_addr_t ret = 0;
441
442 if (pool->ipv4.enabled && hand >= 0 && hand < pool->size)
443 {
444 switch (pool->ipv4.type)
445 {
447 {
448 ret = pool->ipv4.base + (hand << 2);
449 break;
450 }
451
453 {
454 ret = pool->ipv4.base + hand;
455 break;
456 }
457
458 default:
459 ASSERT(0);
460 }
461 }
462
463 return ret;
464}
465
466static struct in6_addr
468{
469 struct in6_addr ret = IN6ADDR_ANY_INIT;
470
471 /* IPv6 pools are always INDIV (--linear) */
472 if (pool->ipv6.enabled && hand >= 0 && hand < pool->size)
473 {
474 ret = add_in6_addr(pool->ipv6.base, hand);
475 }
476 return ret;
477}
478
479static void
481 const bool fixed)
482{
483 struct ifconfig_pool_entry *e = &pool->list[h];
485 e->in_use = false;
486 e->common_name = string_alloc(cn, NULL);
487 e->last_release = now;
488 e->fixed = fixed;
489}
490
491static void
492ifconfig_pool_list(const struct ifconfig_pool *pool, struct status_output *out)
493{
494 if (pool && out)
495 {
496 struct gc_arena gc = gc_new();
497 int i;
498
499 for (i = 0; i < pool->size; ++i)
500 {
501 const struct ifconfig_pool_entry *e = &pool->list[i];
502
503 if (e->common_name)
504 {
505 const char *ip6_str = "";
506 const char *ip_str = "";
507
508 if (pool->ipv4.enabled)
509 {
510 const in_addr_t ip = ifconfig_pool_handle_to_ip_base(pool, i);
511 ip_str = print_in_addr_t(ip, 0, &gc);
512 }
513
514 if (pool->ipv6.enabled)
515 {
516 const struct in6_addr ip6 = ifconfig_pool_handle_to_ipv6_base(pool, i);
517 ip6_str = print_in6_addr(ip6, 0, &gc);
518 }
519
520 status_printf(out, "%s,%s,%s", e->common_name, ip_str, ip6_str);
521 }
522 }
523 gc_free(&gc);
524 }
525}
526
527static void
528ifconfig_pool_msg(const struct ifconfig_pool *pool, int msglevel)
529{
530 struct status_output *so = status_open(NULL, 0, msglevel, NULL, 0);
531 ASSERT(so);
532 status_printf(so, "IFCONFIG POOL LIST");
533 ifconfig_pool_list(pool, so);
534 status_close(so);
535}
536
537/*
538 * Deal with reading/writing the ifconfig pool database to a file
539 */
540
542ifconfig_pool_persist_init(const char *filename, int refresh_freq)
543{
544 struct ifconfig_pool_persist *ret;
545
546 ASSERT(filename);
547
549 if (refresh_freq > 0)
550 {
551 ret->fixed = false;
552 ret->file =
553 status_open(filename, refresh_freq, -1, NULL, STATUS_OUTPUT_READ | STATUS_OUTPUT_WRITE);
554 }
555 else
556 {
557 ret->fixed = true;
558 ret->file = status_open(filename, 0, -1, NULL, STATUS_OUTPUT_READ);
559 }
560 return ret;
561}
562
563void
565{
566 if (persist)
567 {
568 if (persist->file)
569 {
570 status_close(persist->file);
571 }
572 free(persist);
573 }
574}
575
576bool
578{
579 if (persist->file)
580 {
581 return status_trigger(persist->file);
582 }
583 else
584 {
585 return false;
586 }
587}
588
589void
591{
592 const int buf_size = 128;
593
594 update_time();
595
596 if (persist && persist->file && pool)
597 {
598 struct gc_arena gc = gc_new();
599 struct buffer in = alloc_buf_gc(256, &gc);
600 char *cn_buf, *ip_buf, *ip6_buf;
601
605
606 while (true)
607 {
608 ASSERT(buf_init(&in, 0));
609 if (!status_read(persist->file, &in))
610 {
611 break;
612 }
613 if (!BLEN(&in))
614 {
615 continue;
616 }
617
618 int c = *BSTR(&in);
619 if (c == '#' || c == ';')
620 {
621 continue;
622 }
623
624 msg(M_INFO, "ifconfig_pool_read(), in='%s'", BSTR(&in));
625
626 /* The expected format of a line is: "CN,IP4,IP6".
627 *
628 * IP4 or IP6 may be empty when respectively no v4 or v6 pool
629 * was previously specified.
630 *
631 * This means that accepted strings can be:
632 * - CN,IP4,IP6
633 * - CN,IP4
634 * - CN,,IP6
635 */
636 if (!buf_parse(&in, ',', cn_buf, buf_size) || !buf_parse(&in, ',', ip_buf, buf_size))
637 {
638 continue;
639 }
640
641 ifconfig_pool_handle h = -1, h6 = -1;
642
643 if (strlen(ip_buf) > 0)
644 {
645 bool v4_ok = true;
647
648 if (!v4_ok)
649 {
650 msg(M_WARN, "pool: invalid IPv4 (%s) for CN=%s", ip_buf, cn_buf);
651 }
652 else
653 {
655 if (h < 0)
656 {
657 msg(M_WARN, "pool: IPv4 (%s) out of pool range for CN=%s", ip_buf, cn_buf);
658 }
659 }
660 }
661
662 if (buf_parse(&in, ',', ip6_buf, buf_size) && strlen(ip6_buf) > 0)
663 {
664 struct in6_addr addr6;
665
666 if (!get_ipv6_addr(ip6_buf, &addr6, NULL, M_WARN))
667 {
668 msg(M_WARN, "pool: invalid IPv6 (%s) for CN=%s", ip6_buf, cn_buf);
669 }
670 else
671 {
672 h6 = ifconfig_pool_ipv6_base_to_handle(pool, &addr6);
673 if (h6 < 0)
674 {
675 msg(M_WARN, "pool: IPv6 (%s) out of pool range for CN=%s", ip6_buf, cn_buf);
676 }
677
678 /* Rely on IPv6 if no IPv4 was provided or the one provided
679 * was not valid
680 */
681 if (h < 0)
682 {
683 h = h6;
684 }
685 }
686 }
687
688 /* at the moment IPv4 and IPv6 share the same pool, therefore offsets
689 * have to match for the same client.
690 *
691 * If offsets differ we use the IPv4, therefore warn the user about this.
692 */
693 if ((h6 >= 0) && (h != h6))
694 {
695 msg(M_WARN, "pool: IPv4 (%s) and IPv6 (%s) have different offsets! Relying on IPv4",
696 ip_buf, ip6_buf);
697 }
698
699 /* if at least one among v4 and v6 was properly parsed, attempt
700 * setting an handle for this client
701 */
702 if (h >= 0)
703 {
704 msg(M_INFO, "succeeded -> ifconfig_pool_set(hand=%d)", h);
705 ifconfig_pool_set(pool, cn_buf, h, persist->fixed);
706 }
707 }
708
710
711 gc_free(&gc);
712 }
713}
714
715#if defined(__GNUC__) || defined(__clang__)
716#pragma GCC diagnostic pop
717#endif
718
719void
720ifconfig_pool_write(struct ifconfig_pool_persist *persist, const struct ifconfig_pool *pool)
721{
722 if (persist && persist->file && (status_rw_flags(persist->file) & STATUS_OUTPUT_WRITE) && pool)
723 {
724 status_reset(persist->file);
725 ifconfig_pool_list(pool, persist->file);
726 status_flush(persist->file);
727 }
728}
729
730/*
731 * TESTING ONLY
732 */
733
734#ifdef IFCONFIG_POOL_TEST
735
736#define DUP_CN
737
738void
739ifconfig_pool_test(in_addr_t start, in_addr_t end)
740{
741 struct gc_arena gc = gc_new();
743 /*struct ifconfig_pool *p = ifconfig_pool_init (IFCONFIG_POOL_INDIV, start, end);*/
744 ifconfig_pool_handle array[256];
745 int i;
746
747 CLEAR(array);
748
749 msg(M_INFO | M_NOPREFIX, "************ 1");
750 for (i = 0; i < (int)SIZE(array); ++i)
751 {
752 char *cn;
754 in_addr_t local, remote;
755 char buf[256];
756 snprintf(buf, sizeof(buf), "common-name-%d", i);
757#ifdef DUP_CN
758 cn = NULL;
759#else
760 cn = buf;
761#endif
762 h = ifconfig_pool_acquire(p, &local, &remote, NULL, cn);
763 if (h < 0)
764 {
765 break;
766 }
767 msg(M_INFO | M_NOPREFIX, "IFCONFIG_POOL TEST pass 1: l=%s r=%s cn=%s",
768 print_in_addr_t(local, 0, &gc), print_in_addr_t(remote, 0, &gc), cn ? cn : "[NULL]");
769 array[i] = h;
770 }
771
772 msg(M_INFO | M_NOPREFIX, "************* 2");
773 for (i = (int)SIZE(array) / 16; i < (int)SIZE(array) / 8; ++i)
774 {
775 msg(M_INFO, "Attempt to release %d cn=%s", array[i], p->list[i].common_name);
776 if (!ifconfig_pool_release(p, array[i]))
777 {
778 break;
779 }
780 msg(M_INFO, "Succeeded");
781 }
782
783 CLEAR(array);
784
785 msg(M_INFO | M_NOPREFIX, "**************** 3");
786 for (i = 0; i < (int)SIZE(array); ++i)
787 {
788 char *cn;
790 in_addr_t local, remote;
791 char buf[256];
792 snprintf(buf, sizeof(buf), "common-name-%d", i + 24);
793#ifdef DUP_CN
794 cn = NULL;
795#else
796 cn = buf;
797#endif
798 h = ifconfig_pool_acquire(p, &local, &remote, NULL, cn);
799 if (h < 0)
800 {
801 break;
802 }
803 msg(M_INFO | M_NOPREFIX, "IFCONFIG_POOL TEST pass 3: l=%s r=%s cn=%s",
804 print_in_addr_t(local, 0, &gc), print_in_addr_t(remote, 0, &gc), cn ? cn : "[NULL]");
805 array[i] = h;
806 }
807
809 gc_free(&gc);
810}
811
812#endif /* ifdef IFCONFIG_POOL_TEST */
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
Allocate a buffer of the given size under garbage collection.
Definition buffer.c:77
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.
Definition buffer.c:783
char * string_alloc(const char *str, struct gc_arena *gc)
Duplicate a string, allocating memory under garbage collection.
Definition buffer.c:618
Buffer management functions and garbage collection.
#define BSTR(buf)
Return the buffer content pointer cast to char *.
Definition buffer.h:157
#define ALLOC_ARRAY_CLEAR(dptr, type, n)
Allocate and zero-initialise an array of n elements of the given type.
Definition buffer.h:2077
#define ALLOC_ARRAY_CLEAR_GC(dptr, type, n, gc)
Allocate and zero-initialise a garbage-collected array of n elements.
Definition buffer.h:2091
#define BLEN(buf)
Return the length of the buffer content in bytes.
Definition buffer.h:151
static void gc_free(struct gc_arena *a)
Free all allocations in a garbage collection arena.
Definition buffer.h:1974
#define ALLOC_OBJ_CLEAR(dptr, type)
Allocate and zero-initialise memory for a single object of the given type.
Definition buffer.h:2036
#define buf_init(buf, offset)
Definition buffer.h:364
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
Definition buffer.h:1958
#define D_IFCONFIG_POOL
Definition errlevel.h:82
#define M_INFO
Definition errlevel.h:54
#define CLEAR(x)
Definition basic.h:32
#define SIZE(x)
Definition basic.h:29
#define M_NOPREFIX
Definition error.h:98
#define M_FATAL
Definition error.h:90
#define msg(flags,...)
Definition error.h:152
unsigned int msglvl_t
Definition error.h:77
#define ASSERT(x)
Definition error.h:221
#define M_WARN
Definition error.h:92
time_t now
Definition otime.c:33
static void update_time(void)
Definition otime.h:84
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)
Definition pool.c:316
static void ifconfig_pool_list(const struct ifconfig_pool *pool, struct status_output *out)
Definition pool.c:492
static void ifconfig_pool_entry_free(struct ifconfig_pool_entry *ipe, bool hard)
Definition pool.c:53
static in_addr_t ifconfig_pool_handle_to_ip_base(const struct ifconfig_pool *pool, ifconfig_pool_handle hand)
Definition pool.c:438
static ifconfig_pool_handle ifconfig_pool_ip_base_to_handle(const struct ifconfig_pool *pool, const in_addr_t addr)
Definition pool.c:375
static uint32_t in6_addr_low32(const struct in6_addr *a)
Definition pool.c:46
static ifconfig_pool_handle ifconfig_pool_ipv6_base_to_handle(const struct ifconfig_pool *pool, const struct in6_addr *in_addr)
Definition pool.c:406
bool ifconfig_pool_release(struct ifconfig_pool *pool, ifconfig_pool_handle hand, const bool hard)
Definition pool.c:357
struct ifconfig_pool_persist * ifconfig_pool_persist_init(const char *filename, int refresh_freq)
Definition pool.c:542
void ifconfig_pool_write(struct ifconfig_pool_persist *persist, const struct ifconfig_pool *pool)
Definition pool.c:720
static void ifconfig_pool_set(struct ifconfig_pool *pool, const char *cn, ifconfig_pool_handle h, const bool fixed)
Definition pool.c:480
void ifconfig_pool_persist_close(struct ifconfig_pool_persist *persist)
Definition pool.c:564
bool ifconfig_pool_write_trigger(struct ifconfig_pool_persist *persist)
Definition pool.c:577
bool ifconfig_pool_verify_range(const msglvl_t msglevel, const in_addr_t start, const in_addr_t end)
Definition pool.c:132
static int ifconfig_pool_find(struct ifconfig_pool *pool, const char *common_name)
Definition pool.c:72
void ifconfig_pool_free(struct ifconfig_pool *pool)
Definition pool.c:300
static void ifconfig_pool_msg(const struct ifconfig_pool *pool, int msglevel)
Definition pool.c:528
void ifconfig_pool_read(struct ifconfig_pool_persist *persist, struct ifconfig_pool *pool)
Definition pool.c:590
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)
Definition pool.c:160
static struct in6_addr ifconfig_pool_handle_to_ipv6_base(const struct ifconfig_pool *pool, ifconfig_pool_handle hand)
Definition pool.c:467
#define IFCONFIG_POOL_MAX
Definition pool.h:31
pool_type
Definition pool.h:35
@ IFCONFIG_POOL_30NET
Definition pool.h:36
@ IFCONFIG_POOL_INDIV
Definition pool.h:37
int ifconfig_pool_handle
Definition pool.h:72
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.
Definition resolve.c:489
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.
Definition resolve.c:442
DNS resolution.
#define GETADDR_HOST_ORDER
Definition resolve.h:40
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)
Definition status.c:147
bool status_trigger(struct status_output *so)
Definition status.c:132
void status_printf(struct status_output *so, const char *format,...)
Definition status.c:221
bool status_read(struct status_output *so, struct buffer *buf)
Definition status.c:263
struct status_output * status_open(const char *filename, const int refresh_freq, const int msglevel, const struct virtual_output *vout, const unsigned int flags)
Definition status.c:64
void status_flush(struct status_output *so)
Definition status.c:156
bool status_close(struct status_output *so)
Definition status.c:187
static unsigned int status_rw_flags(const struct status_output *so)
Definition status.h:91
#define STATUS_OUTPUT_WRITE
Definition status.h:51
#define STATUS_OUTPUT_READ
Definition status.h:50
Wrapper structure for dynamically allocated memory.
Definition buffer.h:71
int len
Length in bytes of the actual content within the allocated memory.
Definition buffer.h:76
Garbage collection arena used to keep track of dynamically allocated memory.
Definition buffer.h:127
Definition pool.h:41
bool fixed
Definition pool.h:45
time_t last_release
Definition pool.h:44
bool in_use
Definition pool.h:42
char * common_name
Definition pool.h:43
struct status_output * file
Definition pool.h:68
struct ifconfig_pool_entry * list
Definition pool.h:63
bool duplicate_cn
Definition pool.h:50
in_addr_t base
Definition pool.h:55
struct ifconfig_pool::@22 ipv6
struct ifconfig_pool::@21 ipv4
int size
Definition pool.h:62
bool enabled
Definition pool.h:53
enum pool_type type
Definition pool.h:54
int msglevel
Definition status.h:57
uint32_t in_addr_t
Definition syshead.h:52
struct gc_arena gc
Definition test_ssl.c:138