X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fodhcpd.git;a=blobdiff_plain;f=src%2Fdhcpv4.c;h=0d7573011dba88379548ac4ab5bcfa223422b516;hp=b8d64ceaf7358c60bba1a6e3feaef6df90ecbfb3;hb=428908569b8da45613891e21736c587894e0c449;hpb=4267915aef64aae345972c77148b11759a172b14 diff --git a/src/dhcpv4.c b/src/dhcpv4.c index b8d64ce..0d75730 100644 --- a/src/dhcpv4.c +++ b/src/dhcpv4.c @@ -34,7 +34,7 @@ static void handle_dhcpv4(void *addr, void *data, size_t len, - struct interface *iface); + struct interface *iface, void *dest_addr); static struct dhcpv4_assignment* dhcpv4_lease(struct interface *iface, enum dhcpv4_msg msg, const uint8_t *mac, struct in_addr reqaddr, const char *hostname); @@ -225,7 +225,7 @@ static void dhcpv4_put(struct dhcpv4_message *msg, uint8_t **cookie, // Simple DHCPv6-server for information requests static void handle_dhcpv4(void *addr, void *data, size_t len, - struct interface *iface) + struct interface *iface, _unused void *dest_addr) { if (!iface->dhcpv4) return; @@ -334,7 +334,16 @@ static void handle_dhcpv4(void *addr, void *data, size_t len, } else if (reqmsg == DHCPV4_MSG_REQUEST && reqaddr.s_addr && reqaddr.s_addr != htonl(lease->addr)) { msg = DHCPV4_MSG_NAK; - lease = NULL; + /* + * DHCP client requested an IP which we can't offer to him. Probably the + * client changed the network. The reply type is set to DHCPV4_MSG_NAK, + * because the client should not use that IP. + * + * For modern devices we build an answer that includes a valid IP, like + * a DHCPV4_MSG_ACK. The client will use that IP and doesn't need to + * perform additional DHCP round trips. + * + */ } if (reqmsg == DHCPV4_MSG_DECLINE || reqmsg == DHCPV4_MSG_RELEASE) @@ -491,7 +500,6 @@ static struct dhcpv4_assignment* dhcpv4_lease(struct interface *iface, } } - bool update_state = false; if (msg == DHCPV4_MSG_DISCOVER || msg == DHCPV4_MSG_REQUEST) { bool assigned = !!a; size_t hostlen = strlen(hostname) + 1; @@ -530,24 +538,18 @@ static struct dhcpv4_assignment* dhcpv4_lease(struct interface *iface, a = NULL; } - if (a) - update_state = true; - if (assigned && a) lease = a; } else if (msg == DHCPV4_MSG_RELEASE) { if (a) { a->valid_until = 0; - update_state = true; } } else if (msg == DHCPV4_MSG_DECLINE) { memset(a->hwaddr, 0, sizeof(a->hwaddr)); a->valid_until = now + 3600; // Block address for 1h - update_state = true; } - if (update_state) - dhcpv6_write_statefile(); + dhcpv6_write_statefile(); return lease; }