diff options
author | Ted Lemon <source@isc.org> | 1998-07-10 23:14:10 +0000 |
---|---|---|
committer | Ted Lemon <source@isc.org> | 1998-07-10 23:14:10 +0000 |
commit | 8ca74d94cb49220937610deeddaf97be1ed8077c (patch) | |
tree | d83d63405fe6ac34c651031196690308ae370993 /client | |
parent | a163216036b51b62ab201736cc7609dda8c8175b (diff) | |
download | isc-dhcp-8ca74d94cb49220937610deeddaf97be1ed8077c.tar.gz |
Pull up selected changes between 1.44 and 1.49
Diffstat (limited to 'client')
-rw-r--r-- | client/dhclient.c | 70 |
1 files changed, 54 insertions, 16 deletions
diff --git a/client/dhclient.c b/client/dhclient.c index eb4d268f..0f3ce974 100644 --- a/client/dhclient.c +++ b/client/dhclient.c @@ -3,7 +3,7 @@ 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 @@ -56,7 +56,7 @@ #ifndef lint static char copyright[] = -"$Id: dhclient.c,v 1.44.2.1 1997/12/06 11:24:31 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; +"$Id: dhclient.c,v 1.44.2.2 1998/07/10 23:14:10 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -191,6 +191,13 @@ int main (argc, argv, envp) } 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_", @@ -291,10 +298,14 @@ void state_reboot (ipp) /* 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; @@ -432,7 +443,11 @@ void dhcpack (packet) /* 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 -> hw_address.hlen != + packet -> raw -> hlen) || + (memcmp (packet -> interface -> hw_address.haddr, + packet -> raw -> chaddr, packet -> raw -> hlen))) { debug ("DHCPACK in wrong transaction."); return; } @@ -498,7 +513,7 @@ void bind_lease (ip) 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 @@ -662,7 +677,11 @@ void dhcpoffer (packet) /* If we're not receptive to an offer right now, or if the offer has an unrecognizable transaction id, then just drop it. */ if (ip -> client -> state != S_SELECTING || - packet -> interface -> client -> xid != packet -> raw -> xid) { + packet -> interface -> client -> xid != packet -> raw -> xid || + (packet -> interface -> hw_address.hlen != + packet -> raw -> hlen) || + (memcmp (packet -> interface -> hw_address.haddr, + packet -> raw -> chaddr, packet -> raw -> hlen))) { debug ("%s in wrong transaction.", name); return; } @@ -861,7 +880,11 @@ void dhcpnak (packet) /* 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 -> hw_address.hlen != + packet -> raw -> hlen) || + (memcmp (packet -> interface -> hw_address.haddr, + packet -> raw -> chaddr, packet -> raw -> hlen))) { debug ("DHCPNAK in wrong transaction."); return; } @@ -963,8 +986,8 @@ void send_discover (ipp) ip -> client -> config -> backoff_cutoff) ip -> client -> interval = ((ip -> client -> config -> backoff_cutoff / 2) - + ((random () >> 2) - % ip -> client -> interval)); + + ((random () >> 2) % + ip -> client -> config -> backoff_cutoff)); } else if (!ip -> client -> interval) ip -> client -> interval = ip -> client -> config -> initial_interval; @@ -1636,7 +1659,7 @@ void make_release (ip, lease) 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, @@ -1690,30 +1713,39 @@ void rewrite_client_leases () 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. */ @@ -1751,6 +1783,10 @@ void write_client_lease (ip, lease) 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", @@ -1793,7 +1829,9 @@ void script_init (ip, reason, medium) #ifdef HAVE_MKSTEMP fd = mkstemp (scriptName); #else - mktemp (scriptName); + if (!mktemp (scriptName)) + error ("can't create temporary client script %s: %m", + scriptName); fd = creat (scriptName, 0600); } while (fd < 0); #endif |