]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
Fix DHCPRELEASE handling to conform to spec
authorTed Lemon <source@isc.org>
Sat, 29 Nov 1997 07:57:02 +0000 (07:57 +0000)
committerTed Lemon <source@isc.org>
Sat, 29 Nov 1997 07:57:02 +0000 (07:57 +0000)
server/dhcp.c

index 7efd3ddf015f28f68d2fe9d5053e77c9fd844f8e..4a584ce75820e1e61e217742717ccab7a969e2ec 100644 (file)
@@ -42,7 +42,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: dhcp.c,v 1.52 1997/10/20 22:28:18 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: dhcp.c,v 1.53 1997/11/29 07:57:02 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -297,26 +297,44 @@ void dhcprelease (packet)
 {
        struct lease *lease;
        struct iaddr cip;
+       int i;
 
-       /* DHCPRELEASEmust specify address. */
-       if (!packet -> options [DHO_DHCP_REQUESTED_ADDRESS].len) {
-               return;
+       /* DHCPRELEASE must not specify address in requested-address
+           option, but old protocol specs weren't explicit about this,
+           so let it go. */
+       if (packet -> options [DHO_DHCP_REQUESTED_ADDRESS].len) {
+               note ("DHCPRELEASE from %s specified requested-address.",
+                     print_hw_addr (packet -> raw -> htype,
+                                    packet -> raw -> hlen,
+                                    packet -> raw -> chaddr));
        }
 
-       cip.len = 4;
-       memcpy (cip.iabuf,
-               packet -> options [DHO_DHCP_REQUESTED_ADDRESS].data, 4);
-       lease = find_lease_by_ip_addr (cip);
+       i = DHO_DHCP_CLIENT_IDENTIFIER;
+       if (packet -> options [i].len) {
+               lease = find_lease_by_uid (packet -> options [i].data,
+                                          packet -> options [i].len);
+       } else
+               lease = (struct lease *)0;
 
-       note ("DHCPRELEASE of %s from %s via %s",
+       /* The client is supposed to pass a valid client-identifier,
+          but the spec on this has changed historically, so try the
+          IP address in ciaddr if the client-identifier fails. */
+       if (!lease) {
+               cip.len = 4;
+               memcpy (cip.iabuf, &packet -> raw -> ciaddr, 4);
+               lease = find_lease_by_ip_addr (cip);
+       }
+
+
+       note ("DHCPRELEASE of %s from %s via %s (%sfound)",
              inet_ntoa (packet -> raw -> ciaddr),
              print_hw_addr (packet -> raw -> htype,
                             packet -> raw -> hlen,
                             packet -> raw -> chaddr),
              packet -> raw -> giaddr.s_addr
              ? inet_ntoa (packet -> raw -> giaddr)
-             : packet -> interface -> name);
-
+             : packet -> interface -> name,
+             lease ? "" : "not ");
 
        /* If we found a lease, release it. */
        if (lease) {