select.c revision 948f2876ce2a3010558f4f6937e16086ebcd36f2
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * CDDL HEADER START
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * The contents of this file are subject to the terms of the
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Common Development and Distribution License (the "License").
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * You may not use this file except in compliance with the License.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * See the License for the specific language governing permissions
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * and limitations under the License.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * When distributing Covered Code, include this CDDL HEADER in each
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * If applicable, add the following below this CDDL HEADER, with the
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * fields enclosed by brackets "[]" replaced with your own identifying
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * information: Portions Copyright [yyyy] [name of copyright owner]
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * CDDL HEADER END
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Use is subject to license terms.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * SELECTING state of the client state machine.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#pragma ident "%Z%%M% %I% %E% SMI"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * dhcp_start(): starts DHCP on a state machine
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * input: iu_tq_t *: unused
724365f7556fc4201fdb11766ebc6bd918523130sethg * void *: the state machine on which to start DHCP
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * output: void
724365f7556fc4201fdb11766ebc6bd918523130sethg/* ARGSUSED */
724365f7556fc4201fdb11766ebc6bd918523130sethg dhcpmsg(MSG_VERBOSE, "starting DHCP on %s", dsmp->dsm_name);
724365f7556fc4201fdb11766ebc6bd918523130sethg * set_start_timer(): sets a random timer to start a DHCP state machine
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * input: dhcp_smach_t *: the state machine on which to start DHCP
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * output: boolean_t: B_TRUE if a timer is now running
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * dhcp_selecting(): sends a DISCOVER and sets up reception of OFFERs for
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * IPv4, or sends a Solicit and sets up reception of
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Advertisements for DHCPv6.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * input: dhcp_smach_t *: the state machine on which to send the DISCOVER
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * output: void
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi const char *reqhost;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * We first set up to collect OFFER/Advertise packets as they arrive.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * We then send out DISCOVER/Solicit probes. Then we wait a
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * user-tunable number of seconds before seeing if OFFERs/
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Advertisements have come in response to our DISCOVER/Solicit. If
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * none have come in, we continue to wait, sending out our DISCOVER/
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Solicit probes with exponential backoff. If no OFFER/Advertisement
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * is ever received, we will wait forever (note that since we're
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * event-driven though, we're still able to service other state
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * machines).
724365f7556fc4201fdb11766ebc6bd918523130sethg * Note that we do an reset_smach() here because we may be landing in
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * dhcp_selecting() as a result of restarting DHCP, so the state
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * machine may not be fresh.
724365f7556fc4201fdb11766ebc6bd918523130sethg "dhcp_selecting: cannot switch to SELECTING state; "
724365f7556fc4201fdb11766ebc6bd918523130sethg dhcpmsg(MSG_ERROR, "dhcp_selecting: cannot schedule to read "
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi "%s packets", dsmp->dsm_isv6 ? "Advertise" : "OFFER");
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Assemble and send the DHCPDISCOVER or Solicit message.
724365f7556fc4201fdb11766ebc6bd918523130sethg * If this fails, we'll wait for the select timer to go off
724365f7556fc4201fdb11766ebc6bd918523130sethg * before trying again.
724365f7556fc4201fdb11766ebc6bd918523130sethg if ((dpkt = init_pkt(dsmp, DHCPV6_MSG_SOLICIT)) == NULL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi dhcpmsg(MSG_ERROR, "dhcp_selecting: unable to set up "
724365f7556fc4201fdb11766ebc6bd918523130sethg "Solicit packet");
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /* Add an IA_NA option for our controlling LIF */
724365f7556fc4201fdb11766ebc6bd918523130sethg /* Option Request option for desired information */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /* Enable Rapid-Commit */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) add_pkt_opt(dpkt, DHCPV6_OPT_RAPID_COMMIT, NULL, 0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /* xxx add Reconfigure Accept */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) send_pkt_v6(dsmp, dpkt, ipv6_all_dhcp_relay_and_servers,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi stop_selecting, DHCPV6_SOL_TIMEOUT, DHCPV6_SOL_MAX_RT);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi dhcpmsg(MSG_ERROR, "dhcp_selecting: unable to set up "
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi "DISCOVER packet");
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * The max DHCP message size option is set to the interface
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * MTU, minus the size of the UDP and IP headers.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi htons(dsmp->dsm_lif->lif_max - sizeof (struct udpiphdr)));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) add_pkt_opt32(dpkt, CD_LEASE_TIME, htonl(DHCP_PERM));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi "dhcp_selecting: DF_REQUEST_HOSTNAME");
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((reqhost = iffile_to_hostname(hostfile)) != NULL) {
724365f7556fc4201fdb11766ebc6bd918523130sethg "dhcp_selecting: cannot allocate "
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi "memory for host name option");
724365f7556fc4201fdb11766ebc6bd918523130sethg * dhcp_collect_dlpi(): collects incoming OFFERs, ACKs, and NAKs via DLPI.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * input: iu_eh_t *: unused
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * int: unused
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * short: unused
724365f7556fc4201fdb11766ebc6bd918523130sethg * iu_event_id_t: the id of this event callback with the handler
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * void *: the physical interface that received the message
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * output: void
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/* ARGSUSED */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindidhcp_collect_dlpi(iu_eh_t *eh, int fd, short events, iu_event_id_t id,
724365f7556fc4201fdb11766ebc6bd918523130sethg const char *pname;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((plp = recv_pkt(fd, pif->pif_max, B_FALSE, B_TRUE, pif)) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * DHCP_PUNTYPED messages are BOOTP server responses.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi DHCP_PACK | DHCP_PNAK | DHCP_POFFER | DHCP_PUNTYPED)) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi dhcpmsg(MSG_VERBOSE, "dhcp_collect_dlpi: ignored %s packet "
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Loop through the state machines that match on XID to find one that's
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * interested in this offer. If there are none, then discard.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (dsmp = lookup_smach_by_xid(xid, NULL, B_FALSE); dsmp != NULL;
724365f7556fc4201fdb11766ebc6bd918523130sethg * Find state machine on correct interface.
724365f7556fc4201fdb11766ebc6bd918523130sethg dhcpmsg(MSG_VERBOSE, "dhcp_collect_dlpi: no matching state "
724365f7556fc4201fdb11766ebc6bd918523130sethg "machine for %s packet XID %#x received via DLPI on %s",
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Ignore state machines that aren't looking for DLPI messages.
724365f7556fc4201fdb11766ebc6bd918523130sethg dhcpmsg(MSG_VERBOSE, "dhcp_collect_dlpi: ignore state "
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi "machine for %s packet XID %#x received via DLPI on %s",
static boolean_t
return (B_TRUE);
return (B_TRUE);
return (B_FALSE);