From: Roy Marples Date: Thu, 4 Apr 2013 23:57:12 +0000 (+0000) Subject: Move dhcp_release into dhcp_drop X-Git-Tag: v5.99.6~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b3d908a6b0256c7d1391d6f2668b516db7d9da5b;p=thirdparty%2Fdhcpcd.git Move dhcp_release into dhcp_drop --- diff --git a/dhcp.c b/dhcp.c index 1fb36a60..3b24bda7 100644 --- a/dhcp.c +++ b/dhcp.c @@ -1662,30 +1662,6 @@ dhcp_expire(void *arg) start_interface(ifp); } -void -dhcp_release(struct interface *ifp) -{ - struct dhcp_state *state; - struct timespec ts; - - state = D_STATE(ifp); - if (state == NULL) - return; - - if (state->new != NULL && state->new->cookie == htonl(MAGIC_COOKIE)) { - syslog(LOG_INFO, "%s: releasing lease of %s", - ifp->name, inet_ntoa(state->lease.addr)); - state->xid = dhcp_xid(ifp); - send_message(ifp, DHCP_RELEASE, NULL); - /* Give the packet a chance to go before dropping the ip */ - ts.tv_sec = RELEASE_DELAY_S; - ts.tv_nsec = RELEASE_DELAY_NS; - nanosleep(&ts, NULL); - dhcp_drop(ifp, "RELEASE"); - } - unlink(state->leasefile); -} - void dhcp_decline(struct interface *ifp) { @@ -2012,24 +1988,44 @@ dhcp_reboot(struct interface *ifp) } void -dhcp_drop(struct interface *iface, const char *reason) +dhcp_drop(struct interface *ifp, const char *reason) { - struct dhcp_state *state = D_STATE(iface); + struct dhcp_state *state; +#ifdef RELEASE_SLOW + struct timespec ts; +#endif + state = D_STATE(ifp); if (state == NULL) return; - eloop_timeouts_delete(iface, dhcp_expire, NULL); - if (iface->options->options & DHCPCD_RELEASE) + eloop_timeouts_delete(ifp, dhcp_expire, NULL); + if (ifp->options->options & DHCPCD_RELEASE) { unlink(state->leasefile); + if (ifp->carrier != LINK_DOWN && + state->new != NULL && + state->new->cookie == htonl(MAGIC_COOKIE)) + { + syslog(LOG_INFO, "%s: releasing lease of %s", + ifp->name, inet_ntoa(state->lease.addr)); + state->xid = dhcp_xid(ifp); + send_message(ifp, DHCP_RELEASE, NULL); +#ifdef RELEASE_SLOW + /* Give the packet a chance to go */ + ts.tv_sec = RELEASE_DELAY_S; + ts.tv_nsec = RELEASE_DELAY_NS; + nanosleep(&ts, NULL); +#endif + } + } free(state->old); state->old = state->new; state->new = NULL; state->reason = reason; - ipv4_applyaddr(iface); + ipv4_applyaddr(ifp); free(state->old); state->old = NULL; state->lease.addr.s_addr = 0; - iface->options->options &= ~ DHCPCD_CSR_WARNED; + ifp->options->options &= ~ DHCPCD_CSR_WARNED; } static void diff --git a/dhcp.h b/dhcp.h index d6637a0b..bd770c39 100644 --- a/dhcp.h +++ b/dhcp.h @@ -264,7 +264,6 @@ void dhcp_stop(struct interface *); void dhcp_decline(struct interface *); void dhcp_discover(void *); void dhcp_inform(struct interface *); -void dhcp_release(struct interface *); void dhcp_bind(void *); void dhcp_reboot_newopts(struct interface *, int); void dhcp_close(struct interface *); @@ -274,7 +273,6 @@ int dhcp_dump(const char *); #define dhcp_printoptions #define dhcp_drop(a, b) #define dhcp_start(a) {} -#define dhcp_release(a) {} #define dhcp_reboot(a, b) b = b #define dhcp_close(a) #define dhcp_free(a) diff --git a/dhcpcd.c b/dhcpcd.c index f01c0a27..dee42dee 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -68,11 +68,6 @@ const char copyright[] = "Copyright (c) 2006-2013 Roy Marples"; #include "script.h" #include "signals.h" -/* Wait N nanoseconds between sending a RELEASE and dropping the address. - * This gives the kernel enough time to actually send it. */ -#define RELEASE_DELAY_S 0 -#define RELEASE_DELAY_NS 10000000 - struct if_head *ifaces = NULL; char vendor[VENDORCLASSID_MAX_LEN]; int pidfd = -1; @@ -276,8 +271,7 @@ stop_interface(struct interface *ifp) TAILQ_REMOVE(ifaces, ifp, next); dhcp6_drop(ifp, NULL); ipv6rs_drop(ifp); -// if (strcmp(ifp->state->reason, "RELEASE") != 0) - dhcp_drop(ifp, "STOP"); + dhcp_drop(ifp, "STOP"); dhcp_close(ifp); eloop_timeout_delete(NULL, ifp); free_interface(ifp); @@ -722,10 +716,8 @@ handle_signal(int sig) ifp = TAILQ_LAST(ifaces, if_head); if (ifp == NULL) break; - if (ifp->carrier != LINK_DOWN && - (do_release || - ifp->options->options & DHCPCD_RELEASE)) - dhcp_release(ifp); + if (do_release) + ifp->options->options |= DHCPCD_RELEASE; stop_interface(ifp); } exit(EXIT_FAILURE); @@ -863,9 +855,6 @@ handle_args(struct fd_list *fd, int argc, char **argv) continue; if (do_release) ifp->options->options |= DHCPCD_RELEASE; - if (ifp->options->options & DHCPCD_RELEASE && - ifp->carrier != LINK_DOWN) - dhcp_release(ifp); stop_interface(ifp); } return 0;