]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Explain why we decline the address in a message.
authorRoy Marples <roy@marples.name>
Tue, 28 Oct 2008 09:24:23 +0000 (09:24 +0000)
committerRoy Marples <roy@marples.name>
Tue, 28 Oct 2008 09:24:23 +0000 (09:24 +0000)
dhcp.c

diff --git a/dhcp.c b/dhcp.c
index bdcc04eafd26c122b2dd93c728d05dbf8ab33917..4c30dfca39835cdf95058364fabd0aee1b736893 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -53,6 +53,8 @@
 
 #define IPV4R  IPV4 | REQUEST
 
+#define DAD    "Duplicate address detected"
+
 /* Our aggregate option buffer.
  * We ONLY use this when options are split, which for most purposes is
  * practically never. See RFC3396 for details. */
@@ -760,6 +762,7 @@ make_message(struct dhcp_message **message,
        time_t up = uptime() - iface->start_uptime;
        uint32_t ul;
        uint16_t sz;
+       size_t len;
        const struct dhcp_opt *opt;
        const struct if_options *ifo = iface->state->options;
        const struct dhcp_lease *lease = &iface->state->lease;
@@ -794,15 +797,18 @@ make_message(struct dhcp_message **message,
        case ARPHRD_IEEE1394:
        case ARPHRD_INFINIBAND:
                dhcp->hwlen = 0;
-               if (dhcp->ciaddr == 0)
+               if (dhcp->ciaddr == 0 &&
+                   type != DHCP_DECLINE && type != DHCP_RELEASE)
                        dhcp->flags = htons(BROADCAST_FLAG);
                break;
        }
 
-       if (up < 0 || up > (time_t)UINT16_MAX)
-               dhcp->secs = htons((uint16_t)UINT16_MAX);
-       else
-               dhcp->secs = htons(up);
+       if (type != DHCP_DECLINE && type != DHCP_RELEASE) {
+               if (up < 0 || up > (time_t)UINT16_MAX)
+                       dhcp->secs = htons((uint16_t)UINT16_MAX);
+               else
+                       dhcp->secs = htons(up);
+       }
        dhcp->xid = iface->state->xid;
        dhcp->cookie = htonl(MAGIC_COOKIE);
 
@@ -833,6 +839,14 @@ make_message(struct dhcp_message **message,
                }
        }
 
+       if (type == DHCP_DECLINE) {
+               *p++ = DHO_MESSAGE;
+               len = strlen(DAD);
+               *p++ = len;
+               memcpy(p, DAD, len);
+               p += len;
+       }
+
        if (type == DHCP_DISCOVER ||
            type == DHCP_INFORM ||
            type == DHCP_REQUEST)