]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Add support for DHCP auto configuration, RFC 2563.
authorRoy Marples <roy@marples.name>
Fri, 31 Jan 2014 22:15:50 +0000 (22:15 +0000)
committerRoy Marples <roy@marples.name>
Fri, 31 Jan 2014 22:15:50 +0000 (22:15 +0000)
dhcp.c
dhcp.h
dhcpcd-definitions.conf
dhcpcd.8.in

diff --git a/dhcp.c b/dhcp.c
index 280a676fea99a91d1a5ccec636b3055e22be77d9..bc56a00f5badd1126c8e64448a86adfb98fa699f 100644 (file)
--- 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 2b83714405c659890471a5f458756443128e9eca..68f1e678794d16ea87a8e9155f5fca91a6a5f3a0 100644 (file)
--- 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 */
index f9a61d8d902fc0fcac5ce60c73f594c685eeff0d..4fe093c08d9e9d1ad4f491e3fa787471ceb53f35 100644 (file)
@@ -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
 
index 4723c1743bc33210963b2f3eba80f8b88206de32..ad2dcaff94bb4f262f4cd649d69eb716755083b1 100644 (file)
@@ -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