diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2012-12-17 22:53:00 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2012-12-17 22:53:00 +0000 |
commit | 192d608013578764d800f09f298de0971b1d8b21 (patch) | |
tree | 55623c23923192849b96b0c367206eb76be9e85c /sbin | |
parent | 2ec2f1bc4bd67185c900202202bf02b63d2a2ec4 (diff) |
Don't daemonize until the RTM_NEWADDR message is received. Shuffle
things a bit so configuring the address and default route are done
last. This makes it much more likely that all the work is done when
the 'bound to ...' message is displayed.
Amoung other things fixes a problem with the install scripts, where
the first (hostname-associated) dhclient can exit so quickly the
interface doesn't yet have an address and a second (free-floating)
dhclient is therefore often run.
Noted by rpe@, who also tested the fix.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/dhclient/dhclient.c | 38 | ||||
-rw-r--r-- | sbin/dhclient/kroute.c | 4 |
2 files changed, 25 insertions, 17 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 7155446d76e..fa317281646 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.194 2012/12/16 03:15:46 lteo Exp $ */ +/* $OpenBSD: dhclient.c,v 1.195 2012/12/17 22:52:59 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -214,6 +214,12 @@ routehandler(void) if (rtm->rtm_type == RTM_NEWADDR) { if (a.s_addr == adding.s_addr) { adding.s_addr = INADDR_ANY; + note("bound to %s -- renewal in %lld seconds.", + inet_ntoa(client->active->address), + (long long)(client->active->renewal - + time(NULL))); + client->state = S_BOUND; + go_daemon(); break; } errmsg = "interface address added"; @@ -484,6 +490,8 @@ 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; /* If we don't remember an active lease, go straight to INIT. */ if (!client->active || client->active->is_bootp) { @@ -687,14 +695,7 @@ bind_lease(void) memset(&mask, 0, sizeof(mask)); memcpy(&mask.s_addr, options[DHO_SUBNET_MASK].data, options[DHO_SUBNET_MASK].len); - add_address(ifi->name, ifi->rdomain, client->new->address, mask); - if (options[DHO_ROUTERS].len) { - memset(&gateway, 0, sizeof(gateway)); - /* XXX Only use FIRST router address for now. */ - memcpy(&gateway.s_addr, options[DHO_ROUTERS].data, - options[DHO_ROUTERS].len); - add_default_route(ifi->rdomain, client->new->address, gateway); - } + if (options[DHO_DOMAIN_NAME].len) domainname = strdup(pretty_print_option( DHO_DOMAIN_NAME, &options[DHO_DOMAIN_NAME], 0)); @@ -709,6 +710,19 @@ bind_lease(void) new_resolv_conf(ifi->name, domainname, nameservers); + /* + * Add address and default route last, so we know when the binding + * is done by the RTM_NEWADDR message being received. + */ + add_address(ifi->name, ifi->rdomain, client->new->address, mask); + if (options[DHO_ROUTERS].len) { + memset(&gateway, 0, sizeof(gateway)); + /* XXX Only use FIRST router address for now. */ + memcpy(&gateway.s_addr, options[DHO_ROUTERS].data, + options[DHO_ROUTERS].len); + add_default_route(ifi->rdomain, client->new->address, gateway); + } + free(domainname); free(nameservers); free_client_lease(lease); @@ -724,12 +738,6 @@ bind_lease(void) /* Set timeout to start the renewal process. */ set_timeout(client->active->renewal, state_bound); - - note("bound to %s -- renewal in %lld seconds.", - inet_ntoa(client->active->address), - (long long)(client->active->renewal - time(NULL))); - client->state = S_BOUND; - go_daemon(); } /* diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c index 9337ea62726..e9db894642a 100644 --- a/sbin/dhclient/kroute.c +++ b/sbin/dhclient/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.23 2012/12/04 19:24:03 krw Exp $ */ +/* $OpenBSD: kroute.c,v 1.24 2012/12/17 22:52:59 krw Exp $ */ /* * Copyright 2012 Kenneth R Westerback <krw@openbsd.org> @@ -302,7 +302,7 @@ priv_add_default_route(struct imsg_add_default_route *imsg) for (i = 0; i < 5; i++) { if (writev(s, iov, iovcnt) != -1) break; - if (errno != EEXIST) + if (errno != EEXIST && errno != ENETUNREACH) error("failed to add default route: %s", strerror(errno)); sleep(1); |