Extracted in-memory IP address pool from stroke plugin to libhydra.
[strongswan.git] / src / libhydra / attributes / mem_pool.h
1 /*
2 * Copyright (C) 2010 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup mem_pool mem_pool
18 * @{ @ingroup attributes
19 */
20
21 #ifndef MEM_POOL_H
22 #define MEM_POOL_H
23
24 typedef struct mem_pool_t mem_pool_t;
25
26 #include <utils/host.h>
27 #include <utils/identification.h>
28
29 /**
30 * An in-memory IP address pool.
31 *
32 * @note the implementation is not thread-safe.
33 */
34 struct mem_pool_t {
35
36 /**
37 * Get the name of this pool.
38 *
39 * @return the name of this pool
40 */
41 const char* (*get_name)(mem_pool_t *this);
42
43 /**
44 * Get the size (i.e. number of addresses) of this pool.
45 *
46 * @return the size of this pool
47 */
48 u_int (*get_size)(mem_pool_t *this);
49
50 /**
51 * Get the number of online leases.
52 *
53 * @return the number of offline leases
54 */
55 u_int (*get_online)(mem_pool_t *this);
56
57 /**
58 * Get the number of offline leases.
59 *
60 * @return the number of online leases
61 */
62 u_int (*get_offline)(mem_pool_t *this);
63
64 /**
65 * Acquire an address for the given id from this pool.
66 *
67 * @param id the id to acquire an address for
68 * @param requested acquire this address, if possible
69 * @return the acquired address
70 */
71 host_t* (*acquire_address)(mem_pool_t *this, identification_t *id,
72 host_t *requested);
73
74 /**
75 * Release a previously acquired address.
76 *
77 * @param address the address to release
78 * @param id the id the address was assigned to
79 * @return TRUE, if the lease was found
80 */
81 bool (*release_address)(mem_pool_t *this, host_t *address,
82 identification_t *id);
83
84 /**
85 * Create an enumerator over the leases of this pool.
86 *
87 * Enumerator enumerates over
88 * identification_t *id, host_t *address, bool online
89 *
90 * @return enumerator
91 */
92 enumerator_t* (*create_lease_enumerator)(mem_pool_t *this);
93
94 /**
95 * Destroy a mem_pool_t instance.
96 */
97 void (*destroy)(mem_pool_t *this);
98 };
99
100 /**
101 * Create an in-memory IP address pool.
102 *
103 * An empty pool just returns the requested address.
104 *
105 * @param name name of this pool
106 * @param base base address of this pool, NULL to create an empty pool
107 * @param bits net mask
108 */
109 mem_pool_t *mem_pool_create(char *name, host_t *base, int bits);
110
111 #endif /** MEM_POOL_H_ @} */
112