IPv6: add DHCPv6 support

The DHCP version is determined according to the first IP address that
appears in the configuration file.  Caveat; counters are of native long
type.  Since IPv6 address space has 2^128 addresses, they are subject to
overflow.

[Sami Kerola:  This commit also fixed a percent sorting bug, which has
been broken always.  See changes ret_percent() for the fix.]

CC: LI Zimu <lzm@cernet.edu.cn>
CC: Xing Li <xing@cernet.edu.cn>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Cheer Xiao <xiaqqaix@gmail.com>
This commit is contained in:
Cheer Xiao 2012-12-02 19:38:26 +00:00 committed by Sami Kerola
parent 71bcee14e9
commit a57d399643
8 changed files with 267 additions and 119 deletions

View file

@ -36,20 +36,31 @@
#include "dhcpd-pools.h"
#include "xalloc.h"
void add_lease(int ip, enum ltype type)
#define HASH_FIND_V6(head, findv6, out) HASH_FIND(hh, head, findv6, 16, out)
#define HASH_ADD_V6(head, v6field, add) HASH_ADD(hh, head, v6field, 16, add)
void add_lease(union ipaddr_t *addr, enum ltype type)
{
struct leases_t *l;
l = xmalloc(sizeof(struct leases_t));
l->ip = ip;
copy_ipaddr(&l->ip, addr);
l->type = type;
HASH_ADD_INT(leases, ip, l);
if (dhcp_version == VERSION_6) {
HASH_ADD_V6(leases, ip.v6, l);
} else {
HASH_ADD_INT(leases, ip.v4, l);
}
}
struct leases_t *find_lease(int ip)
struct leases_t *find_lease(union ipaddr_t *addr)
{
struct leases_t *l;
HASH_FIND_INT(leases, &ip, l);
if (dhcp_version == VERSION_6) {
HASH_FIND_V6(leases, &addr->v6, l);
} else {
HASH_FIND_INT(leases, &addr->v4, l);
}
return l;
}