attribute-manager: Pass full IKE_SA to handler methods
[strongswan.git] / src / libcharon / 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 typedef enum mem_pool_op_t mem_pool_op_t;
26
27 #include <networking/host.h>
28 #include <utils/identification.h>
29
30 /**
31 * In-memory IP pool acquire operation.
32 */
33 enum mem_pool_op_t {
34 /** Check for an exsiting lease */
35 MEM_POOL_EXISTING,
36 /** Get a new lease */
37 MEM_POOL_NEW,
38 /** Replace an existing offline lease of another ID */
39 MEM_POOL_REASSIGN,
40 };
41
42 /**
43 * An in-memory IP address pool.
44 */
45 struct mem_pool_t {
46
47 /**
48 * Get the name of this pool.
49 *
50 * @return the name of this pool
51 */
52 const char* (*get_name)(mem_pool_t *this);
53
54 /**
55 * Get the base (first) address of this pool.
56 *
57 * @return base address, internal host
58 */
59 host_t* (*get_base)(mem_pool_t *this);
60
61 /**
62 * Get the size (i.e. number of addresses) of this pool.
63 *
64 * @return the size of this pool
65 */
66 u_int (*get_size)(mem_pool_t *this);
67
68 /**
69 * Get the number of online leases.
70 *
71 * @return the number of offline leases
72 */
73 u_int (*get_online)(mem_pool_t *this);
74
75 /**
76 * Get the number of offline leases.
77 *
78 * @return the number of online leases
79 */
80 u_int (*get_offline)(mem_pool_t *this);
81
82 /**
83 * Acquire an address for the given id from this pool.
84 *
85 * This call is usually invoked several times: The first time to find an
86 * existing lease (MEM_POOL_EXISTING), if none found a second time to
87 * acquire a new lease (MEM_POOL_NEW), and if the pool is full once again
88 * to assign an existing offline lease (MEM_POOL_REASSIGN).
89 *
90 * @param id the id to acquire an address for
91 * @param requested acquire this address, if possible
92 * @param operation acquire operation to perform, see above
93 * @return the acquired address
94 */
95 host_t* (*acquire_address)(mem_pool_t *this, identification_t *id,
96 host_t *requested, mem_pool_op_t operation);
97
98 /**
99 * Release a previously acquired address.
100 *
101 * @param address the address to release
102 * @param id the id the address was assigned to
103 * @return TRUE, if the lease was found
104 */
105 bool (*release_address)(mem_pool_t *this, host_t *address,
106 identification_t *id);
107
108 /**
109 * Create an enumerator over the leases of this pool.
110 *
111 * Enumerator enumerates over
112 * identification_t *id, host_t *address, bool online
113 *
114 * @return enumerator
115 */
116 enumerator_t* (*create_lease_enumerator)(mem_pool_t *this);
117
118 /**
119 * Destroy a mem_pool_t instance.
120 */
121 void (*destroy)(mem_pool_t *this);
122 };
123
124 /**
125 * Create an in-memory IP address pool.
126 *
127 * An empty pool just returns the requested address.
128 *
129 * @param name name of this pool
130 * @param base base address of this pool, NULL to create an empty pool
131 * @param bits number of non-network bits in base, as in CIDR notation
132 * @return memory pool instance
133 */
134 mem_pool_t *mem_pool_create(char *name, host_t *base, int bits);
135
136 /**
137 * Create an in-memory IP address from a range.
138 *
139 * @param name name of this pool
140 * @param from start of ranged pool
141 * @param to end of ranged pool
142 * @return memory pool instance, NULL if range invalid
143 */
144 mem_pool_t *mem_pool_create_range(char *name, host_t *from, host_t *to);
145
146 #endif /** MEM_POOL_H_ @} */