diff --git a/src/dhcpd-pools.c b/src/dhcpd-pools.c index 3841158..ea17c06 100644 --- a/src/dhcpd-pools.c +++ b/src/dhcpd-pools.c @@ -155,7 +155,6 @@ int main(int argc, char **argv) atexit(close_stdout); set_program_name(argv[0]); - prepare_memory(&state); set_ipv_functions(&state, IPvUNKNOWN); /* Parse command line options */ @@ -179,24 +178,25 @@ int main(int argc, char **argv) output_format = optarg[0]; break; case 's': - { - /* Output sorting option */ - struct output_sort *p = state.sorts; - size_t len; + { + /* Output sorting option */ + struct output_sort *p = state.sorts; + size_t len; - while (p && p->next) - p = p->next; - for (len = 0; len < strlen(optarg); len++) { - if (state.sorts == NULL) { - state.sorts = xcalloc(1, sizeof(struct output_sort)); - p = state.sorts; - } else { - p->next = xcalloc(1, sizeof(struct output_sort)); + while (p && p->next) p = p->next; + for (len = 0; len < strlen(optarg); len++) { + if (state.sorts == NULL) { + state.sorts = + xcalloc(1, sizeof(struct output_sort)); + p = state.sorts; + } else { + p->next = xcalloc(1, sizeof(struct output_sort)); + p = p->next; + } + p->func = field_selector(optarg[len]); } - p->func = field_selector(optarg[len]); } - } break; case 'r': /* What ever sort in reverse order */ @@ -250,7 +250,7 @@ int main(int argc, char **argv) state.minsize = strtod_or_err(optarg, "illegal argument"); break; case OPT_SET_IPV: - switch(optarg[0]) { + switch (optarg[0]) { case '4': set_ipv_functions(&state, IPv4); break; @@ -276,8 +276,7 @@ int main(int argc, char **argv) /* Print help */ usage(EXIT_SUCCESS); default: - error(EXIT_FAILURE, 0, "Try %s --help for more information.", - program_name); + error(EXIT_FAILURE, 0, "Try %s --help for more information.", program_name); } } @@ -294,13 +293,14 @@ int main(int argc, char **argv) state.header_limit = return_limit(default_limit[0]); state.number_limit = return_limit(default_limit[1]); } - /* Output format is not defined, if alarm thresholds are then it's - * alarming, else use the default. */ + /* Output format is not defined, if alarm thresholds are then it's alarming, else use the + * default. */ if (output_format == '\0') { if (alarming == 1) output_format = 'a'; else { const char *const default_format = OUTPUT_FORMAT; + output_format = default_format[0]; } } @@ -321,4 +321,3 @@ int main(int argc, char **argv) clean_up(&state); return (ret_val); } - diff --git a/src/dhcpd-pools.h b/src/dhcpd-pools.h index f519c6f..3604ad1 100644 --- a/src/dhcpd-pools.h +++ b/src/dhcpd-pools.h @@ -93,6 +93,7 @@ enum dhcp_version { IPv4, IPv6 }; + /*! \enum prefix_t * \brief Enumeration of interesting data in dhcpd.leases file, that has * to be further examined, and saved. @@ -108,6 +109,7 @@ enum prefix_t { PREFIX_HARDWARE_ETHERNET, NUM_OF_PREFIX }; + /*! \struct shared_network_t * \brief Counters for an individual shared network. */ @@ -119,6 +121,7 @@ struct shared_network_t { double backups; int netmask; }; + /*! \struct range_t * \brief Counters for an individual range. */ @@ -130,6 +133,7 @@ struct range_t { double touched; double backups; }; + /*! \enum count_status_t * \brief Enumeration of possible range and shared net statuses. */ @@ -140,6 +144,7 @@ enum count_status_t { STATUS_IGNORED, STATUS_SUPPRESSED }; + /*! \struct output_helper_t * \brief Various per range and shared net temporary calculation results. */ @@ -151,6 +156,7 @@ struct output_helper_t { double tcp; double bup; }; + /*! \enum isc_conf_parser * \brief Configuration file parsing state flags. */ @@ -163,6 +169,7 @@ enum isc_conf_parser { ITS_A_SUBNET, ITS_A_NETMASK }; + /*! \enum ltype * \brief Lease state types. */ @@ -171,6 +178,7 @@ enum ltype { FREE, BACKUP }; + /*! \struct leases_t * \brief An individual lease. The leaases are hashed. */ @@ -180,6 +188,7 @@ struct leases_t { char *ethernet; UT_hash_handle hh; }; + /*! \enum limbits * \brief Output limit bits: R_BIT ranges, S_BIT shared networks, A_BIT all. */ @@ -208,7 +217,7 @@ enum color_mode { color_unknown, color_off, color_on, - color_auto /* default */ + color_auto /* default */ }; /*! \var comparer_t @@ -223,6 +232,7 @@ struct output_sort { comparer_t func; struct output_sort *next; }; + /*! \struct conf_t * \brief Runtime configuration state. */ diff --git a/src/hash.c b/src/hash.c index fdc1861..8bcdb30 100644 --- a/src/hash.c +++ b/src/hash.c @@ -81,7 +81,8 @@ void add_lease_v6(struct conf_t *state, union ipaddr_t *addr, enum ltype type) * \param addr Binary IP searched from leases hash. * \return A lease structure about requested IP, or NULL. */ -struct leases_t *find_lease_init(struct conf_t *state __attribute__ ((unused)), union ipaddr_t *addr __attribute__ ((unused))) +struct leases_t *find_lease_init(struct conf_t *state __attribute__ ((unused)), union ipaddr_t *addr + __attribute__ ((unused))) { return NULL; } diff --git a/src/other.c b/src/other.c index c20bed5..9b83a27 100644 --- a/src/other.c +++ b/src/other.c @@ -56,7 +56,7 @@ #include "dhcpd-pools.h" -char *(*cidr_last)(union ipaddr_t *restrict addr, const int mask); +char *(*cidr_last) (union ipaddr_t *restrict addr, const int mask); static char *cidr_last_v4(union ipaddr_t *restrict addr, const int mask); static char *cidr_last_v6(union ipaddr_t *restrict addr, const int mask); @@ -135,7 +135,9 @@ int parse_ipaddr_init(struct conf_t *state, const char *restrict src, union ipad return parse_ipaddr(state, src, dst); } -int parse_ipaddr_v4(struct conf_t *state __attribute__ ((unused)), const char *restrict src, union ipaddr_t *restrict dst) +int parse_ipaddr_v4(struct conf_t *state + __attribute__ ((unused)), const char *restrict src, + union ipaddr_t *restrict dst) { int rv; struct in_addr addr; @@ -145,7 +147,9 @@ int parse_ipaddr_v4(struct conf_t *state __attribute__ ((unused)), const char *r return rv == 1; } -int parse_ipaddr_v6(struct conf_t *state __attribute__ ((unused)), const char *restrict src, union ipaddr_t *restrict dst) +int parse_ipaddr_v6(struct conf_t *state + __attribute__ ((unused)), const char *restrict src, + union ipaddr_t *restrict dst) { int rv; struct in6_addr addr; @@ -184,7 +188,7 @@ static char *cidr_last_v4(union ipaddr_t *restrict addr, const int mask) netmask = (1U << (32 - mask)) - 1; else netmask = 0; - last_ip.v4 = addr->v4 | netmask; + last_ip.v4 = addr->v4 | netmask; ip = ntop_ipaddr(&last_ip); return xstrdup(ip); @@ -221,8 +225,7 @@ void parse_cidr(struct conf_t *state, struct range_t *range_p, const char *word) *divider++ = '\0'; mask = strtol_mask(divider); if (mask < 0) - error(EXIT_FAILURE, 0, "cidr %s invalid mask %s", word, - divider); + error(EXIT_FAILURE, 0, "cidr %s invalid mask %s", word, divider); if (state->ip_version == IPvUNKNOWN) { if (!strchr(word, ':')) set_ipv_functions(state, IPv4); diff --git a/src/output.c b/src/output.c index cdd37c9..0ed0041 100644 --- a/src/output.c +++ b/src/output.c @@ -72,8 +72,7 @@ void range_output_helper(struct conf_t *state, struct output_helper_t *oh, struc } /* set status */ oh->status = STATUS_OK; - if (state->critical < oh->percent - && (oh->range_size - range_p->count) < state->crit_count) + if (state->critical < oh->percent && (oh->range_size - range_p->count) < state->crit_count) oh->status = STATUS_CRIT; else if (state->warning < oh->percent && (oh->range_size - range_p->count) < state->warn_count) @@ -87,7 +86,8 @@ void range_output_helper(struct conf_t *state, struct output_helper_t *oh, struc } /*! \brief Calculate shared network percentages and such. */ -void shnet_output_helper(struct conf_t *state, struct output_helper_t *oh, struct shared_network_t *shared_p) +void shnet_output_helper(struct conf_t *state, struct output_helper_t *oh, + struct shared_network_t *shared_p) { /* counts and calculations */ oh->tc = shared_p->touched + shared_p->used; @@ -206,6 +206,7 @@ static int output_txt(struct conf_t *state) if (state->number_limit & R_BIT) { for (i = 0; i < state->num_ranges; i++) { int color_set = 0; + range_output_helper(state, &oh, range_p); if (state->skip_ok && oh.status == STATUS_OK) { range_p++; @@ -234,8 +235,7 @@ static int output_txt(struct conf_t *state) oh.tc, oh.tcp); if (state->backups_found == 1) { - fprintf(outfile, "%7g %8.3f", - range_p->backups, oh.bup); + fprintf(outfile, "%7g %8.3f", range_p->backups, oh.bup); } if (color_set) fputs(COLOR_RESET, outfile); @@ -258,6 +258,7 @@ static int output_txt(struct conf_t *state) if (state->number_limit & S_BIT) { for (i = 0; i < state->num_shared_networks; i++) { int color_set = 0; + shared_p++; shnet_output_helper(state, &oh, shared_p); if (state->skip_ok && oh.status == STATUS_OK) @@ -274,9 +275,7 @@ static int output_txt(struct conf_t *state) oh.tc, oh.tcp); if (state->backups_found == 1) { - fprintf(outfile, "%7g %8.3f", - shared_p->backups, - oh.bup); + fprintf(outfile, "%7g %8.3f", shared_p->backups, oh.bup); } if (color_set) fputs(COLOR_RESET, outfile); @@ -298,6 +297,7 @@ static int output_txt(struct conf_t *state) } if (state->number_limit & A_BIT) { int color_set = 0; + shnet_output_helper(state, &oh, state->shared_networks); if (state->color_mode == color_on) color_set = start_color(&oh, outfile); @@ -311,9 +311,7 @@ static int output_txt(struct conf_t *state) oh.tcp); if (state->backups_found == 1) { - fprintf(outfile, "%7g %8.3f", - state->shared_networks->backups, - oh.bup); + fprintf(outfile, "%7g %8.3f", state->shared_networks->backups, oh.bup); } if (color_set) fputs(COLOR_RESET, outfile); @@ -554,12 +552,13 @@ static int output_json(struct conf_t *state, const int print_mac_addreses) fprintf(outfile, " \"used\":%g,\n", state->shared_networks->used); fprintf(outfile, " \"touched\":%g,\n", state->shared_networks->touched); fprintf(outfile, " \"free\":%g,\n", - state->shared_networks->available - state->shared_networks->used); + state->shared_networks->available - state->shared_networks->used); fprintf(outfile, " \"percent\":%g,\n", oh.percent); fprintf(outfile, " \"touch_count\":%g,\n", oh.tc); fprintf(outfile, " \"touch_percent\":%g,\n", oh.tcp); if (state->backups_found == 1) { - fprintf(outfile, " \"backup_count\":%g,\n", state->shared_networks->backups); + fprintf(outfile, " \"backup_count\":%g,\n", + state->shared_networks->backups); fprintf(outfile, " \"backup_percent\":%g,\n", oh.bup); } fprintf(outfile, " \"status\":%d\n", oh.status); @@ -608,7 +607,8 @@ static void html_header(struct conf_t *state, FILE *restrict f) fprintf(f, "
\n"); fprintf(f, "