]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
If the lease we want to give the client is different than the one it's asking for...
authorTed Lemon <source@isc.org>
Sun, 8 Jun 1997 03:55:58 +0000 (03:55 +0000)
committerTed Lemon <source@isc.org>
Sun, 8 Jun 1997 03:55:58 +0000 (03:55 +0000)
CHANGES
includes/dhcpd.h
server/dhcp.c

diff --git a/CHANGES b/CHANGES
index cff17ea919623e69404c5c8f1a152f806a12e340..95e48214fe64c7b2e08870c03c7258f47eb2d200 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -5,6 +5,9 @@
 
 - Always write out two digits for single-byte quantities in arrays.
 
+- When parsing a lease database, correctly transfer the client
+  hostname and hostname to the memory-resident lease structure.
+
 970605
 
 - Add client-hostname token to lexer so that the parser can use it.
index ad84130c2037aa6481f9b8b4a4fd73171f931d5e..3b708800af615a27421f0fdb4db073edfc5d2542 100644 (file)
@@ -547,7 +547,8 @@ void dhcpinform PROTO ((struct packet *));
 void nak_lease PROTO ((struct packet *, struct iaddr *cip));
 void ack_lease PROTO ((struct packet *, struct lease *, unsigned char, TIME));
 void dhcp_reply PROTO ((struct lease *));
-struct lease *find_lease PROTO ((struct packet *, struct shared_network *));
+struct lease *find_lease PROTO ((struct packet *,
+                                struct shared_network *, int *));
 struct lease *mockup_lease PROTO ((struct packet *,
                                   struct shared_network *,
                                   struct host_decl *));
index 7823637b7a02786195bcdc3871756112b9750f37..78c28469faf82d6be8218d406fd1e85772281796 100644 (file)
@@ -42,7 +42,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: dhcp.c,v 1.47 1997/05/09 08:27:14 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: dhcp.c,v 1.48 1997/06/08 03:55:58 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -86,7 +86,7 @@ void dhcp (packet)
 void dhcpdiscover (packet)
        struct packet *packet;
 {
-       struct lease *lease = find_lease (packet, packet -> shared_network);
+       struct lease *lease = find_lease (packet, packet -> shared_network, 0);
        struct host_decl *hp;
 
        note ("DHCPDISCOVER from %s via %s",
@@ -164,6 +164,7 @@ void dhcprequest (packet)
        struct lease *lease;
        struct iaddr cip;
        struct subnet *subnet;
+       int ours = 0;
 
        if (packet -> options [DHO_DHCP_REQUESTED_ADDRESS].len) {
                cip.len = 4;
@@ -180,7 +181,7 @@ void dhcprequest (packet)
           client. */
 
        if (subnet)
-               lease = find_lease (packet, subnet -> shared_network);
+               lease = find_lease (packet, subnet -> shared_network, &ours);
        else
                lease = (struct lease *)0;
 
@@ -265,6 +266,11 @@ void dhcprequest (packet)
           client asked for, don't send it - some other server probably
           made the cut. */
        if (lease && !addr_eq (lease -> ip_addr, cip)) {
+               /* If we found the address the client asked for, but
+                   it wasn't what got picked, the lease belongs to us,
+                   so we can tenuously justify NAKing it. */
+               if (ours)
+                       nak_lease (packet, &cip);
                return;
        }
 
@@ -289,7 +295,17 @@ void dhcprequest (packet)
 void dhcprelease (packet)
        struct packet *packet;
 {
-       struct lease *lease = find_lease (packet, packet -> shared_network);
+       struct lease *lease;
+
+       /* DHCPRELEASEmust specify address. */
+       if (!packet -> options [DHO_DHCP_REQUESTED_ADDRESS].len) {
+               return;
+       }
+
+       cip.len = 4;
+       memcpy (cip.iabuf,
+               packet -> options [DHO_DHCP_REQUESTED_ADDRESS].data, 4);
+       lease = find_lease_by_ip_addr (cip);
 
        note ("DHCPRELEASE of %s from %s via %s",
              inet_ntoa (packet -> raw -> ciaddr),
@@ -310,18 +326,19 @@ void dhcprelease (packet)
 void dhcpdecline (packet)
        struct packet *packet;
 {
-       struct lease *lease = find_lease (packet, packet -> shared_network);
+       struct lease *lease;
        struct iaddr cip;
 
-       if (packet -> options [DHO_DHCP_REQUESTED_ADDRESS].len) {
-               cip.len = 4;
-               memcpy (cip.iabuf,
-                       packet -> options [DHO_DHCP_REQUESTED_ADDRESS].data,
-                       4);
-       } else {
-               cip.len = 0;
+       /* DHCPDECLINE must specify address. */
+       if (!packet -> options [DHO_DHCP_REQUESTED_ADDRESS].len) {
+               return;
        }
 
+       cip.len = 4;
+       memcpy (cip.iabuf,
+               packet -> options [DHO_DHCP_REQUESTED_ADDRESS].data, 4);
+       lease = find_lease_by_ip_addr (cip);
+
        note ("DHCPDECLINE on %s from %s via %s",
              piaddr (cip),
              print_hw_addr (packet -> raw -> htype,
@@ -1056,9 +1073,10 @@ void dhcp_reply (lease)
        lease -> state = (struct lease_state *)0;
 }
 
-struct lease *find_lease (packet, share)
+struct lease *find_lease (packet, share, ours)
        struct packet *packet;
        struct shared_network *share;
+       int *ours;
 {
        struct lease *uid_lease, *ip_lease, *hw_lease;
        struct lease *lease = (struct lease *)0;
@@ -1140,6 +1158,12 @@ struct lease *find_lease (packet, share)
        } else
                ip_lease = (struct lease *)0;
 
+       /* If ip_lease is valid at this point, set ours to one, so that
+          even if we choose a different lease, we know that the address
+          the client was requesting was ours, and thus we can NAK it. */
+       if (ip_lease)
+               *ours = 1;
+
        /* If the requested IP address isn't on the network the packet
           came from, or if it's been abandoned, don't use it. */
        if (ip_lease && (ip_lease -> shared_network != share ||