all files: re-indent

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2017-11-12 13:41:33 +00:00
parent 1875a13733
commit 7cd381ed83
No known key found for this signature in database
GPG key ID: A9553245FDE9B739
6 changed files with 69 additions and 67 deletions

View file

@ -155,7 +155,6 @@ int main(int argc, char **argv)
atexit(close_stdout); atexit(close_stdout);
set_program_name(argv[0]); set_program_name(argv[0]);
prepare_memory(&state); prepare_memory(&state);
set_ipv_functions(&state, IPvUNKNOWN); set_ipv_functions(&state, IPvUNKNOWN);
/* Parse command line options */ /* Parse command line options */
@ -179,24 +178,25 @@ int main(int argc, char **argv)
output_format = optarg[0]; output_format = optarg[0];
break; break;
case 's': case 's':
{ {
/* Output sorting option */ /* Output sorting option */
struct output_sort *p = state.sorts; struct output_sort *p = state.sorts;
size_t len; size_t len;
while (p && p->next) 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 = 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; break;
case 'r': case 'r':
/* What ever sort in reverse order */ /* What ever sort in reverse order */
@ -250,7 +250,7 @@ int main(int argc, char **argv)
state.minsize = strtod_or_err(optarg, "illegal argument"); state.minsize = strtod_or_err(optarg, "illegal argument");
break; break;
case OPT_SET_IPV: case OPT_SET_IPV:
switch(optarg[0]) { switch (optarg[0]) {
case '4': case '4':
set_ipv_functions(&state, IPv4); set_ipv_functions(&state, IPv4);
break; break;
@ -276,8 +276,7 @@ int main(int argc, char **argv)
/* Print help */ /* Print help */
usage(EXIT_SUCCESS); usage(EXIT_SUCCESS);
default: default:
error(EXIT_FAILURE, 0, "Try %s --help for more information.", error(EXIT_FAILURE, 0, "Try %s --help for more information.", program_name);
program_name);
} }
} }
@ -294,13 +293,14 @@ int main(int argc, char **argv)
state.header_limit = return_limit(default_limit[0]); state.header_limit = return_limit(default_limit[0]);
state.number_limit = return_limit(default_limit[1]); state.number_limit = return_limit(default_limit[1]);
} }
/* Output format is not defined, if alarm thresholds are then it's /* Output format is not defined, if alarm thresholds are then it's alarming, else use the
* alarming, else use the default. */ * default. */
if (output_format == '\0') { if (output_format == '\0') {
if (alarming == 1) if (alarming == 1)
output_format = 'a'; output_format = 'a';
else { else {
const char *const default_format = OUTPUT_FORMAT; const char *const default_format = OUTPUT_FORMAT;
output_format = default_format[0]; output_format = default_format[0];
} }
} }
@ -321,4 +321,3 @@ int main(int argc, char **argv)
clean_up(&state); clean_up(&state);
return (ret_val); return (ret_val);
} }

View file

@ -93,6 +93,7 @@ enum dhcp_version {
IPv4, IPv4,
IPv6 IPv6
}; };
/*! \enum prefix_t /*! \enum prefix_t
* \brief Enumeration of interesting data in dhcpd.leases file, that has * \brief Enumeration of interesting data in dhcpd.leases file, that has
* to be further examined, and saved. * to be further examined, and saved.
@ -108,6 +109,7 @@ enum prefix_t {
PREFIX_HARDWARE_ETHERNET, PREFIX_HARDWARE_ETHERNET,
NUM_OF_PREFIX NUM_OF_PREFIX
}; };
/*! \struct shared_network_t /*! \struct shared_network_t
* \brief Counters for an individual shared network. * \brief Counters for an individual shared network.
*/ */
@ -119,6 +121,7 @@ struct shared_network_t {
double backups; double backups;
int netmask; int netmask;
}; };
/*! \struct range_t /*! \struct range_t
* \brief Counters for an individual range. * \brief Counters for an individual range.
*/ */
@ -130,6 +133,7 @@ struct range_t {
double touched; double touched;
double backups; double backups;
}; };
/*! \enum count_status_t /*! \enum count_status_t
* \brief Enumeration of possible range and shared net statuses. * \brief Enumeration of possible range and shared net statuses.
*/ */
@ -140,6 +144,7 @@ enum count_status_t {
STATUS_IGNORED, STATUS_IGNORED,
STATUS_SUPPRESSED STATUS_SUPPRESSED
}; };
/*! \struct output_helper_t /*! \struct output_helper_t
* \brief Various per range and shared net temporary calculation results. * \brief Various per range and shared net temporary calculation results.
*/ */
@ -151,6 +156,7 @@ struct output_helper_t {
double tcp; double tcp;
double bup; double bup;
}; };
/*! \enum isc_conf_parser /*! \enum isc_conf_parser
* \brief Configuration file parsing state flags. * \brief Configuration file parsing state flags.
*/ */
@ -163,6 +169,7 @@ enum isc_conf_parser {
ITS_A_SUBNET, ITS_A_SUBNET,
ITS_A_NETMASK ITS_A_NETMASK
}; };
/*! \enum ltype /*! \enum ltype
* \brief Lease state types. * \brief Lease state types.
*/ */
@ -171,6 +178,7 @@ enum ltype {
FREE, FREE,
BACKUP BACKUP
}; };
/*! \struct leases_t /*! \struct leases_t
* \brief An individual lease. The leaases are hashed. * \brief An individual lease. The leaases are hashed.
*/ */
@ -180,6 +188,7 @@ struct leases_t {
char *ethernet; char *ethernet;
UT_hash_handle hh; UT_hash_handle hh;
}; };
/*! \enum limbits /*! \enum limbits
* \brief Output limit bits: R_BIT ranges, S_BIT shared networks, A_BIT all. * \brief Output limit bits: R_BIT ranges, S_BIT shared networks, A_BIT all.
*/ */
@ -208,7 +217,7 @@ enum color_mode {
color_unknown, color_unknown,
color_off, color_off,
color_on, color_on,
color_auto /* default */ color_auto /* default */
}; };
/*! \var comparer_t /*! \var comparer_t
@ -223,6 +232,7 @@ struct output_sort {
comparer_t func; comparer_t func;
struct output_sort *next; struct output_sort *next;
}; };
/*! \struct conf_t /*! \struct conf_t
* \brief Runtime configuration state. * \brief Runtime configuration state.
*/ */

View file

@ -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. * \param addr Binary IP searched from leases hash.
* \return A lease structure about requested IP, or NULL. * \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; return NULL;
} }

View file

@ -56,7 +56,7 @@
#include "dhcpd-pools.h" #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_v4(union ipaddr_t *restrict addr, const int mask);
static char *cidr_last_v6(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); 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; int rv;
struct in_addr addr; struct in_addr addr;
@ -145,7 +147,9 @@ int parse_ipaddr_v4(struct conf_t *state __attribute__ ((unused)), const char *r
return rv == 1; 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; int rv;
struct in6_addr addr; 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; netmask = (1U << (32 - mask)) - 1;
else else
netmask = 0; netmask = 0;
last_ip.v4 = addr->v4 | netmask; last_ip.v4 = addr->v4 | netmask;
ip = ntop_ipaddr(&last_ip); ip = ntop_ipaddr(&last_ip);
return xstrdup(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'; *divider++ = '\0';
mask = strtol_mask(divider); mask = strtol_mask(divider);
if (mask < 0) if (mask < 0)
error(EXIT_FAILURE, 0, "cidr %s invalid mask %s", word, error(EXIT_FAILURE, 0, "cidr %s invalid mask %s", word, divider);
divider);
if (state->ip_version == IPvUNKNOWN) { if (state->ip_version == IPvUNKNOWN) {
if (!strchr(word, ':')) if (!strchr(word, ':'))
set_ipv_functions(state, IPv4); set_ipv_functions(state, IPv4);

View file

@ -72,8 +72,7 @@ void range_output_helper(struct conf_t *state, struct output_helper_t *oh, struc
} }
/* set status */ /* set status */
oh->status = STATUS_OK; oh->status = STATUS_OK;
if (state->critical < oh->percent if (state->critical < oh->percent && (oh->range_size - range_p->count) < state->crit_count)
&& (oh->range_size - range_p->count) < state->crit_count)
oh->status = STATUS_CRIT; oh->status = STATUS_CRIT;
else if (state->warning < oh->percent else if (state->warning < oh->percent
&& (oh->range_size - range_p->count) < state->warn_count) && (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. */ /*! \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 */ /* counts and calculations */
oh->tc = shared_p->touched + shared_p->used; 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) { if (state->number_limit & R_BIT) {
for (i = 0; i < state->num_ranges; i++) { for (i = 0; i < state->num_ranges; i++) {
int color_set = 0; int color_set = 0;
range_output_helper(state, &oh, range_p); range_output_helper(state, &oh, range_p);
if (state->skip_ok && oh.status == STATUS_OK) { if (state->skip_ok && oh.status == STATUS_OK) {
range_p++; range_p++;
@ -234,8 +235,7 @@ static int output_txt(struct conf_t *state)
oh.tc, oh.tc,
oh.tcp); oh.tcp);
if (state->backups_found == 1) { if (state->backups_found == 1) {
fprintf(outfile, "%7g %8.3f", fprintf(outfile, "%7g %8.3f", range_p->backups, oh.bup);
range_p->backups, oh.bup);
} }
if (color_set) if (color_set)
fputs(COLOR_RESET, outfile); fputs(COLOR_RESET, outfile);
@ -258,6 +258,7 @@ static int output_txt(struct conf_t *state)
if (state->number_limit & S_BIT) { if (state->number_limit & S_BIT) {
for (i = 0; i < state->num_shared_networks; i++) { for (i = 0; i < state->num_shared_networks; i++) {
int color_set = 0; int color_set = 0;
shared_p++; shared_p++;
shnet_output_helper(state, &oh, shared_p); shnet_output_helper(state, &oh, shared_p);
if (state->skip_ok && oh.status == STATUS_OK) if (state->skip_ok && oh.status == STATUS_OK)
@ -274,9 +275,7 @@ static int output_txt(struct conf_t *state)
oh.tc, oh.tc,
oh.tcp); oh.tcp);
if (state->backups_found == 1) { if (state->backups_found == 1) {
fprintf(outfile, "%7g %8.3f", fprintf(outfile, "%7g %8.3f", shared_p->backups, oh.bup);
shared_p->backups,
oh.bup);
} }
if (color_set) if (color_set)
fputs(COLOR_RESET, outfile); fputs(COLOR_RESET, outfile);
@ -298,6 +297,7 @@ static int output_txt(struct conf_t *state)
} }
if (state->number_limit & A_BIT) { if (state->number_limit & A_BIT) {
int color_set = 0; int color_set = 0;
shnet_output_helper(state, &oh, state->shared_networks); shnet_output_helper(state, &oh, state->shared_networks);
if (state->color_mode == color_on) if (state->color_mode == color_on)
color_set = start_color(&oh, outfile); color_set = start_color(&oh, outfile);
@ -311,9 +311,7 @@ static int output_txt(struct conf_t *state)
oh.tcp); oh.tcp);
if (state->backups_found == 1) { if (state->backups_found == 1) {
fprintf(outfile, "%7g %8.3f", fprintf(outfile, "%7g %8.3f", state->shared_networks->backups, oh.bup);
state->shared_networks->backups,
oh.bup);
} }
if (color_set) if (color_set)
fputs(COLOR_RESET, outfile); 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, " \"used\":%g,\n", state->shared_networks->used);
fprintf(outfile, " \"touched\":%g,\n", state->shared_networks->touched); fprintf(outfile, " \"touched\":%g,\n", state->shared_networks->touched);
fprintf(outfile, " \"free\":%g,\n", 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, " \"percent\":%g,\n", oh.percent);
fprintf(outfile, " \"touch_count\":%g,\n", oh.tc); fprintf(outfile, " \"touch_count\":%g,\n", oh.tc);
fprintf(outfile, " \"touch_percent\":%g,\n", oh.tcp); fprintf(outfile, " \"touch_percent\":%g,\n", oh.tcp);
if (state->backups_found == 1) { 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, " \"backup_percent\":%g,\n", oh.bup);
} }
fprintf(outfile, " \"status\":%d\n", oh.status); fprintf(outfile, " \"status\":%d\n", oh.status);
@ -608,7 +607,8 @@ static void html_header(struct conf_t *state, FILE *restrict f)
fprintf(f, "<body>\n"); fprintf(f, "<body>\n");
fprintf(f, "<div class=\"container\">\n"); fprintf(f, "<div class=\"container\">\n");
fprintf(f, "<h2>ISC DHCPD status</h2>\n"); fprintf(f, "<h2>ISC DHCPD status</h2>\n");
fprintf(f, "<small>File %s was last modified at %s</small><hr />\n", state->dhcpdlease_file, outstr); fprintf(f, "<small>File %s was last modified at %s</small><hr />\n", state->dhcpdlease_file,
outstr);
} }
/*! \brief Footer for full html output format. /*! \brief Footer for full html output format.
@ -656,8 +656,7 @@ static void end_tag(FILE *restrict f, char const *restrict tag)
* \param class How the data is aligned. * \param class How the data is aligned.
* \param text Actual payload of the printout. * \param text Actual payload of the printout.
*/ */
static void output_line(FILE *restrict f, char const *restrict type, static void output_line(FILE *restrict f, char const *restrict type, char const *restrict text)
char const *restrict text)
{ {
fprintf(f, "<%s>%s</%s>\n", type, text, type); fprintf(f, "<%s>%s</%s>\n", type, text, type);
} }
@ -909,9 +908,7 @@ static int output_csv(struct conf_t *state)
oh.tc, oh.tc,
oh.tcp); oh.tcp);
if (state->backups_found == 1) { if (state->backups_found == 1) {
fprintf(outfile, ",\"%g\",\"%.3f\"", fprintf(outfile, ",\"%g\",\"%.3f\"", range_p->backups, oh.bup);
range_p->backups,
oh.bup);
} }
fprintf(outfile, "\n"); fprintf(outfile, "\n");
@ -945,9 +942,7 @@ static int output_csv(struct conf_t *state)
oh.tc, oh.tc,
oh.tcp); oh.tcp);
if (state->backups_found == 1) { if (state->backups_found == 1) {
fprintf(outfile, ",\"%g\",\"%.3f\"", fprintf(outfile, ",\"%g\",\"%.3f\"", shared_p->backups, oh.bup);
shared_p->backups,
oh.bup);
} }
fprintf(outfile, "\n"); fprintf(outfile, "\n");
@ -975,9 +970,7 @@ static int output_csv(struct conf_t *state)
oh.tc, oh.tc,
oh.tcp); oh.tcp);
if (state->backups_found == 1) { if (state->backups_found == 1) {
fprintf(outfile, "%7g %8.3f", fprintf(outfile, "%7g %8.3f", state->shared_networks->backups, oh.bup);
state->shared_networks->backups,
oh.bup);
} }
fprintf(outfile, "\n"); fprintf(outfile, "\n");
} }
@ -1086,16 +1079,13 @@ static int output_alarming(struct conf_t *state)
range_p--; range_p--;
range_size = get_range_size(range_p); range_size = get_range_size(range_p);
if (state->minsize < range_size) { if (state->minsize < range_size) {
fprintf(outfile, " %s_r=", fprintf(outfile, " %s_r=", ntop_ipaddr(&range_p->first_ip));
ntop_ipaddr(&range_p->first_ip));
fprintf(outfile, "%g;%g;%g;0;%g", fprintf(outfile, "%g;%g;%g;0;%g",
range_p->count, range_p->count,
(range_size * state->warning / 100), (range_size * state->warning / 100),
(range_size * state->critical / 100), (range_size * state->critical / 100), range_size);
range_size);
fprintf(outfile, " %s_rt=%g", fprintf(outfile, " %s_rt=%g",
ntop_ipaddr(&range_p->first_ip), ntop_ipaddr(&range_p->first_ip), range_p->touched);
range_p->touched);
if (state->backups_found == 1) { if (state->backups_found == 1) {
fprintf(outfile, " %s_rbu=%g", fprintf(outfile, " %s_rbu=%g",
ntop_ipaddr(&range_p->first_ip), ntop_ipaddr(&range_p->first_ip),
@ -1127,12 +1117,10 @@ static int output_alarming(struct conf_t *state)
(shared_p->available * state->critical / 100), (shared_p->available * state->critical / 100),
shared_p->available); shared_p->available);
fprintf(outfile, " '%s_st'=%g", fprintf(outfile, " '%s_st'=%g",
shared_p->name, shared_p->name, shared_p->touched);
shared_p->touched);
if (state->backups_found == 1) { if (state->backups_found == 1) {
fprintf(outfile, " '%s_sbu'=%g", fprintf(outfile, " '%s_sbu'=%g",
shared_p->name, shared_p->name, shared_p->backups);
shared_p->backups);
} }
} }
shared_p--; shared_p--;
@ -1149,6 +1137,7 @@ static int output_alarming(struct conf_t *state)
int output_analysis(struct conf_t *state, const char output_format) int output_analysis(struct conf_t *state, const char output_format)
{ {
int ret = 1; int ret = 1;
switch (output_format) { switch (output_format) {
case 't': case 't':
ret = output_txt(state); ret = output_txt(state);

View file

@ -240,7 +240,8 @@ comparer_t field_selector(char c)
default: default:
{ {
char str[2] = { c, '\0' }; char str[2] = { c, '\0' };
error(EXIT_FAILURE, 0, "field_selector: unknown sort order: %s", quote(str)); error(EXIT_FAILURE, 0, "field_selector: unknown sort order: %s",
quote(str));
} }
} }
return NULL; return NULL;
@ -251,8 +252,7 @@ comparer_t field_selector(char c)
* \param right The right side of the merge sort. * \param right The right side of the merge sort.
* \return Relevant for merge sort decision. * \return Relevant for merge sort decision.
*/ */
int merge(struct conf_t *state, struct range_t *restrict left, int merge(struct conf_t *state, struct range_t *restrict left, struct range_t *restrict right)
struct range_t *restrict right)
{ {
struct output_sort *p; struct output_sort *p;
int ret; int ret;