]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Move dhcp_release into dhcp_drop
authorRoy Marples <roy@marples.name>
Thu, 4 Apr 2013 23:57:12 +0000 (23:57 +0000)
committerRoy Marples <roy@marples.name>
Thu, 4 Apr 2013 23:57:12 +0000 (23:57 +0000)
dhcp.c
dhcp.h
dhcpcd.c

diff --git a/dhcp.c b/dhcp.c
index 1fb36a6008f65bd6f0aa462acb77829122f394ce..3b24bda7dfd5ab9ae2077f2c0ab0bcce973c3973 100644 (file)
--- 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 d6637a0b17fdd486f43e2277329508a8514e28f9..bd770c3999fa3ba903088c5f089378756706171a 100644 (file)
--- 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)
index f01c0a2782f8b752e5c2a0ef44d64fe06611b204..dee42deef616da389307080503199fb7027d697f 100644 (file)
--- 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;