]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Simplify the logic of what to put in the message, and ensure that the MTU size is...
authorRoy Marples <roy@marples.name>
Mon, 6 Oct 2008 07:30:17 +0000 (07:30 +0000)
committerRoy Marples <roy@marples.name>
Mon, 6 Oct 2008 07:30:17 +0000 (07:30 +0000)
dhcp.c

diff --git a/dhcp.c b/dhcp.c
index 2658e89db457534e016f241e4a7a5dd00a85f7c1..bfa5f262abd2ffd4f6f8e8dbc81566674a342c4b 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -747,6 +747,13 @@ encode_rfc1035(const char *src, uint8_t *dst, size_t len)
        return p - dst;
 }
 
+#define PUTADDR(_type, _val) \
+{ \
+       *p++ = _type; \
+       *p++ = 4; \
+       memcpy(p, &_val.s_addr, 4); \
+       p += 4; \
+}
 ssize_t
 make_message(struct dhcp_message **message,
             const struct interface *iface,
@@ -808,7 +815,16 @@ make_message(struct dhcp_message **message,
        *p++ = 1;
        *p++ = type;
 
-       if (type == DHCP_REQUEST) {
+       if (iface->clientid) {
+               *p++ = DHO_CLIENTID;
+               memcpy(p, iface->clientid, iface->clientid[0] + 1);
+               p += iface->clientid[0] + 1;
+       }
+
+       if (type == DHCP_DISCOVER ||
+           type == DHCP_INFORM ||
+           type == DHCP_REQUEST)
+       {
                *p++ = DHO_MAXMESSAGESIZE;
                *p++ = 2;
                sz = get_mtu(iface->name);
@@ -819,15 +835,7 @@ make_message(struct dhcp_message **message,
                sz = htons(sz);
                memcpy(p, &sz, 2);
                p += 2;
-       }
 
-       if (iface->clientid) {
-               *p++ = DHO_CLIENTID;
-               memcpy(p, iface->clientid, iface->clientid[0] + 1);
-               p += iface->clientid[0] + 1;
-       }
-
-       if (type != DHCP_DECLINE && type != DHCP_RELEASE) {
                if (ifo->userclass[0]) {
                        *p++ = DHO_USERCLASS;
                        memcpy(p, ifo->userclass, ifo->userclass[0] + 1);
@@ -840,39 +848,27 @@ make_message(struct dhcp_message **message,
                               ifo->vendorclassid[0] + 1);
                        p += ifo->vendorclassid[0] + 1;
                }
-       }
 
-       if (type == DHCP_DISCOVER || type == DHCP_REQUEST) {
-#define PUTADDR(_type, _val) \
-               { \
-                       *p++ = _type; \
-                       *p++ = 4; \
-                       memcpy(p, &_val.s_addr, 4); \
-                       p += 4; \
-               }
-               if (lease->addr.s_addr &&
-                   lease->addr.s_addr != iface->addr.s_addr &&
-                   !IN_LINKLOCAL(ntohl(lease->addr.s_addr)))
-               {
-                       PUTADDR(DHO_IPADDRESS, lease->addr);
-                       if (lease->server.s_addr)
-                               PUTADDR(DHO_SERVERID, lease->server);
-               }
-#undef PUTADDR
 
-               if (ifo->leasetime != 0) {
-                       *p++ = DHO_LEASETIME;
-                       *p++ = 4;
-                       ul = htonl(ifo->leasetime);
-                       memcpy(p, &ul, 4);
-                       p += 4;
+               if (type != DHCP_INFORM) {
+                       if (lease->addr.s_addr &&
+                           lease->addr.s_addr != iface->addr.s_addr &&
+                           !IN_LINKLOCAL(ntohl(lease->addr.s_addr)))
+                       {
+                               PUTADDR(DHO_IPADDRESS, lease->addr);
+                               if (lease->server.s_addr)
+                                       PUTADDR(DHO_SERVERID, lease->server);
+                       }
+
+                       if (ifo->leasetime != 0) {
+                               *p++ = DHO_LEASETIME;
+                               *p++ = 4;
+                               ul = htonl(ifo->leasetime);
+                               memcpy(p, &ul, 4);
+                               p += 4;
+                       }
                }
-       }
 
-       if (type == DHCP_DISCOVER ||
-           type == DHCP_INFORM ||
-           type == DHCP_REQUEST)
-       {
                if (ifo->hostname[0]) {
                        *p++ = DHO_HOSTNAME;
                        memcpy(p, ifo->hostname, ifo->hostname[0] + 1);
@@ -917,11 +913,11 @@ make_message(struct dhcp_message **message,
                              has_option_mask(ifo->requestmask, opt->option)))
                                continue;
                        switch (opt->option) {
-                       case DHO_RENEWALTIME:   /* FALLTHROUGH */
-                       case DHO_REBINDTIME:
-                               if (type == DHCP_INFORM)
-                                       continue;
-                               break;
+                               case DHO_RENEWALTIME:   /* FALLTHROUGH */
+                               case DHO_REBINDTIME:
+                                       if (type == DHCP_INFORM)
+                                               continue;
+                                       break;
                        }
                        *p++ = opt->option;
                }