mirror of
https://gitlab.isc.org/isc-projects/dhcp
synced 2025-09-02 07:15:44 +00:00
Existing server unittest migrated to ATF.
This commit is contained in:
@@ -1,5 +1,11 @@
|
|||||||
|
SUBDIRS = .
|
||||||
|
|
||||||
AM_CPPFLAGS = -I.. -DLOCALSTATEDIR='"@localstatedir@"'
|
AM_CPPFLAGS = -I.. -DLOCALSTATEDIR='"@localstatedir@"'
|
||||||
|
|
||||||
|
if HAVE_ATF
|
||||||
|
SUBDIRS += tests
|
||||||
|
endif
|
||||||
|
|
||||||
dist_sysconf_DATA = dhcpd.conf
|
dist_sysconf_DATA = dhcpd.conf
|
||||||
sbin_PROGRAMS = dhcpd
|
sbin_PROGRAMS = dhcpd
|
||||||
dhcpd_SOURCES = dhcpd.c dhcp.c bootp.c confpars.c db.c class.c failover.c \
|
dhcpd_SOURCES = dhcpd.c dhcp.c bootp.c confpars.c db.c class.c failover.c \
|
||||||
|
669
server/mdb6.c
669
server/mdb6.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2007-2012 by Internet Systems Consortium, Inc. ("ISC")
|
* Copyright (C) 2007-2011 by Internet Systems Consortium, Inc. ("ISC")
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -313,6 +313,8 @@ void
|
|||||||
ia_remove_iasubopt(struct ia_xx *ia, struct iasubopt *iasubopt,
|
ia_remove_iasubopt(struct ia_xx *ia, struct iasubopt *iasubopt,
|
||||||
const char *file, int line) {
|
const char *file, int line) {
|
||||||
int i, j;
|
int i, j;
|
||||||
|
if (ia == NULL || iasubopt == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
for (i=0; i<ia->num_iasubopt; i++) {
|
for (i=0; i<ia->num_iasubopt; i++) {
|
||||||
if (ia->iasubopt[i] == iasubopt) {
|
if (ia->iasubopt[i] == iasubopt) {
|
||||||
@@ -1155,7 +1157,7 @@ release_lease6(struct ipv6_pool *pool, struct iasubopt *lease) {
|
|||||||
* Create a prefix by hashing the input, and using that for
|
* Create a prefix by hashing the input, and using that for
|
||||||
* the part subject to allocation.
|
* the part subject to allocation.
|
||||||
*/
|
*/
|
||||||
static void
|
void
|
||||||
build_prefix6(struct in6_addr *pref,
|
build_prefix6(struct in6_addr *pref,
|
||||||
const struct in6_addr *net_start_pref,
|
const struct in6_addr *net_start_pref,
|
||||||
int pool_bits, int pref_bits,
|
int pool_bits, int pref_bits,
|
||||||
@@ -1883,665 +1885,4 @@ mark_interfaces_unavailable(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* unittest moved to server/tests/mdb6_unittest.c */
|
||||||
#ifdef UNIT_TEST
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
int
|
|
||||||
main(int argc, char *argv[]) {
|
|
||||||
struct iasubopt *iaaddr;
|
|
||||||
struct iasubopt *iaaddr_copy;
|
|
||||||
u_int32_t iaid;
|
|
||||||
struct ia_xx *ia_na;
|
|
||||||
struct ia_xx *ia_na_copy;
|
|
||||||
int i;
|
|
||||||
struct in6_addr addr;
|
|
||||||
struct ipv6_pool *pool;
|
|
||||||
struct ipv6_pool *pool_copy;
|
|
||||||
char addr_buf[INET6_ADDRSTRLEN];
|
|
||||||
char *uid;
|
|
||||||
struct data_string ds;
|
|
||||||
struct iasubopt *expired_iaaddr;
|
|
||||||
unsigned int attempts;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Test 0: Basic iaaddr manipulation.
|
|
||||||
*/
|
|
||||||
iaaddr = NULL;
|
|
||||||
if (iasubopt_allocate(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: iasubopt_allocate() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (iaaddr->state != FTS_FREE) {
|
|
||||||
printf("ERROR: bad state %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (iaaddr->heap_index != -1) {
|
|
||||||
printf("ERROR: bad heap_index %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
iaaddr_copy = NULL;
|
|
||||||
if (iasubopt_reference(&iaaddr_copy, iaaddr, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: iasubopt_reference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: iasubopt_reference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (iasubopt_dereference(&iaaddr_copy, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: iasubopt_reference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Test 1: Error iaaddr manipulation.
|
|
||||||
*/
|
|
||||||
/* bogus allocate arguments */
|
|
||||||
if (iasubopt_allocate(NULL, MDL) != DHCP_R_INVALIDARG) {
|
|
||||||
printf("ERROR: iasubopt_allocate() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
iaaddr = (struct iasubopt *)1;
|
|
||||||
if (iasubopt_allocate(&iaaddr, MDL) != DHCP_R_INVALIDARG) {
|
|
||||||
printf("ERROR: iasubopt_allocate() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* bogus reference arguments */
|
|
||||||
iaaddr = NULL;
|
|
||||||
if (iasubopt_allocate(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: iasubopt_allocate() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (iasubopt_reference(NULL, iaaddr, MDL) != DHCP_R_INVALIDARG) {
|
|
||||||
printf("ERROR: iasubopt_reference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
iaaddr_copy = (struct iasubopt *)1;
|
|
||||||
if (iasubopt_reference(&iaaddr_copy, iaaddr,
|
|
||||||
MDL) != DHCP_R_INVALIDARG) {
|
|
||||||
printf("ERROR: iasubopt_reference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
iaaddr_copy = NULL;
|
|
||||||
if (iasubopt_reference(&iaaddr_copy, NULL, MDL) != DHCP_R_INVALIDARG) {
|
|
||||||
printf("ERROR: iasubopt_reference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: iasubopt_reference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* bogus dereference arguments */
|
|
||||||
if (iasubopt_dereference(NULL, MDL) != DHCP_R_INVALIDARG) {
|
|
||||||
printf("ERROR: iasubopt_dereference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
iaaddr = NULL;
|
|
||||||
if (iasubopt_dereference(&iaaddr, MDL) != DHCP_R_INVALIDARG) {
|
|
||||||
printf("ERROR: iasubopt_dereference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Test 2: Basic ia_na manipulation.
|
|
||||||
*/
|
|
||||||
iaid = 666;
|
|
||||||
ia_na = NULL;
|
|
||||||
if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ia_allocate() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (memcmp(ia_na->iaid_duid.data, &iaid, sizeof(iaid)) != 0) {
|
|
||||||
printf("ERROR: bad IAID_DUID %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (memcmp(ia_na->iaid_duid.data+sizeof(iaid), "TestDUID", 8) != 0) {
|
|
||||||
printf("ERROR: bad IAID_DUID %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (ia_na->num_iasubopt != 0) {
|
|
||||||
printf("ERROR: bad num_iasubopt %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
ia_na_copy = NULL;
|
|
||||||
if (ia_reference(&ia_na_copy, ia_na, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ia_reference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
iaaddr = NULL;
|
|
||||||
if (iasubopt_allocate(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: iasubopt_allocate() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (ia_add_iasubopt(ia_na, iaaddr, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ia_add_iasubopt() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
ia_remove_iasubopt(ia_na, iaaddr, MDL);
|
|
||||||
if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: iasubopt_reference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (ia_dereference(&ia_na, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ia_dereference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (ia_dereference(&ia_na_copy, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ia_dereference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Test 3: lots of iaaddr in our ia_na
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* lots of iaaddr that we delete */
|
|
||||||
iaid = 666;
|
|
||||||
ia_na = NULL;
|
|
||||||
if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ia_allocate() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
for (i=0; i<100; i++) {
|
|
||||||
iaaddr = NULL;
|
|
||||||
if (iasubopt_allocate(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: iasubopt_allocate() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (ia_add_iasubopt(ia_na, iaaddr, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ia_add_iasubopt() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: iasubopt_reference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (i=0; i<100; i++) {
|
|
||||||
iaaddr = ia_na->iasubopt[random() % ia_na->num_iasubopt];
|
|
||||||
ia_remove_iasubopt(ia_na, iaaddr, MDL);
|
|
||||||
}
|
|
||||||
if (ia_dereference(&ia_na, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ia_dereference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* lots of iaaddr, let dereference cleanup */
|
|
||||||
iaid = 666;
|
|
||||||
ia_na = NULL;
|
|
||||||
if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ia_allocate() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
for (i=0; i<100; i++) {
|
|
||||||
iaaddr = NULL;
|
|
||||||
if (iasubopt_allocate(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: iasubopt_allocate() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (ia_add_iasubopt(ia_na, iaaddr, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ia_add_iasubopt() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: iasubopt_reference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ia_dereference(&ia_na, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ia_dereference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Test 4: Errors in ia_na.
|
|
||||||
*/
|
|
||||||
/* bogus allocate arguments */
|
|
||||||
if (ia_allocate(NULL, 123, "", 0, MDL) != DHCP_R_INVALIDARG) {
|
|
||||||
printf("ERROR: ia_allocate() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
ia_na = (struct ia_na *)1;
|
|
||||||
if (ia_allocate(&ia_na, 456, "", 0, MDL) != DHCP_R_INVALIDARG) {
|
|
||||||
printf("ERROR: ia_allocate() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* bogus reference arguments */
|
|
||||||
iaid = 666;
|
|
||||||
ia_na = NULL;
|
|
||||||
if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ia_allocate() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (ia_reference(NULL, ia_na, MDL) != DHCP_R_INVALIDARG) {
|
|
||||||
printf("ERROR: ia_reference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
ia_na_copy = (struct ia_na *)1;
|
|
||||||
if (ia_reference(&ia_na_copy, ia_na, MDL) != DHCP_R_INVALIDARG) {
|
|
||||||
printf("ERROR: ia_reference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
ia_na_copy = NULL;
|
|
||||||
if (ia_reference(&ia_na_copy, NULL, MDL) != DHCP_R_INVALIDARG) {
|
|
||||||
printf("ERROR: ia_reference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (ia_dereference(&ia_na, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ia_dereference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* bogus dereference arguments */
|
|
||||||
if (ia_dereference(NULL, MDL) != DHCP_R_INVALIDARG) {
|
|
||||||
printf("ERROR: ia_dereference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* bogus remove */
|
|
||||||
iaid = 666;
|
|
||||||
ia_na = NULL;
|
|
||||||
if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ia_allocate() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
ia_remove_iasubopt(ia_na, NULL, MDL);
|
|
||||||
if (ia_dereference(&ia_na, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ia_dereference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Test 5: Basic ipv6_pool manipulation.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* allocate, reference */
|
|
||||||
inet_pton(AF_INET6, "1:2:3:4::", &addr);
|
|
||||||
pool = NULL;
|
|
||||||
if (ipv6_pool_allocate(&pool, 0, &addr, 64, 128, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ipv6_pool_allocate() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (pool->num_active != 0) {
|
|
||||||
printf("ERROR: bad num_active %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (pool->bits != 64) {
|
|
||||||
printf("ERROR: bad bits %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
inet_ntop(AF_INET6, &pool->start_addr, addr_buf, sizeof(addr_buf));
|
|
||||||
if (strcmp(inet_ntop(AF_INET6, &pool->start_addr, addr_buf,
|
|
||||||
sizeof(addr_buf)), "1:2:3:4::") != 0) {
|
|
||||||
printf("ERROR: bad start_addr %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
pool_copy = NULL;
|
|
||||||
if (ipv6_pool_reference(&pool_copy, pool, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ipv6_pool_reference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* create_lease6, renew_lease6, expire_lease6 */
|
|
||||||
uid = "client0";
|
|
||||||
memset(&ds, 0, sizeof(ds));
|
|
||||||
ds.len = strlen(uid);
|
|
||||||
if (!buffer_allocate(&ds.buffer, ds.len, MDL)) {
|
|
||||||
printf("Out of memory\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
ds.data = ds.buffer->data;
|
|
||||||
memcpy((char *)ds.data, uid, ds.len);
|
|
||||||
if (create_lease6(pool, &iaaddr,
|
|
||||||
&attempts, &ds, 1) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: create_lease6() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (pool->num_inactive != 1) {
|
|
||||||
printf("ERROR: bad num_inactive %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (renew_lease6(pool, iaaddr) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: renew_lease6() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (pool->num_active != 1) {
|
|
||||||
printf("ERROR: bad num_active %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
expired_iaaddr = NULL;
|
|
||||||
if (expire_lease6(&expired_iaaddr, pool, 0) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: expire_lease6() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (expired_iaaddr != NULL) {
|
|
||||||
printf("ERROR: should not have expired a lease %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (pool->num_active != 1) {
|
|
||||||
printf("ERROR: bad num_active %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (expire_lease6(&expired_iaaddr, pool, 1000) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: expire_lease6() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (expired_iaaddr == NULL) {
|
|
||||||
printf("ERROR: should have expired a lease %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (iasubopt_dereference(&expired_iaaddr, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: iasubopt_dereference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (pool->num_active != 0) {
|
|
||||||
printf("ERROR: bad num_active %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: iasubopt_dereference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* release_lease6, decline_lease6 */
|
|
||||||
if (create_lease6(pool, &iaaddr, &attempts,
|
|
||||||
&ds, 1) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: create_lease6() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (renew_lease6(pool, iaaddr) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: renew_lease6() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (pool->num_active != 1) {
|
|
||||||
printf("ERROR: bad num_active %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (release_lease6(pool, iaaddr) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: decline_lease6() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (pool->num_active != 0) {
|
|
||||||
printf("ERROR: bad num_active %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: iasubopt_dereference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (create_lease6(pool, &iaaddr, &attempts,
|
|
||||||
&ds, 1) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: create_lease6() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (renew_lease6(pool, iaaddr) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: renew_lease6() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (pool->num_active != 1) {
|
|
||||||
printf("ERROR: bad num_active %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (decline_lease6(pool, iaaddr) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: decline_lease6() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (pool->num_active != 1) {
|
|
||||||
printf("ERROR: bad num_active %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: iasubopt_dereference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* dereference */
|
|
||||||
if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ipv6_pool_reference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (ipv6_pool_dereference(&pool_copy, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ipv6_pool_reference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Test 6: Error ipv6_pool manipulation
|
|
||||||
*/
|
|
||||||
if (ipv6_pool_allocate(NULL, 0, &addr,
|
|
||||||
64, 128, MDL) != DHCP_R_INVALIDARG) {
|
|
||||||
printf("ERROR: ipv6_pool_allocate() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
pool = (struct ipv6_pool *)1;
|
|
||||||
if (ipv6_pool_allocate(&pool, 0, &addr,
|
|
||||||
64, 128, MDL) != DHCP_R_INVALIDARG) {
|
|
||||||
printf("ERROR: ipv6_pool_allocate() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (ipv6_pool_reference(NULL, pool, MDL) != DHCP_R_INVALIDARG) {
|
|
||||||
printf("ERROR: ipv6_pool_reference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
pool_copy = (struct ipv6_pool *)1;
|
|
||||||
if (ipv6_pool_reference(&pool_copy, pool, MDL) != DHCP_R_INVALIDARG) {
|
|
||||||
printf("ERROR: ipv6_pool_reference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
pool_copy = NULL;
|
|
||||||
if (ipv6_pool_reference(&pool_copy, NULL, MDL) != DHCP_R_INVALIDARG) {
|
|
||||||
printf("ERROR: ipv6_pool_reference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (ipv6_pool_dereference(NULL, MDL) != DHCP_R_INVALIDARG) {
|
|
||||||
printf("ERROR: ipv6_pool_dereference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (ipv6_pool_dereference(&pool_copy, MDL) != DHCP_R_INVALIDARG) {
|
|
||||||
printf("ERROR: ipv6_pool_dereference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Test 7: order of expiration
|
|
||||||
*/
|
|
||||||
pool = NULL;
|
|
||||||
if (ipv6_pool_allocate(&pool, 0, &addr, 64, 128, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ipv6_pool_allocate() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
for (i=10; i<100; i+=10) {
|
|
||||||
if (create_lease6(pool, &iaaddr, &attempts,
|
|
||||||
&ds, i) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: create_lease6() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (renew_lease6(pool, iaaddr) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: renew_lease6() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: iasubopt_dereference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (pool->num_active != (i / 10)) {
|
|
||||||
printf("ERROR: bad num_active %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (pool->num_active != 9) {
|
|
||||||
printf("ERROR: bad num_active %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
for (i=10; i<100; i+=10) {
|
|
||||||
if (expire_lease6(&expired_iaaddr,
|
|
||||||
pool, 1000) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: expire_lease6() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (expired_iaaddr == NULL) {
|
|
||||||
printf("ERROR: should have expired a lease %s:%d\n",
|
|
||||||
MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (pool->num_active != (9 - (i / 10))) {
|
|
||||||
printf("ERROR: bad num_active %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (expired_iaaddr->hard_lifetime_end_time != i) {
|
|
||||||
printf("ERROR: bad hard_lifetime_end_time %s:%d\n",
|
|
||||||
MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (iasubopt_dereference(&expired_iaaddr, MDL) !=
|
|
||||||
ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: iasubopt_dereference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (pool->num_active != 0) {
|
|
||||||
printf("ERROR: bad num_active %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
expired_iaaddr = NULL;
|
|
||||||
if (expire_lease6(&expired_iaaddr, pool, 1000) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: expire_lease6() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ipv6_pool_dereference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Test 8: small pool
|
|
||||||
*/
|
|
||||||
pool = NULL;
|
|
||||||
addr.s6_addr[14] = 0x81;
|
|
||||||
if (ipv6_pool_allocate(&pool, 0, &addr, 127, 128, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ipv6_pool_allocate() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (create_lease6(pool, &iaaddr, &attempts,
|
|
||||||
&ds, 42) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: create_lease6() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (renew_lease6(pool, iaaddr) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: renew_lease6() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: iasubopt_dereference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (create_lease6(pool, &iaaddr, &attempts,
|
|
||||||
&ds, 11) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: create_lease6() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (renew_lease6(pool, iaaddr) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: renew_lease6() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: iasubopt_dereference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (create_lease6(pool, &iaaddr, &attempts,
|
|
||||||
&ds, 11) != ISC_R_NORESOURCES) {
|
|
||||||
printf("ERROR: create_lease6() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ipv6_pool_dereference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
addr.s6_addr[14] = 0;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Test 9: functions across all pools
|
|
||||||
*/
|
|
||||||
pool = NULL;
|
|
||||||
if (ipv6_pool_allocate(&pool, 0, &addr, 64, 128, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ipv6_pool_allocate() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (add_ipv6_pool(pool) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: add_ipv6_pool() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ipv6_pool_dereference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
pool = NULL;
|
|
||||||
if (find_ipv6_pool(&pool, 0, &addr) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: find_ipv6_pool() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ipv6_pool_dereference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
inet_pton(AF_INET6, "1:2:3:4:ffff:ffff:ffff:ffff", &addr);
|
|
||||||
pool = NULL;
|
|
||||||
if (find_ipv6_pool(&pool, 0, &addr) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: find_ipv6_pool() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ipv6_pool_dereference() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
inet_pton(AF_INET6, "1:2:3:5::", &addr);
|
|
||||||
pool = NULL;
|
|
||||||
if (find_ipv6_pool(&pool, 0, &addr) != ISC_R_NOTFOUND) {
|
|
||||||
printf("ERROR: find_ipv6_pool() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
inet_pton(AF_INET6, "1:2:3:3:ffff:ffff:ffff:ffff", &addr);
|
|
||||||
pool = NULL;
|
|
||||||
if (find_ipv6_pool(&pool, 0, &addr) != ISC_R_NOTFOUND) {
|
|
||||||
printf("ERROR: find_ipv6_pool() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* iaid = 666;
|
|
||||||
ia_na = NULL;
|
|
||||||
if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) {
|
|
||||||
printf("ERROR: ia_allocate() %s:%d\n", MDL);
|
|
||||||
return 1;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
{
|
|
||||||
struct in6_addr r;
|
|
||||||
struct data_string ds;
|
|
||||||
u_char data[16];
|
|
||||||
char buf[64];
|
|
||||||
int i, j;
|
|
||||||
|
|
||||||
memset(&ds, 0, sizeof(ds));
|
|
||||||
memset(data, 0xaa, sizeof(data));
|
|
||||||
ds.len = 16;
|
|
||||||
ds.data = data;
|
|
||||||
|
|
||||||
inet_pton(AF_INET6, "3ffe:501:ffff:100::", &addr);
|
|
||||||
for (i = 32; i < 42; i++)
|
|
||||||
for (j = i + 1; j < 49; j++) {
|
|
||||||
memset(&r, 0, sizeof(r));
|
|
||||||
memset(buf, 0, 64);
|
|
||||||
build_prefix6(&r, &addr, i, j, &ds);
|
|
||||||
inet_ntop(AF_INET6, &r, buf, 64);
|
|
||||||
printf("%d,%d-> %s/%d\n", i, j, buf, j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("SUCCESS: all tests passed (ignore any warning messages)\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
5
server/tests/Atffile
Normal file
5
server/tests/Atffile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
Content-Type: application/X-atf-atffile; version="1"
|
||||||
|
|
||||||
|
prop: test-suite = dhcp4
|
||||||
|
|
||||||
|
tp-glob: *_unittests
|
45
server/tests/Makefile.am
Normal file
45
server/tests/Makefile.am
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
SUBDIRS = .
|
||||||
|
|
||||||
|
AM_CPPFLAGS = $(ATF_CFLAGS) -DUNIT_TEST -I$((top_srcdir)/includes
|
||||||
|
AM_CPPFLAGS += -I$(top_srcdir)/bind/include -I$(top_srcdir)
|
||||||
|
AM_CPPFLAGS += -DLOCALSTATEDIR='"."' -Wno-unused-function -Wno-error=unused-variable
|
||||||
|
|
||||||
|
# for autotools debugging only
|
||||||
|
info:
|
||||||
|
@echo "ATF_CFLAGS=$(ATF_CFLAGS)"
|
||||||
|
@echo "ATF_LDFLAGS=$(ATF_LDFLAGS)"
|
||||||
|
@echo "ATF_LIBS=$(ATF_LIBS)"
|
||||||
|
|
||||||
|
DHCPSRC = ../dhcp.c ../bootp.c ../confpars.c ../db.c ../class.c \
|
||||||
|
../failover.c ../omapi.c ../mdb.c ../stables.c ../salloc.c \
|
||||||
|
../ddns.c ../dhcpleasequery.c ../dhcpv6.c ../mdb6.c \
|
||||||
|
../ldap.c ../ldap_casa.c ../dhcpd.c
|
||||||
|
|
||||||
|
DHCPLIBS = $(top_builddir)/common/libdhcp.a $(top_builddir)/omapip/libomapi.a \
|
||||||
|
$(top_builddir)/dhcpctl/libdhcpctl.a $(top_builddir)/bind/lib/libdns.a \
|
||||||
|
$(top_builddir)/bind/lib/libisc.a
|
||||||
|
|
||||||
|
ATF_TESTS =
|
||||||
|
TESTS =
|
||||||
|
if HAVE_ATF
|
||||||
|
|
||||||
|
check: $(ATF_TESTS)
|
||||||
|
atf-run | atf-report
|
||||||
|
|
||||||
|
ATF_TESTS += dhcpd_unittests legacy_unittests
|
||||||
|
|
||||||
|
dhcpd_unittests_SOURCES = $(DHCPSRC)
|
||||||
|
dhcpd_unittests_SOURCES += simple_unittest.c
|
||||||
|
|
||||||
|
dhcpd_unittests_LDADD = $(ATF_LDFLAGS)
|
||||||
|
dhcpd_unittests_LDADD += $(DHCPLIBS)
|
||||||
|
|
||||||
|
dhcpd_unittests_LDFLAGS = $(AM_LDFLAGS) $(ATF_LDFLAGS)
|
||||||
|
|
||||||
|
# This is a legacy unittest. It replaces main() with something that was in mdb6.c
|
||||||
|
legacy_unittests_SOURCES = $(DHCPSRC) mdb6_unittest.c
|
||||||
|
legacy_unittests_LDADD = $(DHCPLIBS) $(ATF_LDFLAGS)
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
|
noinst_PROGRAMS = $(ATF_TESTS) $(TESTS)
|
724
server/tests/mdb6_unittest.c
Normal file
724
server/tests/mdb6_unittest.c
Normal file
@@ -0,0 +1,724 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2007-2012 by Internet Systems Consortium, Inc. ("ISC")
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
|
||||||
|
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||||
|
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||||
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||||
|
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
||||||
|
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||||
|
* PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include "dhcpd.h"
|
||||||
|
#include "omapip/omapip.h"
|
||||||
|
#include "omapip/hash.h"
|
||||||
|
#include <isc/md5.h>
|
||||||
|
|
||||||
|
#include <atf-c.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define TEST1
|
||||||
|
#define TEST2
|
||||||
|
#define TEST3
|
||||||
|
#define TEST4
|
||||||
|
#define TEST5
|
||||||
|
#define TEST6
|
||||||
|
//#define TEST7
|
||||||
|
//#define TEST8
|
||||||
|
//#define TEST9
|
||||||
|
|
||||||
|
void build_prefix6(struct in6_addr *pref, const struct in6_addr *net_start_pref,
|
||||||
|
int pool_bits, int pref_bits, const struct data_string *input);
|
||||||
|
|
||||||
|
ATF_TC(iaaddr_basic);
|
||||||
|
ATF_TC_HEAD(iaaddr_basic, tc)
|
||||||
|
{
|
||||||
|
atf_tc_set_md_var(tc, "descr", "This test case checks that basic "
|
||||||
|
"IAADDR manipulation is possible.");
|
||||||
|
}
|
||||||
|
ATF_TC_BODY(iaaddr_basic, tc)
|
||||||
|
{
|
||||||
|
struct iasubopt *iaaddr;
|
||||||
|
struct iasubopt *iaaddr_copy;
|
||||||
|
/*
|
||||||
|
* Test 0: Basic iaaddr manipulation.
|
||||||
|
*/
|
||||||
|
iaaddr = NULL;
|
||||||
|
if (iasubopt_allocate(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_allocate() %s:%d", MDL);
|
||||||
|
}
|
||||||
|
if (iaaddr->state != FTS_FREE) {
|
||||||
|
atf_tc_fail("ERROR: bad state %s:%d", MDL);
|
||||||
|
}
|
||||||
|
if (iaaddr->heap_index != -1) {
|
||||||
|
atf_tc_fail("ERROR: bad heap_index %s:%d", MDL);
|
||||||
|
}
|
||||||
|
iaaddr_copy = NULL;
|
||||||
|
if (iasubopt_reference(&iaaddr_copy, iaaddr, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_reference() %s:%d", MDL);
|
||||||
|
}
|
||||||
|
if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_reference() %s:%d", MDL);
|
||||||
|
}
|
||||||
|
if (iasubopt_dereference(&iaaddr_copy, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_reference() %s:%d", MDL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ATF_TC(iaaddr_negative);
|
||||||
|
ATF_TC_HEAD(iaaddr_negative, tc)
|
||||||
|
{
|
||||||
|
atf_tc_set_md_var(tc, "descr", "This test case checks that IAADDR option "
|
||||||
|
"code can handle various negative scenarios.");
|
||||||
|
}
|
||||||
|
ATF_TC_BODY(iaaddr_negative, tc)
|
||||||
|
{
|
||||||
|
struct iasubopt *iaaddr;
|
||||||
|
struct iasubopt *iaaddr_copy;
|
||||||
|
|
||||||
|
/* bogus allocate arguments */
|
||||||
|
if (iasubopt_allocate(NULL, MDL) != DHCP_R_INVALIDARG) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_allocate() %s:%d", MDL);
|
||||||
|
}
|
||||||
|
iaaddr = (struct iasubopt *)1;
|
||||||
|
if (iasubopt_allocate(&iaaddr, MDL) != DHCP_R_INVALIDARG) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_allocate() %s:%d", MDL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* bogus reference arguments */
|
||||||
|
iaaddr = NULL;
|
||||||
|
if (iasubopt_allocate(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_allocate() %s:%d", MDL);
|
||||||
|
}
|
||||||
|
if (iasubopt_reference(NULL, iaaddr, MDL) != DHCP_R_INVALIDARG) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_reference() %s:%d", MDL);
|
||||||
|
}
|
||||||
|
iaaddr_copy = (struct iasubopt *)1;
|
||||||
|
if (iasubopt_reference(&iaaddr_copy, iaaddr,
|
||||||
|
MDL) != DHCP_R_INVALIDARG) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_reference() %s:%d", MDL);
|
||||||
|
}
|
||||||
|
iaaddr_copy = NULL;
|
||||||
|
if (iasubopt_reference(&iaaddr_copy, NULL, MDL) != DHCP_R_INVALIDARG) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_reference() %s:%d", MDL);
|
||||||
|
}
|
||||||
|
if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_reference() %s:%d", MDL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* bogus dereference arguments */
|
||||||
|
if (iasubopt_dereference(NULL, MDL) != DHCP_R_INVALIDARG) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_dereference() %s:%d", MDL);
|
||||||
|
}
|
||||||
|
iaaddr = NULL;
|
||||||
|
if (iasubopt_dereference(&iaaddr, MDL) != DHCP_R_INVALIDARG) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_dereference() %s:%d", MDL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ATF_TC(ia_na_basic);
|
||||||
|
ATF_TC_HEAD(ia_na_basic, tc)
|
||||||
|
{
|
||||||
|
atf_tc_set_md_var(tc, "descr", "This test case checks that IA_NA code can "
|
||||||
|
"handle various basic scenarios.");
|
||||||
|
}
|
||||||
|
ATF_TC_BODY(ia_na_basic, tc)
|
||||||
|
{
|
||||||
|
uint32_t iaid;
|
||||||
|
struct ia_xx *ia_na;
|
||||||
|
struct ia_xx *ia_na_copy;
|
||||||
|
struct iasubopt *iaaddr;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test 2: Basic ia_na manipulation.
|
||||||
|
*/
|
||||||
|
iaid = 666;
|
||||||
|
ia_na = NULL;
|
||||||
|
if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ia_allocate() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (memcmp(ia_na->iaid_duid.data, &iaid, sizeof(iaid)) != 0) {
|
||||||
|
atf_tc_fail("ERROR: bad IAID_DUID %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (memcmp(ia_na->iaid_duid.data+sizeof(iaid), "TestDUID", 8) != 0) {
|
||||||
|
atf_tc_fail("ERROR: bad IAID_DUID %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (ia_na->num_iasubopt != 0) {
|
||||||
|
atf_tc_fail("ERROR: bad num_iasubopt %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
ia_na_copy = NULL;
|
||||||
|
if (ia_reference(&ia_na_copy, ia_na, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ia_reference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
iaaddr = NULL;
|
||||||
|
if (iasubopt_allocate(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_allocate() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (ia_add_iasubopt(ia_na, iaaddr, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ia_add_iasubopt() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
ia_remove_iasubopt(ia_na, iaaddr, MDL);
|
||||||
|
if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_reference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (ia_dereference(&ia_na, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ia_dereference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (ia_dereference(&ia_na_copy, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ia_dereference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ATF_TC(ia_na_manyaddrs);
|
||||||
|
ATF_TC_HEAD(ia_na_manyaddrs, tc)
|
||||||
|
{
|
||||||
|
atf_tc_set_md_var(tc, "descr", "This test case checks that IA_NA can "
|
||||||
|
"handle lots of addresses.");
|
||||||
|
}
|
||||||
|
ATF_TC_BODY(ia_na_manyaddrs, tc)
|
||||||
|
{
|
||||||
|
uint32_t iaid;
|
||||||
|
struct ia_xx *ia_na;
|
||||||
|
struct iasubopt *iaaddr;
|
||||||
|
int i;
|
||||||
|
/*
|
||||||
|
* Test 3: lots of iaaddr in our ia_na
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* lots of iaaddr that we delete */
|
||||||
|
iaid = 666;
|
||||||
|
ia_na = NULL;
|
||||||
|
if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ia_allocate() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
for (i=0; i<100; i++) {
|
||||||
|
iaaddr = NULL;
|
||||||
|
if (iasubopt_allocate(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_allocate() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (ia_add_iasubopt(ia_na, iaaddr, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ia_add_iasubopt() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_reference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
for (i=0; i<100; i++) {
|
||||||
|
iaaddr = ia_na->iasubopt[random() % ia_na->num_iasubopt];
|
||||||
|
ia_remove_iasubopt(ia_na, iaaddr, MDL);
|
||||||
|
/* TODO: valgrind reports problem here: Invalid read of size 8
|
||||||
|
* Address 0x51e6258 is 56 bytes inside a block of size 88 free'd */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (ia_dereference(&ia_na, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ia_dereference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* lots of iaaddr, let dereference cleanup */
|
||||||
|
iaid = 666;
|
||||||
|
ia_na = NULL;
|
||||||
|
if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ia_allocate() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
for (i=0; i<100; i++) {
|
||||||
|
iaaddr = NULL;
|
||||||
|
if (iasubopt_allocate(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_allocate() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (ia_add_iasubopt(ia_na, iaaddr, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ia_add_iasubopt() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_reference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ia_dereference(&ia_na, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ia_dereference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ATF_TC(ia_na_negative);
|
||||||
|
ATF_TC_HEAD(ia_na_negative, tc)
|
||||||
|
{
|
||||||
|
atf_tc_set_md_var(tc, "descr", "This test case checks that IA_NA option "
|
||||||
|
"code can handle various negative scenarios.");
|
||||||
|
}
|
||||||
|
ATF_TC_BODY(ia_na_negative, tc)
|
||||||
|
{
|
||||||
|
uint32_t iaid;
|
||||||
|
struct ia_xx *ia_na;
|
||||||
|
struct ia_xx *ia_na_copy;
|
||||||
|
/*
|
||||||
|
* Test 4: Errors in ia_na.
|
||||||
|
*/
|
||||||
|
/* bogus allocate arguments */
|
||||||
|
if (ia_allocate(NULL, 123, "", 0, MDL) != DHCP_R_INVALIDARG) {
|
||||||
|
atf_tc_fail("ERROR: ia_allocate() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
ia_na = (struct ia_xx *)1;
|
||||||
|
if (ia_allocate(&ia_na, 456, "", 0, MDL) != DHCP_R_INVALIDARG) {
|
||||||
|
atf_tc_fail("ERROR: ia_allocate() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* bogus reference arguments */
|
||||||
|
iaid = 666;
|
||||||
|
ia_na = NULL;
|
||||||
|
if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ia_allocate() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (ia_reference(NULL, ia_na, MDL) != DHCP_R_INVALIDARG) {
|
||||||
|
atf_tc_fail("ERROR: ia_reference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
ia_na_copy = (struct ia_xx *)1;
|
||||||
|
if (ia_reference(&ia_na_copy, ia_na, MDL) != DHCP_R_INVALIDARG) {
|
||||||
|
atf_tc_fail("ERROR: ia_reference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
ia_na_copy = NULL;
|
||||||
|
if (ia_reference(&ia_na_copy, NULL, MDL) != DHCP_R_INVALIDARG) {
|
||||||
|
atf_tc_fail("ERROR: ia_reference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (ia_dereference(&ia_na, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ia_dereference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* bogus dereference arguments */
|
||||||
|
if (ia_dereference(NULL, MDL) != DHCP_R_INVALIDARG) {
|
||||||
|
atf_tc_fail("ERROR: ia_dereference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* bogus remove */
|
||||||
|
iaid = 666;
|
||||||
|
ia_na = NULL;
|
||||||
|
if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ia_allocate() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
ia_remove_iasubopt(ia_na, NULL, MDL);
|
||||||
|
if (ia_dereference(&ia_na, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ia_dereference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ATF_TC(ipv6_pool_basic);
|
||||||
|
ATF_TC_HEAD(ipv6_pool_basic, tc)
|
||||||
|
{
|
||||||
|
atf_tc_set_md_var(tc, "descr", "This test case checks that IPv6 pool "
|
||||||
|
"manipulation is possible.");
|
||||||
|
}
|
||||||
|
ATF_TC_BODY(ipv6_pool_basic, tc)
|
||||||
|
{
|
||||||
|
struct iasubopt *iaaddr;
|
||||||
|
struct in6_addr addr;
|
||||||
|
struct ipv6_pool *pool;
|
||||||
|
struct ipv6_pool *pool_copy;
|
||||||
|
char addr_buf[INET6_ADDRSTRLEN];
|
||||||
|
char *uid;
|
||||||
|
struct data_string ds;
|
||||||
|
struct iasubopt *expired_iaaddr;
|
||||||
|
unsigned int attempts;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test 5: Basic ipv6_pool manipulation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* allocate, reference */
|
||||||
|
inet_pton(AF_INET6, "1:2:3:4::", &addr);
|
||||||
|
pool = NULL;
|
||||||
|
if (ipv6_pool_allocate(&pool, 0, &addr, 64, 128, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ipv6_pool_allocate() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (pool->num_active != 0) {
|
||||||
|
atf_tc_fail("ERROR: bad num_active %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (pool->bits != 64) {
|
||||||
|
atf_tc_fail("ERROR: bad bits %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
inet_ntop(AF_INET6, &pool->start_addr, addr_buf, sizeof(addr_buf));
|
||||||
|
if (strcmp(inet_ntop(AF_INET6, &pool->start_addr, addr_buf,
|
||||||
|
sizeof(addr_buf)), "1:2:3:4::") != 0) {
|
||||||
|
atf_tc_fail("ERROR: bad start_addr %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
pool_copy = NULL;
|
||||||
|
if (ipv6_pool_reference(&pool_copy, pool, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ipv6_pool_reference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* create_lease6, renew_lease6, expire_lease6 */
|
||||||
|
uid = "client0";
|
||||||
|
memset(&ds, 0, sizeof(ds));
|
||||||
|
ds.len = strlen(uid);
|
||||||
|
if (!buffer_allocate(&ds.buffer, ds.len, MDL)) {
|
||||||
|
atf_tc_fail("Out of memory\n");
|
||||||
|
}
|
||||||
|
ds.data = ds.buffer->data;
|
||||||
|
memcpy((char *)ds.data, uid, ds.len);
|
||||||
|
if (create_lease6(pool, &iaaddr,
|
||||||
|
&attempts, &ds, 1) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: create_lease6() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (pool->num_inactive != 1) {
|
||||||
|
atf_tc_fail("ERROR: bad num_inactive %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (renew_lease6(pool, iaaddr) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: renew_lease6() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (pool->num_active != 1) {
|
||||||
|
atf_tc_fail("ERROR: bad num_active %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
expired_iaaddr = NULL;
|
||||||
|
if (expire_lease6(&expired_iaaddr, pool, 0) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: expire_lease6() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (expired_iaaddr != NULL) {
|
||||||
|
atf_tc_fail("ERROR: should not have expired a lease %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (pool->num_active != 1) {
|
||||||
|
atf_tc_fail("ERROR: bad num_active %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (expire_lease6(&expired_iaaddr, pool, 1000) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: expire_lease6() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (expired_iaaddr == NULL) {
|
||||||
|
atf_tc_fail("ERROR: should have expired a lease %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (iasubopt_dereference(&expired_iaaddr, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_dereference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (pool->num_active != 0) {
|
||||||
|
atf_tc_fail("ERROR: bad num_active %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_dereference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* release_lease6, decline_lease6 */
|
||||||
|
if (create_lease6(pool, &iaaddr, &attempts,
|
||||||
|
&ds, 1) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: create_lease6() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (renew_lease6(pool, iaaddr) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: renew_lease6() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (pool->num_active != 1) {
|
||||||
|
atf_tc_fail("ERROR: bad num_active %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (release_lease6(pool, iaaddr) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: decline_lease6() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (pool->num_active != 0) {
|
||||||
|
atf_tc_fail("ERROR: bad num_active %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_dereference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (create_lease6(pool, &iaaddr, &attempts,
|
||||||
|
&ds, 1) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: create_lease6() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (renew_lease6(pool, iaaddr) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: renew_lease6() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (pool->num_active != 1) {
|
||||||
|
atf_tc_fail("ERROR: bad num_active %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (decline_lease6(pool, iaaddr) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: decline_lease6() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (pool->num_active != 1) {
|
||||||
|
atf_tc_fail("ERROR: bad num_active %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_dereference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* dereference */
|
||||||
|
if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ipv6_pool_reference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (ipv6_pool_dereference(&pool_copy, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ipv6_pool_reference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ATF_TC(ipv6_pool_negative);
|
||||||
|
ATF_TC_HEAD(ipv6_pool_negative, tc)
|
||||||
|
{
|
||||||
|
atf_tc_set_md_var(tc, "descr", "This test case checks that IPv6 pool "
|
||||||
|
"can handle negative cases.");
|
||||||
|
}
|
||||||
|
ATF_TC_BODY(ipv6_pool_negative, tc)
|
||||||
|
{
|
||||||
|
struct in6_addr addr;
|
||||||
|
struct ipv6_pool *pool;
|
||||||
|
struct ipv6_pool *pool_copy;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test 6: Error ipv6_pool manipulation
|
||||||
|
*/
|
||||||
|
if (ipv6_pool_allocate(NULL, 0, &addr,
|
||||||
|
64, 128, MDL) != DHCP_R_INVALIDARG) {
|
||||||
|
atf_tc_fail("ERROR: ipv6_pool_allocate() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
pool = (struct ipv6_pool *)1;
|
||||||
|
if (ipv6_pool_allocate(&pool, 0, &addr,
|
||||||
|
64, 128, MDL) != DHCP_R_INVALIDARG) {
|
||||||
|
atf_tc_fail("ERROR: ipv6_pool_allocate() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (ipv6_pool_reference(NULL, pool, MDL) != DHCP_R_INVALIDARG) {
|
||||||
|
atf_tc_fail("ERROR: ipv6_pool_reference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
pool_copy = (struct ipv6_pool *)1;
|
||||||
|
if (ipv6_pool_reference(&pool_copy, pool, MDL) != DHCP_R_INVALIDARG) {
|
||||||
|
atf_tc_fail("ERROR: ipv6_pool_reference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
pool_copy = NULL;
|
||||||
|
if (ipv6_pool_reference(&pool_copy, NULL, MDL) != DHCP_R_INVALIDARG) {
|
||||||
|
atf_tc_fail("ERROR: ipv6_pool_reference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (ipv6_pool_dereference(NULL, MDL) != DHCP_R_INVALIDARG) {
|
||||||
|
atf_tc_fail("ERROR: ipv6_pool_dereference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (ipv6_pool_dereference(&pool_copy, MDL) != DHCP_R_INVALIDARG) {
|
||||||
|
atf_tc_fail("ERROR: ipv6_pool_dereference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ATF_TC(expire_order);
|
||||||
|
ATF_TC_HEAD(expire_order, tc)
|
||||||
|
{
|
||||||
|
atf_tc_set_md_var(tc, "descr", "This test case checks that order "
|
||||||
|
"of lease expiration is handled properly.");
|
||||||
|
}
|
||||||
|
ATF_TC_BODY(expire_order, tc)
|
||||||
|
{
|
||||||
|
struct iasubopt *iaaddr;
|
||||||
|
struct ipv6_pool *pool;
|
||||||
|
struct in6_addr addr;
|
||||||
|
int i;
|
||||||
|
struct data_string ds;
|
||||||
|
struct iasubopt *expired_iaaddr;
|
||||||
|
unsigned int attempts;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test 7: order of expiration
|
||||||
|
*/
|
||||||
|
pool = NULL;
|
||||||
|
if (ipv6_pool_allocate(&pool, 0, &addr, 64, 128, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ipv6_pool_allocate() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
for (i=10; i<100; i+=10) {
|
||||||
|
if (create_lease6(pool, &iaaddr, &attempts,
|
||||||
|
&ds, i) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: create_lease6() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (renew_lease6(pool, iaaddr) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: renew_lease6() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_dereference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (pool->num_active != (i / 10)) {
|
||||||
|
atf_tc_fail("ERROR: bad num_active %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (pool->num_active != 9) {
|
||||||
|
atf_tc_fail("ERROR: bad num_active %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
for (i=10; i<100; i+=10) {
|
||||||
|
if (expire_lease6(&expired_iaaddr,
|
||||||
|
pool, 1000) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: expire_lease6() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (expired_iaaddr == NULL) {
|
||||||
|
atf_tc_fail("ERROR: should have expired a lease %s:%d\n",
|
||||||
|
MDL);
|
||||||
|
}
|
||||||
|
if (pool->num_active != (9 - (i / 10))) {
|
||||||
|
atf_tc_fail("ERROR: bad num_active %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (expired_iaaddr->hard_lifetime_end_time != i) {
|
||||||
|
atf_tc_fail("ERROR: bad hard_lifetime_end_time %s:%d\n",
|
||||||
|
MDL);
|
||||||
|
}
|
||||||
|
if (iasubopt_dereference(&expired_iaaddr, MDL) !=
|
||||||
|
ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_dereference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (pool->num_active != 0) {
|
||||||
|
atf_tc_fail("ERROR: bad num_active %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
expired_iaaddr = NULL;
|
||||||
|
if (expire_lease6(&expired_iaaddr, pool, 1000) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: expire_lease6() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ipv6_pool_dereference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ATF_TC(small_pool);
|
||||||
|
ATF_TC_HEAD(small_pool, tc)
|
||||||
|
{
|
||||||
|
atf_tc_set_md_var(tc, "descr", "This test case checks that small pool "
|
||||||
|
"is handled properly.");
|
||||||
|
}
|
||||||
|
ATF_TC_BODY(small_pool, tc)
|
||||||
|
{
|
||||||
|
struct in6_addr addr;
|
||||||
|
struct ipv6_pool *pool;
|
||||||
|
struct iasubopt *iaaddr;
|
||||||
|
struct data_string ds;
|
||||||
|
unsigned int attempts;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test 8: small pool
|
||||||
|
*/
|
||||||
|
pool = NULL;
|
||||||
|
addr.s6_addr[14] = 0x81;
|
||||||
|
if (ipv6_pool_allocate(&pool, 0, &addr, 127, 128, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ipv6_pool_allocate() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (create_lease6(pool, &iaaddr, &attempts,
|
||||||
|
&ds, 42) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: create_lease6() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (renew_lease6(pool, iaaddr) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: renew_lease6() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_dereference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (create_lease6(pool, &iaaddr, &attempts,
|
||||||
|
&ds, 11) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: create_lease6() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (renew_lease6(pool, iaaddr) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: renew_lease6() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: iasubopt_dereference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (create_lease6(pool, &iaaddr, &attempts,
|
||||||
|
&ds, 11) != ISC_R_NORESOURCES) {
|
||||||
|
atf_tc_fail("ERROR: create_lease6() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ipv6_pool_dereference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
addr.s6_addr[14] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ATF_TC(many_pools);
|
||||||
|
ATF_TC_HEAD(many_pools, tc)
|
||||||
|
{
|
||||||
|
atf_tc_set_md_var(tc, "descr", "This test case checks that functions "
|
||||||
|
"across all pools are working correctly.");
|
||||||
|
}
|
||||||
|
ATF_TC_BODY(many_pools, tc)
|
||||||
|
{
|
||||||
|
struct in6_addr addr;
|
||||||
|
struct ipv6_pool *pool;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test 9: functions across all pools
|
||||||
|
*/
|
||||||
|
pool = NULL;
|
||||||
|
if (ipv6_pool_allocate(&pool, 0, &addr, 64, 128, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ipv6_pool_allocate() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (add_ipv6_pool(pool) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: add_ipv6_pool() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ipv6_pool_dereference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
pool = NULL;
|
||||||
|
if (find_ipv6_pool(&pool, 0, &addr) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: find_ipv6_pool() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ipv6_pool_dereference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
inet_pton(AF_INET6, "1:2:3:4:ffff:ffff:ffff:ffff", &addr);
|
||||||
|
pool = NULL;
|
||||||
|
if (find_ipv6_pool(&pool, 0, &addr) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: find_ipv6_pool() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ipv6_pool_dereference() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
inet_pton(AF_INET6, "1:2:3:5::", &addr);
|
||||||
|
pool = NULL;
|
||||||
|
if (find_ipv6_pool(&pool, 0, &addr) != ISC_R_NOTFOUND) {
|
||||||
|
atf_tc_fail("ERROR: find_ipv6_pool() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
inet_pton(AF_INET6, "1:2:3:3:ffff:ffff:ffff:ffff", &addr);
|
||||||
|
pool = NULL;
|
||||||
|
if (find_ipv6_pool(&pool, 0, &addr) != ISC_R_NOTFOUND) {
|
||||||
|
atf_tc_fail("ERROR: find_ipv6_pool() %s:%d\n", MDL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* iaid = 666;
|
||||||
|
ia_na = NULL;
|
||||||
|
if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) {
|
||||||
|
atf_tc_fail("ERROR: ia_allocate() %s:%d\n", MDL);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
{
|
||||||
|
struct in6_addr r;
|
||||||
|
struct data_string ds;
|
||||||
|
u_char data[16];
|
||||||
|
char buf[64];
|
||||||
|
int i, j;
|
||||||
|
|
||||||
|
memset(&ds, 0, sizeof(ds));
|
||||||
|
memset(data, 0xaa, sizeof(data));
|
||||||
|
ds.len = 16;
|
||||||
|
ds.data = data;
|
||||||
|
|
||||||
|
inet_pton(AF_INET6, "3ffe:501:ffff:100::", &addr);
|
||||||
|
for (i = 32; i < 42; i++)
|
||||||
|
for (j = i + 1; j < 49; j++) {
|
||||||
|
memset(&r, 0, sizeof(r));
|
||||||
|
memset(buf, 0, 64);
|
||||||
|
build_prefix6(&r, &addr, i, j, &ds);
|
||||||
|
inet_ntop(AF_INET6, &r, buf, 64);
|
||||||
|
printf("%d,%d-> %s/%d\n", i, j, buf, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ATF_TP_ADD_TCS(tp)
|
||||||
|
{
|
||||||
|
ATF_TP_ADD_TC(tp, iaaddr_basic);
|
||||||
|
ATF_TP_ADD_TC(tp, iaaddr_negative);
|
||||||
|
ATF_TP_ADD_TC(tp, ia_na_basic);
|
||||||
|
ATF_TP_ADD_TC(tp, ia_na_manyaddrs);
|
||||||
|
ATF_TP_ADD_TC(tp, ia_na_negative);
|
||||||
|
ATF_TP_ADD_TC(tp, ipv6_pool_basic);
|
||||||
|
ATF_TP_ADD_TC(tp, ipv6_pool_negative);
|
||||||
|
ATF_TP_ADD_TC(tp, expire_order);
|
||||||
|
ATF_TP_ADD_TC(tp, small_pool);
|
||||||
|
ATF_TP_ADD_TC(tp, many_pools);
|
||||||
|
|
||||||
|
return (atf_no_error());
|
||||||
|
}
|
43
server/tests/simple_unittest.c
Normal file
43
server/tests/simple_unittest.c
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
|
||||||
|
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||||
|
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||||
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||||
|
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
||||||
|
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||||
|
* PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
#include <atf-c.h>
|
||||||
|
|
||||||
|
ATF_TC(simple_test_case);
|
||||||
|
ATF_TC_HEAD(simple_test_case, tc)
|
||||||
|
{
|
||||||
|
atf_tc_set_md_var(tc, "descr", "This test case is a simple DHCP test.");
|
||||||
|
}
|
||||||
|
ATF_TC_BODY(simple_test_case, tc)
|
||||||
|
{
|
||||||
|
//ATF_CHECK(returns_a_boolean()); /* Non-fatal test. */
|
||||||
|
//ATF_REQUIRE(returns_a_boolean()); /* Fatal test. */
|
||||||
|
|
||||||
|
//ATF_CHECK_EQ(4, 2 + 2); /* Non-fatal test. */
|
||||||
|
//ATF_REQUIRE_EQ(4, 2 + 2); /* Fatal test. */
|
||||||
|
|
||||||
|
//if (!condition)
|
||||||
|
// atf_tc_fail("Condition not met!"); /* Explicit failure. */
|
||||||
|
}
|
||||||
|
|
||||||
|
ATF_TP_ADD_TCS(tp)
|
||||||
|
{
|
||||||
|
ATF_TP_ADD_TC(tp, simple_test_case);
|
||||||
|
|
||||||
|
return (atf_no_error());
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user