Return to mdb6_unittest.c CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / dhcp / server / tests |
1.1 ! misho 1: /* ! 2: * Copyright (C) 2007-2012 by Internet Systems Consortium, Inc. ("ISC") ! 3: * ! 4: * Permission to use, copy, modify, and distribute this software for any ! 5: * purpose with or without fee is hereby granted, provided that the above ! 6: * copyright notice and this permission notice appear in all copies. ! 7: * ! 8: * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH ! 9: * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY ! 10: * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, ! 11: * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM ! 12: * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE ! 13: * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR ! 14: * PERFORMANCE OF THIS SOFTWARE. ! 15: */ ! 16: ! 17: #include "config.h" ! 18: ! 19: #include <sys/types.h> ! 20: #include <time.h> ! 21: #include <netinet/in.h> ! 22: ! 23: #include <stdarg.h> ! 24: #include "dhcpd.h" ! 25: #include "omapip/omapip.h" ! 26: #include "omapip/hash.h" ! 27: #include <dst/md5.h> ! 28: ! 29: #include <atf-c.h> ! 30: ! 31: #include <stdlib.h> ! 32: ! 33: void build_prefix6(struct in6_addr *pref, const struct in6_addr *net_start_pref, ! 34: int pool_bits, int pref_bits, ! 35: const struct data_string *input); ! 36: ! 37: /* ! 38: * Basic iaaddr manipulation. ! 39: * Verify construction and referencing of an iaaddr. ! 40: */ ! 41: ! 42: ATF_TC(iaaddr_basic); ! 43: ATF_TC_HEAD(iaaddr_basic, tc) ! 44: { ! 45: atf_tc_set_md_var(tc, "descr", "This test case checks that basic " ! 46: "IAADDR manipulation is possible."); ! 47: } ! 48: ATF_TC_BODY(iaaddr_basic, tc) ! 49: { ! 50: struct iasubopt *iaaddr; ! 51: struct iasubopt *iaaddr_copy; ! 52: ! 53: /* and other common arguments */ ! 54: iaaddr = NULL; ! 55: iaaddr_copy = NULL; ! 56: ! 57: /* tests */ ! 58: if (iasubopt_allocate(&iaaddr, MDL) != ISC_R_SUCCESS) { ! 59: atf_tc_fail("ERROR: iasubopt_allocate() %s:%d", MDL); ! 60: } ! 61: if (iaaddr->state != FTS_FREE) { ! 62: atf_tc_fail("ERROR: bad state %s:%d", MDL); ! 63: } ! 64: if (iaaddr->heap_index != -1) { ! 65: atf_tc_fail("ERROR: bad heap_index %s:%d", MDL); ! 66: } ! 67: if (iasubopt_reference(&iaaddr_copy, iaaddr, MDL) != ISC_R_SUCCESS) { ! 68: atf_tc_fail("ERROR: iasubopt_reference() %s:%d", MDL); ! 69: } ! 70: if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) { ! 71: atf_tc_fail("ERROR: iasubopt_reference() %s:%d", MDL); ! 72: } ! 73: if (iasubopt_dereference(&iaaddr_copy, MDL) != ISC_R_SUCCESS) { ! 74: atf_tc_fail("ERROR: iasubopt_reference() %s:%d", MDL); ! 75: } ! 76: } ! 77: ! 78: /* ! 79: * Basic iaaddr sanity checks. ! 80: * Verify that the iaaddr code does some sanity checking. ! 81: */ ! 82: ! 83: ATF_TC(iaaddr_negative); ! 84: ATF_TC_HEAD(iaaddr_negative, tc) ! 85: { ! 86: atf_tc_set_md_var(tc, "descr", "This test case checks that IAADDR " ! 87: "option code can handle various negative scenarios."); ! 88: } ! 89: ATF_TC_BODY(iaaddr_negative, tc) ! 90: { ! 91: struct iasubopt *iaaddr; ! 92: struct iasubopt *iaaddr_copy; ! 93: ! 94: /* tests */ ! 95: /* bogus allocate arguments */ ! 96: if (iasubopt_allocate(NULL, MDL) != ISC_R_INVALIDARG) { ! 97: atf_tc_fail("ERROR: iasubopt_allocate() %s:%d", MDL); ! 98: } ! 99: iaaddr = (struct iasubopt *)1; ! 100: if (iasubopt_allocate(&iaaddr, MDL) != ISC_R_INVALIDARG) { ! 101: atf_tc_fail("ERROR: iasubopt_allocate() %s:%d", MDL); ! 102: } ! 103: ! 104: /* bogus reference arguments */ ! 105: iaaddr = NULL; ! 106: if (iasubopt_allocate(&iaaddr, MDL) != ISC_R_SUCCESS) { ! 107: atf_tc_fail("ERROR: iasubopt_allocate() %s:%d", MDL); ! 108: } ! 109: if (iasubopt_reference(NULL, iaaddr, MDL) != ISC_R_INVALIDARG) { ! 110: atf_tc_fail("ERROR: iasubopt_reference() %s:%d", MDL); ! 111: } ! 112: iaaddr_copy = (struct iasubopt *)1; ! 113: if (iasubopt_reference(&iaaddr_copy, iaaddr, ! 114: MDL) != ISC_R_INVALIDARG) { ! 115: atf_tc_fail("ERROR: iasubopt_reference() %s:%d", MDL); ! 116: } ! 117: iaaddr_copy = NULL; ! 118: if (iasubopt_reference(&iaaddr_copy, NULL, MDL) != ISC_R_INVALIDARG) { ! 119: atf_tc_fail("ERROR: iasubopt_reference() %s:%d", MDL); ! 120: } ! 121: if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) { ! 122: atf_tc_fail("ERROR: iasubopt_reference() %s:%d", MDL); ! 123: } ! 124: ! 125: /* bogus dereference arguments */ ! 126: if (iasubopt_dereference(NULL, MDL) != ISC_R_INVALIDARG) { ! 127: atf_tc_fail("ERROR: iasubopt_dereference() %s:%d", MDL); ! 128: } ! 129: iaaddr = NULL; ! 130: if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_INVALIDARG) { ! 131: atf_tc_fail("ERROR: iasubopt_dereference() %s:%d", MDL); ! 132: } ! 133: } ! 134: ! 135: /* ! 136: * Basic ia_na manipulation. ! 137: */ ! 138: ! 139: ATF_TC(ia_na_basic); ! 140: ATF_TC_HEAD(ia_na_basic, tc) ! 141: { ! 142: atf_tc_set_md_var(tc, "descr", "This test case checks that IA_NA code can " ! 143: "handle various basic scenarios."); ! 144: } ! 145: ATF_TC_BODY(ia_na_basic, tc) ! 146: { ! 147: uint32_t iaid; ! 148: struct ia_xx *ia_na; ! 149: struct ia_xx *ia_na_copy; ! 150: struct iasubopt *iaaddr; ! 151: ! 152: /* and other common arguments */ ! 153: iaid = 666; ! 154: ia_na = NULL; ! 155: ia_na_copy = NULL; ! 156: iaaddr = NULL; ! 157: ! 158: /* tests */ ! 159: if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) { ! 160: atf_tc_fail("ERROR: ia_allocate() %s:%d", MDL); ! 161: } ! 162: if (memcmp(ia_na->iaid_duid.data, &iaid, sizeof(iaid)) != 0) { ! 163: atf_tc_fail("ERROR: bad IAID_DUID %s:%d", MDL); ! 164: } ! 165: if (memcmp(ia_na->iaid_duid.data+sizeof(iaid), "TestDUID", 8) != 0) { ! 166: atf_tc_fail("ERROR: bad IAID_DUID %s:%d", MDL); ! 167: } ! 168: if (ia_na->num_iasubopt != 0) { ! 169: atf_tc_fail("ERROR: bad num_iasubopt %s:%d", MDL); ! 170: } ! 171: if (ia_reference(&ia_na_copy, ia_na, MDL) != ISC_R_SUCCESS) { ! 172: atf_tc_fail("ERROR: ia_reference() %s:%d", MDL); ! 173: } ! 174: if (iasubopt_allocate(&iaaddr, MDL) != ISC_R_SUCCESS) { ! 175: atf_tc_fail("ERROR: iasubopt_allocate() %s:%d", MDL); ! 176: } ! 177: if (ia_add_iasubopt(ia_na, iaaddr, MDL) != ISC_R_SUCCESS) { ! 178: atf_tc_fail("ERROR: ia_add_iasubopt() %s:%d", MDL); ! 179: } ! 180: ia_remove_iasubopt(ia_na, iaaddr, MDL); ! 181: if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) { ! 182: atf_tc_fail("ERROR: iasubopt_reference() %s:%d", MDL); ! 183: } ! 184: if (ia_dereference(&ia_na, MDL) != ISC_R_SUCCESS) { ! 185: atf_tc_fail("ERROR: ia_dereference() %s:%d", MDL); ! 186: } ! 187: if (ia_dereference(&ia_na_copy, MDL) != ISC_R_SUCCESS) { ! 188: atf_tc_fail("ERROR: ia_dereference() %s:%d", MDL); ! 189: } ! 190: } ! 191: ! 192: /* ! 193: * Lots of iaaddr in our ia_na. ! 194: * Create many iaaddrs and attach them to an ia_na ! 195: * then clean up by removing them one at a time and ! 196: * all at once by dereferencing the ia_na. ! 197: */ ! 198: ! 199: ATF_TC(ia_na_manyaddrs); ! 200: ATF_TC_HEAD(ia_na_manyaddrs, tc) ! 201: { ! 202: atf_tc_set_md_var(tc, "descr", "This test case checks that IA_NA can " ! 203: "handle lots of addresses."); ! 204: } ! 205: ATF_TC_BODY(ia_na_manyaddrs, tc) ! 206: { ! 207: uint32_t iaid; ! 208: struct ia_xx *ia_na; ! 209: struct iasubopt *iaaddr; ! 210: int i; ! 211: ! 212: /* tests */ ! 213: /* lots of iaaddr that we delete */ ! 214: iaid = 666; ! 215: ia_na = NULL; ! 216: if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) { ! 217: atf_tc_fail("ERROR: ia_allocate() %s:%d", MDL); ! 218: } ! 219: for (i=0; i<100; i++) { ! 220: iaaddr = NULL; ! 221: if (iasubopt_allocate(&iaaddr, MDL) != ISC_R_SUCCESS) { ! 222: atf_tc_fail("ERROR: iasubopt_allocate() %s:%d", MDL); ! 223: } ! 224: if (ia_add_iasubopt(ia_na, iaaddr, MDL) != ISC_R_SUCCESS) { ! 225: atf_tc_fail("ERROR: ia_add_iasubopt() %s:%d", MDL); ! 226: } ! 227: if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) { ! 228: atf_tc_fail("ERROR: iasubopt_reference() %s:%d", MDL); ! 229: } ! 230: } ! 231: ! 232: #if 0 ! 233: for (i=0; i<100; i++) { ! 234: iaaddr = ia_na->iasubopt[random() % ia_na->num_iasubopt]; ! 235: ia_remove_iasubopt(ia_na, iaaddr, MDL); ! 236: /* TODO: valgrind reports problem here: Invalid read of size 8 ! 237: * Address 0x51e6258 is 56 bytes inside a block of size 88 free'd */ ! 238: } ! 239: #endif ! 240: if (ia_dereference(&ia_na, MDL) != ISC_R_SUCCESS) { ! 241: atf_tc_fail("ERROR: ia_dereference() %s:%d", MDL); ! 242: } ! 243: ! 244: /* lots of iaaddr, let dereference cleanup */ ! 245: iaid = 666; ! 246: ia_na = NULL; ! 247: if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) { ! 248: atf_tc_fail("ERROR: ia_allocate() %s:%d", MDL); ! 249: } ! 250: for (i=0; i<100; i++) { ! 251: iaaddr = NULL; ! 252: if (iasubopt_allocate(&iaaddr, MDL) != ISC_R_SUCCESS) { ! 253: atf_tc_fail("ERROR: iasubopt_allocate() %s:%d", MDL); ! 254: } ! 255: if (ia_add_iasubopt(ia_na, iaaddr, MDL) != ISC_R_SUCCESS) { ! 256: atf_tc_fail("ERROR: ia_add_iasubopt() %s:%d", MDL); ! 257: } ! 258: if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) { ! 259: atf_tc_fail("ERROR: iasubopt_reference() %s:%d", MDL); ! 260: } ! 261: } ! 262: if (ia_dereference(&ia_na, MDL) != ISC_R_SUCCESS) { ! 263: atf_tc_fail("ERROR: ia_dereference() %s:%d", MDL); ! 264: } ! 265: } ! 266: ! 267: /* ! 268: * Basic ia_na sanity checks. ! 269: * Verify that the ia_na code does some sanity checking. ! 270: */ ! 271: ! 272: ATF_TC(ia_na_negative); ! 273: ATF_TC_HEAD(ia_na_negative, tc) ! 274: { ! 275: atf_tc_set_md_var(tc, "descr", "This test case checks that IA_NA option " ! 276: "code can handle various negative scenarios."); ! 277: } ! 278: ATF_TC_BODY(ia_na_negative, tc) ! 279: { ! 280: uint32_t iaid; ! 281: struct ia_xx *ia_na; ! 282: struct ia_xx *ia_na_copy; ! 283: ! 284: /* tests */ ! 285: /* bogus allocate arguments */ ! 286: if (ia_allocate(NULL, 123, "", 0, MDL) != ISC_R_INVALIDARG) { ! 287: atf_tc_fail("ERROR: ia_allocate() %s:%d", MDL); ! 288: } ! 289: ia_na = (struct ia_xx *)1; ! 290: if (ia_allocate(&ia_na, 456, "", 0, MDL) != ISC_R_INVALIDARG) { ! 291: atf_tc_fail("ERROR: ia_allocate() %s:%d", MDL); ! 292: } ! 293: ! 294: /* bogus reference arguments */ ! 295: iaid = 666; ! 296: ia_na = NULL; ! 297: if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) { ! 298: atf_tc_fail("ERROR: ia_allocate() %s:%d", MDL); ! 299: } ! 300: if (ia_reference(NULL, ia_na, MDL) != ISC_R_INVALIDARG) { ! 301: atf_tc_fail("ERROR: ia_reference() %s:%d", MDL); ! 302: } ! 303: ia_na_copy = (struct ia_xx *)1; ! 304: if (ia_reference(&ia_na_copy, ia_na, MDL) != ISC_R_INVALIDARG) { ! 305: atf_tc_fail("ERROR: ia_reference() %s:%d", MDL); ! 306: } ! 307: ia_na_copy = NULL; ! 308: if (ia_reference(&ia_na_copy, NULL, MDL) != ISC_R_INVALIDARG) { ! 309: atf_tc_fail("ERROR: ia_reference() %s:%d", MDL); ! 310: } ! 311: if (ia_dereference(&ia_na, MDL) != ISC_R_SUCCESS) { ! 312: atf_tc_fail("ERROR: ia_dereference() %s:%d", MDL); ! 313: } ! 314: ! 315: /* bogus dereference arguments */ ! 316: if (ia_dereference(NULL, MDL) != ISC_R_INVALIDARG) { ! 317: atf_tc_fail("ERROR: ia_dereference() %s:%d", MDL); ! 318: } ! 319: ! 320: /* bogus remove */ ! 321: iaid = 666; ! 322: ia_na = NULL; ! 323: if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) { ! 324: atf_tc_fail("ERROR: ia_allocate() %s:%d", MDL); ! 325: } ! 326: ia_remove_iasubopt(ia_na, NULL, MDL); ! 327: if (ia_dereference(&ia_na, MDL) != ISC_R_SUCCESS) { ! 328: atf_tc_fail("ERROR: ia_dereference() %s:%d", MDL); ! 329: } ! 330: } ! 331: ! 332: /* ! 333: * Basic ipv6_pool manipulation. ! 334: * Verify that basic pool operations work properly. ! 335: * The operations include creating a pool and creating, ! 336: * renewing, expiring, releasing and declining addresses. ! 337: */ ! 338: ! 339: ATF_TC(ipv6_pool_basic); ! 340: ATF_TC_HEAD(ipv6_pool_basic, tc) ! 341: { ! 342: atf_tc_set_md_var(tc, "descr", "This test case checks that IPv6 pool " ! 343: "manipulation is possible."); ! 344: } ! 345: ATF_TC_BODY(ipv6_pool_basic, tc) ! 346: { ! 347: struct iasubopt *iaaddr; ! 348: struct in6_addr addr; ! 349: struct ipv6_pool *pool; ! 350: struct ipv6_pool *pool_copy; ! 351: char addr_buf[INET6_ADDRSTRLEN]; ! 352: char *uid; ! 353: struct data_string ds; ! 354: struct iasubopt *expired_iaaddr; ! 355: unsigned int attempts; ! 356: ! 357: /* and other common arguments */ ! 358: inet_pton(AF_INET6, "1:2:3:4::", &addr); ! 359: ! 360: uid = "client0"; ! 361: memset(&ds, 0, sizeof(ds)); ! 362: ds.len = strlen(uid); ! 363: if (!buffer_allocate(&ds.buffer, ds.len, MDL)) { ! 364: atf_tc_fail("Out of memory"); ! 365: } ! 366: ds.data = ds.buffer->data; ! 367: memcpy((char *)ds.data, uid, ds.len); ! 368: ! 369: /* tests */ ! 370: /* allocate, reference */ ! 371: pool = NULL; ! 372: if (ipv6_pool_allocate(&pool, D6O_IA_NA, &addr, ! 373: 64, 128, MDL) != ISC_R_SUCCESS) { ! 374: atf_tc_fail("ERROR: ipv6_pool_allocate() %s:%d", MDL); ! 375: } ! 376: if (pool->num_active != 0) { ! 377: atf_tc_fail("ERROR: bad num_active %s:%d", MDL); ! 378: } ! 379: if (pool->bits != 64) { ! 380: atf_tc_fail("ERROR: bad bits %s:%d", MDL); ! 381: } ! 382: inet_ntop(AF_INET6, &pool->start_addr, addr_buf, sizeof(addr_buf)); ! 383: if (strcmp(inet_ntop(AF_INET6, &pool->start_addr, addr_buf, ! 384: sizeof(addr_buf)), "1:2:3:4::") != 0) { ! 385: atf_tc_fail("ERROR: bad start_addr %s:%d", MDL); ! 386: } ! 387: pool_copy = NULL; ! 388: if (ipv6_pool_reference(&pool_copy, pool, MDL) != ISC_R_SUCCESS) { ! 389: atf_tc_fail("ERROR: ipv6_pool_reference() %s:%d", MDL); ! 390: } ! 391: ! 392: /* create_lease6, renew_lease6, expire_lease6 */ ! 393: iaaddr = NULL; ! 394: if (create_lease6(pool, &iaaddr, ! 395: &attempts, &ds, 1) != ISC_R_SUCCESS) { ! 396: atf_tc_fail("ERROR: create_lease6() %s:%d", MDL); ! 397: } ! 398: if (pool->num_inactive != 1) { ! 399: atf_tc_fail("ERROR: bad num_inactive %s:%d", MDL); ! 400: } ! 401: if (renew_lease6(pool, iaaddr) != ISC_R_SUCCESS) { ! 402: atf_tc_fail("ERROR: renew_lease6() %s:%d", MDL); ! 403: } ! 404: if (pool->num_active != 1) { ! 405: atf_tc_fail("ERROR: bad num_active %s:%d", MDL); ! 406: } ! 407: expired_iaaddr = NULL; ! 408: if (expire_lease6(&expired_iaaddr, pool, 0) != ISC_R_SUCCESS) { ! 409: atf_tc_fail("ERROR: expire_lease6() %s:%d", MDL); ! 410: } ! 411: if (expired_iaaddr != NULL) { ! 412: atf_tc_fail("ERROR: should not have expired a lease %s:%d", MDL); ! 413: } ! 414: if (pool->num_active != 1) { ! 415: atf_tc_fail("ERROR: bad num_active %s:%d", MDL); ! 416: } ! 417: if (expire_lease6(&expired_iaaddr, pool, 1000) != ISC_R_SUCCESS) { ! 418: atf_tc_fail("ERROR: expire_lease6() %s:%d", MDL); ! 419: } ! 420: if (expired_iaaddr == NULL) { ! 421: atf_tc_fail("ERROR: should have expired a lease %s:%d", MDL); ! 422: } ! 423: if (iasubopt_dereference(&expired_iaaddr, MDL) != ISC_R_SUCCESS) { ! 424: atf_tc_fail("ERROR: iasubopt_dereference() %s:%d", MDL); ! 425: } ! 426: if (pool->num_active != 0) { ! 427: atf_tc_fail("ERROR: bad num_active %s:%d", MDL); ! 428: } ! 429: if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) { ! 430: atf_tc_fail("ERROR: iasubopt_dereference() %s:%d", MDL); ! 431: } ! 432: ! 433: /* release_lease6, decline_lease6 */ ! 434: if (create_lease6(pool, &iaaddr, &attempts, ! 435: &ds, 1) != ISC_R_SUCCESS) { ! 436: atf_tc_fail("ERROR: create_lease6() %s:%d", MDL); ! 437: } ! 438: if (renew_lease6(pool, iaaddr) != ISC_R_SUCCESS) { ! 439: atf_tc_fail("ERROR: renew_lease6() %s:%d", MDL); ! 440: } ! 441: if (pool->num_active != 1) { ! 442: atf_tc_fail("ERROR: bad num_active %s:%d", MDL); ! 443: } ! 444: if (release_lease6(pool, iaaddr) != ISC_R_SUCCESS) { ! 445: atf_tc_fail("ERROR: decline_lease6() %s:%d", MDL); ! 446: } ! 447: if (pool->num_active != 0) { ! 448: atf_tc_fail("ERROR: bad num_active %s:%d", MDL); ! 449: } ! 450: if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) { ! 451: atf_tc_fail("ERROR: iasubopt_dereference() %s:%d", MDL); ! 452: } ! 453: if (create_lease6(pool, &iaaddr, &attempts, ! 454: &ds, 1) != ISC_R_SUCCESS) { ! 455: atf_tc_fail("ERROR: create_lease6() %s:%d", MDL); ! 456: } ! 457: if (renew_lease6(pool, iaaddr) != ISC_R_SUCCESS) { ! 458: atf_tc_fail("ERROR: renew_lease6() %s:%d", MDL); ! 459: } ! 460: if (pool->num_active != 1) { ! 461: atf_tc_fail("ERROR: bad num_active %s:%d", MDL); ! 462: } ! 463: if (decline_lease6(pool, iaaddr) != ISC_R_SUCCESS) { ! 464: atf_tc_fail("ERROR: decline_lease6() %s:%d", MDL); ! 465: } ! 466: if (pool->num_active != 1) { ! 467: atf_tc_fail("ERROR: bad num_active %s:%d", MDL); ! 468: } ! 469: if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) { ! 470: atf_tc_fail("ERROR: iasubopt_dereference() %s:%d", MDL); ! 471: } ! 472: ! 473: /* dereference */ ! 474: if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) { ! 475: atf_tc_fail("ERROR: ipv6_pool_reference() %s:%d", MDL); ! 476: } ! 477: if (ipv6_pool_dereference(&pool_copy, MDL) != ISC_R_SUCCESS) { ! 478: atf_tc_fail("ERROR: ipv6_pool_reference() %s:%d", MDL); ! 479: } ! 480: } ! 481: ! 482: /* ! 483: * Basic ipv6_pool sanity checks. ! 484: * Verify that the ipv6_pool code does some sanity checking. ! 485: */ ! 486: ! 487: ATF_TC(ipv6_pool_negative); ! 488: ATF_TC_HEAD(ipv6_pool_negative, tc) ! 489: { ! 490: atf_tc_set_md_var(tc, "descr", "This test case checks that IPv6 pool " ! 491: "can handle negative cases."); ! 492: } ! 493: ATF_TC_BODY(ipv6_pool_negative, tc) ! 494: { ! 495: struct in6_addr addr; ! 496: struct ipv6_pool *pool; ! 497: struct ipv6_pool *pool_copy; ! 498: ! 499: /* and other common arguments */ ! 500: inet_pton(AF_INET6, "1:2:3:4::", &addr); ! 501: ! 502: /* tests */ ! 503: if (ipv6_pool_allocate(NULL, D6O_IA_NA, &addr, ! 504: 64, 128, MDL) != ISC_R_INVALIDARG) { ! 505: atf_tc_fail("ERROR: ipv6_pool_allocate() %s:%d", MDL); ! 506: } ! 507: pool = (struct ipv6_pool *)1; ! 508: if (ipv6_pool_allocate(&pool, D6O_IA_NA, &addr, ! 509: 64, 128, MDL) != ISC_R_INVALIDARG) { ! 510: atf_tc_fail("ERROR: ipv6_pool_allocate() %s:%d", MDL); ! 511: } ! 512: if (ipv6_pool_reference(NULL, pool, MDL) != ISC_R_INVALIDARG) { ! 513: atf_tc_fail("ERROR: ipv6_pool_reference() %s:%d", MDL); ! 514: } ! 515: pool_copy = (struct ipv6_pool *)1; ! 516: if (ipv6_pool_reference(&pool_copy, pool, MDL) != ISC_R_INVALIDARG) { ! 517: atf_tc_fail("ERROR: ipv6_pool_reference() %s:%d", MDL); ! 518: } ! 519: pool_copy = NULL; ! 520: if (ipv6_pool_reference(&pool_copy, NULL, MDL) != ISC_R_INVALIDARG) { ! 521: atf_tc_fail("ERROR: ipv6_pool_reference() %s:%d", MDL); ! 522: } ! 523: if (ipv6_pool_dereference(NULL, MDL) != ISC_R_INVALIDARG) { ! 524: atf_tc_fail("ERROR: ipv6_pool_dereference() %s:%d", MDL); ! 525: } ! 526: if (ipv6_pool_dereference(&pool_copy, MDL) != ISC_R_INVALIDARG) { ! 527: atf_tc_fail("ERROR: ipv6_pool_dereference() %s:%d", MDL); ! 528: } ! 529: } ! 530: ! 531: ! 532: /* ! 533: * Order of expiration. ! 534: * Add several addresses to a pool and check that ! 535: * they expire in the proper order. ! 536: */ ! 537: ! 538: ATF_TC(expire_order); ! 539: ATF_TC_HEAD(expire_order, tc) ! 540: { ! 541: atf_tc_set_md_var(tc, "descr", "This test case checks that order " ! 542: "of lease expiration is handled properly."); ! 543: } ! 544: ATF_TC_BODY(expire_order, tc) ! 545: { ! 546: struct iasubopt *iaaddr; ! 547: struct ipv6_pool *pool; ! 548: struct in6_addr addr; ! 549: int i; ! 550: char *uid; ! 551: struct data_string ds; ! 552: struct iasubopt *expired_iaaddr; ! 553: unsigned int attempts; ! 554: ! 555: /* and other common arguments */ ! 556: inet_pton(AF_INET6, "1:2:3:4::", &addr); ! 557: ! 558: uid = "client0"; ! 559: memset(&ds, 0, sizeof(ds)); ! 560: ds.len = strlen(uid); ! 561: if (!buffer_allocate(&ds.buffer, ds.len, MDL)) { ! 562: atf_tc_fail("Out of memory"); ! 563: } ! 564: ds.data = ds.buffer->data; ! 565: memcpy((char *)ds.data, uid, ds.len); ! 566: ! 567: iaaddr = NULL; ! 568: expired_iaaddr = NULL; ! 569: ! 570: /* tests */ ! 571: pool = NULL; ! 572: if (ipv6_pool_allocate(&pool, D6O_IA_NA, &addr, ! 573: 64, 128, MDL) != ISC_R_SUCCESS) { ! 574: atf_tc_fail("ERROR: ipv6_pool_allocate() %s:%d", MDL); ! 575: } ! 576: ! 577: for (i=10; i<100; i+=10) { ! 578: if (create_lease6(pool, &iaaddr, &attempts, ! 579: &ds, i) != ISC_R_SUCCESS) { ! 580: atf_tc_fail("ERROR: create_lease6() %s:%d", MDL); ! 581: } ! 582: if (renew_lease6(pool, iaaddr) != ISC_R_SUCCESS) { ! 583: atf_tc_fail("ERROR: renew_lease6() %s:%d", MDL); ! 584: } ! 585: if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) { ! 586: atf_tc_fail("ERROR: iasubopt_dereference() %s:%d", MDL); ! 587: } ! 588: if (pool->num_active != (i / 10)) { ! 589: atf_tc_fail("ERROR: bad num_active %s:%d", MDL); ! 590: } ! 591: } ! 592: if (pool->num_active != 9) { ! 593: atf_tc_fail("ERROR: bad num_active %s:%d", MDL); ! 594: } ! 595: ! 596: for (i=10; i<100; i+=10) { ! 597: if (expire_lease6(&expired_iaaddr, ! 598: pool, 1000) != ISC_R_SUCCESS) { ! 599: atf_tc_fail("ERROR: expire_lease6() %s:%d", MDL); ! 600: } ! 601: if (expired_iaaddr == NULL) { ! 602: atf_tc_fail("ERROR: should have expired a lease %s:%d", ! 603: MDL); ! 604: } ! 605: if (pool->num_active != (9 - (i / 10))) { ! 606: atf_tc_fail("ERROR: bad num_active %s:%d", MDL); ! 607: } ! 608: if (expired_iaaddr->hard_lifetime_end_time != i) { ! 609: atf_tc_fail("ERROR: bad hard_lifetime_end_time %s:%d", ! 610: MDL); ! 611: } ! 612: if (iasubopt_dereference(&expired_iaaddr, MDL) != ! 613: ISC_R_SUCCESS) { ! 614: atf_tc_fail("ERROR: iasubopt_dereference() %s:%d", MDL); ! 615: } ! 616: } ! 617: if (pool->num_active != 0) { ! 618: atf_tc_fail("ERROR: bad num_active %s:%d", MDL); ! 619: } ! 620: expired_iaaddr = NULL; ! 621: if (expire_lease6(&expired_iaaddr, pool, 1000) != ISC_R_SUCCESS) { ! 622: atf_tc_fail("ERROR: expire_lease6() %s:%d", MDL); ! 623: } ! 624: if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) { ! 625: atf_tc_fail("ERROR: ipv6_pool_dereference() %s:%d", MDL); ! 626: } ! 627: } ! 628: ! 629: /* ! 630: * Reduce the expiration period of a lease. ! 631: * This test reduces the expiration period of ! 632: * a lease to verify we process reductions ! 633: * properly. ! 634: */ ! 635: ATF_TC(expire_order_reduce); ! 636: ATF_TC_HEAD(expire_order_reduce, tc) ! 637: { ! 638: atf_tc_set_md_var(tc, "descr", "This test case checks that reducing " ! 639: "the expiration time of a lease works properly."); ! 640: } ! 641: ATF_TC_BODY(expire_order_reduce, tc) ! 642: { ! 643: struct iasubopt *iaaddr1, *iaaddr2; ! 644: struct ipv6_pool *pool; ! 645: struct in6_addr addr; ! 646: char *uid; ! 647: struct data_string ds; ! 648: struct iasubopt *expired_iaaddr; ! 649: unsigned int attempts; ! 650: ! 651: /* and other common arguments */ ! 652: inet_pton(AF_INET6, "1:2:3:4::", &addr); ! 653: ! 654: uid = "client0"; ! 655: memset(&ds, 0, sizeof(ds)); ! 656: ds.len = strlen(uid); ! 657: if (!buffer_allocate(&ds.buffer, ds.len, MDL)) { ! 658: atf_tc_fail("Out of memory"); ! 659: } ! 660: ds.data = ds.buffer->data; ! 661: memcpy((char *)ds.data, uid, ds.len); ! 662: ! 663: pool = NULL; ! 664: iaaddr1 = NULL; ! 665: iaaddr2 = NULL; ! 666: expired_iaaddr = NULL; ! 667: ! 668: /* ! 669: * Add two leases iaaddr1 with expire time of 200 ! 670: * and iaaddr2 with expire time of 300. Then update ! 671: * iaaddr2 to expire in 100 instead. This should cause ! 672: * iaaddr2 to move with the hash list. ! 673: */ ! 674: /* create pool and add iaaddr1 and iaaddr2 */ ! 675: if (ipv6_pool_allocate(&pool, D6O_IA_NA, &addr, ! 676: 64, 128, MDL) != ISC_R_SUCCESS) { ! 677: atf_tc_fail("ERROR: ipv6_pool_allocate() %s:%d", MDL); ! 678: } ! 679: if (create_lease6(pool, &iaaddr1, &attempts, &ds, 200) != ISC_R_SUCCESS) { ! 680: atf_tc_fail("ERROR: create_lease6() %s:%d", MDL); ! 681: } ! 682: if (renew_lease6(pool, iaaddr1) != ISC_R_SUCCESS) { ! 683: atf_tc_fail("ERROR: renew_lease6() %s:%d", MDL); ! 684: } ! 685: if (create_lease6(pool, &iaaddr2, &attempts, &ds, 300) != ISC_R_SUCCESS) { ! 686: atf_tc_fail("ERROR: create_lease6() %s:%d", MDL); ! 687: } ! 688: if (renew_lease6(pool, iaaddr2) != ISC_R_SUCCESS) { ! 689: atf_tc_fail("ERROR: renew_lease6() %s:%d", MDL); ! 690: } ! 691: ! 692: /* verify pool */ ! 693: if (pool->num_active != 2) { ! 694: atf_tc_fail("ERROR: bad num_active %s:%d", MDL); ! 695: } ! 696: ! 697: /* reduce lease for iaaddr2 */ ! 698: iaaddr2->soft_lifetime_end_time = 100; ! 699: if (renew_lease6(pool, iaaddr2) != ISC_R_SUCCESS) { ! 700: atf_tc_fail("ERROR: renew_lease6() %s:%d", MDL); ! 701: } ! 702: ! 703: /* expire a lease, it should be iaaddr2 with an expire time of 100 */ ! 704: if (expire_lease6(&expired_iaaddr, pool, 1000) != ISC_R_SUCCESS) { ! 705: atf_tc_fail("ERROR: expire_lease6() %s:%d", MDL); ! 706: } ! 707: if (expired_iaaddr == NULL) { ! 708: atf_tc_fail("ERROR: should have expired a lease %s:%d", MDL); ! 709: } ! 710: if (expired_iaaddr != iaaddr2) { ! 711: atf_tc_fail("Error: incorrect lease expired %s:%d", MDL); ! 712: } ! 713: if (expired_iaaddr->hard_lifetime_end_time != 100) { ! 714: atf_tc_fail("ERROR: bad hard_lifetime_end_time %s:%d", MDL); ! 715: } ! 716: if (iasubopt_dereference(&expired_iaaddr, MDL) != ISC_R_SUCCESS) { ! 717: atf_tc_fail("ERROR: iasubopt_dereference() %s:%d", MDL); ! 718: } ! 719: ! 720: /* expire a lease, it should be iaaddr1 with an expire time of 200 */ ! 721: if (expire_lease6(&expired_iaaddr, pool, 1000) != ISC_R_SUCCESS) { ! 722: atf_tc_fail("ERROR: expire_lease6() %s:%d", MDL); ! 723: } ! 724: if (expired_iaaddr == NULL) { ! 725: atf_tc_fail("ERROR: should have expired a lease %s:%d", MDL); ! 726: } ! 727: if (expired_iaaddr != iaaddr1) { ! 728: atf_tc_fail("Error: incorrect lease expired %s:%d", MDL); ! 729: } ! 730: if (expired_iaaddr->hard_lifetime_end_time != 200) { ! 731: atf_tc_fail("ERROR: bad hard_lifetime_end_time %s:%d", MDL); ! 732: } ! 733: if (iasubopt_dereference(&expired_iaaddr, MDL) != ISC_R_SUCCESS) { ! 734: atf_tc_fail("ERROR: iasubopt_dereference() %s:%d", MDL); ! 735: } ! 736: ! 737: /* cleanup */ ! 738: if (iasubopt_dereference(&iaaddr1, MDL) != ISC_R_SUCCESS) { ! 739: atf_tc_fail("ERROR: iasubopt_dereference() %s:%d", MDL); ! 740: } ! 741: if (iasubopt_dereference(&iaaddr2, MDL) != ISC_R_SUCCESS) { ! 742: atf_tc_fail("ERROR: iasubopt_dereference() %s:%d", MDL); ! 743: } ! 744: if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) { ! 745: atf_tc_fail("ERROR: ipv6_pool_dereference() %s:%d", MDL); ! 746: } ! 747: } ! 748: ! 749: /* ! 750: * Small pool. ! 751: * check that a small pool behaves properly. ! 752: */ ! 753: ! 754: ATF_TC(small_pool); ! 755: ATF_TC_HEAD(small_pool, tc) ! 756: { ! 757: atf_tc_set_md_var(tc, "descr", "This test case checks that small pool " ! 758: "is handled properly."); ! 759: } ! 760: ATF_TC_BODY(small_pool, tc) ! 761: { ! 762: struct in6_addr addr; ! 763: struct ipv6_pool *pool; ! 764: struct iasubopt *iaaddr; ! 765: char *uid; ! 766: struct data_string ds; ! 767: unsigned int attempts; ! 768: ! 769: /* and other common arguments */ ! 770: inet_pton(AF_INET6, "1:2:3:4::", &addr); ! 771: addr.s6_addr[14] = 0x81; ! 772: ! 773: uid = "client0"; ! 774: memset(&ds, 0, sizeof(ds)); ! 775: ds.len = strlen(uid); ! 776: if (!buffer_allocate(&ds.buffer, ds.len, MDL)) { ! 777: atf_tc_fail("Out of memory"); ! 778: } ! 779: ds.data = ds.buffer->data; ! 780: memcpy((char *)ds.data, uid, ds.len); ! 781: ! 782: pool = NULL; ! 783: iaaddr = NULL; ! 784: ! 785: /* tests */ ! 786: if (ipv6_pool_allocate(&pool, D6O_IA_NA, &addr, ! 787: 127, 128, MDL) != ISC_R_SUCCESS) { ! 788: atf_tc_fail("ERROR: ipv6_pool_allocate() %s:%d", MDL); ! 789: } ! 790: ! 791: if (create_lease6(pool, &iaaddr, &attempts, ! 792: &ds, 42) != ISC_R_SUCCESS) { ! 793: atf_tc_fail("ERROR: create_lease6() %s:%d", MDL); ! 794: } ! 795: if (renew_lease6(pool, iaaddr) != ISC_R_SUCCESS) { ! 796: atf_tc_fail("ERROR: renew_lease6() %s:%d", MDL); ! 797: } ! 798: if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) { ! 799: atf_tc_fail("ERROR: iasubopt_dereference() %s:%d", MDL); ! 800: } ! 801: if (create_lease6(pool, &iaaddr, &attempts, ! 802: &ds, 11) != ISC_R_SUCCESS) { ! 803: atf_tc_fail("ERROR: create_lease6() %s:%d", MDL); ! 804: } ! 805: if (renew_lease6(pool, iaaddr) != ISC_R_SUCCESS) { ! 806: atf_tc_fail("ERROR: renew_lease6() %s:%d", MDL); ! 807: } ! 808: if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) { ! 809: atf_tc_fail("ERROR: iasubopt_dereference() %s:%d", MDL); ! 810: } ! 811: if (create_lease6(pool, &iaaddr, &attempts, ! 812: &ds, 11) != ISC_R_NORESOURCES) { ! 813: atf_tc_fail("ERROR: create_lease6() %s:%d", MDL); ! 814: } ! 815: if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) { ! 816: atf_tc_fail("ERROR: ipv6_pool_dereference() %s:%d", MDL); ! 817: } ! 818: } ! 819: ! 820: /* ! 821: * Address to pool mapping. ! 822: * Verify that we find the proper pool for an address ! 823: * or don't find a pool if we don't have one for the given ! 824: * address. ! 825: */ ! 826: ATF_TC(many_pools); ! 827: ATF_TC_HEAD(many_pools, tc) ! 828: { ! 829: atf_tc_set_md_var(tc, "descr", "This test case checks that functions " ! 830: "across all pools are working correctly."); ! 831: } ! 832: ATF_TC_BODY(many_pools, tc) ! 833: { ! 834: struct in6_addr addr; ! 835: struct ipv6_pool *pool; ! 836: ! 837: /* and other common arguments */ ! 838: inet_pton(AF_INET6, "1:2:3:4::", &addr); ! 839: ! 840: /* tests */ ! 841: ! 842: pool = NULL; ! 843: if (ipv6_pool_allocate(&pool, D6O_IA_NA, &addr, ! 844: 64, 128, MDL) != ISC_R_SUCCESS) { ! 845: atf_tc_fail("ERROR: ipv6_pool_allocate() %s:%d", MDL); ! 846: } ! 847: if (add_ipv6_pool(pool) != ISC_R_SUCCESS) { ! 848: atf_tc_fail("ERROR: add_ipv6_pool() %s:%d", MDL); ! 849: } ! 850: if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) { ! 851: atf_tc_fail("ERROR: ipv6_pool_dereference() %s:%d", MDL); ! 852: } ! 853: pool = NULL; ! 854: if (find_ipv6_pool(&pool, D6O_IA_NA, &addr) != ISC_R_SUCCESS) { ! 855: atf_tc_fail("ERROR: find_ipv6_pool() %s:%d", MDL); ! 856: } ! 857: if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) { ! 858: atf_tc_fail("ERROR: ipv6_pool_dereference() %s:%d", MDL); ! 859: } ! 860: inet_pton(AF_INET6, "1:2:3:4:ffff:ffff:ffff:ffff", &addr); ! 861: pool = NULL; ! 862: if (find_ipv6_pool(&pool, D6O_IA_NA, &addr) != ISC_R_SUCCESS) { ! 863: atf_tc_fail("ERROR: find_ipv6_pool() %s:%d", MDL); ! 864: } ! 865: if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) { ! 866: atf_tc_fail("ERROR: ipv6_pool_dereference() %s:%d", MDL); ! 867: } ! 868: inet_pton(AF_INET6, "1:2:3:5::", &addr); ! 869: pool = NULL; ! 870: if (find_ipv6_pool(&pool, D6O_IA_NA, &addr) != ISC_R_NOTFOUND) { ! 871: atf_tc_fail("ERROR: find_ipv6_pool() %s:%d", MDL); ! 872: } ! 873: inet_pton(AF_INET6, "1:2:3:3:ffff:ffff:ffff:ffff", &addr); ! 874: pool = NULL; ! 875: if (find_ipv6_pool(&pool, D6O_IA_NA, &addr) != ISC_R_NOTFOUND) { ! 876: atf_tc_fail("ERROR: find_ipv6_pool() %s:%d", MDL); ! 877: } ! 878: ! 879: /* iaid = 666; ! 880: ia_na = NULL; ! 881: if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) { ! 882: atf_tc_fail("ERROR: ia_allocate() %s:%d", MDL); ! 883: }*/ ! 884: ! 885: { ! 886: struct in6_addr r; ! 887: struct data_string ds; ! 888: u_char data[16]; ! 889: char buf[64]; ! 890: int i, j; ! 891: ! 892: memset(&ds, 0, sizeof(ds)); ! 893: memset(data, 0xaa, sizeof(data)); ! 894: ds.len = 16; ! 895: ds.data = data; ! 896: ! 897: inet_pton(AF_INET6, "3ffe:501:ffff:100::", &addr); ! 898: for (i = 32; i < 42; i++) ! 899: for (j = i + 1; j < 49; j++) { ! 900: memset(&r, 0, sizeof(r)); ! 901: memset(buf, 0, 64); ! 902: build_prefix6(&r, &addr, i, j, &ds); ! 903: inet_ntop(AF_INET6, &r, buf, 64); ! 904: printf("%d,%d-> %s/%d\n", i, j, buf, j); ! 905: } ! 906: } ! 907: } ! 908: ! 909: ATF_TP_ADD_TCS(tp) ! 910: { ! 911: ATF_TP_ADD_TC(tp, iaaddr_basic); ! 912: ATF_TP_ADD_TC(tp, iaaddr_negative); ! 913: ATF_TP_ADD_TC(tp, ia_na_basic); ! 914: ATF_TP_ADD_TC(tp, ia_na_manyaddrs); ! 915: ATF_TP_ADD_TC(tp, ia_na_negative); ! 916: ATF_TP_ADD_TC(tp, ipv6_pool_basic); ! 917: ATF_TP_ADD_TC(tp, ipv6_pool_negative); ! 918: ATF_TP_ADD_TC(tp, expire_order); ! 919: ATF_TP_ADD_TC(tp, expire_order_reduce); ! 920: ATF_TP_ADD_TC(tp, small_pool); ! 921: ATF_TP_ADD_TC(tp, many_pools); ! 922: ! 923: return (atf_no_error()); ! 924: }