Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-5]: src/usr.sbin/dhcp/client Pull up revision 1.36 (requested b...
details: https://anonhg.NetBSD.org/src/rev/1f4fb065f1c2
branches: netbsd-1-5
changeset: 491265:1f4fb065f1c2
user: he <he%NetBSD.org@localhost>
date: Sat Apr 21 19:41:43 2001 +0000
description:
Pull up revision 1.36 (requested by mellon):
Fix various bugs:
- PR#11081 (dhclient loops if interface is unplugged)
- PR#12065 (/etc/resolv.conf corrupted during DHCP lease renewal)
- PR#9709 (same as 11081)
- PR#11080 (dhclient -w doesn't work)
- PR#9657 (dhclient requires writable lease file)
diffstat:
usr.sbin/dhcp/client/dhclient.c | 93 ++++++++++++++++++++++++++++++++++++----
1 files changed, 82 insertions(+), 11 deletions(-)
diffs (171 lines):
diff -r bb5e34410c45 -r 1f4fb065f1c2 usr.sbin/dhcp/client/dhclient.c
--- a/usr.sbin/dhcp/client/dhclient.c Sat Apr 21 19:21:11 2001 +0000
+++ b/usr.sbin/dhcp/client/dhclient.c Sat Apr 21 19:41:43 2001 +0000
@@ -41,7 +41,7 @@
#ifndef lint
static char ocopyright[] =
-"$Id: dhclient.c,v 1.26.2.8 2001/04/04 20:55:28 he Exp $ Copyright (c) 1995-2001 Internet Software Consortium. All rights reserved.\n";
+"$Id: dhclient.c,v 1.26.2.9 2001/04/21 19:41:43 he Exp $ Copyright (c) 1995-2001 Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@@ -112,6 +112,16 @@
int no_dhclient_script = 0;
char *s;
+ /* Make sure we have stdin, stdout and stderr. */
+ i = open ("/dev/null", O_RDWR);
+ if (i == 0)
+ i = open ("/dev/null", O_RDWR);
+ if (i == 1) {
+ i = open ("/dev/null", O_RDWR);
+ log_perror = 0; /* No sense logging to /dev/null. */
+ } else if (i != -1)
+ close (i);
+
#ifdef SYSLOG_4_2
openlog ("dhclient", LOG_NDELAY);
log_priority = LOG_DAEMON;
@@ -135,6 +145,7 @@
dhcp_interface_discovery_hook = dhclient_interface_discovery_hook;
dhcp_interface_shutdown_hook = dhclient_interface_shutdown_hook;
+ dhcp_interface_startup_hook = dhclient_interface_startup_hook;
for (i = 1; i < argc; i++) {
if (!strcmp (argv [i], "-r")) {
@@ -1681,7 +1692,6 @@
destination.sin_len = sizeof destination;
#endif
-
/* Set the lease to end now, so that we don't accidentally
reuse it if we restart before the old expiry time. */
client -> active -> expiry =
@@ -2066,8 +2076,10 @@
if (leaseFile)
fclose (leaseFile);
leaseFile = fopen (path_dhclient_db, "w");
- if (!leaseFile)
- log_fatal ("can't create %s: %m", path_dhclient_db);
+ if (!leaseFile) {
+ log_error ("can't create %s: %m", path_dhclient_db);
+ return;
+ }
/* Write out all the leases attached to configured interfaces that
we know about. */
@@ -2159,8 +2171,10 @@
if (!leaseFile) { /* XXX */
leaseFile = fopen (path_dhclient_db, "w");
- if (!leaseFile)
- log_fatal ("can't create %s: %m", path_dhclient_db);
+ if (!leaseFile) {
+ log_error ("can't create %s: %m", path_dhclient_db);
+ return 0;
+ }
}
errno = 0;
@@ -2681,6 +2695,7 @@
case S_INIT:
case S_REBINDING:
+ case S_STOPPED:
break;
}
client -> state = S_INIT;
@@ -2695,9 +2710,7 @@
struct data_string ds;
struct option_cache *oc;
- /* 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. */
+ /* Pick a random xid. */
client -> xid = random ();
/* is there even a lease to release? */
@@ -2742,13 +2755,19 @@
script_go (client);
}
- /* remove the timeouts for this client */
- cancel_timeout (0, client);
+ /* Cancel any timeouts. */
+ cancel_timeout (state_bound, client);
+ cancel_timeout (send_discover, client);
+ cancel_timeout (state_init, client);
+ cancel_timeout (send_request, client);
+ cancel_timeout (state_reboot, client);
+ client -> state = S_STOPPED;
}
int dhclient_interface_shutdown_hook (struct interface_info *interface)
{
do_release (interface -> client);
+
return 1;
}
@@ -2795,6 +2814,58 @@
return 1;
}
+isc_result_t dhclient_interface_startup_hook (struct interface_info *interface)
+{
+ struct interface_info *ip;
+ struct client_state *client;
+
+ /* This code needs some rethinking. It doesn't test against
+ a signal name, and it just kind of bulls into doing something
+ that may or may not be appropriate. */
+
+ if (interfaces) {
+ interface_reference (&interface -> next, interfaces, MDL);
+ interface_dereference (&interfaces, MDL);
+ }
+ interface_reference (&interfaces, interface, MDL);
+
+ discover_interfaces (DISCOVER_UNCONFIGURED);
+
+ for (ip = interfaces; ip; ip = ip -> next) {
+ /* If interfaces were specified, don't configure
+ interfaces that weren't specified! */
+ if (ip -> flags & INTERFACE_RUNNING ||
+ (ip -> flags & (INTERFACE_REQUESTED |
+ INTERFACE_AUTOMATIC)) !=
+ INTERFACE_REQUESTED)
+ continue;
+ script_init (ip -> client,
+ "PREINIT", (struct string_list *)0);
+ if (ip -> client -> alias)
+ script_write_params (ip -> client, "alias_",
+ ip -> client -> alias);
+ script_go (ip -> client);
+ }
+
+ discover_interfaces (interfaces_requested
+ ? DISCOVER_REQUESTED
+ : DISCOVER_RUNNING);
+
+ for (ip = interfaces; ip; ip = ip -> next) {
+ if (ip -> flags & INTERFACE_RUNNING)
+ continue;
+ ip -> flags |= INTERFACE_RUNNING;
+ for (client = ip -> client; client; client = client -> next) {
+ client -> state = S_INIT;
+ /* Set up a timeout to start the initialization
+ process. */
+ add_timeout (cur_time + random () % 5,
+ state_reboot, client, 0, 0);
+ }
+ }
+ return ISC_R_SUCCESS;
+}
+
/* The client should never receive a relay agent information option,
so if it does, log it and discard it. */
Home |
Main Index |
Thread Index |
Old Index