From fa97acc108b8cd7a00b9b692991d5f6fb608630e Mon Sep 17 00:00:00 2001 From: Ted Lemon Date: Sun, 8 Jun 1997 03:55:58 +0000 Subject: [PATCH] If the lease we want to give the client is different than the one it's asking for, and we recognize the one it's asking for as ours, NAK it. --- CHANGES | 3 +++ includes/dhcpd.h | 3 ++- server/dhcp.c | 50 +++++++++++++++++++++++++++++++++++------------- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/CHANGES b/CHANGES index cff17ea91..95e48214f 100644 --- 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. diff --git a/includes/dhcpd.h b/includes/dhcpd.h index ad84130c2..3b708800a 100644 --- a/includes/dhcpd.h +++ b/includes/dhcpd.h @@ -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 *)); diff --git a/server/dhcp.c b/server/dhcp.c index 7823637b7..78c28469f 100644 --- a/server/dhcp.c +++ b/server/dhcp.c @@ -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 || -- 2.47.3