2 * IP address pool functions.
3 * Copyright (C) 2003, 2004 Mondru AB.
5 * The contents of this file may be used under the terms of the GNU
6 * General Public License Version 2, provided that the above copyright
7 * notice and this permission notice is included in all copies or
8 * substantial portions of the software.
15 /* Assuming that the address space is fragmented we need a hash table
16 in order to return the addresses.
18 The list pool should provide for both IPv4 and IPv6 addresses.
20 When initialising a new address pool it should be possible to pass
21 a string of CIDR format networks: "10.0.0.0/24 10.15.0.0/20" would
22 translate to 256 addresses starting at 10.0.0.0 and 1024 addresses
23 starting at 10.15.0.0.
25 The above also applies to IPv6 which can be specified as described
31 #define IPPOOL_NONETWORK 0x01
32 #define IPPOOL_NOBROADCAST 0x02
33 #define IPPOOL_NOGATEWAY 0x04
35 #define IPPOOL_STATSIZE 0x10000
37 struct ippoolm_t
; /* Forward declaration */
40 unsigned int listsize
; /* Total number of addresses */
41 int allowdyn
; /* Allow dynamic IP address allocation */
42 int allowstat
; /* Allow static IP address allocation */
43 struct in_addr stataddr
; /* Static address range network address */
44 struct in_addr statmask
; /* Static address range network mask */
45 struct ippoolm_t
*member
; /* Listsize array of members */
46 unsigned int hashsize
; /* Size of hash table */
47 int hashlog
; /* Log2 size of hash table */
48 int hashmask
; /* Bitmask for calculating hash */
49 struct ippoolm_t
**hash
; /* Hashsize array of pointer to member */
50 struct ippoolm_t
*firstdyn
; /* Pointer to first free dynamic member */
51 struct ippoolm_t
*lastdyn
; /* Pointer to last free dynamic member */
52 struct ippoolm_t
*firststat
; /* Pointer to first free static member */
53 struct ippoolm_t
*laststat
; /* Pointer to last free static member */
58 struct in6_addr addr
; /* IP address of this member */
60 struct in_addr addr
; /* IP address of this member */
62 int inuse
; /* 0=available; 1= dynamic; 2 = static */
63 struct ippoolm_t
*nexthash
; /* Linked list part of hash table */
64 struct ippoolm_t
*prev
, *next
; /* Linked list of free dynamic or static */
65 void *peer
; /* Pointer to peer protocol handler */
68 /* The above structures require approximately 20+4 = 24 bytes for
69 each address (IPv4). For IPv6 the corresponding value is 32+4 = 36
70 bytes for each address. */
72 /* Hash an IP address using code based on Bob Jenkins lookupa */
73 extern unsigned long int ippool_hash4(struct in_addr
*addr
);
75 /* Create new address pool */
76 extern int ippool_new(struct ippool_t
**this, char *dyn
, char *stat
,
77 int allowdyn
, int allowstat
, int flags
);
79 /* Delete existing address pool */
80 extern int ippool_free(struct ippool_t
*this);
82 /* Find an IP address in the pool */
83 extern int ippool_getip(struct ippool_t
*this, struct ippoolm_t
**member
,
84 struct in_addr
*addr
);
86 /* Get an IP address. If addr = 0.0.0.0 get a dynamic IP address. Otherwise
87 check to see if the given address is available */
88 extern int ippool_newip(struct ippool_t
*this, struct ippoolm_t
**member
,
89 struct in_addr
*addr
, int statip
);
91 /* Return a previously allocated IP address */
92 extern int ippool_freeip(struct ippool_t
*this, struct ippoolm_t
*member
);
94 /* Get net and mask based on ascii string */
95 extern int ippool_aton(struct in_addr
*addr
, struct in_addr
*mask
,
96 char *pool
, int number
);
99 extern unsigned long int ippool_hash6(struct in6_addr
*addr
);
100 extern int ippool_getip6(struct ippool_t
*this, struct in6_addr
*addr
);
101 extern int ippool_returnip6(struct ippool_t
*this, struct in6_addr
*addr
);
104 #endif /* !_IPPOOL_H */