mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-16 07:47:00 +00:00
all files: re-indent
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
1875a13733
commit
7cd381ed83
6 changed files with 69 additions and 67 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
15
src/other.c
15
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);
|
||||
|
|
|
|||
59
src/output.c
59
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, "<body>\n");
|
||||
fprintf(f, "<div class=\"container\">\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.
|
||||
|
|
@ -656,8 +656,7 @@ static void end_tag(FILE *restrict f, char const *restrict tag)
|
|||
* \param class How the data is aligned.
|
||||
* \param text Actual payload of the printout.
|
||||
*/
|
||||
static void output_line(FILE *restrict f, char const *restrict type,
|
||||
char const *restrict text)
|
||||
static void output_line(FILE *restrict f, char const *restrict type, char const *restrict text)
|
||||
{
|
||||
fprintf(f, "<%s>%s</%s>\n", type, text, type);
|
||||
}
|
||||
|
|
@ -909,9 +908,7 @@ static int output_csv(struct conf_t *state)
|
|||
oh.tc,
|
||||
oh.tcp);
|
||||
if (state->backups_found == 1) {
|
||||
fprintf(outfile, ",\"%g\",\"%.3f\"",
|
||||
range_p->backups,
|
||||
oh.bup);
|
||||
fprintf(outfile, ",\"%g\",\"%.3f\"", range_p->backups, oh.bup);
|
||||
}
|
||||
|
||||
fprintf(outfile, "\n");
|
||||
|
|
@ -945,9 +942,7 @@ static int output_csv(struct conf_t *state)
|
|||
oh.tc,
|
||||
oh.tcp);
|
||||
if (state->backups_found == 1) {
|
||||
fprintf(outfile, ",\"%g\",\"%.3f\"",
|
||||
shared_p->backups,
|
||||
oh.bup);
|
||||
fprintf(outfile, ",\"%g\",\"%.3f\"", shared_p->backups, oh.bup);
|
||||
}
|
||||
|
||||
fprintf(outfile, "\n");
|
||||
|
|
@ -975,9 +970,7 @@ static int output_csv(struct conf_t *state)
|
|||
oh.tc,
|
||||
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);
|
||||
}
|
||||
fprintf(outfile, "\n");
|
||||
}
|
||||
|
|
@ -1086,16 +1079,13 @@ static int output_alarming(struct conf_t *state)
|
|||
range_p--;
|
||||
range_size = get_range_size(range_p);
|
||||
if (state->minsize < range_size) {
|
||||
fprintf(outfile, " %s_r=",
|
||||
ntop_ipaddr(&range_p->first_ip));
|
||||
fprintf(outfile, " %s_r=", ntop_ipaddr(&range_p->first_ip));
|
||||
fprintf(outfile, "%g;%g;%g;0;%g",
|
||||
range_p->count,
|
||||
(range_size * state->warning / 100),
|
||||
(range_size * state->critical / 100),
|
||||
range_size);
|
||||
(range_size * state->critical / 100), range_size);
|
||||
fprintf(outfile, " %s_rt=%g",
|
||||
ntop_ipaddr(&range_p->first_ip),
|
||||
range_p->touched);
|
||||
ntop_ipaddr(&range_p->first_ip), range_p->touched);
|
||||
if (state->backups_found == 1) {
|
||||
fprintf(outfile, " %s_rbu=%g",
|
||||
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);
|
||||
fprintf(outfile, " '%s_st'=%g",
|
||||
shared_p->name,
|
||||
shared_p->touched);
|
||||
shared_p->name, shared_p->touched);
|
||||
if (state->backups_found == 1) {
|
||||
fprintf(outfile, " '%s_sbu'=%g",
|
||||
shared_p->name,
|
||||
shared_p->backups);
|
||||
shared_p->name, shared_p->backups);
|
||||
}
|
||||
}
|
||||
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 ret = 1;
|
||||
|
||||
switch (output_format) {
|
||||
case 't':
|
||||
ret = output_txt(state);
|
||||
|
|
|
|||
|
|
@ -240,7 +240,8 @@ comparer_t field_selector(char c)
|
|||
default:
|
||||
{
|
||||
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;
|
||||
|
|
@ -251,8 +252,7 @@ comparer_t field_selector(char c)
|
|||
* \param right The right side of the merge sort.
|
||||
* \return Relevant for merge sort decision.
|
||||
*/
|
||||
int merge(struct conf_t *state, struct range_t *restrict left,
|
||||
struct range_t *restrict right)
|
||||
int merge(struct conf_t *state, struct range_t *restrict left, struct range_t *restrict right)
|
||||
{
|
||||
struct output_sort *p;
|
||||
int ret;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue