aboutsummaryrefslogtreecommitdiff
path: root/contrib/isc-dhcp/client
diff options
context:
space:
mode:
authorDavid E. O'Brien <obrien@FreeBSD.org>1999-02-11 12:40:22 +0000
committerDavid E. O'Brien <obrien@FreeBSD.org>1999-02-11 12:40:22 +0000
commitb02401bdd6455578fb36dc5eed002b83d88e4954 (patch)
tree1ab69d6be8758743eebe6650b959ea559178112b /contrib/isc-dhcp/client
parentcd2d014aab8332077aba9b0f6e0d06678fbe1aff (diff)
downloadsrc-b02401bdd6455578fb36dc5eed002b83d88e4954.tar.gz
src-b02401bdd6455578fb36dc5eed002b83d88e4954.zip
Virgin import of ISC-DHCP v2.0b1pl11vendor/isc-dhcp/2.0b1-pl.11
Notes
Notes: svn path=/vendor/isc-dhcp/dist/; revision=43892 svn path=/vendor/isc-dhcp/2.0b1-pl.11/; revision=43894; tag=vendor/isc-dhcp/2.0b1-pl.11
Diffstat (limited to 'contrib/isc-dhcp/client')
-rw-r--r--contrib/isc-dhcp/client/clparse.c24
-rw-r--r--contrib/isc-dhcp/client/dhclient.c143
-rwxr-xr-xcontrib/isc-dhcp/client/scripts/freebsd1
3 files changed, 120 insertions, 48 deletions
diff --git a/contrib/isc-dhcp/client/clparse.c b/contrib/isc-dhcp/client/clparse.c
index 37fafd378f97..e55ea6106949 100644
--- a/contrib/isc-dhcp/client/clparse.c
+++ b/contrib/isc-dhcp/client/clparse.c
@@ -42,7 +42,7 @@
#ifndef lint
static char copyright[] =
-"$Id: clparse.c,v 1.13.2.1 1998/06/25 21:11:27 mellon Exp $ Copyright (c) 1997 The Internet Software Consortium. All rights reserved.\n";
+"$Id: clparse.c,v 1.13.2.2 1998/07/10 23:17:00 mellon Exp $ Copyright (c) 1997 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@@ -112,16 +112,18 @@ int read_client_conf ()
top_level_config.send_options [DHO_DHCP_LEASE_TIME].len
= sizeof requested_lease_time;
- if ((cfile = fopen (path_dhclient_conf, "r")) == NULL)
- error ("Can't open %s: %m", path_dhclient_conf);
- do {
- token = peek_token (&val, cfile);
- if (token == EOF)
- break;
- parse_client_statement (cfile, (struct interface_info *)0,
- &top_level_config);
- } while (1);
- token = next_token (&val, cfile); /* Clear the peek buffer */
+ if ((cfile = fopen (path_dhclient_conf, "r")) != NULL) {
+ do {
+ token = peek_token (&val, cfile);
+ if (token == EOF)
+ break;
+ parse_client_statement (cfile,
+ (struct interface_info *)0,
+ &top_level_config);
+ } while (1);
+ token = next_token (&val, cfile); /* Clear the peek buffer */
+ fclose (cfile);
+ }
/* Set up state and config structures for clients that don't
have per-interface configuration declarations. */
diff --git a/contrib/isc-dhcp/client/dhclient.c b/contrib/isc-dhcp/client/dhclient.c
index eb4d268f9768..08fa4fcef895 100644
--- a/contrib/isc-dhcp/client/dhclient.c
+++ b/contrib/isc-dhcp/client/dhclient.c
@@ -3,8 +3,8 @@
DHCP Client. */
/*
- * Copyright (c) 1995, 1996, 1997 The Internet Software Consortium.
- * All rights reserved.
+ * Copyright (c) 1995, 1996, 1997, 1998, 1999
+ * The Internet Software Consortium. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -55,8 +55,8 @@
*/
#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";
+static char ocopyright[] =
+"$Id: dhclient.c,v 1.44.2.14 1999/02/09 04:59:50 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@@ -83,16 +83,19 @@ struct sockaddr_in sockaddr_broadcast;
assert (state_is == state_shouldbe). */
#define ASSERT_STATE(state_is, state_shouldbe) {}
-#ifdef USE_FALLBACK
-struct interface_info fallback_interface;
-#endif
-
u_int16_t local_port;
u_int16_t remote_port;
int log_priority;
int no_daemon;
int save_scripts;
+static char copyright[] =
+"Copyright 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium.";
+static char arr [] = "All rights reserved.";
+static char message [] = "Internet Software Consortium DHCP Client V2.0b1pl11";
+static char contrib [] = "\nPlease contribute if you find this software useful.";
+static char url [] = "For info, please visit http://www.isc.org/dhcp-contrib.html\n";
+
static void usage PROTO ((void));
int main (argc, argv, envp)
@@ -103,6 +106,7 @@ int main (argc, argv, envp)
struct servent *ent;
struct interface_info *ip;
int seed;
+ int quiet;
#ifdef SYSLOG_4_2
openlog ("dhclient", LOG_NDELAY);
@@ -126,6 +130,13 @@ int main (argc, argv, envp)
no_daemon = 1;
} else if (!strcmp (argv [i], "-D")) {
save_scripts = 1;
+ } else if (!strcmp (argv [i], "-lf")) {
+ if (++i == argc)
+ usage ();
+ path_dhclient_db = argv [i];
+ } else if (!strcmp (argv [i], "-q")) {
+ quiet = 1;
+ quiet_interface_discovery = 1;
} else if (argv [i][0] == '-') {
usage ();
} else {
@@ -143,6 +154,15 @@ int main (argc, argv, envp)
interfaces = tmp;
}
}
+
+ if (!quiet) {
+ note (message);
+ note (copyright);
+ note (arr);
+ note (contrib);
+ note (url);
+ }
+
/* Default to the DHCP/BOOTP port. */
if (!local_port) {
ent = getservbyname ("dhcpc", "udp");
@@ -186,11 +206,19 @@ int main (argc, argv, envp)
(struct string_list *)0);
script_go ((struct interface_info *)0);
+ note ("No broadcast interfaces found - exiting.");
/* Nothing more to do. */
exit (0);
} 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_REQUESTED))
+ continue;
script_init (ip, "PREINIT", (struct string_list *)0);
if (ip -> client -> alias)
script_write_params (ip, "alias_",
@@ -240,7 +268,7 @@ int main (argc, argv, envp)
static void usage ()
{
- error ("Usage: dhclient [-c] [-p <port>] [interface]");
+ error ("Usage: dhclient [-c] [-p <port>] [-lf lease-file] [interface]");
}
void cleanup ()
@@ -291,10 +319,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 +464,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 +534,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 +698,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 +901,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 +1007,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;
@@ -1161,6 +1205,14 @@ void send_request (ipp)
ip -> client -> alias);
script_go (ip);
+ /* Now do a preinit on the interface so that we can
+ discover a new address. */
+ script_init (ip, "PREINIT", (struct string_list *)0);
+ if (ip -> client -> alias)
+ script_write_params (ip, "alias_",
+ ip -> client -> alias);
+ script_go (ip);
+
ip -> client -> state = S_INIT;
state_init (ip);
return;
@@ -1195,6 +1247,7 @@ void send_request (ipp)
/* If the lease T2 time has elapsed, or if we're not yet bound,
broadcast the DHCPREQUEST rather than unicasting. */
if (ip -> client -> state == S_REQUESTING ||
+ ip -> client -> state == S_REBOOTING ||
cur_time > ip -> client -> active -> rebind)
destination.sin_addr.s_addr = INADDR_BROADCAST;
else
@@ -1223,16 +1276,15 @@ void send_request (ipp)
inet_ntoa (destination.sin_addr),
ntohs (destination.sin_port));
-#ifdef USE_FALLBACK
- if (destination.sin_addr.s_addr != INADDR_BROADCAST)
- result = send_fallback (&fallback_interface,
- (struct packet *)0,
- &ip -> client -> packet,
- ip -> client -> packet_length,
- from, &destination,
- (struct hardware *)0);
+ if (destination.sin_addr.s_addr != INADDR_BROADCAST &&
+ fallback_interface)
+ result = send_packet (fallback_interface,
+ (struct packet *)0,
+ &ip -> client -> packet,
+ ip -> client -> packet_length,
+ from, &destination,
+ (struct hardware *)0);
else
-#endif /* USE_FALLBACK */
/* Send out a packet. */
result = send_packet (ip, (struct packet *)0,
&ip -> client -> packet,
@@ -1473,18 +1525,20 @@ void make_request (ip, lease)
ip -> client -> packet.hops = 0;
ip -> client -> packet.xid = ip -> client -> xid;
ip -> client -> packet.secs = 0; /* Filled in by send_request. */
- ip -> client -> packet.flags = htons (BOOTP_BROADCAST);
/* If we own the address we're requesting, put it in ciaddr;
otherwise set ciaddr to zero. */
if (ip -> client -> state == S_BOUND ||
ip -> client -> state == S_RENEWING ||
- ip -> client -> state == S_REBINDING)
+ ip -> client -> state == S_REBINDING) {
memcpy (&ip -> client -> packet.ciaddr,
lease -> address.iabuf, lease -> address.len);
- else
+ ip -> client -> packet.flags = 0;
+ } else {
memset (&ip -> client -> packet.ciaddr, 0,
sizeof ip -> client -> packet.ciaddr);
+ ip -> client -> packet.flags = htons (BOOTP_BROADCAST);
+ }
memset (&ip -> client -> packet.yiaddr, 0,
sizeof ip -> client -> packet.yiaddr);
@@ -1636,7 +1690,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,
@@ -1684,36 +1738,45 @@ void rewrite_client_leases ()
fclose (leaseFile);
leaseFile = fopen (path_dhclient_db, "w");
if (!leaseFile)
- error ("can't create /var/db/dhclient.leases: %m");
+ error ("can't create %s: %m", path_dhclient_db);
/* Write out all the leases attached to configured interfaces that
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. */
@@ -1723,7 +1786,7 @@ void write_client_lease (ip, lease)
if (!leaseFile) { /* XXX */
leaseFile = fopen (path_dhclient_db, "w");
if (!leaseFile)
- error ("can't create /var/db/dhclient.leases: %m");
+ error ("can't create %s: %m", path_dhclient_db);
}
fprintf (leaseFile, "lease {\n");
@@ -1751,6 +1814,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 +1860,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
diff --git a/contrib/isc-dhcp/client/scripts/freebsd b/contrib/isc-dhcp/client/scripts/freebsd
index 7236a67a9a9a..77fdc5c9f26e 100755
--- a/contrib/isc-dhcp/client/scripts/freebsd
+++ b/contrib/isc-dhcp/client/scripts/freebsd
@@ -155,6 +155,7 @@ if [ x$reason = xTIMEOUT ]; then
mv /etc/resolv.conf.std /etc/resolv.conf
exit 0
fi
+ fi
ifconfig $interface inet -alias $new_ip_address $medium
for router in $old_routers; do
route delete default $router >/dev/null 2>&1