changeset 1906:895f1461a075 draft

Move dhcp_release into dhcp_drop
author Roy Marples <roy@marples.name>
date Thu, 04 Apr 2013 23:57:12 +0000
parents 6ce33af38ef4
children 30de1cdd0845
files dhcp.c dhcp.h dhcpcd.c
diffstat 3 files changed, 29 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/dhcp.c	Thu Apr 04 23:30:14 2013 +0000
+++ b/dhcp.c	Thu Apr 04 23:57:12 2013 +0000
@@ -1663,30 +1663,6 @@
 }
 
 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 @@
 }
 
 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
--- a/dhcp.h	Thu Apr 04 23:30:14 2013 +0000
+++ b/dhcp.h	Thu Apr 04 23:57:12 2013 +0000
@@ -264,7 +264,6 @@
 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 @@
 #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)
--- a/dhcpcd.c	Thu Apr 04 23:30:14 2013 +0000
+++ b/dhcpcd.c	Thu Apr 04 23:57:12 2013 +0000
@@ -68,11 +68,6 @@
 #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 @@
 	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 @@
 		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 @@
 				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;