From: Roy Marples Date: Thu, 12 Jul 2012 09:19:14 +0000 (+0000) Subject: Don't restore kernel RA defaults or drop RA's when forking. X-Git-Tag: v5.6.1~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ba0a5b3e17443dfc8d78eee9f68933dd06f0ecc2;p=thirdparty%2Fdhcpcd.git Don't restore kernel RA defaults or drop RA's when forking. Add some more memory cleanups when testing forking. --- diff --git a/bind.c b/bind.c index eed64a60..889d99e8 100644 --- a/bind.c +++ b/bind.c @@ -109,6 +109,7 @@ daemonise(void) writepid(pidfd, pid); close(pidfd); pidfd = -1; + options |= DHCPCD_FORKED; exit(EXIT_SUCCESS); } options |= DHCPCD_DAEMONISED; diff --git a/if-options.h b/if-options.h index 3e083d87..212cd8d4 100644 --- a/if-options.h +++ b/if-options.h @@ -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[]; diff --git a/ipv6.c b/ipv6.c index e88035e6..1367657e 100644 --- a/ipv6.c +++ b/ipv6.c @@ -54,7 +54,12 @@ static struct rt6head *routes; static void ipv6_cleanup() { + struct rt6 *rt; + while ((rt = TAILQ_FIRST(routes))) { + TAILQ_REMOVE(routes, rt, next); + free(rt); + } free(routes); } #endif diff --git a/ipv6rs.c b/ipv6rs.c index 242ff7ca..95e148dc 100644 --- a/ipv6rs.c +++ b/ipv6rs.c @@ -263,14 +263,14 @@ ipv6rs_free_opts(struct ra *rap) } 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 @@ ipv6rs_drop_addrs(struct ra *rap) } } -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 @@ ipv6rs_free(struct interface *ifp) n = 0; TAILQ_FOREACH_SAFE(rap, &ipv6_routers, next, ran) { if (rap->iface == ifp) { - ipv6rs_drop_ra(rap); + ipv6rs_free_ra(rap); n++; } } diff --git a/ipv6rs.h b/ipv6rs.h index 4af65450..cae4058d 100644 --- a/ipv6rs.h +++ b/ipv6rs.h @@ -69,7 +69,9 @@ int ipv6rs_open(void); 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 *); diff --git a/platform-bsd.c b/platform-bsd.c index fc656130..2304680e 100644 --- a/platform-bsd.c +++ b/platform-bsd.c @@ -80,6 +80,8 @@ static void 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"); diff --git a/platform-linux.c b/platform-linux.c index 64059175..393e5198 100644 --- a/platform-linux.c +++ b/platform-linux.c @@ -146,7 +146,15 @@ restore_kernel_ra(void) { 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 @@ restore_kernel_ra(void) 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 @@ check_ipv6(const char *ifname) 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;