request.c (c2934490) | request.c (69bb4bb4) |
---|---|
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 --- 23 unchanged lines hidden (view full) --- 32#include <netinet/in.h> 33#include <netinet/dhcp.h> 34#include <netinet/udp.h> 35#include <netinet/ip_var.h> 36#include <netinet/udp_var.h> 37#include <dhcp_hostconf.h> 38#include <arpa/inet.h> 39#include <string.h> | 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 --- 23 unchanged lines hidden (view full) --- 32#include <netinet/in.h> 33#include <netinet/dhcp.h> 34#include <netinet/udp.h> 35#include <netinet/ip_var.h> 36#include <netinet/udp_var.h> 37#include <dhcp_hostconf.h> 38#include <arpa/inet.h> 39#include <string.h> |
40#include <stdlib.h> | |
41#include <unistd.h> 42#include <dhcpmsg.h> 43 44#include "states.h" 45#include "util.h" 46#include "packet.h" 47#include "interface.h" 48#include "agent.h" | 40#include <unistd.h> 41#include <dhcpmsg.h> 42 43#include "states.h" 44#include "util.h" 45#include "packet.h" 46#include "interface.h" 47#include "agent.h" |
49#include "defaults.h" | |
50 51static PKT_LIST *select_best(PKT_LIST **); | 48 49static PKT_LIST *select_best(PKT_LIST **); |
52static void restart_dhcp(struct ifslist *); | |
53static stop_func_t stop_requesting; 54 55/* 56 * dhcp_requesting(): checks if OFFER packets to come in from DHCP servers. 57 * if so, chooses the best one, sends a REQUEST to the 58 * server and registers an event handler to receive 59 * the ACK/NAK 60 * --- 73 unchanged lines hidden (view full) --- 134 135 if (offer->opts[CD_DHCP_TYPE] == NULL) { 136 137 ifsp->if_state = REQUESTING; 138 139 if (dhcp_bound(ifsp, offer) == 0) { 140 dhcpmsg(MSG_WARNING, "dhcp_requesting: dhcp_bound " 141 "failed for %s", ifsp->if_name); | 50static stop_func_t stop_requesting; 51 52/* 53 * dhcp_requesting(): checks if OFFER packets to come in from DHCP servers. 54 * if so, chooses the best one, sends a REQUEST to the 55 * server and registers an event handler to receive 56 * the ACK/NAK 57 * --- 73 unchanged lines hidden (view full) --- 131 132 if (offer->opts[CD_DHCP_TYPE] == NULL) { 133 134 ifsp->if_state = REQUESTING; 135 136 if (dhcp_bound(ifsp, offer) == 0) { 137 dhcpmsg(MSG_WARNING, "dhcp_requesting: dhcp_bound " 138 "failed for %s", ifsp->if_name); |
142 restart_dhcp(ifsp); | 139 dhcp_restart(ifsp); |
143 return; 144 } 145 146 return; 147 } 148 149 /* 150 * if we got a message from the server, display it. --- 252 unchanged lines hidden (view full) --- 403 stop_pkt_retransmission(ifsp); 404 (void) unregister_acknak(ifsp); 405 406 if (*(plp->opts[CD_DHCP_TYPE]->value) == NAK) { 407 dhcpmsg(MSG_WARNING, "dhcp_acknak: NAK on interface %s", 408 ifsp->if_name); 409 ifsp->if_bad_offers++; 410 free_pkt_list(&plp); | 140 return; 141 } 142 143 return; 144 } 145 146 /* 147 * if we got a message from the server, display it. --- 252 unchanged lines hidden (view full) --- 400 stop_pkt_retransmission(ifsp); 401 (void) unregister_acknak(ifsp); 402 403 if (*(plp->opts[CD_DHCP_TYPE]->value) == NAK) { 404 dhcpmsg(MSG_WARNING, "dhcp_acknak: NAK on interface %s", 405 ifsp->if_name); 406 ifsp->if_bad_offers++; 407 free_pkt_list(&plp); |
411 restart_dhcp(ifsp); | 408 dhcp_restart(ifsp); |
412 413 /* 414 * remove any bogus cached configuration we might have 415 * around (right now would only happen if we got here 416 * from INIT_REBOOT). 417 */ 418 419 (void) remove_hostconf(ifsp->if_name); 420 return; 421 } 422 423 if (plp->opts[CD_SERVER_ID] == NULL || 424 plp->opts[CD_SERVER_ID]->len != sizeof (ipaddr_t)) { 425 dhcpmsg(MSG_ERROR, "dhcp_acknak: ACK with no valid server id, " 426 "restarting DHCP on %s", ifsp->if_name); 427 ifsp->if_bad_offers++; 428 free_pkt_list(&plp); | 409 410 /* 411 * remove any bogus cached configuration we might have 412 * around (right now would only happen if we got here 413 * from INIT_REBOOT). 414 */ 415 416 (void) remove_hostconf(ifsp->if_name); 417 return; 418 } 419 420 if (plp->opts[CD_SERVER_ID] == NULL || 421 plp->opts[CD_SERVER_ID]->len != sizeof (ipaddr_t)) { 422 dhcpmsg(MSG_ERROR, "dhcp_acknak: ACK with no valid server id, " 423 "restarting DHCP on %s", ifsp->if_name); 424 ifsp->if_bad_offers++; 425 free_pkt_list(&plp); |
429 restart_dhcp(ifsp); | 426 dhcp_restart(ifsp); |
430 return; 431 } 432 433 if (plp->opts[CD_MESSAGE] != NULL) 434 print_server_msg(ifsp, plp->opts[CD_MESSAGE]); 435 436 if (dhcp_bound(ifsp, plp) == 0) { 437 dhcpmsg(MSG_WARNING, "dhcp_acknak: dhcp_bound failed " 438 "for %s", ifsp->if_name); | 427 return; 428 } 429 430 if (plp->opts[CD_MESSAGE] != NULL) 431 print_server_msg(ifsp, plp->opts[CD_MESSAGE]); 432 433 if (dhcp_bound(ifsp, plp) == 0) { 434 dhcpmsg(MSG_WARNING, "dhcp_acknak: dhcp_bound failed " 435 "for %s", ifsp->if_name); |
439 restart_dhcp(ifsp); | 436 dhcp_restart(ifsp); |
440 return; 441 } 442 443 dhcpmsg(MSG_VERBOSE, "ACK on interface %s", ifsp->if_name); 444} 445 446/* | 437 return; 438 } 439 440 dhcpmsg(MSG_VERBOSE, "ACK on interface %s", ifsp->if_name); 441} 442 443/* |
447 * restart_dhcp(): restarts DHCP (from INIT) on a given interface | 444 * dhcp_restart(): restarts DHCP (from INIT) on a given interface |
448 * 449 * input: struct ifslist *: the interface to restart DHCP on 450 * output: void 451 */ 452 | 445 * 446 * input: struct ifslist *: the interface to restart DHCP on 447 * output: void 448 */ 449 |
453static void 454restart_dhcp(struct ifslist *ifsp) | 450void 451dhcp_restart(struct ifslist *ifsp) |
455{ 456 if (iu_schedule_timer(tq, DHCP_RESTART_WAIT, dhcp_start, ifsp) == -1) { 457 458 ifsp->if_state = INIT; 459 ifsp->if_dflags |= DHCP_IF_FAILED; 460 461 ipc_action_finish(ifsp, DHCP_IPC_E_MEMORY); 462 async_finish(ifsp); 463 | 452{ 453 if (iu_schedule_timer(tq, DHCP_RESTART_WAIT, dhcp_start, ifsp) == -1) { 454 455 ifsp->if_state = INIT; 456 ifsp->if_dflags |= DHCP_IF_FAILED; 457 458 ipc_action_finish(ifsp, DHCP_IPC_E_MEMORY); 459 async_finish(ifsp); 460 |
464 dhcpmsg(MSG_ERROR, "restart_dhcp: cannot schedule dhcp_start, " | 461 dhcpmsg(MSG_ERROR, "dhcp_restart: cannot schedule dhcp_start, " |
465 "reverting to INIT state on %s", ifsp->if_name); 466 } else 467 hold_ifs(ifsp); 468} 469 470/* 471 * stop_requesting(): decides when to stop retransmitting REQUESTs 472 * --- 21 unchanged lines hidden --- | 462 "reverting to INIT state on %s", ifsp->if_name); 463 } else 464 hold_ifs(ifsp); 465} 466 467/* 468 * stop_requesting(): decides when to stop retransmitting REQUESTs 469 * --- 21 unchanged lines hidden --- |