am 7a659da9: Merge "Get rid of LOCAL_MODULE_TAGS := user"

* commit '7a659da9ec67d85d1b166fc6c1984f488de8e031':
  Get rid of LOCAL_MODULE_TAGS := user
diff --git a/Android.mk b/Android.mk
index e918739..55e5f68 100644
--- a/Android.mk
+++ b/Android.mk
@@ -9,7 +9,7 @@
 LOCAL_SRC_FILES := arp.c bind.c common.c control.c dhcp.c dhcpcd.c duid.c \
 	eloop.c if-options.c if-pref.c ipv4ll.c net.c signals.c configure.c \
 	if-linux.c if-linux-wireless.c lpf.c compat/getline.c \
-	platform-linux.c compat/closefrom.c ifaddrs.c
+	platform-linux.c compat/closefrom.c ifaddrs.c ipv6rs.c
 
 #LOCAL_C_INCLUDES := $(KERNEL_HEADERS)
 LOCAL_SHARED_LIBRARIES := libc libcutils libnetutils
diff --git a/Makefile b/Makefile
index ea6431f..3b4dbfd 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
 
 PROG=		dhcpcd
 SRCS=		arp.c bind.c common.c control.c dhcp.c dhcpcd.c duid.c eloop.c
-SRCS+=		if-options.c if-pref.c ipv4ll.c net.c signals.c
+SRCS+=		if-options.c if-pref.c ipv4ll.c ipv6rs.c net.c signals.c
 SRCS+=		configure.c
 
 CFLAGS?=	-O2
diff --git a/README b/README
index cfbf3cd..32ae27a 100644
--- a/README
+++ b/README
@@ -1,5 +1,5 @@
 dhcpcd - DHCP client daemon
-Copyright (c) 2006-2010 Roy Marples <roy@marples.name>
+Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
 
 
 Installation
diff --git a/ThirdPartyProject.prop b/ThirdPartyProject.prop
deleted file mode 100644
index e8bf489..0000000
--- a/ThirdPartyProject.prop
+++ /dev/null
@@ -1,10 +0,0 @@
-# Copyright 2010 Google Inc. All Rights Reserved.
-#Fri Jul 16 10:03:08 PDT 2010
-currentVersion=5.2.10
-version=5.2.10
-isNative=true
-feedurl=http\://git.marples.name/projects/dhcpcd/wiki
-name=dhcpcd
-keywords=dhcpcd
-onDevice=true
-homepage=http\://roy.marples.name/projects/dhcpcd/log/
diff --git a/arp.c b/arp.c
index 89d63fe..1905508 100644
--- a/arp.c
+++ b/arp.c
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2008 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2011 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -119,7 +119,7 @@
 	state->fail.s_addr = 0;
 	for(;;) {
 		bytes = get_raw_packet(iface, ETHERTYPE_ARP,
-		    arp_buffer, sizeof(arp_buffer));
+		    arp_buffer, sizeof(arp_buffer), NULL);
 		if (bytes == 0 || bytes == -1)
 			return;
 		/* We must have a full ARP header */
@@ -204,6 +204,8 @@
 	struct if_state *state = iface->state;
 	struct timeval tv;
 
+	if (state->new == NULL)
+		return;
 	if (iface->arp_fd == -1) {
 		open_socket(iface, ETHERTYPE_ARP);
 		add_event(iface->arp_fd, handle_arp_packet, iface);
diff --git a/bpf.c b/bpf.c
index beda1ba..1c30c76 100644
--- a/bpf.c
+++ b/bpf.c
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2008 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2011 Roy Marples <roy@marples.name>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -160,7 +160,7 @@
  * So we pass the buffer in the API so we can loop on >1 packet. */
 ssize_t
 get_raw_packet(struct interface *iface, int protocol,
-    void *data, ssize_t len)
+    void *data, ssize_t len, int *partialcsum)
 {
 	int fd = -1;
 	struct bpf_hdr packet;
@@ -172,6 +172,9 @@
 	else
 		fd = iface->raw_fd;
 
+	if (partialcsum != NULL)
+		*partialcsum = 0; /* Not supported on BSD */
+
 	for (;;) {
 		if (iface->buffer_len == 0) {
 			bytes = read(fd, iface->buffer, iface->buffer_size);
diff --git a/common.c b/common.c
index 0642055..05b547b 100644
--- a/common.c
+++ b/common.c
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2009 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -200,6 +200,32 @@
 	return gettimeofday(tp, NULL);
 }
 
+ssize_t
+setvar(char ***e, const char *prefix, const char *var, const char *value)
+{
+	size_t len = strlen(var) + strlen(value) + 3;
+
+	if (prefix)
+		len += strlen(prefix) + 1;
+	**e = xmalloc(len);
+	if (prefix)
+		snprintf(**e, len, "%s_%s=%s", prefix, var, value);
+	else
+		snprintf(**e, len, "%s=%s", var, value);
+	(*e)++;
+	return len;
+}
+
+ssize_t
+setvard(char ***e, const char *prefix, const char *var, int value)
+{
+	char buffer[32];
+
+	snprintf(buffer, sizeof(buffer), "%d", value);
+	return setvar(e, prefix, var, buffer);
+}
+
+
 time_t
 uptime(void)
 {
diff --git a/common.h b/common.h
index 65b060f..4fe2444 100644
--- a/common.h
+++ b/common.h
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2009 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2011 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -28,8 +28,8 @@
 #ifndef COMMON_H
 #define COMMON_H
 
+#include <sys/time.h>
 #include <stdio.h>
-#include <time.h>
 
 #include "config.h"
 #include "defs.h"
@@ -72,6 +72,8 @@
 char *get_line(FILE * __restrict);
 extern int clock_monotonic;
 int get_monotonic(struct timeval *);
+ssize_t setvar(char ***, const char *, const char *, const char *);
+ssize_t setvard(char ***, const char *, const char *, int);
 time_t uptime(void);
 int writepid(int, pid_t);
 void *xrealloc(void *, size_t);
diff --git a/configure.c b/configure.c
index e64dd4e..fe89532 100644
--- a/configure.c
+++ b/configure.c
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2010 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -46,6 +46,7 @@
 #include "dhcp.h"
 #include "if-options.h"
 #include "if-pref.h"
+#include "ipv6rs.h"
 #include "net.h"
 #include "signals.h"
 
@@ -63,7 +64,6 @@
 
 static struct rt *routes;
 
-
 static int
 exec_script(char *const *argv, char *const *env)
 {
@@ -163,23 +163,39 @@
 }
 
 static ssize_t
-make_env(const struct interface *iface, char ***argv)
+make_env(const struct interface *iface, const char *reason, char ***argv)
 {
 	char **env, *p;
 	ssize_t e, elen, l;
 	const struct if_options *ifo = iface->state->options;
 	const struct interface *ifp;
+	int dhcp, ra;
+
+	dhcp = ra = 0;
+	if (strcmp(reason, "ROUTERADVERT") == 0)
+		ra = 1;
+	else
+		dhcp = 1;
+
+	/* When dumping the lease, we only want to report interface and
+	   reason - the other interface variables are meaningless */
+	if (options & DHCPCD_DUMPLEASE)
+		elen = 2;
+	else
+		elen = 10;
 
 	/* Make our env */
-	elen = 8;
 	env = xmalloc(sizeof(char *) * (elen + 1));
 	e = strlen("interface") + strlen(iface->name) + 2;
 	env[0] = xmalloc(e);
 	snprintf(env[0], e, "interface=%s", iface->name);
-	e = strlen("reason") + strlen(iface->state->reason) + 2;
+	e = strlen("reason") + strlen(reason) + 2;
 	env[1] = xmalloc(e);
-	snprintf(env[1], e, "reason=%s", iface->state->reason);
-	e = 20;
+	snprintf(env[1], e, "reason=%s", reason);
+	if (options & DHCPCD_DUMPLEASE)
+		goto dumplease;
+
+ 	e = 20;
 	env[2] = xmalloc(e);
 	snprintf(env[2], e, "pid=%d", getpid());
 	env[3] = xmalloc(e);
@@ -205,6 +221,13 @@
 		e--;
 	}
 	*--p = '\0';
+	if ((dhcp && iface->state->new) || (ra && iface->ras)) {
+		env[8] = strdup("if_up=true");
+		env[9] = strdup("if_down=false");
+	} else {
+		env[8] = strdup("if_up=false");
+		env[9] = strdup("if_down=true");
+	}
 	if (*iface->state->profile) {
 		e = strlen("profile=") + strlen(iface->state->profile) + 2;
 		env[elen] = xmalloc(e);
@@ -227,7 +250,7 @@
 			snprintf(env[elen++], e, "old_ssid=%s", iface->ssid);
 		}
 	}
-	if (iface->state->old) {
+	if (dhcp && iface->state->old) {
 		e = configure_env(NULL, NULL, iface->state->old, ifo);
 		if (e > 0) {
 			env = xrealloc(env, sizeof(char *) * (elen + e + 1));
@@ -237,7 +260,9 @@
 		append_config(&env, &elen, "old",
 		    (const char *const *)ifo->config);
 	}
-	if (iface->state->new) {
+
+dumplease:
+	if (dhcp && iface->state->new) {
 		e = configure_env(NULL, NULL, iface->state->new, ifo);
 		if (e > 0) {
 			env = xrealloc(env, sizeof(char *) * (elen + e + 1));
@@ -247,6 +272,13 @@
 		append_config(&env, &elen, "new",
 		    (const char *const *)ifo->config);
 	}
+	if (ra) {
+		e = ipv6rs_env(NULL, NULL, iface);
+		if (e > 0) {
+			env = xrealloc(env, sizeof(char *) * (elen + e + 1));
+			elen += ipv6rs_env(env + elen, NULL, iface);
+		}
+	}
 
 	/* Add our base environment */
 	if (ifo->environ) {
@@ -267,8 +299,8 @@
 	return elen;
 }
 
-int
-send_interface(int fd, const struct interface *iface)
+static int
+send_interface1(int fd, const struct interface *iface, const char *reason)
 {
 	char **env, **ep, *s;
 	ssize_t elen;
@@ -276,7 +308,7 @@
 	int retval;
 
 	retval = 0;
-	make_env(iface, &env);
+	make_env(iface, reason, &env);
 	elen = arraytostr((const char *const *)env, &s);
 	iov[0].iov_base = &elen;
 	iov[0].iov_len = sizeof(ssize_t);
@@ -292,7 +324,20 @@
 }
 
 int
-run_script(const struct interface *iface)
+send_interface(int fd, const struct interface *iface)
+{
+	int retval = 0;
+	if (send_interface1(fd, iface, iface->state->reason) == -1)
+		retval = -1;
+	if (iface->ras) {
+		if (send_interface1(fd, iface, "ROUTERADVERT") == -1)
+			retval = -1;
+	}
+	return retval;
+}
+
+int
+run_script_reason(const struct interface *iface, const char *reason)
 {
 	char *const argv[2] = { UNCONST(iface->state->options->script), NULL };
 	char **env = NULL, **ep;
@@ -303,11 +348,18 @@
 	const struct fd_list *fd;
 	struct iovec iov[2];
 
+	if (iface->state->options->script == NULL ||
+	    iface->state->options->script[0] == '\0' ||
+	    strcmp(iface->state->options->script, "/dev/null") == 0)
+		return 0;
+
+	if (reason == NULL)
+		reason = iface->state->reason;
 	syslog(LOG_DEBUG, "%s: executing `%s', reason %s",
-	    iface->name, argv[0], iface->state->reason);
+	    iface->name, argv[0], reason);
 
 	/* Make our env */
-	elen = make_env(iface, &env);
+	elen = make_env(iface, reason, &env);
 	env = xrealloc(env, sizeof(char *) * (elen + 2));
 	/* Add path to it */
 	path = getenv("PATH");
@@ -383,9 +435,10 @@
 }
 
 static void
-desc_route(const char *cmd, const struct rt *rt, const char *ifname)
+desc_route(const char *cmd, const struct rt *rt)
 {
 	char addr[sizeof("000.000.000.000") + 1];
+	const char *ifname = rt->iface->name;
 
 	strlcpy(addr, inet_ntoa(rt->dest), sizeof(addr));
 	if (rt->gate.s_addr == INADDR_ANY)
@@ -413,7 +466,7 @@
 	f = find_route(routes, rt, &l, NULL);
 	if (f == NULL)
 		return 0;
-	desc_route("removing", f, f->iface->name);
+	desc_route("removing", f);
 	if (l)
 		l->next = f->next;
 	else
@@ -423,61 +476,60 @@
 }
 
 static int
-n_route(struct rt *rt, const struct interface *iface)
+n_route(struct rt *rt)
 {
 	/* Don't set default routes if not asked to */
 	if (rt->dest.s_addr == 0 &&
 	    rt->net.s_addr == 0 &&
-	    !(iface->state->options->options & DHCPCD_GATEWAY))
+	    !(rt->iface->state->options->options & DHCPCD_GATEWAY))
 		return -1;
 
-	desc_route("adding", rt, iface->name);
-	if (!add_route(iface, &rt->dest, &rt->net, &rt->gate, iface->metric))
+	desc_route("adding", rt);
+	if (!add_route(rt))
 		return 0;
 	if (errno == EEXIST) {
 		/* Pretend we added the subnet route */
-		if (rt->dest.s_addr == (iface->addr.s_addr & iface->net.s_addr) &&
-		    rt->net.s_addr == iface->net.s_addr &&
+		if (rt->dest.s_addr ==
+		    (rt->iface->addr.s_addr & rt->iface->net.s_addr) &&
+		    rt->net.s_addr == rt->iface->net.s_addr &&
 		    rt->gate.s_addr == 0)
 			return 0;
 		else
 			return -1;
 	}
-	syslog(LOG_ERR, "%s: add_route: %m", iface->name);
+	syslog(LOG_ERR, "%s: add_route: %m", rt->iface->name);
 	return -1;
 }
 
 static int
-c_route(struct rt *ort, struct rt *nrt, const struct interface *iface)
+c_route(struct rt *ort, struct rt *nrt)
 {
 	/* Don't set default routes if not asked to */
 	if (nrt->dest.s_addr == 0 &&
 	    nrt->net.s_addr == 0 &&
-	    !(iface->state->options->options & DHCPCD_GATEWAY))
+	    !(nrt->iface->state->options->options & DHCPCD_GATEWAY))
 		return -1;
 
-	desc_route("changing", nrt, iface->name);
+	desc_route("changing", nrt);
 	/* We delete and add the route so that we can change metric.
 	 * This also has the nice side effect of flushing ARP entries so
 	 * we don't have to do that manually. */
-	del_route(ort->iface, &ort->dest, &ort->net, &ort->gate,
-	    ort->iface->metric);
-	if (!add_route(iface, &nrt->dest, &nrt->net, &nrt->gate,
-		iface->metric))
+	del_route(ort);
+	if (!add_route(nrt))
 		return 0;
-	syslog(LOG_ERR, "%s: add_route: %m", iface->name);
+	syslog(LOG_ERR, "%s: add_route: %m", nrt->iface->name);
 	return -1;
 }
 
 static int
-d_route(struct rt *rt, const struct interface *iface, int metric)
+d_route(struct rt *rt)
 {
 	int retval;
 
-	desc_route("deleting", rt, iface->name);
-	retval = del_route(iface, &rt->dest, &rt->net, &rt->gate, metric);
+	desc_route("deleting", rt);
+	retval = del_route(rt);
 	if (retval != 0 && errno != ENOENT && errno != ESRCH)
-		syslog(LOG_ERR,"%s: del_route: %m", iface->name);
+		syslog(LOG_ERR,"%s: del_route: %m", rt->iface->name);
 	return retval;
 }
 
@@ -652,15 +704,19 @@
 		dnr = add_destination_route(dnr, ifp);
 		for (rt = dnr; rt && (rtn = rt->next, 1); lrt = rt, rt = rtn) {
 			rt->iface = ifp;
+			rt->metric = ifp->metric;
 			/* Is this route already in our table? */
 			if ((find_route(nrs, rt, NULL, NULL)) != NULL)
 				continue;
+			rt->src.s_addr = ifp->addr.s_addr;
 			/* Do we already manage it? */
 			if ((or = find_route(routes, rt, &rtl, NULL))) {
 				if (or->iface != ifp ||
-				    rt->gate.s_addr != or->gate.s_addr)
+				    or->src.s_addr != ifp->addr.s_addr ||
+				    rt->gate.s_addr != or->gate.s_addr ||
+				    rt->metric != or->metric)
 				{
-					if (c_route(or, rt, ifp) != 0)
+					if (c_route(or, rt) != 0)
 						continue;
 				}
 				if (rtl != NULL)
@@ -669,7 +725,7 @@
 					routes = or->next;
 				free(or);
 			} else {
-				if (n_route(rt, ifp) != 0)
+				if (n_route(rt) != 0)
 					continue;
 			}
 			if (dnr == rt)
@@ -678,6 +734,7 @@
 				lrt->next = rtn;
 			rt->next = nrs;
 			nrs = rt;
+			rt = lrt; /* When we loop this makes lrt correct */
 		}
 		free_routes(dnr);
 	}
@@ -685,7 +742,7 @@
 	/* Remove old routes we used to manage */
 	for (rt = routes; rt; rt = rt->next) {
 		if (find_route(nrs, rt, NULL, NULL) == NULL)
-			d_route(rt, rt->iface, rt->iface->metric);
+			d_route(rt);
 	}
 
 	free_routes(routes);
@@ -766,8 +823,9 @@
 		rt = get_subnet_route(dhcp);
 		if (rt != NULL) {
 			rt->iface = iface;
+			rt->metric = 0;
 			if (!find_route(routes, rt, NULL, NULL))
-				del_route(iface, &rt->dest, &rt->net, &rt->gate, 0);
+				del_route(rt);
 			free(rt);
 		}
 
diff --git a/configure.h b/configure.h
index 17c506e..e125369 100644
--- a/configure.h
+++ b/configure.h
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2009 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -31,8 +31,10 @@
 #include "net.h"
 
 int send_interface(int, const struct interface *);
-int run_script(const struct interface *);
+int run_script_reason(const struct interface *, const char *);
 void build_routes(void);
 int configure(struct interface *);
 int route_deleted(const struct rt *);
+
+#define run_script(ifp) run_script_reason(ifp, (ifp)->state->reason);
 #endif
diff --git a/defs.h b/defs.h
index 81cf213..b4f2380 100644
--- a/defs.h
+++ b/defs.h
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2010 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -28,7 +28,7 @@
 #define CONFIG_H
 
 #define PACKAGE			"dhcpcd"
-#define VERSION			"5.2.10"
+#define VERSION			"5.5.6"
 
 #ifndef CONFIG
 # define CONFIG			SYSCONFDIR "/" PACKAGE ".conf"
diff --git a/dhcp.c b/dhcp.c
index 1169993..c22e767 100644
--- a/dhcp.c
+++ b/dhcp.c
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2010 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -50,6 +50,7 @@
 #define RFC3361	(1 << 10)
 #define RFC3397	(1 << 11)
 #define RFC3442 (1 << 12)
+#define RFC5969 (1 << 13)
 
 #define IPV4R	IPV4 | REQUEST
 
@@ -163,6 +164,8 @@
 	{ 114,	STRING,		"default_url" },
 	{ 118,	IPV4,		"subnet_selection" },
 	{ 119,	STRING | RFC3397,	"domain_search" },
+	{ 120,	STRING | RFC3361,	"sip_server" },
+	{ 212,  RFC5969,	"sixrd" },
 	{ 0, 0, NULL }
 };
 
@@ -270,18 +273,17 @@
 			*type = opt->type;
 
 		if (opt->type == 0 ||
-		    opt->type & STRING ||
-		    opt->type & RFC3442)
+		    opt->type & (STRING | RFC3442 | RFC5969))
 			return 0;
 
 		sz = 0;
-		if (opt->type & UINT32 || opt->type & IPV4)
+		if (opt->type & (UINT32 | IPV4))
 			sz = sizeof(uint32_t);
 		if (opt->type & UINT16)
 			sz = sizeof(uint16_t);
 		if (opt->type & UINT8)
 			sz = sizeof(uint8_t);
-		if (opt->type & IPV4 || opt->type & ARRAY)
+		if (opt->type & (IPV4 | ARRAY))
 			return dl % sz;
 		return (dl == sz ? 0 : -1);
 	}
@@ -428,7 +430,7 @@
  * separated string. Returns length of string (including
  * terminating zero) or zero on error. out may be NULL
  * to just determine output length. */
-static ssize_t
+ssize_t
 decode_rfc3397(char *out, ssize_t len, int pl, const uint8_t *p)
 {
 	const uint8_t *r, *q = p;
@@ -624,11 +626,11 @@
 		addr.s_addr = INADDR_BROADCAST;
 		l = ((dl / sizeof(addr.s_addr)) * ((4 * 4) + 1)) + 1;
 		sip = p = xmalloc(l);
-		while (l != 0) {
+		while (dl != 0) {
 			memcpy(&addr.s_addr, data, sizeof(addr.s_addr));
 			data += sizeof(addr.s_addr);
 			p += snprintf(p, l - (p - sip), "%s ", inet_ntoa(addr));
-			l -= sizeof(addr.s_addr);
+			dl -= sizeof(addr.s_addr);
 		}
 		*--p = '\0';
 		break;
@@ -640,6 +642,74 @@
 	return sip;
 }
 
+/* Decode an RFC5969 6rd order option into a space
+ * separated string. Returns length of string (including
+ * terminating zero) or zero on error. */
+static ssize_t
+decode_rfc5969(char *out, ssize_t len, int pl, const uint8_t *p)
+{
+	uint8_t ipv4masklen, ipv6prefixlen;
+	uint8_t ipv6prefix[16];
+	uint8_t br[4];
+	int i;
+	ssize_t b, bytes = 0;
+
+	if (pl < 22) {
+		errno = EINVAL;
+		return 0;
+	}
+	
+	ipv4masklen = *p++;
+	pl--;
+	ipv6prefixlen = *p++;
+	pl--;
+	
+	for (i = 0; i < 16; i++) {
+		ipv6prefix[i] = *p++;
+		pl--;
+	}
+	if (out) {
+		b= snprintf(out, len,
+		    "%d %d "
+		    "%02x%02x:%02x%02x:"
+		    "%02x%02x:%02x%02x:"
+		    "%02x%02x:%02x%02x:"
+		    "%02x%02x:%02x%02x",
+		    ipv4masklen, ipv6prefixlen,
+		    ipv6prefix[0], ipv6prefix[1], ipv6prefix[2], ipv6prefix[3],
+		    ipv6prefix[4], ipv6prefix[5], ipv6prefix[6], ipv6prefix[7],
+		    ipv6prefix[8], ipv6prefix[9], ipv6prefix[10],ipv6prefix[11],
+		    ipv6prefix[12],ipv6prefix[13],ipv6prefix[14], ipv6prefix[15]
+		);
+		    
+		len -= b;
+		out += b;
+		bytes += b;
+	} else {
+		bytes += 16 * 2 + 8 + 2 + 1 + 2;
+	}
+
+	while (pl >= 4) {
+		br[0] = *p++;
+		br[1] = *p++;
+		br[2] = *p++;
+		br[3] = *p++;
+		pl -= 4;
+		
+		if (out) {
+			b= snprintf(out, len, " %d.%d.%d.%d",
+			    br[0], br[1], br[2], br[3]);
+			len -= b;
+			out += b;
+			bytes += b;
+		} else {
+			bytes += (4 * 4);
+		}
+	}
+	
+	return bytes;
+}
+
 char *
 get_option_string(const struct dhcp_message *dhcp, uint8_t option)
 {
@@ -706,7 +776,7 @@
  * Otherwise we add static routes and then routers. */
 struct rt *
 get_option_routes(const struct dhcp_message *dhcp,
-    const char *ifname, int *opts)
+    const char *ifname, unsigned long long *opts)
 {
 	const uint8_t *p;
 	const uint8_t *e;
@@ -721,11 +791,13 @@
 		p = get_option(dhcp, DHO_MSCSR, &len, NULL);
 	if (p) {
 		routes = decode_rfc3442_rt(len, p);
-		if (routes && !(*opts & DHCPCD_CSR_WARNED)) {
-			syslog(LOG_DEBUG,
-			    "%s: using Classless Static Routes (RFC3442)",
-			    ifname);
-			*opts |= DHCPCD_CSR_WARNED;
+		if (routes) {
+			if (!(*opts & DHCPCD_CSR_WARNED)) {
+				syslog(LOG_DEBUG,
+				    "%s: using Classless Static Routes",
+				    ifname);
+				*opts |= DHCPCD_CSR_WARNED;
+			}
 			return routes;
 		}
 	}
@@ -1154,7 +1226,9 @@
 		case '\'': /* FALLTHROUGH */
 		case '$':  /* FALLTHROUGH */
 		case '`':  /* FALLTHROUGH */
- 		case '\\':
+ 		case '\\': /* FALLTHROUGH */
+		case '|':  /* FALLTHROUGH */
+		case '&':
 			if (s) {
 				if (len < 3) {
 					errno = ENOBUFS;
@@ -1204,9 +1278,21 @@
 		return l;
 	}
 
+	if (type & RFC3361) {
+		if ((tmp = decode_rfc3361(dl, data)) == NULL)
+			return -1;
+		l = strlen(tmp);
+		l = print_string(s, len, l - 1, (uint8_t *)tmp);
+		free(tmp);
+		return l;
+	}
+
 	if (type & RFC3442)
 		return decode_rfc3442(s, len, dl, data);
 
+	if (type & RFC5969)
+		return decode_rfc5969(s, len, dl, data);
+
 	if (type & STRING) {
 		/* Some DHCP servers return NULL strings */
 		if (*data == '\0')
@@ -1284,16 +1370,6 @@
 	return bytes;
 }
 
-static void
-setvar(char ***e, const char *prefix, const char *var, const char *value)
-{
-	size_t len = strlen(prefix) + strlen(var) + strlen(value) + 4;
-
-	**e = xmalloc(len);
-	snprintf(**e, len, "%s_%s=%s", prefix, var, value);
-	(*e)++;
-}
-
 ssize_t
 configure_env(char **env, const char *prefix, const struct dhcp_message *dhcp,
     const struct if_options *ifo)
diff --git a/dhcp.h b/dhcp.h
index cb42275..fb27e71 100644
--- a/dhcp.h
+++ b/dhcp.h
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2008 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -109,6 +109,7 @@
 	DHO_FQDN                   = 81,
 	DHO_DNSSEARCH              = 119, /* RFC 3397 */
 	DHO_CSR                    = 121, /* RFC 3442 */
+	DHO_SIXRD                  = 212, /* RFC 5969 */
 	DHO_MSCSR                  = 249, /* MS code for RFC 3442 */
 	DHO_END                    = 255
 };
@@ -185,7 +186,9 @@
 #define is_bootp(m) (m &&						\
 	    !IN_LINKLOCAL(htonl((m)->yiaddr)) &&			\
 	    get_option_uint8(NULL, m, DHO_MESSAGETYPE) == -1)
-struct rt *get_option_routes(const struct dhcp_message *, const char *, int *);
+struct rt *get_option_routes(const struct dhcp_message *, const char *,
+    unsigned long long *);
+ssize_t decode_rfc3397(char *, ssize_t, int, const uint8_t *);
 ssize_t configure_env(char **, const char *, const struct dhcp_message *,
     const struct if_options *);
 
diff --git a/dhcpcd-run-hooks.8.in b/dhcpcd-run-hooks.8.in
index bcfc81d..c0dc081 100644
--- a/dhcpcd-run-hooks.8.in
+++ b/dhcpcd-run-hooks.8.in
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2006-2010 Roy Marples
+.\" Copyright (c) 2006-2012 Roy Marples
 .\" All rights reserved
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -22,8 +22,8 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd August 24, 2010
-.Dt DHCPCD-RUN-HOOKS 8 SMM
+.Dd March 19, 2012
+.Dt DHCPCD-RUN-HOOKS 8
 .Os
 .Sh NAME
 .Nm dhcpcd-run-hooks
@@ -69,7 +69,7 @@
 Here's a list of reasons why
 .Nm
 could be invoked:
-.Bl -tag -width PREINIT
+.Bl -tag -width ROUTERADVERT
 .It Dv PREINIT
 dhcpcd is starting up and any pre-initialisation should be done.
 .It Dv CARRIER
@@ -119,6 +119,8 @@
 interface.
 This is primarily used to test the variables are filled correctly for the
 script to process them.
+.It Dv ROUTERADVERT
+dhcpcd has received an IPv6 Router Advertisment, or one has expired.
 .El
 .Sh FILES
 When
@@ -134,4 +136,13 @@
 .Sh AUTHORS
 .An Roy Marples Aq roy@marples.name
 .Sh BUGS
-Please report them to http://roy.marples.name/projects/dhcpcd
+Please report them to
+.Lk http://roy.marples.name/projects/dhcpcd
+.Sh SECURITY CONSIDERATIONS
+Little validation of DHCP options is done in dhcpcd itself.
+Instead, it is up to the hooks to handle any validation needed.
+To this end, some helper functions are provided, such as valid_domainname as
+used by the
+.Pa 20-resolv.conf
+hook to ensure that the hostname is not set to an invalid value.
+valid_path is also provided, but is currently unused by a stock hook script.
diff --git a/dhcpcd-run-hooks.in b/dhcpcd-run-hooks.in
index cb897b4..2125f9a 100644
--- a/dhcpcd-run-hooks.in
+++ b/dhcpcd-run-hooks.in
@@ -2,25 +2,25 @@
 # dhcpcd client configuration script 
 
 # Handy variables and functions for our hooks to use
+if [ "$reason" = ROUTERADVERT ]; then
+	ifsuffix=":ra"
+else
+	ifsuffix=
+fi
+ifname="$interface$ifsuffix"
+
 from=from
 signature_base="# Generated by dhcpcd"
-signature="$signature_base $from $interface"
+signature="$signature_base $from $ifname"
 signature_base_end="# End of dhcpcd"
-signature_end="$signature_base_end $from $interface"
+signature_end="$signature_base_end $from $ifname"
 state_dir=/var/run/dhcpcd
 
-if_up=false
-if_down=false
-case "$reason" in
-BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC)	if_up=true;;
-PREINIT|EXPIRE|FAIL|IPV4LL|NAK|NOCARRIER|RELEASE|STOP)	if_down=true;;
-esac
-
 # Ensure that all arguments are unique
 uniqify()
 {
 	local result= i=
-	for i; do
+	for i do
 		case " $result " in
 			*" $i "*);;
 			*) result="$result $i";;
@@ -62,7 +62,7 @@
 	if type sed >/dev/null 2>&1; then
 		sed -n "s/^$key//p" $@
 	else
-		for x; do
+		for x do
 			while read line; do
 				case "$line" in
 				"$key"*) echo "${line##$key}";;
@@ -82,7 +82,7 @@
 	if type sed >/dev/null 2>&1; then
 		sed "/^$m1/,/^$m2/d" $@
 	else
-		for x; do
+		for x do
 			while read line; do
 				case "$line" in
 				"$m1"*) in_marker=1;;
@@ -142,11 +142,51 @@
 	[ -n "$lvl" ] && shift
 	if [ -n "$*" ]; then
 		if type logger >/dev/null 2>&1; then
-			logger -t dhcpcd -p daemon."$lvl" -s "$*"
+			logger -t dhcpcd -p daemon."$lvl" -is "$interface: $*"
 		fi
 	fi
 }
 
+# Check for a valid domain name as per RFC1123 with the exception of
+# allowing - and _ as they seem to be widely used.
+valid_domainname()
+{
+	local name="$1" label
+
+	[ -z "$name" -o ${#name} -gt 255 ] && return 1
+	
+	while [ -n "$name" ]; do
+		label="${name%%.*}"
+		[ -z "$label" -o ${#label} -gt 63 ] && return 1
+		case "$label" in
+		-*|_*|*-|*_)		return 1;;
+		*[![:alnum:]-_]*)	return 1;;
+		esac
+		[ "$name" = "${name#*.}" ] && break
+		name="${name#*.}"
+	done
+	return 0	
+}
+
+valid_domainname_list()
+{
+	local name
+
+	for name do
+		valid_domainname "$name" || return $?
+	done
+	return 0
+}
+
+# Check for a valid path
+valid_path()
+{
+	case "$@" in
+	*[![:alnum:]#%+-_:\.,@~\\/\[\]=\ ]*) return 1;;
+	esac
+	return 0
+}
+
 # Check a system service exists 
 service_exists()
 {
diff --git a/dhcpcd.8 b/dhcpcd.8
index 2acfb90..bfeb614 100644
--- a/dhcpcd.8
+++ b/dhcpcd.8
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2006-2010 Roy Marples
+.\" Copyright (c) 2006-2012 Roy Marples
 .\" All rights reserved
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -22,52 +22,52 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd August 31, 2010
-.Dt DHCPCD 8 SMM
+.Dd June 7, 2012
+.Dt DHCPCD 8
 .Os
 .Sh NAME
 .Nm dhcpcd
 .Nd an RFC 2131 compliant DHCP client
 .Sh SYNOPSIS
 .Nm
-.Op Fl bdgknpqwABDEGHJKLTV
-.Op Fl c , -script Ar script
-.Op Fl e , -env Ar value
-.Op Fl f , -config Ar file
-.Op Fl h , -hostname Ar hostname
-.Op Fl i , -vendorclassid Ar vendorclassid
-.Op Fl l , -leasetime Ar seconds
-.Op Fl m , -metric Ar metric
-.Op Fl o , -option Ar option
-.Op Fl r , -request Ar address
-.Op Fl s , -inform Ar address Ns Op Ar /cidr
-.Op Fl t , -timeout Ar seconds
-.Op Fl u , -userclass Ar class
-.Op Fl v , -vendor Ar code , Ar value
-.Op Fl y , -reboot Ar seconds
-.Op Fl z , -allowinterfaces Ar pattern
-.Op Fl C , -nohook Ar hook
-.Op Fl F , -fqdn Ar FQDN
-.Op Fl I , -clientid Ar clientid
-.Op Fl O , -nooption Ar option
-.Op Fl Q , -require Ar option
-.Op Fl S , -static Ar value
-.Op Fl W , -whitelist Ar address Ns Op Ar /cidr
-.Op Fl X , -blacklist Ar address Ns Op Ar /cidr
-.Op Fl Z , -denyinterfaces Ar pattern
+.Op Fl ABbDdEGgHJKkLnpqTVw
+.Op Fl C , Fl Fl nohook Ar hook
+.Op Fl c , Fl Fl script Ar script
+.Op Fl e , Fl Fl env Ar value
+.Op Fl F , Fl Fl fqdn Ar FQDN
+.Op Fl f , Fl Fl config Ar file
+.Op Fl h , Fl Fl hostname Ar hostname
+.Op Fl I , Fl Fl clientid Ar clientid
+.Op Fl i , Fl Fl vendorclassid Ar vendorclassid
+.Op Fl l , Fl Fl leasetime Ar seconds
+.Op Fl m , Fl Fl metric Ar metric
+.Op Fl O , Fl Fl nooption Ar option
+.Op Fl o , Fl Fl option Ar option
+.Op Fl Q , Fl Fl require Ar option
+.Op Fl r , Fl Fl request Ar address
+.Op Fl S , Fl Fl static Ar value
+.Op Fl s , Fl Fl inform Ar address Ns Op Ar /cidr
+.Op Fl t , Fl Fl timeout Ar seconds
+.Op Fl u , Fl Fl userclass Ar class
+.Op Fl v , Fl Fl vendor Ar code , Ar value
+.Op Fl W , Fl Fl whitelist Ar address Ns Op Ar /cidr
+.Op Fl y , Fl Fl reboot Ar seconds
+.Op Fl X , Fl Fl blacklist Ar address Ns Op Ar /cidr
+.Op Fl Z , Fl Fl denyinterfaces Ar pattern
+.Op Fl z , Fl Fl allowinterfaces Ar pattern
 .Op interface
 .Op ...
 .Nm
-.Fl k , -release
+.Fl k , Fl Fl release
 .Op interface
 .Nm
-.Fl U, -dumplease
+.Fl U, Fl Fl dumplease
 .Ar interface
 .Nm
-.Fl x , -exit
-.Op interface
+.Fl Fl version
 .Nm
-.Fl v , -version
+.Fl x , Fl Fl exit
+.Op interface
 .Sh DESCRIPTION
 .Nm
 is an implementation of the DHCP client specified in
@@ -99,6 +99,21 @@
 .Nm
 is also an implementation of the BOOTP client specified in
 .Li RFC 951 .
+.Pp
+.Nm
+is also an implementation of an IPv6 Router Solicitor as specified in
+.Li RFC 4861
+and
+.Li RFC 6106 .
+.Nm
+can optionally handle address and route management itself,
+and will do so by default if Router Solicitation is disabled in the kernel.
+If
+.Nm
+is managing routes,
+.Nm
+sends Neighbor Solicitions to each advertising router periodically and will
+expire the ones that do not respond.
 .Ss Local Link configuration
 If
 .Nm
@@ -115,7 +130,7 @@
 In the rare case it fails, it normally means that there is a reverse ARP proxy
 installed which always defeats IPv4LL probing.
 To disable this behaviour, you can use the
-.Fl L , -noipv4ll
+.Fl L , Fl Fl noipv4ll
 option.
 .Ss Multiple interfaces
 If a list of interfaces are given on the command line, then
@@ -128,16 +143,16 @@
 will try and obtain a lease before forking to the background,
 otherwise it will fork right away.
 This behaviour can be modified with the
-.Fl b , -background
+.Fl b , Fl Fl background
 and
-.Fl w , -waitip
+.Fl w , Fl Fl waitip
 options.
 .Pp
 If a single interface is given then
 .Nm
 only works for that interface and runs as a separate instance.
 The
-.Fl w , -waitip
+.Fl w , Fl Fl waitip
 option is enabled in this instance to maintain compatibility with older
 versions.
 .Pp
@@ -154,7 +169,7 @@
 runs
 .Pa /libexec/dhcpcd-run-hooks ,
 or the script specified by the
-.Fl c , -script
+.Fl c , Fl Fl script
 option.
 This script runs each script found in
 .Pa /libexec/dhcpcd-hooks
@@ -166,7 +181,7 @@
 and
 .Pa 30-hostname .
 You can disable each script by using the
-.Fl C , -nohook
+.Fl C , Fl Fl nohook
 option.
 See
 .Xr dhcpcd-run-hooks 8
@@ -178,18 +193,36 @@
 .Nm
 with the following options:
 .Bl -tag -width indent
-.It Fl b , -background
+.It Fl b , Fl Fl background
 Background immediately.
 This is useful for startup scripts which don't disable link messages for
 carrier status.
-.It Fl c , -script Ar script
+.It Fl c , Fl Fl script Ar script
 Use this
 .Ar script
 instead of the default
 .Pa /libexec/dhcpcd-run-hooks .
-.It Fl d , -debug
+.It Fl D , Fl Fl duid
+Generate an
+.Li RFC 4361
+compliant clientid.
+This requires persistent storage and not all DHCP servers work with it so it
+is not enabled by default.
+.Nm
+generates the DUID and stores it in
+.Pa /etc/dhcpcd.duid .
+This file should not be copied to other hosts.
+.It Fl d , Fl Fl debug
 Echo debug messages to the stderr and syslog.
-.It Fl e , -env Ar value
+.It Fl E , Fl Fl lastlease
+If
+.Nm
+cannot obtain a lease, then try to use the last lease acquired for the
+interface.
+If the
+.Fl p, Fl Fl persistent
+option is not given then the lease is used if it hasn't expired.
+.It Fl e , Fl Fl env Ar value
 Push
 .Ar value
 to the environment for use in
@@ -197,7 +230,7 @@
 For example, you can force the hostname hook to always set the hostname with
 .Fl e
 .Va force_hostname=YES .
-.It Fl g , -reconfigure
+.It Fl g , Fl Fl reconfigure
 .Nm
 will re-apply IP address, routing and run
 .Xr dhcpcd-run-hooks 8
@@ -209,12 +242,23 @@
 .Nm
 does not read a new configuration when this happens - you should rebind if you
 need that functionality.
-.It Fl f , -config Ar file
+.It Fl F , Fl Fl fqdn Ar fqdn
+Requests that the DHCP server updates DNS using FQDN instead of just a
+hostname.
+Valid values for
+.Ar fqdn
+are disable, none, ptr and both.
+.Nm
+itself never does any DNS updates.
+.Nm
+encodes the FQDN hostname as specified in
+.Li RFC1035 .
+.It Fl f , Fl Fl config Ar file
 Specify a config to load instead of
 .Pa /etc/dhcpcd.conf .
 .Nm
 always processes the config file before any command line options.
-.It Fl h , -hostname Ar hostname
+.It Fl h , Fl Fl hostname Ar hostname
 Sends
 .Ar hostname
 to the DHCP server so it can be registered in DNS.
@@ -224,13 +268,29 @@
 If
 .Ar hostname
 is a FQDN (ie, contains a .) then it will be encoded as such.
-.It Fl i , -vendorclassid Ar vendorclassid
+.It Fl I , Fl Fl clientid Ar clientid
+Send the
+.Ar clientid .
+If the string is of the format 01:02:03 then it is encoded as hex.
+For interfaces whose hardware address is longer than 8 bytes, or if the
+.Ar clientid
+is an empty string then
+.Nm
+sends a default
+.Ar clientid
+of the hardware family and the hardware address.
+.It Fl i , Fl Fl vendorclassid Ar vendorclassid
 Override the
 .Ar vendorclassid
-field sent. The default is
-dhcpcd <version>.
+field sent.
+The default is
+dhcpcd-<version>:<os>:<machine>:<platform>.
+For example
+.D1 dhcpcd-5.5.6:NetBSD-6.99.5:i386:i386
 If not set then none is sent.
-.It Fl k , -release
+Some badly configured DHCP servers reject unknown vendorclassids.
+To work around it, try and impersonate Windows by using the MSFT vendorclassid.
+.It Fl k , Fl Fl release
 This causes an existing
 .Nm
 process running on the
@@ -240,32 +300,32 @@
 and then exit.
 .Nm
 then waits until this process has exited.
-.It Fl l , -leasetime Ar seconds
+.It Fl l , Fl Fl leasetime Ar seconds
 Request a specific lease time in
 .Ar seconds .
 By default
 .Nm
 does not request any lease time and leaves it in the hands of the
 DHCP server.
-.It Fl m , -metric Ar metric
+.It Fl m , Fl Fl metric Ar metric
 Metrics are used to prefer an interface over another one, lowest wins.
 .Nm
 will supply a default metic of 200 +
 .Xr if_nametoindex 3 .
 An extra 100 will be added for wireless interfaces.
-.It Fl o , -option Ar option
-Request the DHCP
-.Ar option
-variable for use in
-.Pa /libexec/dhcpcd-run-hooks .
-.It Fl n , -rebind
+.It Fl n , Fl Fl rebind
 Notifies
 .Nm
 to reload its configuration and rebind its interfaces.
 If
 .Nm
 is not running, then it starts up as normal.
-.It Fl p , -persistent
+.It Fl o , Fl Fl option Ar option
+Request the DHCP
+.Ar option
+variable for use in
+.Pa /libexec/dhcpcd-run-hooks .
+.It Fl p , Fl Fl persistent
 .Nm
 normally de-configures the
 .Ar interface
@@ -273,27 +333,20 @@
 Sometimes, this isn't desirable if, for example, you have root mounted over
 NFS.
 You can use this option to stop this from happening.
-.It Fl r , -request Op Ar address
-.Nm
-normally sends a DHCP DISCOVER to find servers to offer an address.
-.Nm
-then requests the address used.
-You can use this option to skip the DISCOVER phase and just request the
-.Ar address .
-The downside is if you request an
+.It Fl r , Fl Fl request Op Ar address
+Request the
 .Ar address
-the DHCP server does not know about or the DHCP server is not
-authoritative, it will remain silent.
-In this situation, we go back to the init state and DISCOVER again.
+in the DHCP DISCOVER message.
+There is no guarantee this is the address the DHCP server will actually give.
 If no
 .Ar address
 is given then the first address currently assigned to the
 .Ar interface
 is used.
-.It Fl s , -inform Op Ar address Ns Op Ar /cidr
+.It Fl s , Fl Fl inform Op Ar address Ns Op Ar /cidr
 Behaves like
-.Fl r , -request
-as above, but sends a DHCP INFORM instead of a REQUEST.
+.Fl r , Fl Fl request
+as above, but sends a DHCP INFORM instead of DISCOVER/REQUEST.
 This does not get a lease as such, just notifies the DHCP server of the
 .Ar address
 in use.
@@ -308,7 +361,7 @@
 .Nm
 fails to contact a DHCP server then it returns a failure instead of falling
 back on IPv4LL.
-.It Fl t , -timeout Ar seconds
+.It Fl t , Fl Fl timeout Ar seconds
 Timeout after
 .Ar seconds ,
 instead of the default 30.
@@ -317,12 +370,12 @@
 causes
 .Nm
 to wait forever to get a lease.
-.It Fl u , -userclass Ar class
+.It Fl u , Fl Fl userclass Ar class
 Tags the DHCP message with the userclass
 .Ar class .
 DHCP servers use this to give members of the class DHCP options other than the
 default, without having to know things like hardware address or hostname.
-.It Fl v , -vendor Ar code , Ns Ar value
+.It Fl v , Fl Fl vendor Ar code , Ns Ar value
 Add an encapsulated vendor option.
 .Ar code
 should be between 1 and 254 inclusive.
@@ -339,13 +392,13 @@
 .D1 dhcpcd \-v 03,\e"192.168.0.2\e" eth0
 Set un-encapsulated vendor option to hello world.
 .D1 dhcpcd \-v ,"hello world" eth0
-.It Fl v , -version
+.It Fl Fl version
 Display both program version and copyright information.
 .Nm
 then exits before doing any configuration.
-.It Fl w , -waitip
+.It Fl w , Fl Fl waitip
 Wait for an address to be assigned before forking to the background.
-.It Fl x , -exit
+.It Fl x , Fl Fl exit
 This will signal an existing
 .Nm
 process running on the
@@ -355,54 +408,14 @@
 and exit.
 .Nm
 then waits until this process has exited.
-.It Fl y , -reboot Ar seconds
+.It Fl y , Fl Fl reboot Ar seconds
 Allow
 .Ar reboot
 seconds before moving to the discover phase if we have an old lease to use.
-The default is 10 seconds.
+The default is 5 seconds.
 A setting of 0 seconds causes
 .Nm
 to skip the reboot phase and go straight into discover.
-.It Fl D , -duid
-Generate an
-.Li RFC 4361
-compliant clientid.
-This requires persistent storage and not all DHCP servers work with it so it
-is not enabled by default.
-.Nm
-generates the DUID and stores it in
-.Pa /etc/dhcpcd.duid .
-This file should not be copied to other hosts.
-.It Fl E , -lastlease
-If
-.Nm
-cannot obtain a lease, then try to use the last lease acquired for the
-interface.
-If the
-.Fl p, -persistent
-option is not given then the lease is used if it hasn't expired.
-.It Fl F , -fqdn Ar fqdn
-Requests that the DHCP server updates DNS using FQDN instead of just a
-hostname.
-Valid values for
-.Ar fqdn
-are disable, none, ptr and both.
-.Nm
-itself never does any DNS updates.
-.Nm
-encodes the FQDN hostname as specified in
-.Li RFC1035 .
-.It Fl I , -clientid Ar clientid
-Send the
-.Ar clientid .
-If the string is of the format 01:02:03 then it is encoded as hex.
-For interfaces whose hardware address is longer than 8 bytes, or if the
-.Ar clientid
-is an empty string then
-.Nm
-sends a default
-.Ar clientid
-of the hardware family and the hardware address.
 .El
 .Ss Restricting behaviour
 .Nm
@@ -411,27 +424,14 @@
 configured exactly how the the DHCP server wants.
 Here are some options that deal with turning these bits off.
 .Bl -tag -width indent
-.It Fl q , -quiet
-Quiet
-.Nm
-on the command line, only warnings and errors will be displayed.
-The messages are still logged though.
-.It Fl z , -allowinterfaces Ar pattern
-When discovering interfaces, the interface name must match
-.Ar pattern
-which is a space or comma separated list of patterns passed to
-.Xr fnmatch 3 .
-If the same interface is matched in
-.Fl Z , -denyinterfaces
-then it is still denied.
-.It Fl A , -noarp
+.It Fl A , Fl Fl noarp
 Don't request or claim the address by ARP.
 This also disables IPv4LL.
-.It Fl B , -nobackground
+.It Fl B , Fl Fl nobackground
 Don't run in the background when we acquire a lease.
 This is mainly useful for running under the control of another process, such
 as a debugger or a network manager.
-.It Fl C , -nohook Ar script
+.It Fl C , Fl Fl nohook Ar script
 Don't run this hook script.
 Matches full name, or prefixed with 2 numbers optionally ending with
 .Pa .sh .
@@ -440,30 +440,30 @@
 .Nm
 from touching your DNS or MTU settings you would do:-
 .D1 dhcpcd -C resolv.conf -C mtu eth0
-.It Fl G , -nogateway
+.It Fl G , Fl Fl nogateway
 Don't set any default routes.
-.It Fl H , -xidhwaddr
+.It Fl H , Fl Fl xidhwaddr
 Use the last four bytes of the hardware address as the DHCP xid instead
 of a randomly generated number.
-.It Fl J , -broadcast
+.It Fl J , Fl Fl broadcast
 Instructs the DHCP server to broadcast replies back to the client.
 Normally this is only set for non Ethernet interfaces,
 such as FireWire and InfiniBand.
 In most instances,
 .Nm
 will set this automatically.
-.It Fl K , -nolink
+.It Fl K , Fl Fl nolink
 Don't receive link messages for carrier status.
 You should only have to use this with buggy device drivers or running
 .Nm
 through a network manager.
-.It Fl L , -noipv4ll
+.It Fl L , Fl Fl noipv4ll
 Don't use IPv4LL (aka APIPA, aka Bonjour, aka ZeroConf).
-.It Fl O , -nooption Ar option
+.It Fl O , Fl Fl nooption Ar option
 Don't request the specified option.
 If no option given, then don't request any options other than those to
 configure the interface and routing.
-.It Fl Q , -require Ar option
+.It Fl Q , Fl Fl require Ar option
 Requires the
 .Ar option
 to be present in all DHCP messages, otherwise the message is ignored.
@@ -472,7 +472,12 @@
 only responds to DHCP servers and not BOOTP servers, you can
 .Fl Q
 .Ar dhcp_message_type .
-.It Fl S, -static Ar value
+.It Fl q , Fl Fl quiet
+Quiet
+.Nm
+on the command line, only warnings and errors will be displayed.
+The messages are still logged though.
+.It Fl S, Fl Fl static Ar value
 Configures a static
 .Ar value .
 If you set
@@ -487,7 +492,7 @@
 .D1 -S routers=192.168.0.1 \e
 .D1 -S domain_name_servers=192.168.0.1 \e
 .D1 eth0
-.It Fl T, -test
+.It Fl T, Fl Fl test
 On receipt of DHCP messages just call
 .Pa /libexec/dhcpcd-run-hooks
 with the reason of TEST which echos the DHCP variables found in the message
@@ -497,33 +502,41 @@
 To test INFORM the interface needs to be configured with the desired address
 before starting
 .Nm .
-.It Fl U, -dumplease Ar interface
+.It Fl U, Fl Fl dumplease Ar interface
 Dumps the last lease for the
 .Ar interface
 to stdout.
 .Ar interface
 could also be a path to a DHCP wire formatted file.
-.It Fl V, -variables
+.It Fl V, Fl Fl variables
 Display a list of option codes and the associated variable for use in
 .Xr dhcpcd-run-hooks 8 .
 Variables are prefixed with new_ and old_ unless the option number is -.
 Variables without an option are part of the DHCP message and cannot be
 directly requested.
-.It Fl W, -whitelist Ar address Ns Op /cidr
+.It Fl W, Fl Fl whitelist Ar address Ns Op /cidr
 Only accept packets from
 .Ar address Ns Op /cidr .
-.Fl X, -blacklist
+.Fl X, Fl Fl blacklist
 is ignored if
-.Fl W, -whitelist
+.Fl W, Fl Fl whitelist
 is set.
-.It Fl X, -blacklist Ar address Ns Op Ar /cidr
+.It Fl X, Fl Fl blacklist Ar address Ns Op Ar /cidr
 Ignore all packets from
 .Ar address Ns Op Ar /cidr .
-.It Fl Z , -denyinterfaces Ar pattern
+.It Fl Z , Fl Fl denyinterfaces Ar pattern
 When discovering interfaces, the interface name must not match
 .Ar pattern
 which is a space or comma separated list of patterns passed to
 .Xr fnmatch 3 .
+.It Fl z , Fl Fl allowinterfaces Ar pattern
+When discovering interfaces, the interface name must match
+.Ar pattern
+which is a space or comma separated list of patterns passed to
+.Xr fnmatch 3 .
+If the same interface is matched in
+.Fl Z , Fl Fl denyinterfaces
+then it is still denied.
 .El
 .Sh 3RDPARTY LINK MANAGEMENT
 Some interfaces require configuration by 3rd parties, such as PPP or VPN.
@@ -535,7 +548,7 @@
 act accordingly.
 For point to point interfaces (like PPP), a default route to its
 destination is automatically added to the configuration.
-If the point to point interface if configured for INFORM, then
+If the point to point interface is configured for INFORM, then
 .Nm
 unicasts INFORM to the destination, otherwise it defaults to STATIC.
 .Sh NOTES
@@ -554,10 +567,11 @@
 .It Pa /libexec/dhcpcd-hooks
 A directory containing bourne shell scripts that are run by the above script.
 Each script can be disabled by using the
-.Fl C , -nohook
+.Fl C , Fl Fl nohook
 option described above.
 .It Pa /var/db/dhcpcd\- Ns Ar interface Ns .lease
-The actual DHCP message send by the server. We use this when reading the last
+The actual DHCP message send by the server.
+We use this when reading the last
 lease and use the files mtime as when it was issued.
 .It Pa /var/run/dhcpcd.pid
 Stores the PID of
@@ -570,16 +584,18 @@
 .Ar interface .
 .El
 .Sh SEE ALSO
-.Xr dhcpcd.conf 5 ,
-.Xr dhcpcd-run-hooks 8 ,
-.Xr resolv.conf 5 ,
-.Xr resolvconf 8 ,
+.Xr fnmatch 3 ,
 .Xr if_nametoindex 3 ,
-.Xr fnmatch 3
+.Xr dhcpcd.conf 5 ,
+.Xr resolv.conf 5 ,
+.Xr dhcpcd-run-hooks 8 ,
+.Xr resolvconf 8
 .Sh STANDARDS
 RFC 951, RFC 1534, RFC 2131, RFC 2132, RFC 2855, RFC 3004, RFC 3361, RFC 3396,
-RFC 3397, RFC 3442, RFC 3927, RFC 4361, RFC 4390, RFC 4702.
+RFC 3397, RFC 3442, RFC 3927, RFC 4361, RFC 4390, RFC 4702, RFC 4861, RFC 5969,
+RFC 6106.
 .Sh AUTHORS
 .An Roy Marples Aq roy@marples.name
 .Sh BUGS
-Please report them to http://roy.marples.name/projects/dhcpcd
+Please report them to
+.Lk http://roy.marples.name/projects/dhcpcd
diff --git a/dhcpcd.8.in b/dhcpcd.8.in
index 5993878..fc3c04c 100644
--- a/dhcpcd.8.in
+++ b/dhcpcd.8.in
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2006-2010 Roy Marples
+.\" Copyright (c) 2006-2012 Roy Marples
 .\" All rights reserved
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -22,52 +22,52 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd August 31, 2010
-.Dt DHCPCD 8 SMM
+.Dd March 19, 2012
+.Dt DHCPCD 8
 .Os
 .Sh NAME
 .Nm dhcpcd
 .Nd an RFC 2131 compliant DHCP client
 .Sh SYNOPSIS
 .Nm
-.Op Fl bdgknpqwABDEGHJKLTV
-.Op Fl c , -script Ar script
-.Op Fl e , -env Ar value
-.Op Fl f , -config Ar file
-.Op Fl h , -hostname Ar hostname
-.Op Fl i , -vendorclassid Ar vendorclassid
-.Op Fl l , -leasetime Ar seconds
-.Op Fl m , -metric Ar metric
-.Op Fl o , -option Ar option
-.Op Fl r , -request Ar address
-.Op Fl s , -inform Ar address Ns Op Ar /cidr
-.Op Fl t , -timeout Ar seconds
-.Op Fl u , -userclass Ar class
-.Op Fl v , -vendor Ar code , Ar value
-.Op Fl y , -reboot Ar seconds
-.Op Fl z , -allowinterfaces Ar pattern
-.Op Fl C , -nohook Ar hook
-.Op Fl F , -fqdn Ar FQDN
-.Op Fl I , -clientid Ar clientid
-.Op Fl O , -nooption Ar option
-.Op Fl Q , -require Ar option
-.Op Fl S , -static Ar value
-.Op Fl W , -whitelist Ar address Ns Op Ar /cidr
-.Op Fl X , -blacklist Ar address Ns Op Ar /cidr
-.Op Fl Z , -denyinterfaces Ar pattern
+.Op Fl ABbDdEGgHJKkLnpqTVw
+.Op Fl C , Fl Fl nohook Ar hook
+.Op Fl c , Fl Fl script Ar script
+.Op Fl e , Fl Fl env Ar value
+.Op Fl F , Fl Fl fqdn Ar FQDN
+.Op Fl f , Fl Fl config Ar file
+.Op Fl h , Fl Fl hostname Ar hostname
+.Op Fl I , Fl Fl clientid Ar clientid
+.Op Fl i , Fl Fl vendorclassid Ar vendorclassid
+.Op Fl l , Fl Fl leasetime Ar seconds
+.Op Fl m , Fl Fl metric Ar metric
+.Op Fl O , Fl Fl nooption Ar option
+.Op Fl o , Fl Fl option Ar option
+.Op Fl Q , Fl Fl require Ar option
+.Op Fl r , Fl Fl request Ar address
+.Op Fl S , Fl Fl static Ar value
+.Op Fl s , Fl Fl inform Ar address Ns Op Ar /cidr
+.Op Fl t , Fl Fl timeout Ar seconds
+.Op Fl u , Fl Fl userclass Ar class
+.Op Fl v , Fl Fl vendor Ar code , Ar value
+.Op Fl W , Fl Fl whitelist Ar address Ns Op Ar /cidr
+.Op Fl y , Fl Fl reboot Ar seconds
+.Op Fl X , Fl Fl blacklist Ar address Ns Op Ar /cidr
+.Op Fl Z , Fl Fl denyinterfaces Ar pattern
+.Op Fl z , Fl Fl allowinterfaces Ar pattern
 .Op interface
 .Op ...
 .Nm
-.Fl k , -release
+.Fl k , Fl Fl release
 .Op interface
 .Nm
-.Fl U, -dumplease
+.Fl U, Fl Fl dumplease
 .Ar interface
 .Nm
-.Fl x , -exit
-.Op interface
+.Fl Fl version
 .Nm
-.Fl v , -version
+.Fl x , Fl Fl exit
+.Op interface
 .Sh DESCRIPTION
 .Nm
 is an implementation of the DHCP client specified in
@@ -99,6 +99,11 @@
 .Nm
 is also an implementation of the BOOTP client specified in
 .Li RFC 951 .
+.Pp
+.Nm
+is also an implementation of an IPv6 Router Solicitor as specified in
+.Li RFC 6106
+with regard to the RDNSS and DNSSL options.
 .Ss Local Link configuration
 If
 .Nm
@@ -115,7 +120,7 @@
 In the rare case it fails, it normally means that there is a reverse ARP proxy
 installed which always defeats IPv4LL probing.
 To disable this behaviour, you can use the
-.Fl L , -noipv4ll
+.Fl L , Fl Fl noipv4ll
 option.
 .Ss Multiple interfaces
 If a list of interfaces are given on the command line, then
@@ -128,16 +133,16 @@
 will try and obtain a lease before forking to the background,
 otherwise it will fork right away.
 This behaviour can be modified with the
-.Fl b , -background
+.Fl b , Fl Fl background
 and
-.Fl w , -waitip
+.Fl w , Fl Fl waitip
 options.
 .Pp
 If a single interface is given then
 .Nm
 only works for that interface and runs as a separate instance.
 The
-.Fl w , -waitip
+.Fl w , Fl Fl waitip
 option is enabled in this instance to maintain compatibility with older
 versions.
 .Pp
@@ -154,7 +159,7 @@
 runs
 .Pa @SCRIPT@ ,
 or the script specified by the
-.Fl c , -script
+.Fl c , Fl Fl script
 option.
 This script runs each script found in
 .Pa @HOOKDIR@
@@ -166,7 +171,7 @@
 and
 .Pa 30-hostname .
 You can disable each script by using the
-.Fl C , -nohook
+.Fl C , Fl Fl nohook
 option.
 See
 .Xr dhcpcd-run-hooks 8
@@ -178,18 +183,36 @@
 .Nm
 with the following options:
 .Bl -tag -width indent
-.It Fl b , -background
+.It Fl b , Fl Fl background
 Background immediately.
 This is useful for startup scripts which don't disable link messages for
 carrier status.
-.It Fl c , -script Ar script
+.It Fl c , Fl Fl script Ar script
 Use this
 .Ar script
 instead of the default
 .Pa @SCRIPT@ .
-.It Fl d , -debug
+.It Fl D , Fl Fl duid
+Generate an
+.Li RFC 4361
+compliant clientid.
+This requires persistent storage and not all DHCP servers work with it so it
+is not enabled by default.
+.Nm
+generates the DUID and stores it in
+.Pa @SYSCONFDIR@/dhcpcd.duid .
+This file should not be copied to other hosts.
+.It Fl d , Fl Fl debug
 Echo debug messages to the stderr and syslog.
-.It Fl e , -env Ar value
+.It Fl E , Fl Fl lastlease
+If
+.Nm
+cannot obtain a lease, then try to use the last lease acquired for the
+interface.
+If the
+.Fl p, Fl Fl persistent
+option is not given then the lease is used if it hasn't expired.
+.It Fl e , Fl Fl env Ar value
 Push
 .Ar value
 to the environment for use in
@@ -197,7 +220,7 @@
 For example, you can force the hostname hook to always set the hostname with
 .Fl e
 .Va force_hostname=YES .
-.It Fl g , -reconfigure
+.It Fl g , Fl Fl reconfigure
 .Nm
 will re-apply IP address, routing and run
 .Xr dhcpcd-run-hooks 8
@@ -209,12 +232,23 @@
 .Nm
 does not read a new configuration when this happens - you should rebind if you
 need that functionality.
-.It Fl f , -config Ar file
+.It Fl F , Fl Fl fqdn Ar fqdn
+Requests that the DHCP server updates DNS using FQDN instead of just a
+hostname.
+Valid values for
+.Ar fqdn
+are disable, none, ptr and both.
+.Nm
+itself never does any DNS updates.
+.Nm
+encodes the FQDN hostname as specified in
+.Li RFC1035 .
+.It Fl f , Fl Fl config Ar file
 Specify a config to load instead of
 .Pa @SYSCONFDIR@/dhcpcd.conf .
 .Nm
 always processes the config file before any command line options.
-.It Fl h , -hostname Ar hostname
+.It Fl h , Fl Fl hostname Ar hostname
 Sends
 .Ar hostname
 to the DHCP server so it can be registered in DNS.
@@ -224,13 +258,25 @@
 If
 .Ar hostname
 is a FQDN (ie, contains a .) then it will be encoded as such.
-.It Fl i , -vendorclassid Ar vendorclassid
+.It Fl I , Fl Fl clientid Ar clientid
+Send the
+.Ar clientid .
+If the string is of the format 01:02:03 then it is encoded as hex.
+For interfaces whose hardware address is longer than 8 bytes, or if the
+.Ar clientid
+is an empty string then
+.Nm
+sends a default
+.Ar clientid
+of the hardware family and the hardware address.
+.It Fl i , Fl Fl vendorclassid Ar vendorclassid
 Override the
 .Ar vendorclassid
-field sent. The default is
+field sent.
+The default is
 dhcpcd <version>.
 If not set then none is sent.
-.It Fl k , -release
+.It Fl k , Fl Fl release
 This causes an existing
 .Nm
 process running on the
@@ -240,32 +286,32 @@
 and then exit.
 .Nm
 then waits until this process has exited.
-.It Fl l , -leasetime Ar seconds
+.It Fl l , Fl Fl leasetime Ar seconds
 Request a specific lease time in
 .Ar seconds .
 By default
 .Nm
 does not request any lease time and leaves it in the hands of the
 DHCP server.
-.It Fl m , -metric Ar metric
+.It Fl m , Fl Fl metric Ar metric
 Metrics are used to prefer an interface over another one, lowest wins.
 .Nm
 will supply a default metic of 200 +
 .Xr if_nametoindex 3 .
 An extra 100 will be added for wireless interfaces.
-.It Fl o , -option Ar option
-Request the DHCP
-.Ar option
-variable for use in
-.Pa @SCRIPT@ .
-.It Fl n , -rebind
+.It Fl n , Fl Fl rebind
 Notifies
 .Nm
 to reload its configuration and rebind its interfaces.
 If
 .Nm
 is not running, then it starts up as normal.
-.It Fl p , -persistent
+.It Fl o , Fl Fl option Ar option
+Request the DHCP
+.Ar option
+variable for use in
+.Pa @SCRIPT@ .
+.It Fl p , Fl Fl persistent
 .Nm
 normally de-configures the
 .Ar interface
@@ -273,27 +319,20 @@
 Sometimes, this isn't desirable if, for example, you have root mounted over
 NFS.
 You can use this option to stop this from happening.
-.It Fl r , -request Op Ar address
-.Nm
-normally sends a DHCP DISCOVER to find servers to offer an address.
-.Nm
-then requests the address used.
-You can use this option to skip the DISCOVER phase and just request the
-.Ar address .
-The downside is if you request an
+.It Fl r , Fl Fl request Op Ar address
+Request the
 .Ar address
-the DHCP server does not know about or the DHCP server is not
-authoritative, it will remain silent.
-In this situation, we go back to the init state and DISCOVER again.
+in the DHCP DISCOVER message.
+There is no guarantee this is the address the DHCP server will actually give.
 If no
 .Ar address
 is given then the first address currently assigned to the
 .Ar interface
 is used.
-.It Fl s , -inform Op Ar address Ns Op Ar /cidr
+.It Fl s , Fl Fl inform Op Ar address Ns Op Ar /cidr
 Behaves like
-.Fl r , -request
-as above, but sends a DHCP INFORM instead of a REQUEST.
+.Fl r , Fl Fl request
+as above, but sends a DHCP INFORM instead of DISCOVER/REQUEST.
 This does not get a lease as such, just notifies the DHCP server of the
 .Ar address
 in use.
@@ -308,7 +347,7 @@
 .Nm
 fails to contact a DHCP server then it returns a failure instead of falling
 back on IPv4LL.
-.It Fl t , -timeout Ar seconds
+.It Fl t , Fl Fl timeout Ar seconds
 Timeout after
 .Ar seconds ,
 instead of the default 30.
@@ -317,12 +356,12 @@
 causes
 .Nm
 to wait forever to get a lease.
-.It Fl u , -userclass Ar class
+.It Fl u , Fl Fl userclass Ar class
 Tags the DHCP message with the userclass
 .Ar class .
 DHCP servers use this to give members of the class DHCP options other than the
 default, without having to know things like hardware address or hostname.
-.It Fl v , -vendor Ar code , Ns Ar value
+.It Fl v , Fl Fl vendor Ar code , Ns Ar value
 Add an encapsulated vendor option.
 .Ar code
 should be between 1 and 254 inclusive.
@@ -339,13 +378,13 @@
 .D1 dhcpcd \-v 03,\e"192.168.0.2\e" eth0
 Set un-encapsulated vendor option to hello world.
 .D1 dhcpcd \-v ,"hello world" eth0
-.It Fl v , -version
+.It Fl Fl version
 Display both program version and copyright information.
 .Nm
 then exits before doing any configuration.
-.It Fl w , -waitip
+.It Fl w , Fl Fl waitip
 Wait for an address to be assigned before forking to the background.
-.It Fl x , -exit
+.It Fl x , Fl Fl exit
 This will signal an existing
 .Nm
 process running on the
@@ -355,54 +394,14 @@
 and exit.
 .Nm
 then waits until this process has exited.
-.It Fl y , -reboot Ar seconds
+.It Fl y , Fl Fl reboot Ar seconds
 Allow
 .Ar reboot
 seconds before moving to the discover phase if we have an old lease to use.
-The default is 10 seconds.
+The default is 5 seconds.
 A setting of 0 seconds causes
 .Nm
 to skip the reboot phase and go straight into discover.
-.It Fl D , -duid
-Generate an
-.Li RFC 4361
-compliant clientid.
-This requires persistent storage and not all DHCP servers work with it so it
-is not enabled by default.
-.Nm
-generates the DUID and stores it in
-.Pa @SYSCONFDIR@/dhcpcd.duid .
-This file should not be copied to other hosts.
-.It Fl E , -lastlease
-If
-.Nm
-cannot obtain a lease, then try to use the last lease acquired for the
-interface.
-If the
-.Fl p, -persistent
-option is not given then the lease is used if it hasn't expired.
-.It Fl F , -fqdn Ar fqdn
-Requests that the DHCP server updates DNS using FQDN instead of just a
-hostname.
-Valid values for
-.Ar fqdn
-are disable, none, ptr and both.
-.Nm
-itself never does any DNS updates.
-.Nm
-encodes the FQDN hostname as specified in
-.Li RFC1035 .
-.It Fl I , -clientid Ar clientid
-Send the
-.Ar clientid .
-If the string is of the format 01:02:03 then it is encoded as hex.
-For interfaces whose hardware address is longer than 8 bytes, or if the
-.Ar clientid
-is an empty string then
-.Nm
-sends a default
-.Ar clientid
-of the hardware family and the hardware address.
 .El
 .Ss Restricting behaviour
 .Nm
@@ -411,27 +410,14 @@
 configured exactly how the the DHCP server wants.
 Here are some options that deal with turning these bits off.
 .Bl -tag -width indent
-.It Fl q , -quiet
-Quiet
-.Nm
-on the command line, only warnings and errors will be displayed.
-The messages are still logged though.
-.It Fl z , -allowinterfaces Ar pattern
-When discovering interfaces, the interface name must match
-.Ar pattern
-which is a space or comma separated list of patterns passed to
-.Xr fnmatch 3 .
-If the same interface is matched in
-.Fl Z , -denyinterfaces
-then it is still denied.
-.It Fl A , -noarp
+.It Fl A , Fl Fl noarp
 Don't request or claim the address by ARP.
 This also disables IPv4LL.
-.It Fl B , -nobackground
+.It Fl B , Fl Fl nobackground
 Don't run in the background when we acquire a lease.
 This is mainly useful for running under the control of another process, such
 as a debugger or a network manager.
-.It Fl C , -nohook Ar script
+.It Fl C , Fl Fl nohook Ar script
 Don't run this hook script.
 Matches full name, or prefixed with 2 numbers optionally ending with
 .Pa .sh .
@@ -440,30 +426,30 @@
 .Nm
 from touching your DNS or MTU settings you would do:-
 .D1 dhcpcd -C resolv.conf -C mtu eth0
-.It Fl G , -nogateway
+.It Fl G , Fl Fl nogateway
 Don't set any default routes.
-.It Fl H , -xidhwaddr
+.It Fl H , Fl Fl xidhwaddr
 Use the last four bytes of the hardware address as the DHCP xid instead
 of a randomly generated number.
-.It Fl J , -broadcast
+.It Fl J , Fl Fl broadcast
 Instructs the DHCP server to broadcast replies back to the client.
 Normally this is only set for non Ethernet interfaces,
 such as FireWire and InfiniBand.
 In most instances,
 .Nm
 will set this automatically.
-.It Fl K , -nolink
+.It Fl K , Fl Fl nolink
 Don't receive link messages for carrier status.
 You should only have to use this with buggy device drivers or running
 .Nm
 through a network manager.
-.It Fl L , -noipv4ll
+.It Fl L , Fl Fl noipv4ll
 Don't use IPv4LL (aka APIPA, aka Bonjour, aka ZeroConf).
-.It Fl O , -nooption Ar option
+.It Fl O , Fl Fl nooption Ar option
 Don't request the specified option.
 If no option given, then don't request any options other than those to
 configure the interface and routing.
-.It Fl Q , -require Ar option
+.It Fl Q , Fl Fl require Ar option
 Requires the
 .Ar option
 to be present in all DHCP messages, otherwise the message is ignored.
@@ -472,7 +458,12 @@
 only responds to DHCP servers and not BOOTP servers, you can
 .Fl Q
 .Ar dhcp_message_type .
-.It Fl S, -static Ar value
+.It Fl q , Fl Fl quiet
+Quiet
+.Nm
+on the command line, only warnings and errors will be displayed.
+The messages are still logged though.
+.It Fl S, Fl Fl static Ar value
 Configures a static
 .Ar value .
 If you set
@@ -487,7 +478,7 @@
 .D1 -S routers=192.168.0.1 \e
 .D1 -S domain_name_servers=192.168.0.1 \e
 .D1 eth0
-.It Fl T, -test
+.It Fl T, Fl Fl test
 On receipt of DHCP messages just call
 .Pa @SCRIPT@
 with the reason of TEST which echos the DHCP variables found in the message
@@ -497,33 +488,41 @@
 To test INFORM the interface needs to be configured with the desired address
 before starting
 .Nm .
-.It Fl U, -dumplease Ar interface
+.It Fl U, Fl Fl dumplease Ar interface
 Dumps the last lease for the
 .Ar interface
 to stdout.
 .Ar interface
 could also be a path to a DHCP wire formatted file.
-.It Fl V, -variables
+.It Fl V, Fl Fl variables
 Display a list of option codes and the associated variable for use in
 .Xr dhcpcd-run-hooks 8 .
 Variables are prefixed with new_ and old_ unless the option number is -.
 Variables without an option are part of the DHCP message and cannot be
 directly requested.
-.It Fl W, -whitelist Ar address Ns Op /cidr
+.It Fl W, Fl Fl whitelist Ar address Ns Op /cidr
 Only accept packets from
 .Ar address Ns Op /cidr .
-.Fl X, -blacklist
+.Fl X, Fl Fl blacklist
 is ignored if
-.Fl W, -whitelist
+.Fl W, Fl Fl whitelist
 is set.
-.It Fl X, -blacklist Ar address Ns Op Ar /cidr
+.It Fl X, Fl Fl blacklist Ar address Ns Op Ar /cidr
 Ignore all packets from
 .Ar address Ns Op Ar /cidr .
-.It Fl Z , -denyinterfaces Ar pattern
+.It Fl Z , Fl Fl denyinterfaces Ar pattern
 When discovering interfaces, the interface name must not match
 .Ar pattern
 which is a space or comma separated list of patterns passed to
 .Xr fnmatch 3 .
+.It Fl z , Fl Fl allowinterfaces Ar pattern
+When discovering interfaces, the interface name must match
+.Ar pattern
+which is a space or comma separated list of patterns passed to
+.Xr fnmatch 3 .
+If the same interface is matched in
+.Fl Z , Fl Fl denyinterfaces
+then it is still denied.
 .El
 .Sh 3RDPARTY LINK MANAGEMENT
 Some interfaces require configuration by 3rd parties, such as PPP or VPN.
@@ -535,7 +534,7 @@
 act accordingly.
 For point to point interfaces (like PPP), a default route to its
 destination is automatically added to the configuration.
-If the point to point interface if configured for INFORM, then
+If the point to point interface is configured for INFORM, then
 .Nm
 unicasts INFORM to the destination, otherwise it defaults to STATIC.
 .Sh NOTES
@@ -554,10 +553,11 @@
 .It Pa @HOOKDIR@
 A directory containing bourne shell scripts that are run by the above script.
 Each script can be disabled by using the
-.Fl C , -nohook
+.Fl C , Fl Fl nohook
 option described above.
 .It Pa @DBDIR@/dhcpcd\- Ns Ar interface Ns .lease
-The actual DHCP message send by the server. We use this when reading the last
+The actual DHCP message send by the server.
+We use this when reading the last
 lease and use the files mtime as when it was issued.
 .It Pa /var/run/dhcpcd.pid
 Stores the PID of
@@ -570,16 +570,17 @@
 .Ar interface .
 .El
 .Sh SEE ALSO
-.Xr dhcpcd.conf 5 ,
-.Xr dhcpcd-run-hooks 8 ,
-.Xr resolv.conf 5 ,
-.Xr resolvconf 8 ,
+.Xr fnmatch 3 ,
 .Xr if_nametoindex 3 ,
-.Xr fnmatch 3
+.Xr dhcpcd.conf 5 ,
+.Xr resolv.conf 5 ,
+.Xr dhcpcd-run-hooks 8 ,
+.Xr resolvconf 8
 .Sh STANDARDS
 RFC 951, RFC 1534, RFC 2131, RFC 2132, RFC 2855, RFC 3004, RFC 3361, RFC 3396,
-RFC 3397, RFC 3442, RFC 3927, RFC 4361, RFC 4390, RFC 4702.
+RFC 3397, RFC 3442, RFC 3927, RFC 4361, RFC 4390, RFC 4702, RFC 5969, RFC 6106.
 .Sh AUTHORS
 .An Roy Marples Aq roy@marples.name
 .Sh BUGS
-Please report them to http://roy.marples.name/projects/dhcpcd
+Please report them to
+.Lk http://roy.marples.name/projects/dhcpcd
diff --git a/dhcpcd.c b/dhcpcd.c
index 155c07b..8a008a0 100644
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2010 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -25,7 +25,7 @@
  * SUCH DAMAGE.
  */
 
-const char copyright[] = "Copyright (c) 2006-2010 Roy Marples";
+const char copyright[] = "Copyright (c) 2006-2012 Roy Marples";
 
 #include <sys/file.h>
 #include <sys/socket.h>
@@ -67,7 +67,9 @@
 #include "if-options.h"
 #include "if-pref.h"
 #include "ipv4ll.h"
+#include "ipv6rs.h"
 #include "net.h"
+#include "platform.h"
 #include "signals.h"
 
 #ifdef ANDROID
@@ -85,7 +87,7 @@
 #define RELEASE_DELAY_S		0
 #define RELEASE_DELAY_NS	10000000
 
-int options = 0;
+unsigned long long options = 0;
 int pidfd = -1;
 struct interface *ifaces = NULL;
 int ifac = 0;
@@ -102,7 +104,7 @@
 static int ifc;
 static char *cffile;
 static char *pidfile;
-static int linkfd = -1;
+static int linkfd = -1, ipv6rsfd = -1;
 
 struct dhcp_op {
 	uint8_t value;
@@ -153,15 +155,24 @@
 static void
 usage(void)
 {
-	printf("usage: "PACKAGE" [-adgknpqwxyADEGHJKLOTV] [-c script] [-f file]"
-	    " [-e var=val]\n"
-	    "              [-h hostname] [-i classID ] [-l leasetime]"
-	    " [-m metric] [-o option]\n"
-	    "              [-r ipaddr] [-s ipaddr] [-t timeout]"
-	    " [-u userclass]\n"
-	    "              [-F none|ptr|both] [-I clientID] [-C hookscript]"
-	    " [-Q option]\n"
-	    "              [-X ipaddr] <interface>\n");
+
+printf("usage: "PACKAGE"\t[-aABbDdEGgHJKkLnpqTVw]\n"
+	"\t\t[-C, --nohook hook] [-c, --script script]\n"
+	"\t\t[-e, --env value] [-F, --fqdn FQDN] [-f, --config file]\n"
+	"\t\t[-h, --hostname hostname] [-I, --clientid clientid]\n"
+	"\t\t[-i, --vendorclassid vendorclassid] [-l, --leasetime seconds]\n"
+	"\t\t[-m, --metric metric] [-O, --nooption option]\n"
+	"\t\t[-o, --option option] [-Q, --require option]\n"
+	"\t\t[-r, --request address] [-S, --static value]\n"
+	"\t\t[-s, --inform address[/cidr]] [-t, --timeout seconds]\n"
+	"\t\t[-u, --userclass class] [-v, --vendor code, value]\n"
+	"\t\t[-W, --whitelist address[/cidr]] [-y, --reboot seconds]\n"
+	"\t\t[-X, --blacklist address[/cidr]] [-Z, --denyinterfaces pattern]\n"
+	"\t\t[-z, --allowinterfaces pattern] [interface] [...]\n"
+	"       "PACKAGE"\t-k, --release [interface]\n"
+	"       "PACKAGE"\t-U, --dumplease interface\n"
+	"       "PACKAGE"\t-v, --version\n"
+	"       "PACKAGE"\t-x, --exit [interface]\n");
 }
 
 static void
@@ -217,13 +228,13 @@
 			exit(EXIT_FAILURE);
 	}
 	options &= ~DHCPCD_TIMEOUT_IPV4LL;
-	timeout = (PROBE_NUM * PROBE_MAX) + PROBE_WAIT + 1;
+	timeout = (PROBE_NUM * PROBE_MAX) + (PROBE_WAIT * 2);
 	syslog(LOG_WARNING, "allowing %d seconds for IPv4LL timeout", timeout);
 	add_timeout_sec(timeout, handle_exit_timeout, NULL);
 }
 
 void
-drop_config(struct interface *iface, const char *reason)
+drop_dhcp(struct interface *iface, const char *reason)
 {
 	free(iface->state->old);
 	iface->state->old = iface->state->new;
@@ -252,8 +263,13 @@
 	struct interface *ifp, *ifl = NULL;
 
 	syslog(LOG_INFO, "%s: removing interface", iface->name);
+	if (iface->ras) {
+		ipv6rs_free(iface);
+		iface->ras = NULL;
+		run_script_reason(iface, "ROUTERADVERT");
+	}
 	if (strcmp(iface->state->reason, "RELEASE") != 0)
-		drop_config(iface, "STOP");
+		drop_dhcp(iface, "STOP");
 	close_sockets(iface);
 	delete_timeout(NULL, iface);
 	for (ifp = ifaces; ifp; ifp = ifp->next) {
@@ -357,7 +373,7 @@
 		if (r == -1) {
 			syslog(LOG_ERR, "%s: send_raw_packet: %m", iface->name);
 			if (!(options & DHCPCD_TEST))
-				drop_config(iface, "FAIL");
+				drop_dhcp(iface, "FAIL");
 			close_sockets(iface);
 			delete_timeout(NULL, iface);
 			callback = NULL;
@@ -416,7 +432,7 @@
 
 	syslog(LOG_ERR, "%s: lease expired", iface->name);
 	delete_timeout(NULL, iface);
-	drop_config(iface, "EXPIRE");
+	drop_dhcp(iface, "EXPIRE");
 	unlink(iface->leasefile);
 	if (iface->carrier != LINK_DOWN)
 		start_interface(iface);
@@ -513,7 +529,7 @@
 		/* We should restart on a NAK */
 		log_dhcp(LOG_WARNING, "NAK:", iface, dhcp, from);
 		if (!(options & DHCPCD_TEST)) {
-			drop_config(iface, "NAK");
+			drop_dhcp(iface, "NAK");
 			unlink(iface->leasefile);
 		}
 		close_sockets(iface);
@@ -537,7 +553,17 @@
 			log_dhcp(LOG_WARNING, "reject DHCP", iface, dhcp, from);
 			return;
 		}
-	}		
+	}
+
+	/* Ensure that the address offered is valid */
+	if ((type == 0 || type == DHCP_OFFER || type == DHCP_ACK) &&
+	    (dhcp->ciaddr == INADDR_ANY || dhcp->ciaddr == INADDR_BROADCAST) &&
+	    (dhcp->yiaddr == INADDR_ANY || dhcp->yiaddr == INADDR_BROADCAST))
+	{
+		log_dhcp(LOG_WARNING, "reject invalid address",
+		    iface, dhcp, from);
+		return;
+	}
 
 	/* No NAK, so reset the backoff */
 	state->nakoff = 1;
@@ -640,7 +666,7 @@
 	const uint8_t *pp;
 	ssize_t bytes;
 	struct in_addr from;
-	int i;
+	int i, partialcsum = 0;
 
 	/* We loop through until our buffer is empty.
 	 * The benefit is that if we get >1 DHCP packet in our buffer and
@@ -648,10 +674,10 @@
 	packet = xmalloc(udp_dhcp_len);
 	for(;;) {
 		bytes = get_raw_packet(iface, ETHERTYPE_IP,
-		    packet, udp_dhcp_len);
+		    packet, udp_dhcp_len, &partialcsum);
 		if (bytes == 0 || bytes == -1)
 			break;
-		if (valid_udp_packet(packet, bytes, &from) == -1) {
+		if (valid_udp_packet(packet, bytes, &from, partialcsum) == -1) {
 			syslog(LOG_ERR, "%s: invalid UDP packet from %s",
 			    iface->name, inet_ntoa(from));
 			continue;
@@ -733,7 +759,7 @@
 		ts.tv_sec = RELEASE_DELAY_S;
 		ts.tv_nsec = RELEASE_DELAY_NS;
 		nanosleep(&ts, NULL);
-		drop_config(iface, "RELEASE");
+		drop_dhcp(iface, "RELEASE");
 	}
 	unlink(iface->leasefile);
 }
@@ -760,6 +786,8 @@
 	if (iface->flags & IFF_NOARP ||
 	    ifo->options & (DHCPCD_INFORM | DHCPCD_STATIC))
 		ifo->options &= ~(DHCPCD_ARP | DHCPCD_IPV4LL);
+	if (!(iface->flags & (IFF_POINTOPOINT | IFF_LOOPBACK | IFF_MULTICAST)))
+		ifo->options &= ~DHCPCD_IPV6RS;
 	if (ifo->options & DHCPCD_LINK && carrier_status(iface) == -1)
 		ifo->options &= ~DHCPCD_LINK;
 	
@@ -818,7 +846,7 @@
 	if (ifo->options & DHCPCD_CLIENTID)
 		syslog(LOG_DEBUG, "%s: using ClientID %s", iface->name,
 		    hwaddr_ntoa(iface->clientid + 1, *iface->clientid));
-	else
+	else if (iface->hwlen)
 		syslog(LOG_DEBUG, "%s: using hwaddr %s", iface->name,
 		    hwaddr_ntoa(iface->hwaddr, iface->hwlen));
 }
@@ -870,8 +898,8 @@
 	configure_interface1(iface);
 }
 
-static void
-handle_carrier(const char *ifname)
+void
+handle_carrier(int action, int flags, const char *ifname)
 {
 	struct interface *iface;
 	int carrier;
@@ -881,20 +909,36 @@
 	for (iface = ifaces; iface; iface = iface->next)
 		if (strcmp(iface->name, ifname) == 0)
 			break;
-	if (!iface || !(iface->state->options->options & DHCPCD_LINK))
+	if (!iface) {
+		if (options & DHCPCD_LINK)
+			handle_interface(1, ifname);
 		return;
-	carrier = carrier_status(iface);
+	}
+	if (!(iface->state->options->options & DHCPCD_LINK))
+		return;
+
+	if (action) {
+		carrier = action == 1 ? 1 : 0;
+		iface->flags = flags;
+	} else
+		carrier = carrier_status(iface);
+
 	if (carrier == -1)
 		syslog(LOG_ERR, "%s: carrier_status: %m", ifname);
-	else if (carrier == 0 || !(iface->flags & IFF_RUNNING)) {
+	else if (carrier == 0 || ~iface->flags & IFF_UP) {
 		if (iface->carrier != LINK_DOWN) {
 			iface->carrier = LINK_DOWN;
 			syslog(LOG_INFO, "%s: carrier lost", iface->name);
 			close_sockets(iface);
 			delete_timeouts(iface, start_expire, NULL);
-			drop_config(iface, "NOCARRIER");
+			if (iface->ras) {
+				ipv6rs_free(iface);
+				iface->ras = NULL;
+				run_script_reason(iface, "ROUTERADVERT");
+			}
+			drop_dhcp(iface, "NOCARRIER");
 		}
-	} else if (carrier == 1 && (iface->flags & IFF_RUNNING)) {
+	} else if (carrier == 1 && !(~iface->flags & IFF_UP)) {
 		if (iface->carrier != LINK_UP) {
 			iface->carrier = LINK_UP;
 			syslog(LOG_INFO, "%s: carrier acquired", iface->name);
@@ -914,21 +958,37 @@
 {
 	struct interface *iface = arg;
 	struct if_options *ifo = iface->state->options;
+	int timeout = ifo->timeout;
+
+	/* If we're rebooting and we're not daemonised then we need
+	 * to shorten the normal timeout to ensure we try correctly
+	 * for a fallback or IPv4LL address. */
+	if (iface->state->state == DHS_REBOOT &&
+	    !(options & DHCPCD_DAEMONISED))
+	{
+		timeout -= ifo->reboot;
+		if (timeout <= 0)
+			timeout = 2;
+	}
 
 	iface->state->state = DHS_DISCOVER;
 	iface->state->xid = dhcp_xid(iface);
 	delete_timeout(NULL, iface);
 	if (ifo->fallback)
-		add_timeout_sec(ifo->timeout, start_fallback, iface);
+		add_timeout_sec(timeout, start_fallback, iface);
 	else if (ifo->options & DHCPCD_IPV4LL &&
 	    !IN_LINKLOCAL(htonl(iface->addr.s_addr)))
 	{
 		if (IN_LINKLOCAL(htonl(iface->state->fail.s_addr)))
 			add_timeout_sec(RATE_LIMIT_INTERVAL, start_ipv4ll, iface);
 		else
-			add_timeout_sec(ifo->timeout, start_ipv4ll, iface);
+			add_timeout_sec(timeout, start_ipv4ll, iface);
 	}
-	syslog(LOG_INFO, "%s: broadcasting for a lease", iface->name);
+	if (ifo->options & DHCPCD_REQUEST)
+		syslog(LOG_INFO, "%s: broadcasting for a lease (requesting %s)",
+		    iface->name, inet_ntoa(ifo->req_addr));
+	else
+		syslog(LOG_INFO, "%s: broadcasting for a lease", iface->name);
 	send_discover(iface);
 }
 
@@ -1110,7 +1170,7 @@
 	uint32_t l;
 	int nolease;
 
-	handle_carrier(iface->name);
+	handle_carrier(0, 0, iface->name);
 	if (iface->carrier == LINK_DOWN) {
 		syslog(LOG_INFO, "%s: waiting for carrier", iface->name);
 		return;
@@ -1120,6 +1180,13 @@
 	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 (iface->state->arping_index < ifo->arping_len) {
 		start_arping(iface);
 		return;
@@ -1135,7 +1202,7 @@
 	if (iface->hwlen == 0 && ifo->clientid[0] == '\0') {
 		syslog(LOG_WARNING, "%s: needs a clientid to configure",
 		    iface->name);
-		drop_config(iface, "FAIL");
+		drop_dhcp(iface, "FAIL");
 		close_sockets(iface);
 		delete_timeout(NULL, iface);
 		return;
@@ -1238,9 +1305,6 @@
 		if (ifp != NULL)
 			stop_interface(ifp);
 		return;
-	} else if (action == 0) {
-		handle_carrier(ifname);
-		return;
 	}
 
 	/* If running off an interface list, check it's in it. */
@@ -1297,7 +1361,7 @@
 				syslog(LOG_INFO,
 				    "%s: expiring for new hardware address",
 				    ifp->name);
-				drop_config(ifp, "EXPIRE");
+				drop_dhcp(ifp, "EXPIRE");
 			}
 			memcpy(ifp->hwaddr, hwaddr, hwlen);
 			ifp->hwlen = hwlen;
@@ -1331,43 +1395,44 @@
 			break;
 	if (ifp == NULL)
 		return;
+
+	if (type == RTM_DELADDR) {
+		if (ifp->state->new &&
+		    ifp->state->new->yiaddr == addr->s_addr)
+			syslog(LOG_INFO, "%s: removing IP address %s/%d",
+			    ifp->name, inet_ntoa(ifp->state->lease.addr),
+			    inet_ntocidr(ifp->state->lease.net));
+		return;
+	}
+
+	if (type != RTM_NEWADDR)
+		return;
+
 	ifo = ifp->state->options;
 	if ((ifo->options & (DHCPCD_INFORM | DHCPCD_STATIC)) == 0 ||
 	    ifo->req_addr.s_addr != INADDR_ANY)
 		return;
-	
-	switch (type) {
-	case RTM_DELADDR:
-		if (ifp->state->new &&
-		    ifp->state->new->yiaddr == addr->s_addr)
-			drop_config(ifp, "EXPIRE");
-		break;
-	case RTM_NEWADDR:
-		free(ifp->state->old);
-		ifp->state->old = ifp->state->new;
-		ifp->state->new = dhcp_message_new(addr, net);
-		ifp->dst.s_addr = dst ? dst->s_addr : INADDR_ANY;
-		if (dst) {
-			for (i = 1; i < 255; i++)
-				if (i != DHO_ROUTER &&
-				    has_option_mask(ifo->dstmask, i))
-					dhcp_message_add_addr(
-						ifp->state->new,
-						i, *dst);
-		}
-		ifp->state->reason = "STATIC";
-		build_routes();
-		run_script(ifp);
-		if (ifo->options & DHCPCD_INFORM) {
-			ifp->state->state = DHS_INFORM;
-			ifp->state->xid = dhcp_xid(ifp);
-			ifp->state->lease.server.s_addr =
-			    dst ? dst->s_addr : INADDR_ANY;
-			ifp->addr = *addr;
-			ifp->net = *net;
-			send_inform(ifp);
-		}
-		break;
+
+	free(ifp->state->old);
+	ifp->state->old = ifp->state->new;
+	ifp->state->new = dhcp_message_new(addr, net);
+	ifp->dst.s_addr = dst ? dst->s_addr : INADDR_ANY;
+	if (dst) {
+		for (i = 1; i < 255; i++)
+			if (i != DHO_ROUTER && has_option_mask(ifo->dstmask,i))
+				dhcp_message_add_addr(ifp->state->new, i, *dst);
+	}
+	ifp->state->reason = "STATIC";
+	build_routes();
+	run_script(ifp);
+	if (ifo->options & DHCPCD_INFORM) {
+		ifp->state->state = DHS_INFORM;
+		ifp->state->xid = dhcp_xid(ifp);
+		ifp->state->lease.server.s_addr =
+		    dst ? dst->s_addr : INADDR_ANY;
+		ifp->addr = *addr;
+		ifp->net = *net;
+		send_inform(ifp);
 	}
 }
 
@@ -1395,7 +1460,7 @@
 	    (opt & (DHCPCD_INFORM | DHCPCD_STATIC) &&
 		!(ifo->options & (DHCPCD_INFORM | DHCPCD_STATIC))))
 	{
-		drop_config(iface, "EXPIRE");
+		drop_dhcp(iface, "EXPIRE");
 	} else {
 		free(iface->state->offer);
 		iface->state->offer = NULL;
@@ -1412,25 +1477,6 @@
 	if (ifs == NULL)
 		return;
 
-	/* Remove any old interfaces */
-	if (ifaces) {
-		for (ifl = NULL; ifl != ifaces;) {
-			/* Work our way backwards */
-			for (ifp = ifaces; ifp; ifp = ifp->next)
-				if (ifp->next == ifl) {
-					ifl = ifp;
-					break;
-				}
-			for (ifn = ifs; ifn; ifn = ifn->next)
-				if (strcmp(ifn->name, ifp->name) == 0)
-					break;
-			if (ifn == NULL) {
-				ifl = ifp->next;
-				stop_interface(ifp);
-			}
-		}
-	}
-	
 	for (ifp = ifs; ifp && (ift = ifp->next, 1); ifp = ift) {
 		ifl = NULL;
 		for (ifn = ifaces; ifn; ifn = ifn->next) {
@@ -1502,7 +1548,7 @@
 			ifo->options |= DHCPCD_DAEMONISED;
 		options = ifo->options;
 		free_options(ifo);
-		reconf_reboot(1, 0, NULL, 0);
+		reconf_reboot(1, ifc, ifv, 0);
 #endif
 		return;
 	case SIGHUP:
@@ -1528,7 +1574,7 @@
 	if (options & DHCPCD_TEST)
 		exit(EXIT_FAILURE);
 
-	/* As drop_config could re-arrange the order, we do it like this. */
+	/* As drop_dhcp could re-arrange the order, we do it like this. */
 	for (;;) {
 		/* Be sane and drop the last config first */
 		ifl = NULL;
@@ -1586,8 +1632,11 @@
 		} else if (strcmp(*argv, "--getinterfaces") == 0) {
 			len = 0;
 			if (argc == 1) {
-				for (ifp = ifaces; ifp; ifp = ifp->next)
+				for (ifp = ifaces; ifp; ifp = ifp->next) {
 					len++;
+					if (ifp->ras)
+						len++;
+				}
 				len = write(fd->fd, &len, sizeof(len));
 				if (len != sizeof(len))
 					return -1;
@@ -1598,8 +1647,11 @@
 			opt = 0;
 			while (argv[++opt] != NULL) {
 				for (ifp = ifaces; ifp; ifp = ifp->next)
-					if (strcmp(argv[opt], ifp->name) == 0)
+					if (strcmp(argv[opt], ifp->name) == 0) {
 						len++;
+						if (ifp->ras)
+							len++;
+					}
 			}
 			len = write(fd->fd, &len, sizeof(len));
 			if (len != sizeof(len))
@@ -1948,7 +2000,7 @@
 			if (sig != SIGALRM)
 				exit(EXIT_FAILURE);
 		} else {
-			if (sig == SIGALRM)
+			if (sig == SIGALRM || sig == SIGUSR1)
 				exit(EXIT_SUCCESS);
 			/* Spin until it exits */
 			syslog(LOG_INFO, "waiting for pid %d to exit", pid);
@@ -1980,50 +2032,47 @@
 		}
 
 		/* Ensure we have the needed directories */
-		if (mkdir(RUNDIR, 0755) == -1 && errno != EEXIST) {
+		if (mkdir(RUNDIR, 0755) == -1 && errno != EEXIST)
 			syslog(LOG_ERR, "mkdir `%s': %m", RUNDIR);
-			exit(EXIT_FAILURE);
-		}
-		if (mkdir(DBDIR, 0755) == -1 && errno != EEXIST) {
+		if (mkdir(DBDIR, 0755) == -1 && errno != EEXIST)
 			syslog(LOG_ERR, "mkdir `%s': %m", DBDIR);
-			exit(EXIT_FAILURE);
-		}
 #endif
+
 		pidfd = open(pidfile, O_WRONLY | O_CREAT | O_NONBLOCK, 0664);
-		if (pidfd == -1) {
+		if (pidfd == -1)
 			syslog(LOG_ERR, "open `%s': %m", pidfile);
-			exit(EXIT_FAILURE);
-		}
-		/* Lock the file so that only one instance of dhcpcd runs
-		 * on an interface */
-		if (flock(pidfd, LOCK_EX | LOCK_NB) == -1) {
-			syslog(LOG_ERR, "flock `%s': %m", pidfile);
-			exit(EXIT_FAILURE);
-		}
-		if (set_cloexec(pidfd) == -1)
-			exit(EXIT_FAILURE);
+		else {
+			/* Lock the file so that only one instance of dhcpcd
+			 * runs on an interface */
+			if (flock(pidfd, LOCK_EX | LOCK_NB) == -1) {
+				syslog(LOG_ERR, "flock `%s': %m", pidfile);
+				exit(EXIT_FAILURE);
+			}
+			if (set_cloexec(pidfd) == -1)
+				exit(EXIT_FAILURE);
 #ifdef ANDROID
-		if (optind != argc - 1) {
-			syslog(LOG_ERR, "Android requires an interface");
-			exit(EXIT_FAILURE);
-		}
+			if (optind != argc - 1) {
+				syslog(LOG_ERR, "Android requires an interface");
+				exit(EXIT_FAILURE);
+			}
 
-		if (strncmp(argv[optind], "p2p", 3) == 0) {
-			strncpy(p2p_interface, "p2p", sizeof(p2p_interface));
-		} else {
-			strncpy(p2p_interface, argv[optind], sizeof(p2p_interface));
-		}
+			if (strncmp(argv[optind], "p2p", 3) == 0) {
+				strncpy(p2p_interface, "p2p", sizeof(p2p_interface));
+			} else {
+				strncpy(p2p_interface, argv[optind], sizeof(p2p_interface));
+			}
 
-		if (snprintf(pidpropname,
-			     sizeof(pidpropname),
-			     "dhcp.%s.pid", p2p_interface) >= PROPERTY_KEY_MAX)
-			exit(EXIT_FAILURE);
-		if (snprintf(pidpropval, sizeof(pidpropval), "%d", getpid()) >= PROPERTY_VALUE_MAX)
-			exit(EXIT_FAILURE);
-		property_set(pidpropname, pidpropval);
+			if (snprintf(pidpropname,
+				     sizeof(pidpropname),
+				     "dhcp.%s.pid", p2p_interface) >= PROPERTY_KEY_MAX)
+				exit(EXIT_FAILURE);
+			if (snprintf(pidpropval, sizeof(pidpropval), "%d", getpid()) >= PROPERTY_VALUE_MAX)
+				exit(EXIT_FAILURE);
+			property_set(pidpropname, pidpropval);
 #else
-		writepid(pidfd, getpid());
+			writepid(pidfd, getpid());
 #endif
+		}
 	}
 
 	syslog(LOG_INFO, "version " VERSION " starting");
@@ -2035,10 +2084,8 @@
 	add_event(signal_fd, handle_signal, NULL);
 
 	if (options & DHCPCD_MASTER) {
-		if (start_control() == -1) {
+		if (start_control() == -1)
 			syslog(LOG_ERR, "start_control: %m");
-			exit(EXIT_FAILURE);
-		}
 	}
 
 	if (init_sockets() == -1) {
@@ -2053,6 +2100,26 @@
 			add_event(linkfd, handle_link, NULL);
 	}
 
+#if 0
+	if (options & DHCPCD_IPV6RS && disable_rtadv() == -1) {
+		syslog(LOG_ERR, "ipv6rs: %m");
+		options &= ~DHCPCD_IPV6RS;
+	}
+#endif
+
+	if (options & DHCPCD_IPV6RS && !check_ipv6(NULL))
+		options &= ~DHCPCD_IPV6RS;
+	if (options & DHCPCD_IPV6RS) {
+		ipv6rsfd = ipv6rs_open();
+		if (ipv6rsfd == -1) {
+			syslog(LOG_ERR, "ipv6rs: %m");
+			options &= ~DHCPCD_IPV6RS;
+		} else {
+			add_event(ipv6rsfd, ipv6rs_handledata, NULL);
+//			atexit(restore_rtadv);
+		}
+	}
+
 	ifc = argc - optind;
 	ifv = argv + optind;
 
@@ -2094,7 +2161,7 @@
 
 	if (!(options & DHCPCD_BACKGROUND)) {
 		/* If we don't have a carrier, we may have to wait for a second
-		 * before one becomes available if we brought an interface up. */
+		 * before one becomes available if we brought an interface up */
 		if (opt == 0 &&
 		    options & DHCPCD_LINK &&
 		    options & DHCPCD_WAITUP &&
@@ -2104,24 +2171,27 @@
 			ts.tv_nsec = 0;
 			nanosleep(&ts, NULL);
 			for (iface = ifaces; iface; iface = iface->next) {
-				handle_carrier(iface->name);
+				handle_carrier(0, 0, iface->name);
 				if (iface->carrier != LINK_DOWN) {
 					opt = 1;
 					break;
 				}
 			}
 		}
+		if (options & DHCPCD_MASTER)
+			i = if_options->timeout;
+		else
+			i = ifaces->state->options->timeout;
 		if (opt == 0 &&
 		    options & DHCPCD_LINK &&
 		    !(options & DHCPCD_WAITIP))
 		{
 			syslog(LOG_WARNING, "no interfaces have a carrier");
 			daemonise();
-		} else if (if_options->timeout > 0) {
+		} else if (i > 0) {
 			if (options & DHCPCD_IPV4LL)
 				options |= DHCPCD_TIMEOUT_IPV4LL;
-			add_timeout_sec(if_options->timeout,
-			    handle_exit_timeout, NULL);
+			add_timeout_sec(i, handle_exit_timeout, NULL);
 		}
 	}
 	free_options(if_options);
diff --git a/dhcpcd.conf.5 b/dhcpcd.conf.5
index 03b3521..89cb793 100644
--- a/dhcpcd.conf.5
+++ b/dhcpcd.conf.5
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2006-2010 Roy Marples
+.\" Copyright (c) 2006-2012 Roy Marples
 .\" All rights reserved
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd January 28, 2010
+.Dd May 21, 2012
 .Dt DHCPCD.CONF 5 SMM
 .Os
 .Sh NAME
@@ -144,6 +144,28 @@
 .It Ic interface Ar interface
 Subsequent options are only parsed for this
 .Ar interface .
+.It Ic ipv6ra_fork
+By default, when
+.Nm dhcpcd
+receives an IPv6 RA,
+.Nm dhcpcd
+will only fork to the background if the RA contains at least one unexpired
+RDNSS option.
+Set this option so to make
+.Nm dhcpcd
+always fork on an RA.
+.It ic ipv6ra_own
+Disables kernel IPv6 Router Advertisment processing so dhcpcd can manage
+addresses and routes.
+.It ic ipv6ra_own_default
+Each time dhcpcd receives an IPv6 Router Adveristment, dhcpcd will manage
+the default route only.
+This allows dhcpcd to prefer an interface for outbound traffic based on metric
+and/or user selection rather than the kernel.
+.It ic ipv6rs
+Enables IPv6 Router Advertisment solicitation.
+This is on by default, but is documented here in the case where it is disabled
+globally but needs to be enabled for one interface.
 .It Ic leasetime Ar seconds
 Request a leasetime of
 .Ar seconds .
@@ -173,6 +195,8 @@
 .Rs
 .%T "RFC 3927"
 .Re
+.It Ic noipv6rs
+Disable solicition of IPv6 Router Advertisements.
 .It Ic nolink
 Don't receive link messages about carrier status.
 You should only set this for buggy interface drivers.
@@ -203,7 +227,7 @@
 Allow
 .Ar reboot
 seconds before moving to the discover phase if we have an old lease to use.
-The default is 10 seconds.
+The default is 5 seconds.
 A setting if 0 seconds causes
 .Nm dhcpcd
 to skip the reboot phase and go straight into discover.
@@ -277,8 +301,13 @@
 Set un-encapsulated vendor option to hello world.
 .D1 vendor ,"hello world"
 .It Ic vendorclassid Ar string
-Change the default vendorclassid sent from dhcpcd-version.
+The default is
+dhcpcd-<version>:<os>:<machine>:<platform>.
+For example
+.D1 dhcpcd-5.5.6:NetBSD-6.99.5:i386:i386
 If not set then none is sent.
+Some badly configured DHCP servers reject unknown vendorclassids.
+To work around it, try and impersonate Windows by using the MSFT vendorclassid.
 .It Ic waitip
 Wait for an address to be assigned before forking to the background.
 .It Ic xidhwaddr
@@ -293,4 +322,5 @@
 .Sh AUTHORS
 .An Roy Marples Aq roy@marples.name
 .Sh BUGS
-Please report them to http://roy.marples.name/projects/dhcpcd
+Please report them to
+.Lk http://roy.marples.name/projects/dhcpcd
diff --git a/dhcpcd.conf.5.in b/dhcpcd.conf.5.in
index c3bfa8f..9f0ef27 100644
--- a/dhcpcd.conf.5.in
+++ b/dhcpcd.conf.5.in
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2006-2010 Roy Marples
+.\" Copyright (c) 2006-2012 Roy Marples
 .\" All rights reserved
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd January 28, 2010
+.Dd March 19, 2012
 .Dt DHCPCD.CONF 5 SMM
 .Os
 .Sh NAME
@@ -144,6 +144,16 @@
 .It Ic interface Ar interface
 Subsequent options are only parsed for this
 .Ar interface .
+.It Ic ipv6ra_fork
+By default, when
+.Nm dhcpcd
+receives an IPv6 RA,
+.Nm dhcpcd
+will only fork to the background if the RA contains at least one unexpired
+RDNSS option.
+Set this option so to make
+.Nm dhcpcd
+always fork on an RA.
 .It Ic leasetime Ar seconds
 Request a leasetime of
 .Ar seconds .
@@ -173,6 +183,8 @@
 .Rs
 .%T "RFC 3927"
 .Re
+.It Ic noipv6rs
+Disable solicition of IPv6 Router Advertisements.
 .It Ic nolink
 Don't receive link messages about carrier status.
 You should only set this for buggy interface drivers.
@@ -203,7 +215,7 @@
 Allow
 .Ar reboot
 seconds before moving to the discover phase if we have an old lease to use.
-The default is 10 seconds.
+The default is 5 seconds.
 A setting if 0 seconds causes
 .Nm dhcpcd
 to skip the reboot phase and go straight into discover.
@@ -293,4 +305,5 @@
 .Sh AUTHORS
 .An Roy Marples Aq roy@marples.name
 .Sh BUGS
-Please report them to http://roy.marples.name/projects/dhcpcd
+Please report them to
+.Lk http://roy.marples.name/projects/dhcpcd
diff --git a/dhcpcd.h b/dhcpcd.h
index 85cef7c..c2fdfdf 100644
--- a/dhcpcd.h
+++ b/dhcpcd.h
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2010 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2011 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -30,6 +30,7 @@
 
 #include <sys/socket.h>
 #include <net/if.h>
+#include <netinet/in.h>
 
 #include <limits.h>
 
@@ -81,6 +82,30 @@
 	size_t arping_index;
 };
 
+struct ra_opt {
+	uint8_t type;
+	struct timeval expire;
+	char *option;
+	struct ra_opt *next;
+};
+
+struct ra {
+	struct in6_addr from;
+	char sfrom[INET6_ADDRSTRLEN];
+	unsigned char *data;
+	ssize_t data_len;
+	struct timeval received;
+	uint32_t lifetime;
+	struct in6_addr prefix;
+	int prefix_len;
+	uint32_t prefix_vltime;
+	uint32_t prefix_pltime;
+	char sprefix[INET6_ADDRSTRLEN];
+	struct ra_opt *options;
+	int expired;
+	struct ra *next;
+};
+
 struct interface {
 	char name[IF_NAMESIZE];
 	struct if_state *state;
@@ -109,11 +134,16 @@
 
 	unsigned char *clientid;
 
+	unsigned char *rs;
+	size_t rslen;
+	int rsprobes;
+	struct ra *ras;
+
 	struct interface *next;
 };
 
 extern int pidfd;
-extern int options;
+extern unsigned long long options;
 extern int ifac;
 extern char **ifav;
 extern int ifdc;
@@ -123,6 +153,7 @@
 
 struct interface *find_interface(const char *);
 int handle_args(struct fd_list *, int, char **);
+void handle_carrier(int, int, const char *);
 void handle_interface(int, const char *);
 void handle_hwaddr(const char *, unsigned char *, size_t);
 void handle_ifa(int, const char *,
@@ -138,7 +169,8 @@
 void send_decline(struct interface *);
 void open_sockets(struct interface *);
 void close_sockets(struct interface *);
-void drop_config(struct interface *, const char *);
+void drop_dhcp(struct interface *, const char *);
+void drop_interface(struct interface *, const char *);
 int select_profile(struct interface *, const char *);
 
 #endif
diff --git a/eloop.c b/eloop.c
index a5d08cb..1115d89 100644
--- a/eloop.c
+++ b/eloop.c
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2008 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2010 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
diff --git a/eloop.h b/eloop.h
index 02c9438..ece43c1 100644
--- a/eloop.h
+++ b/eloop.h
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2008 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2010 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
diff --git a/if-bsd.c b/if-bsd.c
index 462ec2a..c3ffcac 100644
--- a/if-bsd.c
+++ b/if-bsd.c
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2010 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -61,9 +61,11 @@
 #include "if-options.h"
 #include "net.h"
 
-#define ROUNDUP(a)							      \
+#ifndef RT_ROUNDUP
+#define RT_ROUNDUP(a)							      \
 	((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
-#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
+#define RT_ADVANCE(x, n) (x += RT_ROUNDUP((n)->sa_len))
+#endif
 
 /* FIXME: Why do we need to check for sa_family 255 */
 #define COPYOUT(sin, sa)						      \
@@ -88,6 +90,15 @@
 	return 0;
 }
 
+#ifdef DEBUG_MEMORY
+static void
+cleanup(void)
+{
+
+	free(link_buf);
+}
+#endif
+
 int
 init_sockets(void)
 {
@@ -127,6 +138,7 @@
 	strlcpy(ireq.i_name, ifname, sizeof(ireq.i_name));
 	ireq.i_type = IEEE80211_IOC_SSID;
 	ireq.i_val = -1;
+	memset(nwid, 0, sizeof(nwid));
 	ireq.i_data = &nwid;
 	if (ioctl(socket_afnet, SIOCG80211, &ireq) == 0) {
 		retval = ireq.i_len;
@@ -175,9 +187,7 @@
 
 /* ARGSUSED4 */
 int
-if_route(const struct interface *iface, const struct in_addr *dest,
-    const struct in_addr *net, const struct in_addr *gate,
-    _unused int metric, int action)
+if_route(const struct rt *rt, int action)
 {
 	union sockunion {
 		struct sockaddr sa;
@@ -193,12 +203,12 @@
 		struct rt_msghdr hdr;
 		char buffer[sizeof(su) * 4];
 	} rtm;
-	char *bp = rtm.buffer, *p;
+	char *bp = rtm.buffer;
 	size_t l;
 	int retval = 0;
 
 #define ADDSU(_su) {							      \
-		l = ROUNDUP(_su.sa.sa_len);				      \
+		l = RT_ROUNDUP(_su.sa.sa_len);				      \
 		memcpy(bp, &(_su), l);					      \
 		bp += l;						      \
 	}
@@ -221,12 +231,13 @@
 		rtm.hdr.rtm_type = RTM_DELETE;
 	rtm.hdr.rtm_flags = RTF_UP;
 	/* None interface subnet routes are static. */
-	if (gate->s_addr != INADDR_ANY ||
-	    net->s_addr != iface->net.s_addr ||
-	    dest->s_addr != (iface->addr.s_addr & iface->net.s_addr))
+	if (rt->gate.s_addr != INADDR_ANY ||
+	    rt->net.s_addr != rt->iface->net.s_addr ||
+	    rt->dest.s_addr != (rt->iface->addr.s_addr & rt->iface->net.s_addr))
 		rtm.hdr.rtm_flags |= RTF_STATIC;
 	rtm.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY;
-	if (dest->s_addr == gate->s_addr && net->s_addr == INADDR_BROADCAST)
+	if (rt->dest.s_addr == rt->gate.s_addr &&
+	    rt->net.s_addr == INADDR_BROADCAST)
 		rtm.hdr.rtm_flags |= RTF_HOST;
 	else {
 		rtm.hdr.rtm_addrs |= RTA_NETMASK;
@@ -236,35 +247,23 @@
 			rtm.hdr.rtm_addrs |= RTA_IFA;
 	}
 
-	ADDADDR(dest);
+	ADDADDR(&rt->dest);
 	if (rtm.hdr.rtm_flags & RTF_HOST ||
 	    !(rtm.hdr.rtm_flags & RTF_STATIC))
 	{
 		/* Make us a link layer socket for the host gateway */
 		memset(&su, 0, sizeof(su));
 		su.sdl.sdl_len = sizeof(struct sockaddr_dl);
-		link_addr(iface->name, &su.sdl);
+		link_addr(rt->iface->name, &su.sdl);
 		ADDSU(su);
 	} else
-		ADDADDR(gate);
+		ADDADDR(&rt->gate);
 
-	if (rtm.hdr.rtm_addrs & RTA_NETMASK) {
-		/* Ensure that netmask is set correctly */
-		memset(&su, 0, sizeof(su));
-		su.sin.sin_family = AF_INET;
-		su.sin.sin_len = sizeof(su.sin);
-		memcpy(&su.sin.sin_addr, &net->s_addr, sizeof(su.sin.sin_addr));
-		p = su.sa.sa_len + (char *)&su;
-		for (su.sa.sa_len = 0; p > (char *)&su;)
-			if (*--p != 0) {
-				su.sa.sa_len = 1 + p - (char *)&su;
-				break;
-			}
-		ADDSU(su);
-	}
+	if (rtm.hdr.rtm_addrs & RTA_NETMASK)
+		ADDADDR(&rt->net);
 
 	if (rtm.hdr.rtm_addrs & RTA_IFA)
-		ADDADDR(&iface->addr);
+		ADDADDR(&rt->iface->addr);
 
 	rtm.hdr.rtm_msglen = l = bp - (char *)&rtm;
 	if (write(r_fd, &rtm, l) == -1)
@@ -277,6 +276,11 @@
 {
 	int fd;
 
+#ifdef DEBUG_MEMORY
+	if (link_buf == NULL)
+		atexit(cleanup);
+#endif
+
 	fd = socket(PF_ROUTE, SOCK_RAW, 0);
 	if (fd != -1) {
 		set_cloexec(fd);
@@ -298,7 +302,7 @@
 			    inet_ntoa(((struct sockaddr_in *)sa[i])->
 				sin_addr));
 #endif
-			ADVANCE(cp, sa[i]);
+			RT_ADVANCE(cp, sa[i]);
 		} else
 			sa[i] = NULL;
 	}
@@ -360,13 +364,31 @@
 			case RTM_IFINFO:
 				ifm = (struct if_msghdr *)(void *)p;
 				memset(ifname, 0, sizeof(ifname));
-				if (if_indextoname(ifm->ifm_index, ifname))
-					handle_interface(0, ifname);
+				if (!(if_indextoname(ifm->ifm_index, ifname)))
+					break;
+				switch (ifm->ifm_data.ifi_link_state) {
+				case LINK_STATE_DOWN:
+					len = -1;
+					break;
+				case LINK_STATE_UP:
+					len = 1;
+					break;
+				default:
+					/* handle_carrier will re-load
+					 * the interface flags and check for
+					 * IFF_RUNNING as some drivers that
+					 * don't handle link state also don't
+					 * set IFF_RUNNING when this routing
+					 * message is generated.
+					 * As such, it is a race ...*/
+					len = 0;
+					break;
+				}
+				handle_carrier(len, ifm->ifm_flags, ifname);
 				break;
 			case RTM_DELETE:
-				if (!(rtm->rtm_addrs & RTA_DST) ||
-				    !(rtm->rtm_addrs & RTA_GATEWAY) ||
-				    !(rtm->rtm_addrs & RTA_NETMASK))
+				if (~rtm->rtm_addrs &
+				    (RTA_DST | RTA_GATEWAY | RTA_NETMASK))
 					break;
 				if (rtm->rtm_pid == getpid())
 					break;
diff --git a/if-linux-wireless.c b/if-linux-wireless.c
index dce1892..f4b649b 100644
--- a/if-linux-wireless.c
+++ b/if-linux-wireless.c
@@ -41,6 +41,7 @@
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 
+#include <linux/types.h>
 #include <linux/rtnetlink.h>
 /* Support older kernels */
 #ifdef IFLA_WIRELESS
diff --git a/if-linux.c b/if-linux.c
index c944a1a..9355359 100644
--- a/if-linux.c
+++ b/if-linux.c
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2010 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2011 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -40,6 +40,13 @@
 # define IFLA_WIRELESS (IFLA_MASTER + 1)
 #endif
 
+/* For some reason, glibc doesn't include newer flags from linux/if.h
+ * However, we cannot include linux/if.h directly as it conflicts
+ * with the glibc version. D'oh! */
+#ifndef IFF_LOWER_UP
+#define IFF_LOWER_UP	0x10000		/* driver signals L1 up		*/
+#endif
+
 #include <errno.h>
 #include <ctype.h>
 #include <stddef.h>
@@ -371,11 +378,23 @@
 		}
 		rta = RTA_NEXT(rta, len);
 	}
-	if (nlm->nlmsg_type == RTM_NEWLINK)
-		len = ifi->ifi_change == ~0U ? 1 : 0;
-	else
-		len = -1;
-	handle_interface(len, ifn);
+
+	if (nlm->nlmsg_type == RTM_DELLINK) {
+		handle_interface(-1, ifn);
+		return 1;
+	}
+
+	/* Bridge interfaces set IFF_LOWER_UP when they have a valid
+	 * hardware address. To trigger a valid hardware address pickup
+	 * we need to pretend that that don't exist until they have
+	 * IFF_LOWER_UP set. */
+	if (ifi->ifi_flags & IFF_MASTER && !(ifi->ifi_flags & IFF_LOWER_UP)) {
+		handle_interface(-1, ifn);
+		return 1;
+	}
+
+	handle_carrier(ifi->ifi_flags & IFF_RUNNING ? 1 : -1,
+	    ifi->ifi_flags, ifn);
 	return 1;
 }
 
@@ -509,15 +528,13 @@
 }
 
 int
-if_route(const struct interface *iface,
-    const struct in_addr *destination, const struct in_addr *netmask,
-    const struct in_addr *gateway, int metric, int action)
+if_route(const struct rt *rt, int action)
 {
 	struct nlmr *nlm;
 	unsigned int ifindex;
 	int retval = 0;
 
-	if (!(ifindex = if_nametoindex(iface->name))) {
+	if (!(ifindex = if_nametoindex(rt->iface->name))) {
 		errno = ENODEV;
 		return -1;
 	}
@@ -540,36 +557,36 @@
 	else {
 		nlm->hdr.nlmsg_flags |= NLM_F_CREATE /*| NLM_F_EXCL*/;
 		/* We only change route metrics for kernel routes */
-		if (destination->s_addr ==
-		    (iface->addr.s_addr & iface->net.s_addr) &&
-		    netmask->s_addr == iface->net.s_addr)
+		if (rt->dest.s_addr ==
+		    (rt->iface->addr.s_addr & rt->iface->net.s_addr) &&
+		    rt->net.s_addr == rt->iface->net.s_addr)
 			nlm->rt.rtm_protocol = RTPROT_KERNEL;
 		else
 			nlm->rt.rtm_protocol = RTPROT_BOOT;
-		if (gateway->s_addr == INADDR_ANY ||
-		    (gateway->s_addr == destination->s_addr &&
-			netmask->s_addr == INADDR_BROADCAST))
+		if (rt->gate.s_addr == INADDR_ANY ||
+		    (rt->gate.s_addr == rt->dest.s_addr &&
+			rt->net.s_addr == INADDR_BROADCAST))
 			nlm->rt.rtm_scope = RT_SCOPE_LINK;
 		else
 			nlm->rt.rtm_scope = RT_SCOPE_UNIVERSE;
 		nlm->rt.rtm_type = RTN_UNICAST;
 	}
 
-	nlm->rt.rtm_dst_len = inet_ntocidr(*netmask);
+	nlm->rt.rtm_dst_len = inet_ntocidr(rt->net);
 	add_attr_l(&nlm->hdr, sizeof(*nlm), RTA_DST,
-	    &destination->s_addr, sizeof(destination->s_addr));
+	    &rt->dest.s_addr, sizeof(rt->dest.s_addr));
 	if (nlm->rt.rtm_protocol == RTPROT_KERNEL) {
 		add_attr_l(&nlm->hdr, sizeof(*nlm), RTA_PREFSRC,
-		    &iface->addr.s_addr, sizeof(iface->addr.s_addr));
+		    &rt->iface->addr.s_addr, sizeof(rt->iface->addr.s_addr));
 	}
 	/* If destination == gateway then don't add the gateway */
-	if (destination->s_addr != gateway->s_addr ||
-	    netmask->s_addr != INADDR_BROADCAST)
+	if (rt->dest.s_addr != rt->gate.s_addr ||
+	    rt->net.s_addr != INADDR_BROADCAST)
 		add_attr_l(&nlm->hdr, sizeof(*nlm), RTA_GATEWAY,
-		    &gateway->s_addr, sizeof(gateway->s_addr));
+		    &rt->gate.s_addr, sizeof(rt->gate.s_addr));
 
 	add_attr_32(&nlm->hdr, sizeof(*nlm), RTA_OIF, ifindex);
-	add_attr_32(&nlm->hdr, sizeof(*nlm), RTA_PRIORITY, metric);
+	add_attr_32(&nlm->hdr, sizeof(*nlm), RTA_PRIORITY, rt->metric);
 
 	if (send_netlink(&nlm->hdr) == -1)
 		retval = -1;
diff --git a/if-options.c b/if-options.c
index 9e77f2b..3f52bfe 100644
--- a/if-options.c
+++ b/if-options.c
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2010 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -53,6 +53,8 @@
 #define O_ARPING	O_BASE + 1
 #define O_FALLBACK	O_BASE + 2
 #define O_DESTINATION	O_BASE + 3
+#define O_NOIPV6RS	O_BASE + 4
+#define O_IPV6_RA_FORK	O_BASE + 5
 
 const struct option cf_options[] = {
 	{"background",      no_argument,       NULL, 'b'},
@@ -103,6 +105,8 @@
 	{"arping",          required_argument, NULL, O_ARPING},
 	{"destination",     required_argument, NULL, O_DESTINATION},
 	{"fallback",        required_argument, NULL, O_FALLBACK},
+	{"noipv6rs",        no_argument,       NULL, O_NOIPV6RS},
+	{"ipv6ra_fork",     no_argument,       NULL, O_IPV6_RA_FORK},
 	{NULL,              0,                 NULL, '\0'}
 };
 
@@ -626,11 +630,16 @@
 		}
 		p++;
 		if (strncmp(arg, "ip_address=", strlen("ip_address=")) == 0) {
-			if (parse_addr(&ifo->req_addr, &ifo->req_mask, p) != 0)
+			if (parse_addr(&ifo->req_addr,
+			    ifo->req_mask.s_addr == 0 ? &ifo->req_mask : NULL,
+			    p) != 0)
 				return -1;
 
 			ifo->options |= DHCPCD_STATIC;
 			ifo->options &= ~DHCPCD_INFORM;
+		} else if (strncmp(arg, "subnet_mask=", strlen("subnet_mask=")) == 0) {
+			if (parse_addr(&ifo->req_mask, NULL, p) != 0)
+				return -1;
 		} else if (strncmp(arg, "routes=", strlen("routes=")) == 0 ||
 		    strncmp(arg, "static_routes=", strlen("static_routes=")) == 0 ||
 		    strncmp(arg, "classless_static_routes=", strlen("classless_static_routes=")) == 0 ||
@@ -736,6 +745,12 @@
 		free(ifo->fallback);
 		ifo->fallback = xstrdup(arg);
 		break;
+	case O_NOIPV6RS:
+		ifo->options &= ~DHCPCD_IPV6RS;
+		break;
+	case O_IPV6_RA_FORK:
+		ifo->options &= ~DHCPCD_IPV6RA_REQRDNSS;
+		break;
 	default:
 		return 0;
 	}
@@ -779,8 +794,9 @@
 
 	/* Seed our default options */
 	ifo = xzalloc(sizeof(*ifo));
-	ifo->options |= DHCPCD_GATEWAY | DHCPCD_DAEMONISE;
-	ifo->options |= DHCPCD_ARP | DHCPCD_IPV4LL | DHCPCD_LINK;
+	ifo->options |= DHCPCD_GATEWAY | DHCPCD_DAEMONISE | DHCPCD_LINK;
+	ifo->options |= DHCPCD_ARP | DHCPCD_IPV4LL;
+	ifo->options |= DHCPCD_IPV6RS | DHCPCD_IPV6RA_REQRDNSS;
 	ifo->timeout = DEFAULT_TIMEOUT;
 	ifo->reboot = DEFAULT_REBOOT;
 	ifo->metric = -1;
diff --git a/if-options.h b/if-options.h
index 98950ef..0e9d103 100644
--- a/if-options.h
+++ b/if-options.h
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2010 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -40,7 +40,7 @@
 #define IF_OPTS "abc:de:f:gh:i:kl:m:no:pqr:s:t:u:v:wxy:z:ABC:DEF:GHI:JKLO:Q:S:TUVW:X:Z:"
 
 #define DEFAULT_TIMEOUT		30
-#define DEFAULT_REBOOT		10
+#define DEFAULT_REBOOT		5
 
 #define HOSTNAME_MAX_LEN	250	/* 255 - 3 (FQDN) - 2 (DNS enc) */
 #define VENDORCLASSID_MAX_LEN	255
@@ -48,35 +48,37 @@
 #define USERCLASS_MAX_LEN	255
 #define VENDOR_MAX_LEN		255
 
-#define DHCPCD_ARP		(1 << 0)
-#define DHCPCD_RELEASE		(1 << 1)
-#define DHCPCD_DOMAIN		(1 << 2)
-#define DHCPCD_GATEWAY		(1 << 3)
-#define DHCPCD_STATIC		(1 << 4)
-#define DHCPCD_DEBUG		(1 << 5)
-#define DHCPCD_LASTLEASE	(1 << 7)
-#define DHCPCD_INFORM		(1 << 8)
-#define DHCPCD_REQUEST		(1 << 9)
-#define DHCPCD_IPV4LL		(1 << 10)
-#define DHCPCD_DUID		(1 << 11)
-#define DHCPCD_PERSISTENT	(1 << 12)
-#define DHCPCD_DAEMONISE	(1 << 14)
-#define DHCPCD_DAEMONISED	(1 << 15)
-#define DHCPCD_TEST		(1 << 16)
-#define DHCPCD_MASTER		(1 << 17)
-#define DHCPCD_HOSTNAME		(1 << 18)
-#define DHCPCD_CLIENTID		(1 << 19)
-#define DHCPCD_LINK		(1 << 20)
-#define DHCPCD_QUIET		(1 << 21) 
-#define DHCPCD_BACKGROUND	(1 << 22)
-#define DHCPCD_VENDORRAW	(1 << 23)
-#define DHCPCD_TIMEOUT_IPV4LL	(1 << 24)
-#define DHCPCD_WAITIP		(1 << 25)
-#define DHCPCD_WAITUP		(1 << 26)
-#define DHCPCD_CSR_WARNED	(1 << 27)
-#define DHCPCD_XID_HWADDR	(1 << 28)
-#define DHCPCD_BROADCAST	(1 << 29)
-#define DHCPCD_DUMPLEASE	(1 << 30)
+#define DHCPCD_ARP			(1ULL << 0)
+#define DHCPCD_RELEASE			(1ULL << 1)
+#define DHCPCD_DOMAIN			(1ULL << 2)
+#define DHCPCD_GATEWAY			(1ULL << 3)
+#define DHCPCD_STATIC			(1ULL << 4)
+#define DHCPCD_DEBUG			(1ULL << 5)
+#define DHCPCD_LASTLEASE		(1ULL << 7)
+#define DHCPCD_INFORM			(1ULL << 8)
+#define DHCPCD_REQUEST			(1ULL << 9)
+#define DHCPCD_IPV4LL			(1ULL << 10)
+#define DHCPCD_DUID			(1ULL << 11)
+#define DHCPCD_PERSISTENT		(1ULL << 12)
+#define DHCPCD_DAEMONISE		(1ULL << 14)
+#define DHCPCD_DAEMONISED		(1ULL << 15)
+#define DHCPCD_TEST			(1ULL << 16)
+#define DHCPCD_MASTER			(1ULL << 17)
+#define DHCPCD_HOSTNAME			(1ULL << 18)
+#define DHCPCD_CLIENTID			(1ULL << 19)
+#define DHCPCD_LINK			(1ULL << 20)
+#define DHCPCD_QUIET			(1ULL << 21) 
+#define DHCPCD_BACKGROUND		(1ULL << 22)
+#define DHCPCD_VENDORRAW		(1ULL << 23)
+#define DHCPCD_TIMEOUT_IPV4LL		(1ULL << 24)
+#define DHCPCD_WAITIP			(1ULL << 25)
+#define DHCPCD_WAITUP			(1ULL << 26)
+#define DHCPCD_CSR_WARNED		(1ULL << 27)
+#define DHCPCD_XID_HWADDR		(1ULL << 28)
+#define DHCPCD_BROADCAST		(1ULL << 29)
+#define DHCPCD_DUMPLEASE		(1ULL << 30)
+#define DHCPCD_IPV6RS			(1ULL << 31)
+#define DHCPCD_IPV6RA_REQRDNSS		(1ULL << 32)
 
 extern const struct option cf_options[];
 
@@ -89,7 +91,7 @@
 	uint32_t leasetime;
 	time_t timeout;
 	time_t reboot;
-	int options;
+	unsigned long long options;
 
 	struct in_addr req_addr;
 	struct in_addr req_mask;
diff --git a/if-pref.c b/if-pref.c
index 83b1b0f..6169dbe 100644
--- a/if-pref.c
+++ b/if-pref.c
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2010 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -55,9 +55,9 @@
 		sill = (si->state->new->cookie == htonl(MAGIC_COOKIE));
 		till = (ti->state->new->cookie == htonl(MAGIC_COOKIE));
 		if (!sill && till)
-			return -1;
-		if (sill && !till)
 			return 1;
+		if (sill && !till)
+			return -1;
 	}
 	/* Then carrier status. */
 	if (si->carrier > ti->carrier)
diff --git a/ifaddrs.c b/ifaddrs.c
index cb8fd76..0554ee7 100644
--- a/ifaddrs.c
+++ b/ifaddrs.c
@@ -32,14 +32,15 @@
 
 struct ifaddrs *get_interface(const char *name, sa_family_t family)
 {
-    unsigned addr, mask, flags;
+    unsigned addr, flags;
+    int masklen;
     struct ifaddrs *ifa;
     struct sockaddr_in *saddr = NULL;
     struct sockaddr_in *smask = NULL;
     struct sockaddr_ll *hwaddr = NULL;
     unsigned char hwbuf[ETH_ALEN];
 
-    if(ifc_get_info(name, &addr, &mask, &flags))
+    if (ifc_get_info(name, &addr, &masklen, &flags))
         return NULL;
 
     if ((family == AF_INET) && (addr == 0))
@@ -66,10 +67,10 @@
         }
         ifa->ifa_addr = (struct sockaddr *)saddr;
 
-        if (mask != 0) {
+        if (masklen != 0) {
             smask = malloc(sizeof(struct sockaddr_in));
             if (smask) {
-                smask->sin_addr.s_addr = mask;
+                smask->sin_addr.s_addr = prefixLengthToIpv4Netmask(masklen);
                 smask->sin_family = family;
             }
         }
diff --git a/ipv4ll.c b/ipv4ll.c
index 4336540..622abb7 100644
--- a/ipv4ll.c
+++ b/ipv4ll.c
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2008 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2011 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -131,7 +131,7 @@
 			syslog(LOG_DEBUG,
 			    "%s: IPv4LL %d second defence failed",
 			    iface->name, DEFEND_INTERVAL);
-			drop_config(iface, "EXPIRE");
+			drop_dhcp(iface, "EXPIRE");
 			iface->state->conflicts = -1;
 		} else {
 			syslog(LOG_DEBUG, "%s: defended IPv4LL address",
diff --git a/ipv6rs.c b/ipv6rs.c
new file mode 100644
index 0000000..df96934
--- /dev/null
+++ b/ipv6rs.c
@@ -0,0 +1,762 @@
+/* 
+ * dhcpcd - DHCP client daemon
+ * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
+ * All rights reserved
+
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <netinet/in.h>
+#include <netinet/ip6.h>
+#include <netinet/icmp6.h>
+
+#include <errno.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <syslog.h>
+
+#ifdef __linux__
+#  define _LINUX_IN6_H
+#  include <linux/ipv6.h>
+#endif
+
+#define ELOOP_QUEUE 1
+#include "bind.h"
+#include "common.h"
+#include "configure.h"
+#include "dhcpcd.h"
+#include "eloop.h"
+#include "ipv6rs.h"
+
+#define ALLROUTERS "ff02::2"
+#define HOPLIMIT 255
+
+#define ROUNDUP8(a) (1 + (((a) - 1) | 7))
+
+#define RTR_SOLICITATION_INTERVAL       4 /* seconds */
+#define MAX_RTR_SOLICITATIONS           3 /* times */
+
+#ifndef ND_OPT_RDNSS
+#define ND_OPT_RDNSS			25
+struct nd_opt_rdnss {           /* RDNSS option RFC 6106 */
+	uint8_t		nd_opt_rdnss_type;
+	uint8_t		nd_opt_rdnss_len;
+	uint16_t	nd_opt_rdnss_reserved;
+	uint32_t	nd_opt_rdnss_lifetime;
+        /* followed by list of IP prefixes */
+} _packed;
+#endif
+
+#ifndef ND_OPT_DNSSL
+#define ND_OPT_DNSSL			31
+struct nd_opt_dnssl {		/* DNSSL option RFC 6106 */
+	uint8_t		nd_opt_dnssl_type;
+	uint8_t		nd_opt_dnssl_len;
+	uint16_t	nd_opt_dnssl_reserved;
+	uint32_t	nd_opt_dnssl_lifetime;
+	/* followed by list of DNS servers */
+} _packed;
+#endif
+
+static int sock;
+static struct sockaddr_in6 allrouters, from;
+static struct msghdr sndhdr;
+static struct iovec sndiov[2];
+static unsigned char *sndbuf;
+static struct msghdr rcvhdr;
+static struct iovec rcviov[2];
+static unsigned char *rcvbuf;
+static unsigned char ansbuf[1500];
+static char ntopbuf[INET6_ADDRSTRLEN];
+
+#if DEBUG_MEMORY
+static void
+ipv6rs_cleanup(void)
+{
+
+	free(sndbuf);
+	free(rcvbuf);
+}
+#endif
+
+int
+ipv6rs_open(void)
+{
+	int on;
+	int len;
+	struct icmp6_filter filt;
+
+	memset(&allrouters, 0, sizeof(allrouters));
+	allrouters.sin6_family = AF_INET6;
+#ifdef SIN6_LEN
+	allrouters.sin6_len = sizeof(allrouters);
+#endif
+	if (inet_pton(AF_INET6, ALLROUTERS, &allrouters.sin6_addr.s6_addr) != 1)
+		return -1;
+	sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
+	if (sock == -1)
+		return -1;
+	on = 1;
+	if (setsockopt(sock, IPPROTO_IPV6, IPV6_RECVPKTINFO,
+		&on, sizeof(on)) == -1)
+		return -1;
+
+	on = 1;
+	if (setsockopt(sock, IPPROTO_IPV6, IPV6_RECVHOPLIMIT,
+		&on, sizeof(on)) == -1)
+		return -1;
+
+	ICMP6_FILTER_SETBLOCKALL(&filt);
+	ICMP6_FILTER_SETPASS(ND_ROUTER_ADVERT, &filt);
+	if (setsockopt(sock, IPPROTO_ICMPV6, ICMP6_FILTER,
+		&filt, sizeof(filt)) == -1)
+		return -1;
+
+#if DEBUG_MEMORY
+	atexit(ipv6rs_cleanup);
+#endif
+
+	len = CMSG_SPACE(sizeof(struct in6_pktinfo)) + CMSG_SPACE(sizeof(int));
+	sndbuf = xzalloc(len);
+	if (sndbuf == NULL)
+		return -1;
+	sndhdr.msg_namelen = sizeof(struct sockaddr_in6);
+	sndhdr.msg_iov = sndiov;
+	sndhdr.msg_iovlen = 1;
+	sndhdr.msg_control = sndbuf;
+	sndhdr.msg_controllen = len;
+	rcvbuf = xzalloc(len);
+	if (rcvbuf == NULL)
+		return -1;
+	rcvhdr.msg_name = &from;
+	rcvhdr.msg_namelen = sizeof(from);
+	rcvhdr.msg_iov = rcviov;
+	rcvhdr.msg_iovlen = 1;
+	rcvhdr.msg_control = rcvbuf;
+	rcvhdr.msg_controllen = len;
+	rcviov[0].iov_base = ansbuf;
+	rcviov[0].iov_len = sizeof(ansbuf);
+	return sock;
+}
+
+static int
+ipv6rs_makeprobe(struct interface *ifp)
+{
+	struct nd_router_solicit *rs;
+	struct nd_opt_hdr *nd;
+
+	free(ifp->rs);
+	ifp->rslen = sizeof(*rs) + ROUNDUP8(ifp->hwlen + 2);
+	ifp->rs = xzalloc(ifp->rslen);
+	if (ifp->rs == NULL)
+		return -1;
+	rs = (struct nd_router_solicit *)ifp->rs;
+	rs->nd_rs_type = ND_ROUTER_SOLICIT;
+	rs->nd_rs_code = 0;
+	rs->nd_rs_cksum = 0;
+	rs->nd_rs_reserved = 0;
+	nd = (struct nd_opt_hdr *)(ifp->rs + sizeof(*rs));
+	nd->nd_opt_type = ND_OPT_SOURCE_LINKADDR;
+	nd->nd_opt_len = (ROUNDUP8(ifp->hwlen + 2)) >> 3;
+	memcpy(nd + 1, ifp->hwaddr, ifp->hwlen);
+	return 0;
+}
+	
+static void
+ipv6rs_sendprobe(void *arg)
+{
+	struct interface *ifp = arg;
+	struct sockaddr_in6 dst;
+	struct cmsghdr *cm;
+	struct in6_pktinfo pi;
+	int hoplimit = HOPLIMIT;
+
+	dst = allrouters;
+	//dst.sin6_scope_id = ifp->linkid;
+
+	ipv6rs_makeprobe(ifp);
+	sndhdr.msg_name = (caddr_t)&dst;
+	sndhdr.msg_iov[0].iov_base = ifp->rs;
+	sndhdr.msg_iov[0].iov_len = ifp->rslen;
+
+	/* Set the outbound interface */
+	cm = CMSG_FIRSTHDR(&sndhdr);
+	cm->cmsg_level = IPPROTO_IPV6;
+	cm->cmsg_type = IPV6_PKTINFO;
+	cm->cmsg_len = CMSG_LEN(sizeof(pi));
+	memset(&pi, 0, sizeof(pi));
+	pi.ipi6_ifindex = if_nametoindex(ifp->name);
+	memcpy(CMSG_DATA(cm), &pi, sizeof(pi));
+
+	/* Hop limit */
+	cm = CMSG_NXTHDR(&sndhdr, cm);
+	cm->cmsg_level = IPPROTO_IPV6;
+	cm->cmsg_type = IPV6_HOPLIMIT;
+	cm->cmsg_len = CMSG_LEN(sizeof(hoplimit));
+	memcpy(CMSG_DATA(cm), &hoplimit, sizeof(hoplimit));
+
+	syslog(LOG_INFO, "%s: sending IPv6 Router Solicitation", ifp->name);
+	if (sendmsg(sock, &sndhdr, 0) == -1)
+		syslog(LOG_ERR, "%s: sendmsg: %m", ifp->name);
+
+	if (ifp->rsprobes++ < MAX_RTR_SOLICITATIONS)
+		add_timeout_sec(RTR_SOLICITATION_INTERVAL,
+		    ipv6rs_sendprobe, ifp);
+	else
+		syslog(LOG_INFO, "%s: no IPv6 Routers available", ifp->name);
+}
+
+static void
+ipv6rs_sort(struct interface *ifp)
+{
+	struct ra *rap, *sorted, *ran, *rat;
+
+	if (ifp->ras == NULL || ifp->ras->next == NULL)
+		return;
+
+	/* Sort our RA's - most recent first */
+	sorted = ifp->ras;
+	ifp->ras = ifp->ras->next;
+	sorted->next = NULL;
+	for (rap = ifp->ras; rap && (ran = rap->next, 1); rap = ran) {
+		/* Are we the new head? */
+		if (timercmp(&rap->received, &sorted->received, <)) {
+			rap->next = sorted;
+			sorted = rap;
+			continue;
+		}
+		/* Do we fit in the middle? */
+		for (rat = sorted; rat->next; rat = rat->next) {
+			if (timercmp(&rap->received, &rat->next->received, <)) {
+				rap->next = rat->next;
+				rat->next = rap;
+				break;
+			}
+		}
+		/* We must be at the end */
+		if (!rat->next) {
+			rat->next = rap;
+			rap->next = NULL;
+		}
+	}
+}
+
+void
+ipv6rs_handledata(_unused void *arg)
+{
+	ssize_t len, l, n, olen;
+	struct cmsghdr *cm;
+	int hoplimit;
+	struct in6_pktinfo pkt;
+	struct icmp6_hdr *icp;
+	struct interface *ifp;
+	const char *sfrom;
+	struct nd_router_advert *nd_ra;
+	struct nd_opt_prefix_info *pi;
+	struct nd_opt_mtu *mtu;
+	struct nd_opt_rdnss *rdnss;
+	struct nd_opt_dnssl *dnssl;
+	uint32_t lifetime;
+	uint8_t *p, *op;
+	struct in6_addr addr;
+	char buf[INET6_ADDRSTRLEN];
+	const char *cbp;
+	struct ra *rap;
+	struct nd_opt_hdr *ndo;
+	struct ra_opt *rao, *raol;
+	char *opt;
+	struct timeval expire;
+	int has_dns;
+
+	len = recvmsg(sock, &rcvhdr, 0);
+	if (len == -1) {
+		syslog(LOG_ERR, "recvmsg: %m");
+		return;
+	}
+	sfrom = inet_ntop(AF_INET6, &from.sin6_addr,
+	    ntopbuf, INET6_ADDRSTRLEN);
+	if ((size_t)len < sizeof(struct nd_router_advert)) {
+		syslog(LOG_ERR, "IPv6 RA packet too short from %s", sfrom);
+		return;
+	}
+
+	pkt.ipi6_ifindex = hoplimit = 0;
+	for (cm = (struct cmsghdr *)CMSG_FIRSTHDR(&rcvhdr);
+	     cm;
+	     cm = (struct cmsghdr *)CMSG_NXTHDR(&rcvhdr, cm))
+	{
+		if (cm->cmsg_level != IPPROTO_IPV6)
+			continue;
+		switch(cm->cmsg_type) {
+		case IPV6_PKTINFO:
+			if (cm->cmsg_len == CMSG_LEN(sizeof(pkt)))
+				memcpy(&pkt, CMSG_DATA(cm), sizeof(pkt));
+			break;
+		case IPV6_HOPLIMIT:
+			if (cm->cmsg_len == CMSG_LEN(sizeof(int)))
+				memcpy(&hoplimit, CMSG_DATA(cm), sizeof(int));
+			break;
+		}
+	}
+
+	if (pkt.ipi6_ifindex == 0 || hoplimit == 0) {
+		syslog(LOG_ERR,
+		    "IPv6 RA did not contain index or hop limit from %s",
+		    sfrom);
+		return;
+	}
+
+	icp = (struct icmp6_hdr *)rcvhdr.msg_iov[0].iov_base;
+	if (icp->icmp6_type != ND_ROUTER_ADVERT ||
+	    icp->icmp6_code != 0)
+	{
+		syslog(LOG_ERR, "invalid IPv6 type or code from %s", sfrom);
+		return;
+	}
+
+	if (!IN6_IS_ADDR_LINKLOCAL(&from.sin6_addr)) {
+		syslog(LOG_ERR, "RA recieved from non local IPv6 address %s",
+		    sfrom);
+		return;
+	}
+
+	for (ifp = ifaces; ifp; ifp = ifp->next)
+		if (if_nametoindex(ifp->name) == (unsigned int)pkt.ipi6_ifindex)
+			break;
+	if (ifp == NULL) {
+		syslog(LOG_ERR,"received RA for unexpected interface from %s",
+		    sfrom);
+		return;
+	}
+	for (rap = ifp->ras; rap; rap = rap->next) {
+		if (memcmp(rap->from.s6_addr, from.sin6_addr.s6_addr,
+		    sizeof(rap->from.s6_addr)) == 0)
+			break;
+	}
+
+	/* We don't want to spam the log with the fact we got an RA every
+	 * 30 seconds or so, so only spam the log if it's different. */
+	if (options & DHCPCD_DEBUG || rap == NULL ||
+	    (rap->expired || rap->data_len != len ||
+	     memcmp(rap->data, (unsigned char *)icp, rap->data_len) != 0))
+	{
+		if (rap) {
+			free(rap->data);
+			rap->data_len = 0;
+		}
+		syslog(LOG_INFO, "%s: Router Advertisement from %s",
+		    ifp->name, sfrom);
+	}
+
+	if (rap == NULL) {
+		rap = xmalloc(sizeof(*rap));
+		rap->next = ifp->ras;
+		rap->options = NULL;
+		ifp->ras = rap;
+		memcpy(rap->from.s6_addr, from.sin6_addr.s6_addr,
+		    sizeof(rap->from.s6_addr));
+		strlcpy(rap->sfrom, sfrom, sizeof(rap->sfrom));
+		rap->data_len = 0;
+	}
+	if (rap->data_len == 0) {
+		rap->data = xmalloc(len);
+		memcpy(rap->data, icp, len);
+		rap->data_len = len;
+	}
+
+	get_monotonic(&rap->received);
+	nd_ra = (struct nd_router_advert *)icp;
+	rap->lifetime = ntohs(nd_ra->nd_ra_router_lifetime);
+	rap->expired = 0;
+
+	len -= sizeof(struct nd_router_advert);
+	p = ((uint8_t *)icp) + sizeof(struct nd_router_advert);
+	olen = 0;
+	lifetime = ~0U;
+	has_dns = 0;
+	for (olen = 0; len > 0; p += olen, len -= olen) {
+		if ((size_t)len < sizeof(struct nd_opt_hdr)) {
+			syslog(LOG_ERR, "%s: Short option", ifp->name);
+			break;
+		}
+		ndo = (struct nd_opt_hdr *)p;
+		olen = ndo->nd_opt_len * 8 ;
+		if (olen == 0) {
+			syslog(LOG_ERR, "%s: zero length option", ifp->name);
+			break;
+		}
+		if (olen > len) {
+			syslog(LOG_ERR,
+			    "%s: Option length exceeds message", ifp->name);
+			break;
+		}
+
+		opt = NULL;
+		switch (ndo->nd_opt_type) {
+		case ND_OPT_PREFIX_INFORMATION:
+			pi = (struct nd_opt_prefix_info *)ndo;
+			if (pi->nd_opt_pi_len != 4) {
+				syslog(LOG_ERR,
+				    "%s: invalid option len for prefix",
+				    ifp->name);
+				break;
+			}
+			if (pi->nd_opt_pi_prefix_len > 128) {
+				syslog(LOG_ERR, "%s: invalid prefix len",
+				    ifp->name);
+				break;
+			}
+			if (IN6_IS_ADDR_MULTICAST(&pi->nd_opt_pi_prefix) ||
+			    IN6_IS_ADDR_LINKLOCAL(&pi->nd_opt_pi_prefix))
+			{
+				syslog(LOG_ERR,
+				    "%s: invalid prefix in RA", ifp->name);
+				break;
+			}
+			opt = xstrdup(inet_ntop(AF_INET6,
+			    pi->nd_opt_pi_prefix.s6_addr,
+			    ntopbuf, INET6_ADDRSTRLEN));
+			if (opt) {
+				rap->prefix_len = pi->nd_opt_pi_prefix_len;
+				rap->prefix_vltime =
+					ntohl(pi->nd_opt_pi_valid_time);
+				rap->prefix_pltime =
+					ntohl(pi->nd_opt_pi_preferred_time);
+			}
+			break;
+
+		case ND_OPT_MTU:
+			mtu = (struct nd_opt_mtu *)p;
+			snprintf(buf, sizeof(buf), "%d",
+			    ntohl(mtu->nd_opt_mtu_mtu));
+			opt = xstrdup(buf);
+			break;
+
+		case ND_OPT_RDNSS:
+			rdnss = (struct nd_opt_rdnss *)p;
+			lifetime = ntohl(rdnss->nd_opt_rdnss_lifetime);
+			op = (uint8_t *)ndo;
+			op += offsetof(struct nd_opt_rdnss,
+			    nd_opt_rdnss_lifetime);
+			op += sizeof(rdnss->nd_opt_rdnss_lifetime);
+			l = 0;
+			for (n = ndo->nd_opt_len - 1; n > 1; n -= 2) {
+				memcpy(&addr.s6_addr, op, sizeof(addr.s6_addr));
+				cbp = inet_ntop(AF_INET6, &addr,
+				    ntopbuf, INET6_ADDRSTRLEN);
+				if (cbp == NULL) {
+					syslog(LOG_ERR,
+					    "%s: invalid RDNSS address",
+					    ifp->name);
+				} else {
+					if (opt) {
+						l = strlen(opt);
+						opt = xrealloc(opt,
+							l + strlen(cbp) + 2);
+						opt[l] = ' ';
+						strcpy(opt + l + 1, cbp);
+					} else
+						opt = xstrdup(cbp);
+					if (lifetime > 0)
+						has_dns = 1;
+				}
+		        	op += sizeof(addr.s6_addr);
+			}
+			break;
+			
+		case ND_OPT_DNSSL:
+			dnssl = (struct nd_opt_dnssl *)p;
+			lifetime = ntohl(dnssl->nd_opt_dnssl_lifetime);
+			op = p + offsetof(struct nd_opt_dnssl,
+			    nd_opt_dnssl_lifetime);
+			op += sizeof(dnssl->nd_opt_dnssl_lifetime);
+			n = (dnssl->nd_opt_dnssl_len - 1) * 8;
+			l = decode_rfc3397(NULL, 0, n, op);
+			if (l < 1) {
+				syslog(LOG_ERR, "%s: invalid DNSSL option",
+				    ifp->name);
+			} else {
+				opt = xmalloc(l);
+				decode_rfc3397(opt, l, n, op);
+			}
+			break;
+		}
+
+		if (opt == NULL)
+			continue;
+		for (raol = NULL, rao = rap->options;
+		    rao;
+		    raol = rao, rao = rao->next)
+		{
+			if (rao->type == ndo->nd_opt_type &&
+			    strcmp(rao->option, opt) == 0)
+				break;
+		}
+		if (lifetime == 0) {
+			if (rao) {
+				if (raol)
+					raol->next = rao->next;
+				else
+					rap->options = rao->next;
+				free(rao->option);
+				free(rao);
+			}
+			continue;
+		}
+
+		if (rao == NULL) {
+			rao = xmalloc(sizeof(*rao));
+			rao->next = rap->options;
+			rap->options = rao;
+			rao->type = ndo->nd_opt_type;
+			rao->option = opt;
+		} else
+			free(opt);
+		if (lifetime == ~0U)
+			timerclear(&rao->expire);
+		else {
+			expire.tv_sec = lifetime;
+			expire.tv_usec = 0;
+			timeradd(&rap->received, &expire, &rao->expire);
+		}
+	}
+
+	ipv6rs_sort(ifp);
+	run_script_reason(ifp, options & DHCPCD_TEST ? "TEST" : "ROUTERADVERT");
+	if (options & DHCPCD_TEST)
+		exit(EXIT_SUCCESS);
+
+	/* If we don't require RDNSS then set has_dns = 1 so we fork */
+	if (!(ifp->state->options->options & DHCPCD_IPV6RA_REQRDNSS))
+		has_dns = 1;
+
+	if (has_dns)
+		delete_q_timeout(0, handle_exit_timeout, NULL);
+	delete_timeout(NULL, ifp);
+	ipv6rs_expire(ifp);
+	if (has_dns)
+		daemonise();
+	else if (options & DHCPCD_DAEMONISE && !(options & DHCPCD_DAEMONISED))
+		syslog(LOG_WARNING,
+		    "%s: did not fork due to an absent RDNSS option in the RA",
+		    ifp->name);
+}
+
+ssize_t
+ipv6rs_env(char **env, const char *prefix, const struct interface *ifp)
+{
+	ssize_t l;
+	struct timeval now;
+	const struct ra *rap;
+	const struct ra_opt *rao;
+	int i;
+	char buffer[32], buffer2[32];
+	const char *optn;
+	
+	l = 0;
+	get_monotonic(&now);
+	for (rap = ifp->ras, i = 1; rap; rap = rap->next, i++) {
+		if (env) {
+			snprintf(buffer, sizeof(buffer),
+			    "ra%d_from", i);
+			setvar(&env, prefix, buffer, rap->sfrom);
+		}
+		l++;
+
+		for (rao = rap->options; rao; rao = rao->next) {
+			if (rao->option == NULL)
+				continue;
+			if (env == NULL) {
+				switch (rao->type) {
+				case ND_OPT_PREFIX_INFORMATION:
+					l += 4;
+					break;
+				default:
+					l++;
+				}
+				continue;
+			}
+			switch (rao->type) {
+			case ND_OPT_PREFIX_INFORMATION:
+				optn = "prefix";
+				break;
+			case ND_OPT_MTU:
+				optn = "mtu";
+				break;
+			case ND_OPT_RDNSS:
+				optn = "rdnss";
+				break;
+			case ND_OPT_DNSSL:
+				optn = "dnssl";
+				break;
+			default:
+				continue;
+			}
+			snprintf(buffer, sizeof(buffer), "ra%d_%s", i, optn);
+			setvar(&env, prefix, buffer, rao->option);
+			l++;
+			switch (rao->type) {
+			case ND_OPT_PREFIX_INFORMATION:
+				snprintf(buffer, sizeof(buffer),
+				    "ra%d_prefix_len", i);
+				snprintf(buffer2, sizeof(buffer2),
+				    "%d", rap->prefix_len);
+				setvar(&env, prefix, buffer, buffer2);
+
+				snprintf(buffer, sizeof(buffer),
+				    "ra%d_prefix_vltime", i);
+				snprintf(buffer2, sizeof(buffer2),
+				    "%d", rap->prefix_vltime);
+				setvar(&env, prefix, buffer, buffer2);
+
+				snprintf(buffer, sizeof(buffer),
+				    "ra%d_prefix_pltime", i);
+				snprintf(buffer2, sizeof(buffer2),
+				    "%d", rap->prefix_pltime);
+				setvar(&env, prefix, buffer, buffer2);
+				l += 3;
+				break;
+			}
+		
+		}
+	}
+
+	if (env)
+		setvard(&env, prefix, "ra_count", i - 1);
+	l++;
+	return l;
+}
+
+static void
+ipv6rs_free_opts(struct ra *rap)
+{
+	struct ra_opt *rao, *raon;
+
+	for (rao = rap->options; rao && (raon = rao->next, 1); rao = raon) {
+		free(rao->option);
+		free(rao);
+	}
+}
+
+void
+ipv6rs_free(struct interface *ifp)
+{
+	struct ra *rap, *ran;
+
+	free(ifp->rs);
+	ifp->rs = NULL;
+	for (rap = ifp->ras; rap && (ran = rap->next, 1); rap = ran) {
+		ipv6rs_free_opts(rap);
+		free(rap->data);
+		free(rap);
+	}
+	ifp->ras = NULL;
+}
+
+void
+ipv6rs_expire(void *arg)
+{
+	struct interface *ifp;
+	struct ra *rap, *ran, *ral;
+	struct ra_opt *rao, *raol, *raon;
+	struct timeval now, lt, expire, next;
+	int expired;
+	uint32_t expire_secs;
+
+	ifp = arg;
+	get_monotonic(&now);
+	expired = 0;
+	expire_secs = ~0U;
+	timerclear(&next);
+
+	for (rap = ifp->ras, ral = NULL;
+	    rap && (ran = rap->next, 1);
+	    ral = rap, rap = ran)
+	{
+		lt.tv_sec = rap->lifetime;
+		lt.tv_usec = 0;
+		timeradd(&rap->received, &lt, &expire);
+		if (timercmp(&now, &expire, >)) {
+			syslog(LOG_INFO, "%s: %s: expired Router Advertisement",
+			    ifp->name, rap->sfrom);
+			rap->expired = expired = 1;
+			if (ral)
+				ral->next = ran;
+			else
+				ifp->ras = ran;
+			ipv6rs_free_opts(rap);
+			free(rap);
+			continue;
+		}
+		timersub(&expire, &now, &lt);
+		if (!timerisset(&next) || timercmp(&next, &lt, >))
+			next = lt;
+		
+		for (rao = rap->options, raol = NULL;
+		    rao && (raon = rao->next);
+		    raol = rao, rao = raon)
+		{
+			if (!timerisset(&rao->expire))
+				continue;
+			if (timercmp(&now, &rao->expire, >)) {
+				syslog(LOG_INFO,
+				    "%s: %s: expired option %d",
+				    ifp->name, rap->sfrom, rao->type);
+				rap->expired = expired = 1;
+				if (raol)
+					raol = raon;
+				else
+					rap->options = raon;
+				continue;
+			}
+			timersub(&rao->expire, &now, &lt);
+			if (!timerisset(&next) || timercmp(&next, &lt, >))
+				next = lt;
+		}
+	}
+
+	if (timerisset(&next))
+		add_timeout_tv(&next, ipv6rs_expire, ifp);
+	if (expired)
+		run_script_reason(ifp, "ROUTERADVERT");
+}
+
+int
+ipv6rs_start(struct interface *ifp)
+{
+
+	delete_timeout(NULL, ifp);
+
+	/* Always make a new probe as the underlying hardware
+	 * address could have changed. */
+	ipv6rs_makeprobe(ifp);
+	if (ifp->rs == NULL)
+		return -1;
+
+	ifp->rsprobes = 0;
+	ipv6rs_sendprobe(ifp);
+	return 0;
+}
diff --git a/ipv6rs.h b/ipv6rs.h
new file mode 100644
index 0000000..ae18d3a
--- /dev/null
+++ b/ipv6rs.h
@@ -0,0 +1,40 @@
+/* 
+ * dhcpcd - DHCP client daemon
+ * Copyright (c) 2006-2011 Roy Marples <roy@marples.name>
+ * All rights reserved
+
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef IPV6RS_H
+#define IPV6RS_H
+
+#ifndef ICMP6_FILTER
+#define ICMP6_FILTER	1
+#endif
+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_free(struct interface *ifp);
+void ipv6rs_expire(void *arg);
+#endif
diff --git a/lpf.c b/lpf.c
index 2907d90..853d0a3 100644
--- a/lpf.c
+++ b/lpf.c
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2009 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2011 Roy Marples <roy@marples.name>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -36,7 +36,7 @@
 #ifdef __linux__
 # include <asm/types.h> /* needed for 2.4 kernels for the below header */
 # include <linux/filter.h>
-# include <netpacket/packet.h>
+# include <linux/if_packet.h>
 # define bpf_insn		sock_filter
 # define BPF_SKIPTYPE
 # define BPF_ETHCOOK		-ETH_HLEN
@@ -76,6 +76,9 @@
 	} su;
 	struct sock_fprog pf;
 	int *fd;
+#ifdef PACKET_AUXDATA
+	int n;
+#endif
 
 	if ((s = socket(PF_PACKET, SOCK_DGRAM, htons(protocol))) == -1)
 		return -1;
@@ -98,6 +101,13 @@
 	}
 	if (setsockopt(s, SOL_SOCKET, SO_ATTACH_FILTER, &pf, sizeof(pf)) != 0)
 		goto eexit;
+#ifdef PACKET_AUXDATA
+	n = 1;
+	if (setsockopt(s, SOL_PACKET, PACKET_AUXDATA, &n, sizeof(n)) != 0) {
+		if (errno != ENOPROTOOPT)
+			goto eexit;
+	}
+#endif
 	if (set_cloexec(s) == -1)
 		goto eexit;
 	if (set_nonblock(s) == -1)
@@ -152,17 +162,53 @@
 }
 
 ssize_t
-get_raw_packet(struct interface *iface, int protocol, void *data, ssize_t len)
+get_raw_packet(struct interface *iface, int protocol,
+    void *data, ssize_t len, int *partialcsum)
 {
+	struct iovec iov = {
+		.iov_base = data,
+		.iov_len = len,
+	};
+	struct msghdr msg = {
+		.msg_iov = &iov,
+		.msg_iovlen = 1,
+	};
+#ifdef PACKET_AUXDATA
+	unsigned char cmsgbuf[CMSG_LEN(sizeof(struct tpacket_auxdata))];
+	struct cmsghdr *cmsg;
+	struct tpacket_auxdata *aux;
+#endif
+
 	ssize_t bytes;
 	int fd = -1;
 
+#ifdef PACKET_AUXDATA
+	msg.msg_control = cmsgbuf;
+	msg.msg_controllen = sizeof(cmsgbuf);
+#endif
+
 	if (protocol == ETHERTYPE_ARP)
 		fd = iface->arp_fd;
 	else
 		fd = iface->raw_fd;
-	bytes = read(fd, data, len);
+	bytes = recvmsg(fd, &msg, 0);
 	if (bytes == -1)
 		return errno == EAGAIN ? 0 : -1;
+	if (partialcsum != NULL) {
+		*partialcsum = 0;
+#ifdef PACKET_AUXDATA
+		for (cmsg = CMSG_FIRSTHDR(&msg);
+		     cmsg;
+		     cmsg = CMSG_NXTHDR(&msg, cmsg))
+		{
+			if (cmsg->cmsg_level == SOL_PACKET &&
+			    cmsg->cmsg_type == PACKET_AUXDATA) {
+				aux = (void *)CMSG_DATA(cmsg);
+				*partialcsum = aux->tp_status &
+				    TP_STATUS_CSUMNOTREADY;
+			}
+		}
+#endif
+	}
 	return bytes;
 }
diff --git a/net.c b/net.c
index f3147d6..1a9780d 100644
--- a/net.c
+++ b/net.c
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2010 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2011 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -66,6 +66,7 @@
 #include "common.h"
 #include "dhcp.h"
 #include "if-options.h"
+#include "ipv6rs.h"
 #include "net.h"
 #include "signals.h"
 
@@ -73,6 +74,21 @@
 
 int socket_afnet = -1;
 
+#if defined(__FreeBSD__) && defined(DEBUG_MEMORY)
+/* FreeBSD does not zero the struct, causing valgrind errors */
+unsigned int
+if_nametoindex(const char *ifname)
+{
+	struct ifreq ifr;
+
+	memset(&ifr, 0, sizeof(ifr));
+	strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+	if (ioctl(socket_afnet, SIOCGIFINDEX, &ifr) != -1)
+		return ifr.ifr_index;
+	return 0;
+}
+#endif
+
 int
 inet_ntocidr(struct in_addr address)
 {
@@ -233,6 +249,7 @@
 {
 	if (!iface)
 		return;
+	ipv6rs_free(iface);
 	if (iface->state) {
 		free_options(iface->state->options);
 		free(iface->state->old);
@@ -240,6 +257,7 @@
 		free(iface->state->offer);
 		free(iface->state);
 	}
+	free(iface->buffer);
 	free(iface->clientid);
 	free(iface);
 }
@@ -315,7 +333,7 @@
 {
 	struct ifaddrs *ifaddrs, *ifa;
 	char *p;
-	int i;
+	int i, sdl_type;
 	struct interface *ifp, *ifs, *ifl;
 #ifdef __linux__
 	char ifn[IF_NAMESIZE];
@@ -409,6 +427,7 @@
 				syslog(LOG_ERR, "%s: up_interface: %m", ifp->name);
 		}
 
+		sdl_type = 0;
 		/* Don't allow loopback unless explicit */
 		if (ifp->flags & IFF_LOOPBACK) {
 			if (argc == 0 && ifac == 0) {
@@ -435,13 +454,22 @@
 			}
 #endif
 
+			sdl_type = sdl->sdl_type;
 			switch(sdl->sdl_type) {
+			case IFT_BRIDGE: /* FALLTHROUGH */
+			case IFT_L2VLAN: /* FALLTHOUGH */
+			case IFT_L3IPVLAN: /* FALLTHROUGH */
 			case IFT_ETHER:
 				ifp->family = ARPHRD_ETHER;
 				break;
 			case IFT_IEEE1394:
 				ifp->family = ARPHRD_IEEE1394;
 				break;
+#ifdef IFT_INFINIBAND
+			case IFT_INFINIBAND:
+				ifp->family = ARPHRD_INFINIBAND;
+				break;
+#endif
 			}
 			ifp->hwlen = sdl->sdl_alen;
 #ifndef CLLADDR
@@ -450,7 +478,7 @@
 			memcpy(ifp->hwaddr, CLLADDR(sdl), ifp->hwlen);
 #elif AF_PACKET
 			sll = (const struct sockaddr_ll *)(void *)ifa->ifa_addr;
-			ifp->family = sll->sll_hatype;
+			ifp->family = sdl_type = sll->sll_hatype;
 			ifp->hwlen = sll->sll_halen;
 			if (ifp->hwlen != 0)
 				memcpy(ifp->hwaddr, sll->sll_addr, ifp->hwlen);
@@ -472,7 +500,11 @@
 				break;
 			default:
 				syslog(LOG_WARNING,
-				    "%s: unknown hardware family", p);
+				    "%s: unsupported interface type %.2x"
+				    ", falling back to ethernet",
+				    ifp->name, sdl_type);
+				ifp->family = ARPHRD_ETHER;
+				break;
 			}
 		}
 
@@ -727,7 +759,8 @@
 }
 
 int
-valid_udp_packet(const uint8_t *data, size_t data_len, struct in_addr *from)
+valid_udp_packet(const uint8_t *data, size_t data_len, struct in_addr *from,
+    int noudpcsum)
 {
 	struct udp_dhcp_packet packet;
 	uint16_t bytes, udpsum;
@@ -755,19 +788,22 @@
 		errno = EINVAL;
 		return -1;
 	}
-	udpsum = packet.udp.uh_sum;
-	packet.udp.uh_sum = 0;
-	packet.ip.ip_hl = 0;
-	packet.ip.ip_v = 0;
-	packet.ip.ip_tos = 0;
-	packet.ip.ip_len = packet.udp.uh_ulen;
-	packet.ip.ip_id = 0;
-	packet.ip.ip_off = 0;
-	packet.ip.ip_ttl = 0;
-	packet.ip.ip_sum = 0;
-	if (udpsum && checksum(&packet, bytes) != udpsum) {
-		errno = EINVAL;
-		return -1;
+
+	if (noudpcsum == 0) {
+		udpsum = packet.udp.uh_sum;
+		packet.udp.uh_sum = 0;
+		packet.ip.ip_hl = 0;
+		packet.ip.ip_v = 0;
+		packet.ip.ip_tos = 0;
+		packet.ip.ip_len = packet.udp.uh_ulen;
+		packet.ip.ip_id = 0;
+		packet.ip.ip_off = 0;
+		packet.ip.ip_ttl = 0;
+		packet.ip.ip_sum = 0;
+		if (udpsum && checksum(&packet, bytes) != udpsum) {
+			errno = EINVAL;
+			return -1;
+		}
 	}
 
 	return 0;
diff --git a/net.h b/net.h
index 6d85930..f181798 100644
--- a/net.h
+++ b/net.h
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2010 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2011 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -84,6 +84,8 @@
 	struct in_addr net;
 	struct in_addr gate;
 	const struct interface *iface;
+	int metric;
+	struct in_addr src;
 	struct rt *next;
 };
 
@@ -122,16 +124,11 @@
 #define get_address(iface, addr, net, dst)				      \
 	do_address(iface, addr, net, dst, 1)
 
-int if_route(const struct interface *, const struct in_addr *,
-    const struct in_addr *, const struct in_addr *, int, int);
-#define add_route(iface, dest, mask, gate, metric)			      \
-	if_route(iface, dest, mask, gate, metric, 1)
-#define change_route(iface, dest, mask, gate, metric)			      \
-	if_route(iface, dest, mask, gate, metric, 0)
-#define del_route(iface, dest, mask, gate, metric)			      \
-	if_route(iface, dest, mask, gate, metric, -1)
-#define del_src_route(iface, dest, mask, gate, metric)			      \
-	if_route(iface, dest, mask, gate, metric, -2)
+int if_route(const struct rt *rt, int);
+#define add_route(rt) if_route(rt, 1)
+#define change_route(rt) if_route(rt, 0)
+#define del_route(rt) if_route(rt, -1)
+#define del_src_route(rt) if_route(rt, -2);
 void free_routes(struct rt *);
 
 int open_udp_socket(struct interface *);
@@ -139,14 +136,14 @@
 ssize_t make_udp_packet(uint8_t **, const uint8_t *, size_t,
     struct in_addr, struct in_addr);
 ssize_t get_udp_data(const uint8_t **, const uint8_t *);
-int valid_udp_packet(const uint8_t *, size_t, struct in_addr *);
+int valid_udp_packet(const uint8_t *, size_t, struct in_addr *, int);
 
 int open_socket(struct interface *, int);
 ssize_t send_packet(const struct interface *, struct in_addr, 
     const uint8_t *, ssize_t);
 ssize_t send_raw_packet(const struct interface *, int,
     const void *, ssize_t);
-ssize_t get_raw_packet(struct interface *, int, void *, ssize_t);
+ssize_t get_raw_packet(struct interface *, int, void *, ssize_t, int *);
 
 int init_sockets(void);
 int open_link_socket(void);
diff --git a/platform-bsd.c b/platform-bsd.c
index dd5791c..afa4384 100644
--- a/platform-bsd.c
+++ b/platform-bsd.c
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2010 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -26,8 +26,12 @@
  */
 
 #include <sys/param.h>
+#include <sys/socket.h>
 #include <sys/sysctl.h>
 #include <sys/utsname.h>
+#include <netinet/in.h>
+
+#include <syslog.h>
 
 #include "platform.h"
 
@@ -48,3 +52,38 @@
 		return NULL;
 	return march;
 }
+
+static int
+inet6_sysctl(int code)
+{
+	int mib[] = { CTL_NET, PF_INET6, IPPROTO_IPV6, 0 };
+	int val;
+	size_t size;
+
+	mib[3] = code;
+	size = sizeof(val);
+	if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &val, &size, NULL, 0) == -1)
+		return -1;
+	return val;
+}
+
+int
+check_ipv6(const char *ifname)
+{
+
+	/* BSD doesn't support these values per iface, so just reutrn 1 */
+	if (ifname)
+		return 1;
+
+	if (inet6_sysctl(IPV6CTL_ACCEPT_RTADV) != 1) {
+		syslog(LOG_WARNING,
+		    "Kernel is not configured to accept IPv6 RAs");
+		return 0;
+	}
+	if (inet6_sysctl(IPV6CTL_FORWARDING) != 0) {
+		syslog(LOG_WARNING,
+		    "Kernel is configured as a router, not a host");
+		return 0;
+	}
+	return 1;
+}
diff --git a/platform-linux.c b/platform-linux.c
index 79562c8..119ec50 100644
--- a/platform-linux.c
+++ b/platform-linux.c
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2010 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -27,7 +27,9 @@
 
 #include <errno.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
+#include <syslog.h>
 
 #include "common.h"
 #include "platform.h"
@@ -102,3 +104,50 @@
 		errno = ESRCH;
 	return p;
 }
+
+static int
+check_proc_int(const char *path)
+{
+	FILE *fp;
+	char *buf;
+
+	fp = fopen(path, "r");
+	if (fp == NULL)
+		return -1;
+	buf = get_line(fp);
+	fclose(fp);
+	if (buf == NULL)
+		return -1;
+	return atoi(buf);
+}
+
+static const char *prefix = "/proc/sys/net/ipv6/conf";
+
+int
+check_ipv6(const char *ifname)
+{
+	int r;
+	char path[256];
+
+	if (ifname == NULL)
+		ifname = "all";
+
+	snprintf(path, sizeof(path), "%s/%s/accept_ra", prefix, ifname);
+	r = check_proc_int(path);
+	if (r != 1 && r != 2) {
+		syslog(LOG_WARNING,
+		    "%s: not configured to accept IPv6 RAs", ifname);
+		return 0;
+	}
+
+	if (r != 2) {
+		snprintf(path, sizeof(path), "%s/%s/forwarding",
+		    prefix, ifname);
+		if (check_proc_int(path) != 0) {
+			syslog(LOG_WARNING,
+			    "%s: configured as a router, not a host", ifname);
+			return 0;
+		}
+	}
+	return 1;
+}
diff --git a/platform.h b/platform.h
index 24731ac..08ec368 100644
--- a/platform.h
+++ b/platform.h
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2010 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2012 Roy Marples <roy@marples.name>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -28,6 +28,7 @@
 #ifndef PLATFORM_H
 #define PLATFORM_H
 
-char * hardware_platform(void);
+char *hardware_platform(void);
+int check_ipv6(const char *);
 
 #endif