2011-07-25 12:00:57 +05:30
|
|
|
/* state.c - high level DHCP state machine
|
|
|
|
*
|
2020-10-20 13:53:55 +05:30
|
|
|
* Copyright 2011-2020 Nicholas J. Kain <njkain at gmail dot com>
|
2011-07-25 12:00:57 +05:30
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* - Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
2011-06-30 09:17:31 +05:30
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
2014-03-31 02:32:48 +05:30
|
|
|
#include "nk/log.h"
|
|
|
|
#include "nk/random.h"
|
|
|
|
|
2011-06-30 09:17:31 +05:30
|
|
|
#include "state.h"
|
|
|
|
#include "ifchange.h"
|
|
|
|
#include "arp.h"
|
|
|
|
#include "options.h"
|
2014-03-13 02:21:10 +05:30
|
|
|
#include "ndhc.h"
|
2011-06-30 09:17:31 +05:30
|
|
|
#include "sys.h"
|
2015-02-14 15:50:04 +05:30
|
|
|
#include "netlink.h"
|
2015-02-18 16:01:13 +05:30
|
|
|
#include "coroutine.h"
|
2015-02-14 15:50:04 +05:30
|
|
|
|
2020-10-19 16:33:03 +05:30
|
|
|
#define IGNORED_RENEWS_BEFORE_REBIND 3
|
|
|
|
|
2015-02-18 16:01:13 +05:30
|
|
|
#define SEL_SUCCESS 0
|
|
|
|
#define SEL_FAIL -1
|
2011-06-30 09:17:31 +05:30
|
|
|
|
2015-02-18 16:01:13 +05:30
|
|
|
#define REQ_SUCCESS 0
|
|
|
|
#define REQ_TIMEOUT -1
|
|
|
|
#define REQ_FAIL -2
|
2011-06-30 09:17:31 +05:30
|
|
|
|
2015-02-18 16:01:13 +05:30
|
|
|
#define ANP_SUCCESS 0
|
|
|
|
#define ANP_IGNORE -1
|
|
|
|
#define ANP_REJECTED -2
|
|
|
|
#define ANP_CHECK_IP -3
|
2011-06-30 09:17:31 +05:30
|
|
|
|
2015-02-18 16:01:13 +05:30
|
|
|
#define BTO_WAIT 0
|
|
|
|
#define BTO_EXPIRED -1
|
|
|
|
#define BTO_HARDFAIL -2
|
2011-06-30 09:17:31 +05:30
|
|
|
|
2015-02-18 16:01:13 +05:30
|
|
|
#define IFUP_REVALIDATE 0
|
|
|
|
#define IFUP_NEWLEASE 1
|
|
|
|
#define IFUP_FAIL -1
|
2011-07-06 01:14:11 +05:30
|
|
|
|
2015-02-14 08:59:03 +05:30
|
|
|
static int delay_timeout(struct client_state_t cs[static 1], size_t numpackets)
|
2011-06-30 12:57:57 +05:30
|
|
|
{
|
|
|
|
int to = 64;
|
|
|
|
char tot[] = { 4, 8, 16, 32, 64 };
|
|
|
|
if (numpackets < sizeof tot)
|
|
|
|
to = tot[numpackets];
|
2014-03-22 11:38:23 +05:30
|
|
|
// Distribution is a bit biased but it doesn't really matter.
|
2018-02-09 13:09:46 +05:30
|
|
|
return to * 1000 + (int)(nk_random_u32(&cs->rnd_state) % 1000);
|
2011-06-30 12:57:57 +05:30
|
|
|
}
|
|
|
|
|
2015-02-18 17:42:35 +05:30
|
|
|
static void reinit_shared_deconfig(struct client_state_t cs[static 1])
|
2011-07-05 07:40:14 +05:30
|
|
|
{
|
2020-10-19 15:09:08 +05:30
|
|
|
cs->xid = nk_random_u32(&cs->rnd_state);
|
2011-07-05 07:40:14 +05:30
|
|
|
cs->clientAddr = 0;
|
2015-02-18 16:01:13 +05:30
|
|
|
cs->num_dhcp_requests = 0;
|
2020-10-19 16:33:03 +05:30
|
|
|
cs->num_dhcp_renews = 0;
|
2020-10-19 12:37:23 +05:30
|
|
|
cs->server_arp_sent = 0;
|
2020-10-19 13:55:15 +05:30
|
|
|
cs->router_arp_sent = 0;
|
2020-10-19 12:37:23 +05:30
|
|
|
cs->server_arp_state = ARP_QUERY;
|
2020-10-19 13:55:15 +05:30
|
|
|
cs->router_arp_state = ARP_QUERY;
|
2017-02-27 21:40:14 +05:30
|
|
|
cs->check_fingerprint = false;
|
2020-10-19 15:35:47 +05:30
|
|
|
cs->sent_renew_or_rebind = false;
|
2017-02-27 21:40:14 +05:30
|
|
|
cs->sent_gw_query = false;
|
|
|
|
cs->sent_first_announce = false;
|
|
|
|
cs->sent_second_announce = false;
|
2017-04-10 19:27:52 +05:30
|
|
|
cs->init_fingerprint_inprogress = false;
|
2011-07-11 22:54:59 +05:30
|
|
|
memset(&cs->routerArp, 0, sizeof cs->routerArp);
|
|
|
|
memset(&cs->serverArp, 0, sizeof cs->serverArp);
|
2017-02-27 22:00:35 +05:30
|
|
|
arp_reset_state(cs);
|
2011-07-11 22:54:59 +05:30
|
|
|
}
|
|
|
|
|
2015-02-18 17:42:35 +05:30
|
|
|
static void reinit_selecting(struct client_state_t cs[static 1], int timeout)
|
2011-07-11 22:54:59 +05:30
|
|
|
{
|
2015-02-18 17:42:35 +05:30
|
|
|
reinit_shared_deconfig(cs);
|
2015-02-18 16:01:13 +05:30
|
|
|
cs->dhcp_wake_ts = curms() + timeout;
|
2014-04-16 10:30:36 +05:30
|
|
|
start_dhcp_listen(cs);
|
2011-07-05 07:40:14 +05:30
|
|
|
}
|
|
|
|
|
2011-06-30 09:17:31 +05:30
|
|
|
// Triggered after a DHCP lease request packet has been sent and no reply has
|
|
|
|
// been received within the response wait time. If we've not exceeded the
|
|
|
|
// maximum number of request retransmits, then send another packet and wait
|
|
|
|
// again. Otherwise, return to the DHCP initialization state.
|
2015-02-18 16:01:13 +05:30
|
|
|
static int requesting_timeout(struct client_state_t cs[static 1],
|
2015-02-14 11:14:21 +05:30
|
|
|
long long nowts)
|
2011-06-30 09:17:31 +05:30
|
|
|
{
|
2015-02-18 16:01:13 +05:30
|
|
|
if (cs->num_dhcp_requests >= 5) {
|
2015-02-18 17:42:35 +05:30
|
|
|
reinit_selecting(cs, 0);
|
2015-02-18 16:01:13 +05:30
|
|
|
return REQ_TIMEOUT;
|
2015-02-14 15:50:04 +05:30
|
|
|
}
|
2015-02-18 17:42:35 +05:30
|
|
|
if (send_selecting(cs) < 0) {
|
2015-02-14 15:50:04 +05:30
|
|
|
log_warning("%s: Failed to send a selecting request packet.",
|
|
|
|
client_config.interface);
|
2015-02-18 16:01:13 +05:30
|
|
|
return REQ_FAIL;
|
2015-02-14 15:50:04 +05:30
|
|
|
}
|
2015-02-18 16:01:13 +05:30
|
|
|
cs->dhcp_wake_ts = nowts + delay_timeout(cs, cs->num_dhcp_requests);
|
|
|
|
cs->num_dhcp_requests++;
|
|
|
|
return REQ_SUCCESS;
|
2011-06-30 09:17:31 +05:30
|
|
|
}
|
|
|
|
|
2020-10-19 15:35:47 +05:30
|
|
|
// Called by renewing_timeout() to try to renew the lease. If all
|
|
|
|
// timeouts expire, then expire the lease and notify the caller.
|
2015-02-18 16:01:13 +05:30
|
|
|
static int rebinding_timeout(struct client_state_t cs[static 1],
|
2020-10-19 15:35:47 +05:30
|
|
|
long long nowts)
|
2011-06-30 09:17:31 +05:30
|
|
|
{
|
2011-06-30 12:18:58 +05:30
|
|
|
long long elt = cs->leaseStartTime + cs->lease * 1000;
|
2015-02-14 15:50:04 +05:30
|
|
|
if (nowts >= elt) {
|
2014-04-16 00:54:22 +05:30
|
|
|
log_line("%s: Lease expired. Searching for a new lease...",
|
|
|
|
client_config.interface);
|
2015-02-18 17:42:35 +05:30
|
|
|
reinit_selecting(cs, 0);
|
2015-02-18 16:01:13 +05:30
|
|
|
return BTO_EXPIRED;
|
2011-07-12 02:03:57 +05:30
|
|
|
}
|
2015-02-18 21:33:58 +05:30
|
|
|
start_dhcp_listen(cs);
|
2015-02-18 17:42:35 +05:30
|
|
|
if (send_rebind(cs) < 0) {
|
2015-02-14 15:50:04 +05:30
|
|
|
log_warning("%s: Failed to send a rebind request packet.",
|
|
|
|
client_config.interface);
|
2015-02-18 16:01:13 +05:30
|
|
|
return BTO_HARDFAIL;
|
2015-02-14 15:50:04 +05:30
|
|
|
}
|
2020-10-19 15:35:47 +05:30
|
|
|
cs->sent_renew_or_rebind = true;
|
2017-08-24 12:06:31 +05:30
|
|
|
long long ts0 = nowts + (50 + nk_random_u32(&cs->rnd_state) % 20) * 1000;
|
2015-02-18 21:33:58 +05:30
|
|
|
cs->dhcp_wake_ts = ts0 < elt ? ts0 : elt;
|
2015-02-18 16:01:13 +05:30
|
|
|
return BTO_WAIT;
|
2011-06-30 09:17:31 +05:30
|
|
|
}
|
|
|
|
|
2020-10-19 15:35:47 +05:30
|
|
|
// Called by bound_timeout() to try to renew the lease.
|
2015-02-18 16:01:13 +05:30
|
|
|
static int renewing_timeout(struct client_state_t cs[static 1],
|
2020-10-19 15:35:47 +05:30
|
|
|
long long nowts)
|
2011-06-30 09:17:31 +05:30
|
|
|
{
|
2015-02-18 16:01:13 +05:30
|
|
|
long long rbt = cs->leaseStartTime + cs->rebindTime * 1000;
|
2020-10-19 16:33:03 +05:30
|
|
|
if (nowts >= rbt || cs->num_dhcp_renews >= IGNORED_RENEWS_BEFORE_REBIND)
|
2015-02-18 16:01:13 +05:30
|
|
|
return rebinding_timeout(cs, nowts);
|
2015-02-18 21:33:58 +05:30
|
|
|
start_dhcp_listen(cs);
|
2015-02-18 17:42:35 +05:30
|
|
|
if (send_renew(cs) < 0) {
|
2015-02-18 16:01:13 +05:30
|
|
|
log_warning("%s: Failed to send a renew request packet.",
|
|
|
|
client_config.interface);
|
|
|
|
return BTO_HARDFAIL;
|
|
|
|
}
|
2020-10-19 15:35:47 +05:30
|
|
|
cs->sent_renew_or_rebind = true;
|
2020-10-19 16:33:03 +05:30
|
|
|
++cs->num_dhcp_renews;
|
2017-08-24 12:06:31 +05:30
|
|
|
long long ts0 = nowts + (50 + nk_random_u32(&cs->rnd_state) % 20) * 1000;
|
2015-02-18 21:33:58 +05:30
|
|
|
cs->dhcp_wake_ts = ts0 < rbt ? ts0 : rbt;
|
2015-02-18 16:01:13 +05:30
|
|
|
return BTO_WAIT;
|
|
|
|
}
|
|
|
|
|
2020-10-19 15:35:47 +05:30
|
|
|
// Called to handle dhcp state timeouts, such as when RENEW or REBIND
|
|
|
|
// DHCPREQUESTs must be sent. Can return BTO_(WAIT|EXPIRED|HARDFAIL).
|
2015-02-18 16:01:13 +05:30
|
|
|
static int bound_timeout(struct client_state_t cs[static 1], long long nowts)
|
|
|
|
{
|
|
|
|
long long rnt = cs->leaseStartTime + cs->renewTime * 1000;
|
|
|
|
if (nowts < rnt) {
|
|
|
|
cs->dhcp_wake_ts = rnt;
|
|
|
|
return BTO_WAIT;
|
|
|
|
}
|
|
|
|
return renewing_timeout(cs, nowts);
|
2011-06-30 09:17:31 +05:30
|
|
|
}
|
|
|
|
|
2015-02-18 17:22:59 +05:30
|
|
|
static void get_leasetime(struct client_state_t cs[static 1],
|
|
|
|
struct dhcpmsg packet[static 1])
|
|
|
|
{
|
|
|
|
cs->lease = get_option_leasetime(packet);
|
|
|
|
cs->leaseStartTime = curms();
|
|
|
|
if (!cs->lease) {
|
|
|
|
log_line("%s: No lease time received; assuming 1h.",
|
|
|
|
client_config.interface);
|
|
|
|
cs->lease = 60 * 60;
|
|
|
|
} else {
|
|
|
|
if (cs->lease < 60) {
|
|
|
|
log_warning("Server sent lease of <1m. Forcing lease to 1m.",
|
|
|
|
client_config.interface);
|
|
|
|
cs->lease = 60;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Always use RFC2131 'default' values. It's not worth validating
|
|
|
|
// the remote server values, if they even exist, for sanity.
|
|
|
|
cs->renewTime = cs->lease >> 1;
|
|
|
|
cs->rebindTime = (cs->lease >> 3) * 0x7; // * 0.875
|
|
|
|
cs->dhcp_wake_ts = cs->leaseStartTime + cs->renewTime * 1000;
|
|
|
|
}
|
|
|
|
|
2020-10-21 16:17:11 +05:30
|
|
|
static bool validate_acknak(struct client_state_t cs[static 1],
|
|
|
|
struct dhcpmsg packet[static 1],
|
|
|
|
const char typemsg[static 1],
|
|
|
|
uint32_t srcaddr)
|
|
|
|
{
|
|
|
|
// Don't validate the server id. Instead validate that the
|
|
|
|
// yiaddr matches. Some networks have multiple servers
|
|
|
|
// that don't respect the serverid that was specified in
|
|
|
|
// our DHCPREQUEST.
|
|
|
|
if (memcmp(&packet->yiaddr, &cs->clientAddr, 4))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
int found;
|
|
|
|
uint32_t sid = get_option_serverid(packet, &found);
|
|
|
|
if (!found) {
|
|
|
|
log_line("%s: Received %s with no server id. Ignoring it.",
|
|
|
|
client_config.interface, typemsg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (cs->serverAddr != sid) {
|
|
|
|
cs->serverAddr = sid;
|
|
|
|
cs->srcAddr = srcaddr;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-18 17:22:59 +05:30
|
|
|
static int extend_packet(struct client_state_t cs[static 1],
|
|
|
|
struct dhcpmsg packet[static 1], uint8_t msgtype,
|
|
|
|
uint32_t srcaddr)
|
2011-06-30 09:17:31 +05:30
|
|
|
{
|
2015-02-13 09:58:54 +05:30
|
|
|
(void)srcaddr;
|
2011-07-18 20:17:35 +05:30
|
|
|
if (msgtype == DHCPACK) {
|
2020-10-21 16:17:11 +05:30
|
|
|
if (!validate_acknak(cs, packet, "DHCPACK", srcaddr))
|
2015-02-18 16:01:13 +05:30
|
|
|
return ANP_IGNORE;
|
2020-10-19 15:35:47 +05:30
|
|
|
cs->sent_renew_or_rebind = false;
|
2020-10-19 16:33:03 +05:30
|
|
|
cs->num_dhcp_renews = 0;
|
2015-02-18 17:22:59 +05:30
|
|
|
get_leasetime(cs, packet);
|
2011-06-30 09:17:31 +05:30
|
|
|
|
2015-02-18 20:26:38 +05:30
|
|
|
// Did we receive a lease with a different IP than we had before?
|
2015-02-18 17:22:59 +05:30
|
|
|
if (memcmp(&packet->yiaddr, &cs->clientAddr, 4)) {
|
2011-07-12 02:32:32 +05:30
|
|
|
char clibuf[INET_ADDRSTRLEN];
|
|
|
|
inet_ntop(AF_INET, &(struct in_addr){.s_addr=cs->clientAddr},
|
|
|
|
clibuf, sizeof clibuf);
|
2015-02-18 20:26:38 +05:30
|
|
|
log_line("%s: Server is now offering IP %s. Validating...",
|
2014-04-16 00:54:22 +05:30
|
|
|
client_config.interface, clibuf);
|
2015-02-18 16:01:13 +05:30
|
|
|
return ANP_CHECK_IP;
|
2011-07-06 21:11:49 +05:30
|
|
|
} else {
|
2014-04-16 00:54:22 +05:30
|
|
|
log_line("%s: Lease refreshed to %u seconds.",
|
|
|
|
client_config.interface, cs->lease);
|
2015-02-18 20:26:38 +05:30
|
|
|
if (arp_set_defense_mode(cs) < 0)
|
|
|
|
log_warning("%s: Failed to create ARP defense socket.",
|
|
|
|
client_config.interface);
|
2014-04-16 10:30:36 +05:30
|
|
|
stop_dhcp_listen(cs);
|
2015-02-18 16:01:13 +05:30
|
|
|
return ANP_SUCCESS;
|
2011-06-30 09:17:31 +05:30
|
|
|
}
|
2011-07-18 20:17:35 +05:30
|
|
|
} else if (msgtype == DHCPNAK) {
|
2020-10-21 16:17:11 +05:30
|
|
|
if (!validate_acknak(cs, packet, "DHCPNAK", srcaddr))
|
2015-02-18 16:01:13 +05:30
|
|
|
return ANP_IGNORE;
|
2020-10-19 15:35:47 +05:30
|
|
|
cs->sent_renew_or_rebind = false;
|
2020-10-19 16:33:03 +05:30
|
|
|
cs->num_dhcp_renews = 0;
|
2014-04-16 00:54:22 +05:30
|
|
|
log_line("%s: Our request was rejected. Searching for a new lease...",
|
|
|
|
client_config.interface);
|
2015-02-18 17:42:35 +05:30
|
|
|
reinit_selecting(cs, 3000);
|
2015-02-18 16:01:13 +05:30
|
|
|
return ANP_REJECTED;
|
2011-06-30 09:17:31 +05:30
|
|
|
}
|
2015-02-18 16:01:13 +05:30
|
|
|
return ANP_IGNORE;
|
2011-06-30 09:17:31 +05:30
|
|
|
}
|
|
|
|
|
2015-02-18 16:01:13 +05:30
|
|
|
static int selecting_packet(struct client_state_t cs[static 1],
|
|
|
|
struct dhcpmsg packet[static 1], uint8_t msgtype,
|
2015-02-18 17:22:59 +05:30
|
|
|
uint32_t srcaddr, bool is_requesting)
|
2011-06-30 09:17:31 +05:30
|
|
|
{
|
2020-10-19 12:41:51 +05:30
|
|
|
char clibuf[INET_ADDRSTRLEN];
|
|
|
|
char svrbuf[INET_ADDRSTRLEN];
|
|
|
|
char srcbuf[INET_ADDRSTRLEN];
|
|
|
|
int found;
|
2015-02-18 17:22:59 +05:30
|
|
|
if (!is_requesting && msgtype == DHCPOFFER) {
|
2011-07-26 10:34:59 +05:30
|
|
|
uint32_t sid = get_option_serverid(packet, &found);
|
2015-02-18 16:01:13 +05:30
|
|
|
if (!found) {
|
2014-04-16 00:54:22 +05:30
|
|
|
log_line("%s: Invalid offer received: it didn't have a server id.",
|
|
|
|
client_config.interface);
|
2015-02-18 16:01:13 +05:30
|
|
|
return ANP_IGNORE;
|
2011-06-30 09:17:31 +05:30
|
|
|
}
|
2020-10-19 15:09:08 +05:30
|
|
|
cs->xid = packet->xid; // Use for subsequent DHCPREQUESTs
|
2015-02-18 16:01:13 +05:30
|
|
|
cs->clientAddr = packet->yiaddr;
|
2015-02-18 17:22:59 +05:30
|
|
|
cs->serverAddr = sid;
|
2015-02-18 16:01:13 +05:30
|
|
|
cs->srcAddr = srcaddr;
|
|
|
|
cs->dhcp_wake_ts = curms();
|
|
|
|
cs->num_dhcp_requests = 0;
|
|
|
|
inet_ntop(AF_INET, &(struct in_addr){.s_addr=cs->clientAddr},
|
|
|
|
clibuf, sizeof clibuf);
|
|
|
|
inet_ntop(AF_INET, &(struct in_addr){.s_addr=cs->serverAddr},
|
|
|
|
svrbuf, sizeof svrbuf);
|
|
|
|
inet_ntop(AF_INET, &(struct in_addr){.s_addr=cs->srcAddr},
|
|
|
|
srcbuf, sizeof srcbuf);
|
|
|
|
log_line("%s: Received IP offer: %s from server %s via %s.",
|
|
|
|
client_config.interface, clibuf, svrbuf, srcbuf);
|
|
|
|
return ANP_SUCCESS;
|
2015-02-18 17:22:59 +05:30
|
|
|
} else if (is_requesting && msgtype == DHCPACK) {
|
2020-10-21 16:17:11 +05:30
|
|
|
if (!validate_acknak(cs, packet, "DHCPACK", srcaddr))
|
|
|
|
return ANP_IGNORE;
|
|
|
|
get_leasetime(cs, packet);
|
2015-02-18 17:22:59 +05:30
|
|
|
|
2020-10-21 16:17:11 +05:30
|
|
|
inet_ntop(AF_INET, &(struct in_addr){.s_addr=cs->clientAddr},
|
|
|
|
clibuf, sizeof clibuf);
|
|
|
|
inet_ntop(AF_INET, &(struct in_addr){.s_addr=cs->serverAddr},
|
|
|
|
svrbuf, sizeof svrbuf);
|
|
|
|
inet_ntop(AF_INET, &(struct in_addr){.s_addr=cs->srcAddr},
|
|
|
|
srcbuf, sizeof srcbuf);
|
|
|
|
log_line("%s: Received ACK: %s from server %s via %s. Validating...",
|
|
|
|
client_config.interface, clibuf, svrbuf, srcbuf);
|
|
|
|
return ANP_CHECK_IP;
|
2011-06-30 09:17:31 +05:30
|
|
|
}
|
2015-02-18 16:01:13 +05:30
|
|
|
return ANP_IGNORE;
|
2011-06-30 09:17:31 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// Triggered after a DHCP discover packet has been sent and no reply has
|
|
|
|
// been received within the response wait time. If we've not exceeded the
|
|
|
|
// maximum number of discover retransmits, then send another packet and wait
|
2020-10-20 16:22:30 +05:30
|
|
|
// again. Otherwise fail.
|
2015-02-18 16:01:13 +05:30
|
|
|
static int selecting_timeout(struct client_state_t cs[static 1],
|
2015-02-14 11:14:21 +05:30
|
|
|
long long nowts)
|
2011-06-30 09:17:31 +05:30
|
|
|
{
|
2017-01-19 15:35:35 +05:30
|
|
|
if (cs->program_init && cs->num_dhcp_requests >= 2) {
|
2020-10-20 16:22:30 +05:30
|
|
|
if (client_config.abort_if_no_lease)
|
2014-04-16 00:54:22 +05:30
|
|
|
suicide("%s: No lease; failing.", client_config.interface);
|
2011-06-30 09:17:31 +05:30
|
|
|
}
|
2015-02-18 17:42:35 +05:30
|
|
|
if (send_discover(cs) < 0) {
|
2014-04-16 03:29:15 +05:30
|
|
|
log_warning("%s: Failed to send a discover request packet.",
|
|
|
|
client_config.interface);
|
2015-02-18 16:01:13 +05:30
|
|
|
return SEL_FAIL;
|
2015-02-14 15:50:04 +05:30
|
|
|
}
|
2015-02-18 16:01:13 +05:30
|
|
|
cs->dhcp_wake_ts = nowts + delay_timeout(cs, cs->num_dhcp_requests);
|
|
|
|
cs->num_dhcp_requests++;
|
|
|
|
return SEL_SUCCESS;
|
2011-06-30 09:17:31 +05:30
|
|
|
}
|
|
|
|
|
2015-02-18 16:01:13 +05:30
|
|
|
// Called for a release signal during SELECTING or REQUESTING.
|
2015-02-18 17:42:35 +05:30
|
|
|
static void print_release(struct client_state_t cs[static 1])
|
2015-02-18 16:01:13 +05:30
|
|
|
{
|
|
|
|
log_line("%s: ndhc going to sleep. Wake it by sending a SIGUSR1.",
|
|
|
|
client_config.interface);
|
2015-02-18 17:42:35 +05:30
|
|
|
reinit_shared_deconfig(cs);
|
2015-02-18 16:01:13 +05:30
|
|
|
cs->dhcp_wake_ts = -1;
|
|
|
|
stop_dhcp_listen(cs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called for a release signal during BOUND, RENEWING, or REBINDING.
|
|
|
|
static int xmit_release(struct client_state_t cs[static 1])
|
2011-06-30 09:17:31 +05:30
|
|
|
{
|
2011-07-12 02:32:32 +05:30
|
|
|
char clibuf[INET_ADDRSTRLEN];
|
|
|
|
char svrbuf[INET_ADDRSTRLEN];
|
|
|
|
inet_ntop(AF_INET, &(struct in_addr){.s_addr=cs->clientAddr},
|
|
|
|
clibuf, sizeof clibuf);
|
|
|
|
inet_ntop(AF_INET, &(struct in_addr){.s_addr=cs->serverAddr},
|
|
|
|
svrbuf, sizeof svrbuf);
|
2014-04-16 00:54:22 +05:30
|
|
|
log_line("%s: Unicasting a release of %s to %s.", client_config.interface,
|
|
|
|
clibuf, svrbuf);
|
2015-02-18 17:42:35 +05:30
|
|
|
if (send_release(cs) < 0) {
|
2014-04-16 03:29:15 +05:30
|
|
|
log_warning("%s: Failed to send a release request packet.",
|
|
|
|
client_config.interface);
|
2015-02-18 16:01:13 +05:30
|
|
|
return -1;
|
2015-02-14 15:50:04 +05:30
|
|
|
}
|
2011-07-06 03:59:06 +05:30
|
|
|
print_release(cs);
|
2015-02-18 16:01:13 +05:30
|
|
|
return 0;
|
2011-06-30 09:17:31 +05:30
|
|
|
}
|
|
|
|
|
2015-02-18 16:01:13 +05:30
|
|
|
// Called for a renewing signal during BOUND or RELEASED
|
|
|
|
static int frenew(struct client_state_t cs[static 1], bool is_bound)
|
2011-06-30 09:17:31 +05:30
|
|
|
{
|
2015-02-18 16:01:13 +05:30
|
|
|
if (is_bound) {
|
2014-04-16 00:54:22 +05:30
|
|
|
log_line("%s: Forcing a DHCP renew...", client_config.interface);
|
2014-04-16 10:30:36 +05:30
|
|
|
start_dhcp_listen(cs);
|
2015-02-18 17:42:35 +05:30
|
|
|
if (send_renew(cs) < 0) {
|
2014-04-16 03:29:15 +05:30
|
|
|
log_warning("%s: Failed to send a renew request packet.",
|
|
|
|
client_config.interface);
|
2015-02-18 16:01:13 +05:30
|
|
|
return -1;
|
2015-02-14 15:50:04 +05:30
|
|
|
}
|
2015-02-18 16:01:13 +05:30
|
|
|
} else { // RELEASED
|
2015-02-18 17:42:35 +05:30
|
|
|
reinit_selecting(cs, 0);
|
2015-02-18 16:01:13 +05:30
|
|
|
}
|
|
|
|
return 0;
|
2011-06-30 09:17:31 +05:30
|
|
|
}
|
|
|
|
|
2015-02-18 16:01:13 +05:30
|
|
|
// If we have a lease, check to see if our gateway is still valid via ARP.
|
|
|
|
// If it fails, state -> SELECTING.
|
|
|
|
static int ifup_action(struct client_state_t cs[static 1])
|
2011-07-05 07:40:14 +05:30
|
|
|
{
|
2015-02-18 16:01:13 +05:30
|
|
|
if (cs->routerAddr && cs->serverAddr) {
|
2020-10-19 13:55:15 +05:30
|
|
|
const bool fp_server = cs->server_arp_state == ARP_FOUND;
|
|
|
|
const bool fp_router = (cs->routerAddr != cs->serverAddr) ? (cs->router_arp_state == ARP_FOUND) : fp_server;
|
|
|
|
if (!fp_server && !fp_router)
|
2020-10-19 12:37:23 +05:30
|
|
|
goto no_fingerprint;
|
2017-04-10 19:27:52 +05:30
|
|
|
if (cs->init_fingerprint_inprogress) {
|
|
|
|
suicide("%s: Carrier lost during initial fingerprint. Forcing restart.",
|
|
|
|
client_config.interface);
|
|
|
|
}
|
2015-02-18 17:42:35 +05:30
|
|
|
if (arp_gw_check(cs) >= 0) {
|
2014-04-16 00:54:22 +05:30
|
|
|
log_line("%s: Interface is back. Revalidating lease...",
|
2011-07-18 19:59:36 +05:30
|
|
|
client_config.interface);
|
2015-02-18 16:01:13 +05:30
|
|
|
return IFUP_REVALIDATE;
|
2015-02-14 16:07:06 +05:30
|
|
|
} else {
|
2015-02-14 11:14:21 +05:30
|
|
|
log_warning("%s: arp_gw_check could not make arp socket.",
|
|
|
|
client_config.interface);
|
2015-02-18 16:01:13 +05:30
|
|
|
return IFUP_FAIL;
|
2015-02-14 16:07:06 +05:30
|
|
|
}
|
2011-07-06 01:10:57 +05:30
|
|
|
}
|
2020-10-19 12:37:23 +05:30
|
|
|
no_fingerprint:
|
2014-04-16 00:54:22 +05:30
|
|
|
log_line("%s: Interface is back. Searching for new lease...",
|
2011-07-12 02:03:57 +05:30
|
|
|
client_config.interface);
|
2015-02-18 16:01:13 +05:30
|
|
|
return IFUP_NEWLEASE;
|
2011-07-05 07:40:14 +05:30
|
|
|
}
|
|
|
|
|
2020-10-20 13:53:55 +05:30
|
|
|
// If ret == 0: do nothing
|
|
|
|
// ret == 1: ret = COR_ERROR; scrReturn(ret); continue
|
|
|
|
// ret == 2: goto skip_to_released
|
|
|
|
// ret == 3: break
|
|
|
|
static int signal_check_nolease(struct client_state_t cs[static 1])
|
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
int s = signals_flagged();
|
|
|
|
if (s == SIGNAL_NONE) break;
|
|
|
|
if (s == SIGNAL_EXIT) signal_exit(EXIT_SUCCESS);
|
|
|
|
if (s == SIGNAL_RELEASE) {
|
|
|
|
print_release(cs);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
static int signal_check_havelease(struct client_state_t cs[static 1])
|
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
int s = signals_flagged();
|
|
|
|
if (s == SIGNAL_NONE) break;
|
|
|
|
if (s == SIGNAL_EXIT) signal_exit(EXIT_SUCCESS);
|
|
|
|
if (s == SIGNAL_RELEASE) {
|
|
|
|
int r = xmit_release(cs);
|
|
|
|
if (r) return 1;
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
if (s == SIGNAL_RENEW) {
|
|
|
|
int r = frenew(cs, true);
|
|
|
|
if (r) return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
static int signal_check_released(struct client_state_t cs[static 1])
|
|
|
|
{
|
|
|
|
(void)cs;
|
|
|
|
for (;;) {
|
|
|
|
int s = signals_flagged();
|
|
|
|
if (s == SIGNAL_NONE) break;
|
|
|
|
if (s == SIGNAL_EXIT) signal_exit(EXIT_SUCCESS);
|
|
|
|
if (s == SIGNAL_RENEW) return 3;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#define SIGNAL_CHECK(NAME) \
|
|
|
|
{ \
|
|
|
|
int tt = signal_check_ ## NAME(cs); \
|
|
|
|
if (tt == 1) { \
|
|
|
|
ret = COR_ERROR; \
|
|
|
|
scrReturn(ret); \
|
|
|
|
continue; \
|
|
|
|
} \
|
|
|
|
if (tt == 2) goto skip_to_released; \
|
|
|
|
if (tt == 3) break; \
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:01:13 +05:30
|
|
|
#define BAD_STATE() suicide("%s(%d): bad state", __func__, __LINE__)
|
2011-06-30 09:17:31 +05:30
|
|
|
|
2015-02-18 16:01:13 +05:30
|
|
|
// XXX: Should be re-entrant so as to handle multiple servers.
|
|
|
|
int dhcp_handle(struct client_state_t cs[static 1], long long nowts,
|
2015-02-18 21:32:13 +05:30
|
|
|
bool sev_dhcp, struct dhcpmsg dhcp_packet[static 1],
|
|
|
|
uint8_t dhcp_msgtype, uint32_t dhcp_srcaddr, bool sev_arp,
|
2020-10-20 13:53:55 +05:30
|
|
|
bool force_fingerprint, bool dhcp_timeout, bool arp_timeout)
|
2011-06-30 09:17:31 +05:30
|
|
|
{
|
2015-02-18 16:01:13 +05:30
|
|
|
scrBegin;
|
|
|
|
reinit:
|
|
|
|
// We're in the SELECTING state here.
|
|
|
|
for (;;) {
|
|
|
|
int ret = COR_SUCCESS;
|
2020-10-20 13:53:55 +05:30
|
|
|
SIGNAL_CHECK(nolease);
|
2015-02-18 16:01:13 +05:30
|
|
|
if (sev_dhcp) {
|
|
|
|
int r = selecting_packet(cs, dhcp_packet, dhcp_msgtype,
|
2015-02-18 17:22:59 +05:30
|
|
|
dhcp_srcaddr, false);
|
2015-02-18 16:01:13 +05:30
|
|
|
if (r == ANP_SUCCESS) {
|
|
|
|
// Send a request packet to the answering DHCP server.
|
|
|
|
sev_dhcp = false;
|
|
|
|
goto skip_to_requesting;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dhcp_timeout) {
|
|
|
|
int r = selecting_timeout(cs, nowts);
|
|
|
|
if (r == SEL_SUCCESS) {
|
|
|
|
} else if (r == SEL_FAIL) {
|
|
|
|
ret = COR_ERROR;
|
|
|
|
} else BAD_STATE();
|
|
|
|
}
|
|
|
|
scrReturn(ret);
|
|
|
|
}
|
|
|
|
scrReturn(COR_SUCCESS);
|
|
|
|
// We're in the REQUESTING state here.
|
|
|
|
for (;;) {
|
|
|
|
int ret;
|
|
|
|
skip_to_requesting:
|
|
|
|
ret = COR_SUCCESS;
|
2020-10-20 13:53:55 +05:30
|
|
|
SIGNAL_CHECK(nolease);
|
2015-02-18 16:01:13 +05:30
|
|
|
if (sev_dhcp) {
|
2015-02-18 17:22:59 +05:30
|
|
|
int r = selecting_packet(cs, dhcp_packet, dhcp_msgtype,
|
|
|
|
dhcp_srcaddr, true);
|
2015-02-18 16:01:13 +05:30
|
|
|
if (r == ANP_IGNORE) {
|
|
|
|
} else if (r == ANP_CHECK_IP) {
|
|
|
|
if (arp_check(cs, dhcp_packet) < 0) {
|
|
|
|
log_warning("%s: Failed to make arp socket. Searching for new lease...",
|
|
|
|
client_config.interface);
|
2015-02-18 17:42:35 +05:30
|
|
|
reinit_selecting(cs, 3000);
|
2015-02-18 16:01:13 +05:30
|
|
|
sev_dhcp = false;
|
|
|
|
goto reinit;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} else BAD_STATE();
|
|
|
|
}
|
|
|
|
if (dhcp_timeout) {
|
|
|
|
// Send a request packet to the answering DHCP server.
|
|
|
|
int r = requesting_timeout(cs, nowts);
|
|
|
|
if (r == REQ_SUCCESS) {
|
|
|
|
} else if (r == REQ_TIMEOUT) {
|
|
|
|
// We timed out. Send another packet.
|
|
|
|
sev_dhcp = false;
|
|
|
|
goto reinit;
|
|
|
|
} else if (r == REQ_FAIL) {
|
|
|
|
// Failed to send packet. Sleep and retry.
|
|
|
|
ret = COR_ERROR;
|
|
|
|
} else BAD_STATE();
|
|
|
|
}
|
|
|
|
scrReturn(ret);
|
|
|
|
}
|
|
|
|
scrReturn(COR_SUCCESS);
|
|
|
|
// We're checking to see if there's a conflict for our IP. Technically,
|
|
|
|
// this is still in REQUESTING.
|
|
|
|
for (;;) {
|
|
|
|
int ret;
|
|
|
|
ret = COR_SUCCESS;
|
2020-10-20 13:53:55 +05:30
|
|
|
SIGNAL_CHECK(nolease);
|
2015-02-18 16:01:13 +05:30
|
|
|
if (sev_dhcp) {
|
|
|
|
// XXX: Maybe I can think of something to do here. Would
|
|
|
|
// be more relevant if we tracked multiple dhcp servers.
|
|
|
|
}
|
|
|
|
if (sev_arp) {
|
|
|
|
int r = arp_do_collision_check(cs);
|
|
|
|
if (r == ARPR_OK) {
|
|
|
|
} else if (r == ARPR_CONFLICT) {
|
|
|
|
// XXX: If we tracked multiple DHCP servers, then we
|
|
|
|
// could fall back on another one.
|
2015-02-18 17:42:35 +05:30
|
|
|
reinit_selecting(cs, 0);
|
2015-02-18 16:01:13 +05:30
|
|
|
sev_dhcp = false;
|
|
|
|
goto reinit;
|
|
|
|
} else if (r == ARPR_FAIL) {
|
|
|
|
ret = COR_ERROR;
|
|
|
|
scrReturn(ret);
|
|
|
|
continue;
|
|
|
|
} else BAD_STATE();
|
|
|
|
}
|
|
|
|
if (arp_timeout) {
|
|
|
|
int r = arp_collision_timeout(cs, nowts);
|
|
|
|
if (r == ARPR_FREE) {
|
2017-02-24 18:09:14 +05:30
|
|
|
arp_query_gateway(cs);
|
2017-02-24 16:57:15 +05:30
|
|
|
arp_announce(cs);
|
2015-02-18 16:01:13 +05:30
|
|
|
break;
|
|
|
|
} else if (r == ARPR_OK) {
|
|
|
|
} else if (r == ARPR_FAIL) {
|
|
|
|
ret = COR_ERROR;
|
|
|
|
scrReturn(ret);
|
|
|
|
continue;
|
|
|
|
} else BAD_STATE();
|
|
|
|
}
|
|
|
|
if (dhcp_timeout) {
|
|
|
|
// Send a request packet to the answering DHCP server.
|
|
|
|
int r = requesting_timeout(cs, nowts);
|
|
|
|
if (r == REQ_SUCCESS) {
|
|
|
|
} else if (r == REQ_TIMEOUT) {
|
|
|
|
// We timed out. Send another packet.
|
|
|
|
sev_dhcp = false;
|
|
|
|
goto reinit;
|
|
|
|
} else if (r == REQ_FAIL) {
|
|
|
|
// Failed to send packet. Sleep and retry.
|
|
|
|
ret = COR_ERROR;
|
|
|
|
} else BAD_STATE();
|
|
|
|
}
|
|
|
|
scrReturn(ret);
|
|
|
|
}
|
|
|
|
scrReturn(COR_SUCCESS);
|
|
|
|
// We're in the BOUND, RENEWING, or REBINDING states here.
|
|
|
|
for (;;) {
|
|
|
|
int ret = COR_SUCCESS;
|
2020-10-20 13:53:55 +05:30
|
|
|
SIGNAL_CHECK(havelease);
|
2020-10-19 15:35:47 +05:30
|
|
|
if (sev_dhcp && cs->sent_renew_or_rebind) {
|
2015-02-18 17:22:59 +05:30
|
|
|
int r = extend_packet(cs, dhcp_packet, dhcp_msgtype, dhcp_srcaddr);
|
2015-02-18 16:01:13 +05:30
|
|
|
if (r == ANP_SUCCESS || r == ANP_IGNORE) {
|
|
|
|
} else if (r == ANP_REJECTED) {
|
|
|
|
sev_dhcp = false;
|
|
|
|
goto reinit;
|
|
|
|
} else if (r == ANP_CHECK_IP) {
|
|
|
|
if (arp_check(cs, dhcp_packet) < 0) {
|
|
|
|
log_warning("%s: Failed to make arp socket. Searching for new lease...",
|
|
|
|
client_config.interface);
|
2015-02-18 17:42:35 +05:30
|
|
|
reinit_selecting(cs, 3000);
|
2015-02-18 16:01:13 +05:30
|
|
|
sev_dhcp = false;
|
|
|
|
goto reinit;
|
|
|
|
}
|
|
|
|
} else BAD_STATE();
|
|
|
|
}
|
|
|
|
if (sev_arp) {
|
|
|
|
int r;
|
|
|
|
r = arp_do_defense(cs);
|
|
|
|
if (r == ARPR_OK) {
|
|
|
|
} else if (r == ARPR_CONFLICT) {
|
2015-02-18 17:42:35 +05:30
|
|
|
reinit_selecting(cs, 0);
|
2015-02-18 16:01:13 +05:30
|
|
|
sev_dhcp = false;
|
|
|
|
goto reinit;
|
|
|
|
} else if (r == ARPR_FAIL) {
|
|
|
|
ret = COR_ERROR;
|
|
|
|
scrReturn(ret);
|
|
|
|
continue;
|
|
|
|
} else BAD_STATE();
|
2020-10-19 13:55:15 +05:30
|
|
|
if (cs->router_arp_state == ARP_QUERY || cs->server_arp_state == ARP_QUERY) {
|
2015-02-18 16:01:13 +05:30
|
|
|
r = arp_do_gw_query(cs);
|
|
|
|
if (r == ARPR_OK) {
|
|
|
|
} else if (r == ARPR_FREE) {
|
2017-04-10 19:27:52 +05:30
|
|
|
log_line("%s: Network fingerprinting complete.", client_config.interface);
|
|
|
|
cs->init_fingerprint_inprogress = false;
|
2015-02-18 16:01:13 +05:30
|
|
|
} else if (r == ARPR_FAIL) {
|
|
|
|
ret = COR_ERROR;
|
|
|
|
scrReturn(ret);
|
|
|
|
continue;
|
|
|
|
} else BAD_STATE();
|
|
|
|
} else if (cs->check_fingerprint) {
|
|
|
|
r = arp_do_gw_check(cs);
|
|
|
|
if (r == ARPR_OK) {
|
|
|
|
} else if (r == ARPR_FREE) {
|
|
|
|
cs->check_fingerprint = false;
|
|
|
|
} else if (r == ARPR_CONFLICT) {
|
|
|
|
cs->check_fingerprint = false;
|
2015-02-18 17:42:35 +05:30
|
|
|
reinit_selecting(cs, 0);
|
2015-02-18 16:01:13 +05:30
|
|
|
sev_dhcp = false;
|
|
|
|
goto reinit;
|
|
|
|
} else if (r == ARPR_FAIL) {
|
|
|
|
ret = COR_ERROR;
|
|
|
|
scrReturn(ret);
|
|
|
|
continue;
|
|
|
|
} else BAD_STATE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (arp_timeout) {
|
2017-02-24 17:18:48 +05:30
|
|
|
if (cs->sent_first_announce && cs->sent_second_announce)
|
|
|
|
arp_defense_timeout(cs, nowts);
|
|
|
|
else
|
2017-02-24 16:57:15 +05:30
|
|
|
arp_announce_timeout(cs, nowts);
|
2017-02-24 18:09:14 +05:30
|
|
|
if (!cs->sent_gw_query)
|
|
|
|
arp_query_gateway_timeout(cs, nowts);
|
2020-10-19 13:55:15 +05:30
|
|
|
else if (cs->router_arp_state == ARP_QUERY || cs->server_arp_state == ARP_QUERY) {
|
2015-02-18 16:01:13 +05:30
|
|
|
int r = arp_gw_query_timeout(cs, nowts);
|
|
|
|
if (r == ARPR_OK) {
|
|
|
|
} else if (r == ARPR_FAIL) {
|
|
|
|
ret = COR_ERROR;
|
|
|
|
scrReturn(ret);
|
|
|
|
continue;
|
|
|
|
} else BAD_STATE();
|
|
|
|
} else if (cs->check_fingerprint) {
|
|
|
|
int r = arp_gw_check_timeout(cs, nowts);
|
|
|
|
if (r == ARPR_OK) {
|
|
|
|
} else if (r == ARPR_CONFLICT) {
|
|
|
|
cs->check_fingerprint = false;
|
2015-02-18 17:42:35 +05:30
|
|
|
reinit_selecting(cs, 0);
|
2015-02-18 16:01:13 +05:30
|
|
|
sev_dhcp = false;
|
|
|
|
goto reinit;
|
|
|
|
} else if (r == ARPR_FAIL) {
|
|
|
|
ret = COR_ERROR;
|
|
|
|
scrReturn(ret);
|
|
|
|
continue;
|
|
|
|
} else BAD_STATE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (force_fingerprint) {
|
|
|
|
int r = ifup_action(cs);
|
|
|
|
if (r == IFUP_REVALIDATE) {
|
|
|
|
} else if (r == IFUP_NEWLEASE) {
|
2015-02-18 17:42:22 +05:30
|
|
|
if (ifchange_deconfig(cs) < 0) {
|
|
|
|
// Likely only to fail because of rfkill.
|
2015-02-18 16:01:13 +05:30
|
|
|
ret = COR_ERROR;
|
|
|
|
scrReturn(ret);
|
|
|
|
}
|
2015-02-18 17:42:22 +05:30
|
|
|
reinit_selecting(cs, 0);
|
2015-02-18 16:01:13 +05:30
|
|
|
sev_dhcp = false;
|
|
|
|
goto reinit;
|
|
|
|
} else if (r == IFUP_FAIL) {
|
|
|
|
ret = COR_ERROR;
|
|
|
|
scrReturn(ret);
|
|
|
|
continue;
|
|
|
|
} else BAD_STATE();
|
|
|
|
}
|
|
|
|
if (dhcp_timeout) {
|
2020-10-19 15:35:47 +05:30
|
|
|
int r = bound_timeout(cs, nowts);
|
2015-02-18 16:01:13 +05:30
|
|
|
if (r == BTO_WAIT) {
|
|
|
|
} else if (r == BTO_EXPIRED) {
|
|
|
|
sev_dhcp = false;
|
|
|
|
goto reinit;
|
|
|
|
} else if (r == BTO_HARDFAIL) {
|
|
|
|
ret = COR_ERROR;
|
|
|
|
} else
|
|
|
|
BAD_STATE();
|
|
|
|
}
|
|
|
|
scrReturn(ret);
|
|
|
|
}
|
|
|
|
sev_dhcp = false;
|
|
|
|
goto reinit;
|
2015-02-18 18:01:19 +05:30
|
|
|
// We're in the RELEASED state here.
|
|
|
|
for (;;) {
|
|
|
|
int ret;
|
|
|
|
skip_to_released:
|
|
|
|
ret = COR_SUCCESS;
|
2020-10-20 13:53:55 +05:30
|
|
|
SIGNAL_CHECK(released);
|
2015-02-18 18:01:19 +05:30
|
|
|
scrReturn(ret);
|
|
|
|
}
|
|
|
|
sev_dhcp = false;
|
|
|
|
goto reinit;
|
2015-02-18 16:01:13 +05:30
|
|
|
scrFinish(COR_SUCCESS);
|
2011-06-30 09:17:31 +05:30
|
|
|
}
|
|
|
|
|
2011-07-11 21:01:27 +05:30
|
|
|
|