From: Ted Lemon Date: Wed, 8 Sep 1999 01:49:56 +0000 (+0000) Subject: Support dynamically-created host entries. X-Git-Tag: V3-BETA-1-PATCH-2~5^2~117 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=612fded7350904ebb81f1c9444176961cf34f12a;p=thirdparty%2Fdhcp.git Support dynamically-created host entries. --- diff --git a/server/confpars.c b/server/confpars.c index be3ffa244..048793220 100644 --- a/server/confpars.c +++ b/server/confpars.c @@ -22,7 +22,7 @@ #ifndef lint static char copyright[] = -"$Id: confpars.c,v 1.76 1999/07/20 18:00:20 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; +"$Id: confpars.c,v 1.77 1999/09/08 01:49:56 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -897,6 +897,7 @@ void parse_host_declaration (cfile, group) struct host_decl *host; char *name; int declaration = 0; + int dynamicp = 0; token = peek_token (&val, cfile); if (token != LBRACE) { @@ -929,12 +930,21 @@ void parse_host_declaration (cfile, group) parse_warn ("unexpected end of file"); break; } + /* If the host declaration was created by the server, + remember to save it. */ + if (token == DYNAMIC) { + dynamicp = 1; + token = next_token (&val, cfile); + if (!parse_semi (cfile)) + break; + continue; + } declaration = parse_statement (cfile, host -> group, HOST_DECL, host, declaration); } while (1); - enter_host (host); + enter_host (host, dynamicp); } /* class-declaration :== STRING LBRACE parameters declarations RBRACE diff --git a/server/db.c b/server/db.c index cc055b9fb..396e0cdd6 100644 --- a/server/db.c +++ b/server/db.c @@ -22,7 +22,7 @@ #ifndef lint static char copyright[] = -"$Id: db.c,v 1.25 1999/07/01 19:55:12 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; +"$Id: db.c,v 1.26 1999/09/08 01:49:56 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -55,22 +55,28 @@ int write_lease (lease) /* Note: the following is not a Y2K bug - it's a Y1.9K bug. Until somebody invents a time machine, I think we can safely disregard it. */ - t = gmtime (&lease -> starts); - sprintf (tbuf, "%d %d/%02d/%02d %02d:%02d:%02d;", - t -> tm_wday, t -> tm_year + 1900, - t -> tm_mon + 1, t -> tm_mday, - t -> tm_hour, t -> tm_min, t -> tm_sec); + if (lease -> starts != MAX_TIME) { + t = gmtime (&lease -> starts); + sprintf (tbuf, "%d %d/%02d/%02d %02d:%02d:%02d;", + t -> tm_wday, t -> tm_year + 1900, + t -> tm_mon + 1, t -> tm_mday, + t -> tm_hour, t -> tm_min, t -> tm_sec); + } else + strcpy (tbuf, "infinite"); errno = 0; fprintf (db_file, "\tstarts %s\n", tbuf); if (errno) { ++errors; } - t = gmtime (&lease -> ends); - sprintf (tbuf, "%d %d/%02d/%02d %02d:%02d:%02d;", - t -> tm_wday, t -> tm_year + 1900, - t -> tm_mon + 1, t -> tm_mday, - t -> tm_hour, t -> tm_min, t -> tm_sec); + if (lease -> ends != MAX_TIME) { + t = gmtime (&lease -> ends); + sprintf (tbuf, "%d %d/%02d/%02d %02d:%02d:%02d;", + t -> tm_wday, t -> tm_year + 1900, + t -> tm_mon + 1, t -> tm_mday, + t -> tm_hour, t -> tm_min, t -> tm_sec); + } else + strcpy (tbuf, "infinite"); errno = 0; fprintf (db_file, "\tends %s", tbuf); if (errno) { @@ -169,6 +175,93 @@ int write_lease (lease) return !errors; } +int write_host (host) + struct host_decl *host; +{ + int errors = 0; + int i; + struct data_string ip_addrs; + + if (!db_printable (host -> name)) + return 0; + + if (counting) + ++count; + errno = 0; + + fprintf (db_file, "host %s {", host -> name); + if (errno) { + ++errors; + } + + errno = 0; + fprintf (db_file, "\n\tdynamic;"); + if (errno) + ++errors; + if (host -> interface.hlen) { + errno = 0; + fprintf (db_file, "\n\thardware %s %s;", + hardware_types [host -> interface.htype], + print_hw_addr (host -> interface.htype, + host -> interface.hlen, + host -> interface.haddr)); + if (errno) { + ++errors; + } + } + if (host -> client_identifier.len) { + int i; + errno = 0; + fprintf (db_file, "\n\toption dhcp-client-identifier %2.2x", + host -> client_identifier.data [0]); + if (errno) { + ++errors; + } + for (i = 1; i < host -> client_identifier.len; i++) { + errno = 0; + fprintf (db_file, ":%2.2x", + host -> client_identifier.data [i]); + if (errno) { + ++errors; + } + } + putc (';', db_file); + } + + if (host -> fixed_addr && + evaluate_option_cache (&ip_addrs, (struct packet *)0, + (struct lease *)0, + (struct option_state *)0, + (struct option_state *)0, + host -> fixed_addr)) { + + fprintf (db_file, "\n\tfixed-address "); + if (errno) { + ++errors; + } + for (i = 0; i < ip_addrs.len - 3; i += 4) { + fprintf (db_file, "\n\t%d.%d.%d.%d%s", + ip_addrs.data [i], ip_addrs.data [i + 1], + ip_addrs.data [i + 2], ip_addrs.data [i + 3], + i + 7 < ip_addrs.len ? "," : ""); + + if (errno) { + ++errors; + } + } + } + + errno = 0; + fputs ("\n}\n", db_file); + if (errno) { + ++errors; + } + if (errors) + log_info ("write_host: unable to write host %s", + host -> name); + return !errors; +} + int db_printable (s) char *s; {