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