17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5d04ccbb3Scarlsonj  * Common Development and Distribution License (the "License").
6d04ccbb3Scarlsonj  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*3dbbe3fbSAnurag S. Maskey  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  *
247c478bd9Sstevel@tonic-gate  * INFORM_SENT state of the client state machine.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #include <sys/types.h>
287c478bd9Sstevel@tonic-gate #include <time.h>
297c478bd9Sstevel@tonic-gate #include <sys/socket.h>
307c478bd9Sstevel@tonic-gate #include <netinet/in.h>
317c478bd9Sstevel@tonic-gate #include <netinet/udp.h>
327c478bd9Sstevel@tonic-gate #include <netinet/ip_var.h>
337c478bd9Sstevel@tonic-gate #include <netinet/udp_var.h>
347c478bd9Sstevel@tonic-gate #include <dhcpmsg.h>
357c478bd9Sstevel@tonic-gate 
36d04ccbb3Scarlsonj #include "agent.h"
37d04ccbb3Scarlsonj #include "states.h"
387c478bd9Sstevel@tonic-gate #include "interface.h"
39d04ccbb3Scarlsonj #include "packet.h"
40d04ccbb3Scarlsonj 
41d04ccbb3Scarlsonj static boolean_t stop_informing(dhcp_smach_t *, unsigned int);
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate  * dhcp_inform(): sends an INFORM packet and sets up reception for an ACK
457c478bd9Sstevel@tonic-gate  *
46d04ccbb3Scarlsonj  *   input: dhcp_smach_t *: the state machine to use
477c478bd9Sstevel@tonic-gate  *  output: void
487c478bd9Sstevel@tonic-gate  *    note: the INFORM cannot be sent successfully if the interface
49d04ccbb3Scarlsonj  *	    does not have an IP address (this is mostly an issue for IPv4).
50cfb9c9abScarlsonj  *	    We switch into INFORM_SENT state before sending the packet so
51cfb9c9abScarlsonj  *	    that the packet-sending subsystem uses regular sockets and sets
52cfb9c9abScarlsonj  *	    the source address.  (See set_smach_state.)
537c478bd9Sstevel@tonic-gate  */
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate void
dhcp_inform(dhcp_smach_t * dsmp)56d04ccbb3Scarlsonj dhcp_inform(dhcp_smach_t *dsmp)
577c478bd9Sstevel@tonic-gate {
587c478bd9Sstevel@tonic-gate 	dhcp_pkt_t		*dpkt;
597c478bd9Sstevel@tonic-gate 
60cfb9c9abScarlsonj 	if (!set_smach_state(dsmp, INFORM_SENT))
61d04ccbb3Scarlsonj 		goto failed;
62d04ccbb3Scarlsonj 
63d04ccbb3Scarlsonj 	if (dsmp->dsm_isv6) {
64d04ccbb3Scarlsonj 		dpkt = init_pkt(dsmp, DHCPV6_MSG_INFO_REQ);
65d04ccbb3Scarlsonj 
66d04ccbb3Scarlsonj 		/* Add required Option Request option */
67d04ccbb3Scarlsonj 		(void) add_pkt_prl(dpkt, dsmp);
68d04ccbb3Scarlsonj 		dsmp->dsm_server = ipv6_all_dhcp_relay_and_servers;
69d04ccbb3Scarlsonj 		(void) send_pkt_v6(dsmp, dpkt, dsmp->dsm_server,
70d04ccbb3Scarlsonj 		    stop_informing, DHCPV6_INF_TIMEOUT, DHCPV6_INF_MAX_RT);
71d04ccbb3Scarlsonj 	} else {
72d04ccbb3Scarlsonj 		ipaddr_t server;
73d04ccbb3Scarlsonj 
74d04ccbb3Scarlsonj 		/*
75d04ccbb3Scarlsonj 		 * Assemble a DHCPREQUEST packet, without the Server ID option.
76d04ccbb3Scarlsonj 		 * Fill in ciaddr, since we know this.  dsm_server will be set
77d04ccbb3Scarlsonj 		 * to the server's IP address, which will be the broadcast
78d04ccbb3Scarlsonj 		 * address if we don't know it.  The max DHCP message size
79d04ccbb3Scarlsonj 		 * option is set to the interface max, minus the size of the
80d04ccbb3Scarlsonj 		 * UDP and IP headers.
81d04ccbb3Scarlsonj 		 */
82d04ccbb3Scarlsonj 
83d04ccbb3Scarlsonj 		dpkt = init_pkt(dsmp, INFORM);
84d04ccbb3Scarlsonj 		IN6_V4MAPPED_TO_INADDR(&dsmp->dsm_lif->lif_v6addr,
85d04ccbb3Scarlsonj 		    &dpkt->pkt->ciaddr);
86d04ccbb3Scarlsonj 
87d04ccbb3Scarlsonj 		(void) add_pkt_opt16(dpkt, CD_MAX_DHCP_SIZE,
88d04ccbb3Scarlsonj 		    htons(dsmp->dsm_lif->lif_pif->pif_max -
89d04ccbb3Scarlsonj 		    sizeof (struct udpiphdr)));
90f4b3ec61Sdh 		if (class_id_len != 0) {
91f4b3ec61Sdh 			(void) add_pkt_opt(dpkt, CD_CLASS_ID, class_id,
92f4b3ec61Sdh 			    class_id_len);
93f4b3ec61Sdh 		}
94d04ccbb3Scarlsonj 		(void) add_pkt_prl(dpkt, dsmp);
95d04ccbb3Scarlsonj 		(void) add_pkt_opt(dpkt, CD_END, NULL, 0);
96d04ccbb3Scarlsonj 
97d04ccbb3Scarlsonj 		IN6_V4MAPPED_TO_IPADDR(&dsmp->dsm_server, server);
98*3dbbe3fbSAnurag S. Maskey 		if (!send_pkt(dsmp, dpkt, server, stop_informing)) {
99d04ccbb3Scarlsonj 			dhcpmsg(MSG_ERROR, "dhcp_inform: send_pkt failed");
100d04ccbb3Scarlsonj 			goto failed;
101d04ccbb3Scarlsonj 		}
1027c478bd9Sstevel@tonic-gate 	}
1037c478bd9Sstevel@tonic-gate 
104d04ccbb3Scarlsonj 	return;
1057c478bd9Sstevel@tonic-gate 
106d04ccbb3Scarlsonj failed:
107d04ccbb3Scarlsonj 	dsmp->dsm_dflags |= DHCP_IF_FAILED;
108d04ccbb3Scarlsonj 	ipc_action_finish(dsmp, DHCP_IPC_E_INT);
109cfb9c9abScarlsonj 	(void) set_smach_state(dsmp, INIT);
110d04ccbb3Scarlsonj }
1117c478bd9Sstevel@tonic-gate 
112d04ccbb3Scarlsonj /*
113d04ccbb3Scarlsonj  * stop_informing(): decides when to stop retransmitting Information-Requests
114d04ccbb3Scarlsonj  *
115d04ccbb3Scarlsonj  *   input: dhcp_smach_t *: the state machine Info-Reqs are being sent from
116d04ccbb3Scarlsonj  *	    unsigned int: the number of requests sent so far
117d04ccbb3Scarlsonj  *  output: boolean_t: B_TRUE if retransmissions should stop
118d04ccbb3Scarlsonj  */
1197c478bd9Sstevel@tonic-gate 
120d04ccbb3Scarlsonj /* ARGSUSED */
121d04ccbb3Scarlsonj static boolean_t
stop_informing(dhcp_smach_t * dsmp,unsigned int n_requests)122d04ccbb3Scarlsonj stop_informing(dhcp_smach_t *dsmp, unsigned int n_requests)
123d04ccbb3Scarlsonj {
124d04ccbb3Scarlsonj 	return (B_FALSE);
1257c478bd9Sstevel@tonic-gate }
126