Add a getter for the mem_pool_t base address
[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 struct mem_pool_t {
33
34 /**
35 * Get the name of this pool.
36 *
37 * @return the name of this pool
38 */
39 const char* (*get_name)(mem_pool_t *this);
40
41 /**
42 * Get the base (first) address of this pool.
43 *
44 * @return base address, internal host
45 */
46 host_t* (*get_base)(mem_pool_t *this);
47
48 /**
49 * Get the size (i.e. number of addresses) of this pool.
50 *
51 * @return the size of this pool
52 */
53 u_int (*get_size)(mem_pool_t *this);
54
55 /**
56 * Get the number of online leases.
57 *
58 * @return the number of offline leases
59 */
60 u_int (*get_online)(mem_pool_t *this);
61
62 /**
63 * Get the number of offline leases.
64 *
65 * @return the number of online leases
66 */
67 u_int (*get_offline)(mem_pool_t *this);
68
69 /**
70 * Acquire an address for the given id from this pool.
71 *
72 * @param id the id to acquire an address for
73 * @param requested acquire this address, if possible
74 * @return the acquired address
75 */
76 host_t* (*acquire_address)(mem_pool_t *this, identification_t *id,
77 host_t *requested);
78
79 /**
80 * Release a previously acquired address.
81 *
82 * @param address the address to release
83 * @param id the id the address was assigned to
84 * @return TRUE, if the lease was found
85 */
86 bool (*release_address)(mem_pool_t *this, host_t *address,
87 identification_t *id);
88
89 /**
90 * Create an enumerator over the leases of this pool.
91 *
92 * Enumerator enumerates over
93 * identification_t *id, host_t *address, bool online
94 *
95 * @return enumerator
96 */
97 enumerator_t* (*create_lease_enumerator)(mem_pool_t *this);
98
99 /**
100 * Destroy a mem_pool_t instance.
101 */
102 void (*destroy)(mem_pool_t *this);
103 };
104
105 /**
106 * Create an in-memory IP address pool.
107 *
108 * An empty pool just returns the requested address.
109 *
110 * @param name name of this pool
111 * @param base base address of this pool, NULL to create an empty pool
112 * @param bits net mask
113 */
114 mem_pool_t *mem_pool_create(char *name, host_t *base, int bits);
115
116 #endif /** MEM_POOL_H_ @} */
117