summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile7
-rw-r--r--bootp.c3
-rw-r--r--client/dhclient.c129
-rw-r--r--common/conflex.c7
-rw-r--r--common/inet.c2
-rw-r--r--common/memory.c3
-rw-r--r--common/options.c54
-rw-r--r--common/socket.c3
-rw-r--r--common/tree.c3
-rw-r--r--conflex.c7
-rw-r--r--confpars.c3
-rw-r--r--dhclient.c129
-rw-r--r--dhcp.h5
-rw-r--r--dhcpd.c3
-rw-r--r--dhcpd.conf2
-rw-r--r--dhcpd.h6
-rw-r--r--dhctoken.h3
-rw-r--r--includes/dhcp.h5
-rw-r--r--includes/dhcpd.h6
-rw-r--r--includes/dhctoken.h3
-rw-r--r--inet.c2
-rw-r--r--memory.c3
-rw-r--r--options.c54
-rw-r--r--server/bootp.c3
-rw-r--r--server/confpars.c3
-rw-r--r--server/dhcpd.c3
-rw-r--r--server/dhcpd.conf2
-rw-r--r--socket.c3
-rw-r--r--tree.c3
29 files changed, 399 insertions, 60 deletions
diff --git a/Makefile b/Makefile
index a81468be..e745f08e 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,14 @@ SRCS = dhcpd.c options.c errwarn.c convert.c conflex.c confpars.c \
hash.c tables.c inet.c
PROG = dhcpd
+all: dhcpd dhclient
+
.include <bsd.prog.mk>
CFLAGS += -DDEBUG -g -Wall -Wstrict-prototypes -Wno-unused \
-Wno-uninitialized -Werror
+
+dhclient: dhclient.o confpars.o alloc.o memory.o options.o \
+ hash.o tables.o inet.o convert.o conflex.o errwarn.o tree.o
+ cc -o dhclient dhclient.o confpars.o alloc.o memory.o options.o \
+ hash.o tables.o inet.o convert.o conflex.o errwarn.o tree.o \ No newline at end of file
diff --git a/bootp.c b/bootp.c
index 348ce0ef..a2e7858a 100644
--- a/bootp.c
+++ b/bootp.c
@@ -3,7 +3,8 @@
BOOTP Protocol support. */
/*
- * Copyright (c) 1995 The Internet Software Consortium. All rights reserved.
+ * Copyright (c) 1995, 1996 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
diff --git a/client/dhclient.c b/client/dhclient.c
new file mode 100644
index 00000000..97115930
--- /dev/null
+++ b/client/dhclient.c
@@ -0,0 +1,129 @@
+/* dhclient.c
+
+ DHCP client program. Intended for testing. */
+
+/*
+ * Copyright (c) 1996 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
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of The Internet Software Consortium nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This software has been written for the Internet Software Consortium
+ * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie
+ * Enterprises. To learn more about the Internet Software Consortium,
+ * see ``http://www.vix.com/isc''. To learn more about Vixie
+ * Enterprises, see ``http://www.vix.com''.
+ */
+
+#include "dhcpd.h"
+#include "dhctoken.h"
+
+TIME cur_time;
+
+int main (argc, argv, envp)
+ int argc;
+ char **argv;
+ char **envp;
+{
+ FILE *cfile = stdin;
+ char *val;
+ int token;
+
+ /* Set up the initial dhcp option universe. */
+ initialize_universes ();
+
+ /* Get the current time... */
+ GET_TIME (&cur_time);
+
+ do {
+ token = peek_token (&val, cfile);
+ if (token == EOF)
+ break;
+ parse_client_statement (cfile);
+ } while (1);
+ exit (0);
+}
+
+/* statement :== host_statement */
+
+void parse_client_statement (cfile)
+ FILE *cfile;
+{
+ char *val;
+ jmp_buf bc;
+ struct host_decl decl;
+ int token;
+ struct dhcp_packet raw;
+ struct packet outpacket, inpacket;
+ int i;
+
+ switch (next_token (&val, cfile)) {
+ case PACKET:
+ memset (&decl, 0, sizeof decl);
+ if (!setjmp (bc)) {
+ do {
+ token = peek_token (&val, cfile);
+ if (token == SEMI) {
+ token = next_token (&val, cfile);
+ break;
+ }
+ parse_host_decl (cfile, &bc, &decl);
+ } while (1);
+ }
+ for (i = 0; i < 256; i++)
+ if (decl.options [i])
+ printf ("option %s\n", dhcp_options [i].name);
+ memset (&outpacket, 0, sizeof outpacket);
+ memset (&raw, 0, sizeof raw);
+ outpacket.raw = &raw;
+ cons_options ((struct packet *)0, &outpacket, &decl, 3);
+ inpacket.raw = &raw;
+ inpacket.packet_length = outpacket.packet_length;
+ parse_options (&inpacket);
+ for (i = 0; i < 256; i++)
+ if (inpacket.options [i].len)
+ printf ("%s=%s\n",
+ dhcp_options [i].name,
+ pretty_print_option
+ (i,
+ inpacket.options [i].data,
+ inpacket.options [i].len));
+ for (i = 0; i < 20; i++)
+ printf ("%s%x", i == 0 ? "" : " ",
+ (unsigned char)raw.options [i]);
+ printf ("\noptions_valid: %d\n", inpacket.options_valid);
+ break;
+ default:
+ parse_warn ("expecting a declaration.");
+ skip_to_semi (cfile);
+ break;
+ }
+}
+
+void cleanup ()
+{
+}
diff --git a/common/conflex.c b/common/conflex.c
index f059a627..33e58318 100644
--- a/common/conflex.c
+++ b/common/conflex.c
@@ -3,7 +3,8 @@
Lexical scanner for dhcpd config file... */
/*
- * Copyright (c) 1995 The Internet Software Consortium. All rights reserved.
+ * Copyright (c) 1995, 1996 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
@@ -296,6 +297,10 @@ static int intern (atom, dfv)
if (!strcasecmp (atom + 1, "ease"))
return LEASE;
break;
+ case 'p':
+ if (!strcasecmp (atom + 1, "acket"))
+ return PACKET;
+ break;
case 'o':
if (!strcasecmp (atom + 1, "ption"))
return OPTION;
diff --git a/common/inet.c b/common/inet.c
index f221f689..fa25efc1 100644
--- a/common/inet.c
+++ b/common/inet.c
@@ -4,7 +4,7 @@
way... */
/*
- * Copyright (c) 1995 The Internet Software Consortium. All rights reserved.
+ * Copyright (c) 1996 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
diff --git a/common/memory.c b/common/memory.c
index 6c1f5502..21b1c010 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -3,7 +3,8 @@
Memory-resident database... */
/*
- * Copyright (c) 1995 The Internet Software Consortium. All rights reserved.
+ * Copyright (c) 1995, 1996 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
diff --git a/common/options.c b/common/options.c
index b9a538a1..e64bfb36 100644
--- a/common/options.c
+++ b/common/options.c
@@ -94,6 +94,8 @@ void parse_option_buffer (packet, buffer, length)
int len;
int code;
+printf ("parse_option_buffer (%x, %x, %d)\n",
+(unsigned long)packet, (unsigned long)buffer, length);
for (s = buffer; *s != DHO_END && s < end; ) {
code = s [0];
/* Pad options don't have a length - just skip them. */
@@ -124,6 +126,8 @@ void parse_option_buffer (packet, buffer, length)
t [len] = 0;
packet -> options [code].len = len;
packet -> options [code].data = t;
+printf ("%s=%s\n", dhcp_options [code].name,
+pretty_print_option (code, t, len));
} else {
/* If it's a repeat, concatenate it to whatever
we last saw. This is really only required
@@ -162,7 +166,7 @@ void cons_options (inpacket, outpacket, hp, overload)
option_mask temp; /* Working option mask. */
unsigned char *priority_list;
int priority_len;
- unsigned char *buffer = inpacket -> raw -> options;
+ unsigned char *buffer = outpacket -> raw -> options;
int buflen, bufix = 0;
int reserved = 3; /* Reserved space for overload. */
unsigned char *overload_ptr = (unsigned char *)0;
@@ -186,7 +190,7 @@ void cons_options (inpacket, outpacket, hp, overload)
/* XXX Maybe it would be safe to assume that we can send a packet
to the client that's as big as the one it sent us, even if it
didn't specify a large MTU. */
- if (inpacket -> options [DHO_DHCP_MAX_MESSAGE_SIZE].data)
+ if (inpacket && inpacket -> options [DHO_DHCP_MAX_MESSAGE_SIZE].data)
buflen = (getUShort (inpacket -> options
[DHO_DHCP_MAX_MESSAGE_SIZE].data)
- DHCP_FIXED_LEN);
@@ -195,7 +199,8 @@ void cons_options (inpacket, outpacket, hp, overload)
/* If the client has provided a list of options that it wishes
returned, use it to prioritize. */
- if (inpacket -> options [DHO_DHCP_PARAMETER_REQUEST_LIST].data) {
+ if (inpacket &&
+ inpacket -> options [DHO_DHCP_PARAMETER_REQUEST_LIST].data) {
priority_list =
inpacket -> options
[DHO_DHCP_PARAMETER_REQUEST_LIST].data;
@@ -219,6 +224,10 @@ void cons_options (inpacket, outpacket, hp, overload)
if (hp -> options [i])
OPTION_SET (options_have, i);
+ /* Put the cookie up front... */
+ memcpy (buffer, DHCP_OPTIONS_COOKIE, 4);
+ bufix += 4;
+
again:
/* Try copying out options that fit easily. */
for (i = 0; i < priority_len; i++) {
@@ -241,6 +250,13 @@ void cons_options (inpacket, outpacket, hp, overload)
if (!tree_evaluate (hp -> options [code]))
continue;
+printf ("hp -> options [%d] = %x %d %d %d %x\n",
+code, (unsigned long)(hp -> options [code] -> value),
+hp -> options [code] -> len, hp -> options [code] -> buf_size,
+hp -> options [code] -> timeout,
+(unsigned long)(hp -> options [code] -> tree));
+printf ("buffer = %x buflen = %d bufix = %d\n",
+(unsigned int)buffer, buflen, bufix);
/* We should now have a constant length for the option. */
length = (hp -> options [code] -> len - stored_length [code]);
@@ -255,7 +271,7 @@ void cons_options (inpacket, outpacket, hp, overload)
}
/* Otherwise, store the option. */
- result = store_option (outpacket, code,
+ result = store_option (hp, code,
buffer + bufix,
buflen - bufix - reserved,
stored_length);
@@ -278,6 +294,10 @@ void cons_options (inpacket, outpacket, hp, overload)
}
}
+ if (buffer == outpacket -> raw -> options) {
+ outpacket -> packet_length = DHCP_FIXED_LEN + bufix;
+ }
+
/* If we didn't miss any options, we're done. */
/* XXX Maybe we want to try to encode options the client didn't
request but that we have available? */
@@ -291,7 +311,7 @@ void cons_options (inpacket, outpacket, hp, overload)
overloading. */
if (reserved && missed == 1
&& (bufix + OPTION_SPACE (missed_length) <= buflen)) {
- result = store_option (outpacket, missed_code,
+ result = store_option (hp, missed_code,
buffer + bufix, buflen - bufix,
stored_length);
bufix += result;
@@ -314,7 +334,7 @@ void cons_options (inpacket, outpacket, hp, overload)
option into the current buffer and part into the next. */
if (bufix + OPTION_SPACE (missed_length) + reserved
< buflen + (overload & 1 ? 128 : 0) + (overload & 2 ? 64 : 0)) {
- result = store_option (outpacket, missed_code,
+ result = store_option (hp, missed_code,
buffer + bufix,
buflen - bufix - reserved,
stored_length);
@@ -358,16 +378,16 @@ void cons_options (inpacket, outpacket, hp, overload)
/* Can we use the file buffer? */
if (overload & 1) {
- buffer = inpacket -> raw -> file;
- buflen = sizeof inpacket -> raw -> file;
+ buffer = outpacket -> raw -> file;
+ buflen = sizeof outpacket -> raw -> file;
bufix = 0;
overload &= ~1;
goto again;
}
/* Can we use the sname buffer? */
if (overload & 2) {
- buffer = inpacket -> raw -> sname;
- buflen = sizeof inpacket -> raw -> sname;
+ buffer = outpacket -> raw -> sname;
+ buflen = sizeof outpacket -> raw -> sname;
bufix = 0;
overload &= ~2;
goto again;
@@ -382,18 +402,18 @@ void cons_options (inpacket, outpacket, hp, overload)
data that has been stored so far. Return 1 if all the option data
has been stored. */
-int store_option (packet, code, buffer, buflen, stored_length)
- struct packet *packet;
+int store_option (hp, code, buffer, buflen, stored_length)
+ struct host_decl *hp;
unsigned char code;
unsigned char *buffer;
int buflen;
int *stored_length;
{
- int length = packet -> options [code].len - stored_length [code];
+ int length = hp -> options [code] -> len - stored_length [code];
int bufix = 0;
- int rv = 1;
+printf ("store_option: length = %d buflen = %d packet %d stored %d\n",
+ length, buflen, hp -> options [code] -> len, stored_length [code]);
if (length > buflen) {
- rv = 0;
length = buflen;
}
@@ -406,13 +426,13 @@ int store_option (packet, code, buffer, buflen, stored_length)
unsigned char incr = length > 255 ? 255 : length;
buffer [bufix] = code;
buffer [bufix + 1] = incr;
- memcpy (buffer + bufix + 2, (packet -> options [code].data
+ memcpy (buffer + bufix + 2, (hp -> options [code] -> value
+ stored_length [code]), incr);
length -= incr;
stored_length [code] += incr;
bufix += 2 + incr;
}
- return rv;
+ return bufix;
}
/* Format the specified option so that a human can easily read it. */
diff --git a/common/socket.c b/common/socket.c
index e3e0974e..3a013cf0 100644
--- a/common/socket.c
+++ b/common/socket.c
@@ -3,7 +3,8 @@
BSD socket interface code... */
/*
- * Copyright (c) 1995 The Internet Software Consortium. All rights reserved.
+ * Copyright (c) 1995, 1996 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
diff --git a/common/tree.c b/common/tree.c
index 102d0efd..7b11cd3e 100644
--- a/common/tree.c
+++ b/common/tree.c
@@ -295,7 +295,8 @@ static TIME do_host_lookup (bufix, bufp, bufcount, dns)
/* If the record hasn't timed out, just copy the data and return. */
if (cur_time <= dns -> timeout) {
debug ("easy copy: %x %d %x",
- dns -> data, dns -> data_len, *(int *)(dns -> data));
+ dns -> data, dns -> data_len,
+ dns -> data ? *(int *)(dns -> data) : 0);
do_data_copy (bufix, bufp, bufcount,
dns -> data, dns -> data_len);
return dns -> timeout;
diff --git a/conflex.c b/conflex.c
index f059a627..33e58318 100644
--- a/conflex.c
+++ b/conflex.c
@@ -3,7 +3,8 @@
Lexical scanner for dhcpd config file... */
/*
- * Copyright (c) 1995 The Internet Software Consortium. All rights reserved.
+ * Copyright (c) 1995, 1996 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
@@ -296,6 +297,10 @@ static int intern (atom, dfv)
if (!strcasecmp (atom + 1, "ease"))
return LEASE;
break;
+ case 'p':
+ if (!strcasecmp (atom + 1, "acket"))
+ return PACKET;
+ break;
case 'o':
if (!strcasecmp (atom + 1, "ption"))
return OPTION;
diff --git a/confpars.c b/confpars.c
index 4e40217d..7335de6f 100644
--- a/confpars.c
+++ b/confpars.c
@@ -3,7 +3,8 @@
Parser for dhcpd config file... */
/*
- * Copyright (c) 1995 The Internet Software Consortium. All rights reserved.
+ * Copyright (c) 1995, 1996 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
diff --git a/dhclient.c b/dhclient.c
new file mode 100644
index 00000000..97115930
--- /dev/null
+++ b/dhclient.c
@@ -0,0 +1,129 @@
+/* dhclient.c
+
+ DHCP client program. Intended for testing. */
+
+/*
+ * Copyright (c) 1996 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
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of The Internet Software Consortium nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This software has been written for the Internet Software Consortium
+ * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie
+ * Enterprises. To learn more about the Internet Software Consortium,
+ * see ``http://www.vix.com/isc''. To learn more about Vixie
+ * Enterprises, see ``http://www.vix.com''.
+ */
+
+#include "dhcpd.h"
+#include "dhctoken.h"
+
+TIME cur_time;
+
+int main (argc, argv, envp)
+ int argc;
+ char **argv;
+ char **envp;
+{
+ FILE *cfile = stdin;
+ char *val;
+ int token;
+
+ /* Set up the initial dhcp option universe. */
+ initialize_universes ();
+
+ /* Get the current time... */
+ GET_TIME (&cur_time);
+
+ do {
+ token = peek_token (&val, cfile);
+ if (token == EOF)
+ break;
+ parse_client_statement (cfile);
+ } while (1);
+ exit (0);
+}
+
+/* statement :== host_statement */
+
+void parse_client_statement (cfile)
+ FILE *cfile;
+{
+ char *val;
+ jmp_buf bc;
+ struct host_decl decl;
+ int token;
+ struct dhcp_packet raw;
+ struct packet outpacket, inpacket;
+ int i;
+
+ switch (next_token (&val, cfile)) {
+ case PACKET:
+ memset (&decl, 0, sizeof decl);
+ if (!setjmp (bc)) {
+ do {
+ token = peek_token (&val, cfile);
+ if (token == SEMI) {
+ token = next_token (&val, cfile);
+ break;
+ }
+ parse_host_decl (cfile, &bc, &decl);
+ } while (1);
+ }
+ for (i = 0; i < 256; i++)
+ if (decl.options [i])
+ printf ("option %s\n", dhcp_options [i].name);
+ memset (&outpacket, 0, sizeof outpacket);
+ memset (&raw, 0, sizeof raw);
+ outpacket.raw = &raw;
+ cons_options ((struct packet *)0, &outpacket, &decl, 3);
+ inpacket.raw = &raw;
+ inpacket.packet_length = outpacket.packet_length;
+ parse_options (&inpacket);
+ for (i = 0; i < 256; i++)
+ if (inpacket.options [i].len)
+ printf ("%s=%s\n",
+ dhcp_options [i].name,
+ pretty_print_option
+ (i,
+ inpacket.options [i].data,
+ inpacket.options [i].len));
+ for (i = 0; i < 20; i++)
+ printf ("%s%x", i == 0 ? "" : " ",
+ (unsigned char)raw.options [i]);
+ printf ("\noptions_valid: %d\n", inpacket.options_valid);
+ break;
+ default:
+ parse_warn ("expecting a declaration.");
+ skip_to_semi (cfile);
+ break;
+ }
+}
+
+void cleanup ()
+{
+}
diff --git a/dhcp.h b/dhcp.h
index f06571d1..5dfec751 100644
--- a/dhcp.h
+++ b/dhcp.h
@@ -64,8 +64,9 @@ struct dhcp_packet {
char chaddr [16]; /* Client hardware address */
char sname [64]; /* Server name */
char file [128]; /* Boot filename */
- char options [DHCP_OPTION_LEN]; /* Optional parameters
- (actual length dependent on MTU). */
+ unsigned char options [DHCP_OPTION_LEN];
+ /* Optional parameters
+ (actual length dependent on MTU). */
};
/* BOOTP (rfc951) message types */
diff --git a/dhcpd.c b/dhcpd.c
index d5a199be..c298c02e 100644
--- a/dhcpd.c
+++ b/dhcpd.c
@@ -3,7 +3,8 @@
DHCP Server Daemon. */
/*
- * Copyright (c) 1995 The Internet Software Consortium. All rights reserved.
+ * Copyright (c) 1995, 1996 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
diff --git a/dhcpd.conf b/dhcpd.conf
index 48257840..10d66a37 100644
--- a/dhcpd.conf
+++ b/dhcpd.conf
@@ -26,5 +26,5 @@ host avogadro
lease 204.254.239.11
starts 2 96/2/6 10:14:02
ends 2 96/2/6 11:15:02
- uid 08:00:2b:4c:39:12
+ hardware ethernet 08:00:2b:4c:39:12
host avogadro;
diff --git a/dhcpd.h b/dhcpd.h
index 5a7c07d1..f5340061 100644
--- a/dhcpd.h
+++ b/dhcpd.h
@@ -149,7 +149,7 @@ void parse_options PROTO ((struct packet *));
void parse_option_buffer PROTO ((struct packet *, unsigned char *, int));
void cons_options PROTO ((struct packet *, struct packet *,
struct host_decl *, int));
-int store_option PROTO ((struct packet *, unsigned char,
+int store_option PROTO ((struct host_decl *, unsigned char,
unsigned char *, int, int *));
char *pretty_print_option PROTO ((unsigned char, unsigned char *, int));
@@ -287,3 +287,7 @@ struct iaddr ip_addr (struct iaddr, struct iaddr, unsigned long);
unsigned long host_addr (struct iaddr, struct iaddr);
int addr_eq (struct iaddr, struct iaddr);
char *piaddr (struct iaddr);
+
+/* dhclient.c */
+void parse_client_statement (FILE *);
+
diff --git a/dhctoken.h b/dhctoken.h
index 1f211f17..f04fae5b 100644
--- a/dhctoken.h
+++ b/dhctoken.h
@@ -63,7 +63,8 @@
#define CLASS 270
#define LEASE 271
#define RANGE 272
-#define LAST_TOKEN RANGE
+#define PACKET 273
+#define LAST_TOKEN PACKET
#define is_identifier(x) ((x) >= FIRST_TOKEN && \
(x) <= LAST_TOKEN && \
diff --git a/includes/dhcp.h b/includes/dhcp.h
index f06571d1..5dfec751 100644
--- a/includes/dhcp.h
+++ b/includes/dhcp.h
@@ -64,8 +64,9 @@ struct dhcp_packet {
char chaddr [16]; /* Client hardware address */
char sname [64]; /* Server name */
char file [128]; /* Boot filename */
- char options [DHCP_OPTION_LEN]; /* Optional parameters
- (actual length dependent on MTU). */
+ unsigned char options [DHCP_OPTION_LEN];
+ /* Optional parameters
+ (actual length dependent on MTU). */
};
/* BOOTP (rfc951) message types */
diff --git a/includes/dhcpd.h b/includes/dhcpd.h
index 5a7c07d1..f5340061 100644
--- a/includes/dhcpd.h
+++ b/includes/dhcpd.h
@@ -149,7 +149,7 @@ void parse_options PROTO ((struct packet *));
void parse_option_buffer PROTO ((struct packet *, unsigned char *, int));
void cons_options PROTO ((struct packet *, struct packet *,
struct host_decl *, int));
-int store_option PROTO ((struct packet *, unsigned char,
+int store_option PROTO ((struct host_decl *, unsigned char,
unsigned char *, int, int *));
char *pretty_print_option PROTO ((unsigned char, unsigned char *, int));
@@ -287,3 +287,7 @@ struct iaddr ip_addr (struct iaddr, struct iaddr, unsigned long);
unsigned long host_addr (struct iaddr, struct iaddr);
int addr_eq (struct iaddr, struct iaddr);
char *piaddr (struct iaddr);
+
+/* dhclient.c */
+void parse_client_statement (FILE *);
+
diff --git a/includes/dhctoken.h b/includes/dhctoken.h
index 1f211f17..f04fae5b 100644
--- a/includes/dhctoken.h
+++ b/includes/dhctoken.h
@@ -63,7 +63,8 @@
#define CLASS 270
#define LEASE 271
#define RANGE 272
-#define LAST_TOKEN RANGE
+#define PACKET 273
+#define LAST_TOKEN PACKET
#define is_identifier(x) ((x) >= FIRST_TOKEN && \
(x) <= LAST_TOKEN && \
diff --git a/inet.c b/inet.c
index f221f689..fa25efc1 100644
--- a/inet.c
+++ b/inet.c
@@ -4,7 +4,7 @@
way... */
/*
- * Copyright (c) 1995 The Internet Software Consortium. All rights reserved.
+ * Copyright (c) 1996 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
diff --git a/memory.c b/memory.c
index 6c1f5502..21b1c010 100644
--- a/memory.c
+++ b/memory.c
@@ -3,7 +3,8 @@
Memory-resident database... */
/*
- * Copyright (c) 1995 The Internet Software Consortium. All rights reserved.
+ * Copyright (c) 1995, 1996 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
diff --git a/options.c b/options.c
index b9a538a1..e64bfb36 100644
--- a/options.c
+++ b/options.c
@@ -94,6 +94,8 @@ void parse_option_buffer (packet, buffer, length)
int len;
int code;
+printf ("parse_option_buffer (%x, %x, %d)\n",
+(unsigned long)packet, (unsigned long)buffer, length);
for (s = buffer; *s != DHO_END && s < end; ) {
code = s [0];
/* Pad options don't have a length - just skip them. */
@@ -124,6 +126,8 @@ void parse_option_buffer (packet, buffer, length)
t [len] = 0;
packet -> options [code].len = len;
packet -> options [code].data = t;
+printf ("%s=%s\n", dhcp_options [code].name,
+pretty_print_option (code, t, len));
} else {
/* If it's a repeat, concatenate it to whatever
we last saw. This is really only required
@@ -162,7 +166,7 @@ void cons_options (inpacket, outpacket, hp, overload)
option_mask temp; /* Working option mask. */
unsigned char *priority_list;
int priority_len;
- unsigned char *buffer = inpacket -> raw -> options;
+ unsigned char *buffer = outpacket -> raw -> options;
int buflen, bufix = 0;
int reserved = 3; /* Reserved space for overload. */
unsigned char *overload_ptr = (unsigned char *)0;
@@ -186,7 +190,7 @@ void cons_options (inpacket, outpacket, hp, overload)
/* XXX Maybe it would be safe to assume that we can send a packet
to the client that's as big as the one it sent us, even if it
didn't specify a large MTU. */
- if (inpacket -> options [DHO_DHCP_MAX_MESSAGE_SIZE].data)
+ if (inpacket && inpacket -> options [DHO_DHCP_MAX_MESSAGE_SIZE].data)
buflen = (getUShort (inpacket -> options
[DHO_DHCP_MAX_MESSAGE_SIZE].data)
- DHCP_FIXED_LEN);
@@ -195,7 +199,8 @@ void cons_options (inpacket, outpacket, hp, overload)
/* If the client has provided a list of options that it wishes
returned, use it to prioritize. */
- if (inpacket -> options [DHO_DHCP_PARAMETER_REQUEST_LIST].data) {
+ if (inpacket &&
+ inpacket -> options [DHO_DHCP_PARAMETER_REQUEST_LIST].data) {
priority_list =
inpacket -> options
[DHO_DHCP_PARAMETER_REQUEST_LIST].data;
@@ -219,6 +224,10 @@ void cons_options (inpacket, outpacket, hp, overload)
if (hp -> options [i])
OPTION_SET (options_have, i);
+ /* Put the cookie up front... */
+ memcpy (buffer, DHCP_OPTIONS_COOKIE, 4);
+ bufix += 4;
+
again:
/* Try copying out options that fit easily. */
for (i = 0; i < priority_len; i++) {
@@ -241,6 +250,13 @@ void cons_options (inpacket, outpacket, hp, overload)
if (!tree_evaluate (hp -> options [code]))
continue;
+printf ("hp -> options [%d] = %x %d %d %d %x\n",
+code, (unsigned long)(hp -> options [code] -> value),
+hp -> options [code] -> len, hp -> options [code] -> buf_size,
+hp -> options [code] -> timeout,
+(unsigned long)(hp -> options [code] -> tree));
+printf ("buffer = %x buflen = %d bufix = %d\n",
+(unsigned int)buffer, buflen, bufix);
/* We should now have a constant length for the option. */
length = (hp -> options [code] -> len - stored_length [code]);
@@ -255,7 +271,7 @@ void cons_options (inpacket, outpacket, hp, overload)
}
/* Otherwise, store the option. */
- result = store_option (outpacket, code,
+ result = store_option (hp, code,
buffer + bufix,
buflen - bufix - reserved,
stored_length);
@@ -278,6 +294,10 @@ void cons_options (inpacket, outpacket, hp, overload)
}
}
+ if (buffer == outpacket -> raw -> options) {
+ outpacket -> packet_length = DHCP_FIXED_LEN + bufix;
+ }
+
/* If we didn't miss any options, we're done. */
/* XXX Maybe we want to try to encode options the client didn't
request but that we have available? */
@@ -291,7 +311,7 @@ void cons_options (inpacket, outpacket, hp, overload)
overloading. */
if (reserved && missed == 1
&& (bufix + OPTION_SPACE (missed_length) <= buflen)) {
- result = store_option (outpacket, missed_code,
+ result = store_option (hp, missed_code,
buffer + bufix, buflen - bufix,
stored_length);
bufix += result;
@@ -314,7 +334,7 @@ void cons_options (inpacket, outpacket, hp, overload)
option into the current buffer and part into the next. */
if (bufix + OPTION_SPACE (missed_length) + reserved
< buflen + (overload & 1 ? 128 : 0) + (overload & 2 ? 64 : 0)) {
- result = store_option (outpacket, missed_code,
+ result = store_option (hp, missed_code,
buffer + bufix,
buflen - bufix - reserved,
stored_length);
@@ -358,16 +378,16 @@ void cons_options (inpacket, outpacket, hp, overload)
/* Can we use the file buffer? */
if (overload & 1) {
- buffer = inpacket -> raw -> file;
- buflen = sizeof inpacket -> raw -> file;
+ buffer = outpacket -> raw -> file;
+ buflen = sizeof outpacket -> raw -> file;
bufix = 0;
overload &= ~1;
goto again;
}
/* Can we use the sname buffer? */
if (overload & 2) {
- buffer = inpacket -> raw -> sname;
- buflen = sizeof inpacket -> raw -> sname;
+ buffer = outpacket -> raw -> sname;
+ buflen = sizeof outpacket -> raw -> sname;
bufix = 0;
overload &= ~2;
goto again;
@@ -382,18 +402,18 @@ void cons_options (inpacket, outpacket, hp, overload)
data that has been stored so far. Return 1 if all the option data
has been stored. */
-int store_option (packet, code, buffer, buflen, stored_length)
- struct packet *packet;
+int store_option (hp, code, buffer, buflen, stored_length)
+ struct host_decl *hp;
unsigned char code;
unsigned char *buffer;
int buflen;
int *stored_length;
{
- int length = packet -> options [code].len - stored_length [code];
+ int length = hp -> options [code] -> len - stored_length [code];
int bufix = 0;
- int rv = 1;
+printf ("store_option: length = %d buflen = %d packet %d stored %d\n",
+ length, buflen, hp -> options [code] -> len, stored_length [code]);
if (length > buflen) {
- rv = 0;
length = buflen;
}
@@ -406,13 +426,13 @@ int store_option (packet, code, buffer, buflen, stored_length)
unsigned char incr = length > 255 ? 255 : length;
buffer [bufix] = code;
buffer [bufix + 1] = incr;
- memcpy (buffer + bufix + 2, (packet -> options [code].data
+ memcpy (buffer + bufix + 2, (hp -> options [code] -> value
+ stored_length [code]), incr);
length -= incr;
stored_length [code] += incr;
bufix += 2 + incr;
}
- return rv;
+ return bufix;
}
/* Format the specified option so that a human can easily read it. */
diff --git a/server/bootp.c b/server/bootp.c
index 348ce0ef..a2e7858a 100644
--- a/server/bootp.c
+++ b/server/bootp.c
@@ -3,7 +3,8 @@
BOOTP Protocol support. */
/*
- * Copyright (c) 1995 The Internet Software Consortium. All rights reserved.
+ * Copyright (c) 1995, 1996 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
diff --git a/server/confpars.c b/server/confpars.c
index 4e40217d..7335de6f 100644
--- a/server/confpars.c
+++ b/server/confpars.c
@@ -3,7 +3,8 @@
Parser for dhcpd config file... */
/*
- * Copyright (c) 1995 The Internet Software Consortium. All rights reserved.
+ * Copyright (c) 1995, 1996 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
diff --git a/server/dhcpd.c b/server/dhcpd.c
index d5a199be..c298c02e 100644
--- a/server/dhcpd.c
+++ b/server/dhcpd.c
@@ -3,7 +3,8 @@
DHCP Server Daemon. */
/*
- * Copyright (c) 1995 The Internet Software Consortium. All rights reserved.
+ * Copyright (c) 1995, 1996 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
diff --git a/server/dhcpd.conf b/server/dhcpd.conf
index 48257840..10d66a37 100644
--- a/server/dhcpd.conf
+++ b/server/dhcpd.conf
@@ -26,5 +26,5 @@ host avogadro
lease 204.254.239.11
starts 2 96/2/6 10:14:02
ends 2 96/2/6 11:15:02
- uid 08:00:2b:4c:39:12
+ hardware ethernet 08:00:2b:4c:39:12
host avogadro;
diff --git a/socket.c b/socket.c
index e3e0974e..3a013cf0 100644
--- a/socket.c
+++ b/socket.c
@@ -3,7 +3,8 @@
BSD socket interface code... */
/*
- * Copyright (c) 1995 The Internet Software Consortium. All rights reserved.
+ * Copyright (c) 1995, 1996 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
diff --git a/tree.c b/tree.c
index 102d0efd..7b11cd3e 100644
--- a/tree.c
+++ b/tree.c
@@ -295,7 +295,8 @@ static TIME do_host_lookup (bufix, bufp, bufcount, dns)
/* If the record hasn't timed out, just copy the data and return. */
if (cur_time <= dns -> timeout) {
debug ("easy copy: %x %d %x",
- dns -> data, dns -> data_len, *(int *)(dns -> data));
+ dns -> data, dns -> data_len,
+ dns -> data ? *(int *)(dns -> data) : 0);
do_data_copy (bufix, bufp, bufcount,
dns -> data, dns -> data_len);
return dns -> timeout;