Sun Mar 24 23:03:07 2013 UTC ()
adjust build to 4.2.5


(christos)
diff -r1.2 -r1.3 src/external/bsd/dhcp/Makefile.inc
diff -r1.2 -r1.3 src/external/bsd/dhcp/dist/client/dhc6.c
diff -r1.2 -r1.3 src/external/bsd/dhcp/dist/client/dhclient.c
diff -r1.1.1.1 -r0 src/external/bsd/dhcp/dist/client/dhclient.conf
diff -r1.2 -r1.3 src/external/bsd/dhcp/dist/common/conflex.c
diff -r1.2 -r1.3 src/external/bsd/dhcp/dist/common/dns.c
diff -r1.2 -r1.3 src/external/bsd/dhcp/dist/common/ns_name.c
diff -r1.3 -r1.4 src/external/bsd/dhcp/dist/dst/base64.c
diff -r1.1.1.2 -r1.2 src/external/bsd/dhcp/dist/dst/dst_api.c
diff -r1.2 -r1.3 src/external/bsd/dhcp/dist/includes/dhcpd.h
diff -r1.2 -r1.3 src/external/bsd/dhcp/dist/omapip/dispatch.c
diff -r1.2 -r1.3 src/external/bsd/dhcp/dist/relay/dhcrelay.c
diff -r1.2 -r1.3 src/external/bsd/dhcp/dist/server/ddns.c
diff -r1.2 -r1.3 src/external/bsd/dhcp/dist/server/dhcpleasequery.c
diff -r1.2 -r1.3 src/external/bsd/dhcp/dist/server/dhcpv6.c
diff -r1.2 -r1.3 src/external/bsd/dhcp/dist/server/mdb6.c
diff -r1.1.1.1 -r0 src/external/bsd/dhcp/dist/server/dhcpd.conf
diff -r1.1 -r1.2 src/external/bsd/dhcp/include/config.h

cvs diff -r1.2 -r1.3 src/external/bsd/dhcp/Attic/Makefile.inc (expand / switch to unified diff)

--- src/external/bsd/dhcp/Attic/Makefile.inc 2013/03/24 22:21:21 1.2
+++ src/external/bsd/dhcp/Attic/Makefile.inc 2013/03/24 23:03:05 1.3
@@ -1,36 +1,36 @@ @@ -1,36 +1,36 @@
1# $NetBSD: Makefile.inc,v 1.2 2013/03/24 22:21:21 christos Exp $ 1# $NetBSD: Makefile.inc,v 1.3 2013/03/24 23:03:05 christos Exp $
2 2
3WARNS?= 1 # XXX -Wshadow -Wcast-qual -Wsign-compare 3WARNS?= 1 # XXX -Wshadow -Wcast-qual -Wsign-compare
4 4
5.include <bsd.own.mk> 5.include <bsd.own.mk>
6 6
7USE_FORT?= yes # network client/server 7USE_FORT?= yes # network client/server
8CWARNFLAGS.clang+= -Wno-tautological-compare \ 8CWARNFLAGS.clang+= -Wno-tautological-compare \
9 -Wno-conversion -Wno-constant-logical-operand \ 9 -Wno-conversion -Wno-constant-logical-operand \
10 -Wno-format-security 10 -Wno-format-security
11 11
12DIST:= ${.PARSEDIR}/dist 12DIST:= ${.PARSEDIR}/dist
13BIND:= ${.PARSEDIR}/../bind/dist 13BIND:= ${.PARSEDIR}/../bind/dist
14.PATH: ${DIST}/${DHCPSRCDIR} 14.PATH: ${DIST}/${DHCPSRCDIR}
15 15
16COBJDIR!=cd ${.PARSEDIR}/lib/common && ${PRINTOBJDIR} 16COBJDIR!=cd ${.PARSEDIR}/lib/common && ${PRINTOBJDIR}
17OMOBJDIR!=cd ${.PARSEDIR}/lib/omapip && ${PRINTOBJDIR} 17OMOBJDIR!=cd ${.PARSEDIR}/lib/omapip && ${PRINTOBJDIR}
18DSTOBJDIR!=cd ${.PARSEDIR}/lib/dst && ${PRINTOBJDIR} 18DSTOBJDIR!=cd ${.PARSEDIR}/lib/dst && ${PRINTOBJDIR}
19 19
20.if (${USE_INET6} != "no") 20.if (${USE_INET6} != "no")
21CPPFLAGS+= -DDHCPv6 21CPPFLAGS+= -DDHCPv6
22.endif 22.endif
23CPPFLAGS+= -DISC_PLATFORM_USETHREADS 23CPPFLAGS+= -DISC_PLATFORM_USETHREADS -DHAVE_CONFIG_H
24CPPFLAGS+= -I${DIST} -I${DIST}/includes -I${DIST}/../include 24CPPFLAGS+= -I${DIST} -I${DIST}/includes -I${DIST}/../include
25CPPFLAGS+= -I${BIND} -I${BIND}/includes -I${BIND}/../include 25CPPFLAGS+= -I${BIND} -I${BIND}/includes -I${BIND}/../include
26.for dir in isc dns 26.for dir in isc dns
27CPPFLAGS+= -I${BIND}/lib/${dir}/include 27CPPFLAGS+= -I${BIND}/lib/${dir}/include
28CPPFLAGS+= -I${BIND}/lib/${dir}/unix/include 28CPPFLAGS+= -I${BIND}/lib/${dir}/unix/include
29CPPFLAGS+= -I${BIND}/lib/${dir}/pthreads/include 29CPPFLAGS+= -I${BIND}/lib/${dir}/pthreads/include
30.endfor 30.endfor
31CPPFLAGS+= -DLOCALSTATEDIR='"/var"' 31CPPFLAGS+= -DLOCALSTATEDIR='"/var"'
32LDADD+= ${COBJDIR}/libdhcp.a 32LDADD+= ${COBJDIR}/libdhcp.a
33LDADD+= ${OMOBJDIR}/libomapi.a ${DSTOBJDIR}/libdst.a 33LDADD+= ${OMOBJDIR}/libomapi.a ${DSTOBJDIR}/libdst.a
34.if defined(PROG) && ${PROG} == "dhclient" 34.if defined(PROG) && ${PROG} == "dhclient"
35LDADD+=--static 35LDADD+=--static
36.endif 36.endif

cvs diff -r1.2 -r1.3 src/external/bsd/dhcp/dist/client/Attic/dhc6.c (expand / switch to unified diff)

--- src/external/bsd/dhcp/dist/client/Attic/dhc6.c 2013/03/24 15:53:58 1.2
+++ src/external/bsd/dhcp/dist/client/Attic/dhc6.c 2013/03/24 23:03:05 1.3
@@ -1,18 +1,19 @@ @@ -1,18 +1,19 @@
1/* $NetBSD: dhc6.c,v 1.2 2013/03/24 15:53:58 christos Exp $ */ 1/* $NetBSD: dhc6.c,v 1.3 2013/03/24 23:03:05 christos Exp $ */
2 2
3/* dhc6.c - DHCPv6 client routines. */ 3/* dhc6.c - DHCPv6 client routines. */
4 4
5/* 5/*
 6 * Copyright (c) 2012 by Internet Systems Consortium, Inc. ("ISC")
6 * Copyright (c) 2006-2010 by Internet Systems Consortium, Inc. ("ISC") 7 * Copyright (c) 2006-2010 by Internet Systems Consortium, Inc. ("ISC")
7 * 8 *
8 * Permission to use, copy, modify, and distribute this software for any 9 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above 10 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies. 11 * copyright notice and this permission notice appear in all copies.
11 * 12 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 13 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
18 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -100,26 +101,27 @@ static void start_bound(struct client_st @@ -100,26 +101,27 @@ static void start_bound(struct client_st
100static void start_informed(struct client_state *client); 101static void start_informed(struct client_state *client);
101void informed_handler(struct packet *packet, struct client_state *client); 102void informed_handler(struct packet *packet, struct client_state *client);
102void bound_handler(struct packet *packet, struct client_state *client); 103void bound_handler(struct packet *packet, struct client_state *client);
103void start_renew6(void *input); 104void start_renew6(void *input);
104void start_rebind6(void *input); 105void start_rebind6(void *input);
105void do_depref(void *input); 106void do_depref(void *input);
106void do_expire(void *input); 107void do_expire(void *input);
107static void make_client6_options(struct client_state *client, 108static void make_client6_options(struct client_state *client,
108 struct option_state **op, 109 struct option_state **op,
109 struct dhc6_lease *lease, u_int8_t message); 110 struct dhc6_lease *lease, u_int8_t message);
110static void script_write_params6(struct client_state *client, 111static void script_write_params6(struct client_state *client,
111 const char *prefix, 112 const char *prefix,
112 struct option_state *options); 113 struct option_state *options);
 114static void script_write_requested6(struct client_state *client);
113static isc_boolean_t active_prefix(struct client_state *client); 115static isc_boolean_t active_prefix(struct client_state *client);
114 116
115static int check_timing6(struct client_state *client, u_int8_t msg_type,  117static int check_timing6(struct client_state *client, u_int8_t msg_type,
116 char *msg_str, struct dhc6_lease *lease, 118 char *msg_str, struct dhc6_lease *lease,
117 struct data_string *ds); 119 struct data_string *ds);
118 120
119extern int onetry; 121extern int onetry;
120extern int stateless; 122extern int stateless;
121 123
122/* 124/*
123 * The "best" default DUID, since we cannot predict any information 125 * The "best" default DUID, since we cannot predict any information
124 * about the system (such as whether or not the hardware addresses are 126 * about the system (such as whether or not the hardware addresses are
125 * integrated into the motherboard or similar), is the "LLT", link local 127 * integrated into the motherboard or similar), is the "LLT", link local
@@ -205,28 +207,30 @@ dhcpv6_client_assignments(void) @@ -205,28 +207,30 @@ dhcpv6_client_assignments(void)
205 } 207 }
206 208
207 if (remote_port == 0) { 209 if (remote_port == 0) {
208 ent = getservbyname("dhcpv6-server", "udp"); 210 ent = getservbyname("dhcpv6-server", "udp");
209 if (ent == NULL) 211 if (ent == NULL)
210 remote_port = htons(547); 212 remote_port = htons(547);
211 else 213 else
212 remote_port = ent->s_port; 214 remote_port = ent->s_port;
213 } 215 }
214 216
215 memset(&DHCPv6DestAddr, 0, sizeof(DHCPv6DestAddr)); 217 memset(&DHCPv6DestAddr, 0, sizeof(DHCPv6DestAddr));
216 DHCPv6DestAddr.sin6_family = AF_INET6; 218 DHCPv6DestAddr.sin6_family = AF_INET6;
217 DHCPv6DestAddr.sin6_port = remote_port; 219 DHCPv6DestAddr.sin6_port = remote_port;
218 inet_pton(AF_INET6, All_DHCP_Relay_Agents_and_Servers, 220 if (inet_pton(AF_INET6, All_DHCP_Relay_Agents_and_Servers,
219 &DHCPv6DestAddr.sin6_addr); 221 &DHCPv6DestAddr.sin6_addr) <= 0) {
 222 log_fatal("Bad address %s", All_DHCP_Relay_Agents_and_Servers);
 223 }
220 224
221 code = D6O_CLIENTID; 225 code = D6O_CLIENTID;
222 if (!option_code_hash_lookup(&clientid_option, 226 if (!option_code_hash_lookup(&clientid_option,
223 dhcpv6_universe.code_hash, &code, 0, MDL)) 227 dhcpv6_universe.code_hash, &code, 0, MDL))
224 log_fatal("Unable to find the CLIENTID option definition."); 228 log_fatal("Unable to find the CLIENTID option definition.");
225 229
226 code = D6O_ELAPSED_TIME; 230 code = D6O_ELAPSED_TIME;
227 if (!option_code_hash_lookup(&elapsed_option, 231 if (!option_code_hash_lookup(&elapsed_option,
228 dhcpv6_universe.code_hash, &code, 0, MDL)) 232 dhcpv6_universe.code_hash, &code, 0, MDL))
229 log_fatal("Unable to find the ELAPSED_TIME option definition."); 233 log_fatal("Unable to find the ELAPSED_TIME option definition.");
230 234
231 code = D6O_IA_NA; 235 code = D6O_IA_NA;
232 if (!option_code_hash_lookup(&ia_na_option, dhcpv6_universe.code_hash, 236 if (!option_code_hash_lookup(&ia_na_option, dhcpv6_universe.code_hash,
@@ -647,27 +651,28 @@ dhc6_leaseify(struct packet *packet) @@ -647,27 +651,28 @@ dhc6_leaseify(struct packet *packet)
647 lease->options) != ISC_R_SUCCESS) { 651 lease->options) != ISC_R_SUCCESS) {
648 /* Error conditions are logged by the caller. */ 652 /* Error conditions are logged by the caller. */
649 dhc6_lease_destroy(&lease, MDL); 653 dhc6_lease_destroy(&lease, MDL);
650 return NULL; 654 return NULL;
651 } 655 }
652 656
653 /* 657 /*
654 * This is last because in the future we may want to make a different 658 * This is last because in the future we may want to make a different
655 * key based upon additional information from the packet (we may need 659 * key based upon additional information from the packet (we may need
656 * to allow multiple leases in one client state per server, but we're 660 * to allow multiple leases in one client state per server, but we're
657 * not sure based on what additional keys now). 661 * not sure based on what additional keys now).
658 */ 662 */
659 oc = lookup_option(&dhcpv6_universe, packet->options, D6O_SERVERID); 663 oc = lookup_option(&dhcpv6_universe, packet->options, D6O_SERVERID);
660 if (!evaluate_option_cache(&lease->server_id, packet, NULL, NULL, 664 if ((oc == NULL) ||
 665 !evaluate_option_cache(&lease->server_id, packet, NULL, NULL,
661 lease->options, NULL, &global_scope, 666 lease->options, NULL, &global_scope,
662 oc, MDL) || 667 oc, MDL) ||
663 lease->server_id.len == 0) { 668 lease->server_id.len == 0) {
664 /* This should be impossible due to validation checks earlier. 669 /* This should be impossible due to validation checks earlier.
665 */ 670 */
666 log_error("Invalid SERVERID option cache."); 671 log_error("Invalid SERVERID option cache.");
667 dhc6_lease_destroy(&lease, MDL); 672 dhc6_lease_destroy(&lease, MDL);
668 return NULL; 673 return NULL;
669 } else { 674 } else {
670 log_debug("RCV: X-- Server ID: %s", 675 log_debug("RCV: X-- Server ID: %s",
671 print_hex_1(lease->server_id.len, 676 print_hex_1(lease->server_id.len,
672 lease->server_id.data, 52)); 677 lease->server_id.data, 52));
673 } 678 }
@@ -4015,27 +4020,27 @@ dhc6_check_times(struct client_state *cl @@ -4015,27 +4020,27 @@ dhc6_check_times(struct client_state *cl
4015 tmp = ia->starts + use_expire; 4020 tmp = ia->starts + use_expire;
4016 } else if (ia->renew == 0xffffffff) 4021 } else if (ia->renew == 0xffffffff)
4017 tmp = MAX_TIME; 4022 tmp = MAX_TIME;
4018 else 4023 else
4019 tmp = ia->starts + ia->renew; 4024 tmp = ia->starts + ia->renew;
4020 4025
4021 if (tmp < renew) 4026 if (tmp < renew)
4022 renew = tmp; 4027 renew = tmp;
4023 4028
4024 if (ia->rebind == 0) { 4029 if (ia->rebind == 0) {
4025 /* Set rebind to 3/4 expiration interval. */ 4030 /* Set rebind to 3/4 expiration interval. */
4026 tmp = ia->starts; 4031 tmp = ia->starts;
4027 tmp += use_expire + (use_expire / 2); 4032 tmp += use_expire + (use_expire / 2);
4028 } else if (ia->renew == 0xffffffff) 4033 } else if (ia->rebind == 0xffffffff)
4029 tmp = MAX_TIME; 4034 tmp = MAX_TIME;
4030 else 4035 else
4031 tmp = ia->starts + ia->rebind; 4036 tmp = ia->starts + ia->rebind;
4032 4037
4033 if (tmp < rebind) 4038 if (tmp < rebind)
4034 rebind = tmp; 4039 rebind = tmp;
4035 } 4040 }
4036 4041
4037 /* 4042 /*
4038 * Return expiration ranges to EPOCH relative for event 4043 * Return expiration ranges to EPOCH relative for event
4039 * scheduling (add_timeout()). 4044 * scheduling (add_timeout()).
4040 */ 4045 */
4041 this_ia_hi_expire += ia->starts; 4046 this_ia_hi_expire += ia->starts;
@@ -4327,58 +4332,61 @@ start_bound(struct client_state *client) @@ -4327,58 +4332,61 @@ start_bound(struct client_state *client)
4327 if ((oldaddr == NULL) && (ia->ia_type == D6O_IA_NA)) 4332 if ((oldaddr == NULL) && (ia->ia_type == D6O_IA_NA))
4328 dhclient_schedule_updates(client, 4333 dhclient_schedule_updates(client,
4329 &addr->address, 4334 &addr->address,
4330 dns_update_offset++); 4335 dns_update_offset++);
4331#endif 4336#endif
4332 4337
4333 /* Shell out to setup the new binding. */ 4338 /* Shell out to setup the new binding. */
4334 script_init(client, reason, NULL); 4339 script_init(client, reason, NULL);
4335 4340
4336 if (old != NULL) 4341 if (old != NULL)
4337 dhc6_marshall_values("old_", client, old, 4342 dhc6_marshall_values("old_", client, old,
4338 oldia, oldaddr); 4343 oldia, oldaddr);
4339 dhc6_marshall_values("new_", client, lease, ia, addr); 4344 dhc6_marshall_values("new_", client, lease, ia, addr);
 4345 script_write_requested6(client);
4340 4346
4341 script_go(client); 4347 script_go(client);
4342 } 4348 }
4343 4349
4344 /* XXX: maybe we should loop on the old values instead? */ 4350 /* XXX: maybe we should loop on the old values instead? */
4345 if (ia->addrs == NULL) { 4351 if (ia->addrs == NULL) {
4346 script_init(client, reason, NULL); 4352 script_init(client, reason, NULL);
4347 4353
4348 if (old != NULL) 4354 if (old != NULL)
4349 dhc6_marshall_values("old_", client, old, 4355 dhc6_marshall_values("old_", client, old,
4350 oldia, 4356 oldia,
4351 oldia != NULL ? 4357 oldia != NULL ?
4352 oldia->addrs : NULL); 4358 oldia->addrs : NULL);
4353 4359
4354 dhc6_marshall_values("new_", client, lease, ia, 4360 dhc6_marshall_values("new_", client, lease, ia,
4355 NULL); 4361 NULL);
 4362 script_write_requested6(client);
4356 4363
4357 script_go(client); 4364 script_go(client);
4358 } 4365 }
4359 } 4366 }
4360 4367
4361 /* XXX: maybe we should loop on the old values instead? */ 4368 /* XXX: maybe we should loop on the old values instead? */
4362 if (lease->bindings == NULL) { 4369 if (lease->bindings == NULL) {
4363 script_init(client, reason, NULL); 4370 script_init(client, reason, NULL);
4364 4371
4365 if (old != NULL) 4372 if (old != NULL)
4366 dhc6_marshall_values("old_", client, old, 4373 dhc6_marshall_values("old_", client, old,
4367 old->bindings, 4374 old->bindings,
4368 (old->bindings != NULL) ? 4375 (old->bindings != NULL) ?
4369 old->bindings->addrs : NULL); 4376 old->bindings->addrs : NULL);
4370 4377
4371 dhc6_marshall_values("new_", client, lease, NULL, NULL); 4378 dhc6_marshall_values("new_", client, lease, NULL, NULL);
 4379 script_write_requested6(client);
4372 4380
4373 script_go(client); 4381 script_go(client);
4374 } 4382 }
4375 4383
4376 go_daemon(); 4384 go_daemon();
4377 4385
4378 if (client->old_lease != NULL) { 4386 if (client->old_lease != NULL) {
4379 dhc6_lease_destroy(&client->old_lease, MDL); 4387 dhc6_lease_destroy(&client->old_lease, MDL);
4380 client->old_lease = NULL; 4388 client->old_lease = NULL;
4381 } 4389 }
4382 4390
4383 /* Schedule events. */ 4391 /* Schedule events. */
4384 dhc6_check_times(client); 4392 dhc6_check_times(client);
@@ -4637,26 +4645,27 @@ do_depref(void *input) @@ -4637,26 +4645,27 @@ do_depref(void *input)
4637 lease = client->active_lease; 4645 lease = client->active_lease;
4638 if (lease == NULL) 4646 if (lease == NULL)
4639 return; 4647 return;
4640 4648
4641 for (ia = lease->bindings ; ia != NULL ; ia = ia->next) { 4649 for (ia = lease->bindings ; ia != NULL ; ia = ia->next) {
4642 for (addr = ia->addrs ; addr != NULL ; addr = addr->next) { 4650 for (addr = ia->addrs ; addr != NULL ; addr = addr->next) {
4643 if (addr->flags & DHC6_ADDR_DEPREFFED) 4651 if (addr->flags & DHC6_ADDR_DEPREFFED)
4644 continue; 4652 continue;
4645 4653
4646 if (addr->starts + addr->preferred_life <= cur_time) { 4654 if (addr->starts + addr->preferred_life <= cur_time) {
4647 script_init(client, "DEPREF6", NULL); 4655 script_init(client, "DEPREF6", NULL);
4648 dhc6_marshall_values("cur_", client, lease, 4656 dhc6_marshall_values("cur_", client, lease,
4649 ia, addr); 4657 ia, addr);
 4658 script_write_requested6(client);
4650 script_go(client); 4659 script_go(client);
4651 4660
4652 addr->flags |= DHC6_ADDR_DEPREFFED; 4661 addr->flags |= DHC6_ADDR_DEPREFFED;
4653 4662
4654 if (ia->ia_type != D6O_IA_PD) 4663 if (ia->ia_type != D6O_IA_PD)
4655 log_info("PRC: Address %s depreferred.", 4664 log_info("PRC: Address %s depreferred.",
4656 piaddr(addr->address)); 4665 piaddr(addr->address));
4657 else 4666 else
4658 log_info("PRC: Prefix %s/%u depreferred.", 4667 log_info("PRC: Prefix %s/%u depreferred.",
4659 piaddr(addr->address), 4668 piaddr(addr->address),
4660 (unsigned) addr->plen); 4669 (unsigned) addr->plen);
4661 4670
4662#if defined (NSUPDATE) 4671#if defined (NSUPDATE)
@@ -4690,26 +4699,27 @@ do_expire(void *input) @@ -4690,26 +4699,27 @@ do_expire(void *input)
4690 lease = client->active_lease; 4699 lease = client->active_lease;
4691 if (lease == NULL) 4700 if (lease == NULL)
4692 return; 4701 return;
4693 4702
4694 for (ia = lease->bindings ; ia != NULL ; ia = ia->next) { 4703 for (ia = lease->bindings ; ia != NULL ; ia = ia->next) {
4695 for (addr = ia->addrs ; addr != NULL ; addr = addr->next) { 4704 for (addr = ia->addrs ; addr != NULL ; addr = addr->next) {
4696 if (addr->flags & DHC6_ADDR_EXPIRED) 4705 if (addr->flags & DHC6_ADDR_EXPIRED)
4697 continue; 4706 continue;
4698 4707
4699 if (addr->starts + addr->max_life <= cur_time) { 4708 if (addr->starts + addr->max_life <= cur_time) {
4700 script_init(client, "EXPIRE6", NULL); 4709 script_init(client, "EXPIRE6", NULL);
4701 dhc6_marshall_values("old_", client, lease, 4710 dhc6_marshall_values("old_", client, lease,
4702 ia, addr); 4711 ia, addr);
 4712 script_write_requested6(client);
4703 script_go(client); 4713 script_go(client);
4704 4714
4705 addr->flags |= DHC6_ADDR_EXPIRED; 4715 addr->flags |= DHC6_ADDR_EXPIRED;
4706 4716
4707 if (ia->ia_type != D6O_IA_PD) 4717 if (ia->ia_type != D6O_IA_PD)
4708 log_info("PRC: Address %s expired.", 4718 log_info("PRC: Address %s expired.",
4709 piaddr(addr->address)); 4719 piaddr(addr->address));
4710 else 4720 else
4711 log_info("PRC: Prefix %s/%u expired.", 4721 log_info("PRC: Prefix %s/%u expired.",
4712 piaddr(addr->address), 4722 piaddr(addr->address),
4713 (unsigned) addr->plen); 4723 (unsigned) addr->plen);
4714 4724
4715#if defined (NSUPDATE) 4725#if defined (NSUPDATE)
@@ -4754,41 +4764,43 @@ do_expire(void *input) @@ -4754,41 +4764,43 @@ do_expire(void *input)
4754 * Stateless is a special case. 4764 * Stateless is a special case.
4755 */ 4765 */
4756void 4766void
4757unconfigure6(struct client_state *client, const char *reason) 4767unconfigure6(struct client_state *client, const char *reason)
4758{ 4768{
4759 struct dhc6_ia *ia; 4769 struct dhc6_ia *ia;
4760 struct dhc6_addr *addr; 4770 struct dhc6_addr *addr;
4761 4771
4762 if (stateless) { 4772 if (stateless) {
4763 script_init(client, reason, NULL); 4773 script_init(client, reason, NULL);
4764 if (client->active_lease != NULL) 4774 if (client->active_lease != NULL)
4765 script_write_params6(client, "old_", 4775 script_write_params6(client, "old_",
4766 client->active_lease->options); 4776 client->active_lease->options);
 4777 script_write_requested6(client);
4767 script_go(client); 4778 script_go(client);
4768 return; 4779 return;
4769 } 4780 }
4770 4781
4771 if (client->active_lease == NULL) 4782 if (client->active_lease == NULL)
4772 return; 4783 return;
4773 4784
4774 for (ia = client->active_lease->bindings ; ia != NULL ; ia = ia->next) { 4785 for (ia = client->active_lease->bindings ; ia != NULL ; ia = ia->next) {
4775 if (ia->ia_type == D6O_IA_TA) 4786 if (ia->ia_type == D6O_IA_TA)
4776 continue; 4787 continue;
4777 4788
4778 for (addr = ia->addrs ; addr != NULL ; addr = addr->next) { 4789 for (addr = ia->addrs ; addr != NULL ; addr = addr->next) {
4779 script_init(client, reason, NULL); 4790 script_init(client, reason, NULL);
4780 dhc6_marshall_values("old_", client, 4791 dhc6_marshall_values("old_", client,
4781 client->active_lease, ia, addr); 4792 client->active_lease, ia, addr);
 4793 script_write_requested6(client);
4782 script_go(client); 4794 script_go(client);
4783 4795
4784#if defined (NSUPDATE) 4796#if defined (NSUPDATE)
4785 if ((ia->ia_type == D6O_IA_NA) && 4797 if ((ia->ia_type == D6O_IA_NA) &&
4786 client->config->do_forward_update) 4798 client->config->do_forward_update)
4787 client_dns_remove(client, &addr->address); 4799 client_dns_remove(client, &addr->address);
4788#endif 4800#endif
4789 } 4801 }
4790 } 4802 }
4791} 4803}
4792 4804
4793static void 4805static void
4794refresh_info_request6(void *input) 4806refresh_info_request6(void *input)
@@ -4862,26 +4874,27 @@ static void @@ -4862,26 +4874,27 @@ static void
4862start_informed(struct client_state *client) 4874start_informed(struct client_state *client)
4863{ 4875{
4864 client->v6_handler = informed_handler; 4876 client->v6_handler = informed_handler;
4865 4877
4866 log_debug("PRC: Done."); 4878 log_debug("PRC: Done.");
4867 4879
4868 client->state = S_BOUND; 4880 client->state = S_BOUND;
4869 4881
4870 script_init(client, "RENEW6", NULL); 4882 script_init(client, "RENEW6", NULL);
4871 if (client->old_lease != NULL) 4883 if (client->old_lease != NULL)
4872 script_write_params6(client, "old_", 4884 script_write_params6(client, "old_",
4873 client->old_lease->options); 4885 client->old_lease->options);
4874 script_write_params6(client, "new_", client->active_lease->options); 4886 script_write_params6(client, "new_", client->active_lease->options);
 4887 script_write_requested6(client);
4875 script_go(client); 4888 script_go(client);
4876 4889
4877 go_daemon(); 4890 go_daemon();
4878 4891
4879 if (client->old_lease != NULL) { 4892 if (client->old_lease != NULL) {
4880 dhc6_lease_destroy(&client->old_lease, MDL); 4893 dhc6_lease_destroy(&client->old_lease, MDL);
4881 client->old_lease = NULL; 4894 client->old_lease = NULL;
4882 } 4895 }
4883 4896
4884 /* Schedule events. */ 4897 /* Schedule events. */
4885 dhc6_check_irt(client); 4898 dhc6_check_irt(client);
4886} 4899}
4887 4900
@@ -5089,26 +5102,52 @@ script_write_params6(struct client_state @@ -5089,26 +5102,52 @@ script_write_params6(struct client_state
5089 return; 5102 return;
5090 5103
5091 es.client = client; 5104 es.client = client;
5092 es.prefix = prefix; 5105 es.prefix = prefix;
5093 5106
5094 for (i = 0 ; i < options->universe_count ; i++) { 5107 for (i = 0 ; i < options->universe_count ; i++) {
5095 option_space_foreach(NULL, NULL, client, NULL, options, 5108 option_space_foreach(NULL, NULL, client, NULL, options,
5096 &global_scope, universes[i], &es, 5109 &global_scope, universes[i], &es,
5097 client_option_envadd); 5110 client_option_envadd);
5098 } 5111 }
5099} 5112}
5100 5113
5101/* 5114/*
 5115 * A clone of the DHCPv4 routine.
 5116 * Write out the environment variables for the objects that the
 5117 * client requested. If the object was requested the variable will be:
 5118 * requested_<option_name>=1
 5119 * If it wasn't requested there won't be a variable.
 5120 */
 5121static void script_write_requested6(client)
 5122 struct client_state *client;
 5123{
 5124 int i;
 5125 struct option **req;
 5126 char name[256];
 5127 req = client->config->requested_options;
 5128
 5129 if (req == NULL)
 5130 return;
 5131
 5132 for (i = 0 ; req[i] != NULL ; i++) {
 5133 if ((req[i]->universe == &dhcpv6_universe) &&
 5134 dhcp_option_ev_name (name, sizeof(name), req[i])) {
 5135 client_envadd(client, "requested_", name, "%d", 1);
 5136 }
 5137 }
 5138}
 5139
 5140/*
5102 * Check if there is something not fully defined in the active lease. 5141 * Check if there is something not fully defined in the active lease.
5103 */ 5142 */
5104static isc_boolean_t 5143static isc_boolean_t
5105active_prefix(struct client_state *client) 5144active_prefix(struct client_state *client)
5106{ 5145{
5107 struct dhc6_lease *lease; 5146 struct dhc6_lease *lease;
5108 struct dhc6_ia *ia; 5147 struct dhc6_ia *ia;
5109 struct dhc6_addr *pref; 5148 struct dhc6_addr *pref;
5110 char zeros[16]; 5149 char zeros[16];
5111 5150
5112 lease = client->active_lease; 5151 lease = client->active_lease;
5113 if (lease == NULL) 5152 if (lease == NULL)
5114 return ISC_FALSE; 5153 return ISC_FALSE;

cvs diff -r1.2 -r1.3 src/external/bsd/dhcp/dist/client/Attic/dhclient.c (expand / switch to unified diff)

--- src/external/bsd/dhcp/dist/client/Attic/dhclient.c 2013/03/24 15:53:58 1.2
+++ src/external/bsd/dhcp/dist/client/Attic/dhclient.c 2013/03/24 23:03:05 1.3
@@ -1,21 +1,21 @@ @@ -1,21 +1,21 @@
1/* $NetBSD: dhclient.c,v 1.2 2013/03/24 15:53:58 christos Exp $ */ 1/* $NetBSD: dhclient.c,v 1.3 2013/03/24 23:03:05 christos Exp $ */
2 2
3/* dhclient.c 3/* dhclient.c
4 4
5 DHCP Client. */ 5 DHCP Client. */
6 6
7/* 7/*
8 * Copyright (c) 2004-2011 by Internet Systems Consortium, Inc. ("ISC") 8 * Copyright (c) 2004-2013 by Internet Systems Consortium, Inc. ("ISC")
9 * Copyright (c) 1995-2003 by Internet Software Consortium 9 * Copyright (c) 1995-2003 by Internet Software Consortium
10 * 10 *
11 * Permission to use, copy, modify, and distribute this software for any 11 * Permission to use, copy, modify, and distribute this software for any
12 * purpose with or without fee is hereby granted, provided that the above 12 * purpose with or without fee is hereby granted, provided that the above
13 * copyright notice and this permission notice appear in all copies. 13 * copyright notice and this permission notice appear in all copies.
14 * 14 *
15 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 15 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
16 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 16 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 17 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
18 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 18 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 20 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 21 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -60,27 +60,27 @@ int interfaces_requested = 0; @@ -60,27 +60,27 @@ int interfaces_requested = 0;
60struct iaddr iaddr_broadcast = { 4, { 255, 255, 255, 255 } }; 60struct iaddr iaddr_broadcast = { 4, { 255, 255, 255, 255 } };
61struct iaddr iaddr_any = { 4, { 0, 0, 0, 0 } }; 61struct iaddr iaddr_any = { 4, { 0, 0, 0, 0 } };
62struct in_addr inaddr_any; 62struct in_addr inaddr_any;
63struct sockaddr_in sockaddr_broadcast; 63struct sockaddr_in sockaddr_broadcast;
64struct in_addr giaddr; 64struct in_addr giaddr;
65struct data_string default_duid; 65struct data_string default_duid;
66int duid_type = 0; 66int duid_type = 0;
67 67
68/* ASSERT_STATE() does nothing now; it used to be 68/* ASSERT_STATE() does nothing now; it used to be
69 assert (state_is == state_shouldbe). */ 69 assert (state_is == state_shouldbe). */
70#define ASSERT_STATE(state_is, state_shouldbe) {} 70#define ASSERT_STATE(state_is, state_shouldbe) {}
71 71
72static const char copyright[] = 72static const char copyright[] =
73"Copyright 2004-2011 Internet Systems Consortium."; 73"Copyright 2004-2013 Internet Systems Consortium.";
74static const char arr [] = "All rights reserved."; 74static const char arr [] = "All rights reserved.";
75static const char message [] = "Internet Systems Consortium DHCP Client"; 75static const char message [] = "Internet Systems Consortium DHCP Client";
76static const char url [] =  76static const char url [] =
77"For info, please visit https://www.isc.org/software/dhcp/"; 77"For info, please visit https://www.isc.org/software/dhcp/";
78 78
79u_int16_t local_port = 0; 79u_int16_t local_port = 0;
80u_int16_t remote_port = 0; 80u_int16_t remote_port = 0;
81int no_daemon = 0; 81int no_daemon = 0;
82struct string_list *client_env = NULL; 82struct string_list *client_env = NULL;
83int client_env_count = 0; 83int client_env_count = 0;
84int onetry = 0; 84int onetry = 0;
85int quiet = 1; 85int quiet = 1;
86int nowait = 0; 86int nowait = 0;
@@ -1197,26 +1197,27 @@ void bind_lease (client) @@ -1197,26 +1197,27 @@ void bind_lease (client)
1197 client -> new -> medium = client -> medium; 1197 client -> new -> medium = client -> medium;
1198 1198
1199 /* Run the client script with the new parameters. */ 1199 /* Run the client script with the new parameters. */
1200 script_init (client, (client -> state == S_REQUESTING 1200 script_init (client, (client -> state == S_REQUESTING
1201 ? "BOUND" 1201 ? "BOUND"
1202 : (client -> state == S_RENEWING 1202 : (client -> state == S_RENEWING
1203 ? "RENEW" 1203 ? "RENEW"
1204 : (client -> state == S_REBOOTING 1204 : (client -> state == S_REBOOTING
1205 ? "REBOOT" : "REBIND"))), 1205 ? "REBOOT" : "REBIND"))),
1206 client -> new -> medium); 1206 client -> new -> medium);
1207 if (client -> active && client -> state != S_REBOOTING) 1207 if (client -> active && client -> state != S_REBOOTING)
1208 script_write_params (client, "old_", client -> active); 1208 script_write_params (client, "old_", client -> active);
1209 script_write_params (client, "new_", client -> new); 1209 script_write_params (client, "new_", client -> new);
 1210 script_write_requested(client);
1210 if (client -> alias) 1211 if (client -> alias)
1211 script_write_params (client, "alias_", client -> alias); 1212 script_write_params (client, "alias_", client -> alias);
1212 1213
1213 /* If the BOUND/RENEW code detects another machine using the 1214 /* If the BOUND/RENEW code detects another machine using the
1214 offered address, it exits nonzero. We need to send a 1215 offered address, it exits nonzero. We need to send a
1215 DHCPDECLINE and toss the lease. */ 1216 DHCPDECLINE and toss the lease. */
1216 if (script_go (client)) { 1217 if (script_go (client)) {
1217 make_decline (client, client -> new); 1218 make_decline (client, client -> new);
1218 send_decline (client); 1219 send_decline (client);
1219 destroy_client_lease (client -> new); 1220 destroy_client_lease (client -> new);
1220 client -> new = (struct client_lease *)0; 1221 client -> new = (struct client_lease *)0;
1221 state_init (client); 1222 state_init (client);
1222 return; 1223 return;
@@ -1303,26 +1304,27 @@ void state_stop (cpp) @@ -1303,26 +1304,27 @@ void state_stop (cpp)
1303{ 1304{
1304 struct client_state *client = cpp; 1305 struct client_state *client = cpp;
1305 1306
1306 /* Cancel all timeouts. */ 1307 /* Cancel all timeouts. */
1307 cancel_timeout(state_selecting, client); 1308 cancel_timeout(state_selecting, client);
1308 cancel_timeout(send_discover, client); 1309 cancel_timeout(send_discover, client);
1309 cancel_timeout(send_request, client); 1310 cancel_timeout(send_request, client);
1310 cancel_timeout(state_bound, client); 1311 cancel_timeout(state_bound, client);
1311 1312
1312 /* If we have an address, unconfigure it. */ 1313 /* If we have an address, unconfigure it. */
1313 if (client->active) { 1314 if (client->active) {
1314 script_init(client, "STOP", client->active->medium); 1315 script_init(client, "STOP", client->active->medium);
1315 script_write_params(client, "old_", client->active); 1316 script_write_params(client, "old_", client->active);
 1317 script_write_requested(client);
1316 if (client->alias) 1318 if (client->alias)
1317 script_write_params(client, "alias_", client->alias); 1319 script_write_params(client, "alias_", client->alias);
1318 script_go(client); 1320 script_go(client);
1319 } 1321 }
1320} 1322}
1321 1323
1322int commit_leases () 1324int commit_leases ()
1323{ 1325{
1324 return 0; 1326 return 0;
1325} 1327}
1326 1328
1327int write_lease (lease) 1329int write_lease (lease)
1328 struct lease *lease; 1330 struct lease *lease;
@@ -1777,26 +1779,27 @@ void dhcpnak (packet) @@ -1777,26 +1779,27 @@ void dhcpnak (packet)
1777#if defined (DEBUG) 1779#if defined (DEBUG)
1778 log_info ("DHCPNAK with no active lease.\n"); 1780 log_info ("DHCPNAK with no active lease.\n");
1779#endif 1781#endif
1780 return; 1782 return;
1781 } 1783 }
1782 1784
1783 /* If we get a DHCPNAK, we use the EXPIRE dhclient-script state 1785 /* If we get a DHCPNAK, we use the EXPIRE dhclient-script state
1784 * to indicate that we want all old bindings to be removed. (It 1786 * to indicate that we want all old bindings to be removed. (It
1785 * is possible that we may get a NAK while in the RENEW state, 1787 * is possible that we may get a NAK while in the RENEW state,
1786 * so we might have bindings active at that time) 1788 * so we might have bindings active at that time)
1787 */ 1789 */
1788 script_init(client, "EXPIRE", NULL); 1790 script_init(client, "EXPIRE", NULL);
1789 script_write_params(client, "old_", client->active); 1791 script_write_params(client, "old_", client->active);
 1792 script_write_requested(client);
1790 if (client->alias) 1793 if (client->alias)
1791 script_write_params(client, "alias_", client->alias); 1794 script_write_params(client, "alias_", client->alias);
1792 script_go(client); 1795 script_go(client);
1793 1796
1794 destroy_client_lease (client -> active); 1797 destroy_client_lease (client -> active);
1795 client -> active = (struct client_lease *)0; 1798 client -> active = (struct client_lease *)0;
1796 1799
1797 /* Stop sending DHCPREQUEST packets... */ 1800 /* Stop sending DHCPREQUEST packets... */
1798 cancel_timeout (send_request, client); 1801 cancel_timeout (send_request, client);
1799 1802
1800 /* On some scripts, 'EXPIRE' causes the interface to be ifconfig'd 1803 /* On some scripts, 'EXPIRE' causes the interface to be ifconfig'd
1801 * down (this expunges any routes and arp cache). This makes the 1804 * down (this expunges any routes and arp cache). This makes the
1802 * interface unusable by state_init(), which we call next. So, we 1805 * interface unusable by state_init(), which we call next. So, we
@@ -1893,31 +1896,34 @@ void send_discover (cpp) @@ -1893,31 +1896,34 @@ void send_discover (cpp)
1893 /* Record the number of seconds since we started sending. */ 1896 /* Record the number of seconds since we started sending. */
1894 if (interval < 65536) 1897 if (interval < 65536)
1895 client -> packet.secs = htons (interval); 1898 client -> packet.secs = htons (interval);
1896 else 1899 else
1897 client -> packet.secs = htons (65535); 1900 client -> packet.secs = htons (65535);
1898 client -> secs = client -> packet.secs; 1901 client -> secs = client -> packet.secs;
1899 1902
1900 log_info ("DHCPDISCOVER on %s to %s port %d interval %ld", 1903 log_info ("DHCPDISCOVER on %s to %s port %d interval %ld",
1901 client -> name ? client -> name : client -> interface -> name, 1904 client -> name ? client -> name : client -> interface -> name,
1902 inet_ntoa (sockaddr_broadcast.sin_addr), 1905 inet_ntoa (sockaddr_broadcast.sin_addr),
1903 ntohs (sockaddr_broadcast.sin_port), (long)(client -> interval)); 1906 ntohs (sockaddr_broadcast.sin_port), (long)(client -> interval));
1904 1907
1905 /* Send out a packet. */ 1908 /* Send out a packet. */
1906 result = send_packet (client -> interface, (struct packet *)0, 1909 result = send_packet(client->interface, NULL, &client->packet,
1907 &client -> packet, 1910 client->packet_length, inaddr_any,
1908 client -> packet_length, 1911 &sockaddr_broadcast, NULL);
1909 inaddr_any, &sockaddr_broadcast, 1912 if (result < 0) {
1910 (struct hardware *)0); 1913 log_error("%s:%d: Failed to send %d byte long packet over %s "
 1914 "interface.", MDL, client->packet_length,
 1915 client->interface->name);
 1916 }
1911 1917
1912 /* 1918 /*
1913 * If we used 0 microseconds here, and there were other clients on the 1919 * If we used 0 microseconds here, and there were other clients on the
1914 * same network with a synchronized local clock (ntp), and a similar 1920 * same network with a synchronized local clock (ntp), and a similar
1915 * zero-microsecond-scheduler behavior, then we could be participating 1921 * zero-microsecond-scheduler behavior, then we could be participating
1916 * in a sub-second DOS ttck. 1922 * in a sub-second DOS ttck.
1917 */ 1923 */
1918 tv.tv_sec = cur_tv.tv_sec + client->interval; 1924 tv.tv_sec = cur_tv.tv_sec + client->interval;
1919 tv.tv_usec = client->interval > 1 ? random() % 1000000 : cur_tv.tv_usec; 1925 tv.tv_usec = client->interval > 1 ? random() % 1000000 : cur_tv.tv_usec;
1920 add_timeout(&tv, send_discover, client, 0, 0); 1926 add_timeout(&tv, send_discover, client, 0, 0);
1921} 1927}
1922 1928
1923/* state_panic gets called if we haven't received any offers in a preset 1929/* state_panic gets called if we haven't received any offers in a preset
@@ -1942,26 +1948,27 @@ void state_panic (cpp) @@ -1942,26 +1948,27 @@ void state_panic (cpp)
1942 if (!client -> active && client -> leases) 1948 if (!client -> active && client -> leases)
1943 goto activate_next; 1949 goto activate_next;
1944 1950
1945 /* Run through the list of leases and see if one can be used. */ 1951 /* Run through the list of leases and see if one can be used. */
1946 while (client -> active) { 1952 while (client -> active) {
1947 if (client -> active -> expiry > cur_time) { 1953 if (client -> active -> expiry > cur_time) {
1948 log_info ("Trying recorded lease %s", 1954 log_info ("Trying recorded lease %s",
1949 piaddr (client -> active -> address)); 1955 piaddr (client -> active -> address));
1950 /* Run the client script with the existing 1956 /* Run the client script with the existing
1951 parameters. */ 1957 parameters. */
1952 script_init (client, "TIMEOUT", 1958 script_init (client, "TIMEOUT",
1953 client -> active -> medium); 1959 client -> active -> medium);
1954 script_write_params (client, "new_", client -> active); 1960 script_write_params (client, "new_", client -> active);
 1961 script_write_requested(client);
1955 if (client -> alias) 1962 if (client -> alias)
1956 script_write_params (client, "alias_", 1963 script_write_params (client, "alias_",
1957 client -> alias); 1964 client -> alias);
1958 1965
1959 /* If the old lease is still good and doesn't 1966 /* If the old lease is still good and doesn't
1960 yet need renewal, go into BOUND state and 1967 yet need renewal, go into BOUND state and
1961 timeout at the renewal time. */ 1968 timeout at the renewal time. */
1962 if (!script_go (client)) { 1969 if (!script_go (client)) {
1963 if (cur_time < client -> active -> renewal) { 1970 if (cur_time < client -> active -> renewal) {
1964 client -> state = S_BOUND; 1971 client -> state = S_BOUND;
1965 log_info ("bound: renewal in %ld %s.", 1972 log_info ("bound: renewal in %ld %s.",
1966 (long)(client -> active -> renewal - 1973 (long)(client -> active -> renewal -
1967 cur_time), "seconds"); 1974 cur_time), "seconds");
@@ -2080,26 +2087,27 @@ void send_request (cpp) @@ -2080,26 +2087,27 @@ void send_request (cpp)
2080 goto cancel; 2087 goto cancel;
2081 2088
2082 /* Record the medium. */ 2089 /* Record the medium. */
2083 client -> medium = client -> active -> medium; 2090 client -> medium = client -> active -> medium;
2084 } 2091 }
2085 2092
2086 /* If the lease has expired, relinquish the address and go back 2093 /* If the lease has expired, relinquish the address and go back
2087 to the INIT state. */ 2094 to the INIT state. */
2088 if (client -> state != S_REQUESTING && 2095 if (client -> state != S_REQUESTING &&
2089 cur_time > client -> active -> expiry) { 2096 cur_time > client -> active -> expiry) {
2090 /* Run the client script with the new parameters. */ 2097 /* Run the client script with the new parameters. */
2091 script_init (client, "EXPIRE", (struct string_list *)0); 2098 script_init (client, "EXPIRE", (struct string_list *)0);
2092 script_write_params (client, "old_", client -> active); 2099 script_write_params (client, "old_", client -> active);
 2100 script_write_requested(client);
2093 if (client -> alias) 2101 if (client -> alias)
2094 script_write_params (client, "alias_", 2102 script_write_params (client, "alias_",
2095 client -> alias); 2103 client -> alias);
2096 script_go (client); 2104 script_go (client);
2097 2105
2098 /* Now do a preinit on the interface so that we can 2106 /* Now do a preinit on the interface so that we can
2099 discover a new address. */ 2107 discover a new address. */
2100 script_init (client, "PREINIT", (struct string_list *)0); 2108 script_init (client, "PREINIT", (struct string_list *)0);
2101 if (client -> alias) 2109 if (client -> alias)
2102 script_write_params (client, "alias_", 2110 script_write_params (client, "alias_",
2103 client -> alias); 2111 client -> alias);
2104 script_go (client); 2112 script_go (client);
2105 2113
@@ -2160,65 +2168,77 @@ void send_request (cpp) @@ -2160,65 +2168,77 @@ void send_request (cpp)
2160 else { 2168 else {
2161 if (interval < 65536) 2169 if (interval < 65536)
2162 client -> packet.secs = htons (interval); 2170 client -> packet.secs = htons (interval);
2163 else 2171 else
2164 client -> packet.secs = htons (65535); 2172 client -> packet.secs = htons (65535);
2165 } 2173 }
2166 2174
2167 log_info ("DHCPREQUEST on %s to %s port %d", 2175 log_info ("DHCPREQUEST on %s to %s port %d",
2168 client -> name ? client -> name : client -> interface -> name, 2176 client -> name ? client -> name : client -> interface -> name,
2169 inet_ntoa (destination.sin_addr), 2177 inet_ntoa (destination.sin_addr),
2170 ntohs (destination.sin_port)); 2178 ntohs (destination.sin_port));
2171 2179
2172 if (destination.sin_addr.s_addr != INADDR_BROADCAST && 2180 if (destination.sin_addr.s_addr != INADDR_BROADCAST &&
2173 fallback_interface) 2181 fallback_interface) {
2174 result = send_packet (fallback_interface, 2182 result = send_packet(fallback_interface, NULL, &client->packet,
2175 (struct packet *)0, 2183 client->packet_length, from, &destination,
2176 &client -> packet, 2184 NULL);
2177 client -> packet_length, 2185 if (result < 0) {
2178 from, &destination, 2186 log_error("%s:%d: Failed to send %d byte long packet "
2179 (struct hardware *)0); 2187 "over %s interface.", MDL,
2180 else 2188 client->packet_length,
 2189 fallback_interface->name);
 2190 }
 2191 }
 2192 else {
2181 /* Send out a packet. */ 2193 /* Send out a packet. */
2182 result = send_packet (client -> interface, (struct packet *)0, 2194 result = send_packet(client->interface, NULL, &client->packet,
2183 &client -> packet, 2195 client->packet_length, from, &destination,
2184 client -> packet_length, 2196 NULL);
2185 from, &destination, 2197 if (result < 0) {
2186 (struct hardware *)0); 2198 log_error("%s:%d: Failed to send %d byte long packet"
 2199 " over %s interface.", MDL,
 2200 client->packet_length,
 2201 client->interface->name);
 2202 }
 2203 }
2187 2204
2188 tv.tv_sec = cur_tv.tv_sec + client->interval; 2205 tv.tv_sec = cur_tv.tv_sec + client->interval;
2189 tv.tv_usec = ((tv.tv_sec - cur_tv.tv_sec) > 1) ? 2206 tv.tv_usec = ((tv.tv_sec - cur_tv.tv_sec) > 1) ?
2190 random() % 1000000 : cur_tv.tv_usec; 2207 random() % 1000000 : cur_tv.tv_usec;
2191 add_timeout(&tv, send_request, client, 0, 0); 2208 add_timeout(&tv, send_request, client, 0, 0);
2192} 2209}
2193 2210
2194void send_decline (cpp) 2211void send_decline (cpp)
2195 void *cpp; 2212 void *cpp;
2196{ 2213{
2197 struct client_state *client = cpp; 2214 struct client_state *client = cpp;
2198 2215
2199 int result; 2216 int result;
2200 2217
2201 log_info ("DHCPDECLINE on %s to %s port %d", 2218 log_info ("DHCPDECLINE on %s to %s port %d",
2202 client -> name ? client -> name : client -> interface -> name, 2219 client->name ? client->name : client->interface->name,
2203 inet_ntoa (sockaddr_broadcast.sin_addr), 2220 inet_ntoa(sockaddr_broadcast.sin_addr),
2204 ntohs (sockaddr_broadcast.sin_port)); 2221 ntohs(sockaddr_broadcast.sin_port));
2205 2222
2206 /* Send out a packet. */ 2223 /* Send out a packet. */
2207 result = send_packet (client -> interface, (struct packet *)0, 2224 result = send_packet(client->interface, NULL, &client->packet,
2208 &client -> packet, 2225 client->packet_length, inaddr_any,
2209 client -> packet_length, 2226 &sockaddr_broadcast, NULL);
2210 inaddr_any, &sockaddr_broadcast, 2227 if (result < 0) {
2211 (struct hardware *)0); 2228 log_error("%s:%d: Failed to send %d byte long packet over %s"
 2229 " interface.", MDL, client->packet_length,
 2230 client->interface->name);
 2231 }
2212} 2232}
2213 2233
2214void send_release (cpp) 2234void send_release (cpp)
2215 void *cpp; 2235 void *cpp;
2216{ 2236{
2217 struct client_state *client = cpp; 2237 struct client_state *client = cpp;
2218 2238
2219 int result; 2239 int result;
2220 struct sockaddr_in destination; 2240 struct sockaddr_in destination;
2221 struct in_addr from; 2241 struct in_addr from;
2222 2242
2223 memcpy (&from, client -> active -> address.iabuf, 2243 memcpy (&from, client -> active -> address.iabuf,
2224 sizeof from); 2244 sizeof from);
@@ -2236,40 +2256,49 @@ void send_release (cpp) @@ -2236,40 +2256,49 @@ void send_release (cpp)
2236 client -> active -> expiry = 2256 client -> active -> expiry =
2237 client -> active -> renewal = 2257 client -> active -> renewal =
2238 client -> active -> rebind = cur_time; 2258 client -> active -> rebind = cur_time;
2239 if (!write_client_lease (client, client -> active, 1, 1)) { 2259 if (!write_client_lease (client, client -> active, 1, 1)) {
2240 log_error ("Can't release lease: lease write failed."); 2260 log_error ("Can't release lease: lease write failed.");
2241 return; 2261 return;
2242 } 2262 }
2243 2263
2244 log_info ("DHCPRELEASE on %s to %s port %d", 2264 log_info ("DHCPRELEASE on %s to %s port %d",
2245 client -> name ? client -> name : client -> interface -> name, 2265 client -> name ? client -> name : client -> interface -> name,
2246 inet_ntoa (destination.sin_addr), 2266 inet_ntoa (destination.sin_addr),
2247 ntohs (destination.sin_port)); 2267 ntohs (destination.sin_port));
2248 2268
2249 if (fallback_interface) 2269 if (fallback_interface) {
2250 result = send_packet (fallback_interface, 2270 result = send_packet(fallback_interface, NULL, &client->packet,
2251 (struct packet *)0, 2271 client->packet_length, from, &destination,
2252 &client -> packet, 2272 NULL);
2253 client -> packet_length, 2273 if (result < 0) {
2254 from, &destination, 2274 log_error("%s:%d: Failed to send %d byte long packet"
2255 (struct hardware *)0); 2275 " over %s interface.", MDL,
2256 else 2276 client->packet_length,
 2277 fallback_interface->name);
 2278 }
 2279 } else {
2257 /* Send out a packet. */ 2280 /* Send out a packet. */
2258 result = send_packet (client -> interface, (struct packet *)0, 2281 result = send_packet(client->interface, NULL, &client->packet,
2259 &client -> packet, 2282 client->packet_length, from, &destination,
2260 client -> packet_length, 2283 NULL);
2261 from, &destination, 2284 if (result < 0) {
2262 (struct hardware *)0); 2285 log_error ("%s:%d: Failed to send %d byte long packet"
 2286 " over %s interface.", MDL,
 2287 client->packet_length,
 2288 client->interface->name);
 2289 }
 2290
 2291 }
2263} 2292}
2264 2293
2265void 2294void
2266make_client_options(struct client_state *client, struct client_lease *lease, 2295make_client_options(struct client_state *client, struct client_lease *lease,
2267 u_int8_t *type, struct option_cache *sid, 2296 u_int8_t *type, struct option_cache *sid,
2268 struct iaddr *rip, struct option **prl, 2297 struct iaddr *rip, struct option **prl,
2269 struct option_state **op) 2298 struct option_state **op)
2270{ 2299{
2271 unsigned i; 2300 unsigned i;
2272 struct option_cache *oc; 2301 struct option_cache *oc;
2273 struct option *option = NULL; 2302 struct option *option = NULL;
2274 struct buffer *bp = (struct buffer *)0; 2303 struct buffer *bp = (struct buffer *)0;
2275 2304
@@ -2712,30 +2741,41 @@ void write_lease_option (struct option_c @@ -2712,30 +2741,41 @@ void write_lease_option (struct option_c
2712 char *preamble = stuff; 2741 char *preamble = stuff;
2713 2742
2714 memset (&ds, 0, sizeof ds); 2743 memset (&ds, 0, sizeof ds);
2715 2744
2716 if (u != &dhcp_universe) { 2745 if (u != &dhcp_universe) {
2717 name = u -> name; 2746 name = u -> name;
2718 dot = "."; 2747 dot = ".";
2719 } else { 2748 } else {
2720 name = ""; 2749 name = "";
2721 dot = ""; 2750 dot = "";
2722 } 2751 }
2723 if (evaluate_option_cache (&ds, packet, lease, client_state, 2752 if (evaluate_option_cache (&ds, packet, lease, client_state,
2724 in_options, cfg_options, scope, oc, MDL)) { 2753 in_options, cfg_options, scope, oc, MDL)) {
2725 fprintf(leaseFile, "%soption %s%s%s %s;\n", preamble, 2754 /* The option name */
2726 name, dot, oc->option->name, 2755 fprintf(leaseFile, "%soption %s%s%s", preamble,
2727 pretty_print_option(oc->option, ds.data, ds.len, 2756 name, dot, oc->option->name);
2728 1, 1)); 2757
 2758 /* The option value if there is one */
 2759 if ((oc->option->format == NULL) ||
 2760 (oc->option->format[0] != 'Z')) {
 2761 fprintf(leaseFile, " %s",
 2762 pretty_print_option(oc->option, ds.data,
 2763 ds.len, 1, 1));
 2764 }
 2765
 2766 /* The closing semi-colon and newline */
 2767 fprintf(leaseFile, ";\n");
 2768
2729 data_string_forget (&ds, MDL); 2769 data_string_forget (&ds, MDL);
2730 } 2770 }
2731} 2771}
2732 2772
2733/* Write an option cache to the lease store. */ 2773/* Write an option cache to the lease store. */
2734static void 2774static void
2735write_options(struct client_state *client, struct option_state *options, 2775write_options(struct client_state *client, struct option_state *options,
2736 const char *preamble) 2776 const char *preamble)
2737{ 2777{
2738 int i; 2778 int i;
2739 2779
2740 for (i = 0; i < options->universe_count; i++) { 2780 for (i = 0; i < options->universe_count; i++) {
2741 option_space_foreach(NULL, NULL, client, NULL, options, 2781 option_space_foreach(NULL, NULL, client, NULL, options,
@@ -3213,38 +3253,62 @@ void script_write_params (client, prefix @@ -3213,38 +3253,62 @@ void script_write_params (client, prefix
3213 3253
3214 if (lease->server_name) { 3254 if (lease->server_name) {
3215 if (check_option_values(NULL, DHO_HOST_NAME, 3255 if (check_option_values(NULL, DHO_HOST_NAME,
3216 lease->server_name, 3256 lease->server_name,
3217 strlen(lease->server_name)) == 0 ) { 3257 strlen(lease->server_name)) == 0 ) {
3218 client_envadd (client, prefix, "server_name", 3258 client_envadd (client, prefix, "server_name",
3219 "%s", lease->server_name); 3259 "%s", lease->server_name);
3220 } else { 3260 } else {
3221 log_error("suspect value in %s " 3261 log_error("suspect value in %s "
3222 "option - discarded", 3262 "option - discarded",
3223 lease->server_name); 3263 lease->server_name);
3224 } 3264 }
3225 } 3265 }
3226  
3227 3266
3228 for (i = 0; i < lease -> options -> universe_count; i++) { 3267 for (i = 0; i < lease -> options -> universe_count; i++) {
3229 option_space_foreach ((struct packet *)0, (struct lease *)0, 3268 option_space_foreach ((struct packet *)0, (struct lease *)0,
3230 client, (struct option_state *)0, 3269 client, (struct option_state *)0,
3231 lease -> options, &global_scope, 3270 lease -> options, &global_scope,
3232 universes [i], 3271 universes [i],
3233 &es, client_option_envadd); 3272 &es, client_option_envadd);
3234 } 3273 }
3235 client_envadd (client, prefix, "expiry", "%d", (int)(lease -> expiry)); 3274 client_envadd (client, prefix, "expiry", "%d", (int)(lease -> expiry));
3236} 3275}
3237 3276
 3277/*
 3278 * Write out the environment variables for the objects that the
 3279 * client requested. If the object was requested the variable will be:
 3280 * requested_<option_name>=1
 3281 * If it wasn't requested there won't be a variable.
 3282 */
 3283void script_write_requested(client)
 3284 struct client_state *client;
 3285{
 3286 int i;
 3287 struct option **req;
 3288 char name[256];
 3289 req = client->config->requested_options;
 3290
 3291 if (req == NULL)
 3292 return;
 3293
 3294 for (i = 0 ; req[i] != NULL ; i++) {
 3295 if ((req[i]->universe == &dhcp_universe) &&
 3296 dhcp_option_ev_name(name, sizeof(name), req[i])) {
 3297 client_envadd(client, "requested_", name, "%d", 1);
 3298 }
 3299 }
 3300}
 3301
3238int script_go (client) 3302int script_go (client)
3239 struct client_state *client; 3303 struct client_state *client;
3240{ 3304{
3241 char *scriptName; 3305 char *scriptName;
3242 char *argv [2]; 3306 char *argv [2];
3243 char **envp; 3307 char **envp;
3244 char reason [] = "REASON=NBI"; 3308 char reason [] = "REASON=NBI";
3245 static char client_path [] = CLIENT_PATH; 3309 static char client_path [] = CLIENT_PATH;
3246 int i; 3310 int i;
3247 struct string_list *sp, *next; 3311 struct string_list *sp, *next;
3248 int pid, wpid, wstatus; 3312 int pid, wpid, wstatus;
3249 3313
3250 if (client) 3314 if (client)
@@ -3532,26 +3596,27 @@ void do_release(client) @@ -3532,26 +3596,27 @@ void do_release(client)
3532 /* Zap the medium list... */ 3596 /* Zap the medium list... */
3533 client -> medium = (struct string_list *)0; 3597 client -> medium = (struct string_list *)0;
3534 3598
3535 /* Send out the first and only DHCPRELEASE packet. */ 3599 /* Send out the first and only DHCPRELEASE packet. */
3536 send_release (client); 3600 send_release (client);
3537 3601
3538 /* Do the client script RELEASE operation. */ 3602 /* Do the client script RELEASE operation. */
3539 script_init (client, 3603 script_init (client,
3540 "RELEASE", (struct string_list *)0); 3604 "RELEASE", (struct string_list *)0);
3541 if (client -> alias) 3605 if (client -> alias)
3542 script_write_params (client, "alias_", 3606 script_write_params (client, "alias_",
3543 client -> alias); 3607 client -> alias);
3544 script_write_params (client, "old_", client -> active); 3608 script_write_params (client, "old_", client -> active);
 3609 script_write_requested(client);
3545 script_go (client); 3610 script_go (client);
3546 } 3611 }
3547 3612
3548 /* Cancel any timeouts. */ 3613 /* Cancel any timeouts. */
3549 cancel_timeout (state_bound, client); 3614 cancel_timeout (state_bound, client);
3550 cancel_timeout (send_discover, client); 3615 cancel_timeout (send_discover, client);
3551 cancel_timeout (state_init, client); 3616 cancel_timeout (state_init, client);
3552 cancel_timeout (send_request, client); 3617 cancel_timeout (send_request, client);
3553 cancel_timeout (state_reboot, client); 3618 cancel_timeout (state_reboot, client);
3554 client -> state = S_STOPPED; 3619 client -> state = S_STOPPED;
3555} 3620}
3556 3621
3557int dhclient_interface_shutdown_hook (struct interface_info *interface) 3622int dhclient_interface_shutdown_hook (struct interface_info *interface)
@@ -3698,47 +3763,47 @@ static void shutdown_exit (void *foo) @@ -3698,47 +3763,47 @@ static void shutdown_exit (void *foo)
3698/* The first and second stages are pretty similar so we combine them */ 3763/* The first and second stages are pretty similar so we combine them */
3699static void 3764static void
3700client_dns_remove_action(dhcp_ddns_cb_t *ddns_cb, 3765client_dns_remove_action(dhcp_ddns_cb_t *ddns_cb,
3701 isc_result_t eresult) 3766 isc_result_t eresult)
3702{ 3767{
3703 3768
3704 isc_result_t result; 3769 isc_result_t result;
3705 3770
3706 if ((eresult == ISC_R_SUCCESS) && 3771 if ((eresult == ISC_R_SUCCESS) &&
3707 (ddns_cb->state == DDNS_STATE_REM_FW_YXDHCID)) { 3772 (ddns_cb->state == DDNS_STATE_REM_FW_YXDHCID)) {
3708 /* Do the second stage of the FWD removal */ 3773 /* Do the second stage of the FWD removal */
3709 ddns_cb->state = DDNS_STATE_REM_FW_NXRR; 3774 ddns_cb->state = DDNS_STATE_REM_FW_NXRR;
3710 3775
3711 result = ddns_modify_fwd(ddns_cb); 3776 result = ddns_modify_fwd(ddns_cb, MDL);
3712 if (result == ISC_R_SUCCESS) { 3777 if (result == ISC_R_SUCCESS) {
3713 return; 3778 return;
3714 } 3779 }
3715 } 3780 }
3716 3781
3717 /* If we are done or have an error clean up */ 3782 /* If we are done or have an error clean up */
3718 ddns_cb_free(ddns_cb, MDL); 3783 ddns_cb_free(ddns_cb, MDL);
3719 return; 3784 return;
3720} 3785}
3721 3786
3722void 3787void
3723client_dns_remove(struct client_state *client, 3788client_dns_remove(struct client_state *client,
3724 struct iaddr *addr) 3789 struct iaddr *addr)
3725{ 3790{
3726 dhcp_ddns_cb_t *ddns_cb; 3791 dhcp_ddns_cb_t *ddns_cb;
3727 isc_result_t result; 3792 isc_result_t result;
3728 3793
3729 /* if we have an old ddns request for this client, cancel it */ 3794 /* if we have an old ddns request for this client, cancel it */
3730 if (client->ddns_cb != NULL) { 3795 if (client->ddns_cb != NULL) {
3731 ddns_cancel(client->ddns_cb); 3796 ddns_cancel(client->ddns_cb, MDL);
3732 client->ddns_cb = NULL; 3797 client->ddns_cb = NULL;
3733 } 3798 }
3734  3799
3735 ddns_cb = ddns_cb_alloc(MDL); 3800 ddns_cb = ddns_cb_alloc(MDL);
3736 if (ddns_cb != NULL) { 3801 if (ddns_cb != NULL) {
3737 ddns_cb->address = *addr; 3802 ddns_cb->address = *addr;
3738 ddns_cb->timeout = 0; 3803 ddns_cb->timeout = 0;
3739 3804
3740 ddns_cb->state = DDNS_STATE_REM_FW_YXDHCID; 3805 ddns_cb->state = DDNS_STATE_REM_FW_YXDHCID;
3741 ddns_cb->flags = DDNS_UPDATE_ADDR; 3806 ddns_cb->flags = DDNS_UPDATE_ADDR;
3742 ddns_cb->cur_func = client_dns_remove_action; 3807 ddns_cb->cur_func = client_dns_remove_action;
3743 3808
3744 result = client_dns_update(client, ddns_cb); 3809 result = client_dns_update(client, ddns_cb);
@@ -3876,27 +3941,27 @@ client_dns_update_action(dhcp_ddns_cb_t  @@ -3876,27 +3941,27 @@ client_dns_update_action(dhcp_ddns_cb_t
3876 /* Either we succeeded or broke in a bad way, clean up */ 3941 /* Either we succeeded or broke in a bad way, clean up */
3877 break; 3942 break;
3878 3943
3879 case DNS_R_YXRRSET: 3944 case DNS_R_YXRRSET:
3880 /* 3945 /*
3881 * This is the only difference between the two stages, 3946 * This is the only difference between the two stages,
3882 * check to see if it is the first stage, in which case 3947 * check to see if it is the first stage, in which case
3883 * start the second stage 3948 * start the second stage
3884 */ 3949 */
3885 if (ddns_cb->state == DDNS_STATE_ADD_FW_NXDOMAIN) { 3950 if (ddns_cb->state == DDNS_STATE_ADD_FW_NXDOMAIN) {
3886 ddns_cb->state = DDNS_STATE_ADD_FW_YXDHCID; 3951 ddns_cb->state = DDNS_STATE_ADD_FW_YXDHCID;
3887 ddns_cb->cur_func = client_dns_update_action; 3952 ddns_cb->cur_func = client_dns_update_action;
3888 3953
3889 result = ddns_modify_fwd(ddns_cb); 3954 result = ddns_modify_fwd(ddns_cb, MDL);
3890 if (result == ISC_R_SUCCESS) { 3955 if (result == ISC_R_SUCCESS) {
3891 return; 3956 return;
3892 } 3957 }
3893 } 3958 }
3894 break; 3959 break;
3895 3960
3896 case ISC_R_TIMEDOUT: 3961 case ISC_R_TIMEDOUT:
3897 /* 3962 /*
3898 * We got a timeout response from the DNS module. Schedule 3963 * We got a timeout response from the DNS module. Schedule
3899 * another attempt for later. We forget the name, dhcid and 3964 * another attempt for later. We forget the name, dhcid and
3900 * zone so if it gets changed we will get the new information. 3965 * zone so if it gets changed we will get the new information.
3901 */ 3966 */
3902 data_string_forget(&ddns_cb->fwd_name, MDL); 3967 data_string_forget(&ddns_cb->fwd_name, MDL);
@@ -4013,27 +4078,27 @@ client_dns_update(struct client_state *c @@ -4013,27 +4078,27 @@ client_dns_update(struct client_state *c
4013 } else 4078 } else
4014 result = get_dhcid(&ddns_cb->dhcid, 0, 4079 result = get_dhcid(&ddns_cb->dhcid, 0,
4015 client->interface->hw_address.hbuf, 4080 client->interface->hw_address.hbuf,
4016 client->interface->hw_address.hlen); 4081 client->interface->hw_address.hlen);
4017 } 4082 }
4018 if (!result) { 4083 if (!result) {
4019 return ISC_R_SUCCESS; 4084 return ISC_R_SUCCESS;
4020 } 4085 }
4021 4086
4022 /* 4087 /*
4023 * Perform updates. 4088 * Perform updates.
4024 */ 4089 */
4025 if (ddns_cb->fwd_name.len && ddns_cb->dhcid.len) { 4090 if (ddns_cb->fwd_name.len && ddns_cb->dhcid.len) {
4026 rcode = ddns_modify_fwd(ddns_cb); 4091 rcode = ddns_modify_fwd(ddns_cb, MDL);
4027 } else 4092 } else
4028 rcode = ISC_R_FAILURE; 4093 rcode = ISC_R_FAILURE;
4029 4094
4030 /* 4095 /*
4031 * A success from the modify routine means we are performing 4096 * A success from the modify routine means we are performing
4032 * async processing, for which we use the timedout error message. 4097 * async processing, for which we use the timedout error message.
4033 */ 4098 */
4034 if (rcode == ISC_R_SUCCESS) { 4099 if (rcode == ISC_R_SUCCESS) {
4035 rcode = ISC_R_TIMEDOUT; 4100 rcode = ISC_R_TIMEDOUT;
4036 } 4101 }
4037 4102
4038 return rcode; 4103 return rcode;
4039} 4104}
@@ -4046,27 +4111,27 @@ client_dns_update(struct client_state *c @@ -4046,27 +4111,27 @@ client_dns_update(struct client_state *c
4046void 4111void
4047dhclient_schedule_updates(struct client_state *client, 4112dhclient_schedule_updates(struct client_state *client,
4048 struct iaddr *addr, 4113 struct iaddr *addr,
4049 int offset) 4114 int offset)
4050{ 4115{
4051 dhcp_ddns_cb_t *ddns_cb; 4116 dhcp_ddns_cb_t *ddns_cb;
4052 struct timeval tv; 4117 struct timeval tv;
4053 4118
4054 if (!client->config->do_forward_update) 4119 if (!client->config->do_forward_update)
4055 return; 4120 return;
4056 4121
4057 /* cancel any outstanding ddns requests */ 4122 /* cancel any outstanding ddns requests */
4058 if (client->ddns_cb != NULL) { 4123 if (client->ddns_cb != NULL) {
4059 ddns_cancel(client->ddns_cb); 4124 ddns_cancel(client->ddns_cb, MDL);
4060 client->ddns_cb = NULL; 4125 client->ddns_cb = NULL;
4061 } 4126 }
4062 4127
4063 ddns_cb = ddns_cb_alloc(MDL); 4128 ddns_cb = ddns_cb_alloc(MDL);
4064 4129
4065 if (ddns_cb != NULL) { 4130 if (ddns_cb != NULL) {
4066 ddns_cb->lease = (void *)client; 4131 ddns_cb->lease = (void *)client;
4067 ddns_cb->address = *addr; 4132 ddns_cb->address = *addr;
4068 ddns_cb->timeout = 1; 4133 ddns_cb->timeout = 1;
4069 4134
4070 /* 4135 /*
4071 * XXX: DNS TTL is a problem we need to solve properly. 4136 * XXX: DNS TTL is a problem we need to solve properly.
4072 * Until that time, 300 is a placeholder default for 4137 * Until that time, 300 is a placeholder default for

File Deleted: src/external/bsd/dhcp/dist/client/Attic/dhclient.conf

cvs diff -r1.2 -r1.3 src/external/bsd/dhcp/dist/common/Attic/conflex.c (expand / switch to unified diff)

--- src/external/bsd/dhcp/dist/common/Attic/conflex.c 2013/03/24 15:53:58 1.2
+++ src/external/bsd/dhcp/dist/common/Attic/conflex.c 2013/03/24 23:03:06 1.3
@@ -1,21 +1,21 @@ @@ -1,21 +1,21 @@
1/* $NetBSD: conflex.c,v 1.2 2013/03/24 15:53:58 christos Exp $ */ 1/* $NetBSD: conflex.c,v 1.3 2013/03/24 23:03:06 christos Exp $ */
2 2
3/* conflex.c 3/* conflex.c
4 4
5 Lexical scanner for dhcpd config file... */ 5 Lexical scanner for dhcpd config file... */
6 6
7/* 7/*
8 * Copyright (c) 2004-2011 by Internet Systems Consortium, Inc. ("ISC") 8 * Copyright (c) 2004-2012 by Internet Systems Consortium, Inc. ("ISC")
9 * Copyright (c) 1995-2003 by Internet Software Consortium 9 * Copyright (c) 1995-2003 by Internet Software Consortium
10 * 10 *
11 * Permission to use, copy, modify, and distribute this software for any 11 * Permission to use, copy, modify, and distribute this software for any
12 * purpose with or without fee is hereby granted, provided that the above 12 * purpose with or without fee is hereby granted, provided that the above
13 * copyright notice and this permission notice appear in all copies. 13 * copyright notice and this permission notice appear in all copies.
14 * 14 *
15 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 15 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
16 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 16 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 17 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
18 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 18 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 20 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 21 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * Redwood City, CA 94063 25 * Redwood City, CA 94063
26 * <info@isc.org> 26 * <info@isc.org>
27 * https://www.isc.org/ 27 * https://www.isc.org/
28 * 28 *
29 * This software has been written for Internet Systems Consortium 29 * This software has been written for Internet Systems Consortium
30 * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc. 30 * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
31 * To learn more about Internet Systems Consortium, see 31 * To learn more about Internet Systems Consortium, see
32 * ``https://www.isc.org/''. To learn more about Vixie Enterprises, 32 * ``https://www.isc.org/''. To learn more about Vixie Enterprises,
33 * see ``http://www.vix.com''. To learn more about Nominum, Inc., see 33 * see ``http://www.vix.com''. To learn more about Nominum, Inc., see
34 * ``http://www.nominum.com''. 34 * ``http://www.nominum.com''.
35 */ 35 */
36 36
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38__RCSID("$NetBSD: conflex.c,v 1.2 2013/03/24 15:53:58 christos Exp $"); 38__RCSID("$NetBSD: conflex.c,v 1.3 2013/03/24 23:03:06 christos Exp $");
39 39
40#include "dhcpd.h" 40#include "dhcpd.h"
41#include <ctype.h> 41#include <ctype.h>
42 42
43static int get_char (struct parse *); 43static int get_char (struct parse *);
44static void unget_char(struct parse *, int); 44static void unget_char(struct parse *, int);
45static void skip_to_eol (struct parse *); 45static void skip_to_eol (struct parse *);
46static enum dhcp_token read_whitespace(int c, struct parse *cfile); 46static enum dhcp_token read_whitespace(int c, struct parse *cfile);
47static enum dhcp_token read_string (struct parse *); 47static enum dhcp_token read_string (struct parse *);
48static enum dhcp_token read_number (int, struct parse *); 48static enum dhcp_token read_number (int, struct parse *);
49static enum dhcp_token read_num_or_name (int, struct parse *); 49static enum dhcp_token read_num_or_name (int, struct parse *);
50static enum dhcp_token intern (char *, enum dhcp_token); 50static enum dhcp_token intern (char *, enum dhcp_token);
51 51
@@ -1038,26 +1038,28 @@ intern(char *atom, enum dhcp_token dfv)  @@ -1038,26 +1038,28 @@ intern(char *atom, enum dhcp_token dfv)
1038 return IA_NA; 1038 return IA_NA;
1039 if (!strcasecmp(atom+1, "a-ta"))  1039 if (!strcasecmp(atom+1, "a-ta"))
1040 return IA_TA; 1040 return IA_TA;
1041 if (!strcasecmp(atom+1, "a-pd"))  1041 if (!strcasecmp(atom+1, "a-pd"))
1042 return IA_PD; 1042 return IA_PD;
1043 if (!strcasecmp(atom+1, "aaddr"))  1043 if (!strcasecmp(atom+1, "aaddr"))
1044 return IAADDR; 1044 return IAADDR;
1045 if (!strcasecmp(atom+1, "aprefix"))  1045 if (!strcasecmp(atom+1, "aprefix"))
1046 return IAPREFIX; 1046 return IAPREFIX;
1047 if (!strcasecmp (atom + 1, "nclude")) 1047 if (!strcasecmp (atom + 1, "nclude"))
1048 return INCLUDE; 1048 return INCLUDE;
1049 if (!strcasecmp (atom + 1, "nteger")) 1049 if (!strcasecmp (atom + 1, "nteger"))
1050 return INTEGER; 1050 return INTEGER;
 1051 if (!strcasecmp (atom + 1, "nfiniband"))
 1052 return TOKEN_INFINIBAND;
1051 if (!strcasecmp (atom + 1, "nfinite")) 1053 if (!strcasecmp (atom + 1, "nfinite"))
1052 return INFINITE; 1054 return INFINITE;
1053 if (!strcasecmp (atom + 1, "nfo")) 1055 if (!strcasecmp (atom + 1, "nfo"))
1054 return INFO; 1056 return INFO;
1055 if (!strcasecmp (atom + 1, "p-address")) 1057 if (!strcasecmp (atom + 1, "p-address"))
1056 return IP_ADDRESS; 1058 return IP_ADDRESS;
1057 if (!strcasecmp (atom + 1, "p6-address")) 1059 if (!strcasecmp (atom + 1, "p6-address"))
1058 return IP6_ADDRESS; 1060 return IP6_ADDRESS;
1059 if (!strcasecmp (atom + 1, "nitial-interval")) 1061 if (!strcasecmp (atom + 1, "nitial-interval"))
1060 return INITIAL_INTERVAL; 1062 return INITIAL_INTERVAL;
1061 if (!strcasecmp (atom + 1, "nitial-delay")) 1063 if (!strcasecmp (atom + 1, "nitial-delay"))
1062 return INITIAL_DELAY; 1064 return INITIAL_DELAY;
1063 if (!strcasecmp (atom + 1, "nterface")) 1065 if (!strcasecmp (atom + 1, "nterface"))

cvs diff -r1.2 -r1.3 src/external/bsd/dhcp/dist/common/Attic/dns.c (expand / switch to unified diff)

--- src/external/bsd/dhcp/dist/common/Attic/dns.c 2013/03/24 15:53:58 1.2
+++ src/external/bsd/dhcp/dist/common/Attic/dns.c 2013/03/24 23:03:06 1.3
@@ -1,21 +1,21 @@ @@ -1,21 +1,21 @@
1/* $NetBSD: dns.c,v 1.2 2013/03/24 15:53:58 christos Exp $ */ 1/* $NetBSD: dns.c,v 1.3 2013/03/24 23:03:06 christos Exp $ */
2 2
3/* dns.c 3/* dns.c
4 4
5 Domain Name Service subroutines. */ 5 Domain Name Service subroutines. */
6 6
7/* 7/*
8 * Copyright (c) 2009-2011 by Internet Systems Consortium, Inc. ("ISC") 8 * Copyright (c) 2009-2012 by Internet Systems Consortium, Inc. ("ISC")
9 * Copyright (c) 2004-2007 by Internet Systems Consortium, Inc. ("ISC") 9 * Copyright (c) 2004-2007 by Internet Systems Consortium, Inc. ("ISC")
10 * Copyright (c) 2001-2003 by Internet Software Consortium 10 * Copyright (c) 2001-2003 by Internet Software Consortium
11 * 11 *
12 * Permission to use, copy, modify, and distribute this software for any 12 * Permission to use, copy, modify, and distribute this software for any
13 * purpose with or without fee is hereby granted, provided that the above 13 * purpose with or without fee is hereby granted, provided that the above
14 * copyright notice and this permission notice appear in all copies. 14 * copyright notice and this permission notice appear in all copies.
15 * 15 *
16 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 16 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
17 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 17 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 18 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
19 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 19 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 20 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
21 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 21 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
@@ -805,26 +805,32 @@ find_cached_zone(dhcp_ddns_cb_t *ddns_cb @@ -805,26 +805,32 @@ find_cached_zone(dhcp_ddns_cb_t *ddns_cb
805void forget_zone (struct dns_zone **zone) 805void forget_zone (struct dns_zone **zone)
806{ 806{
807 dns_zone_dereference (zone, MDL); 807 dns_zone_dereference (zone, MDL);
808} 808}
809 809
810void repudiate_zone (struct dns_zone **zone) 810void repudiate_zone (struct dns_zone **zone)
811{ 811{
812 /* XXX Currently we're not differentiating between a cached 812 /* XXX Currently we're not differentiating between a cached
813 XXX zone and a zone that's been repudiated, which means 813 XXX zone and a zone that's been repudiated, which means
814 XXX that if we reap cached zones, we blow away repudiated 814 XXX that if we reap cached zones, we blow away repudiated
815 XXX zones. This isn't a big problem since we're not yet 815 XXX zones. This isn't a big problem since we're not yet
816 XXX caching zones... :'} */ 816 XXX caching zones... :'} */
817 817
 818 /* verify that we have a pointer at least */
 819 if ((zone == NULL) || (*zone == NULL)) {
 820 log_info("Null argument to repudiate zone");
 821 return;
 822 }
 823
818 (*zone) -> timeout = cur_time - 1; 824 (*zone) -> timeout = cur_time - 1;
819 dns_zone_dereference (zone, MDL); 825 dns_zone_dereference (zone, MDL);
820} 826}
821 827
822/* Have to use TXT records for now. */ 828/* Have to use TXT records for now. */
823#define T_DHCID T_TXT 829#define T_DHCID T_TXT
824 830
825int get_dhcid (struct data_string *id, 831int get_dhcid (struct data_string *id,
826 int type, const u_int8_t *data, unsigned len) 832 int type, const u_int8_t *data, unsigned len)
827{ 833{
828 unsigned char buf[ISC_MD5_DIGESTLENGTH]; 834 unsigned char buf[ISC_MD5_DIGESTLENGTH];
829 isc_md5_t md5; 835 isc_md5_t md5;
830 int i; 836 int i;
@@ -1172,63 +1178,55 @@ ddns_modify_fwd_add2(dhcp_ddns_cb_t *d @@ -1172,63 +1178,55 @@ ddns_modify_fwd_add2(dhcp_ddns_cb_t *d
1172/* 1178/*
1173 * The entity chosen to handle the A record for this client (either the 1179 * The entity chosen to handle the A record for this client (either the
1174 * client or the server) SHOULD delete the A record that was added when 1180 * client or the server) SHOULD delete the A record that was added when
1175 * the lease was made to the client. 1181 * the lease was made to the client.
1176 * 1182 *
1177 * In order to perform this delete, the updater prepares an UPDATE 1183 * In order to perform this delete, the updater prepares an UPDATE
1178 * query which contains two prerequisites. The first prerequisite 1184 * query which contains two prerequisites. The first prerequisite
1179 * asserts that the DHCID RR exists whose data is the client identity 1185 * asserts that the DHCID RR exists whose data is the client identity
1180 * described in Section 4.3. The second prerequisite asserts that the 1186 * described in Section 4.3. The second prerequisite asserts that the
1181 * data in the A RR contains the IP address of the lease that has 1187 * data in the A RR contains the IP address of the lease that has
1182 * expired or been released. 1188 * expired or been released.
1183 * -- "Interaction between DHCP and DNS" 1189 * -- "Interaction between DHCP and DNS"
1184 * 1190 *
 1191 * RFC 4703 has relaxed the prereqisites to only checking the DHCID RR
 1192 * and we have adopted that to minizmie problems due to interruptions
 1193 * when doing a deletion.
 1194 *
1185 * First try has: 1195 * First try has:
1186 * DHCID RR exists, and matches client identity. 1196 * DHCID RR exists, and matches client identity.
1187 * A RR matches the expiring lease. 
1188 * Delete appropriate A RR. 1197 * Delete appropriate A RR.
1189 */ 1198 */
1190 1199
1191static isc_result_t 1200static isc_result_t
1192ddns_modify_fwd_rem1(dhcp_ddns_cb_t *ddns_cb, 1201ddns_modify_fwd_rem1(dhcp_ddns_cb_t *ddns_cb,
1193 dhcp_ddns_data_t *dataspace, 1202 dhcp_ddns_data_t *dataspace,
1194 dns_name_t *pname, 1203 dns_name_t *pname,
1195 dns_name_t *uname) 1204 dns_name_t *uname)
1196{ 1205{
1197 isc_result_t result; 1206 isc_result_t result;
1198 1207
1199 /* Consruct the prereq list */ 1208 /* Consruct the prereq list */
1200 /* The DHCID RR exists and matches the client identity */ 1209 /* The DHCID RR exists and matches the client identity */
1201 result = make_dns_dataset(dns_rdataclass_in, dns_rdatatype_txt, 1210 result = make_dns_dataset(dns_rdataclass_in, dns_rdatatype_txt,
1202 dataspace,  1211 dataspace,
1203 (unsigned char *)ddns_cb->dhcid.data, 1212 (unsigned char *)ddns_cb->dhcid.data,
1204 ddns_cb->dhcid.len, 0); 1213 ddns_cb->dhcid.len, 0);
1205 if (result != ISC_R_SUCCESS) { 1214 if (result != ISC_R_SUCCESS) {
1206 return(result); 1215 return(result);
1207 } 1216 }
1208 ISC_LIST_APPEND(pname->list, &dataspace->rdataset, link); 1217 ISC_LIST_APPEND(pname->list, &dataspace->rdataset, link);
1209 dataspace++; 1218 dataspace++;
1210 1219
1211 /* The A RR matches the expiring lease */ 
1212 result = make_dns_dataset(dns_rdataclass_in, ddns_cb->address_type, 
1213 dataspace,  
1214 (unsigned char *)ddns_cb->address.iabuf, 
1215 ddns_cb->address.len, 0); 
1216 if (result != ISC_R_SUCCESS) { 
1217 return(result); 
1218 } 
1219 ISC_LIST_APPEND(pname->list, &dataspace->rdataset, link); 
1220 dataspace++; 
1221 
1222 /* Construct the update list */ 1220 /* Construct the update list */
1223 /* Delete A RRset */ 1221 /* Delete A RRset */
1224 result = make_dns_dataset(dns_rdataclass_none, ddns_cb->address_type, 1222 result = make_dns_dataset(dns_rdataclass_none, ddns_cb->address_type,
1225 dataspace, 1223 dataspace,
1226 (unsigned char *)ddns_cb->address.iabuf, 1224 (unsigned char *)ddns_cb->address.iabuf,
1227 ddns_cb->address.len, 0); 1225 ddns_cb->address.len, 0);
1228 if (result != ISC_R_SUCCESS) { 1226 if (result != ISC_R_SUCCESS) {
1229 return(result); 1227 return(result);
1230 } 1228 }
1231 ISC_LIST_APPEND(uname->list, &dataspace->rdataset, link); 1229 ISC_LIST_APPEND(uname->list, &dataspace->rdataset, link);
1232 1230
1233 return(ISC_R_SUCCESS); 1231 return(ISC_R_SUCCESS);
1234} 1232}
@@ -1311,79 +1309,97 @@ void ddns_interlude(isc_task_t *taskp, @@ -1311,79 +1309,97 @@ void ddns_interlude(isc_task_t *taskp,
1311#endif 1309#endif
1312 1310
1313#if defined (DEBUG_DNS_UPDATES) 1311#if defined (DEBUG_DNS_UPDATES)
1314 print_dns_status(DDNS_PRINT_INBOUND, ddns_cb, eresult); 1312 print_dns_status(DDNS_PRINT_INBOUND, ddns_cb, eresult);
1315#endif 1313#endif
1316 1314
1317 /* This transaction is complete, clear the value */ 1315 /* This transaction is complete, clear the value */
1318 dns_client_destroyupdatetrans(&ddns_cb->transaction); 1316 dns_client_destroyupdatetrans(&ddns_cb->transaction);
1319 1317
1320 /* If we cancelled or tried to cancel the operation we just 1318 /* If we cancelled or tried to cancel the operation we just
1321 * need to clean up. */ 1319 * need to clean up. */
1322 if ((eresult == ISC_R_CANCELED) || 1320 if ((eresult == ISC_R_CANCELED) ||
1323 ((ddns_cb->flags & DDNS_ABORT) != 0)) { 1321 ((ddns_cb->flags & DDNS_ABORT) != 0)) {
 1322#if defined (DEBUG_DNS_UPDATES)
 1323 log_info("DDNS: completeing transaction cancellation cb=%p, "
 1324 "flags=%x, %s",
 1325 ddns_cb, ddns_cb->flags, isc_result_totext(eresult));
 1326#endif
 1327 if ((ddns_cb->flags & DDNS_ABORT) == 0) {
 1328 log_info("DDNS: cleaning up lease pointer for a cancel "
 1329 "cb=%p", ddns_cb);
 1330 /*
 1331 * We shouldn't actually be able to get here but
 1332 * we are. This means we haven't cleaned up
 1333 * the lease pointer so we need to do that before
 1334 * freeing the cb.
 1335 */
 1336 ddns_cb->cur_func(ddns_cb, eresult);
 1337 return;
 1338 }
 1339
1324 if (ddns_cb->next_op != NULL) { 1340 if (ddns_cb->next_op != NULL) {
1325 /* if necessary cleanup up next op block */ 1341 /* if necessary cleanup up next op block */
1326 ddns_cb_free(ddns_cb->next_op, MDL); 1342 ddns_cb_free(ddns_cb->next_op, MDL);
1327 } 1343 }
1328 ddns_cb_free(ddns_cb, MDL); 1344 ddns_cb_free(ddns_cb, MDL);
1329 return; 1345 return;
1330 } 1346 }
1331 1347
1332 /* If we had a problem with our key or zone try again */ 1348 /* If we had a problem with our key or zone try again */
1333 if ((eresult == DNS_R_NOTAUTH) || 1349 if ((eresult == DNS_R_NOTAUTH) ||
1334 (eresult == DNS_R_NOTZONE)) { 1350 (eresult == DNS_R_NOTZONE)) {
1335 int i; 1351 int i;
1336 /* Our zone information was questionable, 1352 /* Our zone information was questionable,
1337 * repudiate it and try again */ 1353 * repudiate it and try again */
 1354 log_error("DDNS: bad zone information, repudiating zone %s",
 1355 ddns_cb->zone_name);
1338 repudiate_zone(&ddns_cb->zone); 1356 repudiate_zone(&ddns_cb->zone);
1339 ddns_cb->zone_name[0] = 0; 1357 ddns_cb->zone_name[0] = 0;
1340 ISC_LIST_INIT(ddns_cb->zone_server_list); 1358 ISC_LIST_INIT(ddns_cb->zone_server_list);
1341 for (i = 0; i < DHCP_MAXNS; i++) { 1359 for (i = 0; i < DHCP_MAXNS; i++) {
1342 ISC_LINK_INIT(&ddns_cb->zone_addrs[i], link); 1360 ISC_LINK_INIT(&ddns_cb->zone_addrs[i], link);
1343 } 1361 }
1344 1362
1345 if ((ddns_cb->state & 1363 if ((ddns_cb->state == DDNS_STATE_ADD_PTR) ||
1346 (DDNS_STATE_ADD_PTR | DDNS_STATE_REM_PTR)) != 0) { 1364 (ddns_cb->state == DDNS_STATE_REM_PTR)) {
1347 result = ddns_modify_ptr(ddns_cb); 1365 result = ddns_modify_ptr(ddns_cb, MDL);
1348 } else { 1366 } else {
1349 result = ddns_modify_fwd(ddns_cb); 1367 result = ddns_modify_fwd(ddns_cb, MDL);
1350 } 1368 }
1351 1369
1352 if (result != ISC_R_SUCCESS) { 1370 if (result != ISC_R_SUCCESS) {
1353 /* if we couldn't redo the query toss it */ 1371 /* if we couldn't redo the query log it and
1354 if (ddns_cb->next_op != NULL) { 1372 * let the next function clean it up */
1355 /* cleanup up next op block */ 1373 log_info("DDNS: Failed to retry after zone failure");
1356 ddns_cb_free(ddns_cb->next_op, MDL); 1374 ddns_cb->cur_func(ddns_cb, result);
1357 } 
1358 ddns_cb_free(ddns_cb, MDL); 
1359 } 1375 }
1360 return; 1376 return;
1361 } else { 1377 } else {
1362 /* pass it along to be processed */ 1378 /* pass it along to be processed */
1363 ddns_cb->cur_func(ddns_cb, eresult); 1379 ddns_cb->cur_func(ddns_cb, eresult);
1364 } 1380 }
1365  1381
1366 return; 1382 return;
1367} 1383}
1368 1384
1369/* 1385/*
1370 * This routine does the generic work for sending a ddns message to 1386 * This routine does the generic work for sending a ddns message to
1371 * modify the forward record (A or AAAA) and calls one of a set of 1387 * modify the forward record (A or AAAA) and calls one of a set of
1372 * routines to build the specific message. 1388 * routines to build the specific message.
1373 */ 1389 */
1374 1390
1375isc_result_t 1391isc_result_t
1376ddns_modify_fwd(dhcp_ddns_cb_t *ddns_cb) 1392ddns_modify_fwd(dhcp_ddns_cb_t *ddns_cb, const char *file, int line)
1377{ 1393{
1378 isc_result_t result; 1394 isc_result_t result;
1379 dns_tsec_t *tsec_key = NULL; 1395 dns_tsec_t *tsec_key = NULL;
1380 1396
1381 unsigned char *clientname; 1397 unsigned char *clientname;
1382 dhcp_ddns_data_t *dataspace = NULL; 1398 dhcp_ddns_data_t *dataspace = NULL;
1383 dns_namelist_t prereqlist, updatelist; 1399 dns_namelist_t prereqlist, updatelist;
1384 dns_fixedname_t zname0, pname0, uname0; 1400 dns_fixedname_t zname0, pname0, uname0;
1385 dns_name_t *zname = NULL, *pname, *uname; 1401 dns_name_t *zname = NULL, *pname, *uname;
1386 1402
1387 isc_sockaddrlist_t *zlist = NULL; 1403 isc_sockaddrlist_t *zlist = NULL;
1388 1404
1389 /* Get a pointer to the clientname to make things easier. */ 1405 /* Get a pointer to the clientname to make things easier. */
@@ -1533,36 +1549,43 @@ ddns_modify_fwd(dhcp_ddns_cb_t *ddns_cb) @@ -1533,36 +1549,43 @@ ddns_modify_fwd(dhcp_ddns_cb_t *ddns_cb)
1533 ddns_interlude, 1549 ddns_interlude,
1534 (void *)ddns_cb, 1550 (void *)ddns_cb,
1535 &ddns_cb->transaction); 1551 &ddns_cb->transaction);
1536 if (result == ISC_R_FAMILYNOSUPPORT) { 1552 if (result == ISC_R_FAMILYNOSUPPORT) {
1537 log_info("Unable to perform DDNS update, " 1553 log_info("Unable to perform DDNS update, "
1538 "address family not supported"); 1554 "address family not supported");
1539 } 1555 }
1540 1556
1541#if defined (DEBUG_DNS_UPDATES) 1557#if defined (DEBUG_DNS_UPDATES)
1542 print_dns_status(DDNS_PRINT_OUTBOUND, ddns_cb, result); 1558 print_dns_status(DDNS_PRINT_OUTBOUND, ddns_cb, result);
1543#endif 1559#endif
1544 1560
1545 cleanup: 1561 cleanup:
 1562#if defined (DEBUG_DNS_UPDATES)
 1563 if (result != ISC_R_SUCCESS) {
 1564 log_info("DDNS: %s(%d): error in ddns_modify_fwd %s for %p",
 1565 file, line, isc_result_totext(result), ddns_cb);
 1566 }
 1567#endif
 1568
1546 if (dataspace != NULL) { 1569 if (dataspace != NULL) {
1547 isc_mem_put(dhcp_gbl_ctx.mctx, dataspace, 1570 isc_mem_put(dhcp_gbl_ctx.mctx, dataspace,
1548 sizeof(*dataspace) * 4); 1571 sizeof(*dataspace) * 4);
1549 } 1572 }
1550 return(result); 1573 return(result);
1551} 1574}
1552 1575
1553 1576
1554isc_result_t 1577isc_result_t
1555ddns_modify_ptr(dhcp_ddns_cb_t *ddns_cb) 1578ddns_modify_ptr(dhcp_ddns_cb_t *ddns_cb, const char *file, int line)
1556{ 1579{
1557 isc_result_t result; 1580 isc_result_t result;
1558 dns_tsec_t *tsec_key = NULL; 1581 dns_tsec_t *tsec_key = NULL;
1559 unsigned char *ptrname; 1582 unsigned char *ptrname;
1560 dhcp_ddns_data_t *dataspace = NULL; 1583 dhcp_ddns_data_t *dataspace = NULL;
1561 dns_namelist_t updatelist; 1584 dns_namelist_t updatelist;
1562 dns_fixedname_t zname0, uname0; 1585 dns_fixedname_t zname0, uname0;
1563 dns_name_t *zname = NULL, *uname; 1586 dns_name_t *zname = NULL, *uname;
1564 isc_sockaddrlist_t *zlist = NULL; 1587 isc_sockaddrlist_t *zlist = NULL;
1565 unsigned char buf[256]; 1588 unsigned char buf[256];
1566 int buflen; 1589 int buflen;
1567 1590
1568 /* 1591 /*
@@ -1722,34 +1745,46 @@ ddns_modify_ptr(dhcp_ddns_cb_t *ddns_cb) @@ -1722,34 +1745,46 @@ ddns_modify_ptr(dhcp_ddns_cb_t *ddns_cb)
1722 dhcp_gbl_ctx.task, 1745 dhcp_gbl_ctx.task,
1723 ddns_interlude, (void *)ddns_cb, 1746 ddns_interlude, (void *)ddns_cb,
1724 &ddns_cb->transaction); 1747 &ddns_cb->transaction);
1725 if (result == ISC_R_FAMILYNOSUPPORT) { 1748 if (result == ISC_R_FAMILYNOSUPPORT) {
1726 log_info("Unable to perform DDNS update, " 1749 log_info("Unable to perform DDNS update, "
1727 "address family not supported"); 1750 "address family not supported");
1728 } 1751 }
1729 1752
1730#if defined (DEBUG_DNS_UPDATES) 1753#if defined (DEBUG_DNS_UPDATES)
1731 print_dns_status(DDNS_PRINT_OUTBOUND, ddns_cb, result); 1754 print_dns_status(DDNS_PRINT_OUTBOUND, ddns_cb, result);
1732#endif 1755#endif
1733 1756
1734 cleanup: 1757 cleanup:
 1758#if defined (DEBUG_DNS_UPDATES)
 1759 if (result != ISC_R_SUCCESS) {
 1760 log_info("DDNS: %s(%d): error in ddns_modify_ptr %s for %p",
 1761 file, line, isc_result_totext(result), ddns_cb);
 1762 }
 1763#endif
 1764
1735 if (dataspace != NULL) { 1765 if (dataspace != NULL) {
1736 isc_mem_put(dhcp_gbl_ctx.mctx, dataspace, 1766 isc_mem_put(dhcp_gbl_ctx.mctx, dataspace,
1737 sizeof(*dataspace) * 2); 1767 sizeof(*dataspace) * 2);
1738 } 1768 }
1739 return(result); 1769 return(result);
1740} 1770}
1741 1771
1742void 1772void
1743ddns_cancel(dhcp_ddns_cb_t *ddns_cb) { 1773ddns_cancel(dhcp_ddns_cb_t *ddns_cb, const char *file, int line) {
1744 ddns_cb->flags |= DDNS_ABORT; 1774 ddns_cb->flags |= DDNS_ABORT;
1745 if (ddns_cb->transaction != NULL) { 1775 if (ddns_cb->transaction != NULL) {
1746 dns_client_cancelupdate((dns_clientupdatetrans_t *) 1776 dns_client_cancelupdate((dns_clientupdatetrans_t *)
1747 ddns_cb->transaction); 1777 ddns_cb->transaction);
1748 } 1778 }
1749 ddns_cb->lease = NULL; 1779 ddns_cb->lease = NULL;
 1780
 1781#if defined (DEBUG_DNS_UPDATES)
 1782 log_info("DDNS: %s(%d): cancelling transaction for %p",
 1783 file, line, ddns_cb);
 1784#endif
1750} 1785}
1751 1786
1752#endif /* NSUPDATE */ 1787#endif /* NSUPDATE */
1753 1788
1754HASH_FUNCTIONS (dns_zone, const char *, struct dns_zone, dns_zone_hash_t, 1789HASH_FUNCTIONS (dns_zone, const char *, struct dns_zone, dns_zone_hash_t,
1755 dns_zone_reference, dns_zone_dereference, do_case_hash) 1790 dns_zone_reference, dns_zone_dereference, do_case_hash)

cvs diff -r1.2 -r1.3 src/external/bsd/dhcp/dist/common/Attic/ns_name.c (expand / switch to unified diff)

--- src/external/bsd/dhcp/dist/common/Attic/ns_name.c 2013/03/24 15:53:58 1.2
+++ src/external/bsd/dhcp/dist/common/Attic/ns_name.c 2013/03/24 23:03:06 1.3
@@ -1,40 +1,40 @@ @@ -1,40 +1,40 @@
1/* $NetBSD: ns_name.c,v 1.2 2013/03/24 15:53:58 christos Exp $ */ 1/* $NetBSD: ns_name.c,v 1.3 2013/03/24 23:03:06 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2004,2009 by Internet Systems Consortium, Inc. ("ISC") 4 * Copyright (c) 2004,2009 by Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (c) 1996-2003 by Internet Software Consortium 5 * Copyright (c) 1996-2003 by Internet Software Consortium
6 * 6 *
7 * Permission to use, copy, modify, and distribute this software for any 7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above 8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies. 9 * copyright notice and this permission notice appear in all copies.
10 * 10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
17 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 * 18 *
19 * Internet Systems Consortium, Inc. 19 * Internet Systems Consortium, Inc.
20 * 950 Charter Street 20 * 950 Charter Street
21 * Redwood City, CA 94063 21 * Redwood City, CA 94063
22 * <info@isc.org> 22 * <info@isc.org>
23 * http://www.isc.org/ 23 * http://www.isc.org/
24 */ 24 */
25 25
26#ifndef lint 26#ifndef lint
27static const char rcsid[] = "Id: ns_name.c,v 1.2 2009-10-28 04:12:29 sar Exp "; 27static const char rcsid[] = "Id: ns_name.c,v 1.2 2009/10/28 04:12:29 sar Exp ";
28#endif 28#endif
29 29
30#include <sys/types.h> 30#include <sys/types.h>
31 31
32#include <netinet/in.h> 32#include <netinet/in.h>
33#include <sys/socket.h> 33#include <sys/socket.h>
34 34
35#include <errno.h> 35#include <errno.h>
36#include <string.h> 36#include <string.h>
37#include <ctype.h> 37#include <ctype.h>
38 38
39#include "minires.h" 39#include "minires.h"
40#include "arpa/nameser.h" 40#include "arpa/nameser.h"

cvs diff -r1.3 -r1.4 src/external/bsd/dhcp/dist/dst/Attic/base64.c (expand / switch to unified diff)

--- src/external/bsd/dhcp/dist/dst/Attic/base64.c 2013/03/24 16:27:58 1.3
+++ src/external/bsd/dhcp/dist/dst/Attic/base64.c 2013/03/24 23:03:06 1.4
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: base64.c,v 1.3 2013/03/24 16:27:58 christos Exp $ */ 1/* $NetBSD: base64.c,v 1.4 2013/03/24 23:03:06 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2004,2009 by Internet Systems Consortium, Inc. ("ISC") 4 * Copyright (c) 2004,2009 by Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (c) 1996-2003 by Internet Software Consortium 5 * Copyright (c) 1996-2003 by Internet Software Consortium
6 * 6 *
7 * Permission to use, copy, modify, and distribute this software for any 7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above 8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies. 9 * copyright notice and this permission notice appear in all copies.
10 * 10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
@@ -39,27 +39,27 @@ @@ -39,27 +39,27 @@
39 * the extent that such products are used for performing Domain Name System 39 * the extent that such products are used for performing Domain Name System
40 * dynamic updates in TCP/IP networks by means of the Software. No immunity is 40 * dynamic updates in TCP/IP networks by means of the Software. No immunity is
41 * granted for any product per se or for any other function of any product. 41 * granted for any product per se or for any other function of any product.
42 * 42 *
43 * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES, 43 * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
44 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 44 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
45 * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, 45 * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
46 * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING 46 * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
47 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN 47 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
48 * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. 48 * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
49 */ 49 */
50 50
51#if !defined(LINT) && !defined(CODECENTER) 51#if !defined(LINT) && !defined(CODECENTER)
52static const char rcsid[] = "Id: base64.c,v 1.5.6.1 2009-11-20 01:49:01 sar Exp "; 52static const char rcsid[] = "Id: base64.c,v 1.5.6.1 2009/11/20 01:49:01 sar Exp ";
53#endif /* not lint */ 53#endif /* not lint */
54 54
55#include <sys/types.h> 55#include <sys/types.h>
56#include <sys/param.h> 56#include <sys/param.h>
57#include <sys/socket.h> 57#include <sys/socket.h>
58 58
59#include <netinet/in.h> 59#include <netinet/in.h>
60#include <arpa/inet.h> 60#include <arpa/inet.h>
61 61
62#include <ctype.h> 62#include <ctype.h>
63#include <stdio.h> 63#include <stdio.h>
64#include <stdlib.h> 64#include <stdlib.h>
65#include <string.h> 65#include <string.h>

cvs diff -r1.1.1.2 -r1.2 src/external/bsd/dhcp/dist/dst/Attic/dst_api.c (expand / switch to unified diff)

--- src/external/bsd/dhcp/dist/dst/Attic/dst_api.c 2013/03/24 22:50:33 1.1.1.2
+++ src/external/bsd/dhcp/dist/dst/Attic/dst_api.c 2013/03/24 23:03:06 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dst_api.c,v 1.1.1.2 2013/03/24 22:50:33 christos Exp $ */ 1/* $NetBSD: dst_api.c,v 1.2 2013/03/24 23:03:06 christos Exp $ */
2 2
3#ifndef LINT 3#ifndef LINT
4static const char rcsid[] = "Header: /tmp/cvstest/DHCP/dst/dst_api.c,v 1.9.6.1 2012/04/11 15:43:55 sar Exp "; 4static const char rcsid[] = "Header: /tmp/cvstest/DHCP/dst/dst_api.c,v 1.9.6.1 2012/04/11 15:43:55 sar Exp ";
5#endif 5#endif
6 6
7/* 7/*
8 * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc. 8 * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc.
9 * Portions Copyright (c) 2007,2009 by Internet Systems Consortium, Inc. ("ISC") 9 * Portions Copyright (c) 2007,2009 by Internet Systems Consortium, Inc. ("ISC")
10 * Portions Copyright (c) 2012 by Internet Systems Consortium, Inc. ("ISC") 10 * Portions Copyright (c) 2012 by Internet Systems Consortium, Inc. ("ISC")
11 * 11 *
12 * Permission to use, copy modify, and distribute this software for any 12 * Permission to use, copy modify, and distribute this software for any
13 * purpose with or without fee is hereby granted, provided that the above 13 * purpose with or without fee is hereby granted, provided that the above
14 * copyright notice and this permission notice appear in all copies. 14 * copyright notice and this permission notice appear in all copies.
@@ -1007,27 +1007,27 @@ DST_KEY * @@ -1007,27 +1007,27 @@ DST_KEY *
1007dst_free_key(DST_KEY *f_key) 1007dst_free_key(DST_KEY *f_key)
1008{ 1008{
1009 1009
1010 if (f_key == NULL) 1010 if (f_key == NULL)
1011 return (f_key); 1011 return (f_key);
1012 if (f_key->dk_func && f_key->dk_func->destroy) 1012 if (f_key->dk_func && f_key->dk_func->destroy)
1013 f_key->dk_KEY_struct = 1013 f_key->dk_KEY_struct =
1014 f_key->dk_func->destroy(f_key->dk_KEY_struct); 1014 f_key->dk_func->destroy(f_key->dk_KEY_struct);
1015 else { 1015 else {
1016 EREPORT(("dst_free_key(): Unknown key alg %d\n", 1016 EREPORT(("dst_free_key(): Unknown key alg %d\n",
1017 f_key->dk_alg)); 1017 f_key->dk_alg));
1018 } 1018 }
1019 if (f_key->dk_KEY_struct) { 1019 if (f_key->dk_KEY_struct) {
1020 SAFE_FREE(f_key->dk_KEY_struct); 1020 SAFE_FREE2(f_key->dk_KEY_struct, 0);
1021 } 1021 }
1022 if (f_key->dk_key_name) 1022 if (f_key->dk_key_name)
1023 SAFE_FREE(f_key->dk_key_name); 1023 SAFE_FREE(f_key->dk_key_name);
1024 SAFE_FREE(f_key); 1024 SAFE_FREE(f_key);
1025 return (NULL); 1025 return (NULL);
1026} 1026}
1027 1027
1028/* 1028/*
1029 * dst_sig_size 1029 * dst_sig_size
1030 * Return the maximum size of signature from the key specified in bytes 1030 * Return the maximum size of signature from the key specified in bytes
1031 * Parameters 1031 * Parameters
1032 * key  1032 * key
1033 * Returns 1033 * Returns

cvs diff -r1.2 -r1.3 src/external/bsd/dhcp/dist/includes/Attic/dhcpd.h (expand / switch to unified diff)

--- src/external/bsd/dhcp/dist/includes/Attic/dhcpd.h 2013/03/24 15:53:58 1.2
+++ src/external/bsd/dhcp/dist/includes/Attic/dhcpd.h 2013/03/24 23:03:06 1.3
@@ -1,21 +1,21 @@ @@ -1,21 +1,21 @@
1/* $NetBSD: dhcpd.h,v 1.2 2013/03/24 15:53:58 christos Exp $ */ 1/* $NetBSD: dhcpd.h,v 1.3 2013/03/24 23:03:06 christos Exp $ */
2 2
3/* dhcpd.h 3/* dhcpd.h
4 4
5 Definitions for dhcpd... */ 5 Definitions for dhcpd... */
6 6
7/* 7/*
8 * Copyright (c) 2004-2011 by Internet Systems Consortium, Inc. ("ISC") 8 * Copyright (c) 2004-2012 by Internet Systems Consortium, Inc. ("ISC")
9 * Copyright (c) 1996-2003 by Internet Software Consortium 9 * Copyright (c) 1996-2003 by Internet Software Consortium
10 * 10 *
11 * Permission to use, copy, modify, and distribute this software for any 11 * Permission to use, copy, modify, and distribute this software for any
12 * purpose with or without fee is hereby granted, provided that the above 12 * purpose with or without fee is hereby granted, provided that the above
13 * copyright notice and this permission notice appear in all copies. 13 * copyright notice and this permission notice appear in all copies.
14 * 14 *
15 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 15 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
16 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 16 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 17 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
18 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 18 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 20 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 21 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * Redwood City, CA 94063 25 * Redwood City, CA 94063
26 * <info@isc.org> 26 * <info@isc.org>
27 * https://www.isc.org/ 27 * https://www.isc.org/
28 * 28 *
29 * This software has been written for Internet Systems Consortium 29 * This software has been written for Internet Systems Consortium
30 * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc. 30 * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
31 * To learn more about Internet Systems Consortium, see 31 * To learn more about Internet Systems Consortium, see
32 * ``https://www.isc.org/''. To learn more about Vixie Enterprises, 32 * ``https://www.isc.org/''. To learn more about Vixie Enterprises,
33 * see ``http://www.vix.com''. To learn more about Nominum, Inc., see 33 * see ``http://www.vix.com''. To learn more about Nominum, Inc., see
34 * ``http://www.nominum.com''. 34 * ``http://www.nominum.com''.
35 */ 35 */
36 36
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38__RCSID("$NetBSD: dhcpd.h,v 1.2 2013/03/24 15:53:58 christos Exp $"); 38__RCSID("$NetBSD: dhcpd.h,v 1.3 2013/03/24 23:03:06 christos Exp $");
39 39
40#include "config.h" 40#include "config.h"
41 41
42#ifndef __CYGWIN32__ 42#ifndef __CYGWIN32__
43#include <sys/types.h> 43#include <sys/types.h>
44#include <netinet/in.h> 44#include <netinet/in.h>
45#include <sys/socket.h> 45#include <sys/socket.h>
46#include <sys/un.h> 46#include <sys/un.h>
47#include <arpa/inet.h> 47#include <arpa/inet.h>
48#include <errno.h> 48#include <errno.h>
49 49
50#include <netdb.h> 50#include <netdb.h>
51#else 51#else
@@ -427,31 +427,37 @@ struct packet { @@ -427,31 +427,37 @@ struct packet {
427 /* If we stash agent options onto the packet option state, to pretend 427 /* If we stash agent options onto the packet option state, to pretend
428 * options we got in a previous exchange were still there, we need 428 * options we got in a previous exchange were still there, we need
429 * to signal this in a reliable way. 429 * to signal this in a reliable way.
430 */ 430 */
431 isc_boolean_t agent_options_stashed; 431 isc_boolean_t agent_options_stashed;
432 432
433 /* 433 /*
434 * ISC_TRUE if packet received unicast (as opposed to multicast). 434 * ISC_TRUE if packet received unicast (as opposed to multicast).
435 * Only used in DHCPv6. 435 * Only used in DHCPv6.
436 */ 436 */
437 isc_boolean_t unicast; 437 isc_boolean_t unicast;
438}; 438};
439 439
440/* A network interface's MAC address. */ 440/*
 441 * A network interface's MAC address.
 442 * 20 bytes for the hardware address
 443 * and 1 byte for the type tag
 444 */
 445
 446#define HARDWARE_ADDR_LEN 20
441 447
442struct hardware { 448struct hardware {
443 u_int8_t hlen; 449 u_int8_t hlen;
444 u_int8_t hbuf [17]; 450 u_int8_t hbuf[HARDWARE_ADDR_LEN + 1];
445}; 451};
446 452
447#if defined(LDAP_CONFIGURATION) 453#if defined(LDAP_CONFIGURATION)
448# define LDAP_BUFFER_SIZE 8192 454# define LDAP_BUFFER_SIZE 8192
449# define LDAP_METHOD_STATIC 0 455# define LDAP_METHOD_STATIC 0
450# define LDAP_METHOD_DYNAMIC 1 456# define LDAP_METHOD_DYNAMIC 1
451#if defined (LDAP_USE_SSL) 457#if defined (LDAP_USE_SSL)
452# define LDAP_SSL_OFF 0 458# define LDAP_SSL_OFF 0
453# define LDAP_SSL_ON 1 459# define LDAP_SSL_ON 1
454# define LDAP_SSL_TLS 2 460# define LDAP_SSL_TLS 2
455# define LDAP_SSL_LDAPS 3 461# define LDAP_SSL_LDAPS 3
456#endif 462#endif
457 463
@@ -1552,27 +1558,27 @@ struct ipv6_pool { @@ -1552,27 +1558,27 @@ struct ipv6_pool {
1552 this pool */ 1558 this pool */
1553 struct subnet *subnet; /* subnet for this pool */ 1559 struct subnet *subnet; /* subnet for this pool */
1554}; 1560};
1555 1561
1556/* Flags and state for dhcp_ddns_cb_t */ 1562/* Flags and state for dhcp_ddns_cb_t */
1557#define DDNS_UPDATE_ADDR 0x01 1563#define DDNS_UPDATE_ADDR 0x01
1558#define DDNS_UPDATE_PTR 0x02 1564#define DDNS_UPDATE_PTR 0x02
1559#define DDNS_INCLUDE_RRSET 0x04 1565#define DDNS_INCLUDE_RRSET 0x04
1560#define DDNS_CONFLICT_OVERRIDE 0x08 1566#define DDNS_CONFLICT_OVERRIDE 0x08
1561#define DDNS_CLIENT_DID_UPDATE 0x10 1567#define DDNS_CLIENT_DID_UPDATE 0x10
1562#define DDNS_EXECUTE_NEXT 0x20 1568#define DDNS_EXECUTE_NEXT 0x20
1563#define DDNS_ABORT 0x40 1569#define DDNS_ABORT 0x40
1564#define DDNS_STATIC_LEASE 0x80 1570#define DDNS_STATIC_LEASE 0x80
1565 1571#define DDNS_ACTIVE_LEASE 0x100
1566/* 1572/*
1567 * The following two groups are separate and we could reuse 1573 * The following two groups are separate and we could reuse
1568 * values but not reusing them may be useful in the future. 1574 * values but not reusing them may be useful in the future.
1569 */ 1575 */
1570#define DDNS_STATE_CLEANUP 0 // The previous step failed, cleanup 1576#define DDNS_STATE_CLEANUP 0 // The previous step failed, cleanup
1571 1577
1572#define DDNS_STATE_ADD_FW_NXDOMAIN 1 1578#define DDNS_STATE_ADD_FW_NXDOMAIN 1
1573#define DDNS_STATE_ADD_FW_YXDHCID 2 1579#define DDNS_STATE_ADD_FW_YXDHCID 2
1574#define DDNS_STATE_ADD_PTR 3 1580#define DDNS_STATE_ADD_PTR 3
1575 1581
1576#define DDNS_STATE_REM_FW_YXDHCID 17 1582#define DDNS_STATE_REM_FW_YXDHCID 17
1577#define DDNS_STATE_REM_FW_NXRR 18 1583#define DDNS_STATE_REM_FW_NXRR 18
1578#define DDNS_STATE_REM_PTR 19 1584#define DDNS_STATE_REM_PTR 19
@@ -1593,27 +1599,27 @@ typedef struct dhcp_ddns_cb { @@ -1593,27 +1599,27 @@ typedef struct dhcp_ddns_cb {
1593 struct data_string rev_name; 1599 struct data_string rev_name;
1594 struct data_string dhcid; 1600 struct data_string dhcid;
1595 struct iaddr address; 1601 struct iaddr address;
1596 int address_type; 1602 int address_type;
1597 1603
1598 unsigned long ttl; 1604 unsigned long ttl;
1599 1605
1600 unsigned char zone_name[DHCP_MAXDNS_WIRE]; 1606 unsigned char zone_name[DHCP_MAXDNS_WIRE];
1601 isc_sockaddrlist_t zone_server_list; 1607 isc_sockaddrlist_t zone_server_list;
1602 isc_sockaddr_t zone_addrs[DHCP_MAXNS]; 1608 isc_sockaddr_t zone_addrs[DHCP_MAXNS];
1603 int zone_addr_count; 1609 int zone_addr_count;
1604 struct dns_zone *zone; 1610 struct dns_zone *zone;
1605 1611
1606 int flags; 1612 u_int16_t flags;
1607 TIME timeout; 1613 TIME timeout;
1608 int state; 1614 int state;
1609 ddns_action_t cur_func; 1615 ddns_action_t cur_func;
1610 1616
1611 struct dhcp_ddns_cb * next_op; 1617 struct dhcp_ddns_cb * next_op;
1612 1618
1613 /* Lease or client state that triggered the ddns operation */ 1619 /* Lease or client state that triggered the ddns operation */
1614 void *lease; 1620 void *lease;
1615 struct binding_scope **scope; 1621 struct binding_scope **scope;
1616 1622
1617 void *transaction; 1623 void *transaction;
1618 void *dataspace; 1624 void *dataspace;
1619} dhcp_ddns_cb_t; 1625} dhcp_ddns_cb_t;
@@ -1848,26 +1854,28 @@ int linked_option_space_encapsulate (str @@ -1848,26 +1854,28 @@ int linked_option_space_encapsulate (str
1848 struct option_state *, 1854 struct option_state *,
1849 struct binding_scope **, 1855 struct binding_scope **,
1850 struct universe *); 1856 struct universe *);
1851void delete_linked_option (struct universe *, struct option_state *, int); 1857void delete_linked_option (struct universe *, struct option_state *, int);
1852struct option_cache *lookup_linked_option (struct universe *, 1858struct option_cache *lookup_linked_option (struct universe *,
1853 struct option_state *, unsigned); 1859 struct option_state *, unsigned);
1854void do_packet (struct interface_info *, 1860void do_packet (struct interface_info *,
1855 struct dhcp_packet *, unsigned, 1861 struct dhcp_packet *, unsigned,
1856 unsigned int, struct iaddr, struct hardware *); 1862 unsigned int, struct iaddr, struct hardware *);
1857void do_packet6(struct interface_info *, const char *, 1863void do_packet6(struct interface_info *, const char *,
1858 int, int, const struct iaddr *, isc_boolean_t); 1864 int, int, const struct iaddr *, isc_boolean_t);
1859int packet6_len_okay(const char *, int); 1865int packet6_len_okay(const char *, int);
1860 1866
 1867int validate_packet(struct packet *);
 1868
1861int add_option(struct option_state *options, 1869int add_option(struct option_state *options,
1862 unsigned int option_num, 1870 unsigned int option_num,
1863 void *data, 1871 void *data,
1864 unsigned int data_len); 1872 unsigned int data_len);
1865 1873
1866/* dhcpd.c */ 1874/* dhcpd.c */
1867extern struct timeval cur_tv; 1875extern struct timeval cur_tv;
1868#define cur_time cur_tv.tv_sec 1876#define cur_time cur_tv.tv_sec
1869 1877
1870extern int ddns_update_style; 1878extern int ddns_update_style;
1871 1879
1872extern const char *path_dhcpd_conf; 1880extern const char *path_dhcpd_conf;
1873extern const char *path_dhcpd_db; 1881extern const char *path_dhcpd_db;
@@ -1945,27 +1953,28 @@ void parse_address_range (struct parse * @@ -1945,27 +1953,28 @@ void parse_address_range (struct parse *
1945 struct pool *, struct lease **); 1953 struct pool *, struct lease **);
1946void parse_address_range6(struct parse *cfile, struct group *group); 1954void parse_address_range6(struct parse *cfile, struct group *group);
1947void parse_prefix6(struct parse *cfile, struct group *group); 1955void parse_prefix6(struct parse *cfile, struct group *group);
1948void parse_fixed_prefix6(struct parse *cfile, struct host_decl *host_decl); 1956void parse_fixed_prefix6(struct parse *cfile, struct host_decl *host_decl);
1949void parse_ia_na_declaration(struct parse *); 1957void parse_ia_na_declaration(struct parse *);
1950void parse_ia_ta_declaration(struct parse *); 1958void parse_ia_ta_declaration(struct parse *);
1951void parse_ia_pd_declaration(struct parse *); 1959void parse_ia_pd_declaration(struct parse *);
1952void parse_server_duid(struct parse *cfile); 1960void parse_server_duid(struct parse *cfile);
1953void parse_server_duid_conf(struct parse *cfile); 1961void parse_server_duid_conf(struct parse *cfile);
1954 1962
1955/* ddns.c */ 1963/* ddns.c */
1956int ddns_updates(struct packet *, struct lease *, struct lease *, 1964int ddns_updates(struct packet *, struct lease *, struct lease *,
1957 struct iasubopt *, struct iasubopt *, struct option_state *); 1965 struct iasubopt *, struct iasubopt *, struct option_state *);
1958int ddns_removals(struct lease *, struct iasubopt *, struct dhcp_ddns_cb *); 1966isc_result_t ddns_removals(struct lease *, struct iasubopt *,
 1967 struct dhcp_ddns_cb *, isc_boolean_t);
1959#if defined (TRACING) 1968#if defined (TRACING)
1960void trace_ddns_init(void); 1969void trace_ddns_init(void);
1961#endif 1970#endif
1962 1971
1963/* parse.c */ 1972/* parse.c */
1964void add_enumeration (struct enumeration *); 1973void add_enumeration (struct enumeration *);
1965struct enumeration *find_enumeration (const char *, int); 1974struct enumeration *find_enumeration (const char *, int);
1966struct enumeration_value *find_enumeration_value (const char *, int, 1975struct enumeration_value *find_enumeration_value (const char *, int,
1967 unsigned *, 1976 unsigned *,
1968 const char *); 1977 const char *);
1969void skip_to_semi (struct parse *); 1978void skip_to_semi (struct parse *);
1970void skip_to_rbrace (struct parse *, int); 1979void skip_to_rbrace (struct parse *, int);
1971int parse_semi (struct parse *); 1980int parse_semi (struct parse *);
@@ -2167,27 +2176,31 @@ int mockup_lease (struct lease **, struc @@ -2167,27 +2176,31 @@ int mockup_lease (struct lease **, struc
2167 struct host_decl *); 2176 struct host_decl *);
2168void static_lease_dereference (struct lease *, const char *, int); 2177void static_lease_dereference (struct lease *, const char *, int);
2169 2178
2170int allocate_lease (struct lease **, struct packet *, 2179int allocate_lease (struct lease **, struct packet *,
2171 struct pool *, int *); 2180 struct pool *, int *);
2172int permitted (struct packet *, struct permit *); 2181int permitted (struct packet *, struct permit *);
2173int locate_network (struct packet *); 2182int locate_network (struct packet *);
2174int parse_agent_information_option (struct packet *, int, u_int8_t *); 2183int parse_agent_information_option (struct packet *, int, u_int8_t *);
2175unsigned cons_agent_information_options (struct option_state *, 2184unsigned cons_agent_information_options (struct option_state *,
2176 struct dhcp_packet *, 2185 struct dhcp_packet *,
2177 unsigned, unsigned); 2186 unsigned, unsigned);
2178void get_server_source_address(struct in_addr *from, 2187void get_server_source_address(struct in_addr *from,
2179 struct option_state *options, 2188 struct option_state *options,
 2189 struct option_state *out_options,
2180 struct packet *packet); 2190 struct packet *packet);
 2191void setup_server_source_address(struct in_addr *from,
 2192 struct option_state *options,
 2193 struct packet *packet);
2181 2194
2182/* dhcpleasequery.c */ 2195/* dhcpleasequery.c */
2183void dhcpleasequery (struct packet *, int); 2196void dhcpleasequery (struct packet *, int);
2184void dhcpv6_leasequery (struct data_string *, struct packet *); 2197void dhcpv6_leasequery (struct data_string *, struct packet *);
2185 2198
2186/* dhcpv6.c */ 2199/* dhcpv6.c */
2187isc_boolean_t server_duid_isset(void); 2200isc_boolean_t server_duid_isset(void);
2188void copy_server_duid(struct data_string *ds, const char *file, int line); 2201void copy_server_duid(struct data_string *ds, const char *file, int line);
2189void set_server_duid(struct data_string *new_duid); 2202void set_server_duid(struct data_string *new_duid);
2190isc_result_t set_server_duid_from_option(void); 2203isc_result_t set_server_duid_from_option(void);
2191void set_server_duid_type(int type); 2204void set_server_duid_type(int type);
2192isc_result_t generate_new_server_duid(void); 2205isc_result_t generate_new_server_duid(void);
2193isc_result_t get_client_id(struct packet *, struct data_string *); 2206isc_result_t get_client_id(struct packet *, struct data_string *);
@@ -2725,26 +2738,27 @@ int write_client_lease (struct client_st @@ -2725,26 +2738,27 @@ int write_client_lease (struct client_st
2725isc_result_t write_client6_lease(struct client_state *client, 2738isc_result_t write_client6_lease(struct client_state *client,
2726 struct dhc6_lease *lease, 2739 struct dhc6_lease *lease,
2727 int rewrite, int sync); 2740 int rewrite, int sync);
2728int dhcp_option_ev_name (char *, size_t, struct option *); 2741int dhcp_option_ev_name (char *, size_t, struct option *);
2729 2742
2730void script_init (struct client_state *, const char *, 2743void script_init (struct client_state *, const char *,
2731 struct string_list *); 2744 struct string_list *);
2732void client_option_envadd (struct option_cache *, struct packet *, 2745void client_option_envadd (struct option_cache *, struct packet *,
2733 struct lease *, struct client_state *, 2746 struct lease *, struct client_state *,
2734 struct option_state *, struct option_state *, 2747 struct option_state *, struct option_state *,
2735 struct binding_scope **, struct universe *, void *); 2748 struct binding_scope **, struct universe *, void *);
2736void script_write_params (struct client_state *, const char *, 2749void script_write_params (struct client_state *, const char *,
2737 struct client_lease *); 2750 struct client_lease *);
 2751void script_write_requested (struct client_state *);
2738int script_go (struct client_state *); 2752int script_go (struct client_state *);
2739void client_envadd (struct client_state *, 2753void client_envadd (struct client_state *,
2740 const char *, const char *, const char *, ...) 2754 const char *, const char *, const char *, ...)
2741 __attribute__((__format__(__printf__,4,5))); 2755 __attribute__((__format__(__printf__,4,5)));
2742 2756
2743struct client_lease *packet_to_lease (struct packet *, struct client_state *); 2757struct client_lease *packet_to_lease (struct packet *, struct client_state *);
2744void go_daemon (void); 2758void go_daemon (void);
2745void write_client_pid_file (void); 2759void write_client_pid_file (void);
2746void client_location_changed (void); 2760void client_location_changed (void);
2747void do_release (struct client_state *); 2761void do_release (struct client_state *);
2748int dhclient_interface_shutdown_hook (struct interface_info *); 2762int dhclient_interface_shutdown_hook (struct interface_info *);
2749int dhclient_interface_discovery_hook (struct interface_info *); 2763int dhclient_interface_discovery_hook (struct interface_info *);
2750isc_result_t dhclient_interface_startup_hook (struct interface_info *); 2764isc_result_t dhclient_interface_startup_hook (struct interface_info *);
@@ -2773,26 +2787,27 @@ int write_lease (struct lease *); @@ -2773,26 +2787,27 @@ int write_lease (struct lease *);
2773int write_host (struct host_decl *); 2787int write_host (struct host_decl *);
2774int write_server_duid(void); 2788int write_server_duid(void);
2775#if defined (FAILOVER_PROTOCOL) 2789#if defined (FAILOVER_PROTOCOL)
2776int write_failover_state (dhcp_failover_state_t *); 2790int write_failover_state (dhcp_failover_state_t *);
2777#endif 2791#endif
2778int db_printable (const unsigned char *); 2792int db_printable (const unsigned char *);
2779int db_printable_len (const unsigned char *, unsigned); 2793int db_printable_len (const unsigned char *, unsigned);
2780isc_result_t write_named_billing_class(const void *, unsigned, void *); 2794isc_result_t write_named_billing_class(const void *, unsigned, void *);
2781void write_billing_classes (void); 2795void write_billing_classes (void);
2782int write_billing_class (struct class *); 2796int write_billing_class (struct class *);
2783void commit_leases_timeout (void *); 2797void commit_leases_timeout (void *);
2784void commit_leases_readerdry(void *); 2798void commit_leases_readerdry(void *);
2785int commit_leases (void); 2799int commit_leases (void);
 2800int commit_leases_timed (void);
2786void db_startup (int); 2801void db_startup (int);
2787int new_lease_file (void); 2802int new_lease_file (void);
2788int group_writer (struct group_object *); 2803int group_writer (struct group_object *);
2789int write_ia(const struct ia_xx *); 2804int write_ia(const struct ia_xx *);
2790 2805
2791/* packet.c */ 2806/* packet.c */
2792u_int32_t checksum (unsigned char *, unsigned, u_int32_t); 2807u_int32_t checksum (unsigned char *, unsigned, u_int32_t);
2793u_int32_t wrapsum (u_int32_t); 2808u_int32_t wrapsum (u_int32_t);
2794void assemble_hw_header (struct interface_info *, unsigned char *, 2809void assemble_hw_header (struct interface_info *, unsigned char *,
2795 unsigned *, struct hardware *); 2810 unsigned *, struct hardware *);
2796void assemble_udp_ip_header (struct interface_info *, unsigned char *, 2811void assemble_udp_ip_header (struct interface_info *, unsigned char *,
2797 unsigned *, u_int32_t, u_int32_t, 2812 unsigned *, u_int32_t, u_int32_t,
2798 u_int32_t, unsigned char *, unsigned); 2813 u_int32_t, unsigned char *, unsigned);
@@ -3238,27 +3253,30 @@ int find_grouped_subnet (struct subnet * @@ -3238,27 +3253,30 @@ int find_grouped_subnet (struct subnet *
3238int find_subnet(struct subnet **, struct iaddr, const char *, int); 3253int find_subnet(struct subnet **, struct iaddr, const char *, int);
3239void enter_shared_network (struct shared_network *); 3254void enter_shared_network (struct shared_network *);
3240void new_shared_network_interface (struct parse *, 3255void new_shared_network_interface (struct parse *,
3241 struct shared_network *, 3256 struct shared_network *,
3242 const char *); 3257 const char *);
3243int subnet_inner_than(const struct subnet *, const struct subnet *, int); 3258int subnet_inner_than(const struct subnet *, const struct subnet *, int);
3244void enter_subnet (struct subnet *); 3259void enter_subnet (struct subnet *);
3245void enter_lease (struct lease *); 3260void enter_lease (struct lease *);
3246int supersede_lease (struct lease *, struct lease *, int, int, int); 3261int supersede_lease (struct lease *, struct lease *, int, int, int);
3247void make_binding_state_transition (struct lease *); 3262void make_binding_state_transition (struct lease *);
3248int lease_copy (struct lease **, struct lease *, const char *, int); 3263int lease_copy (struct lease **, struct lease *, const char *, int);
3249void release_lease (struct lease *, struct packet *); 3264void release_lease (struct lease *, struct packet *);
3250void abandon_lease (struct lease *, const char *); 3265void abandon_lease (struct lease *, const char *);
 3266#if 0
 3267/* this appears to be unused and I plan to remove it SAR */
3251void dissociate_lease (struct lease *); 3268void dissociate_lease (struct lease *);
 3269#endif
3252void pool_timer (void *); 3270void pool_timer (void *);
3253int find_lease_by_uid (struct lease **, const unsigned char *, 3271int find_lease_by_uid (struct lease **, const unsigned char *,
3254 unsigned, const char *, int); 3272 unsigned, const char *, int);
3255int find_lease_by_hw_addr (struct lease **, const unsigned char *, 3273int find_lease_by_hw_addr (struct lease **, const unsigned char *,
3256 unsigned, const char *, int); 3274 unsigned, const char *, int);
3257int find_lease_by_ip_addr (struct lease **, struct iaddr, 3275int find_lease_by_ip_addr (struct lease **, struct iaddr,
3258 const char *, int); 3276 const char *, int);
3259void uid_hash_add (struct lease *); 3277void uid_hash_add (struct lease *);
3260void uid_hash_delete (struct lease *); 3278void uid_hash_delete (struct lease *);
3261void hw_hash_add (struct lease *); 3279void hw_hash_add (struct lease *);
3262void hw_hash_delete (struct lease *); 3280void hw_hash_delete (struct lease *);
3263int write_leases (void); 3281int write_leases (void);
3264int write_leases6(void); 3282int write_leases6(void);
@@ -3504,29 +3522,33 @@ isc_result_t create_lease6(struct ipv6_p @@ -3504,29 +3522,33 @@ isc_result_t create_lease6(struct ipv6_p
3504 unsigned int *attempts, 3522 unsigned int *attempts,
3505 const struct data_string *uid, 3523 const struct data_string *uid,
3506 time_t soft_lifetime_end_time); 3524 time_t soft_lifetime_end_time);
3507isc_result_t add_lease6(struct ipv6_pool *pool, 3525isc_result_t add_lease6(struct ipv6_pool *pool,
3508 struct iasubopt *lease, 3526 struct iasubopt *lease,
3509 time_t valid_lifetime_end_time); 3527 time_t valid_lifetime_end_time);
3510isc_result_t renew_lease6(struct ipv6_pool *pool, struct iasubopt *lease); 3528isc_result_t renew_lease6(struct ipv6_pool *pool, struct iasubopt *lease);
3511isc_result_t expire_lease6(struct iasubopt **leasep, 3529isc_result_t expire_lease6(struct iasubopt **leasep,
3512 struct ipv6_pool *pool, time_t now); 3530 struct ipv6_pool *pool, time_t now);
3513isc_result_t release_lease6(struct ipv6_pool *pool, struct iasubopt *lease); 3531isc_result_t release_lease6(struct ipv6_pool *pool, struct iasubopt *lease);
3514isc_result_t decline_lease6(struct ipv6_pool *pool, struct iasubopt *lease); 3532isc_result_t decline_lease6(struct ipv6_pool *pool, struct iasubopt *lease);
3515isc_boolean_t lease6_exists(const struct ipv6_pool *pool, 3533isc_boolean_t lease6_exists(const struct ipv6_pool *pool,
3516 const struct in6_addr *addr); 3534 const struct in6_addr *addr);
 3535isc_boolean_t lease6_usable(struct iasubopt *lease);
 3536isc_result_t cleanup_lease6(ia_hash_t *ia_table,
 3537 struct ipv6_pool *pool,
 3538 struct iasubopt *lease,
 3539 struct ia_xx *ia);
3517isc_result_t mark_lease_unavailble(struct ipv6_pool *pool, 3540isc_result_t mark_lease_unavailble(struct ipv6_pool *pool,
3518 const struct in6_addr *addr); 3541 const struct in6_addr *addr);
3519 
3520isc_result_t create_prefix6(struct ipv6_pool *pool, 3542isc_result_t create_prefix6(struct ipv6_pool *pool,
3521 struct iasubopt **pref, 3543 struct iasubopt **pref,
3522 unsigned int *attempts, 3544 unsigned int *attempts,
3523 const struct data_string *uid, 3545 const struct data_string *uid,
3524 time_t soft_lifetime_end_time); 3546 time_t soft_lifetime_end_time);
3525isc_boolean_t prefix6_exists(const struct ipv6_pool *pool, 3547isc_boolean_t prefix6_exists(const struct ipv6_pool *pool,
3526 const struct in6_addr *pref, u_int8_t plen); 3548 const struct in6_addr *pref, u_int8_t plen);
3527 3549
3528isc_result_t add_ipv6_pool(struct ipv6_pool *pool); 3550isc_result_t add_ipv6_pool(struct ipv6_pool *pool);
3529isc_result_t find_ipv6_pool(struct ipv6_pool **pool, u_int16_t type, 3551isc_result_t find_ipv6_pool(struct ipv6_pool **pool, u_int16_t type,
3530 const struct in6_addr *addr); 3552 const struct in6_addr *addr);
3531isc_boolean_t ipv6_in_pool(const struct in6_addr *addr, 3553isc_boolean_t ipv6_in_pool(const struct in6_addr *addr,
3532 const struct ipv6_pool *pool); 3554 const struct ipv6_pool *pool);
@@ -3538,23 +3560,23 @@ void schedule_lease_timeout(struct ipv6_ @@ -3538,23 +3560,23 @@ void schedule_lease_timeout(struct ipv6_
3538void schedule_all_ipv6_lease_timeouts(void); 3560void schedule_all_ipv6_lease_timeouts(void);
3539 3561
3540void mark_hosts_unavailable(void); 3562void mark_hosts_unavailable(void);
3541void mark_phosts_unavailable(void); 3563void mark_phosts_unavailable(void);
3542void mark_interfaces_unavailable(void); 3564void mark_interfaces_unavailable(void);
3543 3565
3544dhcp_ddns_cb_t *ddns_cb_alloc(const char *file, int line); 3566dhcp_ddns_cb_t *ddns_cb_alloc(const char *file, int line);
3545void ddns_cb_free (dhcp_ddns_cb_t *ddns_cb, const char *file, int line); 3567void ddns_cb_free (dhcp_ddns_cb_t *ddns_cb, const char *file, int line);
3546void ddns_cb_forget_zone (dhcp_ddns_cb_t *ddns_cb); 3568void ddns_cb_forget_zone (dhcp_ddns_cb_t *ddns_cb);
3547 3569
3548//void *key_from_zone(struct dns_zone *zone); 3570//void *key_from_zone(struct dns_zone *zone);
3549 3571
3550isc_result_t 3572isc_result_t
3551ddns_modify_fwd(dhcp_ddns_cb_t *ddns_cb); 3573ddns_modify_fwd(dhcp_ddns_cb_t *ddns_cb, const char *file, int line);
3552 3574
3553isc_result_t 3575isc_result_t
3554ddns_modify_ptr(dhcp_ddns_cb_t *ddns_cb); 3576ddns_modify_ptr(dhcp_ddns_cb_t *ddns_cb, const char *file, int line);
3555 3577
3556void 3578void
3557ddns_cancel(dhcp_ddns_cb_t *ddns_cb); 3579ddns_cancel(dhcp_ddns_cb_t *ddns_cb, const char *file, int line);
3558 3580
3559#define MAX_ADDRESS_STRING_LEN \ 3581#define MAX_ADDRESS_STRING_LEN \
3560 (sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")) 3582 (sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"))

cvs diff -r1.2 -r1.3 src/external/bsd/dhcp/dist/omapip/Attic/dispatch.c (expand / switch to unified diff)

--- src/external/bsd/dhcp/dist/omapip/Attic/dispatch.c 2013/03/24 15:53:59 1.2
+++ src/external/bsd/dhcp/dist/omapip/Attic/dispatch.c 2013/03/24 23:03:06 1.3
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dispatch.c,v 1.2 2013/03/24 15:53:59 christos Exp $ */ 1/* $NetBSD: dispatch.c,v 1.3 2013/03/24 23:03:06 christos Exp $ */
2 2
3/* dispatch.c 3/* dispatch.c
4 4
5 I/O dispatcher. */ 5 I/O dispatcher. */
6 6
7/* 7/*
8 * Copyright (c) 2004,2007-2009 by Internet Systems Consortium, Inc. ("ISC") 8 * Copyright (c) 2004,2007-2009 by Internet Systems Consortium, Inc. ("ISC")
9 * Copyright (c) 1999-2003 by Internet Software Consortium 9 * Copyright (c) 1999-2003 by Internet Software Consortium
10 * 10 *
11 * Permission to use, copy, modify, and distribute this software for any 11 * Permission to use, copy, modify, and distribute this software for any
12 * purpose with or without fee is hereby granted, provided that the above 12 * purpose with or without fee is hereby granted, provided that the above
13 * copyright notice and this permission notice appear in all copies. 13 * copyright notice and this permission notice appear in all copies.
14 * 14 *
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * Redwood City, CA 94063 25 * Redwood City, CA 94063
26 * <info@isc.org> 26 * <info@isc.org>
27 * https://www.isc.org/ 27 * https://www.isc.org/
28 * 28 *
29 * This software has been written for Internet Systems Consortium 29 * This software has been written for Internet Systems Consortium
30 * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc. 30 * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
31 * To learn more about Internet Systems Consortium, see 31 * To learn more about Internet Systems Consortium, see
32 * ``https://www.isc.org/''. To learn more about Vixie Enterprises, 32 * ``https://www.isc.org/''. To learn more about Vixie Enterprises,
33 * see ``http://www.vix.com''. To learn more about Nominum, Inc., see 33 * see ``http://www.vix.com''. To learn more about Nominum, Inc., see
34 * ``http://www.nominum.com''. 34 * ``http://www.nominum.com''.
35 */ 35 */
36 36
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38__RCSID("$NetBSD: dispatch.c,v 1.2 2013/03/24 15:53:59 christos Exp $"); 38__RCSID("$NetBSD: dispatch.c,v 1.3 2013/03/24 23:03:06 christos Exp $");
39 39
40#include "dhcpd.h" 40#include "dhcpd.h"
41 41
42#include <omapip/omapip_p.h> 42#include <omapip/omapip_p.h>
43#include <sys/time.h> 43#include <sys/time.h>
44 44
45static omapi_io_object_t omapi_io_states; 45static omapi_io_object_t omapi_io_states;
46struct timeval cur_tv; 46struct timeval cur_tv;
47 47
48struct eventqueue *rw_queue_empty; 48struct eventqueue *rw_queue_empty;
49 49
50OMAPI_OBJECT_ALLOC (omapi_io, 50OMAPI_OBJECT_ALLOC (omapi_io,
51 omapi_io_object_t, omapi_type_io_object) 51 omapi_io_object_t, omapi_type_io_object)
@@ -166,28 +166,35 @@ omapi_iscsock_cb(isc_task_t *task, @@ -166,28 +166,35 @@ omapi_iscsock_cb(isc_task_t *task,
166 * anything just indicate that we don't want any more. 166 * anything just indicate that we don't want any more.
167 * 167 *
168 * This should be a temporary fix until we arrange to properly 168 * This should be a temporary fix until we arrange to properly
169 * close the socket. 169 * close the socket.
170 */ 170 */
171 if (obj->closed == ISC_TRUE) { 171 if (obj->closed == ISC_TRUE) {
172 return(0); 172 return(0);
173 } 173 }
174#endif  174#endif
175 175
176 if ((flags == ISC_SOCKFDWATCH_READ) && 176 if ((flags == ISC_SOCKFDWATCH_READ) &&
177 (obj->reader != NULL) && 177 (obj->reader != NULL) &&
178 (obj->inner != NULL)) { 178 (obj->inner != NULL)) {
179 obj->reader(obj->inner); 179 status = obj->reader(obj->inner);
180 /* We always ask for more when reading */ 180 /*
 181 * If we are shutting down (basically tried to
 182 * read and got no bytes) we don't need to try
 183 * again.
 184 */
 185 if (status == ISC_R_SHUTTINGDOWN)
 186 return (0);
 187 /* Otherwise We always ask for more when reading */
181 return (1); 188 return (1);
182 } else if ((flags == ISC_SOCKFDWATCH_WRITE) && 189 } else if ((flags == ISC_SOCKFDWATCH_WRITE) &&
183 (obj->writer != NULL) && 190 (obj->writer != NULL) &&
184 (obj->inner != NULL)) { 191 (obj->inner != NULL)) {
185 status = obj->writer(obj->inner); 192 status = obj->writer(obj->inner);
186 /* If the writer has more to write they should return 193 /* If the writer has more to write they should return
187 * ISC_R_INPROGRESS */ 194 * ISC_R_INPROGRESS */
188 if (status == ISC_R_INPROGRESS) { 195 if (status == ISC_R_INPROGRESS) {
189 return (1); 196 return (1);
190 } 197 }
191 } 198 }
192 199
193 /* 200 /*

cvs diff -r1.2 -r1.3 src/external/bsd/dhcp/dist/relay/Attic/dhcrelay.c (expand / switch to unified diff)

--- src/external/bsd/dhcp/dist/relay/Attic/dhcrelay.c 2013/03/24 15:53:59 1.2
+++ src/external/bsd/dhcp/dist/relay/Attic/dhcrelay.c 2013/03/24 23:03:06 1.3
@@ -1,21 +1,21 @@ @@ -1,21 +1,21 @@
1/* $NetBSD: dhcrelay.c,v 1.2 2013/03/24 15:53:59 christos Exp $ */ 1/* $NetBSD: dhcrelay.c,v 1.3 2013/03/24 23:03:06 christos Exp $ */
2 2
3/* dhcrelay.c 3/* dhcrelay.c
4 4
5 DHCP/BOOTP Relay Agent. */ 5 DHCP/BOOTP Relay Agent. */
6 6
7/* 7/*
8 * Copyright(c) 2004-2011 by Internet Systems Consortium, Inc.("ISC") 8 * Copyright(c) 2004-2013 by Internet Systems Consortium, Inc.("ISC")
9 * Copyright(c) 1997-2003 by Internet Software Consortium 9 * Copyright(c) 1997-2003 by Internet Software Consortium
10 * 10 *
11 * Permission to use, copy, modify, and distribute this software for any 11 * Permission to use, copy, modify, and distribute this software for any
12 * purpose with or without fee is hereby granted, provided that the above 12 * purpose with or without fee is hereby granted, provided that the above
13 * copyright notice and this permission notice appear in all copies. 13 * copyright notice and this permission notice appear in all copies.
14 * 14 *
15 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 15 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
16 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 16 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 17 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
18 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 18 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 20 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 21 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * Redwood City, CA 94063 25 * Redwood City, CA 94063
26 * <info@isc.org> 26 * <info@isc.org>
27 * https://www.isc.org/ 27 * https://www.isc.org/
28 * 28 *
29 * This software has been written for Internet Systems Consortium 29 * This software has been written for Internet Systems Consortium
30 * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc. 30 * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
31 * To learn more about Internet Systems Consortium, see 31 * To learn more about Internet Systems Consortium, see
32 * ``https://www.isc.org/''. To learn more about Vixie Enterprises, 32 * ``https://www.isc.org/''. To learn more about Vixie Enterprises,
33 * see ``http://www.vix.com''. To learn more about Nominum, Inc., see 33 * see ``http://www.vix.com''. To learn more about Nominum, Inc., see
34 * ``http://www.nominum.com''. 34 * ``http://www.nominum.com''.
35 */ 35 */
36 36
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38__RCSID("$NetBSD: dhcrelay.c,v 1.2 2013/03/24 15:53:59 christos Exp $"); 38__RCSID("$NetBSD: dhcrelay.c,v 1.3 2013/03/24 23:03:06 christos Exp $");
39 39
40#include "dhcpd.h" 40#include "dhcpd.h"
41#include <syslog.h> 41#include <syslog.h>
42#include <sys/time.h> 42#include <sys/time.h>
43 43
44TIME default_lease_time = 43200; /* 12 hours... */ 44TIME default_lease_time = 43200; /* 12 hours... */
45TIME max_lease_time = 86400; /* 24 hours... */ 45TIME max_lease_time = 86400; /* 24 hours... */
46struct tree_cache *global_options[256]; 46struct tree_cache *global_options[256];
47 47
48struct option *requested_opts[2]; 48struct option *requested_opts[2];
49 49
50/* Needed to prevent linking against conflex.c. */ 50/* Needed to prevent linking against conflex.c. */
51int lexline; 51int lexline;
@@ -125,27 +125,27 @@ static void setup_streams(void); @@ -125,27 +125,27 @@ static void setup_streams(void);
125static void do_relay4(struct interface_info *, struct dhcp_packet *, 125static void do_relay4(struct interface_info *, struct dhcp_packet *,
126 unsigned int, unsigned int, struct iaddr, 126 unsigned int, unsigned int, struct iaddr,
127 struct hardware *); 127 struct hardware *);
128static int add_relay_agent_options(struct interface_info *, 128static int add_relay_agent_options(struct interface_info *,
129 struct dhcp_packet *, unsigned, 129 struct dhcp_packet *, unsigned,
130 struct in_addr); 130 struct in_addr);
131static int find_interface_by_agent_option(struct dhcp_packet *, 131static int find_interface_by_agent_option(struct dhcp_packet *,
132 struct interface_info **, u_int8_t *, int); 132 struct interface_info **, u_int8_t *, int);
133static int strip_relay_agent_options(struct interface_info *, 133static int strip_relay_agent_options(struct interface_info *,
134 struct interface_info **, 134 struct interface_info **,
135 struct dhcp_packet *, unsigned); 135 struct dhcp_packet *, unsigned);
136 136
137static const char copyright[] = 137static const char copyright[] =
138"Copyright 2004-2011 Internet Systems Consortium."; 138"Copyright 2004-2013 Internet Systems Consortium.";
139static const char arr[] = "All rights reserved."; 139static const char arr[] = "All rights reserved.";
140static const char message[] = 140static const char message[] =
141"Internet Systems Consortium DHCP Relay Agent"; 141"Internet Systems Consortium DHCP Relay Agent";
142static const char url[] = 142static const char url[] =
143"For info, please visit https://www.isc.org/software/dhcp/"; 143"For info, please visit https://www.isc.org/software/dhcp/";
144 144
145#ifdef DHCPv6 145#ifdef DHCPv6
146#define DHCRELAY_USAGE \ 146#define DHCRELAY_USAGE \
147"Usage: dhcrelay [-4] [-d] [-q] [-a] [-D]\n"\ 147"Usage: dhcrelay [-4] [-d] [-q] [-a] [-D]\n"\
148" [-A <length>] [-c <hops>] [-p <port>]\n" \ 148" [-A <length>] [-c <hops>] [-p <port>]\n" \
149" [-pf <pid-file>] [--no-pid]\n"\ 149" [-pf <pid-file>] [--no-pid]\n"\
150" [-m append|replace|forward|discard]\n" \ 150" [-m append|replace|forward|discard]\n" \
151" [-i interface0 [ ... -i interfaceN]\n" \ 151" [-i interface0 [ ... -i interfaceN]\n" \
@@ -252,33 +252,39 @@ main(int argc, char **argv) { @@ -252,33 +252,39 @@ main(int argc, char **argv) {
252 hcount = atoi(argv[i]); 252 hcount = atoi(argv[i]);
253 if (hcount <= 255) 253 if (hcount <= 255)
254 max_hop_count= hcount; 254 max_hop_count= hcount;
255 else 255 else
256 usage(); 256 usage();
257 } else if (!strcmp(argv[i], "-i")) { 257 } else if (!strcmp(argv[i], "-i")) {
258#ifdef DHCPv6 258#ifdef DHCPv6
259 if (local_family_set && (local_family == AF_INET6)) { 259 if (local_family_set && (local_family == AF_INET6)) {
260 usage(); 260 usage();
261 } 261 }
262 local_family_set = 1; 262 local_family_set = 1;
263 local_family = AF_INET; 263 local_family = AF_INET;
264#endif 264#endif
 265 if (++i == argc) {
 266 usage();
 267 }
 268 if (strlen(argv[i]) >= sizeof(tmp->name)) {
 269 log_fatal("%s: interface name too long "
 270 "(is %ld)",
 271 argv[i], (long)strlen(argv[i]));
 272 }
265 status = interface_allocate(&tmp, MDL); 273 status = interface_allocate(&tmp, MDL);
266 if (status != ISC_R_SUCCESS) 274 if (status != ISC_R_SUCCESS) {
267 log_fatal("%s: interface_allocate: %s", 275 log_fatal("%s: interface_allocate: %s",
268 argv[i], 276 argv[i],
269 isc_result_totext(status)); 277 isc_result_totext(status));
270 if (++i == argc) { 
271 usage(); 
272 } 278 }
273 strcpy(tmp->name, argv[i]); 279 strcpy(tmp->name, argv[i]);
274 interface_snorf(tmp, INTERFACE_REQUESTED); 280 interface_snorf(tmp, INTERFACE_REQUESTED);
275 interface_dereference(&tmp, MDL); 281 interface_dereference(&tmp, MDL);
276 } else if (!strcmp(argv[i], "-a")) { 282 } else if (!strcmp(argv[i], "-a")) {
277#ifdef DHCPv6 283#ifdef DHCPv6
278 if (local_family_set && (local_family == AF_INET6)) { 284 if (local_family_set && (local_family == AF_INET6)) {
279 usage(); 285 usage();
280 } 286 }
281 local_family_set = 1; 287 local_family_set = 1;
282 local_family = AF_INET; 288 local_family = AF_INET;
283#endif 289#endif
284 add_agent_options = 1; 290 add_agent_options = 1;
@@ -603,29 +609,30 @@ do_relay4(struct interface_info *ip, str @@ -603,29 +609,30 @@ do_relay4(struct interface_info *ip, str
603 log_info("Discarding packet received on %s interface that " 609 log_info("Discarding packet received on %s interface that "
604 "has no IPv4 address assigned.", ip->name); 610 "has no IPv4 address assigned.", ip->name);
605 return; 611 return;
606 } 612 }
607 613
608 /* Find the interface that corresponds to the giaddr 614 /* Find the interface that corresponds to the giaddr
609 in the packet. */ 615 in the packet. */
610 if (packet->giaddr.s_addr) { 616 if (packet->giaddr.s_addr) {
611 for (out = interfaces; out; out = out->next) { 617 for (out = interfaces; out; out = out->next) {
612 int i; 618 int i;
613 619
614 for (i = 0 ; i < out->address_count ; i++ ) { 620 for (i = 0 ; i < out->address_count ; i++ ) {
615 if (out->addresses[i].s_addr == 621 if (out->addresses[i].s_addr ==
616 packet->giaddr.s_addr) 622 packet->giaddr.s_addr) {
617 i = -1; 623 i = -1;
618 break; 624 break;
 625 }
619 } 626 }
620 627
621 if (i == -1) 628 if (i == -1)
622 break; 629 break;
623 } 630 }
624 } else { 631 } else {
625 out = NULL; 632 out = NULL;
626 } 633 }
627 634
628 /* If it's a bootreply, forward it to the client. */ 635 /* If it's a bootreply, forward it to the client. */
629 if (packet->op == BOOTREPLY) { 636 if (packet->op == BOOTREPLY) {
630 if (!(packet->flags & htons(BOOTP_BROADCAST)) && 637 if (!(packet->flags & htons(BOOTP_BROADCAST)) &&
631 can_unicast_without_arp(out)) { 638 can_unicast_without_arp(out)) {

cvs diff -r1.2 -r1.3 src/external/bsd/dhcp/dist/server/Attic/ddns.c (expand / switch to unified diff)

--- src/external/bsd/dhcp/dist/server/Attic/ddns.c 2013/03/24 15:53:59 1.2
+++ src/external/bsd/dhcp/dist/server/Attic/ddns.c 2013/03/24 23:03:06 1.3
@@ -1,21 +1,21 @@ @@ -1,21 +1,21 @@
1/* $NetBSD: ddns.c,v 1.2 2013/03/24 15:53:59 christos Exp $ */ 1/* $NetBSD: ddns.c,v 1.3 2013/03/24 23:03:06 christos Exp $ */
2 2
3/* ddns.c 3/* ddns.c
4 4
5 Dynamic DNS updates. */ 5 Dynamic DNS updates. */
6 6
7/* 7/*
8 * Copyright (c) 2009-2011 by Internet Systems Consortium, Inc. ("ISC") 8 * Copyright (c) 2009-2012 by Internet Systems Consortium, Inc. ("ISC")
9 * Copyright (c) 2004-2007 by Internet Systems Consortium, Inc. ("ISC") 9 * Copyright (c) 2004-2007 by Internet Systems Consortium, Inc. ("ISC")
10 * Copyright (c) 2000-2003 by Internet Software Consortium 10 * Copyright (c) 2000-2003 by Internet Software Consortium
11 * 11 *
12 * Permission to use, copy, modify, and distribute this software for any 12 * Permission to use, copy, modify, and distribute this software for any
13 * purpose with or without fee is hereby granted, provided that the above 13 * purpose with or without fee is hereby granted, provided that the above
14 * copyright notice and this permission notice appear in all copies. 14 * copyright notice and this permission notice appear in all copies.
15 * 15 *
16 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 16 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
17 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 17 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 18 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
19 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 19 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 20 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
21 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 21 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
@@ -26,27 +26,27 @@ @@ -26,27 +26,27 @@
26 * Redwood City, CA 94063 26 * Redwood City, CA 94063
27 * <info@isc.org> 27 * <info@isc.org>
28 * https://www.isc.org/ 28 * https://www.isc.org/
29 * 29 *
30 * This software has been donated to Internet Systems Consortium 30 * This software has been donated to Internet Systems Consortium
31 * by Damien Neil of Nominum, Inc. 31 * by Damien Neil of Nominum, Inc.
32 * 32 *
33 * To learn more about Internet Systems Consortium, see 33 * To learn more about Internet Systems Consortium, see
34 * ``https://www.isc.org/''. To learn more about Nominum, Inc., see 34 * ``https://www.isc.org/''. To learn more about Nominum, Inc., see
35 * ``http://www.nominum.com''. 35 * ``http://www.nominum.com''.
36 */ 36 */
37 37
38#include <sys/cdefs.h> 38#include <sys/cdefs.h>
39__RCSID("$NetBSD: ddns.c,v 1.2 2013/03/24 15:53:59 christos Exp $"); 39__RCSID("$NetBSD: ddns.c,v 1.3 2013/03/24 23:03:06 christos Exp $");
40 40
41#include "dhcpd.h" 41#include "dhcpd.h"
42#include "dst/md5.h" 42#include "dst/md5.h"
43#include <dns/result.h> 43#include <dns/result.h>
44 44
45#ifdef NSUPDATE 45#ifdef NSUPDATE
46 46
47static void ddns_fwd_srv_connector(struct lease *lease, 47static void ddns_fwd_srv_connector(struct lease *lease,
48 struct iasubopt *lease6, 48 struct iasubopt *lease6,
49 struct binding_scope **inscope, 49 struct binding_scope **inscope,
50 dhcp_ddns_cb_t *ddns_cb, 50 dhcp_ddns_cb_t *ddns_cb,
51 isc_result_t eresult); 51 isc_result_t eresult);
52 52
@@ -75,71 +75,74 @@ ddns_updates(struct packet *packet, stru @@ -75,71 +75,74 @@ ddns_updates(struct packet *packet, stru
75 unsigned long ddns_ttl = DEFAULT_DDNS_TTL; 75 unsigned long ddns_ttl = DEFAULT_DDNS_TTL;
76 struct data_string ddns_hostname; 76 struct data_string ddns_hostname;
77 struct data_string ddns_domainname; 77 struct data_string ddns_domainname;
78 struct data_string old_ddns_fwd_name; 78 struct data_string old_ddns_fwd_name;
79 struct data_string ddns_fwd_name; 79 struct data_string ddns_fwd_name;
80 //struct data_string ddns_rev_name; 80 //struct data_string ddns_rev_name;
81 struct data_string ddns_dhcid; 81 struct data_string ddns_dhcid;
82 struct binding_scope **scope = NULL; 82 struct binding_scope **scope = NULL;
83 //struct iaddr addr; 83 //struct iaddr addr;
84 struct data_string d1; 84 struct data_string d1;
85 struct option_cache *oc; 85 struct option_cache *oc;
86 int s1, s2; 86 int s1, s2;
87 int result = 0; 87 int result = 0;
88 isc_result_t rcode1 = ISC_R_SUCCESS; 
89 int server_updates_a = 1; 88 int server_updates_a = 1;
90 //int server_updates_ptr = 1; 89 //int server_updates_ptr = 1;
91 struct buffer *bp = (struct buffer *)0; 90 struct buffer *bp = (struct buffer *)0;
92 int ignorep = 0, client_ignorep = 0; 91 int ignorep = 0, client_ignorep = 0;
93 int rev_name_len; 92 int rev_name_len;
94 int i; 93 int i;
95 94
96 dhcp_ddns_cb_t *ddns_cb; 95 dhcp_ddns_cb_t *ddns_cb;
97 int do_remove = 0; 96 int do_remove = 0;
98 97
99 if (ddns_update_style != 2) 98 if (ddns_update_style != 2)
100 return 0; 99 return 0;
101 100
102 /* 101 /*
103 * sigh, I want to cancel any previous udpates before we do anything 102 * sigh, I want to cancel any previous udpates before we do anything
104 * else but this means we need to deal with the lease vs lease6 103 * else but this means we need to deal with the lease vs lease6
105 * question twice. 104 * question twice.
106 * If there is a ddns request already outstanding cancel it. 105 * If there is a ddns request already outstanding cancel it.
107 */ 106 */
108 107
109 if (lease != NULL) { 108 if (lease != NULL) {
110 if ((old != NULL) && (old->ddns_cb != NULL)) { 109 if ((old != NULL) && (old->ddns_cb != NULL)) {
111 ddns_cancel(old->ddns_cb); 110 ddns_cancel(old->ddns_cb, MDL);
112 old->ddns_cb = NULL; 111 old->ddns_cb = NULL;
113 } 112 }
114 } else if (lease6 != NULL) { 113 } else if (lease6 != NULL) {
115 if ((old6 != NULL) && (old6->ddns_cb != NULL)) { 114 if ((old6 != NULL) && (old6->ddns_cb != NULL)) {
116 ddns_cancel(old6->ddns_cb); 115 ddns_cancel(old6->ddns_cb, MDL);
117 old6->ddns_cb = NULL; 116 old6->ddns_cb = NULL;
118 } 117 }
119 } else { 118 } else {
120 log_fatal("Impossible condition at %s:%d.", MDL); 119 log_fatal("Impossible condition at %s:%d.", MDL);
121 /* Silence compiler warnings. */ 120 /* Silence compiler warnings. */
122 result = 0; 121 result = 0;
123 return(0); 122 return(0);
124 } 123 }
125 124
126 /* allocate our control block */ 125 /* allocate our control block */
127 ddns_cb = ddns_cb_alloc(MDL); 126 ddns_cb = ddns_cb_alloc(MDL);
128 if (ddns_cb == NULL) { 127 if (ddns_cb == NULL) {
129 return(0); 128 return(0);
130 } 129 }
131 /* assume that we shall update both the A and ptr records */ 130 /*
132 ddns_cb->flags = DDNS_UPDATE_ADDR | DDNS_UPDATE_PTR; 131 * Assume that we shall update both the A and ptr records and,
 132 * as this is an update, set the active flag
 133 */
 134 ddns_cb->flags = DDNS_UPDATE_ADDR | DDNS_UPDATE_PTR |
 135 DDNS_ACTIVE_LEASE;
133 136
134 /* 137 /*
135 * For v4 we flag static leases so we don't try 138 * For v4 we flag static leases so we don't try
136 * and manipulate the lease later. For v6 we don't 139 * and manipulate the lease later. For v6 we don't
137 * get static leases and don't need to flag them. 140 * get static leases and don't need to flag them.
138 */ 141 */
139 if (lease != NULL) { 142 if (lease != NULL) {
140 scope = &(lease->scope); 143 scope = &(lease->scope);
141 ddns_cb->address = lease->ip_addr; 144 ddns_cb->address = lease->ip_addr;
142 if (lease->flags & STATIC_LEASE) 145 if (lease->flags & STATIC_LEASE)
143 ddns_cb->flags |= DDNS_STATIC_LEASE; 146 ddns_cb->flags |= DDNS_STATIC_LEASE;
144 } else if (lease6 != NULL) { 147 } else if (lease6 != NULL) {
145 scope = &(lease6->scope); 148 scope = &(lease6->scope);
@@ -324,27 +327,27 @@ ddns_updates(struct packet *packet, stru @@ -324,27 +327,27 @@ ddns_updates(struct packet *packet, stru
324 } 327 }
325 in: 328 in:
326  329
327 /* If we don't have a name that the client has been assigned, we 330 /* If we don't have a name that the client has been assigned, we
328 can just skip all this. */ 331 can just skip all this. */
329 332
330 if ((!ddns_fwd_name.len) || (ddns_fwd_name.len > 255)) { 333 if ((!ddns_fwd_name.len) || (ddns_fwd_name.len > 255)) {
331 if (ddns_fwd_name.len > 255) { 334 if (ddns_fwd_name.len > 255) {
332 log_error ("client provided fqdn: too long"); 335 log_error ("client provided fqdn: too long");
333 } 336 }
334 337
335 /* If desired do the removals */ 338 /* If desired do the removals */
336 if (do_remove != 0) { 339 if (do_remove != 0) {
337 (void) ddns_removals(lease, lease6, NULL); 340 (void) ddns_removals(lease, lease6, NULL, ISC_TRUE);
338 } 341 }
339 goto out; 342 goto out;
340 } 343 }
341 344
342 /* 345 /*
343 * Compute the RR TTL. 346 * Compute the RR TTL.
344 * 347 *
345 * We have two ways of computing the TTL. 348 * We have two ways of computing the TTL.
346 * The old behavior was to allow for the customer to set up 349 * The old behavior was to allow for the customer to set up
347 * the option or to default things. For v4 this was 1/2 350 * the option or to default things. For v4 this was 1/2
348 * of the lease time, for v6 this was DEFAULT_DDNS_TTL. 351 * of the lease time, for v6 this was DEFAULT_DDNS_TTL.
349 * The new behavior continues to allow the customer to set 352 * The new behavior continues to allow the customer to set
350 * up an option but the defaults are a little different. 353 * up an option but the defaults are a little different.
@@ -526,27 +529,31 @@ ddns_updates(struct packet *packet, stru @@ -526,27 +529,31 @@ ddns_updates(struct packet *packet, stru
526 NULL, packet->options, 529 NULL, packet->options,
527 options, scope, oc, MDL)) 530 options, scope, oc, MDL))
528 ddns_cb->flags |= DDNS_CONFLICT_OVERRIDE; 531 ddns_cb->flags |= DDNS_CONFLICT_OVERRIDE;
529 532
530 } 533 }
531 534
532 /* 535 /*
533 * Previously if we failed during the removal operations 536 * Previously if we failed during the removal operations
534 * we skipped the fqdn option processing. I'm not sure 537 * we skipped the fqdn option processing. I'm not sure
535 * if we want to continue with that if we fail before sending 538 * if we want to continue with that if we fail before sending
536 * the ddns messages. Currently we don't. 539 * the ddns messages. Currently we don't.
537 */ 540 */
538 if (do_remove) { 541 if (do_remove) {
539 rcode1 = ddns_removals(lease, lease6, ddns_cb); 542 /*
 543 * We should log a more specific error closer to the actual
 544 * error if we want one. ddns_removal failure not logged here.
 545 */
 546 (void) ddns_removals(lease, lease6, ddns_cb, ISC_TRUE);
540 } 547 }
541 else { 548 else {
542 ddns_fwd_srv_connector(lease, lease6, scope, ddns_cb, 549 ddns_fwd_srv_connector(lease, lease6, scope, ddns_cb,
543 ISC_R_SUCCESS); 550 ISC_R_SUCCESS);
544 } 551 }
545 ddns_cb = NULL; 552 ddns_cb = NULL;
546 553
547 noerror: 554 noerror:
548 /* 555 /*
549 * If fqdn-reply option is disabled in dhcpd.conf, then don't 556 * If fqdn-reply option is disabled in dhcpd.conf, then don't
550 * send the client an FQDN option at all, even if one was requested. 557 * send the client an FQDN option at all, even if one was requested.
551 * (WinXP clients allegedly misbehave if the option is present, 558 * (WinXP clients allegedly misbehave if the option is present,
552 * refusing to handle PTR updates themselves). 559 * refusing to handle PTR updates themselves).
@@ -704,56 +711,77 @@ ddns_updates(struct packet *packet, stru @@ -704,56 +711,77 @@ ddns_updates(struct packet *packet, stru
704 data_string_forget(&d1, MDL); 711 data_string_forget(&d1, MDL);
705 data_string_forget(&ddns_hostname, MDL); 712 data_string_forget(&ddns_hostname, MDL);
706 data_string_forget(&ddns_domainname, MDL); 713 data_string_forget(&ddns_domainname, MDL);
707 data_string_forget(&old_ddns_fwd_name, MDL); 714 data_string_forget(&old_ddns_fwd_name, MDL);
708 data_string_forget(&ddns_fwd_name, MDL); 715 data_string_forget(&ddns_fwd_name, MDL);
709 //data_string_forget(&ddns_rev_name, MDL); 716 //data_string_forget(&ddns_rev_name, MDL);
710 //data_string_forget(&ddns_dhcid, MDL); 717 //data_string_forget(&ddns_dhcid, MDL);
711 if (bp) 718 if (bp)
712 buffer_dereference(&bp, MDL); 719 buffer_dereference(&bp, MDL);
713 720
714 return result; 721 return result;
715} 722}
716 723
717/* 724/*%<
718 * Utility function to update text strings within a lease. 725 * Utility function to update text strings within a lease.
719 * 726 *
720 * The first issue is to find the proper scope. Sometimes we shall be 727 * The first issue is to find the proper scope. Sometimes we shall be
721 * called with a pointer to the scope in other cases we need to find 728 * called with a pointer to the scope in other cases we need to find
722 * the proper lease and then get the scope. Once we have the scope we update 729 * the proper lease and then get the scope. Once we have the scope we update
723 * the proper strings, as indicated by the state value in the control block. 730 * the proper strings, as indicated by the state value in the control block.
724 * Lastly, if we needed to find the scope we write it out, if we used a 731 * Lastly, if we needed to find the scope we write it out, if we used a
725 * scope that was passed as an argument we don't write it, assuming that 732 * scope that was passed as an argument we don't write it, assuming that
726 * our caller (or his ...) will do the write. 733 * our caller (or his ...) will do the write.
 734 *
 735 *\li ddns_cb - the control block for the DDNS request
 736 *
 737 *\li inscope - a pointer to the scope to update. This may be NULL
 738 * in which case we use the control block to find the lease and
 739 * then the scope.
 740 *
 741 * Returns
 742 *\li ISC_R_SUCCESS
 743 *
 744 *\li ISC_R_FAILURE - The routine was unable to find an expected scope.
 745 * In some cases (static and inactive leases) we don't expect a scope
 746 * and return success.
727 */ 747 */
728 748
729static isc_result_t 749static isc_result_t
730ddns_update_lease_text(dhcp_ddns_cb_t *ddns_cb, 750ddns_update_lease_text(dhcp_ddns_cb_t *ddns_cb,
731 struct binding_scope **inscope) 751 struct binding_scope **inscope)
732{ 752{
733 struct binding_scope **scope = NULL; 753 struct binding_scope **scope = NULL;
734 struct lease *lease = NULL; 754 struct lease *lease = NULL;
735 struct iasubopt *lease6 = NULL; 755 struct iasubopt *lease6 = NULL;
736 struct ipv6_pool *pool = NULL; 756 struct ipv6_pool *pool = NULL;
737 struct in6_addr addr; 757 struct in6_addr addr;
738 struct data_string lease_dhcid; 758 struct data_string lease_dhcid;
739  759
740 /* 760 /*
741 * If the lease was static (for a fixed address) 761 * If the lease was static (for a fixed address)
742 * we don't need to do any work. 762 * we don't need to do any work.
743 */ 763 */
744 if (ddns_cb->flags & DDNS_STATIC_LEASE) 764 if (ddns_cb->flags & DDNS_STATIC_LEASE)
745 return (ISC_R_SUCCESS); 765 return (ISC_R_SUCCESS);
746 766
 767 /*
 768 * If we are processing an expired or released v6 lease
 769 * or some types of v4 leases we don't actually have a
 770 * scope to update
 771 */
 772 if ((ddns_cb->flags & DDNS_ACTIVE_LEASE) == 0)
 773 return (ISC_R_SUCCESS);
 774
747 if (inscope != NULL) { 775 if (inscope != NULL) {
748 scope = inscope; 776 scope = inscope;
749 } else if (ddns_cb->address.len == 4) { 777 } else if (ddns_cb->address.len == 4) {
750 if (find_lease_by_ip_addr(&lease, ddns_cb->address, MDL) != 0){ 778 if (find_lease_by_ip_addr(&lease, ddns_cb->address, MDL) != 0){
751 scope = &(lease->scope); 779 scope = &(lease->scope);
752 } 780 }
753 } else if (ddns_cb->address.len == 16) { 781 } else if (ddns_cb->address.len == 16) {
754 memcpy(&addr, &ddns_cb->address.iabuf, 16); 782 memcpy(&addr, &ddns_cb->address.iabuf, 16);
755 if ((find_ipv6_pool(&pool, D6O_IA_TA, &addr) == 783 if ((find_ipv6_pool(&pool, D6O_IA_TA, &addr) ==
756 ISC_R_SUCCESS) || 784 ISC_R_SUCCESS) ||
757 (find_ipv6_pool(&pool, D6O_IA_NA, &addr) ==  785 (find_ipv6_pool(&pool, D6O_IA_NA, &addr) ==
758 ISC_R_SUCCESS)) { 786 ISC_R_SUCCESS)) {
759 if (iasubopt_hash_lookup(&lease6, pool->leases, 787 if (iasubopt_hash_lookup(&lease6, pool->leases,
@@ -1061,46 +1089,60 @@ safe_lease6_update(struct iasubopt *leas @@ -1061,46 +1089,60 @@ safe_lease6_update(struct iasubopt *leas
1061 * addition to the address information from the cb to look up the lease. 1089 * addition to the address information from the cb to look up the lease.
1062 * using the same value twice allows me more flexibility. 1090 * using the same value twice allows me more flexibility.
1063 */ 1091 */
1064 1092
1065static isc_result_t  1093static isc_result_t
1066ddns_update_lease_ptr(struct lease *lease, 1094ddns_update_lease_ptr(struct lease *lease,
1067 struct iasubopt *lease6, 1095 struct iasubopt *lease6,
1068 dhcp_ddns_cb_t *ddns_cb, 1096 dhcp_ddns_cb_t *ddns_cb,
1069 dhcp_ddns_cb_t *ddns_cb_set, 1097 dhcp_ddns_cb_t *ddns_cb_set,
1070 const char * file, int line) 1098 const char * file, int line)
1071{ 1099{
1072 char ddns_address[MAX_ADDRESS_STRING_LEN]; 1100 char ddns_address[MAX_ADDRESS_STRING_LEN];
1073 sprintf(ddns_address, "unknown"); 1101 sprintf(ddns_address, "unknown");
1074 if (ddns_cb) { 1102 if (ddns_cb == NULL) {
 1103 log_info("%s(%d): No control block for lease update",
 1104 file, line);
 1105 return (ISC_R_FAILURE);
 1106 }
 1107 else {
1075 strncpy(ddns_address, piaddr(ddns_cb->address),  1108 strncpy(ddns_address, piaddr(ddns_cb->address),
1076 MAX_ADDRESS_STRING_LEN); 1109 MAX_ADDRESS_STRING_LEN);
1077 } 1110 }
1078#if defined (DEBUG_DNS_UPDATES) 1111#if defined (DEBUG_DNS_UPDATES)
1079 log_info("%s(%d): Updating lease_ptr for ddns_cp=%p (addr=%s)", 1112 log_info("%s(%d): Updating lease_ptr for ddns_cp=%p (addr=%s)",
1080 file, line, ddns_cb, ddns_address ); 1113 file, line, ddns_cb, ddns_address );
1081#endif 1114#endif
1082 1115
1083 /* 1116 /*
1084 * If the lease was static (for a fixed address) 1117 * If the lease was static (for a fixed address)
1085 * we don't need to do any work. 1118 * we don't need to do any work.
1086 */ 1119 */
1087 if (ddns_cb->flags & DDNS_STATIC_LEASE) { 1120 if (ddns_cb->flags & DDNS_STATIC_LEASE) {
1088#if defined (DEBUG_DNS_UPDATES) 1121#if defined (DEBUG_DNS_UPDATES)
1089 log_info("lease is static, returning"); 1122 log_info("lease is static, returning");
1090#endif 1123#endif
1091 return (ISC_R_SUCCESS); 1124 return (ISC_R_SUCCESS);
1092 } 1125 }
1093 1126
 1127 /*
 1128 * If we are processing an expired or released v6 lease
 1129 * we don't actually have a lease to update
 1130 */
 1131 if ((ddns_cb->address.len == 16) &&
 1132 ((ddns_cb->flags & DDNS_ACTIVE_LEASE) == 0)) {
 1133 return (ISC_R_SUCCESS);
 1134 }
 1135
1094 if (lease != NULL) { 1136 if (lease != NULL) {
1095 safe_lease_update(lease, ddns_cb, ddns_cb_set,  1137 safe_lease_update(lease, ddns_cb, ddns_cb_set,
1096 file, line); 1138 file, line);
1097 } else if (lease6 != NULL) { 1139 } else if (lease6 != NULL) {
1098 safe_lease6_update(lease6, ddns_cb, ddns_cb_set,  1140 safe_lease6_update(lease6, ddns_cb, ddns_cb_set,
1099 file, line); 1141 file, line);
1100 } else if (ddns_cb->address.len == 4) { 1142 } else if (ddns_cb->address.len == 4) {
1101 struct lease *find_lease = NULL; 1143 struct lease *find_lease = NULL;
1102 if (find_lease_by_ip_addr(&find_lease, 1144 if (find_lease_by_ip_addr(&find_lease,
1103 ddns_cb->address, MDL) != 0) { 1145 ddns_cb->address, MDL) != 0) {
1104#if defined (DEBUG_DNS_UPDATES) 1146#if defined (DEBUG_DNS_UPDATES)
1105 log_info("%s(%d): find_lease_by_ip_addr(%s) successful:" 1147 log_info("%s(%d): find_lease_by_ip_addr(%s) successful:"
1106 "lease=%p", file, line, ddns_address,  1148 "lease=%p", file, line, ddns_address,
@@ -1128,47 +1170,47 @@ ddns_update_lease_ptr(struct lease *l @@ -1128,47 +1170,47 @@ ddns_update_lease_ptr(struct lease *l
1128  1170
1129 } 1171 }
1130 } else if (ddns_cb->address.len == 16) { 1172 } else if (ddns_cb->address.len == 16) {
1131 struct iasubopt *find_lease6 = NULL; 1173 struct iasubopt *find_lease6 = NULL;
1132 struct ipv6_pool *pool = NULL; 1174 struct ipv6_pool *pool = NULL;
1133 struct in6_addr addr; 1175 struct in6_addr addr;
1134 char addrbuf[MAX_ADDRESS_STRING_LEN]; 1176 char addrbuf[MAX_ADDRESS_STRING_LEN];
1135 1177
1136 memcpy(&addr, &ddns_cb->address.iabuf, 16); 1178 memcpy(&addr, &ddns_cb->address.iabuf, 16);
1137 if ((find_ipv6_pool(&pool, D6O_IA_TA, &addr) !=  1179 if ((find_ipv6_pool(&pool, D6O_IA_TA, &addr) !=
1138 ISC_R_SUCCESS) && 1180 ISC_R_SUCCESS) &&
1139 (find_ipv6_pool(&pool, D6O_IA_NA, &addr) !=  1181 (find_ipv6_pool(&pool, D6O_IA_NA, &addr) !=
1140 ISC_R_SUCCESS)) { 1182 ISC_R_SUCCESS)) {
1141 inet_ntop(AF_INET6, &lease6->addr, addrbuf, 1183 inet_ntop(AF_INET6, &addr, addrbuf,
1142 MAX_ADDRESS_STRING_LEN); 1184 MAX_ADDRESS_STRING_LEN);
1143 log_error("%s(%d): Pool for lease %s not found.", 1185 log_error("%s(%d): Pool for lease %s not found.",
1144 file, line, addrbuf); 1186 file, line, addrbuf);
1145#if defined (DNS_UPDATES_MEMORY_CHECKS) 1187#if defined (DNS_UPDATES_MEMORY_CHECKS)
1146 update_lease_failed(NULL, NULL, ddns_cb, ddns_cb_set, 1188 update_lease_failed(NULL, NULL, ddns_cb, ddns_cb_set,
1147 file, line); 1189 file, line);
1148#endif 1190#endif
1149 /* 1191 /*
1150 * never reached. update_lease_failed  1192 * never reached. update_lease_failed
1151 * calls log_fatal.  1193 * calls log_fatal.
1152 */ 1194 */
1153 return(ISC_R_FAILURE); 1195 return(ISC_R_FAILURE);
1154 } 1196 }
1155 1197
1156 if (iasubopt_hash_lookup(&find_lease6, pool->leases, 1198 if (iasubopt_hash_lookup(&find_lease6, pool->leases,
1157 &addr, 16, MDL)) { 1199 &addr, 16, MDL)) {
1158 find_lease6->ddns_cb = ddns_cb_set; 1200 find_lease6->ddns_cb = ddns_cb_set;
1159 iasubopt_dereference(&find_lease6, MDL); 1201 iasubopt_dereference(&find_lease6, MDL);
1160 } else { 1202 } else {
1161 inet_ntop(AF_INET6, &lease6->addr, addrbuf, 1203 inet_ntop(AF_INET6, &addr, addrbuf,
1162 MAX_ADDRESS_STRING_LEN); 1204 MAX_ADDRESS_STRING_LEN);
1163 log_error("%s(%d): Lease %s not found within pool.", 1205 log_error("%s(%d): Lease %s not found within pool.",
1164 file, line, addrbuf); 1206 file, line, addrbuf);
1165#if defined (DNS_UPDATES_MEMORY_CHECKS) 1207#if defined (DNS_UPDATES_MEMORY_CHECKS)
1166 update_lease_failed(NULL, NULL, ddns_cb, ddns_cb_set, 1208 update_lease_failed(NULL, NULL, ddns_cb, ddns_cb_set,
1167 file, line); 1209 file, line);
1168#endif 1210#endif
1169 /* 1211 /*
1170 * never reached. update_lease_failed  1212 * never reached. update_lease_failed
1171 * calls log_fatal.  1213 * calls log_fatal.
1172 */ 1214 */
1173 return(ISC_R_FAILURE); 1215 return(ISC_R_FAILURE);
1174 } 1216 }
@@ -1237,26 +1279,31 @@ ddns_ptr_remove(dhcp_ddns_cb_t *ddns_cb, @@ -1237,26 +1279,31 @@ ddns_ptr_remove(dhcp_ddns_cb_t *ddns_cb,
1237 log_info("Removed reverse map on %.*s", 1279 log_info("Removed reverse map on %.*s",
1238 (int)ddns_cb->rev_name.len, 1280 (int)ddns_cb->rev_name.len,
1239 (const char *)ddns_cb->rev_name.data); 1281 (const char *)ddns_cb->rev_name.data);
1240 /* fall through */ 1282 /* fall through */
1241 case DNS_R_NXRRSET: 1283 case DNS_R_NXRRSET:
1242 case DNS_R_NXDOMAIN: 1284 case DNS_R_NXDOMAIN:
1243 /* No entry is the same as success. 1285 /* No entry is the same as success.
1244 * Remove the information from the lease and 1286 * Remove the information from the lease and
1245 * continue with any next step */ 1287 * continue with any next step */
1246 ddns_update_lease_text(ddns_cb, NULL); 1288 ddns_update_lease_text(ddns_cb, NULL);
1247 1289
1248 /* trigger any add operation */ 1290 /* trigger any add operation */
1249 result = ISC_R_SUCCESS; 1291 result = ISC_R_SUCCESS;
 1292#if defined (DEBUG_DNS_UPDATES)
 1293 log_info("DDNS: removed map or no reverse map to remove %.*s",
 1294 (int)ddns_cb->rev_name.len,
 1295 (const char *)ddns_cb->rev_name.data);
 1296#endif
1250 break; 1297 break;
1251 1298
1252 default: 1299 default:
1253 log_error("Can't remove reverse map on %.*s: %s", 1300 log_error("Can't remove reverse map on %.*s: %s",
1254 (int)ddns_cb->rev_name.len, 1301 (int)ddns_cb->rev_name.len,
1255 (const char *)ddns_cb->rev_name.data, 1302 (const char *)ddns_cb->rev_name.data,
1256 isc_result_totext (eresult)); 1303 isc_result_totext (eresult));
1257 break; 1304 break;
1258 } 1305 }
1259 1306
1260 ddns_update_lease_ptr(NULL, NULL, ddns_cb, NULL, MDL); 1307 ddns_update_lease_ptr(NULL, NULL, ddns_cb, NULL, MDL);
1261 ddns_fwd_srv_connector(NULL, NULL, NULL, ddns_cb->next_op, result); 1308 ddns_fwd_srv_connector(NULL, NULL, NULL, ddns_cb->next_op, result);
1262 ddns_cb_free(ddns_cb, MDL); 1309 ddns_cb_free(ddns_cb, MDL);
@@ -1311,27 +1358,27 @@ ddns_fwd_srv_add2(dhcp_ddns_cb_t *ddns_c @@ -1311,27 +1358,27 @@ ddns_fwd_srv_add2(dhcp_ddns_cb_t *ddns_c
1311 ddns_address); 1358 ddns_address);
1312 1359
1313 ddns_update_lease_text(ddns_cb, NULL); 1360 ddns_update_lease_text(ddns_cb, NULL);
1314 1361
1315 if ((ddns_cb->flags & DDNS_UPDATE_PTR) != 0) { 1362 if ((ddns_cb->flags & DDNS_UPDATE_PTR) != 0) {
1316 /* if we have zone information get rid of it */ 1363 /* if we have zone information get rid of it */
1317 if (ddns_cb->zone != NULL) { 1364 if (ddns_cb->zone != NULL) {
1318 ddns_cb_forget_zone(ddns_cb); 1365 ddns_cb_forget_zone(ddns_cb);
1319 } 1366 }
1320 1367
1321 ddns_cb->state = DDNS_STATE_ADD_PTR; 1368 ddns_cb->state = DDNS_STATE_ADD_PTR;
1322 ddns_cb->cur_func = ddns_ptr_add; 1369 ddns_cb->cur_func = ddns_ptr_add;
1323  1370
1324 result = ddns_modify_ptr(ddns_cb); 1371 result = ddns_modify_ptr(ddns_cb, MDL);
1325 if (result == ISC_R_SUCCESS) { 1372 if (result == ISC_R_SUCCESS) {
1326 return; 1373 return;
1327 } 1374 }
1328 } 1375 }
1329 break; 1376 break;
1330 1377
1331 case DNS_R_YXRRSET: 1378 case DNS_R_YXRRSET:
1332 case DNS_R_YXDOMAIN: 1379 case DNS_R_YXDOMAIN:
1333 logstr = "DHCID mismatch, belongs to another client."; 1380 logstr = "DHCID mismatch, belongs to another client.";
1334 break; 1381 break;
1335 1382
1336 case DNS_R_NXRRSET: 1383 case DNS_R_NXRRSET:
1337 case DNS_R_NXDOMAIN: 1384 case DNS_R_NXDOMAIN:
@@ -1384,44 +1431,42 @@ ddns_fwd_srv_add1(dhcp_ddns_cb_t *ddns_c @@ -1384,44 +1431,42 @@ ddns_fwd_srv_add1(dhcp_ddns_cb_t *ddns_c
1384 ddns_address); 1431 ddns_address);
1385 1432
1386 ddns_update_lease_text(ddns_cb, NULL); 1433 ddns_update_lease_text(ddns_cb, NULL);
1387 1434
1388 if ((ddns_cb->flags & DDNS_UPDATE_PTR) != 0) { 1435 if ((ddns_cb->flags & DDNS_UPDATE_PTR) != 0) {
1389 /* if we have zone information get rid of it */ 1436 /* if we have zone information get rid of it */
1390 if (ddns_cb->zone != NULL) { 1437 if (ddns_cb->zone != NULL) {
1391 ddns_cb_forget_zone(ddns_cb); 1438 ddns_cb_forget_zone(ddns_cb);
1392 } 1439 }
1393 1440
1394 ddns_cb->state = DDNS_STATE_ADD_PTR; 1441 ddns_cb->state = DDNS_STATE_ADD_PTR;
1395 ddns_cb->cur_func = ddns_ptr_add; 1442 ddns_cb->cur_func = ddns_ptr_add;
1396  1443
1397 result = ddns_modify_ptr(ddns_cb); 1444 result = ddns_modify_ptr(ddns_cb, MDL);
1398 if (result == ISC_R_SUCCESS) { 1445 if (result == ISC_R_SUCCESS) {
1399 return; 1446 return;
1400 } 1447 }
1401 } 1448 }
1402  
1403 break; 1449 break;
1404 1450
1405 case DNS_R_YXDOMAIN: 1451 case DNS_R_YXDOMAIN:
1406 /* we can reuse the zone information */ 1452 /* we can reuse the zone information */
1407 ddns_cb->state = DDNS_STATE_ADD_FW_YXDHCID; 1453 ddns_cb->state = DDNS_STATE_ADD_FW_YXDHCID;
1408 ddns_cb->cur_func = ddns_fwd_srv_add2; 1454 ddns_cb->cur_func = ddns_fwd_srv_add2;
1409  1455
1410 result = ddns_modify_fwd(ddns_cb); 1456 result = ddns_modify_fwd(ddns_cb, MDL);
1411 if (result == ISC_R_SUCCESS) { 1457 if (result == ISC_R_SUCCESS) {
1412 return; 1458 return;
1413 } 1459 }
1414 
1415 break; 1460 break;
1416 1461
1417 default: 1462 default:
1418 log_error ("Unable to add forward map from %.*s to %s: %s", 1463 log_error ("Unable to add forward map from %.*s to %s: %s",
1419 (int)ddns_cb->fwd_name.len, 1464 (int)ddns_cb->fwd_name.len,
1420 (const char *)ddns_cb->fwd_name.data, 1465 (const char *)ddns_cb->fwd_name.data,
1421 ddns_address, 1466 ddns_address,
1422 isc_result_totext (eresult)); 1467 isc_result_totext (eresult));
1423 break; 1468 break;
1424 } 1469 }
1425 1470
1426 ddns_update_lease_ptr(NULL, NULL, ddns_cb, NULL, MDL); 1471 ddns_update_lease_ptr(NULL, NULL, ddns_cb, NULL, MDL);
1427 ddns_cb_free(ddns_cb, MDL); 1472 ddns_cb_free(ddns_cb, MDL);
@@ -1452,32 +1497,32 @@ ddns_fwd_srv_connector(struct lease  @@ -1452,32 +1497,32 @@ ddns_fwd_srv_connector(struct lease
1452 /* nothing to do */ 1497 /* nothing to do */
1453 return; 1498 return;
1454 } 1499 }
1455 1500
1456 if (eresult == ISC_R_SUCCESS) { 1501 if (eresult == ISC_R_SUCCESS) {
1457 /* 1502 /*
1458 * If we have updates dispatch as appropriate, 1503 * If we have updates dispatch as appropriate,
1459 * if not do FQDN binding if desired. 1504 * if not do FQDN binding if desired.
1460 */ 1505 */
1461 1506
1462 if (ddns_cb->flags & DDNS_UPDATE_ADDR) { 1507 if (ddns_cb->flags & DDNS_UPDATE_ADDR) {
1463 ddns_cb->state = DDNS_STATE_ADD_FW_NXDOMAIN; 1508 ddns_cb->state = DDNS_STATE_ADD_FW_NXDOMAIN;
1464 ddns_cb->cur_func = ddns_fwd_srv_add1; 1509 ddns_cb->cur_func = ddns_fwd_srv_add1;
1465 result = ddns_modify_fwd(ddns_cb); 1510 result = ddns_modify_fwd(ddns_cb, MDL);
1466 } else if ((ddns_cb->flags & DDNS_UPDATE_PTR) && 1511 } else if ((ddns_cb->flags & DDNS_UPDATE_PTR) &&
1467 (ddns_cb->rev_name.len != 0)) { 1512 (ddns_cb->rev_name.len != 0)) {
1468 ddns_cb->state = DDNS_STATE_ADD_PTR; 1513 ddns_cb->state = DDNS_STATE_ADD_PTR;
1469 ddns_cb->cur_func = ddns_ptr_add; 1514 ddns_cb->cur_func = ddns_ptr_add;
1470 result = ddns_modify_ptr(ddns_cb); 1515 result = ddns_modify_ptr(ddns_cb, MDL);
1471 } else { 1516 } else {
1472 ddns_update_lease_text(ddns_cb, inscope); 1517 ddns_update_lease_text(ddns_cb, inscope);
1473 } 1518 }
1474 } 1519 }
1475 1520
1476 if (result == ISC_R_SUCCESS) { 1521 if (result == ISC_R_SUCCESS) {
1477 ddns_update_lease_ptr(lease, lease6, ddns_cb, ddns_cb, MDL); 1522 ddns_update_lease_ptr(lease, lease6, ddns_cb, ddns_cb, MDL);
1478 } else { 1523 } else {
1479 ddns_cb_free(ddns_cb, MDL); 1524 ddns_cb_free(ddns_cb, MDL);
1480 } 1525 }
1481 1526
1482 return; 1527 return;
1483} 1528}
@@ -1502,27 +1547,27 @@ ddns_fwd_srv_rem2(dhcp_ddns_cb_t *ddns_c @@ -1502,27 +1547,27 @@ ddns_fwd_srv_rem2(dhcp_ddns_cb_t *ddns_c
1502 if (eresult == ISC_R_SUCCESS) { 1547 if (eresult == ISC_R_SUCCESS) {
1503 ddns_update_lease_text(ddns_cb, NULL); 1548 ddns_update_lease_text(ddns_cb, NULL);
1504 1549
1505 /* Do the next operation */ 1550 /* Do the next operation */
1506 if ((ddns_cb->flags & DDNS_UPDATE_PTR) != 0) { 1551 if ((ddns_cb->flags & DDNS_UPDATE_PTR) != 0) {
1507 /* if we have zone information get rid of it */ 1552 /* if we have zone information get rid of it */
1508 if (ddns_cb->zone != NULL) { 1553 if (ddns_cb->zone != NULL) {
1509 ddns_cb_forget_zone(ddns_cb); 1554 ddns_cb_forget_zone(ddns_cb);
1510 } 1555 }
1511 1556
1512 ddns_cb->state = DDNS_STATE_REM_PTR; 1557 ddns_cb->state = DDNS_STATE_REM_PTR;
1513 ddns_cb->cur_func = ddns_ptr_remove; 1558 ddns_cb->cur_func = ddns_ptr_remove;
1514  1559
1515 eresult = ddns_modify_ptr(ddns_cb); 1560 eresult = ddns_modify_ptr(ddns_cb, MDL);
1516 if (eresult == ISC_R_SUCCESS) { 1561 if (eresult == ISC_R_SUCCESS) {
1517 return; 1562 return;
1518 } 1563 }
1519 } 1564 }
1520 } 1565 }
1521 1566
1522 ddns_update_lease_ptr(NULL, NULL, ddns_cb, NULL, MDL); 1567 ddns_update_lease_ptr(NULL, NULL, ddns_cb, NULL, MDL);
1523 ddns_fwd_srv_connector(NULL, NULL, NULL, ddns_cb->next_op, eresult); 1568 ddns_fwd_srv_connector(NULL, NULL, NULL, ddns_cb->next_op, eresult);
1524 ddns_cb_free(ddns_cb, MDL); 1569 ddns_cb_free(ddns_cb, MDL);
1525 return; 1570 return;
1526} 1571}
1527 1572
1528 1573
@@ -1542,124 +1587,224 @@ ddns_fwd_srv_rem1(dhcp_ddns_cb_t *ddns_c @@ -1542,124 +1587,224 @@ ddns_fwd_srv_rem1(dhcp_ddns_cb_t *ddns_c
1542 1587
1543 switch(eresult) { 1588 switch(eresult) {
1544 case ISC_R_SUCCESS: 1589 case ISC_R_SUCCESS:
1545 /* Construct a printable form of the address for logging */ 1590 /* Construct a printable form of the address for logging */
1546 strcpy(ddns_address, piaddr(ddns_cb->address)); 1591 strcpy(ddns_address, piaddr(ddns_cb->address));
1547 log_info("Removed forward map from %.*s to %s", 1592 log_info("Removed forward map from %.*s to %s",
1548 (int)ddns_cb->fwd_name.len,  1593 (int)ddns_cb->fwd_name.len,
1549 (const char*)ddns_cb->fwd_name.data, 1594 (const char*)ddns_cb->fwd_name.data,
1550 ddns_address); 1595 ddns_address);
1551 1596
1552 /* Do the second step of the FWD removal */ 1597 /* Do the second step of the FWD removal */
1553 ddns_cb->state = DDNS_STATE_REM_FW_NXRR; 1598 ddns_cb->state = DDNS_STATE_REM_FW_NXRR;
1554 ddns_cb->cur_func = ddns_fwd_srv_rem2; 1599 ddns_cb->cur_func = ddns_fwd_srv_rem2;
1555 result = ddns_modify_fwd(ddns_cb); 1600 result = ddns_modify_fwd(ddns_cb, MDL);
1556 if (result == ISC_R_SUCCESS) { 1601 if (result == ISC_R_SUCCESS) {
1557 return; 1602 return;
1558 } 1603 }
1559 break; 1604 break;
1560 1605
1561 case DNS_R_NXRRSET: 1606 case DNS_R_NXRRSET:
1562 case DNS_R_NXDOMAIN: 1607 case DNS_R_NXDOMAIN:
1563 ddns_update_lease_text(ddns_cb, NULL); 1608 ddns_update_lease_text(ddns_cb, NULL);
1564 1609
 1610#if defined (DEBUG_DNS_UPDATES)
 1611 log_info("DDNS: no forward map to remove. %p", ddns_cb);
 1612#endif
 1613
1565 /* Do the next operation */ 1614 /* Do the next operation */
1566 if ((ddns_cb->flags & DDNS_UPDATE_PTR) != 0) { 1615 if ((ddns_cb->flags & DDNS_UPDATE_PTR) != 0) {
1567 /* if we have zone information get rid of it */ 1616 /* if we have zone information get rid of it */
1568 if (ddns_cb->zone != NULL) { 1617 if (ddns_cb->zone != NULL) {
1569 ddns_cb_forget_zone(ddns_cb); 1618 ddns_cb_forget_zone(ddns_cb);
1570 } 1619 }
1571 1620
1572 ddns_cb->state = DDNS_STATE_REM_PTR; 1621 ddns_cb->state = DDNS_STATE_REM_PTR;
1573 ddns_cb->cur_func = ddns_ptr_remove; 1622 ddns_cb->cur_func = ddns_ptr_remove;
1574  1623
1575 result = ddns_modify_ptr(ddns_cb); 1624 result = ddns_modify_ptr(ddns_cb, MDL);
1576 if (result == ISC_R_SUCCESS) { 1625 if (result == ISC_R_SUCCESS) {
1577 return; 1626 return;
1578 } 1627 }
1579 } 1628 }
1580 else { 1629 else {
1581 /* Trigger the add operation */ 1630 /* Trigger the add operation */
1582 eresult = ISC_R_SUCCESS; 1631 eresult = ISC_R_SUCCESS;
1583 } 1632 }
1584 break; 1633 break;
1585  1634
1586 default: 1635 default:
1587 break; 1636 break;
1588 } 1637 }
1589 1638
1590 ddns_update_lease_ptr(NULL, NULL, ddns_cb, NULL, MDL); 1639 ddns_update_lease_ptr(NULL, NULL, ddns_cb, NULL, MDL);
1591 ddns_fwd_srv_connector(NULL, NULL, NULL, ddns_cb->next_op, eresult); 1640 ddns_fwd_srv_connector(NULL, NULL, NULL, ddns_cb->next_op, eresult);
1592 ddns_cb_free(ddns_cb, MDL); 1641 ddns_cb_free(ddns_cb, MDL);
1593} 1642}
1594 1643
1595 1644/*%<
1596/* 
1597 * Remove relevant entries from DNS. 1645 * Remove relevant entries from DNS.
1598 * 1646 *
1599 * Return values: 1647 * \li lease - lease to start with if this is for v4
1600 * 0 - badness occurred and we weren't able to do what was wanted 1648 *
1601 * 1 - we were able to do stuff but it's in progress 1649 * \li lease6 - lease to start with if this is for v6
 1650 *
 1651 * \li add_ddns_cb - control block for additional DDNS work. This
 1652 * is used when the code is going to add a DDNS entry after removing
 1653 * the current entry.
 1654 *
 1655 * \li active - indication about the status of the lease. It is
 1656 * ISC_TRUE if the lease is still active, and FALSE if the lease
 1657 * is inactive. This is used to indicate if the lease is inactive or going
 1658 * to inactive so we can avoid trying to update the lease with cb pointers
 1659 * and text information if it isn't useful.
 1660 *
 1661 * Returns
 1662 * \li #ISC_R_FAILURE - badness occurred and we weren't able to do what was wanted
 1663 * \li #ISC_R_SUCCESS - we were able to do stuff but it's in progress
 1664 *
1602 * in both cases any additional block has been passed on to it's handler 1665 * in both cases any additional block has been passed on to it's handler
1603 */ 1666 */
1604 1667
1605int 1668isc_result_t
1606ddns_removals(struct lease *lease, 1669ddns_removals(struct lease *lease,
1607 struct iasubopt *lease6, 1670 struct iasubopt *lease6,
1608 dhcp_ddns_cb_t *add_ddns_cb) 1671 dhcp_ddns_cb_t *add_ddns_cb,
 1672 isc_boolean_t active)
1609{ 1673{
1610 isc_result_t rcode, execute_add = ISC_R_FAILURE; 1674 isc_result_t rcode, execute_add = ISC_R_FAILURE;
1611 struct binding_scope **scope = NULL; 1675 struct binding_scope **scope = NULL;
1612 int result = 0; 1676 isc_result_t result = ISC_R_FAILURE;
1613 dhcp_ddns_cb_t *ddns_cb = NULL; 1677 dhcp_ddns_cb_t *ddns_cb = NULL;
1614 struct data_string leaseid; 1678 struct data_string leaseid;
1615 1679
1616 /* 1680 /*
1617 * Cancel any outstanding requests. When called 1681 * See if we need to cancel an outstanding request. Mostly this is
1618 * from within the DNS code we probably will have 1682 * used to handle the case where this routine is called twice for
1619 * already done the cancel but if called from outside 1683 * the same release or abandon event.
1620 * - for example as part of a lease expiry - we won't. 1684 *
1621 */ 1685 * When called from the dns code as part of an update request
1622 if ((lease != NULL) && (lease->ddns_cb != NULL)) { 1686 * (add_ddns_cb != NULL) any outstanding requests will have already
1623 ddns_cancel(lease->ddns_cb); 1687 * been cancelled.
1624 lease->ddns_cb = NULL; 1688 *
1625 } else if ((lease6 != NULL) && (lease6->ddns_cb != NULL)) { 1689 * If the new request is just a removal and we have an outstanding
1626 ddns_cancel(lease6->ddns_cb); 1690 * request we have several options:
1627 lease6->ddns_cb = NULL; 1691 *
 1692 * - we are doing an update or we are doing a removal and the active
 1693 * flag has changed from TRUE to FALSE. In these cases we need to
 1694 * cancel the old request and start the new one.
 1695 *
 1696 * - other wise we are doing a removal with the active flag unchanged.
 1697 * In this case we can let the current removal continue and do not need
 1698 * to start a new one. If the old request included an update to be
 1699 * done after the removal we need to kill the update part of the
 1700 * request.
 1701 */
 1702
 1703 if (add_ddns_cb == NULL) {
 1704 if ((lease != NULL) && (lease->ddns_cb != NULL)) {
 1705 ddns_cb = lease->ddns_cb;
 1706
 1707 /*
 1708 * Is the old request an update or did the
 1709 * the active flag change?
 1710 */
 1711 if (((ddns_cb->state == DDNS_STATE_ADD_PTR) ||
 1712 (ddns_cb->state == DDNS_STATE_ADD_FW_NXDOMAIN) ||
 1713 (ddns_cb->state == DDNS_STATE_ADD_FW_YXDHCID)) ||
 1714 ((active == ISC_FALSE) &&
 1715 ((ddns_cb->flags & DDNS_ACTIVE_LEASE) != 0))) {
 1716 /* Cancel the current request */
 1717 ddns_cancel(lease->ddns_cb, MDL);
 1718 lease->ddns_cb = NULL;
 1719 } else {
 1720 /* Remvoval, check and remove updates */
 1721 if (ddns_cb->next_op != NULL) {
 1722 ddns_cb_free(ddns_cb->next_op, MDL);
 1723 ddns_cb->next_op = NULL;
 1724 }
 1725#if defined (DEBUG_DNS_UPDATES)
 1726 log_info("DDNS %s(%d): removal already in "
 1727 "progress new ddns_cb=%p",
 1728 MDL, ddns_cb);
 1729#endif
 1730 return (ISC_R_SUCCESS);
 1731 }
 1732 } else if ((lease6 != NULL) && (lease6->ddns_cb != NULL)) {
 1733 ddns_cb = lease6->ddns_cb;
 1734
 1735 /*
 1736 * Is the old request an update or did the
 1737 * the active flag change?
 1738 */
 1739 if (((ddns_cb->state == DDNS_STATE_ADD_PTR) ||
 1740 (ddns_cb->state == DDNS_STATE_ADD_FW_NXDOMAIN) ||
 1741 (ddns_cb->state == DDNS_STATE_ADD_FW_YXDHCID)) ||
 1742 ((active == ISC_FALSE) &&
 1743 ((ddns_cb->flags & DDNS_ACTIVE_LEASE) != 0))) {
 1744 /* Cancel the current request */
 1745 ddns_cancel(lease6->ddns_cb, MDL);
 1746 lease6->ddns_cb = NULL;
 1747 } else {
 1748 /* Remvoval, check and remove updates */
 1749 if (ddns_cb->next_op != NULL) {
 1750 ddns_cb_free(ddns_cb->next_op, MDL);
 1751 ddns_cb->next_op = NULL;
 1752 }
 1753#if defined (DEBUG_DNS_UPDATES)
 1754 log_info("DDNS %s(%d): removal already in "
 1755 "progress new ddns_cb=%p",
 1756 MDL, ddns_cb);
 1757#endif
 1758 return (ISC_R_SUCCESS);
 1759 }
 1760 }
 1761 ddns_cb = NULL;
1628 } 1762 }
1629 1763
1630 /* allocate our control block */ 1764 /* allocate our control block */
1631 ddns_cb = ddns_cb_alloc(MDL); 1765 ddns_cb = ddns_cb_alloc(MDL);
1632 if (ddns_cb == NULL) { 1766 if (ddns_cb == NULL) {
1633 goto cleanup; 1767 goto cleanup;
1634 } 1768 }
1635 1769
1636 /* 1770 /*
1637 * For v4 we flag static leases so we don't try 1771 * For v4 we flag static leases so we don't try
1638 * and manipulate the lease later. For v6 we don't 1772 * and manipulate the lease later. For v6 we don't
1639 * get static leases and don't need to flag them. 1773 * get static leases and don't need to flag them.
1640 */ 1774 */
1641 if (lease != NULL) { 1775 if (lease != NULL) {
1642 scope = &(lease->scope); 1776 scope = &(lease->scope);
1643 ddns_cb->address = lease->ip_addr; 1777 ddns_cb->address = lease->ip_addr;
1644 if (lease->flags & STATIC_LEASE) 1778 if (lease->flags & STATIC_LEASE)
1645 ddns_cb->flags |= DDNS_STATIC_LEASE; 1779 ddns_cb->flags |= DDNS_STATIC_LEASE;
1646 } else if (lease6 != NULL) { 1780 } else if (lease6 != NULL) {
1647 scope = &(lease6->scope); 1781 scope = &(lease6->scope);
1648 memcpy(&ddns_cb->address.iabuf, lease6->addr.s6_addr, 16); 1782 memcpy(&ddns_cb->address.iabuf, lease6->addr.s6_addr, 16);
1649 ddns_cb->address.len = 16; 1783 ddns_cb->address.len = 16;
1650 } else 1784 } else
1651 goto cleanup; 1785 goto cleanup;
1652 1786
 1787 /*
 1788 * Set the flag bit if the lease is active, that is it isn't
 1789 * expired or released. This is used to determine if we need
 1790 * to update the scope information for both v4 and v6 and
 1791 * the lease information for v6 when the response
 1792 * from the DNS code is processed.
 1793 */
 1794 if (active == ISC_TRUE) {
 1795 ddns_cb->flags |= DDNS_ACTIVE_LEASE;
 1796 }
 1797
1653 /* No scope implies that DDNS has not been performed for this lease. */ 1798 /* No scope implies that DDNS has not been performed for this lease. */
1654 if (*scope == NULL) 1799 if (*scope == NULL)
1655 goto cleanup; 1800 goto cleanup;
1656 1801
1657 if (ddns_update_style != 2) 1802 if (ddns_update_style != 2)
1658 goto cleanup; 1803 goto cleanup;
1659 1804
1660 /* Assume that we are removing both records */ 1805 /* Assume that we are removing both records */
1661 ddns_cb->flags |= DDNS_UPDATE_ADDR | DDNS_UPDATE_PTR; 1806 ddns_cb->flags |= DDNS_UPDATE_ADDR | DDNS_UPDATE_PTR;
1662 1807
1663 /* and that we want to do the add call */ 1808 /* and that we want to do the add call */
1664 execute_add = ISC_R_SUCCESS; 1809 execute_add = ISC_R_SUCCESS;
1665 1810
@@ -1724,31 +1869,31 @@ ddns_removals(struct lease *lease, @@ -1724,31 +1869,31 @@ ddns_removals(struct lease *lease,
1724 /* 1869 /*
1725 * Now that we've collected the information we can try to process it. 1870 * Now that we've collected the information we can try to process it.
1726 * If necessary we call an appropriate routine to send a message and 1871 * If necessary we call an appropriate routine to send a message and
1727 * provide it with an action routine to run on the control block given 1872 * provide it with an action routine to run on the control block given
1728 * the results of the message. We have three entry points from here, 1873 * the results of the message. We have three entry points from here,
1729 * one for removing the A record, the next for removing the PTR and 1874 * one for removing the A record, the next for removing the PTR and
1730 * the third for doing any requested add. 1875 * the third for doing any requested add.
1731 */ 1876 */
1732 if ((ddns_cb->flags & DDNS_UPDATE_ADDR) != 0) { 1877 if ((ddns_cb->flags & DDNS_UPDATE_ADDR) != 0) {
1733 if (ddns_cb->fwd_name.len != 0) { 1878 if (ddns_cb->fwd_name.len != 0) {
1734 ddns_cb->state = DDNS_STATE_REM_FW_YXDHCID; 1879 ddns_cb->state = DDNS_STATE_REM_FW_YXDHCID;
1735 ddns_cb->cur_func = ddns_fwd_srv_rem1; 1880 ddns_cb->cur_func = ddns_fwd_srv_rem1;
1736 1881
1737 rcode = ddns_modify_fwd(ddns_cb); 1882 rcode = ddns_modify_fwd(ddns_cb, MDL);
1738 if (rcode == ISC_R_SUCCESS) { 1883 if (rcode == ISC_R_SUCCESS) {
1739 ddns_update_lease_ptr(lease, lease6, ddns_cb, 1884 ddns_update_lease_ptr(lease, lease6, ddns_cb,
1740 ddns_cb, MDL); 1885 ddns_cb, MDL);
1741 return(1); 1886 return (ISC_R_SUCCESS);
1742 } 1887 }
1743 1888
1744 /* 1889 /*
1745 * We weren't able to process the request tag the 1890 * We weren't able to process the request tag the
1746 * add so we won't execute it. 1891 * add so we won't execute it.
1747 */ 1892 */
1748 execute_add = ISC_R_FAILURE; 1893 execute_add = ISC_R_FAILURE;
1749 goto cleanup; 1894 goto cleanup;
1750 } 1895 }
1751 else { 1896 else {
1752 /*remove info from scope */ 1897 /*remove info from scope */
1753 unset(*scope, "ddns-fwd-name"); 1898 unset(*scope, "ddns-fwd-name");
1754 unset(*scope, "ddns-txt"); 1899 unset(*scope, "ddns-txt");
@@ -1761,44 +1906,44 @@ ddns_removals(struct lease *lease, @@ -1761,44 +1906,44 @@ ddns_removals(struct lease *lease,
1761 1906
1762 /* 1907 /*
1763 * if execute add isn't success remove the control block so 1908 * if execute add isn't success remove the control block so
1764 * it won't be processed when the remove completes. We 1909 * it won't be processed when the remove completes. We
1765 * also arrange to clean it up and get rid of it. 1910 * also arrange to clean it up and get rid of it.
1766 */ 1911 */
1767 if (execute_add != ISC_R_SUCCESS) { 1912 if (execute_add != ISC_R_SUCCESS) {
1768 ddns_cb->next_op = NULL; 1913 ddns_cb->next_op = NULL;
1769 ddns_fwd_srv_connector(lease, lease6, scope,  1914 ddns_fwd_srv_connector(lease, lease6, scope,
1770 add_ddns_cb, execute_add); 1915 add_ddns_cb, execute_add);
1771 add_ddns_cb = NULL; 1916 add_ddns_cb = NULL;
1772 } 1917 }
1773 else { 1918 else {
1774 result = 1; 1919 result = ISC_R_SUCCESS;
1775 } 1920 }
1776 1921
1777 rcode = ddns_modify_ptr(ddns_cb); 1922 rcode = ddns_modify_ptr(ddns_cb, MDL);
1778 if (rcode == ISC_R_SUCCESS) { 1923 if (rcode == ISC_R_SUCCESS) {
1779 ddns_update_lease_ptr(lease, lease6, ddns_cb, ddns_cb, 1924 ddns_update_lease_ptr(lease, lease6, ddns_cb, ddns_cb,
1780 MDL); 1925 MDL);
1781 return(result); 1926 return (result);
1782 } 1927 }
1783 1928
1784 /* We weren't able to process the request tag the 1929 /* We weren't able to process the request tag the
1785 * add so we won't execute it */ 1930 * add so we won't execute it */
1786 execute_add = ISC_R_FAILURE; 1931 execute_add = ISC_R_FAILURE;
1787 goto cleanup; 1932 goto cleanup;
1788 } 1933 }
1789 1934
1790 cleanup: 1935 cleanup:
1791 /* 1936 /*
1792 * We've gotten here because we didn't need to send a message or 1937 * We've gotten here because we didn't need to send a message or
1793 * we failed when trying to do so. We send the additional cb 1938 * we failed when trying to do so. We send the additional cb
1794 * off to handle sending and/or cleanup and cleanup anything 1939 * off to handle sending and/or cleanup and cleanup anything
1795 * we allocated here. 1940 * we allocated here.
1796 */ 1941 */
1797 ddns_fwd_srv_connector(lease, lease6, scope, add_ddns_cb, execute_add); 1942 ddns_fwd_srv_connector(lease, lease6, scope, add_ddns_cb, execute_add);
1798 if (ddns_cb != NULL)  1943 if (ddns_cb != NULL)
1799 ddns_cb_free(ddns_cb, MDL); 1944 ddns_cb_free(ddns_cb, MDL);
1800 1945
1801 return(result); 1946 return (result);
1802} 1947}
1803 1948
1804#endif /* NSUPDATE */ 1949#endif /* NSUPDATE */

cvs diff -r1.2 -r1.3 src/external/bsd/dhcp/dist/server/Attic/dhcpleasequery.c (expand / switch to unified diff)

--- src/external/bsd/dhcp/dist/server/Attic/dhcpleasequery.c 2013/03/24 15:53:59 1.2
+++ src/external/bsd/dhcp/dist/server/Attic/dhcpleasequery.c 2013/03/24 23:03:06 1.3
@@ -1,16 +1,17 @@ @@ -1,16 +1,17 @@
1/* $NetBSD: dhcpleasequery.c,v 1.2 2013/03/24 15:53:59 christos Exp $ */ 1/* $NetBSD: dhcpleasequery.c,v 1.3 2013/03/24 23:03:06 christos Exp $ */
2 2
3/* 3/*
 4 * Copyright (C) 2011-2012 by Internet Systems Consortium, Inc. ("ISC")
4 * Copyright (C) 2006-2007,2009 by Internet Systems Consortium, Inc. ("ISC") 5 * Copyright (C) 2006-2007,2009 by Internet Systems Consortium, Inc. ("ISC")
5 * 6 *
6 * Permission to use, copy, modify, and distribute this software for any 7 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above 8 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies. 9 * copyright notice and this permission notice appear in all copies.
9 * 10 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE. 17 * PERFORMANCE OF THIS SOFTWARE.
@@ -446,30 +447,27 @@ dhcpleasequery(struct packet *packet, in @@ -446,30 +447,27 @@ dhcpleasequery(struct packet *packet, in
446 * These seem to be hard-coded in ISC DHCP, to 0.5 and 447 * These seem to be hard-coded in ISC DHCP, to 0.5 and
447 * 0.875 of the lease time. 448 * 0.875 of the lease time.
448 */ 449 */
449 450
450 lease_duration = lease->ends - lease->starts; 451 lease_duration = lease->ends - lease->starts;
451 time_renewal = lease->starts +  452 time_renewal = lease->starts +
452 (lease_duration / 2); 453 (lease_duration / 2);
453 time_rebinding = lease->starts +  454 time_rebinding = lease->starts +
454 (lease_duration / 2) + 455 (lease_duration / 2) +
455 (lease_duration / 4) + 456 (lease_duration / 4) +
456 (lease_duration / 8); 457 (lease_duration / 8);
457 458
458 if (time_renewal > cur_time) { 459 if (time_renewal > cur_time) {
459 if (time_renewal < cur_time) 460 time_renewal = htonl(time_renewal - cur_time);
460 time_renewal = 0; 
461 else 
462 time_renewal = htonl(time_renewal - cur_time); 
463 461
464 if (!add_option(options,  462 if (!add_option(options,
465 DHO_DHCP_RENEWAL_TIME, 463 DHO_DHCP_RENEWAL_TIME,
466 &time_renewal,  464 &time_renewal,
467 sizeof(time_renewal))) { 465 sizeof(time_renewal))) {
468 option_state_dereference(&options, MDL); 466 option_state_dereference(&options, MDL);
469 lease_dereference(&lease, MDL); 467 lease_dereference(&lease, MDL);
470 log_info("%s: out of memory, no reply sent", 468 log_info("%s: out of memory, no reply sent",
471 msgbuf); 469 msgbuf);
472 return; 470 return;
473 } 471 }
474 } 472 }
475 473
@@ -479,35 +477,28 @@ dhcpleasequery(struct packet *packet, in @@ -479,35 +477,28 @@ dhcpleasequery(struct packet *packet, in
479 if (!add_option(options,  477 if (!add_option(options,
480 DHO_DHCP_REBINDING_TIME, 478 DHO_DHCP_REBINDING_TIME,
481 &time_rebinding,  479 &time_rebinding,
482 sizeof(time_rebinding))) { 480 sizeof(time_rebinding))) {
483 option_state_dereference(&options, MDL); 481 option_state_dereference(&options, MDL);
484 lease_dereference(&lease, MDL); 482 lease_dereference(&lease, MDL);
485 log_info("%s: out of memory, no reply sent", 483 log_info("%s: out of memory, no reply sent",
486 msgbuf); 484 msgbuf);
487 return; 485 return;
488 } 486 }
489 } 487 }
490 488
491 if (lease->ends > cur_time) { 489 if (lease->ends > cur_time) {
492 if (time_expiry < cur_time) { 
493 log_error("Impossible condition at %s:%d.", 
494 MDL); 
495 
496 option_state_dereference(&options, MDL); 
497 lease_dereference(&lease, MDL); 
498 return; 
499 } 
500 time_expiry = htonl(lease->ends - cur_time); 490 time_expiry = htonl(lease->ends - cur_time);
 491
501 if (!add_option(options,  492 if (!add_option(options,
502 DHO_DHCP_LEASE_TIME, 493 DHO_DHCP_LEASE_TIME,
503 &time_expiry,  494 &time_expiry,
504 sizeof(time_expiry))) { 495 sizeof(time_expiry))) {
505 option_state_dereference(&options, MDL); 496 option_state_dereference(&options, MDL);
506 lease_dereference(&lease, MDL); 497 lease_dereference(&lease, MDL);
507 log_info("%s: out of memory, no reply sent", 498 log_info("%s: out of memory, no reply sent",
508 msgbuf); 499 msgbuf);
509 return; 500 return;
510 } 501 }
511 } 502 }
512 503
513 /* Supply the Vendor-Class-Identifier. */ 504 /* Supply the Vendor-Class-Identifier. */
@@ -617,27 +608,27 @@ dhcpleasequery(struct packet *packet, in @@ -617,27 +608,27 @@ dhcpleasequery(struct packet *packet, in
617 lease_dereference(&lease, MDL); 608 lease_dereference(&lease, MDL);
618 log_info("%s: error adding option, no reply sent", msgbuf); 609 log_info("%s: error adding option, no reply sent", msgbuf);
619 return; 610 return;
620 } 611 }
621 612
622 /* 613 /*
623 * Log the message we've received. 614 * Log the message we've received.
624 */ 615 */
625 log_info("%s", msgbuf); 616 log_info("%s", msgbuf);
626 617
627 /* 618 /*
628 * Figure out which address to use to send from. 619 * Figure out which address to use to send from.
629 */ 620 */
630 get_server_source_address(&siaddr, options, packet); 621 get_server_source_address(&siaddr, options, options, packet);
631 622
632 /*  623 /*
633 * Set up the option buffer. 624 * Set up the option buffer.
634 */ 625 */
635 626
636 memset(&prl, 0, sizeof(prl)); 627 memset(&prl, 0, sizeof(prl));
637 oc = lookup_option(&dhcp_universe, options,  628 oc = lookup_option(&dhcp_universe, options,
638 DHO_DHCP_PARAMETER_REQUEST_LIST); 629 DHO_DHCP_PARAMETER_REQUEST_LIST);
639 if (oc != NULL) { 630 if (oc != NULL) {
640 evaluate_option_cache(&prl,  631 evaluate_option_cache(&prl,
641 packet,  632 packet,
642 NULL, 633 NULL,
643 NULL, 634 NULL,

cvs diff -r1.2 -r1.3 src/external/bsd/dhcp/dist/server/Attic/dhcpv6.c (expand / switch to unified diff)

--- src/external/bsd/dhcp/dist/server/Attic/dhcpv6.c 2013/03/24 15:53:59 1.2
+++ src/external/bsd/dhcp/dist/server/Attic/dhcpv6.c 2013/03/24 23:03:06 1.3
@@ -1,17 +1,17 @@ @@ -1,17 +1,17 @@
1/* $NetBSD: dhcpv6.c,v 1.2 2013/03/24 15:53:59 christos Exp $ */ 1/* $NetBSD: dhcpv6.c,v 1.3 2013/03/24 23:03:06 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (C) 2006-2011 by Internet Systems Consortium, Inc. ("ISC") 4 * Copyright (C) 2006-2012 by Internet Systems Consortium, Inc. ("ISC")
5 * 5 *
6 * Permission to use, copy, modify, and distribute this software for any 6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above 7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies. 8 * copyright notice and this permission notice appear in all copies.
9 * 9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE. 16 * PERFORMANCE OF THIS SOFTWARE.
17 */ 17 */
@@ -564,26 +564,27 @@ exit: @@ -564,26 +564,27 @@ exit:
564 * 564 *
565 * - The message includes an IA option. 565 * - The message includes an IA option.
566 */ 566 */
567static int 567static int
568valid_client_info_req(struct packet *packet, struct data_string *server_id) { 568valid_client_info_req(struct packet *packet, struct data_string *server_id) {
569 int ret_val; 569 int ret_val;
570 struct option_cache *oc; 570 struct option_cache *oc;
571 struct data_string client_id; 571 struct data_string client_id;
572 char client_id_str[80]; /* print_hex_1() uses maximum 60 characters, 572 char client_id_str[80]; /* print_hex_1() uses maximum 60 characters,
573 plus a few more for extra information */ 573 plus a few more for extra information */
574 574
575 ret_val = 0; 575 ret_val = 0;
576 memset(server_id, 0, sizeof(*server_id)); 576 memset(server_id, 0, sizeof(*server_id));
 577 memset(&client_id, 0, sizeof(client_id));
577 578
578 /* 579 /*
579 * Make a string that we can print out to give more  580 * Make a string that we can print out to give more
580 * information about the client if we need to. 581 * information about the client if we need to.
581 * 582 *
582 * By RFC 3315, Section 18.1.5 clients SHOULD have a  583 * By RFC 3315, Section 18.1.5 clients SHOULD have a
583 * client-id on an Information-request packet, but it  584 * client-id on an Information-request packet, but it
584 * is not strictly necessary. 585 * is not strictly necessary.
585 */ 586 */
586 if (get_client_id(packet, &client_id) == ISC_R_SUCCESS) { 587 if (get_client_id(packet, &client_id) == ISC_R_SUCCESS) {
587 snprintf(client_id_str, sizeof(client_id_str), " (CLIENTID %s)", 588 snprintf(client_id_str, sizeof(client_id_str), " (CLIENTID %s)",
588 print_hex_1(client_id.len, client_id.data, 60)); 589 print_hex_1(client_id.len, client_id.data, 60));
589 data_string_forget(&client_id, MDL); 590 data_string_forget(&client_id, MDL);
@@ -1084,42 +1085,42 @@ static isc_result_t @@ -1084,42 +1085,42 @@ static isc_result_t
1084try_client_v6_prefix(struct iasubopt **pref, 1085try_client_v6_prefix(struct iasubopt **pref,
1085 struct ipv6_pool *pool, 1086 struct ipv6_pool *pool,
1086 const struct data_string *requested_pref) 1087 const struct data_string *requested_pref)
1087{ 1088{
1088 u_int8_t tmp_plen; 1089 u_int8_t tmp_plen;
1089 struct in6_addr tmp_pref; 1090 struct in6_addr tmp_pref;
1090 struct iaddr ia; 1091 struct iaddr ia;
1091 isc_result_t result; 1092 isc_result_t result;
1092 1093
1093 if (requested_pref->len < sizeof(tmp_plen) + sizeof(tmp_pref)) { 1094 if (requested_pref->len < sizeof(tmp_plen) + sizeof(tmp_pref)) {
1094 return DHCP_R_INVALIDARG; 1095 return DHCP_R_INVALIDARG;
1095 } 1096 }
1096 tmp_plen = (int) requested_pref->data[0]; 1097 tmp_plen = (int) requested_pref->data[0];
1097 if ((tmp_plen < 3) || (tmp_plen > 128)) { 1098 if ((tmp_plen < 3) || (tmp_plen > 128) ||
 1099 ((int)tmp_plen != pool->units)) {
1098 return ISC_R_FAILURE; 1100 return ISC_R_FAILURE;
1099 } 1101 }
1100 memcpy(&tmp_pref, requested_pref->data + 1, sizeof(tmp_pref)); 1102 memcpy(&tmp_pref, requested_pref->data + 1, sizeof(tmp_pref));
1101 if (IN6_IS_ADDR_UNSPECIFIED(&tmp_pref)) { 1103 if (IN6_IS_ADDR_UNSPECIFIED(&tmp_pref)) {
1102 return ISC_R_FAILURE; 1104 return ISC_R_FAILURE;
1103 } 1105 }
1104 ia.len = 16; 1106 ia.len = 16;
1105 memcpy(&ia.iabuf, &tmp_pref, 16); 1107 memcpy(&ia.iabuf, &tmp_pref, 16);
1106 if (!is_cidr_mask_valid(&ia, (int) tmp_plen)) { 1108 if (!is_cidr_mask_valid(&ia, (int) tmp_plen)) {
1107 return ISC_R_FAILURE; 1109 return ISC_R_FAILURE;
1108 } 1110 }
1109 1111
1110 if (((int)tmp_plen != pool->units) || 1112 if (!ipv6_in_pool(&tmp_pref, pool)) {
1111 !ipv6_in_pool(&tmp_pref, pool)) { 1113 return ISC_R_ADDRNOTAVAIL;
1112 return ISC_R_FAILURE; 
1113 } 1114 }
1114 1115
1115 if (prefix6_exists(pool, &tmp_pref, tmp_plen)) { 1116 if (prefix6_exists(pool, &tmp_pref, tmp_plen)) {
1116 return ISC_R_ADDRINUSE; 1117 return ISC_R_ADDRINUSE;
1117 } 1118 }
1118 1119
1119 result = iasubopt_allocate(pref, MDL); 1120 result = iasubopt_allocate(pref, MDL);
1120 if (result != ISC_R_SUCCESS) { 1121 if (result != ISC_R_SUCCESS) {
1121 return result; 1122 return result;
1122 } 1123 }
1123 (*pref)->addr = tmp_pref; 1124 (*pref)->addr = tmp_pref;
1124 (*pref)->plen = tmp_plen; 1125 (*pref)->plen = tmp_plen;
1125 1126
@@ -1199,83 +1200,97 @@ pick_v6_prefix(struct iasubopt **pref, i @@ -1199,83 +1200,97 @@ pick_v6_prefix(struct iasubopt **pref, i
1199 return ISC_R_SUCCESS; 1200 return ISC_R_SUCCESS;
1200 } 1201 }
1201 } 1202 }
1202 1203
1203 /* 1204 /*
1204 * If we failed to pick an IPv6 prefix 1205 * If we failed to pick an IPv6 prefix
1205 * Presumably that means we have no prefixes for the client. 1206 * Presumably that means we have no prefixes for the client.
1206 */ 1207 */
1207 log_debug("Unable to pick client prefix: no prefixes available"); 1208 log_debug("Unable to pick client prefix: no prefixes available");
1208 return ISC_R_NORESOURCES; 1209 return ISC_R_NORESOURCES;
1209} 1210}
1210 1211
1211/* 1212/*
 1213 *! \file server/dhcpv6.c
 1214 *
 1215 * \brief construct a reply containing information about a client's lease
 1216 *
1212 * lease_to_client() is called from several messages to construct a 1217 * lease_to_client() is called from several messages to construct a
1213 * reply that contains all that we know about the client's correct lease 1218 * reply that contains all that we know about the client's correct lease
1214 * (or projected lease). 1219 * (or projected lease).
1215 * 1220 *
1216 * Solicit - "Soft" binding, ignore unknown addresses or bindings, just 1221 * Solicit - "Soft" binding, ignore unknown addresses or bindings, just
1217 * send what we "may" give them on a request. 1222 * send what we "may" give them on a request.
1218 * 1223 *
1219 * Request - "Hard" binding, but ignore supplied addresses (just provide what 1224 * Request - "Hard" binding, but ignore supplied addresses (just provide what
1220 * the client should really use). 1225 * the client should really use).
1221 * 1226 *
1222 * Renew - "Hard" binding, but client-supplied addresses are 'real'. Error 1227 * Renew - "Hard" binding, but client-supplied addresses are 'real'. Error
1223 * Rebind out any "wrong" addresses the client sends. This means we send 1228 * Rebind out any "wrong" addresses the client sends. This means we send
1224 * an empty IA_NA with a status code of NoBinding or NotOnLink or 1229 * an empty IA_NA with a status code of NoBinding or NotOnLink or
1225 * possibly send the address with zeroed lifetimes. 1230 * possibly send the address with zeroed lifetimes.
1226 * 1231 *
1227 * Information-Request - No binding. 1232 * Information-Request - No binding.
1228 * 1233 *
1229 * The basic structure is to traverse the client-supplied data first, and 1234 * The basic structure is to traverse the client-supplied data first, and
1230 * validate and echo back any contents that can be. If the client-supplied 1235 * validate and echo back any contents that can be. If the client-supplied
1231 * data does not error out (on renew/rebind as above), but we did not send 1236 * data does not error out (on renew/rebind as above), but we did not send
1232 * any addresses, attempt to allocate one. 1237 * any addresses, attempt to allocate one.
 1238 *
 1239 * At the end of the this function we call commit_leases_timed() to
 1240 * fsync and rotate the file as necessary. commit_leases_timed() will
 1241 * check that we have written at least one lease to the file and that
 1242 * some time has passed before doing any fsync or file rewrite so we
 1243 * don't bother tracking if we did a write_ia during this function.
1233 */ 1244 */
1234/* TODO: look at client hints for lease times */ 1245/* TODO: look at client hints for lease times */
 1246
1235static void 1247static void
1236lease_to_client(struct data_string *reply_ret, 1248lease_to_client(struct data_string *reply_ret,
1237 struct packet *packet,  1249 struct packet *packet,
1238 const struct data_string *client_id, 1250 const struct data_string *client_id,
1239 const struct data_string *server_id) 1251 const struct data_string *server_id)
1240{ 1252{
1241 static struct reply_state reply; 1253 static struct reply_state reply;
1242 struct option_cache *oc; 1254 struct option_cache *oc;
1243 struct data_string packet_oro; 1255 struct data_string packet_oro;
1244 isc_boolean_t no_resources_avail; 1256#if defined (RFC3315_PRE_ERRATA_2010_08)
 1257 isc_boolean_t no_resources_avail = ISC_FALSE;
 1258#endif
 1259
 1260 memset(&packet_oro, 0, sizeof(packet_oro));
1245 1261
1246 /* Locate the client. */ 1262 /* Locate the client. */
1247 if (shared_network_from_packet6(&reply.shared, 1263 if (shared_network_from_packet6(&reply.shared,
1248 packet) != ISC_R_SUCCESS) 1264 packet) != ISC_R_SUCCESS)
1249 goto exit; 1265 goto exit;
1250 1266
1251 /*  1267 /*
1252 * Initialize the reply. 1268 * Initialize the reply.
1253 */ 1269 */
1254 packet_reference(&reply.packet, packet, MDL); 1270 packet_reference(&reply.packet, packet, MDL);
1255 data_string_copy(&reply.client_id, client_id, MDL); 1271 data_string_copy(&reply.client_id, client_id, MDL);
1256 1272
1257 if (!start_reply(packet, client_id, server_id, &reply.opt_state, 1273 if (!start_reply(packet, client_id, server_id, &reply.opt_state,
1258 &reply.buf.reply)) 1274 &reply.buf.reply))
1259 goto exit; 1275 goto exit;
1260 1276
1261 /* Set the write cursor to just past the reply header. */ 1277 /* Set the write cursor to just past the reply header. */
1262 reply.cursor = REPLY_OPTIONS_INDEX; 1278 reply.cursor = REPLY_OPTIONS_INDEX;
1263 1279
1264 /* 1280 /*
1265 * Get the ORO from the packet, if any. 1281 * Get the ORO from the packet, if any.
1266 */ 1282 */
1267 oc = lookup_option(&dhcpv6_universe, packet->options, D6O_ORO); 1283 oc = lookup_option(&dhcpv6_universe, packet->options, D6O_ORO);
1268 memset(&packet_oro, 0, sizeof(packet_oro)); 
1269 if (oc != NULL) { 1284 if (oc != NULL) {
1270 if (!evaluate_option_cache(&packet_oro, packet,  1285 if (!evaluate_option_cache(&packet_oro, packet,
1271 NULL, NULL,  1286 NULL, NULL,
1272 packet->options, NULL, 1287 packet->options, NULL,
1273 &global_scope, oc, MDL)) { 1288 &global_scope, oc, MDL)) {
1274 log_error("lease_to_client: error evaluating ORO."); 1289 log_error("lease_to_client: error evaluating ORO.");
1275 goto exit; 1290 goto exit;
1276 } 1291 }
1277 } 1292 }
1278 1293
1279 /*  1294 /*
1280 * Find a host record that matches from the packet, if any, and is 1295 * Find a host record that matches from the packet, if any, and is
1281 * valid for the shared network the client is on. 1296 * valid for the shared network the client is on.
@@ -1289,103 +1304,100 @@ lease_to_client(struct data_string *repl @@ -1289,103 +1304,100 @@ lease_to_client(struct data_string *repl
1289 seek_shared_host(&reply.host, reply.shared); 1304 seek_shared_host(&reply.host, reply.shared);
1290 1305
1291 /* 1306 /*
1292 * Check for 'hardware' matches last, as some of the synthesis methods 1307 * Check for 'hardware' matches last, as some of the synthesis methods
1293 * are not considered to be as reliable. 1308 * are not considered to be as reliable.
1294 */ 1309 */
1295 if ((reply.host == NULL) && 1310 if ((reply.host == NULL) &&
1296 find_hosts_by_duid_chaddr(&reply.host, client_id)) 1311 find_hosts_by_duid_chaddr(&reply.host, client_id))
1297 seek_shared_host(&reply.host, reply.shared); 1312 seek_shared_host(&reply.host, reply.shared);
1298 1313
1299 /* Process the client supplied IA's onto the reply buffer. */ 1314 /* Process the client supplied IA's onto the reply buffer. */
1300 reply.ia_count = 0; 1315 reply.ia_count = 0;
1301 oc = lookup_option(&dhcpv6_universe, packet->options, D6O_IA_NA); 1316 oc = lookup_option(&dhcpv6_universe, packet->options, D6O_IA_NA);
1302 no_resources_avail = ISC_FALSE; 1317
1303 for (; oc != NULL ; oc = oc->next) { 1318 for (; oc != NULL ; oc = oc->next) {
1304 isc_result_t status; 1319 isc_result_t status;
1305 1320
1306 /* Start counting resources (addresses) offered. */ 1321 /* Start counting resources (addresses) offered. */
1307 reply.client_resources = 0; 1322 reply.client_resources = 0;
1308 reply.resources_included = ISC_FALSE; 1323 reply.resources_included = ISC_FALSE;
1309 1324
1310 status = reply_process_ia_na(&reply, oc); 1325 status = reply_process_ia_na(&reply, oc);
1311 1326
1312 /* 1327 /*
1313 * We continue to try other IA's whether we can address 1328 * We continue to try other IA's whether we can address
1314 * this one or not. Any other result is an immediate fail. 1329 * this one or not. Any other result is an immediate fail.
1315 */ 1330 */
1316 if ((status != ISC_R_SUCCESS) && 1331 if ((status != ISC_R_SUCCESS) &&
1317 (status != ISC_R_NORESOURCES)) 1332 (status != ISC_R_NORESOURCES))
1318 goto exit; 1333 goto exit;
1319 1334
 1335#if defined (RFC3315_PRE_ERRATA_2010_08)
1320 /* 1336 /*
1321 * If any address cannot be given to any IA, then set the 1337 * If any address cannot be given to any IA, then set the
1322 * NoAddrsAvail status code. 1338 * NoAddrsAvail status code.
1323 */ 1339 */
1324 if (reply.client_resources == 0) 1340 if (reply.client_resources == 0)
1325 no_resources_avail = ISC_TRUE; 1341 no_resources_avail = ISC_TRUE;
 1342#endif
1326 } 1343 }
1327 oc = lookup_option(&dhcpv6_universe, packet->options, D6O_IA_TA); 1344 oc = lookup_option(&dhcpv6_universe, packet->options, D6O_IA_TA);
1328 for (; oc != NULL ; oc = oc->next) { 1345 for (; oc != NULL ; oc = oc->next) {
1329 isc_result_t status; 1346 isc_result_t status;
1330 1347
1331 /* Start counting resources (addresses) offered. */ 1348 /* Start counting resources (addresses) offered. */
1332 reply.client_resources = 0; 1349 reply.client_resources = 0;
1333 reply.resources_included = ISC_FALSE; 1350 reply.resources_included = ISC_FALSE;
1334 1351
1335 status = reply_process_ia_ta(&reply, oc); 1352 status = reply_process_ia_ta(&reply, oc);
1336 1353
1337 /* 1354 /*
1338 * We continue to try other IA's whether we can address 1355 * We continue to try other IA's whether we can address
1339 * this one or not. Any other result is an immediate fail. 1356 * this one or not. Any other result is an immediate fail.
1340 */ 1357 */
1341 if ((status != ISC_R_SUCCESS) && 1358 if ((status != ISC_R_SUCCESS) &&
1342 (status != ISC_R_NORESOURCES)) 1359 (status != ISC_R_NORESOURCES))
1343 goto exit; 1360 goto exit;
1344 1361
 1362#if defined (RFC3315_PRE_ERRATA_2010_08)
1345 /* 1363 /*
1346 * If any address cannot be given to any IA, then set the 1364 * If any address cannot be given to any IA, then set the
1347 * NoAddrsAvail status code. 1365 * NoAddrsAvail status code.
1348 */ 1366 */
1349 if (reply.client_resources == 0) 1367 if (reply.client_resources == 0)
1350 no_resources_avail = ISC_TRUE; 1368 no_resources_avail = ISC_TRUE;
 1369#endif
1351 } 1370 }
1352 1371
1353 /* Same for IA_PD's. */ 1372 /* Same for IA_PD's. */
1354 reply.pd_count = 0; 1373 reply.pd_count = 0;
1355 oc = lookup_option(&dhcpv6_universe, packet->options, D6O_IA_PD); 1374 oc = lookup_option(&dhcpv6_universe, packet->options, D6O_IA_PD);
1356 for (; oc != NULL ; oc = oc->next) { 1375 for (; oc != NULL ; oc = oc->next) {
1357 isc_result_t status; 1376 isc_result_t status;
1358 1377
1359 /* Start counting resources (prefixes) offered. */ 1378 /* Start counting resources (prefixes) offered. */
1360 reply.client_resources = 0; 1379 reply.client_resources = 0;
1361 reply.resources_included = ISC_FALSE; 1380 reply.resources_included = ISC_FALSE;
1362 1381
1363 status = reply_process_ia_pd(&reply, oc); 1382 status = reply_process_ia_pd(&reply, oc);
1364 1383
1365 /* 1384 /*
1366 * We continue to try other IA_PD's whether we can address 1385 * We continue to try other IA_PD's whether we can address
1367 * this one or not. Any other result is an immediate fail. 1386 * this one or not. Any other result is an immediate fail.
1368 */ 1387 */
1369 if ((status != ISC_R_SUCCESS) && 1388 if ((status != ISC_R_SUCCESS) &&
1370 (status != ISC_R_NORESOURCES)) 1389 (status != ISC_R_NORESOURCES))
1371 goto exit; 1390 goto exit;
1372 
1373 /* 
1374 * If any prefix cannot be given to any IA_PD, then 
1375 * set the NoPrefixAvail status code. 
1376 */ 
1377 if (reply.client_resources == 0) 
1378 no_resources_avail = ISC_TRUE; 
1379 } 1391 }
1380 1392
1381 /* 1393 /*
1382 * Make no reply if we gave no resources and is not 1394 * Make no reply if we gave no resources and is not
1383 * for Information-Request. 1395 * for Information-Request.
1384 */ 1396 */
1385 if ((reply.ia_count == 0) && (reply.pd_count == 0)) { 1397 if ((reply.ia_count == 0) && (reply.pd_count == 0)) {
1386 if (reply.packet->dhcpv6_msg_type != 1398 if (reply.packet->dhcpv6_msg_type !=
1387 DHCPV6_INFORMATION_REQUEST) 1399 DHCPV6_INFORMATION_REQUEST)
1388 goto exit; 1400 goto exit;
1389 1401
1390 /* 1402 /*
1391 * Because we only execute statements on a per-IA basis, 1403 * Because we only execute statements on a per-IA basis,
@@ -1421,26 +1433,27 @@ lease_to_client(struct data_string *repl @@ -1421,26 +1433,27 @@ lease_to_client(struct data_string *repl
1421 * 1433 *
1422 * If the server cannot assign any addresses to an IA in the 1434 * If the server cannot assign any addresses to an IA in the
1423 * message from the client, the server MUST include the IA in 1435 * message from the client, the server MUST include the IA in
1424 * the Reply message with no addresses in the IA and a Status 1436 * the Reply message with no addresses in the IA and a Status
1425 * Code option in the IA containing status code NoAddrsAvail. 1437 * Code option in the IA containing status code NoAddrsAvail.
1426 * 1438 *
1427 * Section 18.1.8 (Client Behavior): 1439 * Section 18.1.8 (Client Behavior):
1428 * 1440 *
1429 * Leave unchanged any information about addresses the client has 1441 * Leave unchanged any information about addresses the client has
1430 * recorded in the IA but that were not included in the IA from 1442 * recorded in the IA but that were not included in the IA from
1431 * the server. 1443 * the server.
1432 * Sends a Renew/Rebind if the IA is not in the Reply message. 1444 * Sends a Renew/Rebind if the IA is not in the Reply message.
1433 */ 1445 */
 1446#if defined (RFC3315_PRE_ERRATA_2010_08)
1434 if (no_resources_avail && (reply.ia_count != 0) && 1447 if (no_resources_avail && (reply.ia_count != 0) &&
1435 (reply.packet->dhcpv6_msg_type == DHCPV6_SOLICIT)) 1448 (reply.packet->dhcpv6_msg_type == DHCPV6_SOLICIT))
1436 { 1449 {
1437 /* Set the NoAddrsAvail status code. */ 1450 /* Set the NoAddrsAvail status code. */
1438 if (!set_status_code(STATUS_NoAddrsAvail, 1451 if (!set_status_code(STATUS_NoAddrsAvail,
1439 "No addresses available for this " 1452 "No addresses available for this "
1440 "interface.", reply.opt_state)) { 1453 "interface.", reply.opt_state)) {
1441 log_error("lease_to_client: Unable to set " 1454 log_error("lease_to_client: Unable to set "
1442 "NoAddrsAvail status code."); 1455 "NoAddrsAvail status code.");
1443 goto exit; 1456 goto exit;
1444 } 1457 }
1445 1458
1446 /* Rewind the cursor to the start. */ 1459 /* Rewind the cursor to the start. */
@@ -1451,91 +1464,77 @@ lease_to_client(struct data_string *repl @@ -1451,91 +1464,77 @@ lease_to_client(struct data_string *repl
1451 * 1464 *
1452 * Status code. 1465 * Status code.
1453 * Server DUID. 1466 * Server DUID.
1454 * Client DUID. 1467 * Client DUID.
1455 */ 1468 */
1456 reply.buf.reply.msg_type = DHCPV6_ADVERTISE; 1469 reply.buf.reply.msg_type = DHCPV6_ADVERTISE;
1457 reply.cursor += store_options6((char *)reply.buf.data + 1470 reply.cursor += store_options6((char *)reply.buf.data +
1458 reply.cursor, 1471 reply.cursor,
1459 sizeof(reply.buf) - 1472 sizeof(reply.buf) -
1460 reply.cursor, 1473 reply.cursor,
1461 reply.opt_state, reply.packet, 1474 reply.opt_state, reply.packet,
1462 required_opts_NAA, 1475 required_opts_NAA,
1463 NULL); 1476 NULL);
1464 } else if (no_resources_avail && (reply.ia_count == 0) && 
1465 (reply.packet->dhcpv6_msg_type == DHCPV6_SOLICIT)) 
1466 { 
1467 /* Set the NoPrefixAvail status code. */ 
1468 if (!set_status_code(STATUS_NoPrefixAvail, 
1469 "No prefixes available for this " 
1470 "interface.", reply.opt_state)) { 
1471 log_error("lease_to_client: Unable to set " 
1472 "NoPrefixAvail status code."); 
1473 goto exit; 
1474 } 
1475 
1476 /* Rewind the cursor to the start. */ 
1477 reply.cursor = REPLY_OPTIONS_INDEX; 
1478 
1479 /* 
1480 * Produce an advertise that includes only: 
1481 * 
1482 * Status code. 
1483 * Server DUID. 
1484 * Client DUID. 
1485 */ 
1486 reply.buf.reply.msg_type = DHCPV6_ADVERTISE; 
1487 reply.cursor += store_options6((char *)reply.buf.data + 
1488 reply.cursor, 
1489 sizeof(reply.buf) - 
1490 reply.cursor, 
1491 reply.opt_state, reply.packet, 
1492 required_opts_NAA, 
1493 NULL); 
1494 } else { 1477 } else {
1495 /* 1478 /*
1496 * Having stored the client's IA's, store any options that 1479 * Having stored the client's IA's, store any options that
1497 * will fit in the remaining space. 1480 * will fit in the remaining space.
1498 */ 1481 */
1499 reply.cursor += store_options6((char *)reply.buf.data + 1482 reply.cursor += store_options6((char *)reply.buf.data +
1500 reply.cursor, 1483 reply.cursor,
1501 sizeof(reply.buf) - 1484 sizeof(reply.buf) -
1502 reply.cursor, 1485 reply.cursor,
1503 reply.opt_state, reply.packet, 1486 reply.opt_state, reply.packet,
1504 required_opts_solicit, 1487 required_opts_solicit,
1505 &packet_oro); 1488 &packet_oro);
1506 } 1489 }
 1490#else /* defined (RFC3315_PRE_ERRATA_2010_08) */
 1491 /*
 1492 * Having stored the client's IA's, store any options that
 1493 * will fit in the remaining space.
 1494 */
 1495 reply.cursor += store_options6((char *)reply.buf.data + reply.cursor,
 1496 sizeof(reply.buf) - reply.cursor,
 1497 reply.opt_state, reply.packet,
 1498 required_opts_solicit,
 1499 &packet_oro);
 1500#endif /* defined (RFC3315_PRE_ERRATA_2010_08) */
1507 1501
1508 /* Return our reply to the caller. */ 1502 /* Return our reply to the caller. */
1509 reply_ret->len = reply.cursor; 1503 reply_ret->len = reply.cursor;
1510 reply_ret->buffer = NULL; 1504 reply_ret->buffer = NULL;
1511 if (!buffer_allocate(&reply_ret->buffer, reply.cursor, MDL)) { 1505 if (!buffer_allocate(&reply_ret->buffer, reply.cursor, MDL)) {
1512 log_fatal("No memory to store Reply."); 1506 log_fatal("No memory to store Reply.");
1513 } 1507 }
1514 memcpy(reply_ret->buffer->data, reply.buf.data, reply.cursor); 1508 memcpy(reply_ret->buffer->data, reply.buf.data, reply.cursor);
1515 reply_ret->data = reply_ret->buffer->data; 1509 reply_ret->data = reply_ret->buffer->data;
1516 1510
 1511 /* If appropriate commit and rotate the lease file */
 1512 (void) commit_leases_timed();
 1513
1517 exit: 1514 exit:
1518 /* Cleanup. */ 1515 /* Cleanup. */
1519 if (reply.shared != NULL) 1516 if (reply.shared != NULL)
1520 shared_network_dereference(&reply.shared, MDL); 1517 shared_network_dereference(&reply.shared, MDL);
1521 if (reply.host != NULL) 1518 if (reply.host != NULL)
1522 host_dereference(&reply.host, MDL); 1519 host_dereference(&reply.host, MDL);
1523 if (reply.opt_state != NULL) 1520 if (reply.opt_state != NULL)
1524 option_state_dereference(&reply.opt_state, MDL); 1521 option_state_dereference(&reply.opt_state, MDL);
1525 if (reply.packet != NULL) 1522 if (reply.packet != NULL)
1526 packet_dereference(&reply.packet, MDL); 1523 packet_dereference(&reply.packet, MDL);
1527 if (reply.client_id.data != NULL) 1524 if (reply.client_id.data != NULL)
1528 data_string_forget(&reply.client_id, MDL); 1525 data_string_forget(&reply.client_id, MDL);
 1526 if (packet_oro.buffer != NULL)
 1527 data_string_forget(&packet_oro, MDL);
1529 reply.renew = reply.rebind = reply.prefer = reply.valid = 0; 1528 reply.renew = reply.rebind = reply.prefer = reply.valid = 0;
1530 reply.cursor = 0; 1529 reply.cursor = 0;
1531} 1530}
1532 1531
1533/* Process a client-supplied IA_NA. This may append options to the tail of 1532/* Process a client-supplied IA_NA. This may append options to the tail of
1534 * the reply packet being built in the reply_state structure. 1533 * the reply packet being built in the reply_state structure.
1535 */ 1534 */
1536static isc_result_t 1535static isc_result_t
1537reply_process_ia_na(struct reply_state *reply, struct option_cache *ia) { 1536reply_process_ia_na(struct reply_state *reply, struct option_cache *ia) {
1538 isc_result_t status = ISC_R_SUCCESS; 1537 isc_result_t status = ISC_R_SUCCESS;
1539 u_int32_t iaid; 1538 u_int32_t iaid;
1540 unsigned ia_cursor; 1539 unsigned ia_cursor;
1541 struct option_state *packet_ia; 1540 struct option_state *packet_ia;
@@ -1831,29 +1830,26 @@ reply_process_ia_na(struct reply_state * @@ -1831,29 +1830,26 @@ reply_process_ia_na(struct reply_state *
1831 (reply->ia->num_iasubopt != 0)) { 1830 (reply->ia->num_iasubopt != 0)) {
1832 struct iasubopt *tmp; 1831 struct iasubopt *tmp;
1833 struct data_string *ia_id; 1832 struct data_string *ia_id;
1834 int i; 1833 int i;
1835 1834
1836 for (i = 0 ; i < reply->ia->num_iasubopt ; i++) { 1835 for (i = 0 ; i < reply->ia->num_iasubopt ; i++) {
1837 tmp = reply->ia->iasubopt[i]; 1836 tmp = reply->ia->iasubopt[i];
1838 1837
1839 if (tmp->ia != NULL) 1838 if (tmp->ia != NULL)
1840 ia_dereference(&tmp->ia, MDL); 1839 ia_dereference(&tmp->ia, MDL);
1841 ia_reference(&tmp->ia, reply->ia, MDL); 1840 ia_reference(&tmp->ia, reply->ia, MDL);
1842 1841
1843 /* Commit 'hard' bindings. */ 1842 /* Commit 'hard' bindings. */
1844 tmp->hard_lifetime_end_time = 
1845 tmp->soft_lifetime_end_time; 
1846 tmp->soft_lifetime_end_time = 0; 
1847 renew_lease6(tmp->ipv6_pool, tmp); 1843 renew_lease6(tmp->ipv6_pool, tmp);
1848 schedule_lease_timeout(tmp->ipv6_pool); 1844 schedule_lease_timeout(tmp->ipv6_pool);
1849 1845
1850#if defined (NSUPDATE) 1846#if defined (NSUPDATE)
1851 /* 1847 /*
1852 * Perform ddns updates. 1848 * Perform ddns updates.
1853 */ 1849 */
1854 oc = lookup_option(&server_universe, reply->opt_state, 1850 oc = lookup_option(&server_universe, reply->opt_state,
1855 SV_DDNS_UPDATES); 1851 SV_DDNS_UPDATES);
1856 if ((oc == NULL) || 1852 if ((oc == NULL) ||
1857 evaluate_boolean_option_cache(NULL, reply->packet, 1853 evaluate_boolean_option_cache(NULL, reply->packet,
1858 NULL, NULL, 1854 NULL, NULL,
1859 reply->packet->options, 1855 reply->packet->options,
@@ -2220,46 +2216,49 @@ reply_process_addr(struct reply_state *r @@ -2220,46 +2216,49 @@ reply_process_addr(struct reply_state *r
2220 */ 2216 */
2221static isc_boolean_t 2217static isc_boolean_t
2222address_is_owned(struct reply_state *reply, struct iaddr *addr) { 2218address_is_owned(struct reply_state *reply, struct iaddr *addr) {
2223 int i; 2219 int i;
2224 2220
2225 /* 2221 /*
2226 * This faults out addresses that don't match fixed addresses. 2222 * This faults out addresses that don't match fixed addresses.
2227 */ 2223 */
2228 if (reply->static_lease) { 2224 if (reply->static_lease) {
2229 if (reply->fixed.data == NULL) 2225 if (reply->fixed.data == NULL)
2230 log_fatal("Impossible condition at %s:%d.", MDL); 2226 log_fatal("Impossible condition at %s:%d.", MDL);
2231 2227
2232 if (memcmp(addr->iabuf, reply->fixed.data, 16) == 0) 2228 if (memcmp(addr->iabuf, reply->fixed.data, 16) == 0)
2233 return ISC_TRUE; 2229 return (ISC_TRUE);
2234 2230
2235 return ISC_FALSE; 2231 return (ISC_FALSE);
2236 } 2232 }
2237 2233
2238 if ((reply->old_ia == NULL) || (reply->old_ia->num_iasubopt == 0)) 2234 if ((reply->old_ia == NULL) || (reply->old_ia->num_iasubopt == 0))
2239 return ISC_FALSE; 2235 return (ISC_FALSE);
2240 2236
2241 for (i = 0 ; i < reply->old_ia->num_iasubopt ; i++) { 2237 for (i = 0 ; i < reply->old_ia->num_iasubopt ; i++) {
2242 struct iasubopt *tmp; 2238 struct iasubopt *tmp;
2243 2239
2244 tmp = reply->old_ia->iasubopt[i]; 2240 tmp = reply->old_ia->iasubopt[i];
2245 2241
2246 if (memcmp(addr->iabuf, &tmp->addr, 16) == 0) { 2242 if (memcmp(addr->iabuf, &tmp->addr, 16) == 0) {
 2243 if (lease6_usable(tmp) == ISC_FALSE) {
 2244 return (ISC_FALSE);
 2245 }
2247 iasubopt_reference(&reply->lease, tmp, MDL); 2246 iasubopt_reference(&reply->lease, tmp, MDL);
2248 return ISC_TRUE; 2247 return (ISC_TRUE);
2249 } 2248 }
2250 } 2249 }
2251 2250
2252 return ISC_FALSE; 2251 return (ISC_FALSE);
2253} 2252}
2254 2253
2255/* Process a client-supplied IA_TA. This may append options to the tail of 2254/* Process a client-supplied IA_TA. This may append options to the tail of
2256 * the reply packet being built in the reply_state structure. 2255 * the reply packet being built in the reply_state structure.
2257 */ 2256 */
2258static isc_result_t 2257static isc_result_t
2259reply_process_ia_ta(struct reply_state *reply, struct option_cache *ia) { 2258reply_process_ia_ta(struct reply_state *reply, struct option_cache *ia) {
2260 isc_result_t status = ISC_R_SUCCESS; 2259 isc_result_t status = ISC_R_SUCCESS;
2261 u_int32_t iaid; 2260 u_int32_t iaid;
2262 unsigned ia_cursor; 2261 unsigned ia_cursor;
2263 struct option_state *packet_ia; 2262 struct option_state *packet_ia;
2264 struct option_cache *oc; 2263 struct option_cache *oc;
2265 struct data_string ia_data, data; 2264 struct data_string ia_data, data;
@@ -2489,29 +2488,26 @@ reply_process_ia_ta(struct reply_state * @@ -2489,29 +2488,26 @@ reply_process_ia_ta(struct reply_state *
2489 (reply->ia->num_iasubopt != 0)) { 2488 (reply->ia->num_iasubopt != 0)) {
2490 struct iasubopt *tmp; 2489 struct iasubopt *tmp;
2491 struct data_string *ia_id; 2490 struct data_string *ia_id;
2492 int i; 2491 int i;
2493 2492
2494 for (i = 0 ; i < reply->ia->num_iasubopt ; i++) { 2493 for (i = 0 ; i < reply->ia->num_iasubopt ; i++) {
2495 tmp = reply->ia->iasubopt[i]; 2494 tmp = reply->ia->iasubopt[i];
2496 2495
2497 if (tmp->ia != NULL) 2496 if (tmp->ia != NULL)
2498 ia_dereference(&tmp->ia, MDL); 2497 ia_dereference(&tmp->ia, MDL);
2499 ia_reference(&tmp->ia, reply->ia, MDL); 2498 ia_reference(&tmp->ia, reply->ia, MDL);
2500 2499
2501 /* Commit 'hard' bindings. */ 2500 /* Commit 'hard' bindings. */
2502 tmp->hard_lifetime_end_time = 
2503 tmp->soft_lifetime_end_time; 
2504 tmp->soft_lifetime_end_time = 0; 
2505 renew_lease6(tmp->ipv6_pool, tmp); 2501 renew_lease6(tmp->ipv6_pool, tmp);
2506 schedule_lease_timeout(tmp->ipv6_pool); 2502 schedule_lease_timeout(tmp->ipv6_pool);
2507 2503
2508#if defined (NSUPDATE) 2504#if defined (NSUPDATE)
2509 /* 2505 /*
2510 * Perform ddns updates. 2506 * Perform ddns updates.
2511 */ 2507 */
2512 oc = lookup_option(&server_universe, reply->opt_state, 2508 oc = lookup_option(&server_universe, reply->opt_state,
2513 SV_DDNS_UPDATES); 2509 SV_DDNS_UPDATES);
2514 if ((oc == NULL) || 2510 if ((oc == NULL) ||
2515 evaluate_boolean_option_cache(NULL, reply->packet, 2511 evaluate_boolean_option_cache(NULL, reply->packet,
2516 NULL, NULL, 2512 NULL, NULL,
2517 reply->packet->options, 2513 reply->packet->options,
@@ -2677,71 +2673,75 @@ find_client_temporaries(struct reply_sta @@ -2677,71 +2673,75 @@ find_client_temporaries(struct reply_sta
2677 2673
2678 status = reply_process_is_addressed(reply, 2674 status = reply_process_is_addressed(reply,
2679 &reply->lease->scope, 2675 &reply->lease->scope,
2680 reply->lease->ipv6_pool->subnet->group); 2676 reply->lease->ipv6_pool->subnet->group);
2681 if (status != ISC_R_SUCCESS) { 2677 if (status != ISC_R_SUCCESS) {
2682 goto cleanup; 2678 goto cleanup;
2683 } 2679 }
2684 send_addr.len = 16; 2680 send_addr.len = 16;
2685 memcpy(send_addr.iabuf, &reply->lease->addr, 16); 2681 memcpy(send_addr.iabuf, &reply->lease->addr, 16);
2686 status = reply_process_send_addr(reply, &send_addr); 2682 status = reply_process_send_addr(reply, &send_addr);
2687 if (status != ISC_R_SUCCESS) { 2683 if (status != ISC_R_SUCCESS) {
2688 goto cleanup; 2684 goto cleanup;
2689 } 2685 }
2690 if (reply->lease != NULL) { 2686 /*
2691 iasubopt_dereference(&reply->lease, MDL); 2687 * reply->lease can't be null as we use it above
2692 } 2688 * add check if that changes
 2689 */
 2690 iasubopt_dereference(&reply->lease, MDL);
2693 } 2691 }
2694 2692
2695 cleanup: 2693 cleanup:
2696 if (reply->lease != NULL) { 2694 if (reply->lease != NULL) {
2697 iasubopt_dereference(&reply->lease, MDL); 2695 iasubopt_dereference(&reply->lease, MDL);
2698 } 2696 }
2699 return status; 2697 return status;
2700} 2698}
2701 2699
2702/* 2700/*
2703 * This function only returns failure on 'hard' failures. If it succeeds, 2701 * This function only returns failure on 'hard' failures. If it succeeds,
2704 * it will leave a lease structure behind. 2702 * it will leave a lease structure behind.
2705 */ 2703 */
2706static isc_result_t 2704static isc_result_t
2707reply_process_try_addr(struct reply_state *reply, struct iaddr *addr) { 2705reply_process_try_addr(struct reply_state *reply, struct iaddr *addr) {
2708 isc_result_t status = ISC_R_NORESOURCES; 2706 isc_result_t status = ISC_R_ADDRNOTAVAIL;
2709 struct ipv6_pool *pool; 2707 struct ipv6_pool *pool;
2710 int i; 2708 int i;
2711 struct data_string data_addr; 2709 struct data_string data_addr;
2712 2710
2713 if ((reply == NULL) || (reply->shared == NULL) || 2711 if ((reply == NULL) || (reply->shared == NULL) ||
2714 (reply->shared->ipv6_pools == NULL) || (addr == NULL) || 2712 (addr == NULL) || (reply->lease != NULL))
2715 (reply->lease != NULL)) 2713 return (DHCP_R_INVALIDARG);
2716 return DHCP_R_INVALIDARG; 2714
 2715 if (reply->shared->ipv6_pools == NULL)
 2716 return (ISC_R_ADDRNOTAVAIL);
2717 2717
2718 memset(&data_addr, 0, sizeof(data_addr)); 2718 memset(&data_addr, 0, sizeof(data_addr));
2719 data_addr.len = addr->len; 2719 data_addr.len = addr->len;
2720 data_addr.data = addr->iabuf; 2720 data_addr.data = addr->iabuf;
2721 2721
2722 for (i = 0 ; (pool = reply->shared->ipv6_pools[i]) != NULL ; i++) { 2722 for (i = 0 ; (pool = reply->shared->ipv6_pools[i]) != NULL ; i++) {
2723 if (pool->pool_type != D6O_IA_NA) 2723 if (pool->pool_type != D6O_IA_NA)
2724 continue; 2724 continue;
2725 status = try_client_v6_address(&reply->lease, pool, 2725 status = try_client_v6_address(&reply->lease, pool,
2726 &data_addr); 2726 &data_addr);
2727 if (status == ISC_R_SUCCESS) 2727 if (status == ISC_R_SUCCESS)
2728 break; 2728 break;
2729 } 2729 }
2730 2730
2731 /* Note that this is just pedantry. There is no allocation to free. */ 2731 /* Note that this is just pedantry. There is no allocation to free. */
2732 data_string_forget(&data_addr, MDL); 2732 data_string_forget(&data_addr, MDL);
2733 /* Return just the most recent status... */ 2733 /* Return just the most recent status... */
2734 return status; 2734 return (status);
2735} 2735}
2736 2736
2737/* Look around for an address to give the client. First, look through the 2737/* Look around for an address to give the client. First, look through the
2738 * old IA for addresses we can extend. Second, try to allocate a new address. 2738 * old IA for addresses we can extend. Second, try to allocate a new address.
2739 * Finally, actually add that address into the current reply IA. 2739 * Finally, actually add that address into the current reply IA.
2740 */ 2740 */
2741static isc_result_t 2741static isc_result_t
2742find_client_address(struct reply_state *reply) { 2742find_client_address(struct reply_state *reply) {
2743 struct iaddr send_addr; 2743 struct iaddr send_addr;
2744 isc_result_t status = ISC_R_NORESOURCES; 2744 isc_result_t status = ISC_R_NORESOURCES;
2745 struct iasubopt *lease, *best_lease = NULL; 2745 struct iasubopt *lease, *best_lease = NULL;
2746 struct binding_scope **scope; 2746 struct binding_scope **scope;
2747 struct group *group; 2747 struct group *group;
@@ -2761,38 +2761,39 @@ find_client_address(struct reply_state * @@ -2761,38 +2761,39 @@ find_client_address(struct reply_state *
2761 } 2761 }
2762 2762
2763 if (reply->old_ia != NULL) { 2763 if (reply->old_ia != NULL) {
2764 for (i = 0 ; i < reply->old_ia->num_iasubopt ; i++) { 2764 for (i = 0 ; i < reply->old_ia->num_iasubopt ; i++) {
2765 struct shared_network *candidate_shared; 2765 struct shared_network *candidate_shared;
2766 2766
2767 lease = reply->old_ia->iasubopt[i]; 2767 lease = reply->old_ia->iasubopt[i];
2768 candidate_shared = lease->ipv6_pool->shared_network; 2768 candidate_shared = lease->ipv6_pool->shared_network;
2769 2769
2770 /* 2770 /*
2771 * Look for the best lease on the client's shared 2771 * Look for the best lease on the client's shared
2772 * network. 2772 * network.
2773 */ 2773 */
2774 if (candidate_shared == reply->shared) { 2774 if ((candidate_shared == reply->shared) &&
 2775 (lease6_usable(lease) == ISC_TRUE)) {
2775 best_lease = lease_compare(lease, best_lease); 2776 best_lease = lease_compare(lease, best_lease);
2776 } 2777 }
2777 } 2778 }
2778 } 2779 }
2779 2780
2780 /* Try to pick a new address if we didn't find one, or if we found an 2781 /* Try to pick a new address if we didn't find one, or if we found an
2781 * abandoned lease. 2782 * abandoned lease.
2782 */ 2783 */
2783 if ((best_lease == NULL) || (best_lease->state == FTS_ABANDONED)) { 2784 if ((best_lease == NULL) || (best_lease->state == FTS_ABANDONED)) {
2784 status = pick_v6_address(&reply->lease, reply->shared, 2785 status = pick_v6_address(&reply->lease, reply->shared,
2785 &reply->client_id); 2786 &reply->ia->iaid_duid);
2786 } else if (best_lease != NULL) { 2787 } else if (best_lease != NULL) {
2787 iasubopt_reference(&reply->lease, best_lease, MDL); 2788 iasubopt_reference(&reply->lease, best_lease, MDL);
2788 status = ISC_R_SUCCESS; 2789 status = ISC_R_SUCCESS;
2789 } 2790 }
2790 2791
2791 /* Pick the abandoned lease as a last resort. */ 2792 /* Pick the abandoned lease as a last resort. */
2792 if ((status == ISC_R_NORESOURCES) && (best_lease != NULL)) { 2793 if ((status == ISC_R_NORESOURCES) && (best_lease != NULL)) {
2793 /* I don't see how this is supposed to be done right now. */ 2794 /* I don't see how this is supposed to be done right now. */
2794 log_error("Reclaiming abandoned addresses is not yet " 2795 log_error("Reclaiming abandoned addresses is not yet "
2795 "supported. Treating this as an out of space " 2796 "supported. Treating this as an out of space "
2796 "condition."); 2797 "condition.");
2797 /* iasubopt_reference(&reply->lease, best_lease, MDL); */ 2798 /* iasubopt_reference(&reply->lease, best_lease, MDL); */
2798 } 2799 }
@@ -3216,27 +3217,29 @@ reply_process_ia_pd(struct reply_state * @@ -3216,27 +3217,29 @@ reply_process_ia_pd(struct reply_state *
3216 reply->preflen = -1; 3217 reply->preflen = -1;
3217 for (; oc != NULL ; oc = oc->next) { 3218 for (; oc != NULL ; oc = oc->next) {
3218 status = reply_process_prefix(reply, oc); 3219 status = reply_process_prefix(reply, oc);
3219 3220
3220 /* 3221 /*
3221 * Canceled means we did not allocate prefixes to the 3222 * Canceled means we did not allocate prefixes to the
3222 * client, but we're "done" with this IA - we set a status 3223 * client, but we're "done" with this IA - we set a status
3223 * code. So transmit this reply, e.g., move on to the next 3224 * code. So transmit this reply, e.g., move on to the next
3224 * IA. 3225 * IA.
3225 */ 3226 */
3226 if (status == ISC_R_CANCELED) 3227 if (status == ISC_R_CANCELED)
3227 break; 3228 break;
3228 3229
3229 if ((status != ISC_R_SUCCESS) && (status != ISC_R_ADDRINUSE)) 3230 if ((status != ISC_R_SUCCESS) &&
 3231 (status != ISC_R_ADDRINUSE) &&
 3232 (status != ISC_R_ADDRNOTAVAIL))
3230 goto cleanup; 3233 goto cleanup;
3231 } 3234 }
3232 3235
3233 reply->pd_count++; 3236 reply->pd_count++;
3234 3237
3235 /* 3238 /*
3236 * If we fell through the above and never gave the client 3239 * If we fell through the above and never gave the client
3237 * a prefix, give it one now. 3240 * a prefix, give it one now.
3238 */ 3241 */
3239 if ((status != ISC_R_CANCELED) && (reply->client_resources == 0)) { 3242 if ((status != ISC_R_CANCELED) && (reply->client_resources == 0)) {
3240 status = find_client_prefix(reply); 3243 status = find_client_prefix(reply);
3241 3244
3242 if (status == ISC_R_NORESOURCES) { 3245 if (status == ISC_R_NORESOURCES) {
@@ -3356,29 +3359,26 @@ reply_process_ia_pd(struct reply_state * @@ -3356,29 +3359,26 @@ reply_process_ia_pd(struct reply_state *
3356 (reply->ia->num_iasubopt != 0)) { 3359 (reply->ia->num_iasubopt != 0)) {
3357 struct iasubopt *tmp; 3360 struct iasubopt *tmp;
3358 struct data_string *ia_id; 3361 struct data_string *ia_id;
3359 int i; 3362 int i;
3360 3363
3361 for (i = 0 ; i < reply->ia->num_iasubopt ; i++) { 3364 for (i = 0 ; i < reply->ia->num_iasubopt ; i++) {
3362 tmp = reply->ia->iasubopt[i]; 3365 tmp = reply->ia->iasubopt[i];
3363 3366
3364 if (tmp->ia != NULL) 3367 if (tmp->ia != NULL)
3365 ia_dereference(&tmp->ia, MDL); 3368 ia_dereference(&tmp->ia, MDL);
3366 ia_reference(&tmp->ia, reply->ia, MDL); 3369 ia_reference(&tmp->ia, reply->ia, MDL);
3367 3370
3368 /* Commit 'hard' bindings. */ 3371 /* Commit 'hard' bindings. */
3369 tmp->hard_lifetime_end_time = 
3370 tmp->soft_lifetime_end_time; 
3371 tmp->soft_lifetime_end_time = 0; 
3372 renew_lease6(tmp->ipv6_pool, tmp); 3372 renew_lease6(tmp->ipv6_pool, tmp);
3373 schedule_lease_timeout(tmp->ipv6_pool); 3373 schedule_lease_timeout(tmp->ipv6_pool);
3374 } 3374 }
3375 3375
3376 /* Remove any old ia from the hash. */ 3376 /* Remove any old ia from the hash. */
3377 if (reply->old_ia != NULL) { 3377 if (reply->old_ia != NULL) {
3378 ia_id = &reply->old_ia->iaid_duid; 3378 ia_id = &reply->old_ia->iaid_duid;
3379 ia_hash_delete(ia_pd_active, 3379 ia_hash_delete(ia_pd_active,
3380 (unsigned char *)ia_id->data, 3380 (unsigned char *)ia_id->data,
3381 ia_id->len, MDL); 3381 ia_id->len, MDL);
3382 ia_dereference(&reply->old_ia, MDL); 3382 ia_dereference(&reply->old_ia, MDL);
3383 } 3383 }
3384 3384
@@ -3495,28 +3495,29 @@ reply_process_prefix(struct reply_state  @@ -3495,28 +3495,29 @@ reply_process_prefix(struct reply_state
3495 } 3495 }
3496 3496
3497 memcpy(tmp_pref.lo_addr.iabuf, iapref.data + 9, 16); 3497 memcpy(tmp_pref.lo_addr.iabuf, iapref.data + 9, 16);
3498 3498
3499 /* Verify the prefix belongs to the client. */ 3499 /* Verify the prefix belongs to the client. */
3500 if (!prefix_is_owned(reply, &tmp_pref)) { 3500 if (!prefix_is_owned(reply, &tmp_pref)) {
3501 /* Same than for addresses. */ 3501 /* Same than for addresses. */
3502 if ((reply->packet->dhcpv6_msg_type == DHCPV6_SOLICIT) || 3502 if ((reply->packet->dhcpv6_msg_type == DHCPV6_SOLICIT) ||
3503 (reply->packet->dhcpv6_msg_type == DHCPV6_REQUEST) || 3503 (reply->packet->dhcpv6_msg_type == DHCPV6_REQUEST) ||
3504 (reply->packet->dhcpv6_msg_type == DHCPV6_REBIND)) { 3504 (reply->packet->dhcpv6_msg_type == DHCPV6_REBIND)) {
3505 status = reply_process_try_prefix(reply, &tmp_pref); 3505 status = reply_process_try_prefix(reply, &tmp_pref);
3506 3506
3507 /* Either error out or skip this prefix. */ 3507 /* Either error out or skip this prefix. */
3508 if ((status != ISC_R_SUCCESS) &&  3508 if ((status != ISC_R_SUCCESS) &&
3509 (status != ISC_R_ADDRINUSE))  3509 (status != ISC_R_ADDRINUSE) &&
 3510 (status != ISC_R_ADDRNOTAVAIL))
3510 goto cleanup; 3511 goto cleanup;
3511 3512
3512 if (reply->lease == NULL) { 3513 if (reply->lease == NULL) {
3513 if (reply->packet->dhcpv6_msg_type == 3514 if (reply->packet->dhcpv6_msg_type ==
3514 DHCPV6_REBIND) { 3515 DHCPV6_REBIND) {
3515 reply->send_prefer = 0; 3516 reply->send_prefer = 0;
3516 reply->send_valid = 0; 3517 reply->send_valid = 0;
3517 goto send_pref; 3518 goto send_pref;
3518 } 3519 }
3519 3520
3520 /* status remains success - ignore */ 3521 /* status remains success - ignore */
3521 goto cleanup; 3522 goto cleanup;
3522 } 3523 }
@@ -3644,91 +3645,96 @@ reply_process_prefix(struct reply_state  @@ -3644,91 +3645,96 @@ reply_process_prefix(struct reply_state
3644static isc_boolean_t 3645static isc_boolean_t
3645prefix_is_owned(struct reply_state *reply, struct iaddrcidrnet *pref) { 3646prefix_is_owned(struct reply_state *reply, struct iaddrcidrnet *pref) {
3646 struct iaddrcidrnetlist *l; 3647 struct iaddrcidrnetlist *l;
3647 int i; 3648 int i;
3648 3649
3649 /* 3650 /*
3650 * This faults out prefixes that don't match fixed prefixes. 3651 * This faults out prefixes that don't match fixed prefixes.
3651 */ 3652 */
3652 if (reply->static_prefixes > 0) { 3653 if (reply->static_prefixes > 0) {
3653 for (l = reply->host->fixed_prefix; l != NULL; l = l->next) { 3654 for (l = reply->host->fixed_prefix; l != NULL; l = l->next) {
3654 if ((pref->bits == l->cidrnet.bits) && 3655 if ((pref->bits == l->cidrnet.bits) &&
3655 (memcmp(pref->lo_addr.iabuf, 3656 (memcmp(pref->lo_addr.iabuf,
3656 l->cidrnet.lo_addr.iabuf, 16) == 0)) 3657 l->cidrnet.lo_addr.iabuf, 16) == 0))
3657 return ISC_TRUE; 3658 return (ISC_TRUE);
3658 } 3659 }
3659 return ISC_FALSE; 3660 return (ISC_FALSE);
3660 } 3661 }
3661 3662
3662 if ((reply->old_ia == NULL) || 3663 if ((reply->old_ia == NULL) ||
3663 (reply->old_ia->num_iasubopt == 0)) 3664 (reply->old_ia->num_iasubopt == 0))
3664 return ISC_FALSE; 3665 return (ISC_FALSE);
3665 3666
3666 for (i = 0 ; i < reply->old_ia->num_iasubopt ; i++) { 3667 for (i = 0 ; i < reply->old_ia->num_iasubopt ; i++) {
3667 struct iasubopt *tmp; 3668 struct iasubopt *tmp;
3668 3669
3669 tmp = reply->old_ia->iasubopt[i]; 3670 tmp = reply->old_ia->iasubopt[i];
3670 3671
3671 if ((pref->bits == (int) tmp->plen) && 3672 if ((pref->bits == (int) tmp->plen) &&
3672 memcmp(pref->lo_addr.iabuf, &tmp->addr, 16) == 0) { 3673 (memcmp(pref->lo_addr.iabuf, &tmp->addr, 16) == 0)) {
 3674 if (lease6_usable(tmp) == ISC_FALSE) {
 3675 return (ISC_FALSE);
 3676 }
3673 iasubopt_reference(&reply->lease, tmp, MDL); 3677 iasubopt_reference(&reply->lease, tmp, MDL);
3674 return ISC_TRUE; 3678 return (ISC_TRUE);
3675 } 3679 }
3676 } 3680 }
3677 3681
3678 return ISC_FALSE; 3682 return (ISC_FALSE);
3679} 3683}
3680 3684
3681/* 3685/*
3682 * This function only returns failure on 'hard' failures. If it succeeds, 3686 * This function only returns failure on 'hard' failures. If it succeeds,
3683 * it will leave a prefix structure behind. 3687 * it will leave a prefix structure behind.
3684 */ 3688 */
3685static isc_result_t 3689static isc_result_t
3686reply_process_try_prefix(struct reply_state *reply, 3690reply_process_try_prefix(struct reply_state *reply,
3687 struct iaddrcidrnet *pref) { 3691 struct iaddrcidrnet *pref) {
3688 isc_result_t status = ISC_R_NORESOURCES; 3692 isc_result_t status = ISC_R_ADDRNOTAVAIL;
3689 struct ipv6_pool *pool; 3693 struct ipv6_pool *pool;
3690 int i; 3694 int i;
3691 struct data_string data_pref; 3695 struct data_string data_pref;
3692 3696
3693 if ((reply == NULL) || (reply->shared == NULL) || 3697 if ((reply == NULL) || (reply->shared == NULL) ||
3694 (reply->shared->ipv6_pools == NULL) || (pref == NULL) || 3698 (pref == NULL) || (reply->lease != NULL))
3695 (reply->lease != NULL)) 3699 return (DHCP_R_INVALIDARG);
3696 return DHCP_R_INVALIDARG; 3700
 3701 if (reply->shared->ipv6_pools == NULL)
 3702 return (ISC_R_ADDRNOTAVAIL);
3697 3703
3698 memset(&data_pref, 0, sizeof(data_pref)); 3704 memset(&data_pref, 0, sizeof(data_pref));
3699 data_pref.len = 17; 3705 data_pref.len = 17;
3700 if (!buffer_allocate(&data_pref.buffer, data_pref.len, MDL)) { 3706 if (!buffer_allocate(&data_pref.buffer, data_pref.len, MDL)) {
3701 log_error("reply_process_try_prefix: out of memory."); 3707 log_error("reply_process_try_prefix: out of memory.");
3702 return ISC_R_NOMEMORY; 3708 return (ISC_R_NOMEMORY);
3703 } 3709 }
3704 data_pref.data = data_pref.buffer->data; 3710 data_pref.data = data_pref.buffer->data;
3705 data_pref.buffer->data[0] = (u_int8_t) pref->bits; 3711 data_pref.buffer->data[0] = (u_int8_t) pref->bits;
3706 memcpy(data_pref.buffer->data + 1, pref->lo_addr.iabuf, 16); 3712 memcpy(data_pref.buffer->data + 1, pref->lo_addr.iabuf, 16);
3707 3713
3708 for (i = 0 ; (pool = reply->shared->ipv6_pools[i]) != NULL ; i++) { 3714 for (i = 0 ; (pool = reply->shared->ipv6_pools[i]) != NULL ; i++) {
3709 if (pool->pool_type != D6O_IA_PD) 3715 if (pool->pool_type != D6O_IA_PD)
3710 continue; 3716 continue;
3711 status = try_client_v6_prefix(&reply->lease, pool, 3717 status = try_client_v6_prefix(&reply->lease, pool,
3712 &data_pref); 3718 &data_pref);
3713 /* If we found it in this pool (either in use or available),  3719 /* If we found it in this pool (either in use or available),
3714 there is no need to look further. */ 3720 there is no need to look further. */
3715 if ( (status == ISC_R_SUCCESS) || (status == ISC_R_ADDRINUSE) ) 3721 if ( (status == ISC_R_SUCCESS) || (status == ISC_R_ADDRINUSE) )
3716 break; 3722 break;
3717 } 3723 }
3718 3724
3719 data_string_forget(&data_pref, MDL); 3725 data_string_forget(&data_pref, MDL);
3720 /* Return just the most recent status... */ 3726 /* Return just the most recent status... */
3721 return status; 3727 return (status);
3722} 3728}
3723 3729
3724/* Look around for a prefix to give the client. First, look through the old 3730/* Look around for a prefix to give the client. First, look through the old
3725 * IA_PD for prefixes we can extend. Second, try to allocate a new prefix. 3731 * IA_PD for prefixes we can extend. Second, try to allocate a new prefix.
3726 * Finally, actually add that prefix into the current reply IA_PD. 3732 * Finally, actually add that prefix into the current reply IA_PD.
3727 */ 3733 */
3728static isc_result_t 3734static isc_result_t
3729find_client_prefix(struct reply_state *reply) { 3735find_client_prefix(struct reply_state *reply) {
3730 struct iaddrcidrnet send_pref; 3736 struct iaddrcidrnet send_pref;
3731 isc_result_t status = ISC_R_NORESOURCES; 3737 isc_result_t status = ISC_R_NORESOURCES;
3732 struct iasubopt *prefix, *best_prefix = NULL; 3738 struct iasubopt *prefix, *best_prefix = NULL;
3733 struct binding_scope **scope; 3739 struct binding_scope **scope;
3734 int i; 3740 int i;
@@ -3759,28 +3765,29 @@ find_client_prefix(struct reply_state *r @@ -3759,28 +3765,29 @@ find_client_prefix(struct reply_state *r
3759 3765
3760 if (reply->old_ia != NULL) { 3766 if (reply->old_ia != NULL) {
3761 for (i = 0 ; i < reply->old_ia->num_iasubopt ; i++) { 3767 for (i = 0 ; i < reply->old_ia->num_iasubopt ; i++) {
3762 struct shared_network *candidate_shared; 3768 struct shared_network *candidate_shared;
3763 3769
3764 prefix = reply->old_ia->iasubopt[i]; 3770 prefix = reply->old_ia->iasubopt[i];
3765 candidate_shared = prefix->ipv6_pool->shared_network; 3771 candidate_shared = prefix->ipv6_pool->shared_network;
3766 3772
3767 /* 3773 /*
3768 * Consider this prefix if it is in a global pool or 3774 * Consider this prefix if it is in a global pool or
3769 * if it is scoped in a pool under the client's shared 3775 * if it is scoped in a pool under the client's shared
3770 * network. 3776 * network.
3771 */ 3777 */
3772 if (candidate_shared == NULL || 3778 if (((candidate_shared == NULL) ||
3773 candidate_shared == reply->shared) { 3779 (candidate_shared == reply->shared)) &&
 3780 (lease6_usable(prefix) == ISC_TRUE)) {
3774 best_prefix = prefix_compare(reply, prefix, 3781 best_prefix = prefix_compare(reply, prefix,
3775 best_prefix); 3782 best_prefix);
3776 } 3783 }
3777 } 3784 }
3778 } 3785 }
3779 3786
3780 /* Try to pick a new prefix if we didn't find one, or if we found an 3787 /* Try to pick a new prefix if we didn't find one, or if we found an
3781 * abandoned prefix. 3788 * abandoned prefix.
3782 */ 3789 */
3783 if ((best_prefix == NULL) || (best_prefix->state == FTS_ABANDONED)) { 3790 if ((best_prefix == NULL) || (best_prefix->state == FTS_ABANDONED)) {
3784 status = pick_v6_prefix(&reply->lease, reply->preflen, 3791 status = pick_v6_prefix(&reply->lease, reply->preflen,
3785 reply->shared, &reply->client_id); 3792 reply->shared, &reply->client_id);
3786 } else if (best_prefix != NULL) { 3793 } else if (best_prefix != NULL) {
@@ -4614,27 +4621,26 @@ iterate_over_ia_na(struct data_string *r @@ -4614,27 +4621,26 @@ iterate_over_ia_na(struct data_string *r
4614 int *, int)) 4621 int *, int))
4615{ 4622{
4616 struct option_state *opt_state; 4623 struct option_state *opt_state;
4617 struct host_decl *packet_host; 4624 struct host_decl *packet_host;
4618 struct option_cache *ia; 4625 struct option_cache *ia;
4619 struct option_cache *oc; 4626 struct option_cache *oc;
4620 /* cli_enc_... variables come from the IA_NA/IA_TA options */ 4627 /* cli_enc_... variables come from the IA_NA/IA_TA options */
4621 struct data_string cli_enc_opt_data; 4628 struct data_string cli_enc_opt_data;
4622 struct option_state *cli_enc_opt_state; 4629 struct option_state *cli_enc_opt_state;
4623 struct host_decl *host; 4630 struct host_decl *host;
4624 struct option_state *host_opt_state; 4631 struct option_state *host_opt_state;
4625 struct data_string iaaddr; 4632 struct data_string iaaddr;
4626 struct data_string fixed_addr; 4633 struct data_string fixed_addr;
4627 int iaaddr_is_found; 
4628 char reply_data[65536]; 4634 char reply_data[65536];
4629 struct dhcpv6_packet *reply = (struct dhcpv6_packet *)reply_data; 4635 struct dhcpv6_packet *reply = (struct dhcpv6_packet *)reply_data;
4630 int reply_ofs = (int)(offsetof(struct dhcpv6_packet, options)); 4636 int reply_ofs = (int)(offsetof(struct dhcpv6_packet, options));
4631 char status_msg[32]; 4637 char status_msg[32];
4632 struct iasubopt *lease; 4638 struct iasubopt *lease;
4633 struct ia_xx *existing_ia_na; 4639 struct ia_xx *existing_ia_na;
4634 int i; 4640 int i;
4635 struct data_string key; 4641 struct data_string key;
4636 u_int32_t iaid; 4642 u_int32_t iaid;
4637 4643
4638 /* 4644 /*
4639 * Initialize to empty values, in case we have to exit early. 4645 * Initialize to empty values, in case we have to exit early.
4640 */ 4646 */
@@ -4721,27 +4727,26 @@ iterate_over_ia_na(struct data_string *r @@ -4721,27 +4727,26 @@ iterate_over_ia_na(struct data_string *r
4721 * Add our options that are not associated with any IA_NA or IA_TA.  4727 * Add our options that are not associated with any IA_NA or IA_TA.
4722 */ 4728 */
4723 reply_ofs += store_options6(reply_data+reply_ofs, 4729 reply_ofs += store_options6(reply_data+reply_ofs,
4724 sizeof(reply_data)-reply_ofs,  4730 sizeof(reply_data)-reply_ofs,
4725 opt_state, packet, 4731 opt_state, packet,
4726 required_opts, NULL); 4732 required_opts, NULL);
4727 4733
4728 /* 4734 /*
4729 * Loop through the IA_NA reported by the client, and deal with 4735 * Loop through the IA_NA reported by the client, and deal with
4730 * addresses reported as already in use. 4736 * addresses reported as already in use.
4731 */ 4737 */
4732 for (ia = lookup_option(&dhcpv6_universe, packet->options, D6O_IA_NA); 4738 for (ia = lookup_option(&dhcpv6_universe, packet->options, D6O_IA_NA);
4733 ia != NULL; ia = ia->next) { 4739 ia != NULL; ia = ia->next) {
4734 iaaddr_is_found = 0; 
4735 4740
4736 if (!get_encapsulated_IA_state(&cli_enc_opt_state, 4741 if (!get_encapsulated_IA_state(&cli_enc_opt_state,
4737 &cli_enc_opt_data, 4742 &cli_enc_opt_data,
4738 packet, ia, IA_NA_OFFSET)) { 4743 packet, ia, IA_NA_OFFSET)) {
4739 goto exit; 4744 goto exit;
4740 } 4745 }
4741 4746
4742 iaid = getULong(cli_enc_opt_data.data); 4747 iaid = getULong(cli_enc_opt_data.data);
4743 4748
4744 /*  4749 /*
4745 * XXX: It is possible that we can get multiple addresses 4750 * XXX: It is possible that we can get multiple addresses
4746 * sent by the client. We don't send multiple  4751 * sent by the client. We don't send multiple
4747 * addresses, so this indicates a client error.  4752 * addresses, so this indicates a client error.
@@ -5138,27 +5143,26 @@ iterate_over_ia_pd(struct data_string *r @@ -5138,27 +5143,26 @@ iterate_over_ia_pd(struct data_string *r
5138{ 5143{
5139 struct data_string reply_new; 5144 struct data_string reply_new;
5140 int reply_len; 5145 int reply_len;
5141 struct option_state *opt_state; 5146 struct option_state *opt_state;
5142 struct host_decl *packet_host; 5147 struct host_decl *packet_host;
5143 struct option_cache *ia; 5148 struct option_cache *ia;
5144 struct option_cache *oc; 5149 struct option_cache *oc;
5145 /* cli_enc_... variables come from the IA_PD options */ 5150 /* cli_enc_... variables come from the IA_PD options */
5146 struct data_string cli_enc_opt_data; 5151 struct data_string cli_enc_opt_data;
5147 struct option_state *cli_enc_opt_state; 5152 struct option_state *cli_enc_opt_state;
5148 struct host_decl *host; 5153 struct host_decl *host;
5149 struct option_state *host_opt_state; 5154 struct option_state *host_opt_state;
5150 struct data_string iaprefix; 5155 struct data_string iaprefix;
5151 int iaprefix_is_found; 
5152 char reply_data[65536]; 5156 char reply_data[65536];
5153 int reply_ofs; 5157 int reply_ofs;
5154 struct iasubopt *prefix; 5158 struct iasubopt *prefix;
5155 struct ia_xx *existing_ia_pd; 5159 struct ia_xx *existing_ia_pd;
5156 int i; 5160 int i;
5157 struct data_string key; 5161 struct data_string key;
5158 u_int32_t iaid; 5162 u_int32_t iaid;
5159 5163
5160 /* 5164 /*
5161 * Initialize to empty values, in case we have to exit early. 5165 * Initialize to empty values, in case we have to exit early.
5162 */ 5166 */
5163 memset(&reply_new, 0, sizeof(reply_new)); 5167 memset(&reply_new, 0, sizeof(reply_new));
5164 opt_state = NULL; 5168 opt_state = NULL;
@@ -5205,27 +5209,26 @@ iterate_over_ia_pd(struct data_string *r @@ -5205,27 +5209,26 @@ iterate_over_ia_pd(struct data_string *r
5205 log_error("iterate_over_ia_pd: no memory for option_state."); 5209 log_error("iterate_over_ia_pd: no memory for option_state.");
5206 goto exit; 5210 goto exit;
5207 } 5211 }
5208 execute_statements_in_scope(NULL, packet, NULL, NULL,  5212 execute_statements_in_scope(NULL, packet, NULL, NULL,
5209 packet->options, opt_state,  5213 packet->options, opt_state,
5210 &global_scope, root_group, NULL); 5214 &global_scope, root_group, NULL);
5211 5215
5212 /* 5216 /*
5213 * Loop through the IA_PD reported by the client, and deal with 5217 * Loop through the IA_PD reported by the client, and deal with
5214 * prefixes reported as already in use. 5218 * prefixes reported as already in use.
5215 */ 5219 */
5216 for (ia = lookup_option(&dhcpv6_universe, packet->options, D6O_IA_PD); 5220 for (ia = lookup_option(&dhcpv6_universe, packet->options, D6O_IA_PD);
5217 ia != NULL; ia = ia->next) { 5221 ia != NULL; ia = ia->next) {
5218 iaprefix_is_found = 0; 
5219 5222
5220 if (!get_encapsulated_IA_state(&cli_enc_opt_state, 5223 if (!get_encapsulated_IA_state(&cli_enc_opt_state,
5221 &cli_enc_opt_data, 5224 &cli_enc_opt_data,
5222 packet, ia, IA_PD_OFFSET)) { 5225 packet, ia, IA_PD_OFFSET)) {
5223 goto exit; 5226 goto exit;
5224 } 5227 }
5225 5228
5226 iaid = getULong(cli_enc_opt_data.data); 5229 iaid = getULong(cli_enc_opt_data.data);
5227 5230
5228 oc = lookup_option(&dhcpv6_universe, cli_enc_opt_state,  5231 oc = lookup_option(&dhcpv6_universe, cli_enc_opt_state,
5229 D6O_IAPREFIX); 5232 D6O_IAPREFIX);
5230 if (oc == NULL) { 5233 if (oc == NULL) {
5231 /* no prefix given for this IA_PD, ignore */ 5234 /* no prefix given for this IA_PD, ignore */
@@ -5533,56 +5536,58 @@ dhcpv6_relay_forw(struct data_string *re @@ -5533,56 +5536,58 @@ dhcpv6_relay_forw(struct data_string *re
5533 log_error("dhcpv6_forw_relay: " 5536 log_error("dhcpv6_forw_relay: "
5534 "no memory for encapsulated packet's options."); 5537 "no memory for encapsulated packet's options.");
5535 goto exit; 5538 goto exit;
5536 } 5539 }
5537 5540
5538 enc_packet->client_port = packet->client_port; 5541 enc_packet->client_port = packet->client_port;
5539 enc_packet->client_addr = packet->client_addr; 5542 enc_packet->client_addr = packet->client_addr;
5540 interface_reference(&enc_packet->interface, packet->interface, MDL); 5543 interface_reference(&enc_packet->interface, packet->interface, MDL);
5541 enc_packet->dhcpv6_container_packet = packet; 5544 enc_packet->dhcpv6_container_packet = packet;
5542 5545
5543 msg_type = enc_opt_data.data[0]; 5546 msg_type = enc_opt_data.data[0];
5544 if ((msg_type == DHCPV6_RELAY_FORW) || 5547 if ((msg_type == DHCPV6_RELAY_FORW) ||
5545 (msg_type == DHCPV6_RELAY_REPL)) { 5548 (msg_type == DHCPV6_RELAY_REPL)) {
 5549 int relaylen = (int)(offsetof(struct dhcpv6_relay_packet, options));
5546 relay = (struct dhcpv6_relay_packet *)enc_opt_data.data; 5550 relay = (struct dhcpv6_relay_packet *)enc_opt_data.data;
5547 enc_packet->dhcpv6_msg_type = relay->msg_type; 5551 enc_packet->dhcpv6_msg_type = relay->msg_type;
5548 5552
5549 /* relay-specific data */ 5553 /* relay-specific data */
5550 enc_packet->dhcpv6_hop_count = relay->hop_count; 5554 enc_packet->dhcpv6_hop_count = relay->hop_count;
5551 memcpy(&enc_packet->dhcpv6_link_address, 5555 memcpy(&enc_packet->dhcpv6_link_address,
5552 relay->link_address, sizeof(relay->link_address)); 5556 relay->link_address, sizeof(relay->link_address));
5553 memcpy(&enc_packet->dhcpv6_peer_address, 5557 memcpy(&enc_packet->dhcpv6_peer_address,
5554 relay->peer_address, sizeof(relay->peer_address)); 5558 relay->peer_address, sizeof(relay->peer_address));
5555 5559
5556 if (!parse_option_buffer(enc_packet->options, 5560 if (!parse_option_buffer(enc_packet->options,
5557 relay->options,  5561 relay->options,
5558 enc_opt_data.len-sizeof(*relay), 5562 enc_opt_data.len - relaylen,
5559 &dhcpv6_universe)) { 5563 &dhcpv6_universe)) {
5560 /* no logging here, as parse_option_buffer() logs all 5564 /* no logging here, as parse_option_buffer() logs all
5561 cases where it fails */ 5565 cases where it fails */
5562 goto exit; 5566 goto exit;
5563 } 5567 }
5564 } else { 5568 } else {
 5569 int msglen = (int)(offsetof(struct dhcpv6_packet, options));
5565 msg = (struct dhcpv6_packet *)enc_opt_data.data; 5570 msg = (struct dhcpv6_packet *)enc_opt_data.data;
5566 enc_packet->dhcpv6_msg_type = msg->msg_type; 5571 enc_packet->dhcpv6_msg_type = msg->msg_type;
5567 5572
5568 /* message-specific data */ 5573 /* message-specific data */
5569 memcpy(enc_packet->dhcpv6_transaction_id, 5574 memcpy(enc_packet->dhcpv6_transaction_id,
5570 msg->transaction_id, 5575 msg->transaction_id,
5571 sizeof(enc_packet->dhcpv6_transaction_id)); 5576 sizeof(enc_packet->dhcpv6_transaction_id));
5572 5577
5573 if (!parse_option_buffer(enc_packet->options, 5578 if (!parse_option_buffer(enc_packet->options,
5574 msg->options,  5579 msg->options,
5575 enc_opt_data.len-sizeof(*msg), 5580 enc_opt_data.len - msglen,
5576 &dhcpv6_universe)) { 5581 &dhcpv6_universe)) {
5577 /* no logging here, as parse_option_buffer() logs all 5582 /* no logging here, as parse_option_buffer() logs all
5578 cases where it fails */ 5583 cases where it fails */
5579 goto exit; 5584 goto exit;
5580 } 5585 }
5581 } 5586 }
5582 5587
5583 /* 5588 /*
5584 * This is recursive. It is possible to exceed maximum packet size. 5589 * This is recursive. It is possible to exceed maximum packet size.
5585 * XXX: This will cause the packet send to fail. 5590 * XXX: This will cause the packet send to fail.
5586 */ 5591 */
5587 build_dhcpv6_reply(&enc_reply, enc_packet); 5592 build_dhcpv6_reply(&enc_reply, enc_packet);
5588 5593
@@ -6031,27 +6036,27 @@ find_hosts_by_duid_chaddr(struct host_de @@ -6031,27 +6036,27 @@ find_hosts_by_duid_chaddr(struct host_de
6031 case DUID_LL: 6036 case DUID_LL:
6032 /* 6037 /*
6033 * Note that client_id->len must be greater than or equal 6038 * Note that client_id->len must be greater than or equal
6034 * to four to get to this point in the function. 6039 * to four to get to this point in the function.
6035 */ 6040 */
6036 hlen = client_id->len - 4; 6041 hlen = client_id->len - 4;
6037 chaddr = client_id->data + 4; 6042 chaddr = client_id->data + 4;
6038 break; 6043 break;
6039 6044
6040 default: 6045 default:
6041 break; 6046 break;
6042 } 6047 }
6043 6048
6044 if (hlen == 0) 6049 if ((hlen == 0) || (hlen > HARDWARE_ADDR_LEN))
6045 return 0; 6050 return 0;
6046 6051
6047 /* 6052 /*
6048 * XXX: DHCPv6 gives a 16-bit field for the htype. DHCPv4 gives an 6053 * XXX: DHCPv6 gives a 16-bit field for the htype. DHCPv4 gives an
6049 * 8-bit field. To change the semantics of the generic 'hardware' 6054 * 8-bit field. To change the semantics of the generic 'hardware'
6050 * structure, we would have to adjust many DHCPv4 sources (from 6055 * structure, we would have to adjust many DHCPv4 sources (from
6051 * interface to DHCPv4 lease code), and we would have to update the 6056 * interface to DHCPv4 lease code), and we would have to update the
6052 * 'hardware' config directive (probably being reverse compatible and 6057 * 'hardware' config directive (probably being reverse compatible and
6053 * providing a new upgrade/replacement primitive). This is a little 6058 * providing a new upgrade/replacement primitive). This is a little
6054 * too much to change for now. Hopefully we will revisit this before 6059 * too much to change for now. Hopefully we will revisit this before
6055 * hardware types exceeding 8 bits are assigned. 6060 * hardware types exceeding 8 bits are assigned.
6056 */ 6061 */
6057 if ((htype & 0xFF00) && !once_htype) { 6062 if ((htype & 0xFF00) && !once_htype) {

cvs diff -r1.2 -r1.3 src/external/bsd/dhcp/dist/server/Attic/mdb6.c (expand / switch to unified diff)

--- src/external/bsd/dhcp/dist/server/Attic/mdb6.c 2013/03/24 15:53:59 1.2
+++ src/external/bsd/dhcp/dist/server/Attic/mdb6.c 2013/03/24 23:03:06 1.3
@@ -1,34 +1,96 @@ @@ -1,34 +1,96 @@
1/* $NetBSD: mdb6.c,v 1.2 2013/03/24 15:53:59 christos Exp $ */ 1/* $NetBSD: mdb6.c,v 1.3 2013/03/24 23:03:06 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (C) 2007-2011 by Internet Systems Consortium, Inc. ("ISC") 4 * Copyright (C) 2007-2012 by Internet Systems Consortium, Inc. ("ISC")
5 * 5 *
6 * Permission to use, copy, modify, and distribute this software for any 6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above 7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies. 8 * copyright notice and this permission notice appear in all copies.
9 * 9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE. 16 * PERFORMANCE OF THIS SOFTWARE.
17 */ 17 */
18 18
19/* TODO: assert() */ 19/*!
20/* TODO: simplify functions, as pool is now in iaaddr */ 20 * \todo assert()
21 21 * \todo simplify functions, as pool is now in iaaddr
 22 */
 23
 24/*! \file server/mdb6.c
 25 *
 26 * \page ipv6structures IPv6 Structures Overview
 27 *
 28 * A brief description of the IPv6 structures as reverse engineered.
 29 *
 30 * There are three major data strucutes involved in the database:
 31 *
 32 * - ipv6_pool - this contains information about a pool of addresses or prefixes
 33 * that the server is using. This includes a hash table that
 34 * tracks the active items and a pair of heap tables one for
 35 * active items and one for non-active items. The heap tables
 36 * are used to determine the next items to be modified due to
 37 * timing events (expire mostly).
 38 * - ia_xx - this contains information about a single IA from a request
 39 * normally it will contain one pointer to a lease for the client
 40 * but it may contain more in some circumstances. There are 3
 41 * hash tables to aid in accessing these one each for NA, TA and PD.
 42 * - iasubopt- the v6 lease structure. These are created dynamically when
 43 * a client asks for something and will eventually be destroyed
 44 * if the client doesn't re-ask for that item. A lease has space
 45 * for backpointers to the IA and to the pool to which it belongs.
 46 * The pool backpointer is always filled, the IA pointer may not be.
 47 *
 48 * In normal use we then have something like this:
 49 *
 50 * \verbatim
 51 * ia hash tables
 52 * ia_na_active +----------------+
 53 * ia_ta_active +------------+ | pool |
 54 * ia_pd_active | iasubopt |<--| active hash |
 55 * +-----------------+ | aka lease |<--| active heap |
 56 * | ia_xx | | pool ptr |-->| |
 57 * | iasubopt array |<---| iaptr |<--| inactive heap |
 58 * | lease ptr |--->| | | |
 59 * +-----------------+ +------------+ +----------------+
 60 * \endverbatim
 61 *
 62 * For the pool either the inactive heap will have a pointer
 63 * or both the active heap and the active hash will have pointers.
 64 *
 65 * I think there are several major items to notice. The first is
 66 * that as a lease moves around it will be added to and removed
 67 * from the address hash table in the pool and between the active
 68 * and inactive hash tables. The hash table and the active heap
 69 * are used when the lease is either active or abandoned. The
 70 * inactive heap is used for all other states. In particular a
 71 * lease that has expired or been released will be cleaned
 72 * (DDNS removal etc) and then moved to the inactive heap. After
 73 * some time period (currently 1 hour) it will be freed.
 74 *
 75 * The second is that when a client requests specific addresses,
 76 * either because it previously owned them or if the server supplied
 77 * them as part of a solicit, the server will try to lookup the ia_xx
 78 * associated with the client and find the addresses there. If it
 79 * does find appropriate leases it moves them from the old IA to
 80 * a new IA and eventually replaces the old IA with the new IA
 81 * in the IA hash tables.
 82 *
 83 */
22#include "config.h" 84#include "config.h"
23 85
24#include <sys/types.h> 86#include <sys/types.h>
25#include <time.h> 87#include <time.h>
26#include <netinet/in.h> 88#include <netinet/in.h>
27 89
28#include <stdarg.h> 90#include <stdarg.h>
29#include "dhcpd.h" 91#include "dhcpd.h"
30#include "omapip/omapip.h" 92#include "omapip/omapip.h"
31#include "omapip/hash.h" 93#include "omapip/hash.h"
32#include <isc/md5.h> 94#include <isc/md5.h>
33 95
34HASH_FUNCTIONS(ia, unsigned char *, struct ia_xx, ia_hash_t, 96HASH_FUNCTIONS(ia, unsigned char *, struct ia_xx, ia_hash_t,
@@ -305,26 +367,28 @@ ia_add_iasubopt(struct ia_xx *ia, struct @@ -305,26 +367,28 @@ ia_add_iasubopt(struct ia_xx *ia, struct
305 367
306 return ISC_R_SUCCESS; 368 return ISC_R_SUCCESS;
307} 369}
308 370
309/* 371/*
310 * Remove an IAADDR/PREFIX entry to an IA structure. 372 * Remove an IAADDR/PREFIX entry to an IA structure.
311 * 373 *
312 * Note: if a suboption appears more than once, then only ONE will be removed. 374 * Note: if a suboption appears more than once, then only ONE will be removed.
313 */ 375 */
314void 376void
315ia_remove_iasubopt(struct ia_xx *ia, struct iasubopt *iasubopt, 377ia_remove_iasubopt(struct ia_xx *ia, struct iasubopt *iasubopt,
316 const char *file, int line) { 378 const char *file, int line) {
317 int i, j; 379 int i, j;
 380 if (ia == NULL || iasubopt == NULL)
 381 return;
318 382
319 for (i=0; i<ia->num_iasubopt; i++) { 383 for (i=0; i<ia->num_iasubopt; i++) {
320 if (ia->iasubopt[i] == iasubopt) { 384 if (ia->iasubopt[i] == iasubopt) {
321 /* remove this sub option */ 385 /* remove this sub option */
322 iasubopt_dereference(&(ia->iasubopt[i]), file, line); 386 iasubopt_dereference(&(ia->iasubopt[i]), file, line);
323 /* move remaining suboption pointers down one */ 387 /* move remaining suboption pointers down one */
324 for (j=i+1; j < ia->num_iasubopt; j++) { 388 for (j=i+1; j < ia->num_iasubopt; j++) {
325 ia->iasubopt[j-1] = ia->iasubopt[j]; 389 ia->iasubopt[j-1] = ia->iasubopt[j];
326 } 390 }
327 /* decrease our total count */ 391 /* decrease our total count */
328 /* remove the back-reference in the suboption itself */ 392 /* remove the back-reference in the suboption itself */
329 ia_dereference(&iasubopt->ia, file, line); 393 ia_dereference(&iasubopt->ia, file, line);
330 ia->num_iasubopt--; 394 ia->num_iasubopt--;
@@ -800,35 +864,34 @@ create_lease6(struct ipv6_pool *pool, st @@ -800,35 +864,34 @@ create_lease6(struct ipv6_pool *pool, st
800 build_temporary6(&tmp, &pool->start_addr, 864 build_temporary6(&tmp, &pool->start_addr,
801 pool->bits, &ds); 865 pool->bits, &ds);
802 break; 866 break;
803 case D6O_IA_PD: 867 case D6O_IA_PD:
804 /* prefix */ 868 /* prefix */
805 log_error("create_lease6: prefix pool."); 869 log_error("create_lease6: prefix pool.");
806 return DHCP_R_INVALIDARG; 870 return DHCP_R_INVALIDARG;
807 default: 871 default:
808 log_error("create_lease6: untyped pool."); 872 log_error("create_lease6: untyped pool.");
809 return DHCP_R_INVALIDARG; 873 return DHCP_R_INVALIDARG;
810 } 874 }
811 875
812 /* 876 /*
813 * Avoid reserved interface IDs. 877 * Avoid reserved interface IDs. (cf. RFC 5453)
814 * (cf. draft-krishnan-ipv6-reserved-iids-02.txt) 
815 */ 878 */
816 reserved_iid = ISC_FALSE; 879 reserved_iid = ISC_FALSE;
817 if (memcmp(&tmp.s6_addr[8], &rtany, 8) == 0) { 880 if (memcmp(&tmp.s6_addr[8], &rtany.s6_addr[8], 8) == 0) {
818 reserved_iid = ISC_TRUE; 881 reserved_iid = ISC_TRUE;
819 } 882 }
820 if (!reserved_iid && 883 if (!reserved_iid &&
821 (memcmp(&tmp.s6_addr[8], &resany, 7) == 0) && 884 (memcmp(&tmp.s6_addr[8], &resany.s6_addr[8], 7) == 0) &&
822 ((tmp.s6_addr[15] & 0x80) == 0x80)) { 885 ((tmp.s6_addr[15] & 0x80) == 0x80)) {
823 reserved_iid = ISC_TRUE; 886 reserved_iid = ISC_TRUE;
824 } 887 }
825 888
826 /* 889 /*
827 * If this address is not in use, we're happy with it 890 * If this address is not in use, we're happy with it
828 */ 891 */
829 test_iaaddr = NULL; 892 test_iaaddr = NULL;
830 if (!reserved_iid && 893 if (!reserved_iid &&
831 (iasubopt_hash_lookup(&test_iaaddr, pool->leases, 894 (iasubopt_hash_lookup(&test_iaaddr, pool->leases,
832 &tmp, sizeof(tmp), MDL) == 0)) { 895 &tmp, sizeof(tmp), MDL) == 0)) {
833 break; 896 break;
834 } 897 }
@@ -867,26 +930,165 @@ create_lease6(struct ipv6_pool *pool, st @@ -867,26 +930,165 @@ create_lease6(struct ipv6_pool *pool, st
867 memcpy(&iaaddr->addr, &tmp, sizeof(iaaddr->addr)); 930 memcpy(&iaaddr->addr, &tmp, sizeof(iaaddr->addr));
868 931
869 /* 932 /*
870 * Add the lease to the pool (note state is free, not active?!). 933 * Add the lease to the pool (note state is free, not active?!).
871 */ 934 */
872 result = add_lease6(pool, iaaddr, soft_lifetime_end_time); 935 result = add_lease6(pool, iaaddr, soft_lifetime_end_time);
873 if (result == ISC_R_SUCCESS) { 936 if (result == ISC_R_SUCCESS) {
874 iasubopt_reference(addr, iaaddr, MDL); 937 iasubopt_reference(addr, iaaddr, MDL);
875 } 938 }
876 iasubopt_dereference(&iaaddr, MDL); 939 iasubopt_dereference(&iaaddr, MDL);
877 return result; 940 return result;
878} 941}
879 942
 943
 944/*!
 945 *
 946 * \brief Cleans up leases when reading from a lease file
 947 *
 948 * This function is only expected to be run when reading leases in from a file.
 949 * It checks to see if a lease already exists for the new leases's address.
 950 * We don't add expired leases to the structures when reading a lease file
 951 * which limits what can happen. We have two variables the owners of the leases
 952 * being the same or different and the new lease being active or non-active:
 953 * Owners active
 954 * same no remove old lease and its connections
 955 * same yes nothing to do, other code will update the structures.
 956 * diff no nothing to do
 957 * diff yes this combination shouldn't happen, we should only have a
 958 * single active lease per address at a time and that lease
 959 * should move to non-active before any other lease can
 960 * become active for that address.
 961 * Currently we delete the previous lease and pass an error
 962 * to the caller who should log an error.
 963 *
 964 * When we remove a lease we remove it from the hash table and active heap
 965 * (remember only active leases are in the structures at this time) for the
 966 * pool, and from the IA's array. If, after we've removed the pointer from
 967 * IA's array to the lease, the IA has no more pointers we remove it from
 968 * the appropriate hash table as well.
 969 *
 970 * \param[in] ia_table = the hash table for the IA
 971 * \param[in] pool = the pool to update
 972 * \param[in] lease = the new lease we want to add
 973 * \param[in] ia = the new ia we are building
 974 *
 975 * \return
 976 * ISC_R_SUCCESS = the incoming lease and any previous lease were in
 977 * an expected state - one of the first 3 options above.
 978 * If necessary the old lease was removed.
 979 * ISC_R_FAILURE = there is already an active lease for the address in
 980 * the incoming lease. This shouldn't happen if it does
 981 * flag an error for the caller to log.
 982 */
 983
 984isc_result_t
 985cleanup_lease6(ia_hash_t *ia_table,
 986 struct ipv6_pool *pool,
 987 struct iasubopt *lease,
 988 struct ia_xx *ia) {
 989
 990 struct iasubopt *test_iasubopt, *tmp_iasubopt;
 991 struct ia_xx *old_ia;
 992 isc_result_t status = ISC_R_SUCCESS;
 993
 994 test_iasubopt = NULL;
 995 old_ia = NULL;
 996
 997 /*
 998 * Look up the address - if we don't find a lease
 999 * we don't need to do anything.
 1000 */
 1001 if (iasubopt_hash_lookup(&test_iasubopt, pool->leases,
 1002 &lease->addr, sizeof(lease->addr),
 1003 MDL) == 0) {
 1004 return (ISC_R_SUCCESS);
 1005 }
 1006
 1007 if (test_iasubopt->ia == NULL) {
 1008 /* no old ia, no work to do */
 1009 iasubopt_dereference(&test_iasubopt, MDL);
 1010 return (status);
 1011 }
 1012
 1013 ia_reference(&old_ia, test_iasubopt->ia, MDL);
 1014
 1015 if ((old_ia->iaid_duid.len == ia->iaid_duid.len) &&
 1016 (memcmp((unsigned char *)ia->iaid_duid.data,
 1017 (unsigned char *)old_ia->iaid_duid.data,
 1018 ia->iaid_duid.len) == 0)) {
 1019 /* same IA */
 1020 if ((lease->state == FTS_ACTIVE) ||
 1021 (lease->state == FTS_ABANDONED)) {
 1022 /* still active, no need to delete */
 1023 goto cleanup;
 1024 }
 1025 } else {
 1026 /* different IA */
 1027 if ((lease->state != FTS_ACTIVE) &&
 1028 (lease->state != FTS_ABANDONED)) {
 1029 /* new lease isn't active, no work */
 1030 goto cleanup;
 1031 }
 1032
 1033 /*
 1034 * We appear to have two active leases, this shouldn't happen.
 1035 * Before a second lease can be set to active the first lease
 1036 * should be set to inactive (released, expired etc). For now
 1037 * delete the previous lease and indicate a failure to the
 1038 * caller so it can generate a warning.
 1039 * In the future we may try and determine which is the better
 1040 * lease to keep.
 1041 */
 1042
 1043 status = ISC_R_FAILURE;
 1044 }
 1045
 1046 /*
 1047 * Remove the old lease from the active heap and from the hash table
 1048 * then remove the lease from the IA and clean up the IA if necessary.
 1049 */
 1050 isc_heap_delete(pool->active_timeouts, test_iasubopt->heap_index);
 1051 pool->num_active--;
 1052
 1053 iasubopt_hash_delete(pool->leases, &test_iasubopt->addr,
 1054 sizeof(test_iasubopt->addr), MDL);
 1055 ia_remove_iasubopt(old_ia, test_iasubopt, MDL);
 1056 if (old_ia->num_iasubopt <= 0) {
 1057 ia_hash_delete(ia_table,
 1058 (unsigned char *)old_ia->iaid_duid.data,
 1059 old_ia->iaid_duid.len, MDL);
 1060 }
 1061
 1062 /*
 1063 * We derefenrece the subopt here as we've just removed it from
 1064 * the hash table in the pool. We need to make a copy as we
 1065 * need to derefernece it again later.
 1066 */
 1067 tmp_iasubopt = test_iasubopt;
 1068 iasubopt_dereference(&tmp_iasubopt, MDL);
 1069
 1070 cleanup:
 1071 ia_dereference(&old_ia, MDL);
 1072
 1073 /*
 1074 * Clean up the reference, this is in addition to the deference
 1075 * above after removing the entry from the hash table
 1076 */
 1077 iasubopt_dereference(&test_iasubopt, MDL);
 1078
 1079 return (status);
 1080}
 1081
880/* 1082/*
881 * Put a lease in the pool directly. This is intended to be used when 1083 * Put a lease in the pool directly. This is intended to be used when
882 * loading leases from the file. 1084 * loading leases from the file.
883 */ 1085 */
884isc_result_t 1086isc_result_t
885add_lease6(struct ipv6_pool *pool, struct iasubopt *lease, 1087add_lease6(struct ipv6_pool *pool, struct iasubopt *lease,
886 time_t valid_lifetime_end_time) { 1088 time_t valid_lifetime_end_time) {
887 isc_result_t insert_result; 1089 isc_result_t insert_result;
888 struct iasubopt *test_iasubopt; 1090 struct iasubopt *test_iasubopt;
889 struct iasubopt *tmp_iasubopt; 1091 struct iasubopt *tmp_iasubopt;
890 1092
891 /* If a state was not assigned by the caller, assume active. */ 1093 /* If a state was not assigned by the caller, assume active. */
892 if (lease->state == 0) 1094 if (lease->state == 0)
@@ -977,70 +1179,122 @@ isc_boolean_t @@ -977,70 +1179,122 @@ isc_boolean_t
977lease6_exists(const struct ipv6_pool *pool, const struct in6_addr *addr) { 1179lease6_exists(const struct ipv6_pool *pool, const struct in6_addr *addr) {
978 struct iasubopt *test_iaaddr; 1180 struct iasubopt *test_iaaddr;
979 1181
980 test_iaaddr = NULL; 1182 test_iaaddr = NULL;
981 if (iasubopt_hash_lookup(&test_iaaddr, pool->leases,  1183 if (iasubopt_hash_lookup(&test_iaaddr, pool->leases,
982 (void *)addr, sizeof(*addr), MDL)) { 1184 (void *)addr, sizeof(*addr), MDL)) {
983 iasubopt_dereference(&test_iaaddr, MDL); 1185 iasubopt_dereference(&test_iaaddr, MDL);
984 return ISC_TRUE; 1186 return ISC_TRUE;
985 } else { 1187 } else {
986 return ISC_FALSE; 1188 return ISC_FALSE;
987 } 1189 }
988} 1190}
989 1191
 1192/*!
 1193 *
 1194 * \brief Check if address is available to a lease
 1195 *
 1196 * Determine if the address in the lease is available to that
 1197 * lease. Either the address isn't in use or it is in use
 1198 * but by that lease.
 1199 *
 1200 * \param[in] lease = lease to check
 1201 *
 1202 * \return
 1203 * ISC_TRUE = The lease is allowed to use that address
 1204 * ISC_FALSE = The lease isn't allowed to use that address
 1205 */
 1206isc_boolean_t
 1207lease6_usable(struct iasubopt *lease) {
 1208 struct iasubopt *test_iaaddr;
 1209 isc_boolean_t status = ISC_TRUE;
 1210
 1211 test_iaaddr = NULL;
 1212 if (iasubopt_hash_lookup(&test_iaaddr, lease->ipv6_pool->leases,
 1213 (void *)&lease->addr,
 1214 sizeof(lease->addr), MDL)) {
 1215 if (test_iaaddr != lease) {
 1216 status = ISC_FALSE;
 1217 }
 1218 iasubopt_dereference(&test_iaaddr, MDL);
 1219 }
 1220
 1221 return (status);
 1222}
 1223
990/* 1224/*
991 * Put the lease on our active pool. 1225 * Put the lease on our active pool.
992 */ 1226 */
993static isc_result_t 1227static isc_result_t
994move_lease_to_active(struct ipv6_pool *pool, struct iasubopt *lease) { 1228move_lease_to_active(struct ipv6_pool *pool, struct iasubopt *lease) {
995 isc_result_t insert_result; 1229 isc_result_t insert_result;
996 int old_heap_index; 1230 int old_heap_index;
997 1231
998 old_heap_index = lease->heap_index; 1232 old_heap_index = lease->heap_index;
999 insert_result = isc_heap_insert(pool->active_timeouts, lease); 1233 insert_result = isc_heap_insert(pool->active_timeouts, lease);
1000 if (insert_result == ISC_R_SUCCESS) { 1234 if (insert_result == ISC_R_SUCCESS) {
1001 iasubopt_hash_add(pool->leases, &lease->addr,  1235 iasubopt_hash_add(pool->leases, &lease->addr,
1002 sizeof(lease->addr), lease, MDL); 1236 sizeof(lease->addr), lease, MDL);
1003 isc_heap_delete(pool->inactive_timeouts, old_heap_index); 1237 isc_heap_delete(pool->inactive_timeouts, old_heap_index);
1004 pool->num_active++; 1238 pool->num_active++;
1005 pool->num_inactive--; 1239 pool->num_inactive--;
1006 lease->state = FTS_ACTIVE; 1240 lease->state = FTS_ACTIVE;
1007 } 1241 }
1008 return insert_result; 1242 return insert_result;
1009} 1243}
1010 1244
1011/* 1245/*!
1012 * Renew an lease in the pool. 1246 * \brief Renew a lease in the pool.
 1247 *
 1248 * The hard_lifetime_end_time of the lease should be set to
 1249 * the current expiration time.
 1250 * The soft_lifetime_end_time of the lease should be set to
 1251 * the desired expiration time.
 1252 *
 1253 * This routine will compare the two and call the correct
 1254 * heap routine to move the lease. If the lease is active
 1255 * and the new expiration time is greater (the normal case)
 1256 * then we call isc_heap_decreased() as a larger time is a
 1257 * lower priority. If the new expiration time is less then
 1258 * we call isc_heap_increased().
 1259 *
 1260 * If the lease is abandoned then it will be on the active list
 1261 * and we will always call isc_heap_increased() as the previous
 1262 * expiration would have been all 1s (as close as we can get
 1263 * to infinite).
1013 * 1264 *
1014 * To do this, first set the new hard_lifetime_end_time for the resource, 1265 * If the lease is moving to active we call that routine
1015 * and then invoke renew_lease6() on it. 1266 * which will move it from the inactive list to the active list.
1016 * 1267 *
1017 * WARNING: lease times must only be extended, never reduced!!! 1268 * \param pool a pool the lease belongs to
 1269 * \param lease the lease to be renewed
 1270 *
 1271 * \return result of the renew operation (ISC_R_SUCCESS if successful,
 1272 ISC_R_NOMEMORY when run out of memory)
1018 */ 1273 */
1019isc_result_t 1274isc_result_t
1020renew_lease6(struct ipv6_pool *pool, struct iasubopt *lease) { 1275renew_lease6(struct ipv6_pool *pool, struct iasubopt *lease) {
1021 /* 1276 time_t old_end_time = lease->hard_lifetime_end_time;
1022 * If we're already active, then we can just move our expiration 1277 lease->hard_lifetime_end_time = lease->soft_lifetime_end_time;
1023 * time down the heap.  1278 lease->soft_lifetime_end_time = 0;
1024 * 1279
1025 * If we're abandoned then we are already on the active list 
1026 * but we need to retag the lease and move our expiration 
1027 * from infinite to the current value 
1028 * 
1029 * Otherwise, we have to move from the inactive heap to the  
1030 * active heap. 
1031 */ 
1032 if (lease->state == FTS_ACTIVE) { 1280 if (lease->state == FTS_ACTIVE) {
1033 isc_heap_decreased(pool->active_timeouts, lease->heap_index); 1281 if (old_end_time <= lease->hard_lifetime_end_time) {
 1282 isc_heap_decreased(pool->active_timeouts,
 1283 lease->heap_index);
 1284 } else {
 1285 isc_heap_increased(pool->active_timeouts,
 1286 lease->heap_index);
 1287 }
1034 return ISC_R_SUCCESS; 1288 return ISC_R_SUCCESS;
1035 } else if (lease->state == FTS_ABANDONED) { 1289 } else if (lease->state == FTS_ABANDONED) {
1036 char tmp_addr[INET6_ADDRSTRLEN]; 1290 char tmp_addr[INET6_ADDRSTRLEN];
1037 lease->state = FTS_ACTIVE; 1291 lease->state = FTS_ACTIVE;
1038 isc_heap_increased(pool->active_timeouts, lease->heap_index); 1292 isc_heap_increased(pool->active_timeouts, lease->heap_index);
1039 log_info("Reclaiming previously abandoned address %s", 1293 log_info("Reclaiming previously abandoned address %s",
1040 inet_ntop(AF_INET6, &(lease->addr), tmp_addr, 1294 inet_ntop(AF_INET6, &(lease->addr), tmp_addr,
1041 sizeof(tmp_addr))); 1295 sizeof(tmp_addr)));
1042 return ISC_R_SUCCESS; 1296 return ISC_R_SUCCESS;
1043 } else { 1297 } else {
1044 return move_lease_to_active(pool, lease); 1298 return move_lease_to_active(pool, lease);
1045 } 1299 }
1046} 1300}
@@ -1050,27 +1304,27 @@ renew_lease6(struct ipv6_pool *pool, str @@ -1050,27 +1304,27 @@ renew_lease6(struct ipv6_pool *pool, str
1050 */ 1304 */
1051static isc_result_t 1305static isc_result_t
1052move_lease_to_inactive(struct ipv6_pool *pool, struct iasubopt *lease,  1306move_lease_to_inactive(struct ipv6_pool *pool, struct iasubopt *lease,
1053 binding_state_t state) { 1307 binding_state_t state) {
1054 isc_result_t insert_result; 1308 isc_result_t insert_result;
1055 int old_heap_index; 1309 int old_heap_index;
1056 1310
1057 old_heap_index = lease->heap_index; 1311 old_heap_index = lease->heap_index;
1058 insert_result = isc_heap_insert(pool->inactive_timeouts, lease); 1312 insert_result = isc_heap_insert(pool->inactive_timeouts, lease);
1059 if (insert_result == ISC_R_SUCCESS) { 1313 if (insert_result == ISC_R_SUCCESS) {
1060#if defined (NSUPDATE) 1314#if defined (NSUPDATE)
1061 /* Process events upon expiration. */ 1315 /* Process events upon expiration. */
1062 if (pool->pool_type != D6O_IA_PD) { 1316 if (pool->pool_type != D6O_IA_PD) {
1063 ddns_removals(NULL, lease, NULL); 1317 (void) ddns_removals(NULL, lease, NULL, ISC_FALSE);
1064 } 1318 }
1065#endif 1319#endif
1066 1320
1067 /* Binding scopes are no longer valid after expiry or 1321 /* Binding scopes are no longer valid after expiry or
1068 * release. 1322 * release.
1069 */ 1323 */
1070 if (lease->scope != NULL) { 1324 if (lease->scope != NULL) {
1071 binding_scope_dereference(&lease->scope, MDL); 1325 binding_scope_dereference(&lease->scope, MDL);
1072 } 1326 }
1073 1327
1074 iasubopt_hash_delete(pool->leases,  1328 iasubopt_hash_delete(pool->leases,
1075 &lease->addr, sizeof(lease->addr), MDL); 1329 &lease->addr, sizeof(lease->addr), MDL);
1076 isc_heap_delete(pool->active_timeouts, old_heap_index); 1330 isc_heap_delete(pool->active_timeouts, old_heap_index);
@@ -1458,53 +1712,53 @@ cleanup_old_expired(struct ipv6_pool *po @@ -1458,53 +1712,53 @@ cleanup_old_expired(struct ipv6_pool *po
1458static void 1712static void
1459lease_timeout_support(void *vpool) { 1713lease_timeout_support(void *vpool) {
1460 struct ipv6_pool *pool; 1714 struct ipv6_pool *pool;
1461 struct iasubopt *lease; 1715 struct iasubopt *lease;
1462  1716
1463 pool = (struct ipv6_pool *)vpool; 1717 pool = (struct ipv6_pool *)vpool;
1464 for (;;) { 1718 for (;;) {
1465 /* 1719 /*
1466 * Get the next lease scheduled to expire. 1720 * Get the next lease scheduled to expire.
1467 * 1721 *
1468 * Note that if there are no leases in the pool,  1722 * Note that if there are no leases in the pool,
1469 * expire_lease6() will return ISC_R_SUCCESS with  1723 * expire_lease6() will return ISC_R_SUCCESS with
1470 * a NULL lease. 1724 * a NULL lease.
 1725 *
 1726 * expire_lease6() will call move_lease_to_inactive() which
 1727 * calls ddns_removals() do we want that on the standard
 1728 * expiration timer or a special 'depref' timer? Original
 1729 * query from DH, moved here by SAR.
1471 */ 1730 */
1472 lease = NULL; 1731 lease = NULL;
1473 if (expire_lease6(&lease, pool, cur_time) != ISC_R_SUCCESS) { 1732 if (expire_lease6(&lease, pool, cur_time) != ISC_R_SUCCESS) {
1474 break; 1733 break;
1475 } 1734 }
1476 if (lease == NULL) { 1735 if (lease == NULL) {
1477 break; 1736 break;
1478 } 1737 }
1479 1738
1480 /* Look to see if there were ddns updates, and if 
1481 * so, drop them. 
1482 * 
1483 * DH: Do we want to do this on a special 'depref' 
1484 * timer rather than expiration timer? 
1485 */ 
1486#if defined (NSUPDATE) 
1487 if (pool->pool_type != D6O_IA_PD) { 
1488 ddns_removals(NULL, lease, NULL); 
1489 } 
1490#endif 
1491 
1492 write_ia(lease->ia); 1739 write_ia(lease->ia);
1493 1740
1494 iasubopt_dereference(&lease, MDL); 1741 iasubopt_dereference(&lease, MDL);
1495 } 1742 }
1496 1743
1497 /* 1744 /*
 1745 * If appropriate commit and rotate the lease file
 1746 * As commit_leases_timed() checks to see if we've done any writes
 1747 * we don't bother tracking if this function called write _ia
 1748 */
 1749 (void) commit_leases_timed();
 1750
 1751 /*
1498 * Do some cleanup of our expired leases. 1752 * Do some cleanup of our expired leases.
1499 */ 1753 */
1500 cleanup_old_expired(pool); 1754 cleanup_old_expired(pool);
1501 1755
1502 /* 1756 /*
1503 * Schedule next round of expirations. 1757 * Schedule next round of expirations.
1504 */ 1758 */
1505 schedule_lease_timeout(pool); 1759 schedule_lease_timeout(pool);
1506} 1760}
1507 1761
1508/* 1762/*
1509 * For a given pool, add a timer that will remove the next 1763 * For a given pool, add a timer that will remove the next
1510 * lease to expire. 1764 * lease to expire.
@@ -1683,29 +1937,28 @@ change_leases(struct ia_xx *ia,  @@ -1683,29 +1937,28 @@ change_leases(struct ia_xx *ia,
1683 renew_retval = change_func(pool, ia->iasubopt[i]); 1937 renew_retval = change_func(pool, ia->iasubopt[i]);
1684 if (renew_retval != ISC_R_SUCCESS) { 1938 if (renew_retval != ISC_R_SUCCESS) {
1685 retval = renew_retval; 1939 retval = renew_retval;
1686 } 1940 }
1687 } 1941 }
1688 /* XXXsk: should we warn if we don't find a pool? */ 1942 /* XXXsk: should we warn if we don't find a pool? */
1689 } 1943 }
1690 return retval; 1944 return retval;
1691} 1945}
1692 1946
1693/* 1947/*
1694 * Renew all leases in an IA from all pools. 1948 * Renew all leases in an IA from all pools.
1695 * 1949 *
1696 * The new hard_lifetime_end_time should be updated for the addresses/prefixes. 1950 * The new lifetime should be in the soft_lifetime_end_time
1697 * 1951 * and will be moved to hard_lifetime_end_time by renew_lease6.
1698 * WARNING: lease times must only be extended, never reduced!!! 
1699 */ 1952 */
1700isc_result_t  1953isc_result_t
1701renew_leases(struct ia_xx *ia) { 1954renew_leases(struct ia_xx *ia) {
1702 return change_leases(ia, renew_lease6); 1955 return change_leases(ia, renew_lease6);
1703} 1956}
1704 1957
1705/* 1958/*
1706 * Release all leases in an IA from all pools. 1959 * Release all leases in an IA from all pools.
1707 */ 1960 */
1708isc_result_t  1961isc_result_t
1709release_leases(struct ia_xx *ia) { 1962release_leases(struct ia_xx *ia) {
1710 return change_leases(ia, release_lease6); 1963 return change_leases(ia, release_lease6);
1711} 1964}
@@ -1883,675 +2136,14 @@ mark_interfaces_unavailable(void) { @@ -1883,675 +2136,14 @@ mark_interfaces_unavailable(void) {
1883 ipv6_pool_dereference(&p, MDL); 2136 ipv6_pool_dereference(&p, MDL);
1884 }  2137 }
1885 if (find_ipv6_pool(&p, D6O_IA_TA, &ip->v6addresses[i])  2138 if (find_ipv6_pool(&p, D6O_IA_TA, &ip->v6addresses[i])
1886 == ISC_R_SUCCESS) { 2139 == ISC_R_SUCCESS) {
1887 mark_lease_unavailable(p,  2140 mark_lease_unavailable(p,
1888 &ip->v6addresses[i]); 2141 &ip->v6addresses[i]);
1889 ipv6_pool_dereference(&p, MDL); 2142 ipv6_pool_dereference(&p, MDL);
1890 }  2143 }
1891 } 2144 }
1892 ip = ip->next; 2145 ip = ip->next;
1893 } 2146 }
1894} 2147}
1895 2148
1896 2149/* unittest moved to server/tests/mdb6_unittest.c */
1897#ifdef UNIT_TEST 
1898#include <stdlib.h> 
1899 
1900int  
1901main(int argc, char *argv[]) { 
1902 struct iasubopt *iaaddr; 
1903 struct iasubopt *iaaddr_copy; 
1904 u_int32_t iaid; 
1905 struct ia_xx *ia_na; 
1906 struct ia_xx *ia_na_copy; 
1907 int i; 
1908 struct in6_addr addr; 
1909 struct ipv6_pool *pool; 
1910 struct ipv6_pool *pool_copy; 
1911 char addr_buf[INET6_ADDRSTRLEN]; 
1912 char *uid; 
1913 struct data_string ds; 
1914 struct iasubopt *expired_iaaddr; 
1915 unsigned int attempts; 
1916 
1917 /* 
1918 * Test 0: Basic iaaddr manipulation. 
1919 */ 
1920 iaaddr = NULL; 
1921 if (iasubopt_allocate(&iaaddr, MDL) != ISC_R_SUCCESS) { 
1922 printf("ERROR: iasubopt_allocate() %s:%d\n", MDL); 
1923 return 1; 
1924 } 
1925 if (iaaddr->state != FTS_FREE) { 
1926 printf("ERROR: bad state %s:%d\n", MDL); 
1927 return 1; 
1928 } 
1929 if (iaaddr->heap_index != -1) { 
1930 printf("ERROR: bad heap_index %s:%d\n", MDL); 
1931 return 1; 
1932 } 
1933 iaaddr_copy = NULL; 
1934 if (iasubopt_reference(&iaaddr_copy, iaaddr, MDL) != ISC_R_SUCCESS) { 
1935 printf("ERROR: iasubopt_reference() %s:%d\n", MDL); 
1936 return 1; 
1937 } 
1938 if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) { 
1939 printf("ERROR: iasubopt_reference() %s:%d\n", MDL); 
1940 return 1; 
1941 } 
1942 if (iasubopt_dereference(&iaaddr_copy, MDL) != ISC_R_SUCCESS) { 
1943 printf("ERROR: iasubopt_reference() %s:%d\n", MDL); 
1944 return 1; 
1945 } 
1946 
1947 /*  
1948 * Test 1: Error iaaddr manipulation. 
1949 */ 
1950 /* bogus allocate arguments */ 
1951 if (iasubopt_allocate(NULL, MDL) != DHCP_R_INVALIDARG) { 
1952 printf("ERROR: iasubopt_allocate() %s:%d\n", MDL); 
1953 return 1; 
1954 } 
1955 iaaddr = (struct iasubopt *)1; 
1956 if (iasubopt_allocate(&iaaddr, MDL) != DHCP_R_INVALIDARG) { 
1957 printf("ERROR: iasubopt_allocate() %s:%d\n", MDL); 
1958 return 1; 
1959 } 
1960 
1961 /* bogus reference arguments */ 
1962 iaaddr = NULL; 
1963 if (iasubopt_allocate(&iaaddr, MDL) != ISC_R_SUCCESS) { 
1964 printf("ERROR: iasubopt_allocate() %s:%d\n", MDL); 
1965 return 1; 
1966 } 
1967 if (iasubopt_reference(NULL, iaaddr, MDL) != DHCP_R_INVALIDARG) { 
1968 printf("ERROR: iasubopt_reference() %s:%d\n", MDL); 
1969 return 1; 
1970 } 
1971 iaaddr_copy = (struct iasubopt *)1; 
1972 if (iasubopt_reference(&iaaddr_copy, iaaddr, 
1973 MDL) != DHCP_R_INVALIDARG) { 
1974 printf("ERROR: iasubopt_reference() %s:%d\n", MDL); 
1975 return 1; 
1976 } 
1977 iaaddr_copy = NULL; 
1978 if (iasubopt_reference(&iaaddr_copy, NULL, MDL) != DHCP_R_INVALIDARG) { 
1979 printf("ERROR: iasubopt_reference() %s:%d\n", MDL); 
1980 return 1; 
1981 } 
1982 if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) { 
1983 printf("ERROR: iasubopt_reference() %s:%d\n", MDL); 
1984 return 1; 
1985 } 
1986 
1987 /* bogus dereference arguments */ 
1988 if (iasubopt_dereference(NULL, MDL) != DHCP_R_INVALIDARG) { 
1989 printf("ERROR: iasubopt_dereference() %s:%d\n", MDL); 
1990 return 1; 
1991 } 
1992 iaaddr = NULL; 
1993 if (iasubopt_dereference(&iaaddr, MDL) != DHCP_R_INVALIDARG) { 
1994 printf("ERROR: iasubopt_dereference() %s:%d\n", MDL); 
1995 return 1; 
1996 } 
1997 
1998 /* 
1999 * Test 2: Basic ia_na manipulation. 
2000 */ 
2001 iaid = 666; 
2002 ia_na = NULL; 
2003 if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) { 
2004 printf("ERROR: ia_allocate() %s:%d\n", MDL); 
2005 return 1; 
2006 } 
2007 if (memcmp(ia_na->iaid_duid.data, &iaid, sizeof(iaid)) != 0) { 
2008 printf("ERROR: bad IAID_DUID %s:%d\n", MDL); 
2009 return 1; 
2010 } 
2011 if (memcmp(ia_na->iaid_duid.data+sizeof(iaid), "TestDUID", 8) != 0) { 
2012 printf("ERROR: bad IAID_DUID %s:%d\n", MDL); 
2013 return 1; 
2014 } 
2015 if (ia_na->num_iasubopt != 0) { 
2016 printf("ERROR: bad num_iasubopt %s:%d\n", MDL); 
2017 return 1; 
2018 } 
2019 ia_na_copy = NULL; 
2020 if (ia_reference(&ia_na_copy, ia_na, MDL) != ISC_R_SUCCESS) { 
2021 printf("ERROR: ia_reference() %s:%d\n", MDL); 
2022 return 1; 
2023 } 
2024 iaaddr = NULL; 
2025 if (iasubopt_allocate(&iaaddr, MDL) != ISC_R_SUCCESS) { 
2026 printf("ERROR: iasubopt_allocate() %s:%d\n", MDL); 
2027 return 1; 
2028 } 
2029 if (ia_add_iasubopt(ia_na, iaaddr, MDL) != ISC_R_SUCCESS) { 
2030 printf("ERROR: ia_add_iasubopt() %s:%d\n", MDL); 
2031 return 1; 
2032 } 
2033 ia_remove_iasubopt(ia_na, iaaddr, MDL); 
2034 if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) { 
2035 printf("ERROR: iasubopt_reference() %s:%d\n", MDL); 
2036 return 1; 
2037 } 
2038 if (ia_dereference(&ia_na, MDL) != ISC_R_SUCCESS) { 
2039 printf("ERROR: ia_dereference() %s:%d\n", MDL); 
2040 return 1; 
2041 } 
2042 if (ia_dereference(&ia_na_copy, MDL) != ISC_R_SUCCESS) { 
2043 printf("ERROR: ia_dereference() %s:%d\n", MDL); 
2044 return 1; 
2045 } 
2046 
2047 /*  
2048 * Test 3: lots of iaaddr in our ia_na 
2049 */ 
2050 
2051 /* lots of iaaddr that we delete */ 
2052 iaid = 666; 
2053 ia_na = NULL; 
2054 if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) { 
2055 printf("ERROR: ia_allocate() %s:%d\n", MDL); 
2056 return 1; 
2057 } 
2058 for (i=0; i<100; i++) { 
2059 iaaddr = NULL; 
2060 if (iasubopt_allocate(&iaaddr, MDL) != ISC_R_SUCCESS) { 
2061 printf("ERROR: iasubopt_allocate() %s:%d\n", MDL); 
2062 return 1; 
2063 } 
2064 if (ia_add_iasubopt(ia_na, iaaddr, MDL) != ISC_R_SUCCESS) { 
2065 printf("ERROR: ia_add_iasubopt() %s:%d\n", MDL); 
2066 return 1; 
2067 } 
2068 if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) { 
2069 printf("ERROR: iasubopt_reference() %s:%d\n", MDL); 
2070 return 1; 
2071 } 
2072 } 
2073 for (i=0; i<100; i++) { 
2074 iaaddr = ia_na->iasubopt[random() % ia_na->num_iasubopt]; 
2075 ia_remove_iasubopt(ia_na, iaaddr, MDL); 
2076 } 
2077 if (ia_dereference(&ia_na, MDL) != ISC_R_SUCCESS) { 
2078 printf("ERROR: ia_dereference() %s:%d\n", MDL); 
2079 return 1; 
2080 } 
2081 
2082 /* lots of iaaddr, let dereference cleanup */ 
2083 iaid = 666; 
2084 ia_na = NULL; 
2085 if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) { 
2086 printf("ERROR: ia_allocate() %s:%d\n", MDL); 
2087 return 1; 
2088 } 
2089 for (i=0; i<100; i++) { 
2090 iaaddr = NULL; 
2091 if (iasubopt_allocate(&iaaddr, MDL) != ISC_R_SUCCESS) { 
2092 printf("ERROR: iasubopt_allocate() %s:%d\n", MDL); 
2093 return 1; 
2094 } 
2095 if (ia_add_iasubopt(ia_na, iaaddr, MDL) != ISC_R_SUCCESS) { 
2096 printf("ERROR: ia_add_iasubopt() %s:%d\n", MDL); 
2097 return 1; 
2098 } 
2099 if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) { 
2100 printf("ERROR: iasubopt_reference() %s:%d\n", MDL); 
2101 return 1; 
2102 } 
2103 } 
2104 if (ia_dereference(&ia_na, MDL) != ISC_R_SUCCESS) { 
2105 printf("ERROR: ia_dereference() %s:%d\n", MDL); 
2106 return 1; 
2107 } 
2108 
2109 /* 
2110 * Test 4: Errors in ia_na. 
2111 */ 
2112 /* bogus allocate arguments */ 
2113 if (ia_allocate(NULL, 123, "", 0, MDL) != DHCP_R_INVALIDARG) { 
2114 printf("ERROR: ia_allocate() %s:%d\n", MDL); 
2115 return 1; 
2116 } 
2117 ia_na = (struct ia_na *)1; 
2118 if (ia_allocate(&ia_na, 456, "", 0, MDL) != DHCP_R_INVALIDARG) { 
2119 printf("ERROR: ia_allocate() %s:%d\n", MDL); 
2120 return 1; 
2121 } 
2122 
2123 /* bogus reference arguments */ 
2124 iaid = 666; 
2125 ia_na = NULL; 
2126 if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) { 
2127 printf("ERROR: ia_allocate() %s:%d\n", MDL); 
2128 return 1; 
2129 } 
2130 if (ia_reference(NULL, ia_na, MDL) != DHCP_R_INVALIDARG) { 
2131 printf("ERROR: ia_reference() %s:%d\n", MDL); 
2132 return 1; 
2133 } 
2134 ia_na_copy = (struct ia_na *)1; 
2135 if (ia_reference(&ia_na_copy, ia_na, MDL) != DHCP_R_INVALIDARG) { 
2136 printf("ERROR: ia_reference() %s:%d\n", MDL); 
2137 return 1; 
2138 } 
2139 ia_na_copy = NULL; 
2140 if (ia_reference(&ia_na_copy, NULL, MDL) != DHCP_R_INVALIDARG) { 
2141 printf("ERROR: ia_reference() %s:%d\n", MDL); 
2142 return 1; 
2143 } 
2144 if (ia_dereference(&ia_na, MDL) != ISC_R_SUCCESS) { 
2145 printf("ERROR: ia_dereference() %s:%d\n", MDL); 
2146 return 1; 
2147 } 
2148 
2149 /* bogus dereference arguments */ 
2150 if (ia_dereference(NULL, MDL) != DHCP_R_INVALIDARG) { 
2151 printf("ERROR: ia_dereference() %s:%d\n", MDL); 
2152 return 1; 
2153 } 
2154 
2155 /* bogus remove */ 
2156 iaid = 666; 
2157 ia_na = NULL; 
2158 if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) { 
2159 printf("ERROR: ia_allocate() %s:%d\n", MDL); 
2160 return 1; 
2161 } 
2162 ia_remove_iasubopt(ia_na, NULL, MDL); 
2163 if (ia_dereference(&ia_na, MDL) != ISC_R_SUCCESS) { 
2164 printf("ERROR: ia_dereference() %s:%d\n", MDL); 
2165 return 1; 
2166 } 
2167 
2168 /* 
2169 * Test 5: Basic ipv6_pool manipulation. 
2170 */ 
2171 
2172 /* allocate, reference */ 
2173 inet_pton(AF_INET6, "1:2:3:4::", &addr); 
2174 pool = NULL; 
2175 if (ipv6_pool_allocate(&pool, 0, &addr, 64, 128, MDL) != ISC_R_SUCCESS) { 
2176 printf("ERROR: ipv6_pool_allocate() %s:%d\n", MDL); 
2177 return 1; 
2178 } 
2179 if (pool->num_active != 0) { 
2180 printf("ERROR: bad num_active %s:%d\n", MDL); 
2181 return 1; 
2182 } 
2183 if (pool->bits != 64) { 
2184 printf("ERROR: bad bits %s:%d\n", MDL); 
2185 return 1; 
2186 } 
2187 inet_ntop(AF_INET6, &pool->start_addr, addr_buf, sizeof(addr_buf)); 
2188 if (strcmp(inet_ntop(AF_INET6, &pool->start_addr, addr_buf,  
2189 sizeof(addr_buf)), "1:2:3:4::") != 0) { 
2190 printf("ERROR: bad start_addr %s:%d\n", MDL); 
2191 return 1; 
2192 } 
2193 pool_copy = NULL; 
2194 if (ipv6_pool_reference(&pool_copy, pool, MDL) != ISC_R_SUCCESS) { 
2195 printf("ERROR: ipv6_pool_reference() %s:%d\n", MDL); 
2196 return 1; 
2197 } 
2198 
2199 /* create_lease6, renew_lease6, expire_lease6 */ 
2200 uid = "client0"; 
2201 memset(&ds, 0, sizeof(ds)); 
2202 ds.len = strlen(uid); 
2203 if (!buffer_allocate(&ds.buffer, ds.len, MDL)) { 
2204 printf("Out of memory\n"); 
2205 return 1; 
2206 } 
2207 ds.data = ds.buffer->data; 
2208 memcpy((char *)ds.data, uid, ds.len); 
2209 if (create_lease6(pool, &iaaddr,  
2210 &attempts, &ds, 1) != ISC_R_SUCCESS) { 
2211 printf("ERROR: create_lease6() %s:%d\n", MDL); 
2212 return 1; 
2213 } 
2214 if (pool->num_inactive != 1) { 
2215 printf("ERROR: bad num_inactive %s:%d\n", MDL); 
2216 return 1; 
2217 } 
2218 if (renew_lease6(pool, iaaddr) != ISC_R_SUCCESS) { 
2219 printf("ERROR: renew_lease6() %s:%d\n", MDL); 
2220 return 1; 
2221 } 
2222 if (pool->num_active != 1) { 
2223 printf("ERROR: bad num_active %s:%d\n", MDL); 
2224 return 1; 
2225 } 
2226 expired_iaaddr = NULL; 
2227 if (expire_lease6(&expired_iaaddr, pool, 0) != ISC_R_SUCCESS) { 
2228 printf("ERROR: expire_lease6() %s:%d\n", MDL); 
2229 return 1; 
2230 } 
2231 if (expired_iaaddr != NULL) { 
2232 printf("ERROR: should not have expired a lease %s:%d\n", MDL); 
2233 return 1; 
2234 } 
2235 if (pool->num_active != 1) { 
2236 printf("ERROR: bad num_active %s:%d\n", MDL); 
2237 return 1; 
2238 } 
2239 if (expire_lease6(&expired_iaaddr, pool, 1000) != ISC_R_SUCCESS) { 
2240 printf("ERROR: expire_lease6() %s:%d\n", MDL); 
2241 return 1; 
2242 } 
2243 if (expired_iaaddr == NULL) { 
2244 printf("ERROR: should have expired a lease %s:%d\n", MDL); 
2245 return 1; 
2246 } 
2247 if (iasubopt_dereference(&expired_iaaddr, MDL) != ISC_R_SUCCESS) { 
2248 printf("ERROR: iasubopt_dereference() %s:%d\n", MDL); 
2249 return 1; 
2250 } 
2251 if (pool->num_active != 0) { 
2252 printf("ERROR: bad num_active %s:%d\n", MDL); 
2253 return 1; 
2254 } 
2255 if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) { 
2256 printf("ERROR: iasubopt_dereference() %s:%d\n", MDL); 
2257 return 1; 
2258 } 
2259 
2260 /* release_lease6, decline_lease6 */ 
2261 if (create_lease6(pool, &iaaddr, &attempts,  
2262 &ds, 1) != ISC_R_SUCCESS) { 
2263 printf("ERROR: create_lease6() %s:%d\n", MDL); 
2264 return 1; 
2265 } 
2266 if (renew_lease6(pool, iaaddr) != ISC_R_SUCCESS) { 
2267 printf("ERROR: renew_lease6() %s:%d\n", MDL); 
2268 return 1; 
2269 } 
2270 if (pool->num_active != 1) { 
2271 printf("ERROR: bad num_active %s:%d\n", MDL); 
2272 return 1; 
2273 } 
2274 if (release_lease6(pool, iaaddr) != ISC_R_SUCCESS) { 
2275 printf("ERROR: decline_lease6() %s:%d\n", MDL); 
2276 return 1; 
2277 } 
2278 if (pool->num_active != 0) { 
2279 printf("ERROR: bad num_active %s:%d\n", MDL); 
2280 return 1; 
2281 } 
2282 if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) { 
2283 printf("ERROR: iasubopt_dereference() %s:%d\n", MDL); 
2284 return 1; 
2285 } 
2286 if (create_lease6(pool, &iaaddr, &attempts,  
2287 &ds, 1) != ISC_R_SUCCESS) { 
2288 printf("ERROR: create_lease6() %s:%d\n", MDL); 
2289 return 1; 
2290 } 
2291 if (renew_lease6(pool, iaaddr) != ISC_R_SUCCESS) { 
2292 printf("ERROR: renew_lease6() %s:%d\n", MDL); 
2293 return 1; 
2294 } 
2295 if (pool->num_active != 1) { 
2296 printf("ERROR: bad num_active %s:%d\n", MDL); 
2297 return 1; 
2298 } 
2299 if (decline_lease6(pool, iaaddr) != ISC_R_SUCCESS) { 
2300 printf("ERROR: decline_lease6() %s:%d\n", MDL); 
2301 return 1; 
2302 } 
2303 if (pool->num_active != 1) { 
2304 printf("ERROR: bad num_active %s:%d\n", MDL); 
2305 return 1; 
2306 } 
2307 if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) { 
2308 printf("ERROR: iasubopt_dereference() %s:%d\n", MDL); 
2309 return 1; 
2310 } 
2311 
2312 /* dereference */ 
2313 if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) { 
2314 printf("ERROR: ipv6_pool_reference() %s:%d\n", MDL); 
2315 return 1; 
2316 } 
2317 if (ipv6_pool_dereference(&pool_copy, MDL) != ISC_R_SUCCESS) { 
2318 printf("ERROR: ipv6_pool_reference() %s:%d\n", MDL); 
2319 return 1; 
2320 } 
2321 
2322 /* 
2323 * Test 6: Error ipv6_pool manipulation 
2324 */ 
2325 if (ipv6_pool_allocate(NULL, 0, &addr, 
2326 64, 128, MDL) != DHCP_R_INVALIDARG) { 
2327 printf("ERROR: ipv6_pool_allocate() %s:%d\n", MDL); 
2328 return 1; 
2329 } 
2330 pool = (struct ipv6_pool *)1; 
2331 if (ipv6_pool_allocate(&pool, 0, &addr, 
2332 64, 128, MDL) != DHCP_R_INVALIDARG) { 
2333 printf("ERROR: ipv6_pool_allocate() %s:%d\n", MDL); 
2334 return 1; 
2335 } 
2336 if (ipv6_pool_reference(NULL, pool, MDL) != DHCP_R_INVALIDARG) { 
2337 printf("ERROR: ipv6_pool_reference() %s:%d\n", MDL); 
2338 return 1; 
2339 } 
2340 pool_copy = (struct ipv6_pool *)1; 
2341 if (ipv6_pool_reference(&pool_copy, pool, MDL) != DHCP_R_INVALIDARG) { 
2342 printf("ERROR: ipv6_pool_reference() %s:%d\n", MDL); 
2343 return 1; 
2344 } 
2345 pool_copy = NULL; 
2346 if (ipv6_pool_reference(&pool_copy, NULL, MDL) != DHCP_R_INVALIDARG) { 
2347 printf("ERROR: ipv6_pool_reference() %s:%d\n", MDL); 
2348 return 1; 
2349 } 
2350 if (ipv6_pool_dereference(NULL, MDL) != DHCP_R_INVALIDARG) { 
2351 printf("ERROR: ipv6_pool_dereference() %s:%d\n", MDL); 
2352 return 1; 
2353 } 
2354 if (ipv6_pool_dereference(&pool_copy, MDL) != DHCP_R_INVALIDARG) { 
2355 printf("ERROR: ipv6_pool_dereference() %s:%d\n", MDL); 
2356 return 1; 
2357 } 
2358 
2359 /* 
2360 * Test 7: order of expiration 
2361 */ 
2362 pool = NULL; 
2363 if (ipv6_pool_allocate(&pool, 0, &addr, 64, 128, MDL) != ISC_R_SUCCESS) { 
2364 printf("ERROR: ipv6_pool_allocate() %s:%d\n", MDL); 
2365 return 1; 
2366 } 
2367 for (i=10; i<100; i+=10) { 
2368 if (create_lease6(pool, &iaaddr, &attempts, 
2369 &ds, i) != ISC_R_SUCCESS) { 
2370 printf("ERROR: create_lease6() %s:%d\n", MDL); 
2371 return 1; 
2372 } 
2373 if (renew_lease6(pool, iaaddr) != ISC_R_SUCCESS) { 
2374 printf("ERROR: renew_lease6() %s:%d\n", MDL); 
2375 return 1; 
2376 } 
2377 if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) { 
2378 printf("ERROR: iasubopt_dereference() %s:%d\n", MDL); 
2379 return 1; 
2380 } 
2381 if (pool->num_active != (i / 10)) { 
2382 printf("ERROR: bad num_active %s:%d\n", MDL); 
2383 return 1; 
2384 } 
2385 } 
2386 if (pool->num_active != 9) { 
2387 printf("ERROR: bad num_active %s:%d\n", MDL); 
2388 return 1; 
2389 } 
2390 for (i=10; i<100; i+=10) { 
2391 if (expire_lease6(&expired_iaaddr,  
2392 pool, 1000) != ISC_R_SUCCESS) { 
2393 printf("ERROR: expire_lease6() %s:%d\n", MDL); 
2394 return 1; 
2395 } 
2396 if (expired_iaaddr == NULL) { 
2397 printf("ERROR: should have expired a lease %s:%d\n",  
2398 MDL); 
2399 return 1; 
2400 } 
2401 if (pool->num_active != (9 - (i / 10))) { 
2402 printf("ERROR: bad num_active %s:%d\n", MDL); 
2403 return 1; 
2404 } 
2405 if (expired_iaaddr->hard_lifetime_end_time != i) { 
2406 printf("ERROR: bad hard_lifetime_end_time %s:%d\n",  
2407 MDL); 
2408 return 1; 
2409 } 
2410 if (iasubopt_dereference(&expired_iaaddr, MDL) != 
2411 ISC_R_SUCCESS) { 
2412 printf("ERROR: iasubopt_dereference() %s:%d\n", MDL); 
2413 return 1; 
2414 } 
2415 } 
2416 if (pool->num_active != 0) { 
2417 printf("ERROR: bad num_active %s:%d\n", MDL); 
2418 return 1; 
2419 } 
2420 expired_iaaddr = NULL; 
2421 if (expire_lease6(&expired_iaaddr, pool, 1000) != ISC_R_SUCCESS) { 
2422 printf("ERROR: expire_lease6() %s:%d\n", MDL); 
2423 return 1; 
2424 } 
2425 if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) { 
2426 printf("ERROR: ipv6_pool_dereference() %s:%d\n", MDL); 
2427 return 1; 
2428 } 
2429 
2430 /* 
2431 * Test 8: small pool 
2432 */ 
2433 pool = NULL; 
2434 addr.s6_addr[14] = 0x81; 
2435 if (ipv6_pool_allocate(&pool, 0, &addr, 127, 128, MDL) != ISC_R_SUCCESS) { 
2436 printf("ERROR: ipv6_pool_allocate() %s:%d\n", MDL); 
2437 return 1; 
2438 } 
2439 if (create_lease6(pool, &iaaddr, &attempts,  
2440 &ds, 42) != ISC_R_SUCCESS) { 
2441 printf("ERROR: create_lease6() %s:%d\n", MDL); 
2442 return 1; 
2443 } 
2444 if (renew_lease6(pool, iaaddr) != ISC_R_SUCCESS) { 
2445 printf("ERROR: renew_lease6() %s:%d\n", MDL); 
2446 return 1; 
2447 } 
2448 if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) { 
2449 printf("ERROR: iasubopt_dereference() %s:%d\n", MDL); 
2450 return 1; 
2451 } 
2452 if (create_lease6(pool, &iaaddr, &attempts,  
2453 &ds, 11) != ISC_R_SUCCESS) { 
2454 printf("ERROR: create_lease6() %s:%d\n", MDL); 
2455 return 1; 
2456 } 
2457 if (renew_lease6(pool, iaaddr) != ISC_R_SUCCESS) { 
2458 printf("ERROR: renew_lease6() %s:%d\n", MDL); 
2459 return 1; 
2460 } 
2461 if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) { 
2462 printf("ERROR: iasubopt_dereference() %s:%d\n", MDL); 
2463 return 1; 
2464 } 
2465 if (create_lease6(pool, &iaaddr, &attempts,  
2466 &ds, 11) != ISC_R_NORESOURCES) { 
2467 printf("ERROR: create_lease6() %s:%d\n", MDL); 
2468 return 1; 
2469 } 
2470 if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) { 
2471 printf("ERROR: ipv6_pool_dereference() %s:%d\n", MDL); 
2472 return 1; 
2473 } 
2474 addr.s6_addr[14] = 0; 
2475 
2476 /*  
2477 * Test 9: functions across all pools 
2478 */ 
2479 pool = NULL; 
2480 if (ipv6_pool_allocate(&pool, 0, &addr, 64, 128, MDL) != ISC_R_SUCCESS) { 
2481 printf("ERROR: ipv6_pool_allocate() %s:%d\n", MDL); 
2482 return 1; 
2483 } 
2484 if (add_ipv6_pool(pool) != ISC_R_SUCCESS) { 
2485 printf("ERROR: add_ipv6_pool() %s:%d\n", MDL); 
2486 return 1; 
2487 } 
2488 if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) { 
2489 printf("ERROR: ipv6_pool_dereference() %s:%d\n", MDL); 
2490 return 1; 
2491 } 
2492 pool = NULL; 
2493 if (find_ipv6_pool(&pool, 0, &addr) != ISC_R_SUCCESS) { 
2494 printf("ERROR: find_ipv6_pool() %s:%d\n", MDL); 
2495 return 1; 
2496 } 
2497 if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) { 
2498 printf("ERROR: ipv6_pool_dereference() %s:%d\n", MDL); 
2499 return 1; 
2500 } 
2501 inet_pton(AF_INET6, "1:2:3:4:ffff:ffff:ffff:ffff", &addr); 
2502 pool = NULL; 
2503 if (find_ipv6_pool(&pool, 0, &addr) != ISC_R_SUCCESS) { 
2504 printf("ERROR: find_ipv6_pool() %s:%d\n", MDL); 
2505 return 1; 
2506 } 
2507 if (ipv6_pool_dereference(&pool, MDL) != ISC_R_SUCCESS) { 
2508 printf("ERROR: ipv6_pool_dereference() %s:%d\n", MDL); 
2509 return 1; 
2510 } 
2511 inet_pton(AF_INET6, "1:2:3:5::", &addr); 
2512 pool = NULL; 
2513 if (find_ipv6_pool(&pool, 0, &addr) != ISC_R_NOTFOUND) { 
2514 printf("ERROR: find_ipv6_pool() %s:%d\n", MDL); 
2515 return 1; 
2516 } 
2517 inet_pton(AF_INET6, "1:2:3:3:ffff:ffff:ffff:ffff", &addr); 
2518 pool = NULL; 
2519 if (find_ipv6_pool(&pool, 0, &addr) != ISC_R_NOTFOUND) { 
2520 printf("ERROR: find_ipv6_pool() %s:%d\n", MDL); 
2521 return 1; 
2522 } 
2523 
2524/* iaid = 666; 
2525 ia_na = NULL; 
2526 if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) { 
2527 printf("ERROR: ia_allocate() %s:%d\n", MDL); 
2528 return 1; 
2529 }*/ 
2530 
2531 { 
2532 struct in6_addr r; 
2533 struct data_string ds; 
2534 u_char data[16]; 
2535 char buf[64]; 
2536 int i, j; 
2537 
2538 memset(&ds, 0, sizeof(ds)); 
2539 memset(data, 0xaa, sizeof(data)); 
2540 ds.len = 16; 
2541 ds.data = data; 
2542 
2543 inet_pton(AF_INET6, "3ffe:501:ffff:100::", &addr); 
2544 for (i = 32; i < 42; i++) 
2545 for (j = i + 1; j < 49; j++) { 
2546 memset(&r, 0, sizeof(r)); 
2547 memset(buf, 0, 64); 
2548 build_prefix6(&r, &addr, i, j, &ds); 
2549 inet_ntop(AF_INET6, &r, buf, 64); 
2550 printf("%d,%d-> %s/%d\n", i, j, buf, j); 
2551 } 
2552 } 
2553  
2554 printf("SUCCESS: all tests passed (ignore any warning messages)\n"); 
2555 return 0; 
2556} 
2557#endif 

File Deleted: src/external/bsd/dhcp/dist/server/Attic/dhcpd.conf

cvs diff -r1.1 -r1.2 src/external/bsd/dhcp/include/Attic/config.h (expand / switch to unified diff)

--- src/external/bsd/dhcp/include/Attic/config.h 2013/03/24 15:54:31 1.1
+++ src/external/bsd/dhcp/include/Attic/config.h 2013/03/24 23:03:07 1.2
@@ -3,51 +3,51 @@ @@ -3,51 +3,51 @@
3 3
4/* Define to compile debug-only DHCP software. */ 4/* Define to compile debug-only DHCP software. */
5/* #undef DEBUG */ 5/* #undef DEBUG */
6 6
7/* Define to queue multiple DHCPACK replies per fsync. */ 7/* Define to queue multiple DHCPACK replies per fsync. */
8/* #undef DELAYED_ACK */ 8/* #undef DELAYED_ACK */
9 9
10/* Define to BIG_ENDIAN for MSB (Motorola or SPARC CPUs) or LITTLE_ENDIAN for 10/* Define to BIG_ENDIAN for MSB (Motorola or SPARC CPUs) or LITTLE_ENDIAN for
11 LSB (Intel CPUs). */ 11 LSB (Intel CPUs). */
12#include <sys/endian.h> 12#include <sys/endian.h>
13#define DHCP_BYTE_ORDER _BYTE_ORDER 13#define DHCP_BYTE_ORDER _BYTE_ORDER
14 14
15#if 0 15#if 0
16/* Define to 1 to include DHCPv6 support. */ 
17/* From the Makefile */ 16/* From the Makefile */
 17/* Define to 1 to include DHCPv6 support. */
18#define DHCPv6 1 18#define DHCPv6 1
19#endif 19#endif
20 20
21/* Define to any value to chroot() prior to loading config. */ 21/* Define to any value to chroot() prior to loading config. */
22/* #undef EARLY_CHROOT */ 22/* #undef EARLY_CHROOT */
23 23
24/* Define to include execute() config language support. */ 24/* Define to include execute() config language support. */
25#define ENABLE_EXECUTE 1 25#define ENABLE_EXECUTE 1
26 26
27/* Define to include Failover Protocol support. */ 27/* Define to include Failover Protocol support. */
28#define FAILOVER_PROTOCOL 1 28#define FAILOVER_PROTOCOL 1
29 29
30/* Define to nothing if C supports flexible array members, and to 1 if it does 30/* Define to nothing if C supports flexible array members, and to 1 if it does
31 not. That way, with a declaration like `struct s { int n; double 31 not. That way, with a declaration like `struct s { int n; double
32 d[FLEXIBLE_ARRAY_MEMBER]; };', the struct hack can be used with pre-C99 32 d[FLEXIBLE_ARRAY_MEMBER]; };', the struct hack can be used with pre-C99
33 compilers. When computing the size of such an object, don't use 'sizeof 33 compilers. When computing the size of such an object, don't use 'sizeof
34 (struct s)' as it overestimates the size. Use 'offsetof (struct s, d)' 34 (struct s)' as it overestimates the size. Use 'offsetof (struct s, d)'
35 instead. Don't use 'offsetof (struct s, d[0])', as this doesn't work with 35 instead. Don't use 'offsetof (struct s, d[0])', as this doesn't work with
36 MSVC and with C++ compilers. */ 36 MSVC and with C++ compilers. */
37#define FLEXIBLE_ARRAY_MEMBER  37#define FLEXIBLE_ARRAY_MEMBER
38 38
39/* Define to 1 to use the Berkeley Packet Filter interface code. */ 39/* Define to 1 to use the Berkeley Packet Filter interface code. */
40#define HAVE_BPF "" 40#define HAVE_BPF 1
41 41
42/* Define to 1 if you have the /dev/random file. */ 42/* Define to 1 if you have the /dev/random file. */
43#define HAVE_DEV_RANDOM 1 43#define HAVE_DEV_RANDOM 1
44 44
45/* Define to 1 to use DLPI interface code. */ 45/* Define to 1 to use DLPI interface code. */
46/* #undef HAVE_DLPI */ 46/* #undef HAVE_DLPI */
47 47
48/* Define to 1 if you have the <ifaddrs.h> header file. */ 48/* Define to 1 if you have the <ifaddrs.h> header file. */
49#define HAVE_IFADDRS_H 1 49#define HAVE_IFADDRS_H 1
50 50
51/* Define to 1 if you have the <inttypes.h> header file. */ 51/* Define to 1 if you have the <inttypes.h> header file. */
52#define HAVE_INTTYPES_H 1 52#define HAVE_INTTYPES_H 1
53 53
@@ -86,76 +86,82 @@ @@ -86,76 +86,82 @@
86 86
87/* Define to 1 if you have the <sys/socket.h> header file. */ 87/* Define to 1 if you have the <sys/socket.h> header file. */
88#define HAVE_SYS_SOCKET_H 1 88#define HAVE_SYS_SOCKET_H 1
89 89
90/* Define to 1 if you have the <sys/stat.h> header file. */ 90/* Define to 1 if you have the <sys/stat.h> header file. */
91#define HAVE_SYS_STAT_H 1 91#define HAVE_SYS_STAT_H 1
92 92
93/* Define to 1 if you have the <sys/types.h> header file. */ 93/* Define to 1 if you have the <sys/types.h> header file. */
94#define HAVE_SYS_TYPES_H 1 94#define HAVE_SYS_TYPES_H 1
95 95
96/* Define to 1 if you have the <unistd.h> header file. */ 96/* Define to 1 if you have the <unistd.h> header file. */
97#define HAVE_UNISTD_H 1 97#define HAVE_UNISTD_H 1
98 98
 99/* Define to the string for a noreturn attribute. */
 100#define ISC_DHCP_NORETURN __attribute__((noreturn))
 101
99/* Define to 1 if the system has 'struct if_laddrconf'. */ 102/* Define to 1 if the system has 'struct if_laddrconf'. */
100/* #undef ISC_PLATFORM_HAVEIF_LADDRCONF */ 103/* #undef ISC_PLATFORM_HAVEIF_LADDRCONF */
101 104
102/* Define to 1 if the system has 'struct if_laddrreq'. */ 105/* Define to 1 if the system has 'struct if_laddrreq'. */
103/* #undef ISC_PLATFORM_HAVEIF_LADDRREQ */ 106/* #undef ISC_PLATFORM_HAVEIF_LADDRREQ */
104 107
105/* Define to 1 if the system has 'struct lifnum'. */ 108/* Define to 1 if the system has 'struct lifnum'. */
106/* #undef ISC_PLATFORM_HAVELIFNUM */ 109/* #undef ISC_PLATFORM_HAVELIFNUM */
107 110
108/* Define to 1 if the inet_aton() function is missing. */ 111/* Define to 1 if the inet_aton() function is missing. */
109/* #undef NEED_INET_ATON */ 112/* #undef NEED_INET_ATON */
110 113
111/* Name of package */ 114/* Name of package */
112#define PACKAGE "dhcp" 115#define PACKAGE "dhcp"
113 116
114/* Define to the address where bug reports for this package should be sent. */ 117/* Define to the address where bug reports for this package should be sent. */
115#define PACKAGE_BUGREPORT "dhcp-users@isc.org" 118#define PACKAGE_BUGREPORT "dhcp-users@isc.org"
116 119
117/* Define to the full name of this package. */ 120/* Define to the full name of this package. */
118#define PACKAGE_NAME "DHCP" 121#define PACKAGE_NAME "DHCP"
119 122
120/* Define to the full name and version of this package. */ 123/* Define to the full name and version of this package. */
121#define PACKAGE_STRING "DHCP 4.2.3" 124#define PACKAGE_STRING "DHCP 4.2.5"
122 125
123/* Define to the one symbol short name of this package. */ 126/* Define to the one symbol short name of this package. */
124#define PACKAGE_TARNAME "dhcp" 127#define PACKAGE_TARNAME "dhcp"
125 128
126/* Define to the version of this package. */ 129/* Define to the version of this package. */
127#define PACKAGE_VERSION "4.2.3" 130#define PACKAGE_VERSION "4.2.5"
128 131
129/* Define to any value to include Ari's PARANOIA patch. */ 132/* Define to any value to include Ari's PARANOIA patch. */
130/* #undef PARANOIA */ 133/* #undef PARANOIA */
131 134
 135/* Define to correct bad byteorders in secs field. */
 136/* #undef SECS_BYTEORDER */
 137
132/* The size of `struct iaddr *', as computed by sizeof. */ 138/* The size of `struct iaddr *', as computed by sizeof. */
133#define SIZEOF_STRUCT_IADDR_P 8 139#define SIZEOF_STRUCT_IADDR_P 8
134 140
135/* Define to 1 if you have the ANSI C header files. */ 141/* Define to 1 if you have the ANSI C header files. */
136#define STDC_HEADERS 1 142#define STDC_HEADERS 1
137 143
138/* Define to include server activity tracing support. */ 144/* Define to include server activity tracing support. */
139#define TRACING 1 145#define TRACING 1
140 146
141/* Define to 1 to use the standard BSD socket API. */ 147/* Define to 1 to use the standard BSD socket API. */
142/* #undef USE_SOCKETS */ 148/* #undef USE_SOCKETS */
143 149
144/* Define to 1 to enable IPv4 packet info support. */ 150/* Define to 1 to enable IPv4 packet info support. */
145/* #undef USE_V4_PKTINFO */ 151/* #undef USE_V4_PKTINFO */
146 152
147/* Version number of package */ 153/* Version number of package */
148#define VERSION "4.2.3" 154#define VERSION "4.2.5"
149 155
150/* Define to 1 if on AIX 3. 156/* Define to 1 if on AIX 3.
151 System headers sometimes define this. 157 System headers sometimes define this.
152 We just want to avoid a redefinition error message. */ 158 We just want to avoid a redefinition error message. */
153#ifndef _ALL_SOURCE 159#ifndef _ALL_SOURCE
154/* # undef _ALL_SOURCE */ 160/* # undef _ALL_SOURCE */
155#endif 161#endif
156 162
157/* Enable GNU extensions on systems that have them. */ 163/* Enable GNU extensions on systems that have them. */
158#ifndef _GNU_SOURCE 164#ifndef _GNU_SOURCE
159# define _GNU_SOURCE 1 165# define _GNU_SOURCE 1
160#endif 166#endif
161 167