1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright (c) 1995-2001 by Sun Microsystems, Inc. 24*0Sstevel@tonic-gate * All rights reserved. 25*0Sstevel@tonic-gate * 26*0Sstevel@tonic-gate * INFORM_SENT state of the client state machine. 27*0Sstevel@tonic-gate */ 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate #include <sys/types.h> 32*0Sstevel@tonic-gate #include <string.h> 33*0Sstevel@tonic-gate #include <time.h> 34*0Sstevel@tonic-gate #include <unistd.h> 35*0Sstevel@tonic-gate #include <sys/sockio.h> 36*0Sstevel@tonic-gate #include <sys/socket.h> 37*0Sstevel@tonic-gate #include <netinet/in.h> 38*0Sstevel@tonic-gate #include <netinet/udp.h> 39*0Sstevel@tonic-gate #include <netinet/ip_var.h> 40*0Sstevel@tonic-gate #include <netinet/udp_var.h> 41*0Sstevel@tonic-gate #include <dhcpmsg.h> 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gate #include "util.h" 44*0Sstevel@tonic-gate #include "packet.h" 45*0Sstevel@tonic-gate #include "interface.h" 46*0Sstevel@tonic-gate 47*0Sstevel@tonic-gate /* 48*0Sstevel@tonic-gate * dhcp_inform(): sends an INFORM packet and sets up reception for an ACK 49*0Sstevel@tonic-gate * 50*0Sstevel@tonic-gate * input: struct ifslist *: the interface to send the inform on, ... 51*0Sstevel@tonic-gate * output: void 52*0Sstevel@tonic-gate * note: the INFORM cannot be sent successfully if the interface 53*0Sstevel@tonic-gate * does not have an IP address 54*0Sstevel@tonic-gate */ 55*0Sstevel@tonic-gate 56*0Sstevel@tonic-gate void 57*0Sstevel@tonic-gate dhcp_inform(struct ifslist *ifsp) 58*0Sstevel@tonic-gate { 59*0Sstevel@tonic-gate dhcp_pkt_t *dpkt; 60*0Sstevel@tonic-gate struct in_addr *our_addr; 61*0Sstevel@tonic-gate struct ifreq ifr; 62*0Sstevel@tonic-gate 63*0Sstevel@tonic-gate ifsp->if_state = INIT; 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate /* 66*0Sstevel@tonic-gate * fetch our IP address -- since we may not manage the 67*0Sstevel@tonic-gate * interface, go fetch it with ioctl() 68*0Sstevel@tonic-gate */ 69*0Sstevel@tonic-gate 70*0Sstevel@tonic-gate (void) memset(&ifr, 0, sizeof (struct ifreq)); 71*0Sstevel@tonic-gate (void) strlcpy(ifr.ifr_name, ifsp->if_name, IFNAMSIZ); 72*0Sstevel@tonic-gate ifr.ifr_addr.sa_family = AF_INET; 73*0Sstevel@tonic-gate 74*0Sstevel@tonic-gate if (ioctl(ifsp->if_sock_fd, SIOCGIFADDR, &ifr) == -1) { 75*0Sstevel@tonic-gate ifsp->if_dflags |= DHCP_IF_FAILED; 76*0Sstevel@tonic-gate ipc_action_finish(ifsp, DHCP_IPC_E_INT); 77*0Sstevel@tonic-gate async_finish(ifsp); 78*0Sstevel@tonic-gate return; 79*0Sstevel@tonic-gate } 80*0Sstevel@tonic-gate 81*0Sstevel@tonic-gate /* 82*0Sstevel@tonic-gate * the error handling here and in the check for IFF_UP below 83*0Sstevel@tonic-gate * are handled different from most since it is the user who is 84*0Sstevel@tonic-gate * at fault for the problem, not the machine. 85*0Sstevel@tonic-gate */ 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate /* LINTED [ifr_addr is a sockaddr which will be aligned] */ 88*0Sstevel@tonic-gate our_addr = &((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr; 89*0Sstevel@tonic-gate if (our_addr->s_addr == htonl(INADDR_ANY)) { 90*0Sstevel@tonic-gate dhcpmsg(MSG_WARNING, "dhcp_inform: INFORM attempted on " 91*0Sstevel@tonic-gate "interface with no IP address"); 92*0Sstevel@tonic-gate ipc_action_finish(ifsp, DHCP_IPC_E_NOIPIF); 93*0Sstevel@tonic-gate async_finish(ifsp); 94*0Sstevel@tonic-gate remove_ifs(ifsp); 95*0Sstevel@tonic-gate return; 96*0Sstevel@tonic-gate } 97*0Sstevel@tonic-gate 98*0Sstevel@tonic-gate if (ioctl(ifsp->if_sock_fd, SIOCGIFFLAGS, &ifr) == -1) { 99*0Sstevel@tonic-gate ifsp->if_dflags |= DHCP_IF_FAILED; 100*0Sstevel@tonic-gate ipc_action_finish(ifsp, DHCP_IPC_E_INT); 101*0Sstevel@tonic-gate async_finish(ifsp); 102*0Sstevel@tonic-gate return; 103*0Sstevel@tonic-gate } 104*0Sstevel@tonic-gate 105*0Sstevel@tonic-gate if ((ifr.ifr_flags & IFF_UP) == 0) { 106*0Sstevel@tonic-gate dhcpmsg(MSG_WARNING, "dhcp_inform: INFORM attempted on downed " 107*0Sstevel@tonic-gate "interface"); 108*0Sstevel@tonic-gate ipc_action_finish(ifsp, DHCP_IPC_E_DOWNIF); 109*0Sstevel@tonic-gate async_finish(ifsp); 110*0Sstevel@tonic-gate remove_ifs(ifsp); 111*0Sstevel@tonic-gate return; 112*0Sstevel@tonic-gate } 113*0Sstevel@tonic-gate 114*0Sstevel@tonic-gate /* 115*0Sstevel@tonic-gate * assemble a DHCPREQUEST packet, without the server id 116*0Sstevel@tonic-gate * option. fill in ciaddr, since we know this. if_server 117*0Sstevel@tonic-gate * will be set to the server's IP address, which will be the 118*0Sstevel@tonic-gate * broadcast address if we don't know it. The max dhcp message size 119*0Sstevel@tonic-gate * option is set to the interface max, minus the size of the udp and 120*0Sstevel@tonic-gate * ip headers. 121*0Sstevel@tonic-gate */ 122*0Sstevel@tonic-gate 123*0Sstevel@tonic-gate dpkt = init_pkt(ifsp, INFORM); 124*0Sstevel@tonic-gate dpkt->pkt->ciaddr = *our_addr; 125*0Sstevel@tonic-gate 126*0Sstevel@tonic-gate add_pkt_opt16(dpkt, CD_MAX_DHCP_SIZE, htons(ifsp->if_max - 127*0Sstevel@tonic-gate sizeof (struct udpiphdr))); 128*0Sstevel@tonic-gate add_pkt_opt(dpkt, CD_CLASS_ID, class_id, class_id_len); 129*0Sstevel@tonic-gate add_pkt_opt(dpkt, CD_REQUEST_LIST, ifsp->if_prl, ifsp->if_prllen); 130*0Sstevel@tonic-gate add_pkt_opt(dpkt, CD_END, NULL, 0); 131*0Sstevel@tonic-gate 132*0Sstevel@tonic-gate if (send_pkt(ifsp, dpkt, ifsp->if_server.s_addr, NULL) == 0) { 133*0Sstevel@tonic-gate ifsp->if_dflags |= DHCP_IF_FAILED; 134*0Sstevel@tonic-gate dhcpmsg(MSG_ERROR, "dhcp_inform: send_pkt failed"); 135*0Sstevel@tonic-gate ipc_action_finish(ifsp, DHCP_IPC_E_INT); 136*0Sstevel@tonic-gate async_finish(ifsp); 137*0Sstevel@tonic-gate return; 138*0Sstevel@tonic-gate } 139*0Sstevel@tonic-gate 140*0Sstevel@tonic-gate if (register_acknak(ifsp) == 0) { 141*0Sstevel@tonic-gate ifsp->if_dflags |= DHCP_IF_FAILED; 142*0Sstevel@tonic-gate ipc_action_finish(ifsp, DHCP_IPC_E_MEMORY); 143*0Sstevel@tonic-gate async_finish(ifsp); 144*0Sstevel@tonic-gate return; 145*0Sstevel@tonic-gate } 146*0Sstevel@tonic-gate 147*0Sstevel@tonic-gate ifsp->if_state = INFORM_SENT; 148*0Sstevel@tonic-gate } 149