From 782f63c3ad2ec9ae46af90ae4507693e2a873f63 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sat, 9 Sep 2017 10:09:35 +0100 Subject: [PATCH] add --ip-version option to force either IPv4 or IPv6 analysis Proposed-by: Jeff Balley Signed-off-by: Sami Kerola --- man/dhcpd-pools.1.in | 6 ++++++ src/dhcpd-pools.c | 18 ++++++++++++++++-- src/other.c | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/man/dhcpd-pools.1.in b/man/dhcpd-pools.1.in index 8a55165..0eee034 100644 --- a/man/dhcpd-pools.1.in +++ b/man/dhcpd-pools.1.in @@ -206,6 +206,12 @@ is not in use. Treat all stand-alone subnets as shared-network with named formed from it's CIDR. By default this option is not in use for backwards compatibility. .TP +\fB\-\-ip\-version\fR=\fI4|6\fR +Force command to read configuration and leases files in IPv4 or IPv6 mode. +Notice that when inputs do not match with what is forced analysis output is +garbage. This option should not be necessary to use, and exists only to +allow debugging. +.TP \fB\-v\fR, \fB\-\-version\fR Print version information to standard output and exit successfully. .TP diff --git a/src/dhcpd-pools.c b/src/dhcpd-pools.c index 16d685e..4f6f22b 100644 --- a/src/dhcpd-pools.c +++ b/src/dhcpd-pools.c @@ -108,7 +108,8 @@ int main(int argc, char **argv) OPT_CRIT, OPT_MINSIZE, OPT_WARN_COUNT, - OPT_CRIT_COUNT + OPT_CRIT_COUNT, + OPT_SET_IPV }; int ret_val; @@ -130,6 +131,7 @@ int main(int argc, char **argv) {"minsize", required_argument, NULL, OPT_MINSIZE}, {"perfdata", no_argument, NULL, 'p'}, {"all-as-shared", no_argument, NULL, 'A'}, + {"ip-version", required_argument, NULL, OPT_SET_IPV}, {NULL, 0, NULL, 0} }; @@ -165,6 +167,7 @@ int main(int argc, char **argv) /* Treat single networks as shared with network CIDR as name */ config.all_as_shared = 0; prepare_memory(); + set_ipv_functions(IPvUNKNOWN); /* Parse command line options */ while (1) { int c; @@ -240,6 +243,18 @@ int main(int argc, char **argv) case OPT_MINSIZE: config.minsize = strtod_or_err(optarg, "illegal argument"); break; + case OPT_SET_IPV: + switch(optarg[0]) { + case '4': + set_ipv_functions(IPv4); + break; + case '6': + set_ipv_functions(IPv6); + break; + default: + error(EXIT_FAILURE, 0, "unknown --ip-version argument: %s", optarg); + } + break; case 'p': /* Print additional performance data in alarming mode */ config.perfdata = 1; @@ -301,7 +316,6 @@ int main(int argc, char **argv) error(EXIT_FAILURE, 0, "unknown output format: %s", quote(print_mac_addreses_tmp)); } /* Do the job */ - set_ipv_functions(IPvUNKNOWN); parse_config(1, config.dhcpdconf_file, shared_networks); parse_leases(); prepare_data(); diff --git a/src/other.c b/src/other.c index 5794ccc..7ac69c9 100644 --- a/src/other.c +++ b/src/other.c @@ -476,6 +476,7 @@ void __attribute__ ((__noreturn__)) usage(int status) fputs( " --snet-alarms suppress range alarms that are part of a shared-net\n", out); fputs( " -p, --perfdata print additional perfdata in alarming mode\n", out); fputs( " -A, --all-as-shared treat single subnets as shared-network with CIDR as their name\n", out); + fputs( " --ip-version=4|6 force analysis to use either IPv4 or IPv6 functions\n", out); fputs( " -v, --version output version information and exit\n", out); fputs( " -h, --help display this help and exit\n", out); fputs( "\n", out);