changeset 2270:ac944f101beb draft

Add support for DHCP auto configuration, RFC 2563.
author Roy Marples <roy@marples.name>
date Fri, 31 Jan 2014 22:15:50 +0000
parents 43c72364c4b7
children 3f402daf273e
files dhcp.c dhcp.h dhcpcd-definitions.conf dhcpcd.8.in
diffstat 4 files changed, 56 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/dhcp.c	Fri Jan 31 18:33:11 2014 +0000
+++ b/dhcp.c	Fri Jan 31 22:15:50 2014 +0000
@@ -777,6 +777,13 @@
 	if (type == DHCP_DISCOVER && ifo->options & DHCPCD_REQUEST)
 		PUTADDR(DHO_IPADDRESS, ifo->req_addr);
 
+	/* RFC 2563 Auto Configure */
+	if (type == DHCP_DISCOVER && ifo->options & DHCPCD_IPV4LL) {
+		*p++ = DHO_AUTOCONFIGURE;
+		*p++ = 1;
+		*p++ = 1;
+	}
+
 	if (type == DHCP_DISCOVER ||
 	    type == DHCP_INFORM ||
 	    type == DHCP_REQUEST)
@@ -2147,6 +2154,7 @@
 	struct in_addr addr;
 	size_t i;
 	int auth_len;
+	char *msg;
 
 	/* We may have found a BOOTP server */
 	if (get_option_uint8(&type, dhcp, DHO_MESSAGETYPE) == -1)
@@ -2236,6 +2244,11 @@
 
 		/* We should restart on a NAK */
 		log_dhcp(LOG_WARNING, "NAK:", iface, dhcp, from);
+		if ((msg = get_option_string(dhcp, DHO_MESSAGE))) {
+			syslog(LOG_WARNING, "%s: message: %s",
+			    iface->name, msg);
+			free(msg);
+		}
 		if (!(options & DHCPCD_TEST)) {
 			dhcp_drop(iface, "NAK");
 			unlink(state->leasefile);
@@ -2253,6 +2266,40 @@
 		return;
 	}
 
+	/* DHCP Auto-Configure, RFC 2563 */
+	if (type == DHCP_OFFER && dhcp->yiaddr == 0) {
+		log_dhcp(LOG_WARNING, "no address given", iface, dhcp, from);
+		if ((msg = get_option_string(dhcp, DHO_MESSAGE))) {
+			syslog(LOG_WARNING, "%s: message: %s",
+			    iface->name, msg);
+			free(msg);
+		}
+		if (get_option_uint8(&tmp, dhcp, DHO_AUTOCONFIGURE) != 0) {
+			switch (tmp) {
+			case 0:
+				log_dhcp(LOG_WARNING, "IPv4LL disabled from",
+				    iface, dhcp, from);
+				dhcp_close(iface);
+				eloop_timeout_delete(NULL, iface);
+				eloop_timeout_add_sec(DHCP_MAX, dhcp_discover,
+				    iface);
+				break;
+			case 1:
+				log_dhcp(LOG_WARNING, "IPv4LL enabled from",
+				    iface, dhcp, from);
+				eloop_timeout_delete(NULL, iface);
+				ipv4ll_start(iface);
+				break;
+			default:
+				syslog(LOG_ERR,
+				    "%s: unknown auto configuration option %d",
+				    iface->name, tmp);
+				break;
+			}
+		}
+		return;
+	}
+
 	/* Ensure that all required options are present */
 	for (i = 1; i < 255; i++) {
 		if (has_option_mask(ifo->requiremask, i) &&
--- a/dhcp.h	Fri Jan 31 18:33:11 2014 +0000
+++ b/dhcp.h	Fri Jan 31 22:15:50 2014 +0000
@@ -108,6 +108,7 @@
 	DHO_RAPIDCOMMIT            = 80,  /* RFC 4039 */
 	DHO_FQDN                   = 81,
 	DHO_AUTHENTICATION         = 90,  /* RFC 3118 */
+	DHO_AUTOCONFIGURE          = 116, /* RFC 2563 */
 	DHO_DNSSEARCH              = 119, /* RFC 3397 */
 	DHO_CSR                    = 121, /* RFC 3442 */
 	DHO_VIVCO                  = 124, /* RFC 3925 */
--- a/dhcpcd-definitions.conf	Fri Jan 31 18:33:11 2014 +0000
+++ b/dhcpcd-definitions.conf	Fri Jan 31 22:15:50 2014 +0000
@@ -130,6 +130,9 @@
 define 100	string			posix_timezone
 define 101	string			tzdb_timezone
 
+# DHCP Auto-Configuration, RFC2563
+define 116	byte			auto_configure
+
 # DHCP Subnet Selection, RFC3011
 define 118	ipaddress		subnet_selection
 
--- a/dhcpcd.8.in	Fri Jan 31 18:33:11 2014 +0000
+++ b/dhcpcd.8.in	Fri Jan 31 22:15:50 2014 +0000
@@ -652,11 +652,11 @@
 .Xr dhcpcd-run-hooks 8 ,
 .Xr resolvconf 8
 .Sh STANDARDS
-RFC\ 951, RFC\ 1534, RFC\ 2104, RFC\ 2131, RFC\ 2132, RFC\ 2855, RFC\ 3004,
-RFC\ 3118, RFC\ 3203, RFC\ 3315, RFC\ 3361, RFC\ 3633, RFC\ 3396, RFC\ 3397,
-RFC\ 3442, RFC\ 3495, RFC\ 3925, RFC\ 3927, RFC\ 4039, RFC\ 4075, RFC\ 4242,
-RFC\ 4361, RFC\ 4390, RFC\ 4702, RFC\ 4074, RFC\ 4861, RFC\ 4833, RFC\ 5227,
-RFC\ 5942, RFC\ 5969, RFC\ 6106, RFC\ 6334, RFC\ 6704.
+RFC\ 951, RFC\ 1534, RFC\ 2104, RFC\ 2131, RFC\ 2132, RFC\ 2563, RFC\ 2855, 
+RFC\ 3004, RFC\ 3118, RFC\ 3203, RFC\ 3315, RFC\ 3361, RFC\ 3633, RFC\ 3396,
+RFC\ 3397, RFC\ 3442, RFC\ 3495, RFC\ 3925, RFC\ 3927, RFC\ 4039, RFC\ 4075,
+RFC\ 4242, RFC\ 4361, RFC\ 4390, RFC\ 4702, RFC\ 4074, RFC\ 4861, RFC\ 4833,
+RFC\ 5227, RFC\ 5942, RFC\ 5969, RFC\ 6106, RFC\ 6334, RFC\ 6704.
 .Sh AUTHORS
 .An Roy Marples Aq Mt roy@marples.name
 .Sh BUGS