From: Roy Marples Date: Wed, 11 Jun 2008 09:47:37 +0000 (+0000) Subject: Don't flush addresses on startup anymore. Also, fix inform leasetimes. X-Git-Tag: v4.0.2~281 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aabb7df95fddaddbf7df11820ca2fe85fecb3846;p=thirdparty%2Fdhcpcd.git Don't flush addresses on startup anymore. Also, fix inform leasetimes. --- diff --git a/client.c b/client.c index 65674a17..89302652 100644 --- a/client.c +++ b/client.c @@ -465,7 +465,6 @@ client_setup(struct if_state *state, const struct options *options) struct interface *iface = state->interface; struct dhcp_lease *lease = &state->lease; struct in_addr addr; - struct in_addr net; size_t duid_len = 0; #ifdef ENABLE_DUID unsigned char *duid = NULL; @@ -506,6 +505,23 @@ client_setup(struct if_state *state, const struct options *options) lease->net.s_addr = options->request_netmask.s_addr; } + /* If INFORMing, ensure the interface has the address */ + if (state->options & DHCPCD_INFORM && + has_address(iface->name, &lease->addr, &lease->net) < 1) + { + addr.s_addr = lease->addr.s_addr | ~lease->net.s_addr; + logger(LOG_DEBUG, "adding IP address %s/%d", + inet_ntoa(lease->addr), inet_ntocidr(lease->net)); + if (add_address(iface->name, &lease->addr, + &lease->net, &addr) == -1) + { + logger(LOG_ERR, "add_address: %s", strerror(errno)); + return -1; + } + iface->addr.s_addr = lease->addr.s_addr; + iface->net.s_addr = lease->net.s_addr; + } + if (*options->clientid) { /* Attempt to see if the ClientID is a hardware address */ iface->clientid_len = hwaddr_aton(NULL, options->clientid); @@ -560,47 +576,6 @@ client_setup(struct if_state *state, const struct options *options) } } - /* Remove all existing addresses. - * After all, we ARE a DHCP client whose job it is to configure the - * interface. We only do this on start, so persistent addresses - * can be added afterwards by the user if needed. */ - if (!(options->options & DHCPCD_TEST) && - !(options->options & DHCPCD_DAEMONISED)) - { - if (!(options->options & DHCPCD_INFORM)) { - while (get_address(iface->name, &addr, &net) == 1) { - logger(LOG_DEBUG, "deleting IP address %s/%d", - inet_ntoa(addr), - inet_ntocidr(net)); - if (del_address(iface->name, &addr, &net) == -1) - { - logger(LOG_ERR, "delete_address: %s", - strerror(errno)); - break; - } - } - } else if (has_address(iface->name, - &lease->addr, &lease->net) < 1) - { - /* The inform address HAS to be configured for it to - * work with most DHCP servers */ - /* add_address */ - addr.s_addr = lease->addr.s_addr | ~lease->net.s_addr; - logger(LOG_DEBUG, "adding IP address %s/%d", - inet_ntoa(lease->addr), - inet_ntocidr(lease->net)); - if (add_address(iface->name, &lease->addr, - &lease->net, &addr) == -1) - { - logger(LOG_ERR, "add_address: %s", - strerror(errno)); - return -1; - } - iface->addr.s_addr = lease->addr.s_addr; - iface->net.s_addr = lease->net.s_addr; - } - } - return 0; } @@ -755,11 +730,13 @@ handle_signal(int sig, struct if_state *state, const struct options *options) switch (sig) { case SIGINT: logger(LOG_INFO, "received SIGINT, stopping"); - drop_config(state, "STOP", options); + if (!(state->options & DHCPCD_PERSISTENT)) + drop_config(state, "STOP", options); return -1; case SIGTERM: logger(LOG_INFO, "received SIGTERM, stopping"); - drop_config(state, "STOP", options); + if (!(state->options & DHCPCD_PERSISTENT)) + drop_config(state, "STOP", options); return -1; case SIGALRM: @@ -831,13 +808,10 @@ static int bind_dhcp(struct if_state *state, const struct options *options) lease->addr.s_addr = options->request_address.s_addr; else lease->addr.s_addr = iface->addr.s_addr; - logger(LOG_INFO, "received approval for %s", inet_ntoa(lease->addr)); - state->timeout = options->leasetime; - if (state->timeout == 0) - state->timeout = DEFAULT_LEASETIME; - state->state = STATE_INIT; + state->state = STATE_BOUND; + state->lease.leasetime = ~0U; reason = "INFORM"; } else if (IN_LINKLOCAL(htonl(lease->addr.s_addr))) { if (lease->addr.s_addr != iface->addr.s_addr) @@ -1252,9 +1226,11 @@ handle_dhcp(struct if_state *state, struct dhcp_message **dhcpp, case STATE_REQUESTING: case STATE_RENEWING: case STATE_REBINDING: - saddr.s_addr = dhcp->yiaddr; - logger(LOG_INFO, "lease of %s acknowledged", - inet_ntoa(saddr)); + if (!(state->options & DHCPCD_INFORM)) { + saddr.s_addr = dhcp->yiaddr; + logger(LOG_INFO, "lease of %s acknowledged", + inet_ntoa(saddr)); + } break; default: logger(LOG_ERR, "wrong state %d", state->state); diff --git a/dhcpcd.8.in b/dhcpcd.8.in index 96004f98..e5066877 100644 --- a/dhcpcd.8.in +++ b/dhcpcd.8.in @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd Jun 07, 2008 +.Dd Jun 11, 2008 .Dt DHCPCD 8 SMM .Sh NAME .Nm dhcpcd @@ -88,14 +88,6 @@ aka Zeroconf, aka APIPA Once obtained it will probe every 10 seconds for a DHCP server to get a proper address. .Pp -Even when -.Nm -obtains a proper lease, it will still add a Local Link route -.Po -165.254.0.0/16 -.Pc -so that the host can communicate with clients using these addresses. -.Pp When using IPv4LL, .Nm will always succeed and return a 0 exit code. To disable this behaviour, you @@ -158,7 +150,7 @@ from being sent. .It Fl i , -classid Ar classid Override the DHCP vendor .Ar classid -field we send. The default is +field sent. The default is dhcpcd . If not set then none is sent. .It Fl k , -release @@ -219,16 +211,23 @@ authorative, it will remain silent. In this situation, we go back to the init state and broadcast again. If no .Ar address -is given then we use the first address currently assigned to the -.Ar interface . +is given then the first address currently assigned to the +.Ar interface +is used. .It Fl s , -inform Op Ar address Ns Op Ar /cidr Behaves exactly like .Fl r , -request as above, but sends a DHCP INFORM instead of a REQUEST. This does not get a lease as such, just notifies the DHCP server of the .Ar address -we are using. -If we fail to contact a DHCP server then we return a failure instead of falling +in use. +.Nm +remains running and pretends it has an infinite lease. +.Nm +will not de-configure the interface when it exits. +If +.Nm +fails to contact a DHCP server then it returns a failure instead of falling back on IPv4LL. .It Fl t , -timeout Ar seconds Timeout after @@ -266,10 +265,11 @@ and should not be copied to other hosts. .It Fl E , -lastlease If .Nm -cannot obtain a lease, then try to use the last lease we got for the interface. +cannot obtain a lease, then try to use the last lease acquired for the +interface. If the .Fl p, -persistent -option is not given then we only use the lease if it hasn't expired. +option is not given then the lease is used if it hasn't expired. .It Fl F , -fqdn Ar fqdn Requests that the DHCP server updates DNS using FQDN instead of just a hostname. @@ -311,7 +311,7 @@ Don't request the specified option. If no option given, then don't request any options other than those to configure the interface and routing. .It Fl T, -test -On receipt of discover messages we just call +On receipt of OFFER messages just call .Pa @SCRIPT@ with the reason of TEST which echo's the DHCP variables found in the message to the console. @@ -333,7 +333,7 @@ If you always use the same options, put them here. .It Pa @SYSCONFDIR@/dhcpcd.duid Text file that holds the DUID used to identify the host. .It Pa @SCRIPT@ -Bourne shell script that is run when we configure or deconfigure an interface. +Bourne shell script that is run to configure or deconfigure an interface. .It Pa @HOOKDIR@ A directory containing bourne shell scripts that are run by the above script. Each script can be disabled by using the