summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcvs2git <source@isc.org>1996-03-16 17:56:08 +0000
committercvs2git <source@isc.org>1996-03-16 17:56:08 +0000
commit24721101a8633584338964a7fb5ff1154dc86744 (patch)
treeed52c5c15d28c170c10f0b94675b400188e0f588
parentf76ebbfdcf3ad587eed7e664fe1a57fabcf34bca (diff)
downloadisc-dhcp-BETA-1.tar.gz
This commit was manufactured by cvs2git to create tag 'BETA-1'.BETA-1
-rw-r--r--common/alloc.c211
-rw-r--r--common/conflex.c358
-rw-r--r--common/errwarn.c200
-rw-r--r--common/hash.c156
-rw-r--r--common/inet.c154
-rw-r--r--common/memory.c545
-rw-r--r--common/options.c520
-rw-r--r--common/print.c155
-rw-r--r--common/socket.c471
-rw-r--r--common/tables.c670
-rw-r--r--common/tree.c394
11 files changed, 0 insertions, 3834 deletions
diff --git a/common/alloc.c b/common/alloc.c
deleted file mode 100644
index 4647b794..00000000
--- a/common/alloc.c
+++ /dev/null
@@ -1,211 +0,0 @@
-/* alloc.c
-
- Memory allocation... */
-
-/*
- * Copyright (c) 1995 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''.
- */
-
-#ifndef lint
-static char copyright[] =
-"@(#) Copyright (c) 1995 The Internet Software Consortium. All rights reserved.\n";
-#endif /* not lint */
-
-#include "dhcpd.h"
-
-struct dhcp_packet *dhcp_free_list;
-struct packet *packet_free_list;
-
-VOIDPTR dmalloc (size, name)
- int size;
- char *name;
-{
- VOIDPTR foo = (VOIDPTR)malloc (size);
- if (!foo)
- warn ("No memory for %s.", name);
- return foo;
-}
-
-void dfree (ptr, name)
- VOIDPTR ptr;
- char *name;
-{
- free (ptr);
-}
-
-struct packet *new_packet (name)
- char *name;
-{
- struct packet *rval;
- rval = (struct packet *)dmalloc (sizeof (struct packet), name);
- return rval;
-}
-
-struct dhcp_packet *new_dhcp_packet (name)
- char *name;
-{
- struct dhcp_packet *rval;
- rval = (struct dhcp_packet *)dmalloc (sizeof (struct dhcp_packet),
- name);
- return rval;
-}
-
-struct tree *new_tree (name)
- char *name;
-{
- struct tree *rval = dmalloc (sizeof (struct tree), name);
- return rval;
-}
-
-struct tree_cache *new_tree_cache (name)
- char *name;
-{
- struct tree_cache *rval = dmalloc (sizeof (struct tree_cache), name);
- return rval;
-}
-
-struct hash_table *new_hash_table (count, name)
- int count;
- char *name;
-{
- struct hash_table *rval = dmalloc (sizeof (struct hash_table)
- - (DEFAULT_HASH_SIZE
- * sizeof (struct hash_bucket *))
- + (count
- * sizeof (struct hash_bucket *)),
- name);
- rval -> hash_count = count;
- return rval;
-}
-
-struct hash_bucket *new_hash_bucket (name)
- char *name;
-{
- struct hash_bucket *rval = dmalloc (sizeof (struct hash_bucket), name);
- return rval;
-}
-
-struct lease *new_leases (n, name)
- int n;
- char *name;
-{
- struct lease *rval = dmalloc (n * sizeof (struct lease), name);
- return rval;
-}
-
-struct lease *new_lease (name)
- char *name;
-{
- struct lease *rval = dmalloc (sizeof (struct lease), name);
- return rval;
-}
-
-struct subnet *new_subnet (name)
- char *name;
-{
- struct subnet *rval = dmalloc (sizeof (struct subnet), name);
- return rval;
-}
-
-struct class *new_class (name)
- char *name;
-{
- struct class *rval = dmalloc (sizeof (struct class), name);
- return rval;
-}
-
-void free_class (ptr, name)
- struct class *ptr;
- char *name;
-{
- dfree ((VOIDPTR)ptr, name);
-}
-
-void free_subnet (ptr, name)
- struct subnet *ptr;
- char *name;
-{
- dfree ((VOIDPTR)ptr, name);
-}
-
-void free_lease (ptr, name)
- struct lease *ptr;
- char *name;
-{
- dfree ((VOIDPTR)ptr, name);
-}
-
-void free_hash_bucket (ptr, name)
- struct hash_bucket *ptr;
- char *name;
-{
- dfree ((VOIDPTR)ptr, name);
-}
-
-void free_hash_table (ptr, name)
- struct hash_table *ptr;
- char *name;
-{
- dfree ((VOIDPTR)ptr, name);
-}
-
-void free_tree_cache (ptr, name)
- struct tree_cache *ptr;
- char *name;
-{
- dfree ((VOIDPTR)ptr, name);
-}
-
-void free_packet (ptr, name)
- struct packet *ptr;
- char *name;
-{
- dfree ((VOIDPTR)ptr, name);
-}
-
-void free_dhcp_packet (ptr, name)
- struct dhcp_packet *ptr;
- char *name;
-{
- dfree ((VOIDPTR)ptr, name);
-}
-
-void free_tree (ptr, name)
- struct tree *ptr;
- char *name;
-{
- dfree ((VOIDPTR)ptr, name);
-}
diff --git a/common/conflex.c b/common/conflex.c
deleted file mode 100644
index 57eb1ecf..00000000
--- a/common/conflex.c
+++ /dev/null
@@ -1,358 +0,0 @@
-/* conflex.c
-
- Lexical scanner for dhcpd config file... */
-
-/*
- * 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
- * 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''.
- */
-
-#ifndef lint
-static char copyright[] =
-"@(#) Copyright (c) 1995 The Internet Software Consortium. All rights reserved.\n";
-#endif /* not lint */
-
-#include "dhcpd.h"
-#include "dhctoken.h"
-#include <ctype.h>
-
-static int line;
-static int lpos;
-int tlpos;
-int tline;
-static int token;
-static int ugflag;
-static char *tval;
-static char tokbuf [1500];
-
-static int get_char PROTO ((FILE *));
-static int get_token PROTO ((FILE *));
-static void skip_to_eol PROTO ((FILE *));
-static int read_string PROTO ((FILE *));
-static int read_number PROTO ((int, FILE *));
-static int read_num_or_atom PROTO ((int, FILE *));
-static int intern PROTO ((char *, int));
-
-static int get_char (cfile)
- FILE *cfile;
-{
- char c = getc (cfile);
- if (!ugflag) {
- if (c == EOL) {
- line++;
- lpos = 1;
- } else {
- lpos++;
- }
- } else
- ugflag = 0;
- return c;
-}
-
-static int get_token (cfile)
- FILE *cfile;
-{
- int c;
- int i;
- int ttok;
-#ifdef DEBUG_TOKENS
- static char tb [2];
-#endif
-
- do {
- c = get_char (cfile);
- if (isascii (c) && isspace (c))
- continue;
- if (c == '#') {
- skip_to_eol (cfile);
- continue;
- }
- tlpos = lpos;
- tline = line;
- if (c == '"') {
- ttok = read_string (cfile);
- break;
- }
- if ((isascii (c) && isdigit (c)) || c == '-') {
- ttok = read_number (c, cfile);
- break;
- } else if (isascii (c) && isalpha (c)) {
- ttok = read_num_or_atom (c, cfile);
- break;
- } else {
-#ifdef DEBUG_TOKENS
- tb [0] = c;
- tb [1] = 0;
- tval = tb;
-#else
- tval = 0;
-#endif
- ttok = c;
- break;
- }
- } while (1);
- return ttok;
-}
-
-int next_token (rval, cfile)
- char **rval;
- FILE *cfile;
-{
- int rv;
-
- if (token) {
- rv = token;
- token = 0;
- } else {
- rv = get_token (cfile);
- }
- if (rval)
- *rval = tval;
-#ifdef DEBUG_TOKENS
- fprintf (stderr, "%s:%d ", tval, rv);
-#endif
- return rv;
-}
-
-int peek_token (rval, cfile)
- char **rval;
- FILE *cfile;
-{
- if (!token)
- token = get_token (cfile);
- if (rval)
- *rval = tval;
-#ifdef DEBUG_TOKENS
- fprintf (stderr, "(%s:%d) ", tval, token);
-#endif
- return token;
-}
-
-static void skip_to_eol (cfile)
- FILE *cfile;
-{
- int c;
- do {
- c = get_char (cfile);
- if (c == EOF)
- return;
- if (c == EOL) {
- ungetc (c, cfile);
- ugflag = 1;
- return;
- }
- } while (1);
-}
-
-static int read_string (cfile)
- FILE *cfile;
-{
- int i;
- int bs = 0;
- int c;
-
- for (i = 0; i < sizeof tokbuf; i++) {
- c = get_char (cfile);
- if (c == EOF) {
- parse_warn ("eof in string constant");
- break;
- }
- if (bs) {
- bs = 0;
- tokbuf [i] = c;
- } else if (c == '\\')
- bs = 1;
- else if (c == '"')
- break;
- else
- tokbuf [i] = c;
- }
- /* Normally, I'd feel guilty about this, but we're talking about
- strings that'll fit in a DHCP packet here... */
- if (i == sizeof tokbuf) {
- parse_warn ("string constant larger than internal buffer");
- --i;
- }
- tokbuf [i] = 0;
- tval = tokbuf;
- return STRING;
-}
-
-static int read_number (c, cfile)
- int c;
- FILE *cfile;
-{
- int seenx = 0;
- int i = 0;
- tokbuf [i++] = c;
- for (; i < sizeof tokbuf; i++) {
- c = get_char (cfile);
- if (!seenx && c == 'x')
- seenx = 1;
- else if (!isascii (c) || !isxdigit (c)) {
- ungetc (c, cfile);
- ugflag = 1;
- break;
- }
- tokbuf [i] = c;
- }
- if (i == sizeof tokbuf) {
- parse_warn ("numeric token larger than internal buffer");
- --i;
- }
- tokbuf [i] = 0;
- tval = tokbuf;
- return NUMBER;
-}
-
-static int read_num_or_atom (c, cfile)
- int c;
- FILE *cfile;
-{
- int i = 0;
- int rv = NUMBER_OR_ATOM;
- tokbuf [i++] = c;
- for (; i < sizeof tokbuf; i++) {
- c = get_char (cfile);
- if (!isascii (c) ||
- (c != '-' && c != '_' && !isalnum (c))) {
- ungetc (c, cfile);
- ugflag = 1;
- break;
- }
- if (!isxdigit (c))
- rv = ATOM;
- tokbuf [i] = c;
- }
- if (i == sizeof tokbuf) {
- parse_warn ("token larger than internal buffer");
- --i;
- }
- tokbuf [i] = 0;
- tval = tokbuf;
- return intern (tval, rv);
-}
-
-static int intern (atom, dfv)
- char *atom;
- int dfv;
-{
- switch (atom [0]) {
- case 'c':
- if (!strcasecmp (atom + 1, "lass"))
- return CLASS;
- if (!strcasecmp (atom + 1, "iaddr"))
- return CIADDR;
- break;
- case 'd':
- if (!strcasecmp (atom + 1, "efault-lease-time"))
- return DEFAULT_LEASE_TIME;
- break;
- case 'e':
- if (!strcasecmp (atom + 1, "thernet"))
- return ETHERNET;
- if (!strcasecmp (atom + 1, "nds"))
- return ENDS;
- break;
- case 'f':
- if (!strcasecmp (atom + 1, "ilename"))
- return FILENAME;
- if (!strcasecmp (atom + 1, "ixed-address"))
- return FIXED_ADDR;
- break;
- case 'g':
- if (!strcasecmp (atom + 1, "iaddr"))
- return GIADDR;
- break;
- case 'h':
- if (!strcasecmp (atom + 1, "ost"))
- return HOST;
- if (!strcasecmp (atom + 1, "ardware"))
- return HARDWARE;
- break;
- case 'l':
- if (!strcasecmp (atom + 1, "ease"))
- return LEASE;
- break;
- case 'm':
- if (!strcasecmp (atom + 1, "ax-lease-time"))
- return MAX_LEASE_TIME;
- break;
- case 'n':
- if (!strcasecmp (atom + 1, "etmask"))
- return NETMASK;
- break;
- case 'p':
- if (!strcasecmp (atom + 1, "acket"))
- return PACKET;
- break;
- case 'o':
- if (!strcasecmp (atom + 1, "ption"))
- return OPTION;
- break;
- case 'r':
- if (!strcasecmp (atom + 1, "ange"))
- return RANGE;
- break;
- case 's':
- if (!strcasecmp (atom + 1, "tarts"))
- return STARTS;
- if (!strcasecmp (atom + 1, "iaddr"))
- return SIADDR;
- if (!strcasecmp (atom + 1, "ubnet"))
- return SUBNET;
- break;
- case 't':
- if (!strcasecmp (atom + 1, "timestamp"))
- return TIMESTAMP;
- break;
- case 'u':
- if (!strcasecmp (atom + 1, "id"))
- return UID;
- if (!strcasecmp (atom + 1, "ser-class"))
- return USER_CLASS;
- break;
- case 'v':
- if (!strcasecmp (atom + 1, "endor-class"))
- return VENDOR_CLASS;
- break;
- case 'y':
- if (!strcasecmp (atom + 1, "iaddr"))
- return YIADDR;
- break;
- }
- return dfv;
-}
diff --git a/common/errwarn.c b/common/errwarn.c
deleted file mode 100644
index d29a2d79..00000000
--- a/common/errwarn.c
+++ /dev/null
@@ -1,200 +0,0 @@
-/* errwarn.c
-
- Errors and warnings... */
-
-/*
- * Copyright (c) 1995 RadioMail Corporation. 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 RadioMail Corporation 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 RADIOMAIL CORPORATION 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
- * RADIOMAIL CORPORATION 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 was written for RadioMail Corporation by Ted Lemon
- * under a contract with Vixie Enterprises, and is based on an earlier
- * design by Paul Vixie.
- */
-
-#ifndef lint
-static char copyright[] =
-"@(#) Copyright (c) 1995 RadioMail Corporation. All rights reserved.\n";
-#endif /* not lint */
-
-#include "dhcpd.h"
-#include <syslog.h>
-#include <errno.h>
-
-static void do_percentm PROTO ((char *obuf, char *ibuf));
-
-static char mbuf [1024];
-static char fbuf [1024];
-
-/* Log an error message, then exit... */
-
-int error (ANSI_DECL(char *) fmt, VA_DOTDOTDOT)
- KandR (char *fmt;)
- va_dcl
-{
- va_list list;
- extern int logged_in;
-
- do_percentm (fbuf, fmt);
-
- VA_start (list, fmt);
- vsnprintf (mbuf, sizeof mbuf, fbuf, list);
- va_end (list);
-#ifndef DEBUG
- syslog (LOG_ERR, mbuf);
-#else
- write (1, mbuf, strlen (mbuf));
- write (1, "\n", 1);
-#endif
-
- cleanup ();
- exit (1);
-}
-
-/* Log a warning message... */
-
-int warn (ANSI_DECL (char *) fmt, VA_DOTDOTDOT)
- KandR (char *fmt;)
- va_dcl
-{
- va_list list;
-
- do_percentm (fbuf, fmt);
-
- VA_start (list, fmt);
- vsnprintf (mbuf, sizeof mbuf, fbuf, list);
- va_end (list);
-#ifndef DEBUG
- syslog (LOG_ERR, mbuf);
-#else
- write (1, mbuf, strlen (mbuf));
- write (1, "\n", 1);
-#endif
- return 0;
-}
-
-/* Log a note... */
-
-int note (ANSI_DECL (char *) fmt, VA_DOTDOTDOT)
- KandR (char *fmt;)
- va_dcl
-{
- va_list list;
-
- do_percentm (fbuf, fmt);
-
- VA_start (list, fmt);
- vsnprintf (mbuf, sizeof mbuf, fbuf, list);
- va_end (list);
-#ifndef DEBUG
- syslog (LOG_INFO, mbuf);
-#else
- write (1, mbuf, strlen (mbuf));
- write (1, "\n", 1);
-#endif
- return 0;
-}
-
-/* Log a debug message... */
-
-int debug (ANSI_DECL (char *) fmt, VA_DOTDOTDOT)
- KandR (char *fmt;)
- va_dcl
-{
- va_list list;
-
- do_percentm (fbuf, fmt);
-
- VA_start (list, fmt);
- vsnprintf (mbuf, sizeof mbuf, fbuf, list);
- va_end (list);
-#ifndef DEBUG
- syslog (LOG_DEBUG, mbuf);
-#else
- write (1, mbuf, strlen (mbuf));
- write (1, "\n", 1);
-#endif
- return 0;
-}
-
-/* Find %m in the input string and substitute an error message string. */
-
-static void do_percentm (obuf, ibuf)
- char *obuf;
- char *ibuf;
-{
- char *s = ibuf;
- char *p = obuf;
- int infmt = 0;
-
- while (*s)
- {
- if (infmt)
- {
- if (*s == 'm')
- {
- strcpy (p - 1, strerror (errno));
- p += strlen (p);
- ++s;
- }
- else
- *p++ = *s++;
- infmt = 0;
- }
- else
- {
- if (*s == '%')
- infmt = 1;
- *p++ = *s++;
- }
- }
- *p = 0;
-}
-
-
-int parse_warn (ANSI_DECL (char *) fmt, VA_DOTDOTDOT)
- KandR (char *fmt;)
- va_dcl
-{
- extern int tline, tlpos;
- va_list list;
-
- do_percentm (mbuf, fmt);
- snprintf (fbuf, sizeof fbuf, "dhcpd.conf line %d char %d: %s",
- tline, tlpos, mbuf);
-
- VA_start (list, fmt);
- vsnprintf (mbuf, sizeof mbuf, fbuf, list);
- va_end (list);
-#ifndef DEBUG
- syslog (LOG_ERR, mbuf);
-#else
- write (1, mbuf, strlen (mbuf));
- write (1, "\n", 1);
-#endif
- return 0;
-}
diff --git a/common/hash.c b/common/hash.c
deleted file mode 100644
index cf15ba31..00000000
--- a/common/hash.c
+++ /dev/null
@@ -1,156 +0,0 @@
-/* hash.c
-
- Routines for manipulating hash tables... */
-
-/*
- * Copyright (c) 1995 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''.
- */
-
-#ifndef lint
-static char copyright[] =
-"@(#) Copyright (c) 1995 The Internet Software Consortium. All rights reserved.\n";
-#endif /* not lint */
-
-#include "dhcpd.h"
-
-static INLINE int do_hash PROTO ((char *, int, int));
-
-struct hash_table *new_hash ()
-{
- struct hash_table *rv = new_hash_table (DEFAULT_HASH_SIZE, "new_hash");
- if (!rv)
- return rv;
- memset (&rv -> buckets, 0,
- DEFAULT_HASH_SIZE * sizeof (struct hash_bucket *));
- return rv;
-}
-
-static INLINE int do_hash (name, len, size)
- char *name;
- int len;
- int size;
-{
- register int accum = 0;
- register unsigned char *s = (unsigned char *)name;
- int i = len;
- if (i) {
- while (i--) {
- /* Add the character in... */
- accum += *s++;
- /* Add carry back in... */
- while (accum > 255) {
- accum = (accum & 255) + (accum >> 8);
- }
- }
- } else {
- while (*s) {
- /* Add the character in... */
- accum += *s++;
- /* Add carry back in... */
- while (accum > 255) {
- accum = (accum & 255) + (accum >> 8);
- }
- }
- }
- return accum % size;
-}
-
-void add_hash (table, name, len, pointer)
- struct hash_table *table;
- int len;
- char *name;
- unsigned char *pointer;
-{
- int hashno = do_hash (name, len, table -> hash_count);
- struct hash_bucket *bp = new_hash_bucket ("add_hash");
- if (!bp) {
- warn ("Can't add %s to hash table.", name);
- return;
- }
- bp -> name = name;
- bp -> value = pointer;
- bp -> next = table -> buckets [hashno];
- bp -> len = len;
- table -> buckets [hashno] = bp;
-}
-
-void delete_hash_entry (table, name, len)
- struct hash_table *table;
- int len;
- char *name;
-{
- int hashno = do_hash (name, len, table -> hash_count);
- struct hash_bucket *bp, *pbp = (struct hash_bucket *)0;
-
- /* Go through the list looking for an entry that matches;
- if we find it, delete it. */
- for (bp = table -> buckets [hashno]; bp; bp = bp -> next) {
- if ((!bp -> len && !strcmp (bp -> name, name)) ||
- (bp -> len == len &&
- !memcmp (bp -> name, name, len))) {
- if (pbp) {
- pbp -> next = bp -> next;
- } else {
- table -> buckets [hashno] = bp -> next;
- }
- free_hash_bucket (bp, "delete_hash_entry");
- break;
- }
- }
-}
-
-unsigned char *hash_lookup (table, name, len)
- struct hash_table *table;
- char *name;
- int len;
-{
- int hashno = do_hash (name, len, table -> hash_count);
- struct hash_bucket *bp;
-
- if (len) {
- for (bp = table -> buckets [hashno]; bp; bp = bp -> next) {
- if (len == bp -> len
- && !memcmp (bp -> name, name, len))
- return bp -> value;
- }
- } else {
- for (bp = table -> buckets [hashno]; bp; bp = bp -> next)
- if (!strcmp (bp -> name, name))
- return bp -> value;
- }
- return (unsigned char *)0;
-}
-
diff --git a/common/inet.c b/common/inet.c
deleted file mode 100644
index ce63a2b4..00000000
--- a/common/inet.c
+++ /dev/null
@@ -1,154 +0,0 @@
-/* inet.c
-
- Subroutines to manipulate internet addresses in a safely portable
- way... */
-
-/*
- * 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"
-
-/* Return just the network number of an internet address... */
-
-struct iaddr subnet_number (addr, mask)
- struct iaddr addr;
- struct iaddr mask;
-{
- int i;
- struct iaddr rv;
-
- rv.len = 0;
-
- /* Both addresses must have the same length... */
- if (addr.len != mask.len)
- return rv;
-
- rv.len = addr.len;
- for (i = 0; i < rv.len; i++)
- rv.iabuf [i] = addr.iabuf [i] & mask.iabuf [i];
- return rv;
-}
-
-/* Combine a network number and a integer to produce an internet address.
- This won't work for subnets with more than 32 bits of host address, but
- maybe this isn't a problem. */
-
-struct iaddr ip_addr (subnet, mask, host_address)
- struct iaddr subnet;
- struct iaddr mask;
- unsigned long host_address;
-{
- int i, j, k;
- unsigned long swaddr;
- struct iaddr rv;
- unsigned char habuf [sizeof swaddr];
-
- swaddr = htonl (host_address);
- memcpy (habuf, &swaddr, sizeof swaddr);
-
- /* Combine the subnet address and the host address. If
- the host address is bigger than can fit in the subnet,
- return a zero-length iaddr structure. */
- rv = subnet;
- j = rv.len - sizeof habuf;
- for (i = sizeof habuf - 1; i >= 0; i--) {
- if (mask.iabuf [i + j]) {
- if (habuf [i] > (mask.iabuf [i + j] ^ 0xFF)) {
- rv.len = 0;
- return rv;
- }
- for (k = i - 1; k >= 0; k--) {
- if (habuf [k]) {
- rv.len = 0;
- return rv;
- }
- }
- rv.iabuf [i + j] |= habuf [i];
- break;
- } else
- rv.iabuf [i + j] = habuf [i];
- }
-
- return rv;
-}
-
-unsigned long host_addr (addr, mask)
- struct iaddr addr;
- struct iaddr mask;
-{
- int i;
- unsigned long swaddr;
- struct iaddr rv;
-
- rv.len = 0;
-
- /* Mask out the network bits... */
- rv.len = addr.len;
- for (i = 0; i < rv.len; i++)
- rv.iabuf [i] = addr.iabuf [i] & ~mask.iabuf [i];
-
- /* Copy out up to 32 bits... */
- memcpy (&swaddr, &rv.iabuf [rv.len - sizeof swaddr], sizeof swaddr);
-
- /* Swap it and return it. */
- return ntohl (swaddr);
-}
-
-int addr_eq (addr1, addr2)
- struct iaddr addr1, addr2;
-{
- if (addr1.len != addr2.len)
- return 0;
- return memcmp (addr1.iabuf, addr2.iabuf, addr1.len) == 0;
-}
-
-char *piaddr (addr)
- struct iaddr addr;
-{
- static char pbuf [4 * 16];
- char *s = pbuf;
- int i;
-
- if (addr.len == 0) {
- strcpy (s, "<null address>");
- }
- for (i = 0; i < addr.len; i++) {
- sprintf (s, "%s%d", i ? "." : "", addr.iabuf [i]);
- s += strlen (s);
- }
- return pbuf;
-}
diff --git a/common/memory.c b/common/memory.c
deleted file mode 100644
index 272f8799..00000000
--- a/common/memory.c
+++ /dev/null
@@ -1,545 +0,0 @@
-/* memory.c
-
- Memory-resident database... */
-
-/*
- * 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
- * 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''.
- */
-
-#ifndef lint
-static char copyright[] =
-"@(#) Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n";
-#endif /* not lint */
-
-#include "dhcpd.h"
-
-static struct host_decl *hosts;
-static struct subnet *subnets;
-static struct hash_table *lease_uid_hash;
-static struct hash_table *lease_ip_addr_hash;
-static struct hash_table *lease_hw_addr_hash;
-static struct lease *dangling_leases;
-
-static struct hash_table *vendor_class_hash;
-static struct hash_table *user_class_hash;
-
-void enter_host (hd)
- struct host_decl *hd;
-{
- hd -> n_name = hosts;
- hd -> n_haddr = hosts;
- hd -> n_cid = hosts;
-
- hosts = hd;
-}
-
-struct host_decl *find_host_by_name (name)
- char *name;
-{
- struct host_decl *foo;
-
- for (foo = hosts; foo; foo = foo -> n_name)
- if (!strcmp (name, foo -> name))
- return foo;
- return (struct host_decl *)0;
-}
-
-struct host_decl *find_host_by_addr (htype, haddr, hlen)
- int htype;
- unsigned char *haddr;
- int hlen;
-{
- struct host_decl *foo;
- int i;
-
- for (foo = hosts; foo; foo = foo -> n_haddr)
- for (i = 0; i < foo -> interface_count; i++)
- if (foo -> interfaces [i].htype == htype &&
- foo -> interfaces [i].hlen == hlen &&
- !memcmp (foo -> interfaces [i].haddr, haddr, hlen))
- return foo;
- return (struct host_decl *)0;
-}
-
-void new_address_range (low, high, subnet)
- struct iaddr low, high;
- struct subnet *subnet;
-{
- struct lease *address_range, *lp, *plp;
- struct iaddr net;
- int min, max, i;
- char lowbuf [16], highbuf [16], netbuf [16];
-
- /* Initialize the hash table if it hasn't been done yet. */
- if (!lease_uid_hash)
- lease_uid_hash = new_hash ();
- if (!lease_ip_addr_hash)
- lease_ip_addr_hash = new_hash ();
- if (!lease_hw_addr_hash)
- lease_hw_addr_hash = new_hash ();
-
- /* Make sure that high and low addresses are in same subnet. */
- net = subnet_number (low, subnet -> netmask);
- if (!addr_eq (net, subnet_number (high, subnet -> netmask))) {
- strcpy (lowbuf, piaddr (low));
- strcpy (highbuf, piaddr (high));
- strcpy (netbuf, piaddr (subnet -> netmask));
- error ("Address range %s to %s, netmask %s spans %s!",
- lowbuf, highbuf, netbuf, "multiple subnets");
- }
-
- /* Get the high and low host addresses... */
- max = host_addr (high, subnet -> netmask);
- min = host_addr (low, subnet -> netmask);
-
- /* Allow range to be specified high-to-low as well as low-to-high. */
- if (min > max) {
- max = min;
- min = host_addr (high, subnet -> netmask);
- }
-
- /* Get a lease structure for each address in the range. */
- address_range = new_leases (max - min + 1, "new_address_range");
- if (!address_range) {
- strcpy (lowbuf, piaddr (low));
- strcpy (highbuf, piaddr (high));
- error ("No memory for address range %s-%s.", lowbuf, highbuf);
- }
- memset (address_range, 0, (sizeof *address_range) * (max - min + 1));
-
- /* Fill in the last lease if it hasn't been already... */
- if (!subnet -> last_lease) {
- subnet -> last_lease = &address_range [0];
- }
-
- /* Fill out the lease structures with some minimal information. */
- for (i = 0; i < max - min + 1; i++) {
- address_range [i].ip_addr =
- ip_addr (subnet -> net, subnet -> netmask, i + min);
- address_range [i].starts =
- address_range [i].timestamp = MIN_TIME;
- address_range [i].ends = MIN_TIME;
- address_range [i].contain = subnet;
-
- /* Link this entry into the list. */
- address_range [i].next = subnet -> leases;
- address_range [i].prev = (struct lease *)0;
- subnet -> leases = &address_range [i];
- if (address_range [i].next)
- address_range [i].next -> prev = subnet -> leases;
- add_hash (lease_ip_addr_hash,
- address_range [i].ip_addr.iabuf,
- address_range [i].ip_addr.len,
- (unsigned char *)&address_range [i]);
- }
-
- /* Find out if any dangling leases are in range... */
- plp = (struct lease *)0;
- for (lp = dangling_leases; lp; lp = lp -> next) {
- struct iaddr lnet;
- int lhost;
-
- lnet = subnet_number (lp -> ip_addr, subnet -> netmask);
- lhost = host_addr (lp -> ip_addr, subnet -> netmask);
-
- /* If it's in range, fill in the real lease structure with
- the dangling lease's values, and remove the lease from
- the list of dangling leases. */
- if (addr_eq (lnet, subnet -> net) &&
- lhost >= i && lhost <= max) {
- if (plp) {
- plp -> next = lp -> next;
- } else {
- dangling_leases = lp -> next;
- }
- lp -> next = (struct lease *)0;
- supersede_lease (&address_range [lhost - i], lp, 0);
- free_lease (lp, "new_address_range");
- } else
- plp = lp;
- }
-}
-
-struct subnet *find_subnet (addr)
- struct iaddr addr;
-{
- struct subnet *rv;
-
- for (rv = subnets; rv; rv = rv -> next) {
- if (addr_eq (subnet_number (addr, rv -> netmask), rv -> net))
- return rv;
- }
- return (struct subnet *)0;
-}
-
-/* Enter a new subnet into the subnet hash. */
-
-void enter_subnet (subnet)
- struct subnet *subnet;
-{
- /* XXX Sort the nets into a balanced tree to make searching quicker. */
- subnet -> next = subnets;
- subnets = subnet;
-}
-
-/* Enter a lease into the system. This is called by the parser each
- time it reads in a new lease. If the subnet for that lease has
- already been read in (usually the case), just update that lease;
- otherwise, allocate temporary storage for the lease and keep it around
- until we're done reading in the config file. */
-
-void enter_lease (lease)
- struct lease *lease;
-{
- struct lease *comp = find_lease_by_ip_addr (lease -> ip_addr);
-
- /* If we don't have a place for this lease yet, save it for
- later. */
- if (!comp) {
- comp = new_lease ("enter_lease");
- if (!comp) {
- error ("No memory for lease %s\n",
- piaddr (lease -> ip_addr));
- }
- *comp = *lease;
- lease -> next = dangling_leases;
- lease -> prev = (struct lease *)0;
- dangling_leases = lease;
- } else {
- supersede_lease (comp, lease, 0);
- }
-}
-
-/* Replace the data in an existing lease with the data in a new lease;
- adjust hash tables to suit, and insertion sort the lease into the
- list of leases by expiry time so that we can always find the oldest
- lease. */
-
-int supersede_lease (comp, lease, commit)
- struct lease *comp, *lease;
- int commit;
-{
- int enter_uid = 0;
- int enter_hwaddr = 0;
- struct subnet *parent;
- struct lease *lp;
-
- /* If the existing lease hasn't expired and has a different
- unique identifier or, if it doesn't have a unique
- identifier, a different hardware address, then the two
- leases are in conflict. */
- if (comp -> ends > cur_time &&
- ((comp -> uid &&
- (comp -> uid_len != lease -> uid_len ||
- memcmp (comp -> uid, lease -> uid, comp -> uid_len))) ||
- (!comp -> uid &&
- ((comp -> hardware_addr.htype !=
- lease -> hardware_addr.htype) ||
- (comp -> hardware_addr.hlen !=
- lease -> hardware_addr.hlen) ||
- memcmp (comp -> hardware_addr.haddr,
- lease -> hardware_addr.haddr,
- comp -> hardware_addr.hlen))))) {
- warn ("Lease conflict at %s",
- piaddr (comp -> ip_addr));
- } else {
- /* If there's a Unique ID, dissociate it from the hash
- table if necessary, and always free it. */
- if (comp -> uid) {
- if (comp -> uid_len != lease -> uid_len ||
- memcmp (comp -> uid, lease -> uid,
- comp -> uid_len)) {
- delete_hash_entry (lease_uid_hash,
- comp -> uid,
- comp -> uid_len);
- enter_uid = 1;
- }
- free (comp -> uid);
- } else
- enter_uid = 1;
-
- if (comp -> hardware_addr.htype &&
- ((comp -> hardware_addr.hlen !=
- lease -> hardware_addr.hlen) ||
- (comp -> hardware_addr.htype !=
- lease -> hardware_addr.htype) ||
- memcmp (comp -> hardware_addr.haddr,
- lease -> hardware_addr.haddr,
- comp -> hardware_addr.hlen))) {
- delete_hash_entry (lease_hw_addr_hash,
- comp -> hardware_addr.haddr,
- comp -> hardware_addr.hlen);
- enter_hwaddr = 1;
- } else if (!comp -> hardware_addr.htype)
- enter_hwaddr = 1;
-
- /* Copy the data files, but not the linkages. */
- comp -> starts = lease -> starts;
- comp -> offered_expiry = lease -> offered_expiry;
- comp -> timestamp = lease -> timestamp;
- comp -> uid = lease -> uid;
- comp -> uid_len = lease -> uid_len;
- comp -> host = lease -> host;
- comp -> hardware_addr = lease -> hardware_addr;
- comp -> state = lease -> state;
-
- /* Record the lease in the uid hash if necessary. */
- if (enter_uid && lease -> uid) {
- add_hash (lease_uid_hash, comp -> uid,
- comp -> uid_len, (unsigned char *)comp);
- }
-
- /* Record it in the hardware address hash if necessary. */
- if (enter_hwaddr && lease -> hardware_addr.htype) {
- add_hash (lease_hw_addr_hash,
- comp -> hardware_addr.haddr,
- comp -> hardware_addr.hlen,
- (unsigned char *)comp);
- }
-
- /* Remove the lease from its current place in the list. */
- if (comp -> prev) {
- comp -> prev -> next = comp -> next;
- } else {
- comp -> contain -> leases = comp -> next;
- }
- if (comp -> next) {
- comp -> next -> prev = comp -> prev;
- }
- if (comp -> contain -> last_lease == comp) {
- comp -> contain -> last_lease = comp -> prev;
- }
-
- /* Find the last insertion point... */
- if (comp == comp -> contain -> insertion_point ||
- !comp -> contain -> insertion_point) {
- lp = comp -> contain -> leases;
- } else {
- lp = comp -> contain -> insertion_point;
- }
-
- if (!lp) {
- /* Nothing on the list yet? Just make comp the
- head of the list. */
- comp -> contain -> leases = comp;
- comp -> contain -> last_lease = comp;
- } else if (lp -> ends > lease -> ends) {
- /* Skip down the list until we run out of list
- or find a place for comp. */
- while (lp -> next && lp -> ends > lease -> ends) {
- lp = lp -> next;
- }
- if (lp -> ends > lease -> ends) {
- /* If we ran out of list, put comp
- at the end. */
- lp -> next = comp;
- comp -> prev = lp;
- comp -> next = (struct lease *)0;
- comp -> contain -> last_lease = comp;
- } else {
- /* If we didn't, put it between lp and
- the previous item on the list. */
- if ((comp -> prev = lp -> prev))
- comp -> prev -> next = comp;
- comp -> next = lp;
- lp -> prev = comp;
- }
- } else {
- /* Skip up the list until we run out of list
- or find a place for comp. */
- while (lp -> prev && lp -> ends < lease -> ends) {
- lp = lp -> prev;
- }
- if (lp -> ends < lease -> ends) {
- /* If we ran out of list, put comp
- at the beginning. */
- lp -> prev = comp;
- comp -> next = lp;
- comp -> prev = (struct lease *)0;
- comp -> contain -> leases = comp;
- } else {
- /* If we didn't, put it between lp and
- the next item on the list. */
- if ((comp -> next = lp -> next))
- comp -> next -> prev = comp;
- comp -> prev = lp;
- lp -> next = comp;
- }
- }
- comp -> contain -> insertion_point = comp;
- comp -> ends = lease -> ends;
- }
-
- /* Return zero if we didn't commit the lease to permanent storage;
- nonzero if we did. */
- return commit && write_lease (comp) && commit_leases ();
-}
-
-/* Release the specified lease and re-hash it as appropriate. */
-
-void release_lease (lease)
- struct lease *lease;
-{
- struct lease lt;
-
- lt = *lease;
- lt.ends = cur_time;
- supersede_lease (lease, &lt, 1);
-}
-
-/* Abandon the specified lease (set its timeout to infinity and its
- particulars to zero, and re-hash it as appropriate. */
-
-void abandon_lease (lease)
- struct lease *lease;
-{
- struct lease lt;
-
- lt = *lease;
- lt.ends = 0xFFFFFFFF;
- warn ("Abandoning IP address %s\n",
- piaddr (lease -> ip_addr));
- lt.hardware_addr.htype = -1;
- lt.hardware_addr.hlen = 0;
- lt.uid = (char *)0;
- lt.uid_len = 0;
- supersede_lease (lease, &lt, 1);
-}
-
-/* Locate the lease associated with a given IP address... */
-
-struct lease *find_lease_by_ip_addr (addr)
- struct iaddr addr;
-{
- struct lease *lease = (struct lease *)hash_lookup (lease_ip_addr_hash,
- addr.iabuf,
- addr.len);
- return lease;
-}
-
-struct lease *find_lease_by_uid (uid, len)
- unsigned char *uid;
- int len;
-{
- struct lease *lease = (struct lease *)hash_lookup (lease_uid_hash,
- uid, len);
- return lease;
-}
-
-struct lease *find_lease_by_hw_addr (hwaddr, hwlen)
- unsigned char *hwaddr;
- int hwlen;
-{
- struct lease *lease = (struct lease *)hash_lookup (lease_hw_addr_hash,
- hwaddr, hwlen);
- return lease;
-}
-
-struct class *add_class (type, name)
- int type;
- char *name;
-{
- struct class *class = new_class ("add_class");
- char *tname = (char *)malloc (strlen (name) + 1);
-
- if (!vendor_class_hash)
- vendor_class_hash = new_hash ();
- if (!user_class_hash)
- user_class_hash = new_hash ();
-
- if (!tname || !class || !vendor_class_hash || !user_class_hash)
- return (struct class *)0;
-
- memset (class, 0, sizeof *class);
- strcpy (tname, name);
- class -> name = tname;
-
- if (type)
- add_hash (user_class_hash,
- tname, strlen (tname), (unsigned char *)class);
- else
- add_hash (user_class_hash,
- tname, strlen (tname), (unsigned char *)class);
- return class;
-}
-
-struct class *find_class (type, name, len)
- int type;
- char *name;
- int len;
-{
- struct class *class =
- (struct class *)hash_lookup (type
- ? user_class_hash
- : vendor_class_hash, name, len);
- return class;
-}
-
-/* Write all interesting leases to permanent storage. */
-
-void write_leases ()
-{
- struct lease *l;
- struct subnet *s;
- int i;
-
- for (s = subnets; s; s = s -> next) {
- for (l = s -> leases; l; l = l -> next) {
- if (l -> hardware_addr.hlen || l -> uid_len)
- write_lease (l);
- }
- }
- commit_leases ();
-}
-
-void dump_subnets ()
-{
- struct lease *l;
- struct subnet *s;
- int i;
-
- for (s = subnets; s; s = s -> next) {
- debug ("Subnet %s", piaddr (s -> net));
- debug (" netmask %s",
- piaddr (s -> netmask));
- for (l = s -> leases; l; l = l -> next) {
- print_lease (l);
- }
- debug ("Last Lease:");
- print_lease (s -> last_lease);
- }
-}
diff --git a/common/options.c b/common/options.c
deleted file mode 100644
index 354c10a4..00000000
--- a/common/options.c
+++ /dev/null
@@ -1,520 +0,0 @@
-/* options.c
-
- DHCP options parsing and reassembly. */
-
-/*
- * 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
- * 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''.
- */
-
-#ifndef lint
-static char copyright[] =
-"@(#) Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n";
-#endif /* not lint */
-
-#define DHCP_OPTION_DATA
-#include "dhcpd.h"
-
-/* Parse all available options out of the specified packet. */
-
-void parse_options (packet)
- struct packet *packet;
-{
- /* Initially, zero all option pointers. */
- memset (packet -> options, 0, sizeof (packet -> options));
-
- /* If we don't see the magic cookie, there's nothing to parse. */
- if (memcmp (packet -> raw -> options, DHCP_OPTIONS_COOKIE, 4)) {
- packet -> options_valid = 0;
- return;
- }
-
- /* Go through the options field, up to the end of the packet
- or the End field. */
- parse_option_buffer (packet, &packet -> raw -> options [4],
- packet -> packet_length - DHCP_FIXED_NON_UDP + 4);
- /* If we parsed a DHCP Option Overload option, parse more
- options out of the buffer(s) containing them. */
- if (packet -> options_valid
- && packet -> options [DHO_DHCP_OPTION_OVERLOAD].data) {
- if (packet -> options [DHO_DHCP_OPTION_OVERLOAD].data [0] & 1)
- parse_option_buffer (packet,
- packet -> raw -> file,
- sizeof packet -> raw -> file);
- if (packet -> options [DHO_DHCP_OPTION_OVERLOAD].data [0] & 2)
- parse_option_buffer (packet,
- packet -> raw -> sname,
- sizeof packet -> raw -> sname);
- }
-}
-
-/* Parse options out of the specified buffer, storing addresses of option
- values in packet -> options and setting packet -> options_valid if no
- errors are encountered. */
-
-void parse_option_buffer (packet, buffer, length)
- struct packet *packet;
- unsigned char *buffer;
- int length;
-{
- unsigned char *s, *t;
- unsigned char *end = buffer + length;
- int len;
- int code;
-
- for (s = buffer; *s != DHO_END && s < end; ) {
- code = s [0];
- /* Pad options don't have a length - just skip them. */
- if (code == DHO_PAD) {
- ++s;
- continue;
- }
- /* All other fields (except end, see above) have a
- one-byte length. */
- len = s [1];
-
- /* If the length is outrageous, the options are bad. */
- if (s + len + 2 > end) {
- warn ("Option %s length %d overflows input buffer.",
- dhcp_options [code].name,
- len);
- packet -> options_valid = 0;
- return;
- }
- /* If we haven't seen this option before, just make
- space for it and copy it there. */
- if (!packet -> options [code].data) {
- if (!(t = (unsigned char *)malloc (len + 1)))
- error ("Can't allocate storage for option %s.",
- dhcp_options [code].name);
- /* Copy and NUL-terminate the option (in case it's an
- ASCII string. */
- memcpy (t, &s [2], len);
- t [len] = 0;
- packet -> options [code].len = len;
- packet -> options [code].data = t;
- } else {
- /* If it's a repeat, concatenate it to whatever
- we last saw. This is really only required
- for clients, but what the heck... */
- t = (unsigned char *)
- malloc (len + packet -> options [code].len);
- if (!t)
- error ("Can't expand storage for option %s.",
- dhcp_options [code].name);
- memcpy (t, packet -> options [code].data,
- packet -> options [code].len);
- memcpy (t + packet -> options [code].len,
- &s [2], len);
- packet -> options [code].len += len;
- t [packet -> options [code].len] = 0;
- free (packet -> options [code].data);
- packet -> options [code].data = t;
- }
- s += len + 2;
- }
- packet -> options_valid = 1;
-}
-
-/* cons options into a big buffer, and then split them out into the
- three seperate buffers if needed. This allows us to cons up a set
- of vendor options using the same routine. */
-
-void cons_options (inpacket, outpacket, options, overload)
- struct packet *inpacket;
- struct packet *outpacket;
- struct tree_cache **options;
- int overload; /* Overload flags that may be set. */
-{
- unsigned char priority_list [300];
- int priority_len;
- unsigned char buffer [4096]; /* Really big buffer... */
- int main_buffer_size;
- int mainbufix, bufix;
- int option_size;
- int result;
- int i;
-
- /* If the client has provided a maximum DHCP message size,
- use that. Otherwise, we use the default MTU size (576 bytes). */
- /* 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 && inpacket -> options [DHO_DHCP_MAX_MESSAGE_SIZE].data) {
- main_buffer_size =
- (getUShort (inpacket -> options
- [DHO_DHCP_MAX_MESSAGE_SIZE].data)
- - DHCP_FIXED_LEN);
- /* Enforce a minimum packet size... */
- if (main_buffer_size < (576 - DHCP_FIXED_LEN))
- main_buffer_size = 576 - DHCP_FIXED_LEN;
- } else
- main_buffer_size = 576 - DHCP_FIXED_LEN;
-
- /* Preload the option priority list with mandatory options. */
- priority_len = 0;
- priority_list [priority_len++] = DHO_DHCP_MESSAGE_TYPE;
- priority_list [priority_len++] = DHO_DHCP_SERVER_IDENTIFIER;
- priority_list [priority_len++] = DHO_DHCP_LEASE_TIME;
- priority_list [priority_len++] = DHO_DHCP_MESSAGE;
-
- /* If the client has provided a list of options that it wishes
- returned, use it to prioritize. Otherwise, prioritize
- based on the default priority list. */
-
- if (inpacket &&
- inpacket -> options [DHO_DHCP_PARAMETER_REQUEST_LIST].data) {
- memcpy (&priority_list [priority_len],
- inpacket -> options
- [DHO_DHCP_PARAMETER_REQUEST_LIST].data,
- inpacket -> options
- [DHO_DHCP_PARAMETER_REQUEST_LIST].len);
- priority_len +=
- inpacket -> options
- [DHO_DHCP_PARAMETER_REQUEST_LIST].len;
- } else {
- memcpy (&priority_list [priority_len],
- dhcp_option_default_priority_list,
- sizeof_dhcp_option_default_priority_list);
- priority_len += sizeof_dhcp_option_default_priority_list;
- }
-
- /* Copy the options into the big buffer... */
- option_size = store_options (buffer,
- (main_buffer_size - 7 +
- ((overload & 1) ? DHCP_FILE_LEN : 0) +
- ((overload & 2) ? DHCP_SNAME_LEN : 0)),
- options, priority_list, priority_len,
- main_buffer_size,
- (main_buffer_size +
- ((overload & 1) ? DHCP_FILE_LEN : 0)));
-
- /* Put the cookie up front... */
- memcpy (outpacket -> raw -> options, DHCP_OPTIONS_COOKIE, 4);
- mainbufix = 4;
-
- /* If we're going to have to overload, store the overload
- option at the beginning. If we can, though, just store the
- whole thing in the packet's option buffer and leave it at
- that. */
- if (option_size <= main_buffer_size - mainbufix) {
- memcpy (&outpacket -> raw -> options [mainbufix],
- buffer, option_size);
- mainbufix += option_size;
- if (mainbufix < main_buffer_size)
- outpacket -> raw -> options [mainbufix++]
- = DHO_END;
- outpacket -> packet_length = DHCP_FIXED_NON_UDP + mainbufix;
- } else {
- outpacket -> raw -> options [mainbufix++] =
- DHO_DHCP_OPTION_OVERLOAD;
- outpacket -> raw -> options [mainbufix++] = 1;
- if (option_size > main_buffer_size - mainbufix + DHCP_FILE_LEN)
- outpacket -> raw -> options [mainbufix++] = 3;
- else
- outpacket -> raw -> options [mainbufix++] = 1;
-
- memcpy (&outpacket -> raw -> options [mainbufix],
- buffer, main_buffer_size - mainbufix);
- bufix = main_buffer_size - mainbufix;
- outpacket -> packet_length = DHCP_FIXED_NON_UDP + mainbufix;
- if (overload & 1) {
- if (option_size - bufix <= DHCP_FILE_LEN) {
- memcpy (outpacket -> raw -> file,
- &buffer [bufix], option_size - bufix);
- mainbufix = option_size - bufix;
- if (mainbufix < DHCP_FILE_LEN)
- outpacket -> raw -> file [mainbufix++]
- = DHO_END;
- while (mainbufix < DHCP_FILE_LEN)
- outpacket -> raw -> file [mainbufix++]
- = DHO_PAD;
- } else {
- memcpy (outpacket -> raw -> file,
- &buffer [bufix], DHCP_FILE_LEN);
- bufix += DHCP_FILE_LEN;
- }
- }
- if ((overload & 2) && option_size < bufix) {
- memcpy (outpacket -> raw -> sname,
- &buffer [bufix], option_size - bufix);
-
- mainbufix = option_size - bufix;
- if (mainbufix < DHCP_SNAME_LEN)
- outpacket -> raw -> file [mainbufix++]
- = DHO_END;
- while (mainbufix < DHCP_SNAME_LEN)
- outpacket -> raw -> file [mainbufix++]
- = DHO_PAD;
- }
- }
- return;
-}
-
-/* Store all the requested options into the requested buffer. */
-
-int store_options (buffer, buflen, options, priority_list, priority_len,
- first_cutoff, second_cutoff)
- unsigned char *buffer;
- int buflen;
- struct tree_cache **options;
- unsigned char *priority_list;
- int priority_len;
- int first_cutoff, second_cutoff;
-{
- int bufix = 0;
- int option_stored [256];
- int missed = 0;
- int missed_code = 0;
- int missed_length = 0;
- int result;
- int i;
- int ix;
-
- /* Zero out the stored-lengths array. */
- memset (option_stored, 0, sizeof option_stored);
-
- /* Copy out the options in the order that they appear in the
- priority list... */
- for (i = 0; i < priority_len; i++) {
- /* Code for next option to try to store. */
- int code = priority_list [i];
- int optstart;
-
- /* Number of bytes left to store (some may already
- have been stored by a previous pass). */
- int length;
-
- /* If no data is available for this option, skip it. */
- if (!options [code]) {
- continue;
- }
-
- /* The client could ask for things that are mandatory,
- in which case we should avoid storing them twice... */
- if (option_stored [code])
- continue;
- option_stored [code] = 1;
-
- /* Find the value of the option... */
- if (!tree_evaluate (options [code])) {
- continue;
- }
-
- /* We should now have a constant length for the option. */
- length = options [code] -> len;
-
- /* Try to store the option. */
-
- /* If the option's length is more than 255, we must store it
- in multiple hunks. Store 255-byte hunks first. However,
- in any case, if the option data will cross a buffer
- boundary, split it across that boundary. */
-
- ix = 0;
-
- optstart = bufix;
- while (length) {
- unsigned char incr = length > 255 ? 255 : length;
-
- /* If this hunk of the buffer will cross a
- boundary, only go up to the boundary in this
- pass. */
- if (bufix < first_cutoff &&
- bufix + incr > first_cutoff)
- incr = first_cutoff - bufix;
- else if (bufix < second_cutoff &&
- bufix + incr > second_cutoff)
- incr = second_cutoff - bufix;
-
- /* If this option is going to overflow the buffer,
- skip it. */
- if (bufix + 2 + incr > buflen) {
- bufix = optstart;
- break;
- }
-
- /* Everything looks good - copy it in! */
- buffer [bufix] = code;
- buffer [bufix + 1] = incr;
- memcpy (buffer + bufix + 2,
- options [code] -> value + ix, incr);
- length -= incr;
- ix += incr;
- bufix += 2 + incr;
- }
- }
- return bufix;
-}
-
-/* Format the specified option so that a human can easily read it. */
-
-char *pretty_print_option (code, data, len)
- unsigned char code;
- unsigned char *data;
- int len;
-{
- static char optbuf [32768]; /* XXX */
- int hunksize = 0;
- int numhunk = -1;
- int numelem = 0;
- char fmtbuf [32];
- int i, j;
- char *op = optbuf;
- unsigned char *dp = data;
- struct in_addr foo;
-
- /* Figure out the size of the data. */
- for (i = 0; dhcp_options [code].format [i]; i++) {
- if (!numhunk) {
- warn ("%s: Excess information in format string: %s\n",
- dhcp_options [code].name,
- &(dhcp_options [code].format [i]));
- break;
- }
- numelem++;
- fmtbuf [i] = dhcp_options [code].format [i];
- switch (dhcp_options [code].format [i]) {
- case 'A':
- --numelem;
- fmtbuf [i] = 0;
- numhunk = 0;
- break;
- case 't':
- fmtbuf [i] = 't';
- fmtbuf [i + 1] = 0;
- numhunk = -2;
- break;
- case 'I':
- case 'l':
- case 'L':
- hunksize += 4;
- break;
- case 's':
- case 'S':
- hunksize += 2;
- break;
- case 'b':
- case 'B':
- case 'f':
- hunksize++;
- break;
- case 'e':
- break;
- default:
- warn ("%s: garbage in format string: %s\n",
- dhcp_options [code].name,
- &(dhcp_options [code].format [i]));
- break;
- }
- }
-
- /* Check for too few bytes... */
- if (hunksize > len) {
- warn ("%s: expecting at least %d bytes; got %d",
- dhcp_options [code].name,
- hunksize, len);
- return "<error>";
- }
- /* Check for too many bytes... */
- if (numhunk == -1 && hunksize < len)
- warn ("%s: %d extra bytes",
- dhcp_options [code].name,
- len - hunksize);
-
- /* If this is an array, compute its size. */
- if (!numhunk)
- numhunk = len / hunksize;
- /* See if we got an exact number of hunks. */
- if (numhunk > 0 && numhunk * hunksize < len)
- warn ("%s: %d extra bytes at end of array\n",
- dhcp_options [code].name,
- len - numhunk * hunksize);
-
- /* A one-hunk array prints the same as a single hunk. */
- if (numhunk < 0)
- numhunk = 1;
-
- /* Cycle through the array (or hunk) printing the data. */
- for (i = 0; i < numhunk; i++) {
- for (j = 0; j < numelem; j++) {
- switch (fmtbuf [j]) {
- case 't':
- strcpy (op, dp);
- break;
- case 'I':
- foo.s_addr = htonl (getULong (dp));
- strcpy (op, inet_ntoa (foo));
- dp += 4;
- break;
- case 'l':
- sprintf (op, "%ld", getLong (dp));
- dp += 4;
- break;
- case 'L':
- sprintf (op, "%ld", getULong (dp));
- dp += 4;
- break;
- case 's':
- sprintf (op, "%d", getShort (dp));
- dp += 2;
- break;
- case 'S':
- sprintf (op, "%d", getUShort (dp));
- dp += 2;
- break;
- case 'b':
- sprintf (op, "%d", *(char *)dp++);
- break;
- case 'B':
- sprintf (op, "%d", *dp++);
- break;
- case 'f':
- strcpy (op, *dp++ ? "true" : "false");
- break;
- default:
- warn ("Unexpected format code %c", fmtbuf [j]);
- }
- op += strlen (op);
- *op++ = ' ';
- }
- }
- *--op = 0;
- return optbuf;
-}
-
-
-
diff --git a/common/print.c b/common/print.c
deleted file mode 100644
index 0af176c3..00000000
--- a/common/print.c
+++ /dev/null
@@ -1,155 +0,0 @@
-/* print.c
-
- Turn data structures into printable text. */
-
-/*
- * Copyright (c) 1995 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''.
- */
-
-#ifndef lint
-static char copyright[] =
-"@(#) Copyright (c) 1995 The Internet Software Consortium. All rights reserved.\n";
-#endif /* not lint */
-
-#include "dhcpd.h"
-
-char *print_hw_addr (htype, hlen, data)
- int htype;
- int hlen;
- unsigned char *data;
-{
- static char habuf [49];
- char *s;
- int i;
-
- if (htype == 0 || hlen == 0) {
- strcpy (habuf, "<null>");
- } else {
- s = habuf;
- for (i = 0; i < hlen; i++) {
- sprintf (s, "%x", data [i]);
- s += strlen (s);
- *s++ = ':';
- }
- *--s = 0;
- }
- return habuf;
-}
-
-void print_lease (lease)
- struct lease *lease;
-{
- struct tm *t;
- char tbuf [32];
-
- debug (" Lease %s",
- piaddr (lease -> ip_addr));
-
- t = gmtime (&lease -> starts);
- strftime (tbuf, sizeof tbuf, "%D %H:%M:%S", t);
- debug (" start %s", tbuf);
-
- t = gmtime (&lease -> ends);
- strftime (tbuf, sizeof tbuf, "%D %H:%M:%S", t);
- debug (" end %s", tbuf);
-
- t = gmtime (&lease -> timestamp);
- strftime (tbuf, sizeof tbuf, "%D %H:%M:%S", t);
- debug (" stamp %s", tbuf);
-
- debug (" hardware addr = %s",
- print_hw_addr (lease -> hardware_addr.htype,
- lease -> hardware_addr.hlen,
- lease -> hardware_addr.haddr));
- debug (" host %s state %x",
- lease -> host ? lease -> host -> name : "<none>",
- lease -> state);
-}
-
-void dump_packet (tp)
- struct packet *tp;
-{
- struct dhcp_packet *tdp = tp -> raw;
-
- debug ("packet length %d", tp -> packet_length);
- debug ("op = %d htype = %d hlen = %d hops = %d",
- tdp -> op, tdp -> htype, tdp -> hlen, tdp -> hops);
- debug ("xid = %x secs = %d flags = %x",
- tdp -> xid, tdp -> secs, tdp -> flags);
- debug ("ciaddr = %s", inet_ntoa (tdp -> ciaddr));
- debug ("yiaddr = %s", inet_ntoa (tdp -> yiaddr));
- debug ("siaddr = %s", inet_ntoa (tdp -> siaddr));
- debug ("giaddr = %s", inet_ntoa (tdp -> giaddr));
- debug ("chaddr = %02.2x:%02.2x:%02.2x:%02.2x:%02.2x:%02.2x",
- ((unsigned char *)(tdp -> chaddr)) [0],
- ((unsigned char *)(tdp -> chaddr)) [1],
- ((unsigned char *)(tdp -> chaddr)) [2],
- ((unsigned char *)(tdp -> chaddr)) [3],
- ((unsigned char *)(tdp -> chaddr)) [4],
- ((unsigned char *)(tdp -> chaddr)) [5]);
- debug ("filename = %s", tdp -> file);
- debug ("server_name = %s", tdp -> sname);
- if (tp -> options_valid) {
- int i;
-
- for (i = 0; i < 256; i++) {
- if (tp -> options [i].data)
- debug (" %s = %s",
- dhcp_options [i].name,
- pretty_print_option
- (i, tp -> options [i].data,
- tp -> options [i].len));
- }
- }
- debug ("");
-}
-
-void dump_raw (buf, len)
- unsigned char *buf;
- int len;
-{
- int i;
-
- for (i = 0; i < len; i++) {
- if ((i & 15) == 0)
- fprintf (stderr, "\n%03x:", i);
- else if ((i & 7) == 0)
- fprintf (stderr, " ");
- fprintf (stderr, " %02x", buf [i]);
- }
- fprintf (stderr, "\n");
-}
-
diff --git a/common/socket.c b/common/socket.c
deleted file mode 100644
index 1c5aafca..00000000
--- a/common/socket.c
+++ /dev/null
@@ -1,471 +0,0 @@
-/* socket.c
-
- BSD socket interface code... */
-
-/*
- * 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
- * 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''.
- */
-
-#ifndef lint
-static char copyright[] =
-"@(#) Copyright (c) 1995 The Internet Software Consortium. All rights reserved.\n";
-#endif /* not lint */
-
-#include "dhcpd.h"
-#include <sys/ioctl.h>
-
-#ifdef USE_BPF
-
-#include <net/bpf.h>
-#include <net/if.h>
-#include <net/if_arp.h>
-#include <net/if_dl.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <netinet/udp.h>
-#include <netinet/if_ether.h>
-
-struct interface {
- struct in_addr address;
- int bpf;
-};
-
-static struct interface *if_list;
-static int num_ifaces;
-
-#endif
-
-/* List of sockets we're accepting packets on... */
-struct socklist {
- struct socklist *next;
- struct sockaddr_in addr;
- int sock;
-} *sockets;
-
-/* Return the list of IP addresses associated with each network interface. */
-
-u_int32_t *get_interface_list (count)
- int *count;
-{
- u_int32_t *intbuf = (u_int32_t *)0;
- static char buf [8192];
- struct ifconf ic;
- int i;
- int sock;
- int ifcount = 0;
- int ifix = 0;
-
- /* Create an unbound datagram socket to do the SIOCGIFADDR ioctl on. */
- if ((sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
- error ("Can't create addrlist socket");
-
- /* Get the interface configuration information... */
- ic.ifc_len = sizeof buf;
- ic.ifc_ifcu.ifcu_buf = (caddr_t)buf;
- i = ioctl(sock, SIOCGIFCONF, &ic);
- close (sock);
- if (i < 0)
- error ("ioctl: SIOCGIFCONF: %m");
-
- again:
- /* Cycle through the list of interfaces looking for IP addresses.
- Go through twice; once to count the number if addresses, and a
- second time to copy them into an array of addresses. */
- for (i = 0; i < ic.ifc_len;) {
- struct ifreq *ifp = (struct ifreq *)((caddr_t)ic.ifc_req + i);
-#ifdef HAVE_SIN_LEN
- i += (sizeof ifp -> ifr_name) + ifp -> ifr_addr.sa_len;
-#else
- i += sizeof *ifp;
-#endif
- if (ifp -> ifr_addr.sa_family == AF_INET) {
- struct sockaddr_in *foo =
- (struct sockaddr_in *)(&ifp -> ifr_addr);
- /* We don't want the loopback interface. */
- if (foo -> sin_addr.s_addr == INADDR_LOOPBACK)
- continue;
- if (intbuf) {
- intbuf [ifix] = foo -> sin_addr.s_addr;
-#ifdef USE_BPF
- /* Open a bpf device for this interface */
- {
- int b;
- char filename[50];
-
- for (b = 0; 1; b++)
- {
- snprintf(filename, sizeof(filename),
- "/dev/bpf%d", b);
- if ((if_list[ifix].bpf =
- open(filename, O_RDWR, 0)) < 0)
- if (errno == EBUSY)
- continue;
- else
- error ("Can't find free bpf: %m");
- else
- break;
- }
- if (ioctl(if_list[ifix].bpf,
- BIOCSETIF, ifp) < 0)
- error ("Can't BIOCSETIF on bpf: %m");
- }
- if_list[ifix].address = foo->sin_addr;
-#endif
- ifix++;
- } else {
- ++ifcount;
- }
- }
- }
- /* If we haven't already filled our array, allocate it and go
- again. */
- if (!intbuf) {
- intbuf = (u_int32_t *)dmalloc ((ifcount + 1)
- * sizeof (u_int32_t),
- "get_interface_list");
- if (!intbuf)
- return intbuf;
-#ifdef USE_BPF
- num_ifaces = ifcount;
- if (!(if_list = (struct interface *)dmalloc
- (num_ifaces * sizeof(*if_list),
- "get_interface_list")))
- error ("Can't allocate memory for if_list");
-#endif
- goto again;
- }
- *count = ifcount;
- return intbuf;
-}
-
-void listen_on (port, address)
- u_int16_t port;
- u_int32_t address;
-{
- struct sockaddr_in name;
- int sock;
- struct socklist *tmp;
- int flag;
-
- name.sin_family = AF_INET;
- name.sin_port = port;
- name.sin_addr.s_addr = address;
- memset (name.sin_zero, 0, sizeof (name.sin_zero));
-
- /* List addresses on which we're listening. */
- note ("Receiving on %s, port %d",
- inet_ntoa (name.sin_addr), htons (name.sin_port));
- if ((sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
- error ("Can't create dhcp socket: %m");
-
- flag = 1;
- if (setsockopt (sock, SOL_SOCKET, SO_REUSEADDR,
- &flag, sizeof flag) < 0)
- error ("Can't set SO_REUSEADDR option on dhcp socket: %m");
-
- if (setsockopt (sock, SOL_SOCKET, SO_BROADCAST,
- &flag, sizeof flag) < 0)
- error ("Can't set SO_BROADCAST option on dhcp socket: %m");
-
- if (bind (sock, (struct sockaddr *)&name, sizeof name) < 0)
- error ("Can't bind to dhcp address: %m");
-
- tmp = (struct socklist *)dmalloc (sizeof (struct socklist),
- "listen_on");
- if (!tmp)
- error ("Can't allocate memory for socket list.");
- tmp -> addr = name;
- tmp -> sock = sock;
- tmp -> next = sockets;
- sockets = tmp;
-}
-
-unsigned char packbuf [4095]; /* Should cover the gnarliest MTU... */
-
-void dispatch ()
-{
- struct sockaddr_in from;
- struct iaddr ifrom;
- int fromlen = sizeof from;
- fd_set r, w, x;
- struct socklist *l;
- int max = 0;
- int count;
- int result;
-
- FD_ZERO (&r);
- FD_ZERO (&w);
- FD_ZERO (&x);
-
- do {
- /* Set up the read mask. */
- for (l = sockets; l; l = l -> next) {
- FD_SET (l -> sock, &r);
- FD_SET (l -> sock, &x);
- if (l -> sock > max)
- max = l -> sock;
- }
-
- /* Wait for a packet or a timeout... XXX */
- count = select (max + 1, &r, &w, &x, (struct timeval *)0);
-
- /* Get the current time... */
- GET_TIME (&cur_time);
-
- /* Not likely to be transitory... */
- if (count < 0)
- error ("select: %m");
-
- for (l = sockets; l; l = l -> next) {
- if (!FD_ISSET (l -> sock, &r))
- continue;
- if ((result =
- recvfrom (l -> sock, packbuf, sizeof packbuf, 0,
- (struct sockaddr *)&from, &fromlen))
- < 0) {
- warn ("recvfrom failed on %s: %m",
- inet_ntoa (l -> addr.sin_addr));
- sleep (5);
- continue;
- }
- note ("request from %s, port %d",
- inet_ntoa (from.sin_addr),
- htons (from.sin_port));
- ifrom.len = 4;
- memcpy (ifrom.iabuf, &from.sin_addr, ifrom.len);
-
- do_packet (packbuf, result, from.sin_port,
- ifrom, l -> sock);
- }
- } while (1);
-}
-
-#ifndef USE_BPF
-
-int sendpkt (packet, raw, len, to, tolen)
- struct packet *packet;
- struct dhcp_packet *raw;
- size_t len;
- struct sockaddr *to;
- int tolen;
-{
- return(sendto(packet->client_sock, raw, len, 0, to, tolen));
-}
-
-#else
-
-static void IpChecksum(struct ip *ip);
-static void UdpChecksum(struct ip *ip);
-static u_int32_t Checksum(u_int16_t *buf, int nwords);
-
-struct raw_packet
-{
- u_int16_t space;
- struct ether_header en_hdr;
- struct ip ip;
- struct udphdr udp;
- struct dhcp_packet dhcp;
-};
-
-int sendpkt (in_packet, raw, len, to, tolen)
- struct packet *in_packet;
- struct dhcp_packet *raw;
- size_t len;
- struct sockaddr *to;
- int tolen;
-{
- int i, k;
- struct iaddr dest;
- struct subnet *subnet;
- struct raw_packet out_packet;
- struct raw_packet *const pkt = &out_packet;
-
-/* Find local subnet, or else forward to gateway */
-
- dest.len = 4;
- memcpy(&dest.iabuf, &((struct sockaddr_in *) to)->sin_addr, dest.len);
- if ((subnet = find_subnet(dest)) == NULL)
- return(sendto(in_packet->client_sock, raw, len, 0, to, tolen));
-
-/* Find interface corresponding to subnet */
-
- for (i = 0; i < num_ifaces; i++)
- {
- for (k = 0; k < subnet->net.len
- && (dest.iabuf[k] & subnet->netmask.iabuf[k])
- == (subnet->net.iabuf[k] & subnet->netmask.iabuf[k]);
- k++);
- if (k == subnet->net.len)
- break;
- }
- if (i == num_ifaces)
- return(sendto(in_packet->client_sock, raw, len, 0, to, tolen));
-
-/* EtherNet header */
-
- memset(pkt->en_hdr.ether_dhost, 0xff, sizeof(pkt->en_hdr.ether_dhost));
- memset(pkt->en_hdr.ether_shost, 0x00, sizeof(pkt->en_hdr.ether_shost));
- pkt->en_hdr.ether_type = ETHERTYPE_IP;
-
-/* IP header (except for checksum) */
-
- pkt->ip.ip_v = 4;
- pkt->ip.ip_hl = 5;
- pkt->ip.ip_tos = IPTOS_LOWDELAY;
- pkt->ip.ip_len = htons(sizeof(pkt->ip) + sizeof(pkt->udp) + len);
- pkt->ip.ip_id = 0;
- pkt->ip.ip_off = 0;
- pkt->ip.ip_ttl = 16;
- pkt->ip.ip_p = IPPROTO_UDP;
- pkt->ip.ip_sum = 0;
- pkt->ip.ip_src = if_list[i].address;
- inet_aton("255.255.255.255", &pkt->ip.ip_dst);
-
-/* UDP header */
-
- pkt->udp.uh_sport = htons(67); /* XXX! */
- pkt->udp.uh_dport = in_packet->client_port;
- pkt->udp.uh_ulen = htons(sizeof(pkt->udp) + len);
- pkt->udp.uh_sum = 0;
-
-/* DHCP packet */
-
- pkt->dhcp = *raw;
-
-/* Compute checksums */
-
- UdpChecksum(&pkt->ip);
- IpChecksum(&pkt->ip);
-
-/* Fire it off */
-
- if (write(if_list[i].bpf, &pkt->en_hdr,
- ntohs(pkt->ip.ip_len) + sizeof(pkt->en_hdr)) < 0)
- warn ("Can't deliver packet: write: %m");
- return(0);
-}
-
-/*
- * UdpChecksum()
- *
- * Recompute a UDP checksum on a packet
- *
- * UDP pseudo-header (prot = IPPROTO_UDP = 17):
- *
- * | source IP address |
- * | dest. IP address |
- * | zero | prot | UDP leng |
- *
- */
-
-static void
-UdpChecksum(struct ip *ip)
-{
- struct udphdr *udp = (struct udphdr *) ((long *) ip + ip->ip_hl);
- u_int32_t sum;
-
-/* Pad with zero */
-
- if (ntohs(udp->uh_ulen) & 0x1)
- *((u_char *) udp + ntohs(udp->uh_ulen)) = 0;
-
-/* Do pseudo-header first */
-
- sum = Checksum((u_int16_t *) &ip->ip_src, 4);
- sum += (u_int16_t) IPPROTO_UDP;
- sum += (u_int16_t) ntohs(udp->uh_ulen);
-
-/* Now do UDP packet itself */
-
- udp->uh_sum = 0;
- sum += Checksum((u_int16_t *) udp,
- ((u_int16_t) ntohs(udp->uh_ulen) + 1) >> 1);
-
-/* Flip it & stick it */
-
- sum = (sum >> 16) + (sum & 0xFFFF);
- sum += (sum >> 16);
- sum = ~sum;
-
- udp->uh_sum = htons(sum);
-}
-
-/*
- * IpChecksum()
- *
- * Recompute an IP header checksum
- *
- */
-
-static void
-IpChecksum(struct ip *ip)
-{
- u_int32_t sum;
-
-/* Sum up IP header words */
-
- ip->ip_sum = 0;
- sum = Checksum((u_int16_t *) ip, ip->ip_hl * 2);
-
-/* Flip it & stick it */
-
- sum = (sum >> 16) + (sum & 0xFFFF);
- sum += (sum >> 16);
- sum = ~sum;
-
- ip->ip_sum = htons(sum);
-}
-
-/*
- * Checksum()
- *
- * Do the one's complement sum thing over a range of words
- * Ideally, this should get replaced by an assembly version.
- */
-
-static u_int32_t
-Checksum(u_int16_t *buf, int nwords)
-{
- u_int32_t sum = 0;
-
- while (nwords--)
- sum += (u_int16_t) ntohs(*buf++);
- return(sum);
-}
-
-#endif
-
diff --git a/common/tables.c b/common/tables.c
deleted file mode 100644
index 5b79b145..00000000
--- a/common/tables.c
+++ /dev/null
@@ -1,670 +0,0 @@
-/* tables.c
-
- Tables of information... */
-
-/*
- * Copyright (c) 1995 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''.
- */
-
-#ifndef lint
-static char copyright[] =
-"@(#) Copyright (c) 1995 The Internet Software Consortium. All rights reserved.\n";
-#endif /* not lint */
-
-#include "dhcpd.h"
-
-/* DHCP Option names, formats and codes, from RFC1533.
-
- Format codes:
-
- e - end of data
- I - IP address
- l - 32-bit signed integer
- L - 32-bit unsigned integer
- s - 16-bit signed integer
- S - 16-bit unsigned integer
- b - 8-bit signed integer
- B - 8-bit unsigned integer
- t - ASCII text
- f - flag (true or false)
- A - array of whatever precedes (e.g., IA means array of IP addresses)
-*/
-
-struct universe dhcp_universe;
-struct option dhcp_options [256] = {
- { "pad", "", &dhcp_universe, 0 },
- { "subnet-mask", "I", &dhcp_universe, 1 },
- { "time-offset", "l", &dhcp_universe, 2 },
- { "routers", "IA", &dhcp_universe, 3 },
- { "time-servers", "IA", &dhcp_universe, 4 },
- { "name-servers", "IA", &dhcp_universe, 5 },
- { "domain-name-servers", "IA", &dhcp_universe, 6 },
- { "log-servers", "IA", &dhcp_universe, 7 },
- { "cookie-servers", "IA", &dhcp_universe, 8 },
- { "lpr-servers", "IA", &dhcp_universe, 9 },
- { "impress-servers", "IA", &dhcp_universe, 10 },
- { "resource-location-servers", "IA", &dhcp_universe, 11 },
- { "host-name", "t", &dhcp_universe, 12 },
- { "boot-size", "S", &dhcp_universe, 13 },
- { "merit-dump", "t", &dhcp_universe, 14 },
- { "domain-name", "t", &dhcp_universe, 15 },
- { "swap-server", "I", &dhcp_universe, 16 },
- { "root-path", "t", &dhcp_universe, 17 },
- { "extensions-path", "t", &dhcp_universe, 18 },
- { "ip-forwarding", "f", &dhcp_universe, 19 },
- { "non-local-source-routing", "f", &dhcp_universe, 20 },
- { "policy-filter", "IIA", &dhcp_universe, 21 },
- { "max-dgram-reassembly", "S", &dhcp_universe, 22 },
- { "default-ip-ttl", "B", &dhcp_universe, 23 },
- { "path-mtu-aging-timeout", "L", &dhcp_universe, 24 },
- { "path-mtu-plateau-table", "SA", &dhcp_universe, 25 },
- { "interface-mtu", "S", &dhcp_universe, 26 },
- { "all-subnets-local", "f", &dhcp_universe, 27 },
- { "broadcast-address", "I", &dhcp_universe, 28 },
- { "perform-mask-discovery", "f", &dhcp_universe, 29 },
- { "mask-supplier", "f", &dhcp_universe, 30 },
- { "router-discovery", "f", &dhcp_universe, 31 },
- { "router-solicitation-address", "I", &dhcp_universe, 32 },
- { "static-routes", "IIA", &dhcp_universe, 33 },
- { "trailer-encapsulation", "f", &dhcp_universe, 34 },
- { "arp-cache-timeout", "L", &dhcp_universe, 35 },
- { "ieee802.3-encapsulation", "f", &dhcp_universe, 36 },
- { "default-tcp-ttl", "B", &dhcp_universe, 37 },
- { "tcp-keepalive-interval", "L", &dhcp_universe, 38 },
- { "tcp-keepalive-garbage", "f", &dhcp_universe, 39 },
- { "nis-domain", "t", &dhcp_universe, 40 },
- { "nis-servers", "IA", &dhcp_universe, 41 },
- { "ntp-servers", "IA", &dhcp_universe, 42 },
- { "vendor-encapsulated-options", "t", &dhcp_universe, 43 },
- { "netbios-name-servers", "IA", &dhcp_universe, 44 },
- { "netbios-dd-server", "IA", &dhcp_universe, 45 },
- { "netbios-node-type", "B", &dhcp_universe, 46 },
- { "netbios-scope", "t", &dhcp_universe, 47 },
- { "font-servers", "IA", &dhcp_universe, 48 },
- { "x-display-manager", "IA", &dhcp_universe, 49 },
- { "dhcp-requested-address", "I", &dhcp_universe, 50 },
- { "dhcp-lease-time", "L", &dhcp_universe, 51 },
- { "dhcp-option-overload", "B", &dhcp_universe, 52 },
- { "dhcp-message-type", "B", &dhcp_universe, 53 },
- { "dhcp-server-identifier", "I", &dhcp_universe, 54 },
- { "dhcp-parameter-request-list", "BA", &dhcp_universe, 55 },
- { "dhcp-message", "t", &dhcp_universe, 56 },
- { "dhcp-max-message-size", "S", &dhcp_universe, 57 },
- { "dhcp-renewal-time", "L", &dhcp_universe, 58 },
- { "dhcp-rebinding-time", "L", &dhcp_universe, 59 },
- { "dhcp-class-identifier", "t", &dhcp_universe, 60 },
- { "dhcp-client-identifier", "BA", &dhcp_universe, 61 },
- { "option-62", "", &dhcp_universe, 62 },
- { "option-63", "", &dhcp_universe, 63 },
- { "option-64", "", &dhcp_universe, 64 },
- { "option-65", "", &dhcp_universe, 65 },
- { "option-66", "", &dhcp_universe, 66 },
- { "option-67", "", &dhcp_universe, 67 },
- { "option-68", "", &dhcp_universe, 68 },
- { "option-69", "", &dhcp_universe, 69 },
- { "option-70", "", &dhcp_universe, 70 },
- { "option-71", "", &dhcp_universe, 71 },
- { "option-72", "", &dhcp_universe, 72 },
- { "option-73", "", &dhcp_universe, 73 },
- { "option-74", "", &dhcp_universe, 74 },
- { "option-75", "", &dhcp_universe, 75 },
- { "option-76", "", &dhcp_universe, 76 },
- { "dhcp-user-class-identifier", "t", &dhcp_universe, 77 },
- { "option-78", "", &dhcp_universe, 78 },
- { "option-79", "", &dhcp_universe, 79 },
- { "option-80", "", &dhcp_universe, 80 },
- { "option-81", "", &dhcp_universe, 81 },
- { "option-82", "", &dhcp_universe, 82 },
- { "option-83", "", &dhcp_universe, 83 },
- { "option-84", "", &dhcp_universe, 84 },
- { "option-85", "", &dhcp_universe, 85 },
- { "option-86", "", &dhcp_universe, 86 },
- { "option-87", "", &dhcp_universe, 87 },
- { "option-88", "", &dhcp_universe, 88 },
- { "option-89", "", &dhcp_universe, 89 },
- { "option-90", "", &dhcp_universe, 90 },
- { "option-91", "", &dhcp_universe, 91 },
- { "option-92", "", &dhcp_universe, 92 },
- { "option-93", "", &dhcp_universe, 93 },
- { "option-94", "", &dhcp_universe, 94 },
- { "option-95", "", &dhcp_universe, 95 },
- { "option-96", "", &dhcp_universe, 96 },
- { "option-97", "", &dhcp_universe, 97 },
- { "option-98", "", &dhcp_universe, 98 },
- { "option-99", "", &dhcp_universe, 99 },
- { "option-100", "", &dhcp_universe, 100 },
- { "option-101", "", &dhcp_universe, 101 },
- { "option-102", "", &dhcp_universe, 102 },
- { "option-103", "", &dhcp_universe, 103 },
- { "option-104", "", &dhcp_universe, 104 },
- { "option-105", "", &dhcp_universe, 105 },
- { "option-106", "", &dhcp_universe, 106 },
- { "option-107", "", &dhcp_universe, 107 },
- { "option-108", "", &dhcp_universe, 108 },
- { "option-109", "", &dhcp_universe, 109 },
- { "option-110", "", &dhcp_universe, 110 },
- { "option-111", "", &dhcp_universe, 111 },
- { "option-112", "", &dhcp_universe, 112 },
- { "option-113", "", &dhcp_universe, 113 },
- { "option-114", "", &dhcp_universe, 114 },
- { "option-115", "", &dhcp_universe, 115 },
- { "option-116", "", &dhcp_universe, 116 },
- { "option-117", "", &dhcp_universe, 117 },
- { "option-118", "", &dhcp_universe, 118 },
- { "option-119", "", &dhcp_universe, 119 },
- { "option-120", "", &dhcp_universe, 120 },
- { "option-121", "", &dhcp_universe, 121 },
- { "option-122", "", &dhcp_universe, 122 },
- { "option-123", "", &dhcp_universe, 123 },
- { "option-124", "", &dhcp_universe, 124 },
- { "option-125", "", &dhcp_universe, 125 },
- { "option-126", "", &dhcp_universe, 126 },
- { "option-127", "", &dhcp_universe, 127 },
- { "option-128", "", &dhcp_universe, 128 },
- { "option-129", "", &dhcp_universe, 129 },
- { "option-130", "", &dhcp_universe, 130 },
- { "option-131", "", &dhcp_universe, 131 },
- { "option-132", "", &dhcp_universe, 132 },
- { "option-133", "", &dhcp_universe, 133 },
- { "option-134", "", &dhcp_universe, 134 },
- { "option-135", "", &dhcp_universe, 135 },
- { "option-136", "", &dhcp_universe, 136 },
- { "option-137", "", &dhcp_universe, 137 },
- { "option-138", "", &dhcp_universe, 138 },
- { "option-139", "", &dhcp_universe, 139 },
- { "option-140", "", &dhcp_universe, 140 },
- { "option-141", "", &dhcp_universe, 141 },
- { "option-142", "", &dhcp_universe, 142 },
- { "option-143", "", &dhcp_universe, 143 },
- { "option-144", "", &dhcp_universe, 144 },
- { "option-145", "", &dhcp_universe, 145 },
- { "option-146", "", &dhcp_universe, 146 },
- { "option-147", "", &dhcp_universe, 147 },
- { "option-148", "", &dhcp_universe, 148 },
- { "option-149", "", &dhcp_universe, 149 },
- { "option-150", "", &dhcp_universe, 150 },
- { "option-151", "", &dhcp_universe, 151 },
- { "option-152", "", &dhcp_universe, 152 },
- { "option-153", "", &dhcp_universe, 153 },
- { "option-154", "", &dhcp_universe, 154 },
- { "option-155", "", &dhcp_universe, 155 },
- { "option-156", "", &dhcp_universe, 156 },
- { "option-157", "", &dhcp_universe, 157 },
- { "option-158", "", &dhcp_universe, 158 },
- { "option-159", "", &dhcp_universe, 159 },
- { "option-160", "", &dhcp_universe, 160 },
- { "option-161", "", &dhcp_universe, 161 },
- { "option-162", "", &dhcp_universe, 162 },
- { "option-163", "", &dhcp_universe, 163 },
- { "option-164", "", &dhcp_universe, 164 },
- { "option-165", "", &dhcp_universe, 165 },
- { "option-166", "", &dhcp_universe, 166 },
- { "option-167", "", &dhcp_universe, 167 },
- { "option-168", "", &dhcp_universe, 168 },
- { "option-169", "", &dhcp_universe, 169 },
- { "option-170", "", &dhcp_universe, 170 },
- { "option-171", "", &dhcp_universe, 171 },
- { "option-172", "", &dhcp_universe, 172 },
- { "option-173", "", &dhcp_universe, 173 },
- { "option-174", "", &dhcp_universe, 174 },
- { "option-175", "", &dhcp_universe, 175 },
- { "option-176", "", &dhcp_universe, 176 },
- { "option-177", "", &dhcp_universe, 177 },
- { "option-178", "", &dhcp_universe, 178 },
- { "option-179", "", &dhcp_universe, 179 },
- { "option-180", "", &dhcp_universe, 180 },
- { "option-181", "", &dhcp_universe, 181 },
- { "option-182", "", &dhcp_universe, 182 },
- { "option-183", "", &dhcp_universe, 183 },
- { "option-184", "", &dhcp_universe, 184 },
- { "option-185", "", &dhcp_universe, 185 },
- { "option-186", "", &dhcp_universe, 186 },
- { "option-187", "", &dhcp_universe, 187 },
- { "option-188", "", &dhcp_universe, 188 },
- { "option-189", "", &dhcp_universe, 189 },
- { "option-190", "", &dhcp_universe, 190 },
- { "option-191", "", &dhcp_universe, 191 },
- { "option-192", "", &dhcp_universe, 192 },
- { "option-193", "", &dhcp_universe, 193 },
- { "option-194", "", &dhcp_universe, 194 },
- { "option-195", "", &dhcp_universe, 195 },
- { "option-196", "", &dhcp_universe, 196 },
- { "option-197", "", &dhcp_universe, 197 },
- { "option-198", "", &dhcp_universe, 198 },
- { "option-199", "", &dhcp_universe, 199 },
- { "option-200", "", &dhcp_universe, 200 },
- { "option-201", "", &dhcp_universe, 201 },
- { "option-202", "", &dhcp_universe, 202 },
- { "option-203", "", &dhcp_universe, 203 },
- { "option-204", "", &dhcp_universe, 204 },
- { "option-205", "", &dhcp_universe, 205 },
- { "option-206", "", &dhcp_universe, 206 },
- { "option-207", "", &dhcp_universe, 207 },
- { "option-208", "", &dhcp_universe, 208 },
- { "option-209", "", &dhcp_universe, 209 },
- { "option-210", "", &dhcp_universe, 210 },
- { "option-211", "", &dhcp_universe, 211 },
- { "option-212", "", &dhcp_universe, 212 },
- { "option-213", "", &dhcp_universe, 213 },
- { "option-214", "", &dhcp_universe, 214 },
- { "option-215", "", &dhcp_universe, 215 },
- { "option-216", "", &dhcp_universe, 216 },
- { "option-217", "", &dhcp_universe, 217 },
- { "option-218", "", &dhcp_universe, 218 },
- { "option-219", "", &dhcp_universe, 219 },
- { "option-220", "", &dhcp_universe, 220 },
- { "option-221", "", &dhcp_universe, 221 },
- { "option-222", "", &dhcp_universe, 222 },
- { "option-223", "", &dhcp_universe, 223 },
- { "option-224", "", &dhcp_universe, 224 },
- { "option-225", "", &dhcp_universe, 225 },
- { "option-226", "", &dhcp_universe, 226 },
- { "option-227", "", &dhcp_universe, 227 },
- { "option-228", "", &dhcp_universe, 228 },
- { "option-229", "", &dhcp_universe, 229 },
- { "option-230", "", &dhcp_universe, 230 },
- { "option-231", "", &dhcp_universe, 231 },
- { "option-232", "", &dhcp_universe, 232 },
- { "option-233", "", &dhcp_universe, 233 },
- { "option-234", "", &dhcp_universe, 234 },
- { "option-235", "", &dhcp_universe, 235 },
- { "option-236", "", &dhcp_universe, 236 },
- { "option-237", "", &dhcp_universe, 237 },
- { "option-238", "", &dhcp_universe, 238 },
- { "option-239", "", &dhcp_universe, 239 },
- { "option-240", "", &dhcp_universe, 240 },
- { "option-241", "", &dhcp_universe, 241 },
- { "option-242", "", &dhcp_universe, 242 },
- { "option-243", "", &dhcp_universe, 243 },
- { "option-244", "", &dhcp_universe, 244 },
- { "option-245", "", &dhcp_universe, 245 },
- { "option-246", "", &dhcp_universe, 246 },
- { "option-247", "", &dhcp_universe, 247 },
- { "option-248", "", &dhcp_universe, 248 },
- { "option-249", "", &dhcp_universe, 249 },
- { "option-250", "", &dhcp_universe, 250 },
- { "option-251", "", &dhcp_universe, 251 },
- { "option-252", "", &dhcp_universe, 252 },
- { "option-253", "", &dhcp_universe, 253 },
- { "option-254", "", &dhcp_universe, 254 },
- { "option-end", "e", &dhcp_universe, 255 },
-};
-
-/* Default dhcp option priority list (this is ad hoc and should not be
- mistaken for a carefully crafted and optimized list). */
-unsigned char dhcp_option_default_priority_list [] = {
- DHO_DHCP_REQUESTED_ADDRESS,
- DHO_DHCP_OPTION_OVERLOAD,
- DHO_DHCP_MAX_MESSAGE_SIZE,
- DHO_DHCP_RENEWAL_TIME,
- DHO_DHCP_REBINDING_TIME,
- DHO_DHCP_CLASS_IDENTIFIER,
- DHO_DHCP_CLIENT_IDENTIFIER,
- DHO_SUBNET_MASK,
- DHO_TIME_OFFSET,
- DHO_ROUTERS,
- DHO_TIME_SERVERS,
- DHO_NAME_SERVERS,
- DHO_DOMAIN_NAME_SERVERS,
- DHO_LOG_SERVERS,
- DHO_COOKIE_SERVERS,
- DHO_LPR_SERVERS,
- DHO_IMPRESS_SERVERS,
- DHO_RESOURCE_LOCATION_SERVERS,
- DHO_HOST_NAME,
- DHO_BOOT_SIZE,
- DHO_MERIT_DUMP,
- DHO_DOMAIN_NAME,
- DHO_SWAP_SERVER,
- DHO_ROOT_PATH,
- DHO_EXTENSIONS_PATH,
- DHO_IP_FORWARDING,
- DHO_NON_LOCAL_SOURCE_ROUTING,
- DHO_POLICY_FILTER,
- DHO_MAX_DGRAM_REASSEMBLY,
- DHO_DEFAULT_IP_TTL,
- DHO_PATH_MTU_AGING_TIMEOUT,
- DHO_PATH_MTU_PLATEAU_TABLE,
- DHO_INTERFACE_MTU,
- DHO_ALL_SUBNETS_LOCAL,
- DHO_BROADCAST_ADDRESS,
- DHO_PERFORM_MASK_DISCOVERY,
- DHO_MASK_SUPPLIER,
- DHO_ROUTER_DISCOVERY,
- DHO_ROUTER_SOLICITATION_ADDRESS,
- DHO_STATIC_ROUTES,
- DHO_TRAILER_ENCAPSULATION,
- DHO_ARP_CACHE_TIMEOUT,
- DHO_IEEE802_3_ENCAPSULATION,
- DHO_DEFAULT_TCP_TTL,
- DHO_TCP_KEEPALIVE_INTERVAL,
- DHO_TCP_KEEPALIVE_GARBAGE,
- DHO_NIS_DOMAIN,
- DHO_NIS_SERVERS,
- DHO_NTP_SERVERS,
- DHO_VENDOR_ENCAPSULATED_OPTIONS,
- DHO_NETBIOS_NAME_SERVERS,
- DHO_NETBIOS_DD_SERVER,
- DHO_NETBIOS_NODE_TYPE,
- DHO_NETBIOS_SCOPE,
- DHO_FONT_SERVERS,
- DHO_X_DISPLAY_MANAGER,
- DHO_DHCP_PARAMETER_REQUEST_LIST,
-};
-
-int sizeof_dhcp_option_default_priority_list =
- sizeof dhcp_option_default_priority_list;
-
-
-char *hardware_types [] = {
- "unknown-0",
- "ethernet",
- "unknown-2",
- "unknown-3",
- "unknown-4",
- "unknown-5",
- "unknown-6",
- "unknown-7",
- "unknown-8",
- "unknown-9",
- "unknown-10",
- "unknown-11",
- "unknown-12",
- "unknown-13",
- "unknown-14",
- "unknown-15",
- "unknown-16",
- "unknown-17",
- "unknown-18",
- "unknown-19",
- "unknown-20",
- "unknown-21",
- "unknown-22",
- "unknown-23",
- "unknown-24",
- "unknown-25",
- "unknown-26",
- "unknown-27",
- "unknown-28",
- "unknown-29",
- "unknown-30",
- "unknown-31",
- "unknown-32",
- "unknown-33",
- "unknown-34",
- "unknown-35",
- "unknown-36",
- "unknown-37",
- "unknown-38",
- "unknown-39",
- "unknown-40",
- "unknown-41",
- "unknown-42",
- "unknown-43",
- "unknown-44",
- "unknown-45",
- "unknown-46",
- "unknown-47",
- "unknown-48",
- "unknown-49",
- "unknown-50",
- "unknown-51",
- "unknown-52",
- "unknown-53",
- "unknown-54",
- "unknown-55",
- "unknown-56",
- "unknown-57",
- "unknown-58",
- "unknown-59",
- "unknown-60",
- "unknown-61",
- "unknown-62",
- "unknown-63",
- "unknown-64",
- "unknown-65",
- "unknown-66",
- "unknown-67",
- "unknown-68",
- "unknown-69",
- "unknown-70",
- "unknown-71",
- "unknown-72",
- "unknown-73",
- "unknown-74",
- "unknown-75",
- "unknown-76",
- "unknown-77",
- "unknown-78",
- "unknown-79",
- "unknown-80",
- "unknown-81",
- "unknown-82",
- "unknown-83",
- "unknown-84",
- "unknown-85",
- "unknown-86",
- "unknown-87",
- "unknown-88",
- "unknown-89",
- "unknown-90",
- "unknown-91",
- "unknown-92",
- "unknown-93",
- "unknown-94",
- "unknown-95",
- "unknown-96",
- "unknown-97",
- "unknown-98",
- "unknown-99",
- "unknown-100",
- "unknown-101",
- "unknown-102",
- "unknown-103",
- "unknown-104",
- "unknown-105",
- "unknown-106",
- "unknown-107",
- "unknown-108",
- "unknown-109",
- "unknown-110",
- "unknown-111",
- "unknown-112",
- "unknown-113",
- "unknown-114",
- "unknown-115",
- "unknown-116",
- "unknown-117",
- "unknown-118",
- "unknown-119",
- "unknown-120",
- "unknown-121",
- "unknown-122",
- "unknown-123",
- "unknown-124",
- "unknown-125",
- "unknown-126",
- "unknown-127",
- "unknown-128",
- "unknown-129",
- "unknown-130",
- "unknown-131",
- "unknown-132",
- "unknown-133",
- "unknown-134",
- "unknown-135",
- "unknown-136",
- "unknown-137",
- "unknown-138",
- "unknown-139",
- "unknown-140",
- "unknown-141",
- "unknown-142",
- "unknown-143",
- "unknown-144",
- "unknown-145",
- "unknown-146",
- "unknown-147",
- "unknown-148",
- "unknown-149",
- "unknown-150",
- "unknown-151",
- "unknown-152",
- "unknown-153",
- "unknown-154",
- "unknown-155",
- "unknown-156",
- "unknown-157",
- "unknown-158",
- "unknown-159",
- "unknown-160",
- "unknown-161",
- "unknown-162",
- "unknown-163",
- "unknown-164",
- "unknown-165",
- "unknown-166",
- "unknown-167",
- "unknown-168",
- "unknown-169",
- "unknown-170",
- "unknown-171",
- "unknown-172",
- "unknown-173",
- "unknown-174",
- "unknown-175",
- "unknown-176",
- "unknown-177",
- "unknown-178",
- "unknown-179",
- "unknown-180",
- "unknown-181",
- "unknown-182",
- "unknown-183",
- "unknown-184",
- "unknown-185",
- "unknown-186",
- "unknown-187",
- "unknown-188",
- "unknown-189",
- "unknown-190",
- "unknown-191",
- "unknown-192",
- "unknown-193",
- "unknown-194",
- "unknown-195",
- "unknown-196",
- "unknown-197",
- "unknown-198",
- "unknown-199",
- "unknown-200",
- "unknown-201",
- "unknown-202",
- "unknown-203",
- "unknown-204",
- "unknown-205",
- "unknown-206",
- "unknown-207",
- "unknown-208",
- "unknown-209",
- "unknown-210",
- "unknown-211",
- "unknown-212",
- "unknown-213",
- "unknown-214",
- "unknown-215",
- "unknown-216",
- "unknown-217",
- "unknown-218",
- "unknown-219",
- "unknown-220",
- "unknown-221",
- "unknown-222",
- "unknown-223",
- "unknown-224",
- "unknown-225",
- "unknown-226",
- "unknown-227",
- "unknown-228",
- "unknown-229",
- "unknown-230",
- "unknown-231",
- "unknown-232",
- "unknown-233",
- "unknown-234",
- "unknown-235",
- "unknown-236",
- "unknown-237",
- "unknown-238",
- "unknown-239",
- "unknown-240",
- "unknown-241",
- "unknown-242",
- "unknown-243",
- "unknown-244",
- "unknown-245",
- "unknown-246",
- "unknown-247",
- "unknown-248",
- "unknown-249",
- "unknown-250",
- "unknown-251",
- "unknown-252",
- "unknown-253",
- "unknown-254",
- "unknown-255" };
-
-
-
-struct hash_table universe_hash;
-
-void initialize_universes()
-{
- int i;
-
- dhcp_universe.name = "dhcp";
- dhcp_universe.hash = new_hash ();
- if (!dhcp_universe.hash)
- error ("Can't allocate dhcp option hash table.");
- for (i = 0; i < 256; i++) {
- dhcp_universe.options [i] = &dhcp_options [i];
- add_hash (dhcp_universe.hash, dhcp_options [i].name, 0,
- (unsigned char *)&dhcp_options [i]);
- }
- universe_hash.hash_count = DEFAULT_HASH_SIZE;
- add_hash (&universe_hash, dhcp_universe.name, 0,
- (unsigned char *)&dhcp_universe);
-}
diff --git a/common/tree.c b/common/tree.c
deleted file mode 100644
index 3c667726..00000000
--- a/common/tree.c
+++ /dev/null
@@ -1,394 +0,0 @@
-/* tree.c
-
- Routines for manipulating parse trees... */
-
-/*
- * Copyright (c) 1995 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''.
- */
-
-#ifndef lint
-static char copyright[] =
-"@(#) Copyright (c) 1995 The Internet Software Consortium. All rights reserved.\n";
-#endif /* not lint */
-
-#include "dhcpd.h"
-
-static TIME tree_evaluate_recurse PROTO ((int *, unsigned char **, int *,
- struct tree *));
-static TIME do_host_lookup PROTO ((int *, unsigned char **, int *,
- struct dns_host_entry *));
-static void do_data_copy PROTO ((int *, unsigned char **, int *,
- unsigned char *, int));
-
-pair cons (car, cdr)
- caddr_t car;
- pair cdr;
-{
- pair foo = (pair)dmalloc (sizeof *foo, "cons");
- if (!foo)
- error ("no memory for cons.");
- foo -> car = car;
- foo -> cdr = cdr;
- return foo;
-}
-
-struct tree_cache *tree_cache (tree)
- struct tree *tree;
-{
- struct tree_cache *tc;
-
- tc = new_tree_cache ("tree_cache");
- if (!tc)
- return 0;
- tc -> value = (char *)0;
- tc -> len = tc -> buf_size = 0;
- tc -> timeout = 0;
- tc -> tree = tree;
- return tc;
-}
-
-struct tree *tree_host_lookup (name)
- char *name;
-{
- struct tree *nt;
- nt = new_tree ("tree_host_lookup");
- if (!nt)
- error ("No memory for host lookup tree node.");
- nt -> op = TREE_HOST_LOOKUP;
- nt -> data.host_lookup.host = enter_dns_host (name);
- return nt;
-}
-
-struct dns_host_entry *enter_dns_host (name)
- char *name;
-{
- struct dns_host_entry *dh;
-
- if (!(dh = (struct dns_host_entry *)dmalloc
- (sizeof (struct dns_host_entry), "enter_dns_host"))
- || !(dh -> hostname = dmalloc (strlen (name) + 1,
- "enter_dns_host")))
- error ("Can't allocate space for new host.");
- strcpy (dh -> hostname, name);
- dh -> data = (unsigned char *)0;
- dh -> data_len = 0;
- dh -> buf_len = 0;
- dh -> timeout = 0;
- return dh;
-}
-
-struct tree *tree_const (data, len)
- unsigned char *data;
- int len;
-{
- struct tree *nt;
- if (!(nt = new_tree ("tree_const"))
- || !(nt -> data.const_val.data =
- (unsigned char *)dmalloc (len, "tree_const")))
- error ("No memory for constant data tree node.");
- nt -> op = TREE_CONST;
- memcpy (nt -> data.const_val.data, data, len);
- nt -> data.const_val.len = len;
- return nt;
-}
-
-struct tree *tree_concat (left, right)
- struct tree *left, *right;
-{
- struct tree *nt;
-
- /* If we're concatenating a null tree to a non-null tree, just
- return the non-null tree; if both trees are null, return
- a null tree. */
- if (!left)
- return right;
- if (!right)
- return left;
-
- /* If both trees are constant, combine them. */
- if (left -> op == TREE_CONST && right -> op == TREE_CONST) {
- unsigned char *buf = dmalloc (left -> data.const_val.len
- + right -> data.const_val.len,
- "tree_concat");
- if (!buf)
- error ("No memory to concatenate constants.");
- memcpy (buf, left -> data.const_val.data,
- left -> data.const_val.len);
- memcpy (buf + left -> data.const_val.len,
- right -> data.const_val.data,
- right -> data.const_val.len);
- dfree (left -> data.const_val.data, "tree_concat");
- dfree (right -> data.const_val.data, "tree_concat");
- left -> data.const_val.data = buf;
- left -> data.const_val.len += right -> data.const_val.len;
- free_tree (right, "tree_concat");
- return left;
- }
-
- /* Otherwise, allocate a new node to concatenate the two. */
- if (!(nt = new_tree ("tree_concat")))
- error ("No memory for data tree concatenation node.");
- nt -> op = TREE_CONCAT;
- nt -> data.concat.left = left;
- nt -> data.concat.right = right;
- return nt;
-}
-
-struct tree *tree_limit (tree, limit)
- struct tree *tree;
- int limit;
-{
- struct tree *rv;
-
- /* If the tree we're limiting is constant, limit it now. */
- if (tree -> op == TREE_CONST) {
- if (tree -> data.const_val.len > limit)
- tree -> data.const_val.len = limit;
- return tree;
- }
-
- /* Otherwise, put in a node which enforces the limit on evaluation. */
- rv = new_tree ("tree_limit");
- if (!rv)
- return (struct tree *)0;
- rv -> op = TREE_LIMIT;
- rv -> data.limit.tree = tree;
- rv -> data.limit.limit = limit;
- return rv;
-}
-
-int tree_evaluate (tree_cache)
- struct tree_cache *tree_cache;
-{
- unsigned char *bp = tree_cache -> value;
- int bc = tree_cache -> buf_size;
- int bufix = 0;
-
- /* If there's no tree associated with this cache, it evaluates
- to a constant and that was detected at startup. */
- if (!tree_cache -> tree)
- return 1;
-
- /* Try to evaluate the tree without allocating more memory... */
- tree_cache -> timeout = tree_evaluate_recurse (&bufix, &bp, &bc,
- tree_cache -> tree);
-
- /* No additional allocation needed? */
- if (bufix <= bc) {
- tree_cache -> len = bufix;
- return 1;
- }
-
- /* If we can't allocate more memory, return with what we
- have (maybe nothing). */
- if (!(bp = (unsigned char *)dmalloc (bufix, "tree_evaluate")))
- return 0;
-
- /* Record the change in conditions... */
- bc = bufix;
- bufix = 0;
-
- /* Note that the size of the result shouldn't change on the
- second call to tree_evaluate_recurse, since we haven't
- changed the ``current'' time. */
- tree_evaluate_recurse (&bufix, &bp, &bc, tree_cache -> tree);
-
- /* Free the old buffer if needed, then store the new buffer
- location and size and return. */
- if (tree_cache -> value)
- dfree (tree_cache -> value, "tree_evaluate");
- tree_cache -> value = bp;
- tree_cache -> len = bufix;
- tree_cache -> buf_size = bc;
- return 1;
-}
-
-static TIME tree_evaluate_recurse (bufix, bufp, bufcount, tree)
- int *bufix;
- unsigned char **bufp;
- int *bufcount;
- struct tree *tree;
-{
- int limit;
- TIME t1, t2;
-
- switch (tree -> op) {
- case TREE_CONCAT:
- t1 = tree_evaluate_recurse (bufix, bufp, bufcount,
- tree -> data.concat.left);
- t2 = tree_evaluate_recurse (bufix, bufp, bufcount,
- tree -> data.concat.right);
- if (t1 > t2)
- return t2;
- return t1;
-
- case TREE_HOST_LOOKUP:
- return do_host_lookup (bufix, bufp, bufcount,
- tree -> data.host_lookup.host);
-
- case TREE_CONST:
- do_data_copy (bufix, bufp, bufcount,
- tree -> data.const_val.data,
- tree -> data.const_val.len);
- t1 = MAX_TIME;
- return t1;
-
- case TREE_LIMIT:
- limit = *bufix + tree -> data.limit.limit;
- t1 = tree_evaluate_recurse (bufix, bufp, bufcount,
- tree -> data.limit.tree);
- *bufix = limit;
- return t1;
-
- default:
- warn ("Bad node id in tree: %d.");
- t1 = MAX_TIME;
- return t1;
- }
-}
-
-static TIME do_host_lookup (bufix, bufp, bufcount, dns)
- int *bufix;
- unsigned char **bufp;
- int *bufcount;
- struct dns_host_entry *dns;
-{
- struct hostent *h;
- int i;
- int new_len;
-
- debug ("time: now = %d dns = %d %d diff = %d",
- cur_time, dns -> timeout, cur_time - dns -> timeout);
-
- /* 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,
- dns -> data ? *(int *)(dns -> data) : 0);
- do_data_copy (bufix, bufp, bufcount,
- dns -> data, dns -> data_len);
- return dns -> timeout;
- }
- debug ("Looking up %s", dns -> hostname);
-
- /* Otherwise, look it up... */
- h = gethostbyname (dns -> hostname);
- if (!h) {
- switch (h_errno) {
- case HOST_NOT_FOUND:
- warn ("%s: host unknown.", dns -> hostname);
- break;
- case TRY_AGAIN:
- warn ("%s: temporary name server failure",
- dns -> hostname);
- break;
- case NO_RECOVERY:
- warn ("%s: name server failed", dns -> hostname);
- break;
- case NO_DATA:
- warn ("%s: no A record associated with address",
- dns -> hostname);
- }
-
- /* Okay to try again after a minute. */
- return cur_time + 60;
- }
-
- debug ("Lookup succeeded; first address is %x",
- h -> h_addr_list [0]);
-
- /* Count the number of addresses we got... */
- for (i = 0; h -> h_addr_list [i]; i++)
- ;
-
- /* Do we need to allocate more memory? */
- new_len = i * h -> h_length;
- if (dns -> buf_len < i) {
- unsigned char *buf =
- (unsigned char *)dmalloc (new_len, "do_host_lookup");
- /* If we didn't get more memory, use what we have. */
- if (!buf) {
- new_len = dns -> buf_len;
- if (!dns -> buf_len) {
- dns -> timeout = cur_time + 60;
- return dns -> timeout;
- }
- } else {
- dfree (dns -> data, "do_host_lookup");
- dns -> data = buf;
- dns -> buf_len = new_len;
- }
- }
-
- /* Addresses are conveniently stored one to the buffer, so we
- have to copy them out one at a time... :'( */
- for (i = 0; i < new_len / h -> h_length; i++) {
- memcpy (dns -> data + h -> h_length * i,
- h -> h_addr_list [i], h -> h_length);
- }
- debug ("dns -> data: %x h -> h_addr_list [0]: %x",
- *(int *)(dns -> data), h -> h_addr_list [0]);
- dns -> data_len = new_len;
-
- /* Set the timeout for an hour from now.
- XXX This should really use the time on the DNS reply. */
- dns -> timeout = cur_time + 3600;
-
- debug ("hard copy: %x %d %x",
- dns -> data, dns -> data_len, *(int *)(dns -> data));
- do_data_copy (bufix, bufp, bufcount, dns -> data, dns -> data_len);
- return dns -> timeout;
-}
-
-static void do_data_copy (bufix, bufp, bufcount, data, len)
- int *bufix;
- unsigned char **bufp;
- int *bufcount;
- unsigned char *data;
- int len;
-{
- int space = *bufcount - *bufix;
-
- /* If there's more space than we need, use only what we need. */
- if (space > len)
- space = len;
-
- /* Copy as much data as will fit, then increment the buffer index
- by the amount we actually had to copy, which could be more. */
- if (space > 0)
- memcpy (*bufp + *bufix, data, space);
- *bufix += len;
-}