8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / cmd-inet / sbin / dhcpagent / inform.c
blobd47125b78a67ffedebd55ff29e0e054c4da9f6ec
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
24 * INFORM_SENT state of the client state machine.
27 #include <sys/types.h>
28 #include <time.h>
29 #include <sys/socket.h>
30 #include <netinet/in.h>
31 #include <netinet/udp.h>
32 #include <netinet/ip_var.h>
33 #include <netinet/udp_var.h>
34 #include <dhcpmsg.h>
36 #include "agent.h"
37 #include "states.h"
38 #include "interface.h"
39 #include "packet.h"
41 static boolean_t stop_informing(dhcp_smach_t *, unsigned int);
44 * dhcp_inform(): sends an INFORM packet and sets up reception for an ACK
46 * input: dhcp_smach_t *: the state machine to use
47 * output: void
48 * note: the INFORM cannot be sent successfully if the interface
49 * does not have an IP address (this is mostly an issue for IPv4).
50 * We switch into INFORM_SENT state before sending the packet so
51 * that the packet-sending subsystem uses regular sockets and sets
52 * the source address. (See set_smach_state.)
55 void
56 dhcp_inform(dhcp_smach_t *dsmp)
58 dhcp_pkt_t *dpkt;
60 if (!set_smach_state(dsmp, INFORM_SENT))
61 goto failed;
63 if (dsmp->dsm_isv6) {
64 dpkt = init_pkt(dsmp, DHCPV6_MSG_INFO_REQ);
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;
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.
83 dpkt = init_pkt(dsmp, INFORM);
84 IN6_V4MAPPED_TO_INADDR(&dsmp->dsm_lif->lif_v6addr,
85 &dpkt->pkt->ciaddr);
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);
94 (void) add_pkt_prl(dpkt, dsmp);
95 (void) add_pkt_opt(dpkt, CD_END, NULL, 0);
97 IN6_V4MAPPED_TO_IPADDR(&dsmp->dsm_server, server);
98 if (!send_pkt(dsmp, dpkt, server, stop_informing)) {
99 dhcpmsg(MSG_ERROR, "dhcp_inform: send_pkt failed");
100 goto failed;
104 return;
106 failed:
107 dsmp->dsm_dflags |= DHCP_IF_FAILED;
108 ipc_action_finish(dsmp, DHCP_IPC_E_INT);
109 (void) set_smach_state(dsmp, INIT);
113 * stop_informing(): decides when to stop retransmitting Information-Requests
115 * input: dhcp_smach_t *: the state machine Info-Reqs are being sent from
116 * unsigned int: the number of requests sent so far
117 * output: boolean_t: B_TRUE if retransmissions should stop
120 /* ARGSUSED */
121 static boolean_t
122 stop_informing(dhcp_smach_t *dsmp, unsigned int n_requests)
124 return (B_FALSE);