.chaddr = { 0 },
.sname = { 0 },
.file = { 0 },
- .options = { DHCPV4_MAGIC_COOKIE },
+ .cookie = htonl(DHCPV4_MAGIC_COOKIE),
};
struct dhcpv4_auth_forcerenew *auth_o, auth = {
.protocol = DHCPV4_AUTH_PROTO_RKAP,
.key = { 0 },
};
struct interface *iface = a->iface;
- uint8_t *cursor = &fr_msg.options[DHCPV4_MAGIC_COOKIE_LEN];
+ uint8_t *cursor = fr_msg.options;
uint8_t msg = DHCPV4_MSG_FORCERENEW;
struct sockaddr_in dest = {
.sin_family = AF_INET,
if (iface->dhcpv4 == MODE_DISABLED)
return;
- if (len < offsetof(struct dhcpv4_message, options) + 4 ||
- req->op != DHCPV4_OP_BOOTREQUEST || req->hlen != ETH_ALEN)
+ /* FIXME: would checking the magic cookie value here break any clients? */
+
+ if (len < offsetof(struct dhcpv4_message, options) ||
+ req->op != DHCPV4_OP_BOOTREQUEST || req->hlen != ETH_ALEN)
return;
syslog(LOG_DEBUG, "Got DHCPv4 request on %s", iface->name);
.ciaddr = { INADDR_ANY },
.giaddr = req->giaddr,
.siaddr = iface->dhcpv4_local,
- .options = { DHCPV4_MAGIC_COOKIE },
+ .cookie = htonl(DHCPV4_MAGIC_COOKIE),
};
memcpy(reply.chaddr, req->chaddr, sizeof(reply.chaddr));
- uint8_t *cursor = &reply.options[DHCPV4_MAGIC_COOKIE_LEN];
+ uint8_t *cursor = reply.options;
uint8_t reqmsg = DHCPV4_MSG_REQUEST;
uint8_t msg = DHCPV4_MSG_ACK;
bool accept_fr_nonce = false;
bool incl_fr_opt = false;
- uint8_t *start = &req->options[4];
- uint8_t *end = ((uint8_t*)data) + len;
+ uint8_t *start = req->options;
+ uint8_t *end = ((uint8_t *)data) + len;
struct dhcpv4_option *opt;
+
dhcpv4_for_each_option(start, end, opt) {
if (opt->type == DHCPV4_OPT_MESSAGE && opt->len == 1)
reqmsg = opt->data[0];
odhcpd_print_mac(req->chaddr, req->hlen), iface->name);
#ifdef WITH_UBUS
- if (reqmsg == DHCPV4_MSG_RELEASE)
+ if (reqmsg == DHCPV4_MSG_RELEASE) {
+ struct in_addr ciaddr = req->ciaddr; // ensure pointer alignment
ubus_bcast_dhcp_event("dhcp.release", req->chaddr, req->hlen,
- &req->ciaddr, a ? a->hostname : NULL, iface->ifname);
+ &ciaddr, a ? a->hostname : NULL, iface->ifname);
+ }
#endif
+
if (reqmsg == DHCPV4_MSG_DECLINE || reqmsg == DHCPV4_MSG_RELEASE)
return;
"ff:ff:ff:ff:ff:ff": odhcpd_print_mac(req->chaddr, req->hlen),
inet_ntoa(dest.sin_addr));
-
#ifdef WITH_UBUS
- if (msg == DHCPV4_MSG_ACK)
- ubus_bcast_dhcp_event("dhcp.ack", req->chaddr, req->hlen, &reply.yiaddr,
+ if (msg == DHCPV4_MSG_ACK) {
+ struct in_addr yiaddr = reply.yiaddr; // ensure pointer alignment
+ ubus_bcast_dhcp_event("dhcp.ack", req->chaddr, req->hlen, &yiaddr,
a ? a->hostname : NULL, iface->ifname);
+ }
#endif
}