changeset 1697:1801cec47ba0 draft

Disable kernel interface RA as early as possible on Linux. Don't add duplicate interfaces to the restore kernel RA on Linux.
author Roy Marples <roy@marples.name>
date Fri, 13 Jul 2012 08:22:04 +0000
parents 163ab06f2fe9
children e372c338898b
files dhcpcd.c platform-linux.c
diffstat 2 files changed, 20 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/dhcpcd.c	Thu Jul 12 16:34:33 2012 +0000
+++ b/dhcpcd.c	Fri Jul 13 08:22:04 2012 +0000
@@ -785,6 +785,12 @@
 	if (ifo->metric != -1)
 		iface->metric = ifo->metric;
 
+	/* We want to disable kernel interface RA as early as possible. */
+	if (options & DHCPCD_IPV6RS && ifo->options & DHCPCD_IPV6RS) {
+		if (check_ipv6(iface->name) != 1)
+			ifo->options &= ~DHCPCD_IPV6RS;
+	}
+
 	/* If we haven't specified a ClientID and our hardware address
 	 * length is greater than DHCP_CHADDR_LEN then we enforce a ClientID
 	 * of the hardware address family and the hardware address. */
@@ -1167,12 +1173,8 @@
 	free(iface->state->offer);
 	iface->state->offer = NULL;
 
-	if (options & DHCPCD_IPV6RS && ifo->options & DHCPCD_IPV6RS) {
-		if (check_ipv6(iface->name) == 1)
-			ipv6rs_start(iface);
-		else
-			ifo->options &= ~DHCPCD_IPV6RS;
-	}
+	if (options & DHCPCD_IPV6RS && ifo->options & DHCPCD_IPV6RS)
+		ipv6rs_start(iface);
 
 	if (iface->state->arping_index < ifo->arping_len) {
 		start_arping(iface);
--- a/platform-linux.c	Thu Jul 12 16:34:33 2012 +0000
+++ b/platform-linux.c	Fri Jul 13 08:22:04 2012 +0000
@@ -174,7 +174,7 @@
 int
 check_ipv6(const char *ifname)
 {
-	int r, ex;
+	int r, ex, i;
 	char path[256];
 
 	if (ifname == NULL) {
@@ -194,12 +194,18 @@
 			syslog(LOG_ERR, "write_path: %s: %m", path);
 			return 0;
 		}
-		restore = realloc(restore, (nrestore + 1) * sizeof(char *));
-		if (restore == NULL) {
-			syslog(LOG_ERR, "realloc: %m");
-			exit(EXIT_FAILURE);
+		for (i = 0; i < nrestore; i++)
+			if (strcmp(restore[i], ifname) == 0)
+				break;
+		if (i == nrestore) {
+			restore = realloc(restore,
+			    (nrestore + 1) * sizeof(char *));
+			if (restore == NULL) {
+				syslog(LOG_ERR, "realloc: %m");
+				exit(EXIT_FAILURE);
+			}
+			restore[nrestore++] = xstrdup(ifname);
 		}
-		restore[nrestore++] = xstrdup(ifname);
 		if (ex)
 			atexit(restore_kernel_ra);
 	}