DHCP Client. */
/*
- * Copyright (c) 1995, 1996, 1997 The Internet Software Consortium.
+ * Copyright (c) 1995, 1996, 1997, 1998 The Internet Software Consortium.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#ifndef lint
static char copyright[] =
-"$Id: dhclient.c,v 1.46 1998/02/06 00:58:36 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n";
+"$Id: dhclient.c,v 1.47 1998/03/15 21:04:52 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
} else {
/* Call the script with the list of interfaces. */
for (ip = interfaces; ip; ip = ip -> next) {
+ /* If interfaces were specified, don't configure
+ interfaces that weren't specified! */
+ if (interfaces_requested &&
+ ((ip -> flags & (INTERFACE_REQUESTED |
+ INTERFACE_AUTOMATIC)) ==
+ INTERFACE_AUTOMATIC))
+ continue;
script_init (ip, "PREINIT", (struct string_list *)0);
if (ip -> client -> alias)
script_write_params (ip, "alias_",
/* We are in the rebooting state. */
ip -> client -> state = S_REBOOTING;
+ /* make_request doesn't initialize xid because it normally comes
+ from the DHCPDISCOVER, but we haven't sent a DHCPDISCOVER,
+ so pick an xid now. */
+ ip -> client -> xid = random ();
+
/* Make a DHCPREQUEST packet, and set appropriate per-interface
flags. */
make_request (ip, ip -> client -> active);
- ip -> client -> xid = ip -> client -> packet.xid;
ip -> client -> destination = iaddr_broadcast;
ip -> client -> first_sending = cur_time;
ip -> client -> interval = ip -> client -> config -> initial_interval;
/* If we're not receptive to an offer right now, or if the offer
has an unrecognizable transaction id, then just drop it. */
- if (packet -> interface -> client -> xid != packet -> raw -> xid) {
+ if (packet -> interface -> client -> xid != packet -> raw -> xid ||
+ (packet -> interface -> client -> hw_address.hlen !=
+ packet -> raw -> hlen) ||
+ (memcmp (packet -> interface -> client -> hw_address.haddr,
+ packet -> raw -> chaddr))) {
debug ("DHCPACK in wrong transaction.");
return;
}
ip -> client -> new -> medium = ip -> client -> medium;
/* Write out the new lease. */
- write_client_lease (ip, ip -> client -> new);
+ write_client_lease (ip, ip -> client -> new, 0);
/* Run the client script with the new parameters. */
script_init (ip, (ip -> client -> state == S_REQUESTING
ip -> client -> packet.htype = ip -> hw_address.htype;
ip -> client -> packet.hlen = ip -> hw_address.hlen;
ip -> client -> packet.hops = 0;
- ip -> client -> packet.xid = ip -> client -> packet.xid;
+ ip -> client -> packet.xid = ip -> client -> xid;
ip -> client -> packet.secs = 0;
ip -> client -> packet.flags = 0;
memcpy (&ip -> client -> packet.ciaddr,
we know about. */
for (ip = interfaces; ip; ip = ip -> next) {
for (lp = ip -> client -> leases; lp; lp = lp -> next) {
- write_client_lease (ip, lp);
+ write_client_lease (ip, lp, 1);
}
if (ip -> client -> active)
- write_client_lease (ip, ip -> client -> active);
+ write_client_lease (ip, ip -> client -> active, 1);
}
/* Write out any leases that are attached to interfaces that aren't
currently configured. */
for (ip = dummy_interfaces; ip; ip = ip -> next) {
for (lp = ip -> client -> leases; lp; lp = lp -> next) {
- write_client_lease (ip, lp);
+ write_client_lease (ip, lp, 1);
}
if (ip -> client -> active)
- write_client_lease (ip, ip -> client -> active);
+ write_client_lease (ip, ip -> client -> active, 1);
}
fflush (leaseFile);
}
-void write_client_lease (ip, lease)
+void write_client_lease (ip, lease, rewrite)
struct interface_info *ip;
struct client_lease *lease;
+ int rewrite;
{
int i;
struct tm *t;
+ static int leases_written;
+
+ if (!rewrite) {
+ if (leases_written++ > 20) {
+ rewrite_client_leases ();
+ leases_written = 0;
+ }
+ }
/* If the lease came from the config file, we don't need to stash
a copy in the lease database. */
lease -> options [i].len, 1, 1));
}
}
+
+ /* Note: the following is not a Y2K bug - it's a Y1.9K bug. Until
+ somebody invents a time machine, I think we can safely disregard
+ it. */
t = gmtime (&lease -> renewal);
fprintf (leaseFile,
" renew %d %d/%d/%d %02d:%02d:%02d;\n",