DHCPv4: send DHCPNAK if requested addr != leased addr
authorSteven Barth <steven@midlink.org>
Tue, 1 Jul 2014 08:05:30 +0000 (10:05 +0200)
committerSteven Barth <steven@midlink.org>
Tue, 1 Jul 2014 08:06:08 +0000 (10:06 +0200)
src/dhcpv4.c

index 1fac8a1ccf53748775b479211f046e9dcb880f6a..b8d64ceaf7358c60bba1a6e3feaef6df90ecbfb3 100644 (file)
@@ -331,6 +331,10 @@ static void handle_dhcpv4(void *addr, void *data, size_t len,
                        return;
        } else if (reqmsg == DHCPV4_MSG_DISCOVER) {
                msg = DHCPV4_MSG_OFFER;
+       } else if (reqmsg == DHCPV4_MSG_REQUEST && reqaddr.s_addr &&
+                       reqaddr.s_addr != htonl(lease->addr)) {
+               msg = DHCPV4_MSG_NAK;
+               lease = NULL;
        }
 
        if (reqmsg == DHCPV4_MSG_DECLINE || reqmsg == DHCPV4_MSG_RELEASE)
@@ -401,7 +405,7 @@ static void handle_dhcpv4(void *addr, void *data, size_t len,
                dest.sin_addr = req->ciaddr;
                dest.sin_port = htons(DHCPV4_CLIENT_PORT);
        } else if ((ntohs(req->flags) & DHCPV4_FLAG_BROADCAST) ||
-                       req->hlen != reply.hlen) {
+                       req->hlen != reply.hlen || !reply.yiaddr.s_addr) {
                dest.sin_addr.s_addr = INADDR_BROADCAST;
                dest.sin_port = htons(DHCPV4_CLIENT_PORT);
        } else {