Annotation of embedaddon/coova-chilli/src/ippool.h, revision 1.1
1.1 ! misho 1: /*
! 2: *
! 3: * IP address pool functions.
! 4: * Copyright (C) 2003, 2004 Mondru AB.
! 5: * Copyright (c) 2006-2007 David Bird <david@coova.com>
! 6: *
! 7: * The contents of this file may be used under the terms of the GNU
! 8: * General Public License Version 2, provided that the above copyright
! 9: * notice and this permission notice is included in all copies or
! 10: * substantial portions of the software.
! 11: *
! 12: */
! 13:
! 14: #ifndef _IPPOOL_H
! 15: #define _IPPOOL_H
! 16:
! 17: /* Assuming that the address space is fragmented we need a hash table
! 18: in order to return the addresses.
! 19:
! 20: The list pool should provide for both IPv4 and IPv6 addresses.
! 21:
! 22: When initialising a new address pool it should be possible to pass
! 23: a string of CIDR format networks: "10.0.0.0/24 10.15.0.0/20" would
! 24: translate to 256 addresses starting at 10.0.0.0 and 1024 addresses
! 25: starting at 10.15.0.0.
! 26:
! 27: The above also applies to IPv6 which can be specified as described
! 28: in RFC2373.
! 29: */
! 30:
! 31: #define IPPOOL_NOIP6
! 32:
! 33: #include "system.h"
! 34:
! 35: struct ippoolm_t; /* Forward declaration */
! 36:
! 37: struct ippool_t {
! 38: int listsize; /* Total number of addresses */
! 39: int allowdyn; /* Allow dynamic IP address allocation */
! 40: int allowstat; /* Allow static IP address allocation */
! 41: struct in_addr stataddr; /* Static address range network address */
! 42: struct in_addr statmask; /* Static address range network mask */
! 43: struct ippoolm_t *member; /* Listsize array of members */
! 44: int hashsize; /* Size of hash table */
! 45: int hashlog; /* Log2 size of hash table */
! 46: int hashmask; /* Bitmask for calculating hash */
! 47: struct ippoolm_t **hash; /* Hashsize array of pointer to member */
! 48: struct ippoolm_t *firstdyn; /* Pointer to first free dynamic member */
! 49: struct ippoolm_t *lastdyn; /* Pointer to last free dynamic member */
! 50: struct ippoolm_t *firststat; /* Pointer to first free static member */
! 51: struct ippoolm_t *laststat; /* Pointer to last free static member */
! 52: };
! 53:
! 54: struct ippoolm_t {
! 55: #ifndef IPPOOL_NOIP6
! 56: struct in6_addr addr; /* IP address of this member */
! 57: #else
! 58: struct in_addr addr; /* IP address of this member */
! 59: #endif
! 60: int inuse; /* 0=available; 1= dynamic; 2 = static */
! 61: struct ippoolm_t *nexthash; /* Linked list part of hash table */
! 62: struct ippoolm_t *prev, *next; /* Linked list of free dynamic or static */
! 63: void *peer; /* Pointer to peer protocol handler */
! 64: };
! 65:
! 66: /* The above structures require approximately 20+4 = 24 bytes for
! 67: each address (IPv4). For IPv6 the corresponding value is 32+4 = 36
! 68: bytes for each address. */
! 69:
! 70: /* Hash an IP address using code based on Bob Jenkins lookupa */
! 71: extern uint32_t ippool_hash4(struct in_addr *addr);
! 72:
! 73: /* Create new address pool */
! 74: extern int ippool_new(struct ippool_t **this,
! 75: char *dyn, int start, int end,
! 76: char *stat, int allowdyn, int allowstat);
! 77:
! 78: /* Delete existing address pool */
! 79: extern int ippool_free(struct ippool_t *this);
! 80:
! 81: /* Find an IP address in the pool */
! 82: extern int ippool_getip(struct ippool_t *this, struct ippoolm_t **member,
! 83: struct in_addr *addr);
! 84:
! 85: /* Get an IP address. If addr = 0.0.0.0 get a dynamic IP address. Otherwise
! 86: check to see if the given address is available */
! 87: extern int ippool_newip(struct ippool_t *this, struct ippoolm_t **member,
! 88: struct in_addr *addr, int statip);
! 89:
! 90: /* Return a previously allocated IP address */
! 91: extern int ippool_freeip(struct ippool_t *this, struct ippoolm_t *member);
! 92:
! 93: /* Get net and mask based on ascii string */
! 94: extern int ippool_aton(struct in_addr *addr, struct in_addr *mask,
! 95: char *pool, int number);
! 96:
! 97: int ippool_hashadd(struct ippool_t *this, struct ippoolm_t *member);
! 98:
! 99: #ifndef IPPOOL_NOIP6
! 100: extern uint32_t ippool_hash6(struct in6_addr *addr);
! 101: extern int ippool_getip6(struct ippool_t *this, struct in6_addr *addr);
! 102: extern int ippool_returnip6(struct ippool_t *this, struct in6_addr *addr);
! 103: #endif
! 104:
! 105: #endif /* !_IPPOOL_H */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>