2
0
mirror of https://gitlab.isc.org/isc-projects/dhcp synced 2025-08-31 06:15:55 +00:00

Sync with 3.0rc7

This commit is contained in:
Ted Lemon
2001-05-17 19:04:09 +00:00
parent cb7cfe5cb7
commit 31bbee784c
21 changed files with 449 additions and 167 deletions

View File

@@ -43,7 +43,7 @@
#ifndef lint
static char copyright[] =
"$Id: bootp.c,v 1.69 2001/02/12 20:51:26 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n";
"$Id: bootp.c,v 1.70 2001/05/17 19:04:03 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@@ -341,7 +341,6 @@ void bootp (packet)
/* We're done with the option state. */
option_state_dereference (&options, MDL);
static_lease_dereference (lease, MDL);
/* Set up the hardware destination address... */
hto.hbuf [0] = packet -> raw -> htype;
@@ -403,10 +402,8 @@ void bootp (packet)
out:
if (options)
option_state_dereference (&options, MDL);
if (lease) {
static_lease_dereference (lease, MDL);
if (lease)
lease_dereference (&lease, MDL);
}
if (hp)
host_dereference (&hp, MDL);
if (host)

View File

@@ -43,11 +43,12 @@
#ifndef lint
static char copyright[] =
"$Id: db.c,v 1.63 2001/03/15 23:21:25 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n";
"$Id: db.c,v 1.64 2001/05/17 19:04:04 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
#include <ctype.h>
#include "version.h"
FILE *db_file;
@@ -741,7 +742,9 @@ void new_lease_file ()
"confusing to you, we sincerely\n");
fprintf (db_file, "# apologize. Seriously, though - don't ask.\n");
fprintf (db_file, "# The format of this file is documented in the %s",
"dhcpd.leases(5) manual page.\n\n");
"dhcpd.leases(5) manual page.\n");
fprintf (db_file, "# This lease file was written by isc-dhcp-%s\n\n",
DHCP_VERSION);
/* Write out all the leases that we know of... */
counting = 0;

View File

@@ -43,7 +43,7 @@
#ifndef lint
static char copyright[] =
"$Id: dhcp.c,v 1.192 2001/05/03 18:22:58 mellon Exp $ Copyright (c) 1995-2001 The Internet Software Consortium. All rights reserved.\n";
"$Id: dhcp.c,v 1.193 2001/05/17 19:04:05 mellon Exp $ Copyright (c) 1995-2001 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@@ -476,6 +476,16 @@ void dhcprequest (packet, ms_nulltp, ip_lease)
goto out;
}
}
/* Don't let a client allocate a lease using DHCPREQUEST
if the lease isn't ours to allocate. */
if ((lease -> binding_state == FTS_FREE &&
peer -> i_am == secondary) ||
(lease -> binding_state == FTS_BACKUP &&
peer -> i_am == primary)) {
log_debug ("%s: expired", msgbuf);
goto out;
}
} else
peer = (dhcp_failover_state_t *)0;
#endif
@@ -1579,7 +1589,6 @@ void ack_lease (packet, lease, offer, when, msg, ms_nulltp)
d1.data [0]);
data_string_forget (&d1, MDL);
free_lease_state (state, MDL);
static_lease_dereference (lease, MDL);
return;
}
data_string_forget (&d1, MDL);
@@ -1639,7 +1648,6 @@ void ack_lease (packet, lease, offer, when, msg, ms_nulltp)
if (!ignorep)
log_info ("%s: unknown client", msg);
free_lease_state (state, MDL);
static_lease_dereference (lease, MDL);
return;
}
@@ -1656,7 +1664,6 @@ void ack_lease (packet, lease, offer, when, msg, ms_nulltp)
if (!ignorep)
log_info ("%s: bootp disallowed", msg);
free_lease_state (state, MDL);
static_lease_dereference (lease, MDL);
return;
}
@@ -1673,7 +1680,6 @@ void ack_lease (packet, lease, offer, when, msg, ms_nulltp)
if (!ignorep)
log_info ("%s: booting disallowed", msg);
free_lease_state (state, MDL);
static_lease_dereference (lease, MDL);
return;
}
@@ -1710,7 +1716,6 @@ void ack_lease (packet, lease, offer, when, msg, ms_nulltp)
msg);
free_lease_state (state, MDL);
/* XXX probably not necessary: */
static_lease_dereference (lease, MDL);
return;
}
}
@@ -1743,7 +1748,6 @@ void ack_lease (packet, lease, offer, when, msg, ms_nulltp)
log_info ("%s: can't allocate temporary lease structure: %s",
msg, isc_result_totext (result));
free_lease_state (state, MDL);
static_lease_dereference (lease, MDL);
return;
}
@@ -2096,7 +2100,6 @@ void ack_lease (packet, lease, offer, when, msg, ms_nulltp)
offer == DHCPACK, offer == DHCPACK)) {
log_info ("%s: database update failed", msg);
free_lease_state (state, MDL);
static_lease_dereference (lease, MDL);
lease_dereference (&lt, MDL);
return;
}
@@ -2475,7 +2478,6 @@ void ack_lease (packet, lease, offer, when, msg, ms_nulltp)
++outstanding_pings;
} else {
lease -> timestamp = cur_time;
static_lease_dereference (lease, MDL);
dhcp_reply (lease);
}
}
@@ -3366,38 +3368,6 @@ int mockup_lease (struct lease **lp, struct packet *packet,
return 1;
}
/* Dereference all dynamically-allocated information that may be dangling
off of a static lease. Otherwise, once ack_lease returns, the information
dangling from the lease will be lost, so reference counts will be screwed
up and memory leaks will occur. */
void static_lease_dereference (lease, file, line)
struct lease *lease;
const char *file;
int line;
{
if (!(lease -> flags & STATIC_LEASE))
return;
if (lease -> on_release)
executable_statement_dereference (&lease -> on_release,
file, line);
if (lease -> on_expiry)
executable_statement_dereference (&lease -> on_expiry,
file, line);
if (lease -> on_commit)
executable_statement_dereference (&lease -> on_commit,
file, line);
if (lease -> scope)
binding_scope_dereference (&lease -> scope, file, line);
if (lease -> agent_options)
option_chain_head_dereference (&lease -> agent_options,
file, line);
if (lease -> uid != lease -> uid_buf) {
dfree (lease -> uid, file, line);
lease -> uid = (unsigned char *)0;
}
}
/* Look through all the pools in a list starting with the specified pool
for a free lease. We try to find a virgin lease if we can. If we
don't find a virgin lease, we try to find a non-virgin lease that's

View File

@@ -43,7 +43,7 @@
#ifndef lint
static char copyright[] =
"$Id: failover.c,v 1.53 2001/05/03 18:31:28 mellon Exp $ Copyright (c) 1999-2001 The Internet Software Consortium. All rights reserved.\n";
"$Id: failover.c,v 1.54 2001/05/17 19:04:07 mellon Exp $ Copyright (c) 1999-2001 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@@ -1363,6 +1363,7 @@ isc_result_t dhcp_failover_state_transition (dhcp_failover_state_t *state,
case resolution_interrupted:
case partner_down:
case communications_interrupted:
case recover:
/* Already in the right state? */
if (state -> me.state == startup)
return (dhcp_failover_set_state
@@ -1373,14 +1374,6 @@ isc_result_t dhcp_failover_state_transition (dhcp_failover_state_t *state,
return dhcp_failover_set_state
(state, resolution_interrupted);
case recover:
/* XXX I don't think it makes sense to make a
XXX transition from recover to communications-
XXX interrupted, because then when the connect
XXX occurred, we'd make a transition into
XXX normal, not recover. */
break; /* Kim says stay in recover. */
case normal:
return dhcp_failover_set_state
(state, communications_interrupted);
@@ -1533,6 +1526,9 @@ isc_result_t dhcp_failover_set_state (dhcp_failover_state_t *state,
{
enum failover_state saved_state;
TIME saved_stos;
struct pool *p;
struct shared_network *s;
struct lease *l;
/* First make the transition out of the current state. */
switch (state -> me.state) {
@@ -1658,6 +1654,27 @@ isc_result_t dhcp_failover_set_state (dhcp_failover_state_t *state,
dhcp_failover_send_update_request_all (state);
break;
case partner_down:
/* For every expired lease, set a timeout for it to become free. */
for (s = shared_networks; s; s = s -> next) {
for (p = s -> pools; p; p = p -> next) {
if (p -> failover_peer == state) {
for (l = p -> expired; l; l = l -> next)
l -> tsfp = state -> me.stos + state -> mclt;
if (p -> next_event_time >
state -> me.stos + state -> mclt) {
p -> next_event_time =
state -> me.stos + state -> mclt;
add_timeout (p -> next_event_time, pool_timer, p,
(tvref_t)pool_reference,
(tvunref_t)pool_dereference);
}
}
}
}
break;
default:
break;
}
@@ -2307,7 +2324,6 @@ int dhcp_failover_queue_ack (dhcp_failover_state_t *state,
(tvunref_t)dhcp_failover_state_dereference);
}
return 1;
}
@@ -4234,13 +4250,13 @@ isc_result_t dhcp_failover_process_bind_update (dhcp_failover_state_t *state,
if (state -> me.state == normal) {
new_binding_state =
(normal_binding_state_transition_check
(lease, state,
msg -> binding_status));
(lease, state, msg -> binding_status,
msg -> potential_expiry));
} else {
new_binding_state =
(conflict_binding_state_transition_check
(lease, state,
msg -> binding_status));
(lease, state, msg -> binding_status,
msg -> potential_expiry));
}
if (new_binding_state != msg -> binding_status) {
char outbuf [100];
@@ -4318,8 +4334,20 @@ isc_result_t dhcp_failover_process_bind_ack (dhcp_failover_state_t *state,
if (msg -> options_present & FTB_POTENTIAL_EXPIRY) {
/* XXX it could be a problem to do this directly if the
XXX lease is sorted by tsfp. */
lease -> tsfp = msg -> potential_expiry;
write_lease (lease);
if (lease -> binding_state == FTS_EXPIRED) {
lease -> next_binding_state = FTS_FREE;
supersede_lease (lease, (struct lease *)0, 0, 1, 0);
write_lease (lease);
if (state -> me.state == normal)
commit_leases ();
} else {
lease -> tsfp = msg -> potential_expiry;
write_lease (lease);
#if 0 /* XXX This might be needed. */
if (state -> me.state == normal)
commit_leases ();
#endif
}
}
unqueue:
@@ -4639,7 +4667,8 @@ int load_balance_mine (struct packet *packet, dhcp_failover_state_t *state)
binding_state_t
normal_binding_state_transition_check (struct lease *lease,
dhcp_failover_state_t *state,
binding_state_t binding_state)
binding_state_t binding_state,
u_int32_t tsfp)
{
binding_state_t new_state;
@@ -4688,8 +4717,7 @@ normal_binding_state_transition_check (struct lease *lease,
case FTS_BACKUP:
/* Can't set a lease to free or backup until the
peer agrees that it's expired. */
/* XXX but have we updated tsfp yet? */
if (lease -> tsfp > cur_time) {
if (tsfp > cur_time) {
new_state = lease -> binding_state;
goto out;
}
@@ -4716,8 +4744,7 @@ normal_binding_state_transition_check (struct lease *lease,
case FTS_BACKUP:
/* Can't set a lease to free or backup until the
peer agrees that it's expired. */
/* XXX but have we updated tsfp yet? */
if (lease -> tsfp > cur_time) {
if (tsfp > cur_time) {
new_state = lease -> binding_state;
goto out;
}
@@ -4738,8 +4765,7 @@ normal_binding_state_transition_check (struct lease *lease,
case FTS_BACKUP:
/* Can't set a lease to free or backup until the
peer agrees that it's expired. */
/* XXX but have we updated tsfp yet? */
if (lease -> tsfp > cur_time) {
if (tsfp > cur_time) {
new_state = lease -> binding_state;
goto out;
}
@@ -4758,10 +4784,9 @@ normal_binding_state_transition_check (struct lease *lease,
switch (binding_state) {
case FTS_FREE:
case FTS_BACKUP:
/* XXX but have we updated tsfp yet? */
/* Can't set a lease to free or backup until the
peer agrees that it's expired. */
if (lease -> tsfp > cur_time) {
if (tsfp > cur_time) {
new_state = lease -> binding_state;
goto out;
}
@@ -4811,7 +4836,8 @@ normal_binding_state_transition_check (struct lease *lease,
binding_state_t
conflict_binding_state_transition_check (struct lease *lease,
dhcp_failover_state_t *state,
binding_state_t binding_state)
binding_state_t binding_state,
u_int32_t tsfp)
{
binding_state_t new_state;

View File

@@ -43,7 +43,7 @@
#ifndef lint
static char copyright[] =
"$Id: mdb.c,v 1.67 2001/05/02 07:09:36 mellon Exp $ Copyright (c) 1996-2000 The Internet Software Consortium. All rights reserved.\n";
"$Id: mdb.c,v 1.68 2001/05/17 19:04:08 mellon Exp $ Copyright (c) 1996-2000 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@@ -821,6 +821,7 @@ int supersede_lease (comp, lease, commit, propogate, pimmediate)
requested *after* a DHCP lease has been assigned. */
if (lease -> binding_state != FTS_ABANDONED &&
lease -> next_binding_state != FTS_ABANDONED &&
(comp -> binding_state == FTS_ACTIVE ||
comp -> binding_state == FTS_RESERVED ||
comp -> binding_state == FTS_BOOTP) &&
@@ -1066,7 +1067,7 @@ int supersede_lease (comp, lease, commit, propogate, pimmediate)
and the expiry code sets the timer if there's anything left
to expire after it's run any outstanding expiry events on
the pool. */
if (commit &&
if ((commit || !pimmediate) &&
comp -> sort_time != MIN_TIME &&
comp -> sort_time > cur_time &&
(comp -> sort_time < comp -> pool -> next_event_time ||
@@ -1215,6 +1216,15 @@ void make_binding_state_transition (struct lease *lease)
case FTS_ABANDONED:
case FTS_RESET:
lease -> next_binding_state = FTS_FREE;
/* If we are not in partner_down, leases don't go from
EXPIRED to FREE on a timeout - only on an update.
If we're in partner_down, they expire at mclt past
the time we entered partner_down. */
if (lease -> pool -> failover_peer &&
lease -> pool -> failover_peer -> me.state == partner_down)
lease -> tsfp =
(lease -> pool -> failover_peer -> me.stos +
lease -> pool -> failover_peer -> mclt);
break;
case FTS_FREE:
@@ -1445,7 +1455,22 @@ void pool_timer (vpool)
/* If there's nothing on the queue, skip it. */
if (!*(lptr [i]))
continue;
#if defined (FAILOVER_PROTOCOL)
if (pool -> failover_peer &&
pool -> failover_peer -> me.state != partner_down) {
/* The secondary can't remove a lease from the
active state except in partner_down. */
if (i == ACTIVE_LEASES &&
pool -> failover_peer -> i_am == secondary)
continue;
/* Leases in an expired state don't move to
free because of a timeout unless we're in
partner_down. */
if (i == EXPIRED_LEASES)
continue;
}
#endif
lease_reference (&lease, *(lptr [i]), MDL);
while (lease) {

View File

@@ -3,7 +3,7 @@
OMAPI object interfaces for the DHCP server. */
/*
* Copyright (c) 1999-2000 Internet Software Consortium.
* Copyright (c) 1999-2001 Internet Software Consortium.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -50,7 +50,7 @@
#ifndef lint
static char copyright[] =
"$Id: omapi.c,v 1.46 2001/05/02 07:11:38 mellon Exp $ Copyright (c) 1999-2000 The Internet Software Consortium. All rights reserved.\n";
"$Id: omapi.c,v 1.47 2001/05/17 19:04:09 mellon Exp $ Copyright (c) 1999-2001 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@@ -354,35 +354,43 @@ isc_result_t dhcp_lease_destroy (omapi_object_t *h, const char *file, int line)
return ISC_R_INVALIDARG;
lease = (struct lease *)h;
uid_hash_delete (lease);
if (lease -> uid)
uid_hash_delete (lease);
hw_hash_delete (lease);
if (lease -> billing_class)
class_dereference
(&lease -> billing_class, file, line);
if (lease -> uid && lease -> uid != &lease -> uid_buf [0]) {
dfree (lease -> uid, MDL);
lease -> uid = &lease -> uid_buf [0];
lease -> uid_len = 0;
}
if (lease -> client_hostname) {
dfree (lease -> client_hostname, MDL);
lease -> client_hostname = (char *)0;
}
if (lease -> host)
host_dereference (&lease -> host, file, line);
if (lease -> subnet)
subnet_dereference (&lease -> subnet, file, line);
if (lease -> pool)
pool_dereference (&lease -> pool, file, line);
if (lease -> on_release)
executable_statement_dereference (&lease -> on_release,
file, line);
if (lease -> on_expiry)
executable_statement_dereference (&lease -> on_expiry,
file, line);
if (lease -> on_commit)
executable_statement_dereference (&lease -> on_commit,
file, line);
if (lease -> on_release)
executable_statement_dereference (&lease -> on_release,
file, line);
if (lease -> scope)
binding_scope_dereference (&lease -> scope, file, line);
if (lease -> agent_options)
option_chain_head_dereference (&lease -> agent_options,
file, line);
if (lease -> uid && lease -> uid != lease -> uid_buf) {
dfree (lease -> uid, MDL);
lease -> uid = &lease -> uid_buf [0];
lease -> uid_len = 0;
}
if (lease -> client_hostname) {
dfree (lease -> client_hostname, MDL);
lease -> client_hostname = (char *)0;
}
if (lease -> host)
host_dereference (&lease -> host, file, line);
if (lease -> subnet)
subnet_dereference (&lease -> subnet, file, line);
if (lease -> pool)
pool_dereference (&lease -> pool, file, line);
if (lease -> state) {
free_lease_state (lease -> state, file, line);
lease -> state = (struct lease_state *)0;
@@ -390,6 +398,11 @@ isc_result_t dhcp_lease_destroy (omapi_object_t *h, const char *file, int line)
cancel_timeout (lease_ping_timeout, lease);
--outstanding_pings; /* XXX */
}
if (lease -> billing_class)
class_dereference
(&lease -> billing_class, file, line);
return ISC_R_SUCCESS;
}