diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2013-05-02 16:35:28 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2013-05-02 16:35:28 +0000 |
commit | 8d9f399f7f91f12b17648750f292c377bfbbb3bf (patch) | |
tree | 50c9df89147f3f84e406832b86eb45963f3bf474 /sbin/dhclient/dhclient.c | |
parent | 3a4fe79c2140b22104c6748e938e2cf520e5ee36 (diff) |
Bunch of comment/whitespace cleanup. Eliminate some misleading or
pointless ones, make multiline comments readable, nuke '...' in
favour of '.', etc.
Diffstat (limited to 'sbin/dhclient/dhclient.c')
-rw-r--r-- | sbin/dhclient/dhclient.c | 167 |
1 files changed, 75 insertions, 92 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 7b392f9a0d8..d0c45f8bda6 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.245 2013/05/02 14:48:35 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.246 2013/05/02 16:35:27 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -63,7 +63,7 @@ #include <resolv.h> #define CLIENT_PATH "PATH=/usr/bin:/usr/sbin:/bin:/sbin" -#define DEFAULT_LEASE_TIME 43200 /* 12 hours... */ +#define DEFAULT_LEASE_TIME 43200 /* 12 hours. */ #define TIME_MAX 2147483647 char *path_dhclient_conf = _PATH_DHCLIENT_CONF; @@ -487,7 +487,7 @@ main(int argc, char *argv[]) /* set up the interface */ discover_interface(); - /* Register the interface... */ + /* Register the interface. */ if_register_receive(); if_register_send(); @@ -567,39 +567,11 @@ usage(void) } /* - * Individual States: - * - * Each routine is called from the dhclient_state_machine() in one of - * these conditions: - * -> entering INIT state - * -> recvpacket_flag == 0: timeout in this state - * -> otherwise: received a packet in this state - * - * Return conditions as handled by dhclient_state_machine(): - * Returns 1, sendpacket_flag = 1: send packet, reset timer. - * Returns 1, sendpacket_flag = 0: just reset the timer (wait for a milestone). - * Returns 0: finish the nap which was interrupted for no good reason. - * - * Several per-interface variables are used to keep track of the process: - * active_lease: the lease that is being used on the interface - * (null pointer if not configured yet). - * offered_leases: leases corresponding to DHCPOFFER messages that have - * been sent to us by DHCP servers. - * acked_leases: leases corresponding to DHCPACK messages that have been - * sent to us by DHCP servers. - * sendpacket: DHCP packet we're trying to send. - * destination: IP address to send sendpacket to - * In addition, there are several relevant per-lease variables. - * T1_expiry, T2_expiry, lease_expiry: lease milestones - * In the active lease, these control the process of renewing the lease; - * In leases on the acked_leases list, this simply determines when we - * can no longer legitimately use the lease. + * Called when the interface link becomes active. */ void state_reboot(void) { - /* Cancel all timeouts, since a link state change gets us here - and can happen anytime. */ cancel_timeout(); deleting.s_addr = INADDR_ANY; adding.s_addr = INADDR_ANY; @@ -622,8 +594,7 @@ state_reboot(void) } /* - * Called when a lease has completely expired and we've - * been unable to renew it. + * Called when a lease has completely expired and we've been unable to renew it. */ void state_init(void) @@ -640,8 +611,8 @@ state_init(void) } /* - * state_selecting is called when one or more DHCPOFFER packets - * have been received and a configurable period of time has passed. + * Called when one or more DHCPOFFER packets have been received and a + * configurable period of time has passed. */ void state_selecting(void) @@ -649,8 +620,6 @@ state_selecting(void) struct client_lease *lp, *picked; time_t cur_time; - /* Cancel state_selecting and send_discover timeouts, since either - one could have got us here. */ cancel_timeout(); /* Take the first DHCPOFFER, discard the rest. */ @@ -694,7 +663,6 @@ state_selecting(void) return; } - /* Go to the REQUESTING state. */ client->destination.s_addr = INADDR_BROADCAST; client->state = S_REQUESTING; client->first_sending = cur_time; @@ -746,16 +714,20 @@ dhcpack(struct in_addr client_addr, struct option_data *options, char *info) getULong(client->new->options[DHO_DHCP_LEASE_TIME].data); else client->new->expiry = DEFAULT_LEASE_TIME; - /* A number that looks negative here is really just very large, - because the lease expiry offset is unsigned. */ + /* + * A number that looks negative here is really just very large, + * because the lease expiry offset is unsigned. + */ if (client->new->expiry < 0) client->new->expiry = TIME_MAX; /* XXX should be fixed by resetting the client state */ if (client->new->expiry < 60) client->new->expiry = 60; - /* Take the server-provided renewal time if there is one; - otherwise figure it out according to the spec. */ + /* + * Take the server-provided renewal time if there is one; + * otherwise figure it out according to the spec. + */ if (client->new->options[DHO_DHCP_RENEWAL_TIME].len) client->new->renewal = getULong(client->new->options[DHO_DHCP_RENEWAL_TIME].data); @@ -844,15 +816,13 @@ bind_lease(void) } /* - * state_bound is called when we've successfully bound to a particular - * lease, but the renewal time on that lease has expired. We are - * expected to unicast a DHCPREQUEST to the server that gave us our - * original lease. + * Called when we've successfully bound to a particular lease, but the renewal + * time on that lease has expired. We are expected to unicast a DHCPREQUEST to + * the server that gave us our original lease. */ void state_bound(void) { - /* T1 has expired. */ client->xid = arc4random(); make_request(client->active); @@ -905,8 +875,10 @@ dhcpoffer(struct in_addr client_addr, struct option_data *options, char *info) if (subnet_exists(lease)) return; - /* If this lease was acquired through a BOOTREPLY, record that - fact. */ + /* + * If this lease was acquired through a BOOTREPLY, record that + * fact. + */ if (!options[DHO_DHCP_MESSAGE_TYPE].len) lease->is_bootp = 1; @@ -925,9 +897,6 @@ dhcpoffer(struct in_addr client_addr, struct option_data *options, char *info) note("%s", info); - /* If the selecting interval has expired, go immediately to - state_selecting(). Otherwise, time out into - state_selecting at the select interval. */ if (stop_selecting <= time(NULL)) state_selecting(); else { @@ -1056,7 +1025,7 @@ dhcpnak(struct in_addr client_addr, struct option_data *options, char *info) free_client_lease(client->active); client->active = NULL; - /* Stop sending DHCPREQUEST packets... */ + /* Stop sending DHCPREQUEST packets. */ cancel_timeout(); client->state = S_INIT; @@ -1132,9 +1101,8 @@ send_discover(void) } /* - * state_panic gets called if we haven't received any offers in a preset - * amount of time. When this happens, we try to use existing leases - * that haven't yet expired. + * Called if we haven't received any offers in a preset amount of time. When + * this happens, we try to use existing leases that haven't yet expired. */ void state_panic(void) @@ -1145,8 +1113,10 @@ state_panic(void) time(&cur_time); note("No acceptable DHCPOFFERS received."); - /* We may not have an active lease, but we may have some - predefined leases that we can try. */ + /* + * We may not have an active lease, but we may have some predefined + * leases that we can try. + */ if (!client->active && !TAILQ_EMPTY(&client->leases)) goto activate_next; @@ -1186,17 +1156,20 @@ state_panic(void) } activate_next: - /* Otherwise, put the active lease at the end of the - lease list, and try another lease.. */ + /* + * Otherwise, put the active lease at the end of the lease + * list, and try another lease. + */ if (client->active) TAILQ_INSERT_TAIL(&client->leases, client->active, next); client->active = TAILQ_FIRST(&client->leases); TAILQ_REMOVE(&client->leases, client->active, next); - /* If we already tried this lease, we've exhausted the - set of leases, so we might as well give up for - now. */ + /* + * If we already tried this lease, we've exhausted the set of + * leases, so we might as well give up for now. + */ if (client->active == loop) break; else if (!loop) @@ -1225,16 +1198,19 @@ send_request(void) /* Figure out how long it's been since we started transmitting. */ interval = (int)(cur_time - client->first_sending); - /* If we're in the INIT-REBOOT or REQUESTING state and we're - past the reboot timeout, go to INIT and see if we can - DISCOVER an address... */ - /* XXX In the INIT-REBOOT state, if we don't get an ACK, it - means either that we're on a network with no DHCP server, - or that our server is down. In the latter case, assuming - that there is a backup DHCP server, DHCPDISCOVER will get - us a new address, but we could also have successfully - reused our old address. In the former case, we're hosed - anyway. This is not a win-prone situation. */ + /* + * If we're in the INIT-REBOOT or REQUESTING state and we're + * past the reboot timeout, go to INIT and see if we can + * DISCOVER an address. + * + * XXX In the INIT-REBOOT state, if we don't get an ACK, it + * means either that we're on a network with no DHCP server, + * or that our server is down. In the latter case, assuming + * that there is a backup DHCP server, DHCPDISCOVER will get + * us a new address, but we could also have successfully + * reused our old address. In the former case, we're hosed + * anyway. This is not a win-prone situation. + */ if ((client->state == S_REBOOTING || client->state == S_REQUESTING) && interval > config->reboot_timeout) { @@ -1244,8 +1220,10 @@ send_request(void) return; } - /* If the lease has expired, relinquish the address and go back - to the INIT state. */ + /* + * If the lease has expired, relinquish the address and go back to the + * INIT state. + */ if (client->state != S_REQUESTING && cur_time > client->active->expiry) { if (client->active) { @@ -1257,7 +1235,7 @@ send_request(void) return; } - /* Do the exponential backoff... */ + /* Do the exponential backoff. */ if (!client->interval) client->interval = config->initial_interval; else @@ -1269,14 +1247,18 @@ send_request(void) client->interval = ((config->backoff_cutoff / 2) + ((arc4random() >> 2) % client->interval)); - /* If the backoff would take us to the expiry time, just set the - timeout to the expiry time. */ + /* + * If the backoff would take us to the expiry time, just set the + * timeout to the expiry time. + */ if (client->state != S_REQUESTING && cur_time + client->interval > client->active->expiry) client->interval = client->active->expiry - cur_time + 1; - /* If the lease T2 time has elapsed, or if we're not yet bound, - broadcast the DHCPREQUEST rather than unicasting. */ + /* + * If the lease rebind time has elapsed, or if we're not yet bound, + * broadcast the DHCPREQUEST rather than unicasting. + */ memset(&destination, 0, sizeof(destination)); if (client->state == S_REQUESTING || client->state == S_REBOOTING || @@ -1403,10 +1385,12 @@ make_request(struct client_lease * lease) options[i].data = config->requested_options; options[i].len = config->requested_option_count; - /* If we are requesting an address that hasn't yet been assigned - to us, use the DHCP Requested Address option. */ + /* + * If we are requesting an address that hasn't yet been assigned + * to us, use the DHCP Requested Address option. + */ if (client->state == S_REQUESTING) { - /* Send back the server identifier... */ + /* Send back the server identifier. */ i = DHO_DHCP_SERVER_IDENTIFIER; options[i].data = lease->options[i].data; options[i].len = lease->options[i].len; @@ -1442,8 +1426,10 @@ make_request(struct client_lease * lease) packet->secs = 0; /* Filled in by send_request. */ packet->flags = 0; - /* If we own the address we're requesting, put it in ciaddr; - otherwise set ciaddr to zero. */ + /* + * If we own the address we're requesting, put it in ciaddr. Otherwise + * set ciaddr to zero. + */ if (client->state == S_BOUND || client->state == S_RENEWING || client->state == S_REBINDING) { @@ -1475,7 +1461,7 @@ make_decline(struct client_lease *lease) options[i].data = &decline; options[i].len = sizeof(decline); - /* Send back the server identifier... */ + /* Send back the server identifier. */ i = DHO_DHCP_SERVER_IDENTIFIER; options[i].data = lease->options[i].data; options[i].len = lease->options[i].len; @@ -1697,7 +1683,7 @@ go_daemon(void) state = 1; - /* Stop logging to stderr... */ + /* Stop logging to stderr. */ log_perror = 0; if (daemon(1, 0) == -1) @@ -1712,9 +1698,7 @@ go_daemon(void) nullfd = -1; } - /* - * Catch stuff that might be trying to terminate the program. - */ + /* Catch stuff that might be trying to terminate the program. */ signal(SIGHUP, sighdlr); signal(SIGINT, sighdlr); signal(SIGTERM, sighdlr); @@ -1935,7 +1919,6 @@ get_ifname(char *arg) /* * Update resolv.conf. */ - char * resolv_conf_contents(struct option_data *domainname, struct option_data *nameservers) |