changeset 1694:2f2700ce3dba draft

Don't restore kernel RA defaults or drop RA's when forking. Add some more memory cleanups when testing forking.
author Roy Marples <roy@marples.name>
date Thu, 12 Jul 2012 09:19:14 +0000
parents 829716214dbc
children 03e32ad4e5a0
files bind.c if-options.h ipv6.c ipv6rs.c ipv6rs.h platform-bsd.c platform-linux.c
diffstat 7 files changed, 29 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/bind.c	Thu Jul 05 16:37:41 2012 +0000
+++ b/bind.c	Thu Jul 12 09:19:14 2012 +0000
@@ -109,6 +109,7 @@
 		writepid(pidfd, pid);
 		close(pidfd);
 		pidfd = -1;
+		options |= DHCPCD_FORKED;
 		exit(EXIT_SUCCESS);
 	}
 	options |= DHCPCD_DAEMONISED;
--- a/if-options.h	Thu Jul 05 16:37:41 2012 +0000
+++ b/if-options.h	Thu Jul 12 09:19:14 2012 +0000
@@ -82,6 +82,7 @@
 #define DHCPCD_IPV6RA_OWN		(1ULL << 33)
 #define DHCPCD_IPV6RA_OWN_DEFAULT	(1ULL << 34)
 #define DHCPCD_IPV4			(1ULL << 35)
+#define DHCPCD_FORKED			(1ULL << 36)
 
 extern const struct option cf_options[];
 
--- a/ipv6.c	Thu Jul 05 16:37:41 2012 +0000
+++ b/ipv6.c	Thu Jul 12 09:19:14 2012 +0000
@@ -54,7 +54,12 @@
 static void
 ipv6_cleanup()
 {
+	struct rt6 *rt;
 
+	while ((rt = TAILQ_FIRST(routes))) {
+		TAILQ_REMOVE(routes, rt, next);
+		free(rt);
+	}
 	free(routes);
 }
 #endif
--- a/ipv6rs.c	Thu Jul 05 16:37:41 2012 +0000
+++ b/ipv6rs.c	Thu Jul 12 09:19:14 2012 +0000
@@ -263,14 +263,14 @@
 }
 
 static void
-ipv6rs_drop_addrs(struct ra *rap)
+ipv6rs_freedrop_addrs(struct ra *rap, int drop)
 {
 	struct ipv6_addr *ap;
 
 	while ((ap = TAILQ_FIRST(&rap->addrs))) {
 		TAILQ_REMOVE(&rap->addrs, ap, next);
-		if ((options & DHCPCD_IPV6RA_OWN)) {
-		syslog(LOG_INFO, "%s: deleting address %s",
+		if (drop && (options & DHCPCD_IPV6RA_OWN)) {
+			syslog(LOG_INFO, "%s: deleting address %s",
 			    rap->iface->name, ap->saddr);
 			if (del_address6(rap->iface, ap) == -1)
 				syslog(LOG_ERR, "del_address6 %m");
@@ -279,13 +279,13 @@
 	}
 }
 
-void ipv6rs_drop_ra(struct ra *rap)
+void ipv6rs_freedrop_ra(struct ra *rap, int drop)
 {
 
 	delete_timeout(NULL, rap->iface);
 	delete_timeout(NULL, rap);
 	TAILQ_REMOVE(&ipv6_routers, rap, next);
-	ipv6rs_drop_addrs(rap);
+	ipv6rs_freedrop_addrs(rap, drop);
 	ipv6rs_free_opts(rap);
 	free(rap->data);
 	free(rap->ns);
@@ -303,7 +303,7 @@
 	n = 0;
 	TAILQ_FOREACH_SAFE(rap, &ipv6_routers, next, ran) {
 		if (rap->iface == ifp) {
-			ipv6rs_drop_ra(rap);
+			ipv6rs_free_ra(rap);
 			n++;
 		}
 	}
--- a/ipv6rs.h	Thu Jul 05 16:37:41 2012 +0000
+++ b/ipv6rs.h	Thu Jul 12 09:19:14 2012 +0000
@@ -69,7 +69,9 @@
 void ipv6rs_handledata(void *);
 int ipv6rs_start(struct interface *);
 ssize_t ipv6rs_env(char **, const char *, const struct interface *);
-void ipv6rs_drop_ra(struct ra *);
+void ipv6rs_freedrop_ra(struct ra *, int);
+#define ipv6rs_free_ra(ra) ipv6rs_freedrop_ra((ra),  0)
+#define ipv6rs_drop_ra(ra) ipv6rs_freedrop_ra((ra),  1)
 ssize_t ipv6rs_free(struct interface *);
 void ipv6rs_expire(void *arg);
 int ipv6rs_has_ra(const struct interface *);
--- a/platform-bsd.c	Thu Jul 05 16:37:41 2012 +0000
+++ b/platform-bsd.c	Thu Jul 12 09:19:14 2012 +0000
@@ -80,6 +80,8 @@
 restore_kernel_ra(void)
 {
 
+	if (!(options & DHCPCD_FORKED))
+		return;
 	syslog(LOG_INFO, "restoring Kernel IPv6 RA support");
 	if (set_inet6_sysctl(IPV6CTL_ACCEPT_RTADV, 1) == -1)
 		syslog(LOG_ERR, "IPV6CTL_ACCEPT_RTADV: %m");
--- a/platform-linux.c	Thu Jul 05 16:37:41 2012 +0000
+++ b/platform-linux.c	Thu Jul 12 09:19:14 2012 +0000
@@ -146,7 +146,15 @@
 {
 	char path[256];
 
+#ifndef DEBUG_MEMORY
+	if (options & DHCPCD_FORKED)
+		return;
+#endif
+
 	for (nrestore--; nrestore >= 0; nrestore--) {
+#ifdef DEBUG_MEMORY
+		if (!(options & DHCPCD_FORKED)) {
+#endif
 		syslog(LOG_INFO, "%s: restoring Kernel IPv6 RA support",
 		       restore[nrestore]);
 		snprintf(path, sizeof(path), "%s/%s/accept_ra",
@@ -154,6 +162,7 @@
 		if (write_path(path, "1") == -1)
 			syslog(LOG_ERR, "write_path: %s: %m", path);
 #ifdef DEBUG_MEMORY
+		}
 		free(restore[nrestore]);
 #endif
 	}
@@ -179,7 +188,8 @@
 	if (r == 0)
 		options |= DHCPCD_IPV6RA_OWN;
 	else if (options & DHCPCD_IPV6RA_OWN) {
-		syslog(LOG_INFO, "disabling Kernel IPv6 RA support");
+		syslog(LOG_INFO, "%s: disabling Kernel IPv6 RA support",
+		    ifname);
 		if (write_path(path, "0") == -1) {
 			syslog(LOG_ERR, "write_path: %s: %m", path);
 			return 0;