mirror of
https://gitlab.isc.org/isc-projects/dhcp
synced 2025-09-02 07:15:44 +00:00
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.
This commit is contained in:
3
CHANGES
3
CHANGES
@@ -5,6 +5,9 @@
|
|||||||
|
|
||||||
- Always write out two digits for single-byte quantities in arrays.
|
- 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
|
970605
|
||||||
|
|
||||||
- Add client-hostname token to lexer so that the parser can use it.
|
- Add client-hostname token to lexer so that the parser can use it.
|
||||||
|
@@ -547,7 +547,8 @@ void dhcpinform PROTO ((struct packet *));
|
|||||||
void nak_lease PROTO ((struct packet *, struct iaddr *cip));
|
void nak_lease PROTO ((struct packet *, struct iaddr *cip));
|
||||||
void ack_lease PROTO ((struct packet *, struct lease *, unsigned char, TIME));
|
void ack_lease PROTO ((struct packet *, struct lease *, unsigned char, TIME));
|
||||||
void dhcp_reply PROTO ((struct lease *));
|
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 lease *mockup_lease PROTO ((struct packet *,
|
||||||
struct shared_network *,
|
struct shared_network *,
|
||||||
struct host_decl *));
|
struct host_decl *));
|
||||||
|
@@ -42,7 +42,7 @@
|
|||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char copyright[] =
|
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 */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include "dhcpd.h"
|
#include "dhcpd.h"
|
||||||
@@ -86,7 +86,7 @@ void dhcp (packet)
|
|||||||
void dhcpdiscover (packet)
|
void dhcpdiscover (packet)
|
||||||
struct packet *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;
|
struct host_decl *hp;
|
||||||
|
|
||||||
note ("DHCPDISCOVER from %s via %s",
|
note ("DHCPDISCOVER from %s via %s",
|
||||||
@@ -164,6 +164,7 @@ void dhcprequest (packet)
|
|||||||
struct lease *lease;
|
struct lease *lease;
|
||||||
struct iaddr cip;
|
struct iaddr cip;
|
||||||
struct subnet *subnet;
|
struct subnet *subnet;
|
||||||
|
int ours = 0;
|
||||||
|
|
||||||
if (packet -> options [DHO_DHCP_REQUESTED_ADDRESS].len) {
|
if (packet -> options [DHO_DHCP_REQUESTED_ADDRESS].len) {
|
||||||
cip.len = 4;
|
cip.len = 4;
|
||||||
@@ -180,7 +181,7 @@ void dhcprequest (packet)
|
|||||||
client. */
|
client. */
|
||||||
|
|
||||||
if (subnet)
|
if (subnet)
|
||||||
lease = find_lease (packet, subnet -> shared_network);
|
lease = find_lease (packet, subnet -> shared_network, &ours);
|
||||||
else
|
else
|
||||||
lease = (struct lease *)0;
|
lease = (struct lease *)0;
|
||||||
|
|
||||||
@@ -265,6 +266,11 @@ void dhcprequest (packet)
|
|||||||
client asked for, don't send it - some other server probably
|
client asked for, don't send it - some other server probably
|
||||||
made the cut. */
|
made the cut. */
|
||||||
if (lease && !addr_eq (lease -> ip_addr, cip)) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,7 +295,17 @@ void dhcprequest (packet)
|
|||||||
void dhcprelease (packet)
|
void dhcprelease (packet)
|
||||||
struct packet *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",
|
note ("DHCPRELEASE of %s from %s via %s",
|
||||||
inet_ntoa (packet -> raw -> ciaddr),
|
inet_ntoa (packet -> raw -> ciaddr),
|
||||||
@@ -310,18 +326,19 @@ void dhcprelease (packet)
|
|||||||
void dhcpdecline (packet)
|
void dhcpdecline (packet)
|
||||||
struct packet *packet;
|
struct packet *packet;
|
||||||
{
|
{
|
||||||
struct lease *lease = find_lease (packet, packet -> shared_network);
|
struct lease *lease;
|
||||||
struct iaddr cip;
|
struct iaddr cip;
|
||||||
|
|
||||||
if (packet -> options [DHO_DHCP_REQUESTED_ADDRESS].len) {
|
/* DHCPDECLINE must specify address. */
|
||||||
cip.len = 4;
|
if (!packet -> options [DHO_DHCP_REQUESTED_ADDRESS].len) {
|
||||||
memcpy (cip.iabuf,
|
return;
|
||||||
packet -> options [DHO_DHCP_REQUESTED_ADDRESS].data,
|
|
||||||
4);
|
|
||||||
} else {
|
|
||||||
cip.len = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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",
|
note ("DHCPDECLINE on %s from %s via %s",
|
||||||
piaddr (cip),
|
piaddr (cip),
|
||||||
print_hw_addr (packet -> raw -> htype,
|
print_hw_addr (packet -> raw -> htype,
|
||||||
@@ -1056,9 +1073,10 @@ void dhcp_reply (lease)
|
|||||||
lease -> state = (struct lease_state *)0;
|
lease -> state = (struct lease_state *)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct lease *find_lease (packet, share)
|
struct lease *find_lease (packet, share, ours)
|
||||||
struct packet *packet;
|
struct packet *packet;
|
||||||
struct shared_network *share;
|
struct shared_network *share;
|
||||||
|
int *ours;
|
||||||
{
|
{
|
||||||
struct lease *uid_lease, *ip_lease, *hw_lease;
|
struct lease *uid_lease, *ip_lease, *hw_lease;
|
||||||
struct lease *lease = (struct lease *)0;
|
struct lease *lease = (struct lease *)0;
|
||||||
@@ -1140,6 +1158,12 @@ struct lease *find_lease (packet, share)
|
|||||||
} else
|
} else
|
||||||
ip_lease = (struct lease *)0;
|
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
|
/* If the requested IP address isn't on the network the packet
|
||||||
came from, or if it's been abandoned, don't use it. */
|
came from, or if it's been abandoned, don't use it. */
|
||||||
if (ip_lease && (ip_lease -> shared_network != share ||
|
if (ip_lease && (ip_lease -> shared_network != share ||
|
||||||
|
Reference in New Issue
Block a user