xref: /titanic_52/usr/src/cmd/cmd-inet/sbin/dhcpagent/inform.c (revision 1da218965c488f7b3d6e513e49cda33fdbc08b7f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  *
25  * INFORM_SENT state of the client state machine.
26  */
27 
28 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 
30 #include <sys/types.h>
31 #include <time.h>
32 #include <sys/socket.h>
33 #include <netinet/in.h>
34 #include <netinet/udp.h>
35 #include <netinet/ip_var.h>
36 #include <netinet/udp_var.h>
37 #include <dhcpmsg.h>
38 
39 #include "agent.h"
40 #include "states.h"
41 #include "interface.h"
42 #include "packet.h"
43 
44 static boolean_t stop_informing(dhcp_smach_t *, unsigned int);
45 
46 /*
47  * dhcp_inform(): sends an INFORM packet and sets up reception for an ACK
48  *
49  *   input: dhcp_smach_t *: the state machine to use
50  *  output: void
51  *    note: the INFORM cannot be sent successfully if the interface
52  *	    does not have an IP address (this is mostly an issue for IPv4).
53  */
54 
55 void
56 dhcp_inform(dhcp_smach_t *dsmp)
57 {
58 	dhcp_pkt_t		*dpkt;
59 
60 	if (!set_smach_state(dsmp, INIT))
61 		goto failed;
62 
63 	if (dsmp->dsm_isv6) {
64 		dpkt = init_pkt(dsmp, DHCPV6_MSG_INFO_REQ);
65 
66 		/* Add required Option Request option */
67 		(void) add_pkt_prl(dpkt, dsmp);
68 		dsmp->dsm_server = ipv6_all_dhcp_relay_and_servers;
69 		(void) send_pkt_v6(dsmp, dpkt, dsmp->dsm_server,
70 		    stop_informing, DHCPV6_INF_TIMEOUT, DHCPV6_INF_MAX_RT);
71 	} else {
72 		ipaddr_t server;
73 
74 		/*
75 		 * Assemble a DHCPREQUEST packet, without the Server ID option.
76 		 * Fill in ciaddr, since we know this.  dsm_server will be set
77 		 * to the server's IP address, which will be the broadcast
78 		 * address if we don't know it.  The max DHCP message size
79 		 * option is set to the interface max, minus the size of the
80 		 * UDP and IP headers.
81 		 */
82 
83 		dpkt = init_pkt(dsmp, INFORM);
84 		IN6_V4MAPPED_TO_INADDR(&dsmp->dsm_lif->lif_v6addr,
85 		    &dpkt->pkt->ciaddr);
86 
87 		(void) add_pkt_opt16(dpkt, CD_MAX_DHCP_SIZE,
88 		    htons(dsmp->dsm_lif->lif_pif->pif_max -
89 		    sizeof (struct udpiphdr)));
90 		if (class_id_len != 0) {
91 			(void) add_pkt_opt(dpkt, CD_CLASS_ID, class_id,
92 			    class_id_len);
93 		}
94 		(void) add_pkt_prl(dpkt, dsmp);
95 		(void) add_pkt_opt(dpkt, CD_END, NULL, 0);
96 
97 		IN6_V4MAPPED_TO_IPADDR(&dsmp->dsm_server, server);
98 		if (!send_pkt(dsmp, dpkt, server, NULL)) {
99 			dhcpmsg(MSG_ERROR, "dhcp_inform: send_pkt failed");
100 			goto failed;
101 		}
102 	}
103 
104 	if (!set_smach_state(dsmp, INFORM_SENT))
105 		goto failed;
106 
107 	return;
108 
109 failed:
110 	dsmp->dsm_dflags |= DHCP_IF_FAILED;
111 	ipc_action_finish(dsmp, DHCP_IPC_E_INT);
112 }
113 
114 /*
115  * stop_informing(): decides when to stop retransmitting Information-Requests
116  *
117  *   input: dhcp_smach_t *: the state machine Info-Reqs are being sent from
118  *	    unsigned int: the number of requests sent so far
119  *  output: boolean_t: B_TRUE if retransmissions should stop
120  */
121 
122 /* ARGSUSED */
123 static boolean_t
124 stop_informing(dhcp_smach_t *dsmp, unsigned int n_requests)
125 {
126 	return (B_FALSE);
127 }
128