summaryrefslogtreecommitdiffstats
path: root/dhcp.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-10-06 07:30:17 +0000
committerRoy Marples <roy@marples.name>2008-10-06 07:30:17 +0000
commit7dc5bd24b9c334b9ec495976e17fb4f0a0da235c (patch)
tree129de2df06c99958087875ff04ee502bc62e9edc /dhcp.c
parent764eb12abd25802e1f1d072c53076a8a8fe47018 (diff)
downloaddhcpcd-7dc5bd24b9c334b9ec495976e17fb4f0a0da235c.tar.xz
Simplify the logic of what to put in the message, and ensure that the MTU size is in the DISCOVER message.
Diffstat (limited to 'dhcp.c')
-rw-r--r--dhcp.c82
1 files changed, 39 insertions, 43 deletions
diff --git a/dhcp.c b/dhcp.c
index 2658e89d..bfa5f262 100644
--- 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;
}