bound.c revision dc041e83f8b943874ea814b873eaa8ee53498cf2
198N/A * The contents of this file are subject to the terms of the 198N/A * Common Development and Distribution License (the "License"). 198N/A * You may not use this file except in compliance with the License. 198N/A * See the License for the specific language governing permissions 198N/A * and limitations under the License. 198N/A * When distributing Covered Code, include this CDDL HEADER in each 198N/A * If applicable, add the following below this CDDL HEADER, with the 198N/A * fields enclosed by brackets "[]" replaced with your own identifying 198N/A * information: Portions Copyright [yyyy] [name of copyright owner] 198N/A * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 198N/A * Use is subject to license terms. 198N/A * BOUND state of the DHCP client state machine. 198N/A#
pragma ident "%Z%%M% %I% %E% SMI" 379N/A * bound_event_cb(): callback for script_start on the event EVENT_BOUND 379N/A * input: struct ifslist *: the interface configured 379N/A * output: int: always 1 198N/A * dhcp_bound(): configures an interface and ifs using information contained 198N/A * in the ACK packet and sets up lease timers. before starting, 198N/A * the requested address is arped to make sure it's not in use. 198N/A * input: struct ifslist *: the interface to move to bound 198N/A * PKT_LIST *: the ACK packet, or NULL if it should use ifsp->if_ack 198N/A * output: int: 0 on failure, 1 on success 379N/A const char *
noext =
"lease renewed but time not extended";
379N/A /* If ack we're replacing is not the original, then free it */ 379N/A /* Save the first ack as the original */ 198N/A * if we're adopting an interface, the lease timers 198N/A * only provide an upper bound since we don't know 198N/A * from what time they are relative to. assume we 198N/A * have a lease time of at most DHCP_ADOPT_LEASE_MAX. 198N/A * we have no idea when the REQUEST that generated 198N/A * this ACK was sent, but for diagnostic purposes 198N/A * we'll assume its close to the current time. * We will continue configuring this interface via * dhcp_bound_complete, once kernel DAD completes. /* This is just a duplicate ack; silently ignore it */ * if the current lease is mysteriously close to the new * lease, warn the user. unless there's less than a minute * left, round to the closest minute. /* something is really bizarre... */ * remove any stale hostconf file that might be lying around for * this interface. (in general, it's harmless, since we'll write a * fresh one when we exit anyway, but just to reduce confusion..) * dhcp_bound_complete(): complete interface configuration after DAD * input: struct ifslist *: the interface to configure * if the state is ADOPTING, event loop has not been started * at this time; so don't run the EVENT_BOUND script. * configure_timers(): configures the lease timers on an interface * input: struct ifslist *: the interface to configure (with a valid if_ack) * output: int: 1 on success, 0 on failure * type has already been verified as ACK. if type is not set, * then we got a BOOTP packet. we now fetch the t1, t2, and * lease options out of the packet into variables. they are * returned as relative host-byte-ordered times. * according to RFC2131, there is no minimum lease time, but don't * set up renew/rebind timers if lease is shorter than DHCP_REBIND_MIN. * configure_if(): configures an interface with DHCP parameters from an ACK * input: struct ifslist *: the interface to configure (with a valid if_ack) * output: int: 1 on success, 0 on failure * if we're using DHCP, then we'll have a valid CD_SERVER_ID * (we checked in dhcp_acknak()); set it now so that * ifsp->if_server is valid in case we need to send_decline(). * note that we use comparisons against opts[CD_DHCP_TYPE] * since we haven't set DHCP_IF_BOOTP yet (we don't do that * until we're sure we want the offered address.) * bring the interface online. note that there is no optimal * order here: it is considered bad taste (and in > solaris 7, * likely illegal) to bring an interface up before it has an * ip address. however, due to an apparent bug in sun fddi * 5.0, fddi will not obtain a network routing entry unless * the interface is brought up before it has an ip address. * we take the lesser of the two evils; if fddi customers have * problems, they can get a newer fddi distribution which /* LINTED [ifr_addr is a sockaddr which will be aligned] */ "mask length is %d instead of %d, ignoring",
* no legitimate IP subnet mask specified.. use best * guess. recall that if_addr is in network order, so * imagine it's 0x11223344: then when it is read into * a register on x86, it becomes 0x44332211, so we * must ntohl() it to convert it to 0x11223344 in else /* must be class d */ "broadcast address length is %d instead of %d, " * no legitimate IP broadcast specified. compute it * from the IP address and netmask. * the kernel will set the broadcast address for us as part of * bringing the interface up. since experience has shown that dhcp * servers sometimes provide a bogus broadcast address, we let the * kernel set it so that it's guaranteed to be correct. * also, note any inconsistencies and save the broadcast address the * kernel set so that we can watch for changes to it. * configure_bound(): configures routing with DHCP parameters from an ACK, * and sets up the if_sock_ip_fd socket used for lease * input: struct ifslist *: the interface to configure (with a valid if_ack) * output: int: 1 on success, 0 on failure * add each provided router; we'll clean them up when the * interface goes away or when our lease expires. "default router list, ignoring default routers");
* we wait until here to bind if_sock_fd because it turns out * the kernel has difficulties doing binds before interfaces * are up (although it may work sometimes, it doesn't work all * the time.) that's okay, because we don't use if_sock_fd * for receiving data until we're BOUND anyway. * we'll be using if_sock_fd for the remainder of the lease;