Version 2.8

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2008-06-21 00:00:00 +02:00
parent 625cde6b9c
commit 40edcd2aba
16 changed files with 303 additions and 76 deletions

View file

@ -1,3 +1,10 @@
2008-06-21 Sami Kerola <kerolasa@iki.fi>
* dhcpd-pools.c: Default will skip merge sorting.
* getdata.c: Interpretation of range wrote without spaces fixed.
* getdata.c: Shared network name ending to brace fixed.
* Failover backup IP counting.
* CSV output bug fixed.
2008-05-18 Sami Kerola <kerolasa@iki.fi> 2008-05-18 Sami Kerola <kerolasa@iki.fi>
* Some automake files to help make install pass without complains. * Some automake files to help make install pass without complains.
* Function names to error messages where they where missing. * Function names to error messages where they where missing.

7
NEWS
View file

@ -5,6 +5,13 @@ See the end for copying conditions.
Please send dhcpd-pools bug reports to kerolasa@iki.fi. Please send dhcpd-pools bug reports to kerolasa@iki.fi.
Version 2.8
* dhcpd-pools.c: Default will skip merge sorting.
* getdata.c: Interpretation of range wrote without spaces fixed.
* getdata.c: Shared network name ending to brace fixed.
* Failover backup IP counting.
* CSV output bug fixed.
Version 2.7 Version 2.7
* Some automake files to help make install pass without complains. * Some automake files to help make install pass without complains.

11
THANKS
View file

@ -1,12 +1,13 @@
dhcpd-pools THANKS file dhcpd-pools THANKS file
dhcpd-pools has originally been written by Sami Kerola. Many Project is originated by Sami Kerola.
people have further contributed to dhcpd-pools by reporting
problems, suggesting various improvements, or submitting actual Many have reported problems, give improvement suggestions and
code. Here is a list of these people. Help me keep it complete have some even contributed code. Here is a list of these people.
and exempt of errors.
Otto J. Mäkelä Otto J. Mäkelä
Mika Paananen Mika Paananen
Frank Bulk Frank Bulk
Roar Pettersen Roar Pettersen
Jeff Wieland
Rusty

View file

@ -1,6 +1,6 @@
@%:@! /bin/sh @%:@! /bin/sh
@%:@ Guess values for system-dependent variables and create Makefiles. @%:@ Guess values for system-dependent variables and create Makefiles.
@%:@ Generated by GNU Autoconf 2.59 for dhcpd-pools 2.7. @%:@ Generated by GNU Autoconf 2.59 for dhcpd-pools 2.8.
@%:@ @%:@
@%:@ Report bugs to <kerolasa@iki.fi>. @%:@ Report bugs to <kerolasa@iki.fi>.
@%:@ @%:@
@ -269,8 +269,8 @@ SHELL=${CONFIG_SHELL-/bin/sh}
# Identity of this package. # Identity of this package.
PACKAGE_NAME='dhcpd-pools' PACKAGE_NAME='dhcpd-pools'
PACKAGE_TARNAME='dhcpd-pools' PACKAGE_TARNAME='dhcpd-pools'
PACKAGE_VERSION='2.7' PACKAGE_VERSION='2.8'
PACKAGE_STRING='dhcpd-pools 2.7' PACKAGE_STRING='dhcpd-pools 2.8'
PACKAGE_BUGREPORT='kerolasa@iki.fi' PACKAGE_BUGREPORT='kerolasa@iki.fi'
# Factoring default headers for most tests. # Factoring default headers for most tests.
@ -779,7 +779,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing. # Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh. # This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF cat <<_ACEOF
\`configure' configures dhcpd-pools 2.7 to adapt to many kinds of systems. \`configure' configures dhcpd-pools 2.8 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]... Usage: $0 [OPTION]... [VAR=VALUE]...
@ -841,7 +841,7 @@ fi
if test -n "$ac_init_help"; then if test -n "$ac_init_help"; then
case $ac_init_help in case $ac_init_help in
short | recursive ) echo "Configuration of dhcpd-pools 2.7:";; short | recursive ) echo "Configuration of dhcpd-pools 2.8:";;
esac esac
cat <<\_ACEOF cat <<\_ACEOF
@ -967,7 +967,7 @@ fi
test -n "$ac_init_help" && exit 0 test -n "$ac_init_help" && exit 0
if $ac_init_version; then if $ac_init_version; then
cat <<\_ACEOF cat <<\_ACEOF
dhcpd-pools configure 2.7 dhcpd-pools configure 2.8
generated by GNU Autoconf 2.59 generated by GNU Autoconf 2.59
Copyright (C) 2003 Free Software Foundation, Inc. Copyright (C) 2003 Free Software Foundation, Inc.
@ -981,7 +981,7 @@ cat >&5 <<_ACEOF
This file contains any messages produced by compilers while This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake. running configure, to aid debugging if configure makes a mistake.
It was created by dhcpd-pools $as_me 2.7, which was It was created by dhcpd-pools $as_me 2.8, which was
generated by GNU Autoconf 2.59. Invocation command line was generated by GNU Autoconf 2.59. Invocation command line was
$ $0 $@ $ $0 $@
@ -1574,7 +1574,7 @@ fi
# Define the identity of the package. # Define the identity of the package.
PACKAGE=dhcpd-pools PACKAGE=dhcpd-pools
VERSION=2.7 VERSION=2.8
cat >>confdefs.h <<_ACEOF cat >>confdefs.h <<_ACEOF
@ -4712,7 +4712,7 @@ _ASBOX
} >&5 } >&5
cat >&5 <<_CSEOF cat >&5 <<_CSEOF
This file was extended by dhcpd-pools $as_me 2.7, which was This file was extended by dhcpd-pools $as_me 2.8, which was
generated by GNU Autoconf 2.59. Invocation command line was generated by GNU Autoconf 2.59. Invocation command line was
CONFIG_FILES = $CONFIG_FILES CONFIG_FILES = $CONFIG_FILES
@ -4775,7 +4775,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF cat >>$CONFIG_STATUS <<_ACEOF
ac_cs_version="\\ ac_cs_version="\\
dhcpd-pools config.status 2.7 dhcpd-pools config.status 2.8
configured by $0, generated by GNU Autoconf 2.59, configured by $0, generated by GNU Autoconf 2.59,
with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\" with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\"

View file

@ -1,5 +1,5 @@
m4trace:aclocal.m4:50: -1- m4_pattern_allow([^AM_[A-Z]+FLAGS$]) m4trace:aclocal.m4:50: -1- m4_pattern_allow([^AM_[A-Z]+FLAGS$])
m4trace:configure.in:5: -1- AC_INIT([dhcpd-pools], [2.7], [kerolasa@iki.fi]) m4trace:configure.in:5: -1- AC_INIT([dhcpd-pools], [2.8], [kerolasa@iki.fi])
m4trace:configure.in:5: -1- m4_pattern_forbid([^_?A[CHUM]_]) m4trace:configure.in:5: -1- m4_pattern_forbid([^_?A[CHUM]_])
m4trace:configure.in:5: -1- m4_pattern_forbid([_AC_]) m4trace:configure.in:5: -1- m4_pattern_forbid([_AC_])
m4trace:configure.in:5: -1- m4_pattern_forbid([^LIBOBJS$], [do not use LIBOBJS directly, use AC_LIBOBJ (see section `AC_LIBOBJ vs LIBOBJS']) m4trace:configure.in:5: -1- m4_pattern_forbid([^LIBOBJS$], [do not use LIBOBJS directly, use AC_LIBOBJ (see section `AC_LIBOBJ vs LIBOBJS'])

4
bind.state.backup Normal file
View file

@ -0,0 +1,4 @@
No, 'backup' means that the secondary server in a failover pair can
allocate this address. The lease states should *always* be the same on both
servers

20
configure vendored
View file

@ -1,6 +1,6 @@
#! /bin/sh #! /bin/sh
# Guess values for system-dependent variables and create Makefiles. # Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.59 for dhcpd-pools 2.7. # Generated by GNU Autoconf 2.59 for dhcpd-pools 2.8.
# #
# Report bugs to <kerolasa@iki.fi>. # Report bugs to <kerolasa@iki.fi>.
# #
@ -269,8 +269,8 @@ SHELL=${CONFIG_SHELL-/bin/sh}
# Identity of this package. # Identity of this package.
PACKAGE_NAME='dhcpd-pools' PACKAGE_NAME='dhcpd-pools'
PACKAGE_TARNAME='dhcpd-pools' PACKAGE_TARNAME='dhcpd-pools'
PACKAGE_VERSION='2.7' PACKAGE_VERSION='2.8'
PACKAGE_STRING='dhcpd-pools 2.7' PACKAGE_STRING='dhcpd-pools 2.8'
PACKAGE_BUGREPORT='kerolasa@iki.fi' PACKAGE_BUGREPORT='kerolasa@iki.fi'
# Factoring default headers for most tests. # Factoring default headers for most tests.
@ -779,7 +779,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing. # Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh. # This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF cat <<_ACEOF
\`configure' configures dhcpd-pools 2.7 to adapt to many kinds of systems. \`configure' configures dhcpd-pools 2.8 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]... Usage: $0 [OPTION]... [VAR=VALUE]...
@ -841,7 +841,7 @@ fi
if test -n "$ac_init_help"; then if test -n "$ac_init_help"; then
case $ac_init_help in case $ac_init_help in
short | recursive ) echo "Configuration of dhcpd-pools 2.7:";; short | recursive ) echo "Configuration of dhcpd-pools 2.8:";;
esac esac
cat <<\_ACEOF cat <<\_ACEOF
@ -967,7 +967,7 @@ fi
test -n "$ac_init_help" && exit 0 test -n "$ac_init_help" && exit 0
if $ac_init_version; then if $ac_init_version; then
cat <<\_ACEOF cat <<\_ACEOF
dhcpd-pools configure 2.7 dhcpd-pools configure 2.8
generated by GNU Autoconf 2.59 generated by GNU Autoconf 2.59
Copyright (C) 2003 Free Software Foundation, Inc. Copyright (C) 2003 Free Software Foundation, Inc.
@ -981,7 +981,7 @@ cat >&5 <<_ACEOF
This file contains any messages produced by compilers while This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake. running configure, to aid debugging if configure makes a mistake.
It was created by dhcpd-pools $as_me 2.7, which was It was created by dhcpd-pools $as_me 2.8, which was
generated by GNU Autoconf 2.59. Invocation command line was generated by GNU Autoconf 2.59. Invocation command line was
$ $0 $@ $ $0 $@
@ -1574,7 +1574,7 @@ fi
# Define the identity of the package. # Define the identity of the package.
PACKAGE=dhcpd-pools PACKAGE=dhcpd-pools
VERSION=2.7 VERSION=2.8
cat >>confdefs.h <<_ACEOF cat >>confdefs.h <<_ACEOF
@ -4712,7 +4712,7 @@ _ASBOX
} >&5 } >&5
cat >&5 <<_CSEOF cat >&5 <<_CSEOF
This file was extended by dhcpd-pools $as_me 2.7, which was This file was extended by dhcpd-pools $as_me 2.8, which was
generated by GNU Autoconf 2.59. Invocation command line was generated by GNU Autoconf 2.59. Invocation command line was
CONFIG_FILES = $CONFIG_FILES CONFIG_FILES = $CONFIG_FILES
@ -4775,7 +4775,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF cat >>$CONFIG_STATUS <<_ACEOF
ac_cs_version="\\ ac_cs_version="\\
dhcpd-pools config.status 2.7 dhcpd-pools config.status 2.8
configured by $0, generated by GNU Autoconf 2.59, configured by $0, generated by GNU Autoconf 2.59,
with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\" with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\"

View file

@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59) AC_PREREQ(2.59)
AC_INIT([dhcpd-pools], [2.7], [kerolasa@iki.fi]) AC_INIT([dhcpd-pools], [2.8], [kerolasa@iki.fi])
AM_INIT_AUTOMAKE([1.6 foreign]) AM_INIT_AUTOMAKE([1.6 foreign])

View file

@ -2,7 +2,7 @@
.\" http://www.iki.fi/kerolasa/ .\" http://www.iki.fi/kerolasa/
.\" kerolasa@iki.fi .\" kerolasa@iki.fi
.\" .\"
.TH DHCPD-POOLS 1 "May 18 2008 - version 2.7" .TH DHCPD-POOLS 1 "May 18 2008 - version 2.8"
.SH NAME .SH NAME
dhcpd-pools \- ISC dhcp pools usage analysis dhcpd-pools \- ISC dhcp pools usage analysis
.SH SYNOPSIS .SH SYNOPSIS
@ -40,6 +40,10 @@ Touched leases and currently in use together.
.TP .TP
.I "t+c perc" .I "t+c perc"
Percent of touched and currently in use together compared to max. Percent of touched and currently in use together compared to max.
.I "bu"
Failover pair can allocate these addresses. The count appears only if there is failover configuration.
.I "bu perc"
Percent of addresses that failover pair can allocate. The percent appears only if there is failover configuration.
.SH ARGUMENTS .SH ARGUMENTS
.TP .TP
.I "\-c, \-\-config" .I "\-c, \-\-config"

View file

@ -64,6 +64,12 @@ prepare_data (void)
/* Sort ranges */ /* Sort ranges */
qsort (ranges, (size_t) num_ranges, sizeof (struct range_t), &rangecomp); qsort (ranges, (size_t) num_ranges, sizeof (struct range_t), &rangecomp);
/* Sort backups */
if (num_backups > 0)
{
qsort (backups, (size_t) num_backups, sizeof (long int), &intcomp);
}
return 0; return 0;
} }
@ -72,9 +78,9 @@ int
do_counting (void) do_counting (void)
{ {
struct range_t *range_p; struct range_t *range_p;
unsigned int i, j, k, block_size; unsigned int i, j, k, m, block_size;
i = j = 0; i = j = m = 0;
range_p = ranges; range_p = ranges;
/* Walk through ranges */ /* Walk through ranges */
@ -112,6 +118,26 @@ do_counting (void)
} }
} }
/* Count backup IPs */
if (num_backups > 0)
{
for (;
range_p->last_ip > backups[m]
&& (unsigned long) m < num_touches; m++)
{
if (range_p->first_ip > touches[m])
{
continue;
}
/* IP with in range */
range_p->backups++;
if (range_p->shared_net)
{
range_p->shared_net->backups++;
}
}
}
/* Size of range, shared net & all networks */ /* Size of range, shared net & all networks */
block_size = (unsigned int) (range_p->last_ip - range_p->first_ip - 1); block_size = (unsigned int) (range_p->last_ip - range_p->first_ip - 1);
if (range_p->shared_net) if (range_p->shared_net)
@ -139,8 +165,11 @@ do_counting (void)
shared_networks->available += range_p->last_ip - range_p->first_ip - 1; shared_networks->available += range_p->last_ip - range_p->first_ip - 1;
shared_networks->used += range_p->count; shared_networks->used += range_p->count;
shared_networks->touched += range_p->touched; shared_networks->touched += range_p->touched;
shared_networks->backups += range_p->backups;
range_p++; range_p++;
} }
return 0; return 0;
} }

View file

@ -32,9 +32,6 @@
#ifndef OUTPUT_FORMAT #ifndef OUTPUT_FORMAT
# define OUTPUT_FORMAT "text" # define OUTPUT_FORMAT "text"
#endif #endif
#ifndef OUTPUT_ORDER
# define OUTPUT_ORDER 'i'
#endif
#ifndef OUTPUT_LIMIT #ifndef OUTPUT_LIMIT
# define OUTPUT_LIMIT "77" # define OUTPUT_LIMIT "77"
#endif #endif

View file

@ -43,7 +43,7 @@ extern char *malloc ();
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
int c, i, sorts = 1; int c, i, sorts = 0;
int option_index = 0; int option_index = 0;
char *tmp; char *tmp;
struct range_t *tmp_ranges; struct range_t *tmp_ranges;
@ -86,7 +86,6 @@ main (int argc, char **argv)
strncpy (config.output_format, OUTPUT_FORMAT, (size_t) 1); strncpy (config.output_format, OUTPUT_FORMAT, (size_t) 1);
/* Default sort order is by IPs small to big */ /* Default sort order is by IPs small to big */
config.sort[0] = OUTPUT_ORDER;
config.reverse_order = false; config.reverse_order = false;
/* Parse command line options */ /* Parse command line options */
@ -260,9 +259,13 @@ main (int argc, char **argv)
prepare_data (); prepare_data ();
do_counting (); do_counting ();
tmp_ranges = safe_malloc (sizeof (struct range_t) * num_ranges); tmp_ranges = safe_malloc (sizeof (struct range_t) * num_ranges);
if (sorts != 0)
{
mergesort_ranges (ranges, num_ranges, tmp_ranges); mergesort_ranges (ranges, num_ranges, tmp_ranges);
if (config.reverse_order == true) { }
flip_ranges(ranges, tmp_ranges); if (config.reverse_order == true)
{
flip_ranges (ranges, tmp_ranges);
} }
free (tmp_ranges); free (tmp_ranges);
output_analysis (); output_analysis ();

View file

@ -47,6 +47,7 @@ struct shared_network_t
unsigned long int available; unsigned long int available;
unsigned long int used; unsigned long int used;
unsigned long int touched; unsigned long int touched;
unsigned long int backups;
}; };
struct range_t struct range_t
{ {
@ -55,6 +56,7 @@ struct range_t
unsigned long int last_ip; unsigned long int last_ip;
unsigned long int count; unsigned long int count;
unsigned long int touched; unsigned long int touched;
unsigned long int backups;
}; };
/* Global variables */ /* Global variables */
static int true = 1; static int true = 1;
@ -80,6 +82,9 @@ unsigned long int num_leases;
unsigned long int *touches; unsigned long int *touches;
unsigned long int num_touches; unsigned long int num_touches;
unsigned long int *backups;
unsigned long int num_backups;
/* Function prototypes */ /* Function prototypes */
int prepare_memory (void); int prepare_memory (void);
int parse_leases (void); int parse_leases (void);

View file

@ -59,7 +59,7 @@ parse_leases (void)
struct in_addr inp; struct in_addr inp;
struct stat lease_file_stats; struct stat lease_file_stats;
num_touches = num_leases = 0; num_touches = num_leases = num_backups = 0;
dhcpd_leases = fopen (config.dhcpdlease_file, "r"); dhcpd_leases = fopen (config.dhcpdlease_file, "r");
if (dhcpd_leases == NULL) if (dhcpd_leases == NULL)
@ -69,10 +69,9 @@ parse_leases (void)
} }
/* I found out that there's one lease address per 300 bytes in /* I found out that there's one lease address per 300 bytes in
* dhcpd.leases file. Malloc is little bit pessimistic, but I * dhcpd.leases file. Malloc is little bit pessimistic and uses
* think that this way program crashes slightly less frequetly. * 250. If someone has higher density in lease file I'm
* If someone has higher density in lease file I'm interested * interested to hear about that. */
* to hear about that. */
if (stat (config.dhcpdlease_file, &lease_file_stats)) if (stat (config.dhcpdlease_file, &lease_file_stats))
{ {
eprintf ("parse_leases: %s:", config.dhcpdlease_file); eprintf ("parse_leases: %s:", config.dhcpdlease_file);
@ -97,20 +96,33 @@ parse_leases (void)
strncpy (ipstring, line, (size_t) MAXLEN - 1); strncpy (ipstring, line, (size_t) MAXLEN - 1);
} }
/* And this is lease state which we are interested about */ /* And this is lease state which we are interested about */
if (strstr (line, "binding state active")) else if (strstr (line, "binding state active"))
{ {
nth_field (2, ipstring, ipstring); nth_field (2, ipstring, ipstring);
inet_aton (ipstring, &inp); inet_aton (ipstring, &inp);
leases[num_leases] = htonl (inp.s_addr); leases[num_leases] = htonl (inp.s_addr);
num_leases++; num_leases++;
} }
if (strstr (line, " binding state free")) else if (strstr (line, " binding state free"))
{ {
nth_field (2, ipstring, ipstring); nth_field (2, ipstring, ipstring);
inet_aton (ipstring, &inp); inet_aton (ipstring, &inp);
touches[num_touches] = htonl (inp.s_addr); touches[num_touches] = htonl (inp.s_addr);
num_touches++; num_touches++;
} }
else if (strstr (line, " binding state backup"))
{
nth_field (2, ipstring, ipstring);
inet_aton (ipstring, &inp);
if (num_backups == 0)
{
backups =
safe_malloc ((size_t) sizeof (long int) *
((lease_file_stats.st_size / 250) + MAXLEN));
}
backups[num_backups] = htonl (inp.s_addr);
num_backups++;
}
} }
return 0; return 0;
@ -121,7 +133,6 @@ parse_leases (void)
* have. Question of semantics, send mail to author if this * have. Question of semantics, send mail to author if this
* annoys. All performance boosts for this function are well * annoys. All performance boosts for this function are well
* come. */ * come. */
int int
nth_field (int n, char *dest, const char *src) nth_field (int n, char *dest, const char *src)
{ {
@ -176,13 +187,15 @@ is_interesting_config_clause (char *s)
} }
} }
/* This function is far too long. */ /* TODO: This spagetti monster function need to be rewrote at
* least ones. */
int int
parse_config (char *config_file, char *current_shared_name, parse_config (char *config_file, char *current_shared_name,
char *next_free_shared_name, struct shared_network_t *shared_p) char *next_free_shared_name, struct shared_network_t *shared_p)
{ {
FILE *dhcpd_config; FILE *dhcpd_config;
int i = 0, newclause = 1, argument = 0, comment = 0, braces = 0, quote = 0; int i = 0, newclause = true, argument = false, comment = false, braces =
0, quote = false;
char word[MAXLEN], c; char word[MAXLEN], c;
int braces_shared = 1000; int braces_shared = 1000;
struct in_addr inp; struct in_addr inp;
@ -203,7 +216,7 @@ parse_config (char *config_file, char *current_shared_name,
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
/* Hairy stuff begins. */ /* Very hairy stuff begins. */
while (!feof (dhcpd_config)) while (!feof (dhcpd_config))
{ {
c = fgetc (dhcpd_config); c = fgetc (dhcpd_config);
@ -243,6 +256,16 @@ parse_config (char *config_file, char *current_shared_name,
newclause = true; newclause = true;
i = 0; i = 0;
} }
else if (argument == 2)
{
/* Range ends to ; and this hair in code make two
* ranges wrote to gether like...
*
* range 10.20.30.40 10.20.30.41;range 10.20.30.42 10.20.30.43;
*
* ...to be interpreted correctly. */
c = ' ';
}
continue; continue;
case '{': case '{':
if (quote == true) if (quote == true)
@ -252,6 +275,12 @@ parse_config (char *config_file, char *current_shared_name,
if (comment == false) if (comment == false)
{ {
braces++; braces++;
}
/* i == 0 detects word that ends to brace like:
*
* shared-network DSL{ ... */
if (i == 0)
{
newclause = true; newclause = true;
} }
continue; continue;
@ -285,7 +314,7 @@ parse_config (char *config_file, char *current_shared_name,
continue; continue;
} }
/* Strip white spaces before new clause word. */ /* Strip white spaces before new clause word. */
if ((newclause == true || argument != 0) && isspace (c) && i == false) if ((newclause == true || argument != 0) && isspace (c) && i == 0)
{ {
continue; continue;
} }
@ -337,6 +366,7 @@ parse_config (char *config_file, char *current_shared_name,
shared_p->available = 0; shared_p->available = 0;
shared_p->used = 0; shared_p->used = 0;
shared_p->touched = 0; shared_p->touched = 0;
shared_p->backups = 0;
/* Temporary abuse of argument variable */ /* Temporary abuse of argument variable */
argument = strlen (next_free_shared_name) + 1; argument = strlen (next_free_shared_name) + 1;
if (last_shared_name > next_free_shared_name + argument) if (last_shared_name > next_free_shared_name + argument)
@ -359,6 +389,7 @@ parse_config (char *config_file, char *current_shared_name,
range_p->last_ip = htonl (inp.s_addr) + 1; range_p->last_ip = htonl (inp.s_addr) + 1;
range_p->count = 0; range_p->count = 0;
range_p->touched = 0; range_p->touched = 0;
range_p->backups = 0;
range_p->shared_net = shared_p; range_p->shared_net = shared_p;
num_ranges++; num_ranges++;
if (num_ranges > RANGES) if (num_ranges > RANGES)

View file

@ -72,11 +72,13 @@ eprintf (char *fmt, ...)
fprintf (stderr, "\n"); fprintf (stderr, "\n");
} }
void flip_ranges(struct range_t *ranges, struct range_t *tmp_ranges) void
flip_ranges (struct range_t *ranges, struct range_t *tmp_ranges)
{ {
int i = num_ranges - 1, j; int i = num_ranges - 1, j;
for (j = 0; j < num_ranges; j++) { for (j = 0; j < num_ranges; j++)
{
*(tmp_ranges + j) = *(ranges + i); *(tmp_ranges + j) = *(ranges + i);
i--; i--;
} }
@ -114,7 +116,7 @@ clean_up (void)
void void
print_version (void) print_version (void)
{ {
fprintf (stdout, "%s version 2.7\n", program_name); fprintf (stdout, "%s version 2.8\n", program_name);
fprintf (stdout, fprintf (stdout,
"Program may be copied only under the terms of GNU General Public\n"); "Program may be copied only under the terms of GNU General Public\n");
fprintf (stdout, fprintf (stdout,

View file

@ -59,7 +59,12 @@ output_txt (void)
fprintf (outfile, "Ranges:\n"); fprintf (outfile, "Ranges:\n");
fprintf fprintf
(outfile, (outfile,
"shared net name first ip last ip max cur percent touch t+c t+c perc\n"); "shared net name first ip last ip max cur percent touch t+c t+c perc");
if (num_backups > 0)
{
fprintf (outfile, " bu bu perc");
}
fprintf (outfile, "\n");
} }
if (config.output_limit[1] & output_limit_bit_1) if (config.output_limit[1] & output_limit_bit_1)
{ {
@ -77,7 +82,7 @@ output_txt (void)
fprintf (outfile, "not_defined "); fprintf (outfile, "not_defined ");
} }
fprintf (outfile, "%-16s", inet_ntoa (first)); fprintf (outfile, "%-16s", inet_ntoa (first));
fprintf (outfile, " - %-16s %5lu %5lu %10.3f %5lu %5lu %9.3f\n", fprintf (outfile, " - %-16s %5lu %5lu %10.3f %5lu %5lu %9.3f",
inet_ntoa (last), inet_ntoa (last),
range_p->last_ip - range_p->first_ip - 1, range_p->last_ip - range_p->first_ip - 1,
range_p->count, range_p->count,
@ -87,6 +92,14 @@ output_txt (void)
range_p->touched + range_p->count, range_p->touched + range_p->count,
(float) (100 * (range_p->touched + range_p->count)) / (float) (100 * (range_p->touched + range_p->count)) /
(range_p->last_ip - range_p->first_ip - 1)); (range_p->last_ip - range_p->first_ip - 1));
if (num_backups > 0)
{
fprintf (outfile, "%7lu %8.3f", range_p->backups,
(float) (100 * range_p->backups) / (range_p->last_ip -
range_p->first_ip -
1));
}
fprintf (outfile, "\n");
range_p++; range_p++;
} }
} }
@ -99,14 +112,19 @@ output_txt (void)
{ {
fprintf (outfile, "Shared networks:\n"); fprintf (outfile, "Shared networks:\n");
fprintf (outfile, fprintf (outfile,
"name max cur percent touch t+c t+c perc\n"); "name max cur percent touch t+c t+c perc");
if (num_backups > 0)
{
fprintf (outfile, " bu bu perc");
}
fprintf (outfile, "\n");
} }
if (config.output_limit[1] & output_limit_bit_2) if (config.output_limit[1] & output_limit_bit_2)
{ {
for (i = 0; i < num_shared_networks; i++) for (i = 0; i < num_shared_networks; i++)
{ {
shared_p++; shared_p++;
fprintf (outfile, "%-20s %5lu %5lu %10.3f %7lu %6lu %9.3f\n", fprintf (outfile, "%-20s %5lu %5lu %10.3f %7lu %6lu %9.3f",
shared_p->name, shared_p->name,
shared_p->available, shared_p->available,
shared_p->used, shared_p->used,
@ -115,6 +133,14 @@ output_txt (void)
shared_p->touched + shared_p->used, shared_p->touched + shared_p->used,
(float) (100 * (shared_p->touched + shared_p->used)) / (float) (100 * (shared_p->touched + shared_p->used)) /
shared_p->available); shared_p->available);
if (num_backups > 0)
{
fprintf (outfile, "%7lu %8.3f", shared_p->backups,
(float) (100 * shared_p->backups) /
shared_p->available);
}
fprintf (outfile, "\n");
} }
} }
if (config.output_limit[1] & output_limit_bit_2 if (config.output_limit[1] & output_limit_bit_2
@ -126,11 +152,17 @@ output_txt (void)
{ {
fprintf (outfile, "Sum of all ranges:\n"); fprintf (outfile, "Sum of all ranges:\n");
fprintf (outfile, fprintf (outfile,
"name max cur percent touch t+c t+c perc\n"); "name max cur percent touch t+c t+c perc");
if (num_backups > 0)
{
fprintf (outfile, " bu bu perc");
}
fprintf (outfile, "\n");
} }
if (config.output_limit[1] & output_limit_bit_3) if (config.output_limit[1] & output_limit_bit_3)
{ {
fprintf (outfile, "%-20s %5lu %5lu %10.3f %7lu %6lu %9.3f\n", fprintf (outfile, "%-20s %5lu %5lu %10.3f %7lu %6lu %9.3f",
shared_networks->name, shared_networks->name,
shared_networks->available, shared_networks->available,
shared_networks->used, shared_networks->used,
@ -142,6 +174,14 @@ output_txt (void)
(shared_networks->touched + (shared_networks->touched +
shared_networks->used)) / shared_networks->used)) /
shared_networks->available); shared_networks->available);
if (num_backups > 0)
{
fprintf (outfile, "%7lu %8.3f", shared_networks->backups,
(float) (100 * shared_networks->backups) /
shared_networks->available);
}
fprintf (outfile, "\n");
} }
if (outfile == stdout) if (outfile == stdout)
{ {
@ -197,7 +237,14 @@ output_html (void)
fprintf (outfile, "<tr><th>Ranges:</th></tr>\n"); fprintf (outfile, "<tr><th>Ranges:</th></tr>\n");
fprintf fprintf
(outfile, (outfile,
"<tr><th>shared net name</th><th>first ip</th><th>last ip</th><th align=\"right\">max</th><th align=\"right\">cur</th><th align=\"right\">percent</th><th align=\"right\">touch</th><th align=\"right\">t+c</th><th align=\"right\">t+c perc</th></tr>\n"); "<tr><th>shared net name</th><th>first ip</th><th>last ip</th><th align=\"right\">max</th><th align=\"right\">cur</th><th align=\"right\">percent</th><th align=\"right\">touch</th><th align=\"right\">t+c</th><th align=\"right\">t+c perc</th>");
if (num_backups > 0)
{
fprintf (outfile,
"<th align=\"right\">bu</th><th align=\"right\">bu perc</th>");
}
fprintf (outfile, "</tr>\n");
} }
if (config.output_limit[1] & output_limit_bit_1) if (config.output_limit[1] & output_limit_bit_1)
{ {
@ -216,7 +263,7 @@ output_html (void)
} }
fprintf (outfile, "<td>%s</td>", inet_ntoa (first)); fprintf (outfile, "<td>%s</td>", inet_ntoa (first));
fprintf (outfile, fprintf (outfile,
"<td>%s</td><td align=\"right\">%lu</td><td align=\"right\">%lu</td><td align=\"right\">%.3f</td><td align=\"right\">%lu</td><td align=\"right\">%lu</td><td align=\"right\">%.3f</td></tr>\n", "<td>%s</td><td align=\"right\">%lu</td><td align=\"right\">%lu</td><td align=\"right\">%.3f</td><td align=\"right\">%lu</td><td align=\"right\">%lu</td><td align=\"right\">%.3f</td>",
inet_ntoa (last), range_p->last_ip - range_p->first_ip - 1, inet_ntoa (last), range_p->last_ip - range_p->first_ip - 1,
range_p->count, range_p->count,
(float) (100 * range_p->count) / (range_p->last_ip - (float) (100 * range_p->count) / (range_p->last_ip -
@ -225,6 +272,17 @@ output_html (void)
range_p->touched + range_p->count, range_p->touched + range_p->count,
(float) (100 * (range_p->touched + range_p->count)) / (float) (100 * (range_p->touched + range_p->count)) /
(range_p->last_ip - range_p->first_ip - 1)); (range_p->last_ip - range_p->first_ip - 1));
if (num_backups > 0)
{
fprintf (outfile,
"<td align=\"right\">%lu</td><td align=\"right\">%.3f</td>",
range_p->backups,
(float) (100 * range_p->backups) / (range_p->last_ip -
range_p->first_ip -
1));
}
fprintf (outfile, "</tr>\n");
range_p++; range_p++;
} }
} }
@ -232,7 +290,14 @@ output_html (void)
{ {
fprintf (outfile, "\n<tr><th>Shared networks:</th></tr>\n"); fprintf (outfile, "\n<tr><th>Shared networks:</th></tr>\n");
fprintf (outfile, fprintf (outfile,
"<tr><th>name</td><th align=\"right\">max</th><th align=\"right\">cur</th><th align=\"right\">percent</th><th align=\"right\">touch</th><th align=\"right\">t+c</th><th align=\"right\">t+c perc</th></tr>\n"); "<tr><th>name</td><th align=\"right\">max</th><th align=\"right\">cur</th><th align=\"right\">percent</th><th align=\"right\">touch</th><th align=\"right\">t+c</th><th align=\"right\">t+c perc</th>");
if (num_backups > 0)
{
fprintf (outfile,
"<th align=\"right\">bu</th><th align=\"right\">bu perc</th>");
}
fprintf (outfile, "</tr>\n");
} }
if (config.output_limit[1] & output_limit_bit_2) if (config.output_limit[1] & output_limit_bit_2)
{ {
@ -240,25 +305,42 @@ output_html (void)
{ {
shared_p++; shared_p++;
fprintf (outfile, fprintf (outfile,
"<tr><td>%s</td><td align=\"right\">%lu</td><td align=\"right\">%lu</td><td align=\"right\">%.3f</td><td align=\"right\">%lu</td><td align=\"right\">%lu</td><td align=\"right\">%.3f</td></tr>\n", "<tr><td>%s</td><td align=\"right\">%lu</td><td align=\"right\">%lu</td><td align=\"right\">%.3f</td><td align=\"right\">%lu</td><td align=\"right\">%lu</td><td align=\"right\">%.3f</td>",
shared_p->name, shared_p->available, shared_p->used, shared_p->name, shared_p->available, shared_p->used,
(float) (100 * shared_p->used) / shared_p->available, (float) (100 * shared_p->used) / shared_p->available,
shared_p->touched, shared_p->touched,
shared_p->touched + shared_p->used, shared_p->touched + shared_p->used,
(float) (100 * (shared_p->touched + shared_p->used)) / (float) (100 * (shared_p->touched + shared_p->used)) /
shared_p->available); shared_p->available);
if (num_backups > 0)
{
fprintf (outfile,
"<td align=\"right\">%lu</td><td align=\"right\">%.3f</td>",
shared_p->backups,
(float) (100 * shared_p->backups) /
shared_p->available);
}
fprintf (outfile, "</tr>\n");
} }
} }
if (config.output_limit[0] & output_limit_bit_3) if (config.output_limit[0] & output_limit_bit_3)
{ {
fprintf (outfile, "\n<tr><th>Sum of all ranges:</th></tr>\n"); fprintf (outfile, "\n<tr><th>Sum of all ranges:</th></tr>\n");
fprintf (outfile, fprintf (outfile,
"<tr><th>name</th><th align=\"right\">max</th><th align=\"right\">cur</th><th align=\"right\">percent</th><th align=\"right\">touch</th><th align=\"right\">t+c</th><th align=\"right\">t+c perc</th></tr>\n"); "<tr><th>name</th><th align=\"right\">max</th><th align=\"right\">cur</th><th align=\"right\">percent</th><th align=\"right\">touch</th><th align=\"right\">t+c</th><th align=\"right\">t+c perc</th>");
if (num_backups > 0)
{
fprintf (outfile,
"<th align=\"right\">bu</th><th align=\"right\">bu perc</th>");
}
fprintf (outfile, "</tr>\n");
} }
if (config.output_limit[1] & output_limit_bit_3) if (config.output_limit[1] & output_limit_bit_3)
{ {
fprintf (outfile, fprintf (outfile,
"<tr><td>%s</td><td align=\"right\">%lu</td><td align=\"right\">%lu</td><td align=\"right\">%.3f</td><td align=\"right\">%lu</td><td align=\"right\">%lu</td><td align=\"right\">%.3f</td>\n", "<tr><td>%s</td><td align=\"right\">%lu</td><td align=\"right\">%lu</td><td align=\"right\">%.3f</td><td align=\"right\">%lu</td><td align=\"right\">%lu</td><td align=\"right\">%.3f</td>",
shared_networks->name, shared_networks->available, shared_networks->name, shared_networks->available,
shared_networks->used, shared_networks->used,
(float) (100 * shared_networks->used) / (float) (100 * shared_networks->used) /
@ -269,6 +351,16 @@ output_html (void)
(shared_networks->touched + (shared_networks->touched +
shared_networks->used)) / shared_networks->used)) /
shared_networks->available); shared_networks->available);
if (num_backups > 0)
{
fprintf (outfile,
"<td align=\"right\">%lu</td><td align=\"right\">%.3f</td>",
shared_networks->backups,
(float) (100 * shared_networks->backups) /
shared_networks->available);
}
fprintf (outfile, "\n");
fprintf (outfile, "</tr>\n");
} }
fprintf (outfile, "</table>\n"); fprintf (outfile, "</table>\n");
if (outfile == stdout) if (outfile == stdout)
@ -323,7 +415,13 @@ output_csv (void)
fprintf (outfile, "\"Ranges:\"\n"); fprintf (outfile, "\"Ranges:\"\n");
fprintf fprintf
(outfile, (outfile,
"\"shared net name\",\"first ip\",\"last ip\",\"max\",\"cur\",\"percent\",\"touch\",\"t+c\",\"t+c perc\"\n"); "\"shared net name\",\"first ip\",\"last ip\",\"max\",\"cur\",\"percent\",\"touch\",\"t+c\",\"t+c perc\"");
if (num_backups > 0)
{
fprintf (outfile, ",\"bu\",\"bu perc\"");
}
fprintf (outfile, "\n");
} }
if (config.output_limit[1] & output_limit_bit_1) if (config.output_limit[1] & output_limit_bit_1)
{ {
@ -342,7 +440,7 @@ output_csv (void)
} }
fprintf (outfile, "\"%s\",", inet_ntoa (first)); fprintf (outfile, "\"%s\",", inet_ntoa (first));
fprintf (outfile, fprintf (outfile,
"\"%s\",\"%lu\",\"%lu\",\"%.3f\",\"%lu\",\"%lu\",\"%.3f\"\n", "\"%s\",\"%lu\",\"%lu\",\"%.3f\",\"%lu\",\"%lu\",\"%.3f\"",
inet_ntoa (last), range_p->last_ip - range_p->first_ip - 1, inet_ntoa (last), range_p->last_ip - range_p->first_ip - 1,
range_p->count, range_p->count,
(float) (100 * range_p->count) / (range_p->last_ip - (float) (100 * range_p->count) / (range_p->last_ip -
@ -350,6 +448,16 @@ output_csv (void)
range_p->touched, range_p->touched + range_p->count, range_p->touched, range_p->touched + range_p->count,
(float) (100 * (range_p->touched + range_p->count)) / (float) (100 * (range_p->touched + range_p->count)) /
(range_p->last_ip - range_p->first_ip - 1)); (range_p->last_ip - range_p->first_ip - 1));
if (num_backups > 0)
{
fprintf (outfile, ",\"%lu\",\"%.3f\"", range_p->backups,
(float) (100 * range_p->backups) / (range_p->last_ip -
range_p->first_ip -
1));
}
fprintf (outfile, "\n");
range_p++; range_p++;
} }
fprintf (outfile, "\n"); fprintf (outfile, "\n");
@ -358,7 +466,12 @@ output_csv (void)
{ {
fprintf (outfile, "\"Shared networks:\"\n"); fprintf (outfile, "\"Shared networks:\"\n");
fprintf (outfile, fprintf (outfile,
"\"name\",\"max\",\"cur\",\"percent\",\"touch\",\"t+c\",\"t+c perc\"\n"); "\"name\",\"max\",\"cur\",\"percent\",\"touch\",\"t+c\",\"t+c perc\"");
if (num_backups > 0)
{
fprintf (outfile, ",\"bu\",\"bu perc\"");
}
fprintf (outfile, "\n");
} }
if (config.output_limit[1] & output_limit_bit_2) if (config.output_limit[1] & output_limit_bit_2)
{ {
@ -367,12 +480,23 @@ output_csv (void)
{ {
shared_p++; shared_p++;
fprintf (outfile, fprintf (outfile,
"\"%s\",\"%lu\",\"%lu\",\"%.3f\",\"%lu\",\"%lu\",\"%.3f\"\n", "\"%s\",\"%lu\",\"%lu\",\"%.3f\",\"%lu\",\"%lu\",\"%.3f\"",
shared_p->name, shared_p->available, shared_p->used, shared_p->name, shared_p->available, shared_p->used,
(float) (100 * shared_p->used) / shared_p->available, (float) (100 * shared_p->used) / shared_p->available,
shared_p->touched,
shared_p->touched + shared_p->used, shared_p->touched + shared_p->used,
(float) (100 * (shared_p->touched + shared_p->used)) / (float) (100 * (shared_p->touched + shared_p->used)) /
shared_p->available); shared_p->available);
if (num_backups > 0)
{
fprintf (outfile, ",\"%lu\",\"%.3f\"", shared_p->backups,
(float) (100 * shared_p->backups) /
shared_p->available);
}
fprintf (outfile, "\n");
} }
fprintf (outfile, "\n"); fprintf (outfile, "\n");
} }
@ -380,13 +504,18 @@ output_csv (void)
{ {
fprintf (outfile, "\"Sum of all ranges:\"\n"); fprintf (outfile, "\"Sum of all ranges:\"\n");
fprintf (outfile, fprintf (outfile,
"\"name\",\"max\",\"cur\",\"percent\",\"touch\",\"t+c\",\"t+c perc\"\n"); "\"name\",\"max\",\"cur\",\"percent\",\"touch\",\"t+c\",\"t+c perc\"");
if (num_backups > 0)
{
fprintf (outfile, ",\"bu\",\"bu perc\"");
}
fprintf (outfile, "\n");
} }
if (config.output_limit[1] & output_limit_bit_3) if (config.output_limit[1] & output_limit_bit_3)
{ {
fprintf (outfile, fprintf (outfile,
"\"%s\",\"%lu\",\"%lu\",\"%.3f\",\"%lu\",\"%lu\",\"%.3f\"\n", "\"%s\",\"%lu\",\"%lu\",\"%.3f\",\"%lu\",\"%lu\",\"%.3f\"",
shared_networks->name, shared_networks->available, shared_networks->name, shared_networks->available,
shared_networks->used, shared_networks->used,
(float) (100 * shared_networks->used) / (float) (100 * shared_networks->used) /
@ -396,6 +525,14 @@ output_csv (void)
(shared_networks->touched + (shared_networks->touched +
shared_networks->used)) / shared_networks->used)) /
shared_networks->available); shared_networks->available);
if (num_backups > 0)
{
fprintf (outfile, "%7lu %8.3f", shared_networks->backups,
(float) (100 * shared_networks->backups) /
shared_networks->available);
}
fprintf (outfile, "\n");
} }
if (outfile == stdout) if (outfile == stdout)
{ {