10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
53431Scarlsonj * Common Development and Distribution License (the "License").
63431Scarlsonj * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*12912SAnurag.Maskey@Oracle.COM * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate *
240Sstevel@tonic-gate * INFORM_SENT state of the client state machine.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate #include <sys/types.h>
280Sstevel@tonic-gate #include <time.h>
290Sstevel@tonic-gate #include <sys/socket.h>
300Sstevel@tonic-gate #include <netinet/in.h>
310Sstevel@tonic-gate #include <netinet/udp.h>
320Sstevel@tonic-gate #include <netinet/ip_var.h>
330Sstevel@tonic-gate #include <netinet/udp_var.h>
340Sstevel@tonic-gate #include <dhcpmsg.h>
350Sstevel@tonic-gate
363431Scarlsonj #include "agent.h"
373431Scarlsonj #include "states.h"
383431Scarlsonj #include "interface.h"
390Sstevel@tonic-gate #include "packet.h"
403431Scarlsonj
413431Scarlsonj static boolean_t stop_informing(dhcp_smach_t *, unsigned int);
420Sstevel@tonic-gate
430Sstevel@tonic-gate /*
440Sstevel@tonic-gate * dhcp_inform(): sends an INFORM packet and sets up reception for an ACK
450Sstevel@tonic-gate *
463431Scarlsonj * input: dhcp_smach_t *: the state machine to use
470Sstevel@tonic-gate * output: void
480Sstevel@tonic-gate * note: the INFORM cannot be sent successfully if the interface
493431Scarlsonj * does not have an IP address (this is mostly an issue for IPv4).
504106Scarlsonj * We switch into INFORM_SENT state before sending the packet so
514106Scarlsonj * that the packet-sending subsystem uses regular sockets and sets
524106Scarlsonj * the source address. (See set_smach_state.)
530Sstevel@tonic-gate */
540Sstevel@tonic-gate
550Sstevel@tonic-gate void
dhcp_inform(dhcp_smach_t * dsmp)563431Scarlsonj dhcp_inform(dhcp_smach_t *dsmp)
570Sstevel@tonic-gate {
580Sstevel@tonic-gate dhcp_pkt_t *dpkt;
590Sstevel@tonic-gate
604106Scarlsonj if (!set_smach_state(dsmp, INFORM_SENT))
613431Scarlsonj goto failed;
623431Scarlsonj
633431Scarlsonj if (dsmp->dsm_isv6) {
643431Scarlsonj dpkt = init_pkt(dsmp, DHCPV6_MSG_INFO_REQ);
650Sstevel@tonic-gate
663431Scarlsonj /* Add required Option Request option */
673431Scarlsonj (void) add_pkt_prl(dpkt, dsmp);
683431Scarlsonj dsmp->dsm_server = ipv6_all_dhcp_relay_and_servers;
693431Scarlsonj (void) send_pkt_v6(dsmp, dpkt, dsmp->dsm_server,
703431Scarlsonj stop_informing, DHCPV6_INF_TIMEOUT, DHCPV6_INF_MAX_RT);
713431Scarlsonj } else {
723431Scarlsonj ipaddr_t server;
730Sstevel@tonic-gate
743431Scarlsonj /*
753431Scarlsonj * Assemble a DHCPREQUEST packet, without the Server ID option.
763431Scarlsonj * Fill in ciaddr, since we know this. dsm_server will be set
773431Scarlsonj * to the server's IP address, which will be the broadcast
783431Scarlsonj * address if we don't know it. The max DHCP message size
793431Scarlsonj * option is set to the interface max, minus the size of the
803431Scarlsonj * UDP and IP headers.
813431Scarlsonj */
823431Scarlsonj
833431Scarlsonj dpkt = init_pkt(dsmp, INFORM);
843431Scarlsonj IN6_V4MAPPED_TO_INADDR(&dsmp->dsm_lif->lif_v6addr,
853431Scarlsonj &dpkt->pkt->ciaddr);
860Sstevel@tonic-gate
873431Scarlsonj (void) add_pkt_opt16(dpkt, CD_MAX_DHCP_SIZE,
883431Scarlsonj htons(dsmp->dsm_lif->lif_pif->pif_max -
893431Scarlsonj sizeof (struct udpiphdr)));
903448Sdh155122 if (class_id_len != 0) {
913448Sdh155122 (void) add_pkt_opt(dpkt, CD_CLASS_ID, class_id,
923448Sdh155122 class_id_len);
933448Sdh155122 }
943431Scarlsonj (void) add_pkt_prl(dpkt, dsmp);
953431Scarlsonj (void) add_pkt_opt(dpkt, CD_END, NULL, 0);
960Sstevel@tonic-gate
973431Scarlsonj IN6_V4MAPPED_TO_IPADDR(&dsmp->dsm_server, server);
98*12912SAnurag.Maskey@Oracle.COM if (!send_pkt(dsmp, dpkt, server, stop_informing)) {
993431Scarlsonj dhcpmsg(MSG_ERROR, "dhcp_inform: send_pkt failed");
1003431Scarlsonj goto failed;
1013431Scarlsonj }
1020Sstevel@tonic-gate }
1030Sstevel@tonic-gate
1043431Scarlsonj return;
1050Sstevel@tonic-gate
1063431Scarlsonj failed:
1073431Scarlsonj dsmp->dsm_dflags |= DHCP_IF_FAILED;
1083431Scarlsonj ipc_action_finish(dsmp, DHCP_IPC_E_INT);
1094106Scarlsonj (void) set_smach_state(dsmp, INIT);
1103431Scarlsonj }
1110Sstevel@tonic-gate
1123431Scarlsonj /*
1133431Scarlsonj * stop_informing(): decides when to stop retransmitting Information-Requests
1143431Scarlsonj *
1153431Scarlsonj * input: dhcp_smach_t *: the state machine Info-Reqs are being sent from
1163431Scarlsonj * unsigned int: the number of requests sent so far
1173431Scarlsonj * output: boolean_t: B_TRUE if retransmissions should stop
1183431Scarlsonj */
1190Sstevel@tonic-gate
1203431Scarlsonj /* ARGSUSED */
1213431Scarlsonj static boolean_t
stop_informing(dhcp_smach_t * dsmp,unsigned int n_requests)1223431Scarlsonj stop_informing(dhcp_smach_t *dsmp, unsigned int n_requests)
1233431Scarlsonj {
1243431Scarlsonj return (B_FALSE);
1250Sstevel@tonic-gate }
126