lp->tstp = cur_time;
lp->starts = cur_time;
- if (!supersede_lease(lp, NULL, 0, 1, 0) ||
+ if (!supersede_lease(lp, NULL, 0, 1, 0, 0) ||
!write_lease(lp))
log_error("can't commit lease %s on "
"giveaway", piaddr(lp->ip_addr));
lease->rewind_binding_state = lt->next_binding_state;
/* Try to install the new information. */
- if (!supersede_lease (lease, lt, 0, 0, 0) ||
+ if (!supersede_lease (lease, lt, 0, 0, 0, 0) ||
!write_lease (lease)) {
message = "database update failed";
bad:
lease->tstp = cur_time;
lease->starts = cur_time;
- if (!supersede_lease(lease, NULL, 0, 1, 0) ||
+ if (!supersede_lease(lease, NULL, 0, 1, 0, 0) ||
!write_lease(lease))
log_error("can't commit lease %s for mac addr "
"affinity", piaddr(lease->ip_addr));
/* The peer will have made this state change, so set rewind. */
lease->rewind_binding_state = lease->next_binding_state;
- supersede_lease(lease, (struct lease *)0, 0, 0, 0);
+ supersede_lease(lease, NULL, 0, 0, 0, 0);
write_lease(lease);
/* Lease has returned to FREE state from the
if (lease->desired_binding_state != lease->binding_state) {
lease->next_binding_state =
lease->desired_binding_state;
- supersede_lease(lease,
- (struct lease *)0, 0, 0, 0);
+ supersede_lease(lease, NULL, 0, 0, 0, 0);
}
write_lease(lease);
/* Commit the lease only after a two-second timeout,
lease->next_binding_state = FTS_BACKUP;
lease->tstp = lease->starts = cur_time;
- if (!supersede_lease(lease, NULL, 0, 1, 0) ||
+ if (!supersede_lease(lease, NULL, 0, 1, 0, 0) ||
!write_lease(lease))
log_error("can't commit lease %s for "
"client affinity", piaddr(lease->ip_addr));
list of leases by expiry time so that we can always find the oldest
lease. */
-int supersede_lease (comp, lease, commit, propogate, pimmediate)
+int supersede_lease (comp, lease, commit, propogate, pimmediate, from_pool)
struct lease *comp, *lease;
int commit;
int propogate;
int pimmediate;
+ int from_pool;
{
struct lease *lp, **lq, *prev;
struct timeval tv;
dhcp_failover_pool_check(comp->pool);
#endif
- /* If the current binding state has already expired, do an
- expiry event right now. */
+ /* If the current binding state has already expired and we haven't
+ * been called from pool_timer, do an expiry event right now.
+ */
/* XXX At some point we should optimize this so that we don't
XXX write the lease twice, but this is a safe way to fix the
XXX problem for 3.0 (I hope!). */
- if ((commit || !pimmediate) &&
- comp -> sort_time < cur_time &&
- comp -> next_binding_state != comp -> binding_state)
- pool_timer (comp -> pool);
+ if ((from_pool == 0) &&
+ (commit || !pimmediate) &&
+ (comp->sort_time < cur_time) &&
+ (comp->next_binding_state != comp->binding_state))
+ pool_timer(comp->pool);
return 1;
}
#else
lease -> next_binding_state = FTS_FREE;
#endif
- supersede_lease (lease, (struct lease *)0, 1, 1, 1);
+ supersede_lease(lease, NULL, 1, 1, 1, 0);
}
}
lt -> uid = (unsigned char *)0;
lt -> uid_len = 0;
lt -> uid_max = 0;
- supersede_lease (lease, lt, 1, 1, 1);
+ supersede_lease (lease, lt, 1, 1, 1, 0);
lease_dereference (<, MDL);
}
lt -> uid = (unsigned char *)0;
lt -> uid_len = 0;
lt -> uid_max = 0;
- supersede_lease (lease, lt, 1, 1, 1);
+ supersede_lease (lease, lt, 1, 1, 1, 0);
lease_dereference (<, MDL);
}
#endif
void *vpool;
{
struct pool *pool;
- struct lease *next = (struct lease *)0;
- struct lease *lease = (struct lease *)0;
+ struct lease *next = NULL;
+ struct lease *lease = NULL;
#define FREE_LEASES 0
#define ACTIVE_LEASES 1
#define EXPIRED_LEASES 2
pool = (struct pool *)vpool;
- lptr [FREE_LEASES] = &pool -> free;
- lptr [ACTIVE_LEASES] = &pool -> active;
- lptr [EXPIRED_LEASES] = &pool -> expired;
- lptr [ABANDONED_LEASES] = &pool -> abandoned;
- lptr [BACKUP_LEASES] = &pool -> backup;
+ lptr[FREE_LEASES] = &pool->free;
+ lptr[ACTIVE_LEASES] = &pool->active;
+ lptr[EXPIRED_LEASES] = &pool->expired;
+ lptr[ABANDONED_LEASES] = &pool->abandoned;
+ lptr[BACKUP_LEASES] = &pool->backup;
lptr[RESERVED_LEASES] = &pool->reserved;
for (i = FREE_LEASES; i <= RESERVED_LEASES; i++) {
continue;
}
#endif
- lease_reference (&lease, *(lptr [i]), MDL);
+ lease_reference(&lease, *(lptr [i]), MDL);
while (lease) {
/* Remember the next lease in the list. */
if (next)
- lease_dereference (&next, MDL);
+ lease_dereference(&next, MDL);
if (lease -> next)
- lease_reference (&next, lease -> next, MDL);
+ lease_reference(&next, lease->next, MDL);
/* If we've run out of things to expire on this list,
stop. */
- if (lease -> sort_time > cur_time) {
- if (lease -> sort_time < next_expiry)
- next_expiry = lease -> sort_time;
+ if (lease->sort_time > cur_time) {
+ if (lease->sort_time < next_expiry)
+ next_expiry = lease->sort_time;
break;
}
lease->next_binding_state =
lease->rewind_binding_state;
#endif
- supersede_lease(lease, NULL, 1, 1, 1);
+ supersede_lease(lease, NULL, 1, 1, 1, 1);
}
- lease_dereference (&lease, MDL);
+ lease_dereference(&lease, MDL);
if (next)
- lease_reference (&lease, next, MDL);
+ lease_reference(&lease, next, MDL);
}
if (next)
- lease_dereference (&next, MDL);
+ lease_dereference(&next, MDL);
if (lease)
- lease_dereference (&lease, MDL);
+ lease_dereference(&lease, MDL);
}
- if (next_expiry != MAX_TIME) {
- pool -> next_event_time = next_expiry;
- tv . tv_sec = pool -> next_event_time;
- tv . tv_usec = 0;
+
+ /* If we found something to expire and its expiration time
+ * is either less than the current expiration time or the
+ * current expiration time is already expired update the
+ * timer.
+ */
+ if ((next_expiry != MAX_TIME) &&
+ ((pool->next_event_time > next_expiry) ||
+ (pool->next_event_time <= cur_time))) {
+ pool->next_event_time = next_expiry;
+ tv.tv_sec = pool->next_event_time;
+ tv.tv_usec = 0;
add_timeout (&tv, pool_timer, pool,
(tvref_t)pool_reference,
(tvunref_t)pool_dereference);
} else
- pool -> next_event_time = MIN_TIME;
+ pool->next_event_time = MIN_TIME;
}
if (lease -> binding_state != bar) {
lease -> next_binding_state = bar;
- if (supersede_lease (lease, 0, 1, 1, 1)) {
+ if (supersede_lease (lease, NULL, 1, 1, 1, 0)) {
log_info ("lease %s state changed from %s to %s",
piaddr(lease->ip_addr), ols, nls);
return ISC_R_SUCCESS;
return status;
old_lease_end = lease->ends;
lease->ends = lease_end;
- if (supersede_lease (lease, 0, 1, 1, 1)) {
+ if (supersede_lease (lease, NULL, 1, 1, 1, 0)) {
log_info ("lease %s end changed from %lu to %lu",
piaddr(lease->ip_addr), old_lease_end, lease_end);
return ISC_R_SUCCESS;
(lease->flags & ~EPHEMERAL_FLAGS);
if(oldflags == lease->flags)
return ISC_R_SUCCESS;
- if (!supersede_lease(lease, NULL, 1, 1, 1)) {
+ if (!supersede_lease(lease, NULL, 1, 1, 1, 0)) {
log_error("Failed to update flags for lease %s.",
piaddr(lease->ip_addr));
return ISC_R_IOERROR;