From: krw Date: Sat, 17 Jun 2017 20:23:17 +0000 (+0000) Subject: Shuffle dhcp[offer|ack|nak]() functions together for easy reference. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=ea1fbf107b9efb16aa8a01703dc62f2878e5943a;p=openbsd Shuffle dhcp[offer|ack|nak]() functions together for easy reference. --- diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 84f2831cb7c..fe02ad0d21f 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.431 2017/06/17 17:10:26 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.432 2017/06/17 20:23:17 krw Exp $ */ /* * Copyright 2004 Henning Brauer @@ -873,6 +873,45 @@ state_selecting(struct interface_info *ifi) send_request(ifi); } +void +dhcpoffer(struct interface_info *ifi, struct option_data *options, char *info) +{ + struct client_lease *lease; + time_t stop_selecting; + + if (ifi->state != S_SELECTING) { +#ifdef DEBUG + log_debug("Unexpected %s. State #%d.", info, client->state); +#endif /* DEBUG */ + return; + } + + log_info("%s", info); + + lease = packet_to_lease(ifi, options); + if (lease != NULL) { + if (ifi->offer == NULL) { + ifi->offer = lease; + } else if (lease->address.s_addr == + ifi->requested_address.s_addr) { + free_client_lease(ifi->offer); + ifi->offer = lease; + } + if (ifi->offer != lease) { + make_decline(ifi, lease); + send_decline(ifi); + free_client_lease(lease); + } + } + + /* Figure out when we're supposed to stop selecting. */ + stop_selecting = ifi->first_sending + config->select_interval; + if (stop_selecting <= time(NULL)) + state_selecting(ifi); + else + set_timeout(stop_selecting, state_selecting, ifi); +} + void dhcpack(struct interface_info *ifi, struct option_data *options, char *info) { @@ -907,6 +946,43 @@ dhcpack(struct interface_info *ifi, struct option_data *options, char *info) bind_lease(ifi); } +void +dhcpnak(struct interface_info *ifi, struct option_data *options, char *info) +{ + if (ifi->state != S_REBOOTING && + ifi->state != S_REQUESTING && + ifi->state != S_RENEWING && + ifi->state != S_REBINDING) { +#ifdef DEBUG + log_debug("Unexpected %s. State #%d", info, client->state); +#endif /* DEBUG */ + return; + } + + if (!ifi->active) { +#ifdef DEBUG + log_debug("Unexpected %s. No active lease.", info); +#endif /* DEBUG */ + return; + } + + log_info("%s", info); + + /* XXX Do we really want to remove a NAK'd lease from the database? */ + if (!ifi->active->is_static) { + TAILQ_REMOVE(&ifi->leases, ifi->active, next); + free_client_lease(ifi->active); + } + + ifi->active = NULL; + + /* Stop sending DHCPREQUEST packets. */ + cancel_timeout(); + + ifi->state = S_INIT; + state_init(ifi); +} + void bind_lease(struct interface_info *ifi) { @@ -1084,45 +1160,6 @@ state_bound(struct interface_info *ifi) send_request(ifi); } -void -dhcpoffer(struct interface_info *ifi, struct option_data *options, char *info) -{ - struct client_lease *lease; - time_t stop_selecting; - - if (ifi->state != S_SELECTING) { -#ifdef DEBUG - log_debug("Unexpected %s. State #%d.", info, client->state); -#endif /* DEBUG */ - return; - } - - log_info("%s", info); - - lease = packet_to_lease(ifi, options); - if (lease != NULL) { - if (ifi->offer == NULL) { - ifi->offer = lease; - } else if (lease->address.s_addr == - ifi->requested_address.s_addr) { - free_client_lease(ifi->offer); - ifi->offer = lease; - } - if (ifi->offer != lease) { - make_decline(ifi, lease); - send_decline(ifi); - free_client_lease(lease); - } - } - - /* Figure out when we're supposed to stop selecting. */ - stop_selecting = ifi->first_sending + config->select_interval; - if (stop_selecting <= time(NULL)) - state_selecting(ifi); - else - set_timeout(stop_selecting, state_selecting, ifi); -} - int addressinuse(struct interface_info *ifi, struct in_addr address, char *ifname) { @@ -1295,43 +1332,6 @@ packet_to_lease(struct interface_info *ifi, struct option_data *options) return NULL; } -void -dhcpnak(struct interface_info *ifi, struct option_data *options, char *info) -{ - if (ifi->state != S_REBOOTING && - ifi->state != S_REQUESTING && - ifi->state != S_RENEWING && - ifi->state != S_REBINDING) { -#ifdef DEBUG - log_debug("Unexpected %s. State #%d", info, client->state); -#endif /* DEBUG */ - return; - } - - if (!ifi->active) { -#ifdef DEBUG - log_debug("Unexpected %s. No active lease.", info); -#endif /* DEBUG */ - return; - } - - log_info("%s", info); - - /* XXX Do we really want to remove a NAK'd lease from the database? */ - if (!ifi->active->is_static) { - TAILQ_REMOVE(&ifi->leases, ifi->active, next); - free_client_lease(ifi->active); - } - - ifi->active = NULL; - - /* Stop sending DHCPREQUEST packets. */ - cancel_timeout(); - - ifi->state = S_INIT; - state_init(ifi); -} - /* * Send out a DHCPDISCOVER packet, and set a timeout to send out another * one after the right interval has expired. If we don't get an offer by