From: Roy Marples Date: Fri, 31 Jan 2014 22:15:50 +0000 (+0000) Subject: Add support for DHCP auto configuration, RFC 2563. X-Git-Tag: v6.3.0~63 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e575a2b43b521602f8872b22970611748f6caf48;p=thirdparty%2Fdhcpcd.git Add support for DHCP auto configuration, RFC 2563. --- diff --git a/dhcp.c b/dhcp.c index 280a676f..bc56a00f 100644 --- a/dhcp.c +++ b/dhcp.c @@ -777,6 +777,13 @@ make_message(struct dhcp_message **message, 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 @@ dhcp_handledhcp(struct interface *iface, struct dhcp_message **dhcpp, 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 @@ dhcp_handledhcp(struct interface *iface, struct dhcp_message **dhcpp, /* 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 @@ dhcp_handledhcp(struct interface *iface, struct dhcp_message **dhcpp, 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) && diff --git a/dhcp.h b/dhcp.h index 2b837144..68f1e678 100644 --- a/dhcp.h +++ b/dhcp.h @@ -108,6 +108,7 @@ enum DHO { 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 */ diff --git a/dhcpcd-definitions.conf b/dhcpcd-definitions.conf index f9a61d8d..4fe093c0 100644 --- a/dhcpcd-definitions.conf +++ b/dhcpcd-definitions.conf @@ -130,6 +130,9 @@ define 98 string uap_servers 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 diff --git a/dhcpcd.8.in b/dhcpcd.8.in index 4723c174..ad2dcaff 100644 --- a/dhcpcd.8.in +++ b/dhcpcd.8.in @@ -652,11 +652,11 @@ running on the .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