diff options
-rw-r--r-- | Makefile.conf | 5 | ||||
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | RELNOTES | 2 | ||||
-rw-r--r-- | common/conflex.c | 6 | ||||
-rw-r--r-- | common/parse.c | 4 | ||||
-rw-r--r-- | common/print.c | 4 | ||||
-rw-r--r-- | common/tables.c | 10 | ||||
-rw-r--r-- | dst/dst_api.c | 5 | ||||
-rw-r--r-- | includes/dhcpd.h | 2 | ||||
-rw-r--r-- | includes/tree.h | 4 | ||||
-rw-r--r-- | minires/ns_date.c | 6 | ||||
-rw-r--r-- | minires/res_init.c | 5 | ||||
-rw-r--r-- | minires/res_query.c | 5 | ||||
-rw-r--r-- | omapip/hash.c | 10 | ||||
-rw-r--r-- | server/db.c | 142 | ||||
-rw-r--r-- | server/dhcpd.c | 4 | ||||
-rw-r--r-- | server/failover.c | 51 | ||||
-rw-r--r-- | server/mdb.c | 47 |
18 files changed, 179 insertions, 135 deletions
diff --git a/Makefile.conf b/Makefile.conf index 8d6cb796..e50e3c59 100644 --- a/Makefile.conf +++ b/Makefile.conf @@ -230,9 +230,8 @@ MINORVERSION=MinorVersion #CF = cf/netbsd.h #COPTS = -Wall -Wstrict-prototypes -Wno-unused -Wno-comment \ # -Wno-uninitialized $(WARNERR) \ -# -Wimplicit-function-declaration -Wpointer-arith -Wcast-qual \ -# -Wwrite-strings -Wmissing-prototypes \ -# -Wmissing-declarations -Wnested-externs \ +# -Wimplicit-function-declaration -Wpointer-arith \ +# -Wwrite-strings -Wnested-externs \ # -pipe $(BINDDEF) $(CC_OPTIONS) #SCRIPT=netbsd ##--netbsd-- @@ -1,6 +1,6 @@ Internet Systems Consortium DHCP Distribution Version 3.1.0rc1 - June 6, 2007 + June 11, 2007 README FILE @@ -1,6 +1,6 @@ Internet Systems Consortium DHCP Distribution Version 3.1.0rc1 - June 6, 2007 + June 11, 2007 Release Notes diff --git a/common/conflex.c b/common/conflex.c index 9ae06533..baae0112 100644 --- a/common/conflex.c +++ b/common/conflex.c @@ -34,7 +34,7 @@ #ifndef lint static char copyright[] = -"$Id: conflex.c,v 1.105 2006/08/04 10:59:32 shane Exp $ Copyright (c) 2004-2006 Internet Systems Consortium. All rights reserved.\n"; +"$Id: conflex.c,v 1.105.92.1 2007/06/11 22:53:34 each Exp $ Copyright (c) 2004-2006 Internet Systems Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -46,7 +46,7 @@ static void skip_to_eol PROTO ((struct parse *)); static enum dhcp_token read_string PROTO ((struct parse *)); static enum dhcp_token read_number PROTO ((int, struct parse *)); static enum dhcp_token read_num_or_name PROTO ((int, struct parse *)); -static enum dhcp_token intern PROTO ((char *, enum dhcp_token)); +static enum dhcp_token intern PROTO ((unsigned char *, enum dhcp_token)); isc_result_t new_parse (cfile, file, inbuf, buflen, name, eolp) struct parse **cfile; @@ -528,7 +528,7 @@ static enum dhcp_token read_num_or_name (c, cfile) } static enum dhcp_token intern (atom, dfv) - char *atom; + unsigned char *atom; enum dhcp_token dfv; { if (!isascii (atom [0])) diff --git a/common/parse.c b/common/parse.c index fb08e6c1..d98d6908 100644 --- a/common/parse.c +++ b/common/parse.c @@ -34,7 +34,7 @@ #ifndef lint static char copyright[] = -"$Id: parse.c,v 1.117.8.4 2007/04/16 17:33:00 dhankins Exp $ Copyright (c) 2004-2007 Internet Systems Consortium. All rights reserved.\n"; +"$Id: parse.c,v 1.117.8.4.10.1 2007/06/11 22:53:34 each Exp $ Copyright (c) 2004-2007 Internet Systems Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -614,7 +614,7 @@ void convert_num (cfile, buf, str, base, size) int base; unsigned size; { - const char *ptr = str; + const unsigned char *ptr = str; int negative = 0; u_int32_t val = 0; int tval; diff --git a/common/print.c b/common/print.c index 11f3e868..163e3150 100644 --- a/common/print.c +++ b/common/print.c @@ -34,7 +34,7 @@ #ifndef lint static char copyright[] = -"$Id: print.c,v 1.61.12.3 2007/02/14 22:41:22 dhankins Exp $ Copyright (c) 2004-2007 Internet Systems Consortium. All rights reserved.\n"; +"$Id: print.c,v 1.61.12.3.10.1 2007/06/11 22:53:34 each Exp $ Copyright (c) 2004-2007 Internet Systems Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -44,7 +44,7 @@ int db_time_format = DEFAULT_TIME_FORMAT; char *quotify_string (const char *s, const char *file, int line) { unsigned len = 0; - const char *sp; + const unsigned char *sp; char *buf, *nsp; for (sp = s; sp && *sp; sp++) { diff --git a/common/tables.c b/common/tables.c index 36aea5f9..d2677081 100644 --- a/common/tables.c +++ b/common/tables.c @@ -34,7 +34,7 @@ #ifndef lint static char copyright[] = -"$Id: tables.c,v 1.58.14.4 2007/02/14 22:41:22 dhankins Exp $ Copyright (c) 2004-2007 Internet Systems Consortium. All rights reserved.\n"; +"$Id: tables.c,v 1.58.14.4.10.1 2007/06/11 22:53:34 each Exp $ Copyright (c) 2004-2007 Internet Systems Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -562,7 +562,7 @@ struct universe *config_universe; * option structures omapi typed objects, which is a bigger headache. */ -char *default_option_format = "X"; +char *default_option_format = (char *) "X"; /* Must match hash_reference/dereference types in omapip/hash.h. */ int @@ -617,14 +617,14 @@ option_dereference(struct option **dest, const char *file, int line) /* The option name may be packed in the same alloc as the * option structure. */ - if ((*dest)->name != (char *)((*dest) + 1)) - dfree((*dest)->name, file, line); + if ((char *) (*dest)->name != (char *)((*dest) + 1)) + dfree((char *) (*dest)->name, file, line); /* It's either a user-configured format (allocated), or the * default static format. */ if ((*dest)->format != default_option_format) - dfree((*dest)->format, file, line); + dfree((char *) (*dest)->format, file, line); dfree(*dest, file, line); } diff --git a/dst/dst_api.c b/dst/dst_api.c index 3af7dc4c..96365222 100644 --- a/dst/dst_api.c +++ b/dst/dst_api.c @@ -1,5 +1,5 @@ #ifndef LINT -static const char rcsid[] = "$Header: /tmp/cvstest/DHCP/dst/dst_api.c,v 1.1 2001/02/22 07:22:08 mellon Exp $"; +static const char rcsid[] = "$Header: /tmp/cvstest/DHCP/dst/dst_api.c,v 1.1.534.1 2007/06/11 22:53:34 each Exp $"; #endif /* @@ -470,7 +470,8 @@ dst_s_read_public_key(const char *in_name, const unsigned in_id, int in_alg) unsigned flags, len; int proto, alg, dlen; int c; - char name[PATH_MAX], enckey[RAW_KEY_SIZE], *notspace; + char name[PATH_MAX], enckey[RAW_KEY_SIZE]; + unsigned char *notspace; u_char deckey[RAW_KEY_SIZE]; FILE *fp; diff --git a/includes/dhcpd.h b/includes/dhcpd.h index b621eb95..6a17afca 100644 --- a/includes/dhcpd.h +++ b/includes/dhcpd.h @@ -2086,7 +2086,7 @@ int write_host PROTO ((struct host_decl *)); #if defined (FAILOVER_PROTOCOL) int write_failover_state (dhcp_failover_state_t *); #endif -int db_printable PROTO ((const char *)); +int db_printable PROTO ((const unsigned char *)); int db_printable_len PROTO ((const unsigned char *, unsigned)); isc_result_t write_named_billing_class(const void *, unsigned, void *); void write_billing_classes (void); diff --git a/includes/tree.h b/includes/tree.h index 64b731a4..e5c52b0a 100644 --- a/includes/tree.h +++ b/includes/tree.h @@ -337,8 +337,8 @@ struct universe { }; struct option { - char *name; - char *format; + const char *name; + const char *format; struct universe *universe; unsigned code; int refcnt; diff --git a/minires/ns_date.c b/minires/ns_date.c index 5f3cb6cb..12d24af2 100644 --- a/minires/ns_date.c +++ b/minires/ns_date.c @@ -22,7 +22,7 @@ */ #ifndef lint -static const char rcsid[] = "$Id: ns_date.c,v 1.3 2005/03/17 20:15:17 dhankins Exp $"; +static const char rcsid[] = "$Id: ns_date.c,v 1.3.388.1 2007/06/11 22:53:34 each Exp $"; #endif /* Import. */ @@ -48,7 +48,7 @@ static const char rcsid[] = "$Id: ns_date.c,v 1.3 2005/03/17 20:15:17 dhankins E /* Forward. */ -static int datepart(const char *, int, int, int, int *); +static int datepart(const unsigned char *, int, int, int, int *); /* Public. */ @@ -118,7 +118,7 @@ ns_datetosecs(const char *cp, int *errp) { * Don't reset the flag if there is no error. */ static int -datepart(const char *buf, int size, int min, int max, int *errp) { +datepart(const unsigned char *buf, int size, int min, int max, int *errp) { int result = 0; int i; diff --git a/minires/res_init.c b/minires/res_init.c index e8170eab..04f93d0b 100644 --- a/minires/res_init.c +++ b/minires/res_init.c @@ -76,7 +76,7 @@ #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; -static const char rcsid[] = "$Id: res_init.c,v 1.6 2005/03/17 20:15:19 dhankins Exp $"; +static const char rcsid[] = "$Id: res_init.c,v 1.6.388.1 2007/06/11 22:53:34 each Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -154,7 +154,8 @@ res_ninit(res_state statp) { int minires_vinit(res_state statp, int preinit) { register FILE *fp; - register char *cp, **pp; + register unsigned char *cp; + register char **pp; register int n; char buf[BUFSIZ]; int nserv = 0; /* number of nameserver records read from file */ diff --git a/minires/res_query.c b/minires/res_query.c index 0c28f75b..be181b34 100644 --- a/minires/res_query.c +++ b/minires/res_query.c @@ -76,7 +76,7 @@ #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$Id: res_query.c,v 1.5 2005/03/17 20:15:19 dhankins Exp $"; +static const char rcsid[] = "$Id: res_query.c,v 1.5.388.1 2007/06/11 22:53:34 each Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -383,7 +383,8 @@ res_nquerydomain(res_state statp, const char * res_hostalias(const res_state statp, const char *name, char *dst, size_t siz) { - char *file, *cp1, *cp2; + char *file; + unsigned char *cp1, *cp2; char buf[BUFSIZ]; FILE *fp; diff --git a/omapip/hash.c b/omapip/hash.c index 9a4c251e..51269e3d 100644 --- a/omapip/hash.c +++ b/omapip/hash.c @@ -34,7 +34,7 @@ #ifndef lint static char copyright[] = -"$Id: hash.c,v 1.11.16.1 2006/10/27 22:54:50 dhankins Exp $ Copyright (c) 2004-2006 Internet Systems Consortium. All rights reserved.\n"; +"$Id: hash.c,v 1.11.16.1.10.1 2007/06/11 22:53:34 each Exp $ Copyright (c) 2004-2006 Internet Systems Consortium. All rights reserved.\n"; #endif /* not lint */ #include <omapip/omapip_p.h> @@ -349,7 +349,7 @@ hash_report(struct hash_table *table) struct hash_bucket *bp; if (table->hash_count == 0) - return "Invalid hash table."; + return (char *) "Invalid hash table."; for (i = 0 ; i < table->hash_count ; i++) { curlen = 0; @@ -378,7 +378,7 @@ hash_report(struct hash_table *table) pct > 2147483647 || minlen > 2147483647 || maxlen > 2147483647) - return "Report out of range for display."; + return (char *) "Report out of range for display."; sprintf(retbuf, "Contents/Size (%%): %u/%u (%u%%). Min/max: %u/%u", contents, table->hash_count, pct, minlen, maxlen); @@ -527,8 +527,8 @@ int hash_foreach (struct hash_table *table, hash_foreach_func func) int casecmp (const void *v1, const void *v2, size_t len) { size_t i; - const char *s = v1; - const char *t = v2; + const unsigned char *s = v1; + const unsigned char *t = v2; for (i = 0; i < len; i++) { diff --git a/server/db.c b/server/db.c index 462e1a8f..4939fb7f 100644 --- a/server/db.c +++ b/server/db.c @@ -34,7 +34,7 @@ #ifndef lint static char copyright[] = -"$Id: db.c,v 1.74.32.1 2006/10/27 22:54:50 dhankins Exp $ Copyright (c) 2004-2006 Internet Systems Consortium. All rights reserved.\n"; +"$Id: db.c,v 1.74.32.1.10.1 2007/06/11 22:53:34 each Exp $ Copyright (c) 2004-2006 Internet Systems Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -71,7 +71,7 @@ int write_lease (lease) fprintf (db_file, "lease %s {", piaddr (lease -> ip_addr)); if (errno) { ++errors; - } + } if (lease->starts && ((tval = print_time(lease->starts)) == NULL || @@ -103,24 +103,29 @@ int write_lease (lease) fprintf(db_file, "\n cltt %s", tval) < 0)) ++errors; - fprintf (db_file, "\n binding state %s;", + if (fprintf (db_file, "\n binding state %s;", ((lease -> binding_state > 0 && lease -> binding_state <= FTS_LAST) ? binding_state_names [lease -> binding_state - 1] - : "abandoned")); + : "abandoned")) < 0) + ++errors; if (lease -> binding_state != lease -> next_binding_state) - fprintf (db_file, "\n next binding state %s;", + if (fprintf (db_file, "\n next binding state %s;", ((lease -> next_binding_state > 0 && lease -> next_binding_state <= FTS_LAST) ? (binding_state_names [lease -> next_binding_state - 1]) - : "abandoned")); + : "abandoned")) < 0) + ++errors; if (lease->flags & RESERVED_LEASE) - fprintf(db_file, "\n reserved;"); + if (fprintf(db_file, "\n reserved;") < 0) + ++errors; + if (lease->flags & BOOTP_LEASE) - fprintf(db_file, "\n dynamic-bootp;"); + if (fprintf(db_file, "\n dynamic-bootp;") < 0) + ++errors; /* If this lease is billed to a class and is still valid, write it out. */ @@ -139,14 +144,14 @@ int write_lease (lease) print_hw_addr (lease -> hardware_addr.hbuf [0], lease -> hardware_addr.hlen - 1, &lease -> hardware_addr.hbuf [1])); - if (errno) { + if (errno) ++errors; - } } if (lease -> uid_len) { int i; s = quotify_buf (lease -> uid, lease -> uid_len, MDL); if (s) { + errno = 0; fprintf (db_file, "\n uid \"%s\";", s); if (errno) ++errors; @@ -233,31 +238,33 @@ int write_lease (lease) fprintf (db_file, "\n on expiry%s {", lease -> on_expiry == lease -> on_release ? " or release" : ""); - if (errno) - ++errors; write_statements (db_file, lease -> on_expiry, 4); /* XXX */ fprintf (db_file, "\n }"); + if (errno) + ++errors; } if (lease -> on_release && lease -> on_release != lease -> on_expiry) { errno = 0; fprintf (db_file, "\n on release {"); - if (errno) - ++errors; write_statements (db_file, lease -> on_release, 4); /* XXX */ fprintf (db_file, "\n }"); + if (errno) + ++errors; } + errno = 0; fputs ("\n}\n", db_file); - if (errno) { + if (errno) ++errors; - } - if (errors) + + if (errors) { log_info ("write_lease: unable to write lease %s", piaddr (lease -> ip_addr)); - if (errors) lease_file_is_corrupt = 1; + } + return !errors; } @@ -279,12 +286,11 @@ int write_host (host) if (counting) ++count; - errno = 0; + errno = 0; fprintf (db_file, "host %s {", host -> name); - if (errno) { + if (errno) ++errors; - } if (host -> flags & HOST_DECL_DYNAMIC) { errno = 0; @@ -306,9 +312,8 @@ int write_host (host) print_hw_addr (host -> interface.hbuf [0], host -> interface.hlen - 1, &host -> interface.hbuf [1])); - if (errno) { + if (errno) ++errors; - } } if (host -> client_identifier.len) { int i; @@ -318,24 +323,28 @@ int write_host (host) fprintf (db_file, "\n uid \"%.*s\";", (int)host -> client_identifier.len, host -> client_identifier.data); + if (errno) + ++errors; } else { fprintf (db_file, "\n uid %2.2x", host -> client_identifier.data [0]); - if (errno) { + 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) { + if (errno) ++errors; - } } - putc (';', db_file); + + errno = 0; + fputc (';', db_file); + if (errno) + ++errors; } } @@ -351,10 +360,10 @@ int write_host (host) errno = 0; fprintf (db_file, "\n fixed-address "); - if (errno) { + if (errno) ++errors; - } for (i = 0; i < ip_addrs.len - 3; i += 4) { + errno = 0; fprintf (db_file, "%u.%u.%u.%u%s", ip_addrs.data [i] & 0xff, @@ -362,24 +371,22 @@ int write_host (host) ip_addrs.data [i + 2] & 0xff, ip_addrs.data [i + 3] & 0xff, i + 7 < ip_addrs.len ? "," : ""); - if (errno) { + if (errno) ++errors; - } } + errno = 0; fputc (';', db_file); - if (errno) { + if (errno) ++errors; - } } if (host -> named_group) { errno = 0; fprintf (db_file, "\n group \"%s\";", host -> named_group -> name); - if (errno) { + if (errno) ++errors; - } } if (host -> group && @@ -389,22 +396,22 @@ int write_host (host) errno = 0; write_statements (db_file, host -> group -> statements, 8); - if (errno) { + if (errno) ++errors; - } } } errno = 0; fputs ("\n}\n", db_file); - if (errno) { + if (errno) ++errors; - } + if (errors) { log_info ("write_host: unable to write host %s", host -> name); lease_file_is_corrupt = 1; } + return !errors; } @@ -425,12 +432,11 @@ int write_group (group) if (counting) ++count; - errno = 0; + errno = 0; fprintf (db_file, "group %s {", group -> name); - if (errno) { + if (errno) ++errors; - } if (group -> flags & GROUP_OBJECT_DYNAMIC) { errno = 0; @@ -456,22 +462,22 @@ int write_group (group) errno = 0; write_statements (db_file, group -> group -> statements, 8); - if (errno) { + if (errno) ++errors; - } } } errno = 0; fputs ("\n}\n", db_file); - if (errno) { + if (errno) ++errors; - } + if (errors) { log_info ("write_group: unable to write group %s", group -> name); lease_file_is_corrupt = 1; } + return !errors; } @@ -514,6 +520,8 @@ int write_failover_state (dhcp_failover_state_t *state) if (errno) ++errors; } + + errno = 0; fprintf (db_file, "\n}\n"); if (errno) ++errors; @@ -524,13 +532,14 @@ int write_failover_state (dhcp_failover_state_t *state) lease_file_is_corrupt = 1; return 0; } + return 1; } #endif int db_printable (s) - const char *s; + const unsigned char *s; { int i; for (i = 0; s [i]; i++) @@ -624,7 +633,12 @@ write_named_billing_class(const void *key, unsigned len, void *object) if (class->expr != 0) { if (fprintf(db_file, " match if ") <= 0) return ISC_R_IOERROR; + + errno = 0; write_expression(db_file, class->expr, 5, 5, 0); + if (errno) + return ISC_R_IOERROR; + if (fprintf(db_file, ";\n") <= 0) return ISC_R_IOERROR; } @@ -638,20 +652,31 @@ write_named_billing_class(const void *key, unsigned len, void *object) return ISC_R_IOERROR; } + errno = 0; write_expression(db_file, class->submatch, 5, 5, 0); + if (errno) + return ISC_R_IOERROR; + if (fprintf(db_file, ";\n") <= 0) return ISC_R_IOERROR; } if (class->statements != 0) { + errno = 0; write_statements(db_file, class->statements, 8); + if (errno) + return ISC_R_IOERROR; } /* XXXJAB this isn't right, but classes read in off the leases file don't get the root group assigned to them (due to clone_group() call). */ - if (class->group != 0 && class->group->authoritative != 0) + if (class->group != 0 && class->group->authoritative != 0) { + errno = 0; write_statements(db_file, class->group->statements, 8); + if (errno) + return ISC_R_IOERROR; + } if (fprintf(db_file, "}\n\n") <= 0) return ISC_R_IOERROR; @@ -701,18 +726,20 @@ int write_billing_class (class) return !errno; } - errno = 0; - fprintf (db_file, "\n billing subclass \"%s\"", - class -> superclass -> name); - if (errno) + if (fprintf(db_file, "\n billing subclass \"%s\"", + class -> superclass -> name) < 0) ++errors; - print_hash_string(db_file, class); - fprintf(db_file, ";"); + if (!print_hash_string(db_file, class)) + ++errors; + + if (fprintf(db_file, ";") < 0) + ++errors; class -> dirty = !errors; if (errors) lease_file_is_corrupt = 1; + return !errors; } @@ -841,11 +868,12 @@ int new_lease_file () errno = 0; fprintf (db_file, "# The format of this file is documented in the %s", "dhcpd.leases(5) manual page.\n"); - if (errno != 0) + if (errno) goto fail; + fprintf (db_file, "# This lease file was written by isc-dhcp-%s\n\n", DHCP_VERSION); - if (errno != 0) + if (errno) goto fail; /* At this point we have a new lease file that, so far, could not diff --git a/server/dhcpd.c b/server/dhcpd.c index 6aa59f9f..9dd5e56e 100644 --- a/server/dhcpd.c +++ b/server/dhcpd.c @@ -34,7 +34,7 @@ #ifndef lint static char ocopyright[] = -"$Id: dhcpd.c,v 1.121.42.1 2007/01/11 16:36:52 dhankins Exp $ Copyright 2004-2007 Internet Systems Consortium."; +"$Id: dhcpd.c,v 1.121.42.1.10.1 2007/06/11 22:53:35 each Exp $ Copyright 2004-2007 Internet Systems Consortium."; #endif static char copyright[] = @@ -200,7 +200,7 @@ int main (argc, argv, envp) int fd; int i, status; struct servent *ent; - char *s; + unsigned char *s; int cftest = 0; int lftest = 0; #ifndef DEBUG diff --git a/server/failover.c b/server/failover.c index eee6630b..9d095c6b 100644 --- a/server/failover.c +++ b/server/failover.c @@ -34,7 +34,7 @@ #ifndef lint static char copyright[] = -"$Id: failover.c,v 1.63.56.8 2007/05/22 22:58:14 dhankins Exp $ Copyright (c) 2004-2007 Internet Systems Consortium. All rights reserved.\n"; +"$Id: failover.c,v 1.63.56.8.4.1 2007/06/11 22:53:35 each Exp $ Copyright (c) 2004-2007 Internet Systems Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -2291,6 +2291,8 @@ static int dhcp_failover_pool_dobalance(dhcp_failover_state_t *state) binding_state_t peer_lease_state; binding_state_t my_lease_state; struct lease **lq; + int (*log_func)(const char *, ...); + const char *result; if (state -> me.state != normal) return 0; @@ -2320,17 +2322,18 @@ static int dhcp_failover_pool_dobalance(dhcp_failover_state_t *state) lq = &p->backup; } - log_info ("pool %lx %s total %d free %d backup %d lts %d", - (unsigned long)p, - (p->shared_network ? - p->shared_network->name : ""), p->lease_count, - p->free_leases, p->backup_leases, lts); - total = p->backup_leases + p->free_leases; thresh = ((total * state->max_lease_misbalance) + 50) / 100; hold = ((total * state->max_lease_ownership) + 50) / 100; + log_info("balancing pool %lx %s total %d free %d " + "backup %d lts %d max-own (+/-)%d", + (unsigned long)p, + (p->shared_network ? + p->shared_network->name : ""), p->lease_count, + p->free_leases, p->backup_leases, lts, hold); + /* If lts is in the negatives (we need leases) more than * negative double the thresh%, panic and send poolreq to * hopefully wake up the peer. @@ -2355,10 +2358,12 @@ static int dhcp_failover_pool_dobalance(dhcp_failover_state_t *state) pass = 0; lease_reference(&lp, *lq, MDL); - /* hold may be zero (consider the case where there are 2 - * leases, both on one server), therefore use >=. + /* In the case where there are 2 leases, hold is zero, and + * lts is 1 if both leases are on the local server. If + * there is only 1 lease, both lts and hold are zero. Let's + * not play ping pong. */ - while (lp && (lts >= (pass ? hold : -hold))) { + while (lp && (lts > (pass ? hold : -hold))) { if (next) lease_dereference(&next, MDL); if (lp->next) @@ -2391,8 +2396,19 @@ static int dhcp_failover_pool_dobalance(dhcp_failover_state_t *state) if (lp) lease_dereference(&lp, MDL); - if (lts > thresh) - log_error("lease imbalance persists - lts = %d", lts); + if (lts > thresh) { + result = "IMBALANCED"; + log_func = log_error; + } else { + result = "balanced"; + log_func = log_info; + } + + log_func("%s pool %lx %s total %d free %d backup %d " + "lts %d max-misbal %d", result, (unsigned long)p, + (p->shared_network ? + p->shared_network->name : ""), p->lease_count, + p->free_leases, p->backup_leases, lts, thresh); /* Recalculate next rebalance event timer. */ dhcp_failover_pool_check(p); @@ -2471,6 +2487,9 @@ dhcp_failover_pool_check(struct pool *pool) if(peer->last_balance && (est1 < est2)) est1 = est2; + /* Introduce a random delay. */ + est1 += random() % 5; + /* Do not move the time forward, or reset to the same time. */ if(peer->sched_balance) { if (est1 >= peer->sched_balance) @@ -2519,6 +2538,12 @@ isc_result_t dhcp_failover_send_updates (dhcp_failover_state_t *state) if (!state -> link_to_peer) return ISC_R_SUCCESS; + /* If there are acks pending, transmit them prior to potentialy + * sending new updates for the same lease. + */ + if (state->toack_queue_head != NULL) + dhcp_failover_send_acks(state); + while ((state -> partner.max_flying_updates > state -> cur_unacked_updates) && state -> update_queue_head) { /* Grab the head of the update queue. */ @@ -5126,7 +5151,7 @@ isc_result_t dhcp_failover_process_bind_ack (dhcp_failover_state_t *state, dhcp_failover_send_update_done (state); } - /* Now that the least is off the ack queue, consider putting it + /* Now that the lease is off the ack queue, consider putting it * back on the update queue for mac address affinity. */ if (send_to_backup && secondary_not_hoarding(state, lease->pool)) { diff --git a/server/mdb.c b/server/mdb.c index d2f76a45..fd3ac8ad 100644 --- a/server/mdb.c +++ b/server/mdb.c @@ -34,7 +34,7 @@ #ifndef lint static char copyright[] = -"$Id: mdb.c,v 1.83.16.6 2007/05/23 23:30:33 each Exp $ Copyright (c) 2004-2006 Internet Systems Consortium. All rights reserved.\n"; +"$Id: mdb.c,v 1.83.16.6.4.1 2007/06/11 22:53:35 each Exp $ Copyright (c) 2004-2006 Internet Systems Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -872,8 +872,6 @@ int supersede_lease (comp, lease, commit, propogate, pimmediate) int propogate; int pimmediate; { - int enter_uid = 0; - int enter_hwaddr = 0; struct lease *lp, **lq, *prev; TIME lp_next_state; #if defined (FAILOVER_PROTOCOL) @@ -921,28 +919,21 @@ int supersede_lease (comp, lease, commit, propogate, pimmediate) /* If there's a Unique ID, dissociate it from the hash table and free it if necessary. */ - if (comp -> uid) { - uid_hash_delete (comp); - enter_uid = 1; - if (comp -> uid != &comp -> uid_buf [0]) { - dfree (comp -> uid, MDL); - comp -> uid_max = 0; - comp -> uid_len = 0; + if (comp->uid) { + uid_hash_delete(comp); + if (comp->uid != comp->uid_buf) { + dfree(comp->uid, MDL); + comp->uid_max = 0; + comp->uid_len = 0; } comp -> uid = (unsigned char *)0; - } else - enter_uid = 1; - - if (comp -> hardware_addr.hlen && - ((comp -> hardware_addr.hlen != - lease -> hardware_addr.hlen) || - memcmp (comp -> hardware_addr.hbuf, - lease -> hardware_addr.hbuf, - comp -> hardware_addr.hlen))) { - hw_hash_delete (comp); - enter_hwaddr = 1; - } else if (!comp -> hardware_addr.hlen) - enter_hwaddr = 1; + } + + /* If there's a hardware address, remove the lease from its + * old position in the hash bucket's ordered list. + */ + if (comp->hardware_addr.hlen) + hw_hash_delete(comp); /* If the lease has been billed to a class, remove the billing. */ if (comp -> billing_class != lease -> billing_class) { @@ -1032,14 +1023,12 @@ int supersede_lease (comp, lease, commit, propogate, pimmediate) } /* Record the lease in the uid hash if necessary. */ - if (enter_uid && comp -> uid) { - uid_hash_add (comp); - } + if (comp->uid) + uid_hash_add(comp); /* Record it in the hardware address hash if necessary. */ - if (enter_hwaddr && lease -> hardware_addr.hlen) { - hw_hash_add (comp); - } + if (comp->hardware_addr.hlen) + hw_hash_add(comp); comp->cltt = lease->cltt; #if defined (FAILOVER_PROTOCOL) |