dhcpd-pools
3.0
ISC dhcpd lease usage analyser
|
Global definitions of structures, enums, and function prototypes. More...
#include <config.h>
#include <arpa/inet.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <uthash.h>
Go to the source code of this file.
Data Structures | |
union | ipaddr_t |
Memory space for a binary IP address saving. More... | |
struct | shared_network_t |
Counters for an individual shared network. More... | |
struct | range_t |
Counters for an individual range. More... | |
struct | output_helper_t |
Various per range and shared net temporary calculation results. More... | |
struct | leases_t |
An individual lease. More... | |
struct | output_sort |
Linked list of sort functions. More... | |
struct | conf_t |
Runtime configuration state. More... | |
Macros | |
#define | likely(x) (x) |
Symbolic call to __builtin_expect'ed branch. More... | |
#define | unlikely(x) (x) |
Symbolic call to not-__builtin_expect'ed branch. More... | |
#define | _DP_ATTRIBUTE_HOT /* empty */ |
The function attribute hot was added in gcc 4.3. More... | |
#define | STATE_OK 0 |
Nagios alarm exit value. More... | |
#define | STATE_WARNING 1 |
#define | STATE_CRITICAL 2 |
Typedefs | |
typedef int(* | comparer_t) (struct range_t *r1, struct range_t *r2) |
Function pointer holding sort algorithm. More... | |
Enumerations | |
enum | dhcp_version { IPvUNKNOWN, IPv4, IPv6 } |
The IP version, IPv4 or IPv6, served by the dhcpd. More... | |
enum | prefix_t { PREFIX_LEASE, PREFIX_BINDING_STATE_FREE, PREFIX_BINDING_STATE_ABANDONED, PREFIX_BINDING_STATE_EXPIRED, PREFIX_BINDING_STATE_RELEASED, PREFIX_BINDING_STATE_ACTIVE, PREFIX_BINDING_STATE_BACKUP, PREFIX_HARDWARE_ETHERNET, NUM_OF_PREFIX } |
Enumeration of interesting data in dhcpd.leases file, that has to be further examined, and saved. More... | |
enum | color_mode { color_unknown, color_off, color_on, color_auto } |
Enumeration whether to use or not color output. More... | |
enum | ltype { ACTIVE, FREE, BACKUP } |
Lease state types. More... | |
enum | limbits { R_BIT = (1 << 0), S_BIT = (1 << 1), A_BIT = (1 << 2) } |
Output limit bits. More... | |
Functions | |
void | prepare_data (struct conf_t *state) |
Prepare data for analysis. More... | |
void | do_counting (struct conf_t *state) |
Perform counting. More... | |
int | parse_leases (struct conf_t *state, const int print_mac_addreses) |
Lease file parser. More... | |
void | parse_config (struct conf_t *state, const int is_include, const char *restrict config_file, struct shared_network_t *restrict shared_p) |
The dhcpd.conf file parser. More... | |
void | add_lease_init (struct conf_t *state, union ipaddr_t *addr, enum ltype type) |
void | add_lease_v4 (struct conf_t *state, union ipaddr_t *addr, enum ltype type) |
void | add_lease_v6 (struct conf_t *state, union ipaddr_t *addr, enum ltype type) |
struct leases_t * | find_lease_init (struct conf_t *state, union ipaddr_t *addr) |
struct leases_t * | find_lease_v4 (struct conf_t *state, union ipaddr_t *addr) |
struct leases_t * | find_lease_v6 (struct conf_t *state, union ipaddr_t *addr) |
void | delete_lease (struct conf_t *state, struct leases_t *lease) |
Delete a lease from hash array. More... | |
void | delete_all_leases (struct conf_t *state) |
Delete all leases from hash array. More... | |
int | mustach_dhcpd_pools (struct conf_t *state) |
Start mustach processing. More... | |
void | set_ipv_functions (struct conf_t *state, int version) |
Set function pointers depending on IP version. More... | |
void | flip_ranges (struct conf_t *state) |
Reverse range. More... | |
void | clean_up (struct conf_t *state) |
Free memory, flush buffers etc. More... | |
void | parse_cidr (struct conf_t *state, struct range_t *range_p, const char *word) |
Convert a cidr notated address to a range. More... | |
int | parse_color_mode (const char *restrict optarg) |
Parse option argument color mode. More... | |
double | strtod_or_err (const char *restrict str, const char *restrict errmesg) |
Return a double floating point value. More... | |
void | __attribute__ ((noreturn)) print_version(void) |
void | dp_time_tool (FILE *file, const char *path, int epoch) |
Print a time stamp of a path or now to output file. More... | |
int | parse_ipaddr_init (struct conf_t *state, const char *restrict src, union ipaddr_t *restrict dst) |
Convert text string IP address from either IPv4 or IPv6 to an integer. More... | |
int | parse_ipaddr_v4 (struct conf_t *state, const char *restrict src, union ipaddr_t *restrict dst) |
int | parse_ipaddr_v6 (struct conf_t *state, const char *restrict src, union ipaddr_t *restrict dst) |
int | xstrstr_init (struct conf_t *state, const char *restrict str) |
int | xstrstr_v4 (struct conf_t *state, const char *restrict str) |
int | xstrstr_v6 (struct conf_t *state, const char *restrict str) |
void | copy_ipaddr_init (union ipaddr_t *restrict dst, const union ipaddr_t *restrict src) |
void | copy_ipaddr_v4 (union ipaddr_t *restrict dst, const union ipaddr_t *restrict src) |
void | copy_ipaddr_v6 (union ipaddr_t *restrict dst, const union ipaddr_t *restrict src) |
const char * | ntop_ipaddr_init (const union ipaddr_t *ip) |
const char * | ntop_ipaddr_v4 (const union ipaddr_t *ip) |
const char * | ntop_ipaddr_v6 (const union ipaddr_t *ip) |
double | get_range_size_init (const struct range_t *r) |
double | get_range_size_v4 (const struct range_t *r) |
double | get_range_size_v6 (const struct range_t *r) |
int | range_output_helper (struct conf_t *state, struct output_helper_t *oh, struct range_t *range_p) |
Calculate range percentages and such. More... | |
int | shnet_output_helper (struct conf_t *state, struct output_helper_t *oh, struct shared_network_t *shared_p) |
Calculate shared network percentages and such. More... | |
int | output_analysis (struct conf_t *state, const char output_format) |
Return output_format_names enum based on single char input. More... | |
void | mergesort_ranges (struct conf_t *state, struct range_t *restrict orig, unsigned int size, struct range_t *restrict temp, const int root_call) |
Mergesort for range table. More... | |
int | leasecomp_init (const struct leases_t *restrict a __attribute__((unused)), const struct leases_t *restrict b __attribute__((unused))) |
Compare IP address in leases_t structure, with IPv4/v6 determination. More... | |
int | leasecomp_v4 (const struct leases_t *restrict a, const struct leases_t *restrict b) |
int | leasecomp_v6 (const struct leases_t *restrict a, const struct leases_t *restrict b) |
int | ipcomp_init (const union ipaddr_t *restrict a, const union ipaddr_t *restrict b) |
int | ipcomp_v4 (const union ipaddr_t *restrict a, const union ipaddr_t *restrict b) |
int | ipcomp_v6 (const union ipaddr_t *restrict a, const union ipaddr_t *restrict b) |
int | rangecomp (const void *restrict r1, const void *restrict r2) __attribute__((nonnull(1 |
int int | comp_cur (struct range_t *r1, struct range_t *r2) |
Compare two range_t by their current usage. More... | |
int | comp_double (double f1, double f2) |
Compare two doubles. More... | |
int | comp_ip (struct range_t *r1, struct range_t *r2) |
Compare two range_t by their first_ip. More... | |
int | comp_max (struct range_t *r1, struct range_t *r2) |
Compare two range_t by their capacity. More... | |
int | comp_percent (struct range_t *r1, struct range_t *r2) |
Compare two range_t by their current usage percentage. More... | |
int | comp_tc (struct range_t *r1, struct range_t *r2) |
Compare two range_t by their touched and in use addresses. More... | |
int | comp_tcperc (struct range_t *r1, struct range_t *r2) |
Compare two range_t by their touched and in use percentage. More... | |
int | comp_touched (struct range_t *r1, struct range_t *r2) |
Compare two range_t by their touched addresses. More... | |
comparer_t | field_selector (char c) |
Sort field selector. More... | |
double | ret_percent (struct range_t r) |
Percentage in use in range. More... | |
double | ret_tc (struct range_t r) |
Touched and in use in range. More... | |
double | ret_tcperc (struct range_t r) |
Return percentage of addresses touched and in use in range. More... | |
Variables | |
void(* | add_lease )(struct conf_t *state, union ipaddr_t *addr, enum ltype type) |
struct leases_t *(* | find_lease )(struct conf_t *state, union ipaddr_t *addr) |
int(* | parse_ipaddr )(struct conf_t *state, const char *restrict src, union ipaddr_t *restrict dst) |
int(* | xstrstr )(struct conf_t *state, const char *restrict str) |
void(* | copy_ipaddr )(union ipaddr_t *restrict dst, const union ipaddr_t *restrict src) |
const char *(* | ntop_ipaddr )(const union ipaddr_t *ip) |
double(* | get_range_size )(const struct range_t *r) |
int(* | leasecomp )(const struct leases_t *restrict a, const struct leases_t *restrict b) |
int(* | ipcomp )(const union ipaddr_t *restrict a, const union ipaddr_t *restrict b) |
Global definitions of structures, enums, and function prototypes.
#define _DP_ATTRIBUTE_HOT /* empty */ |
The function attribute hot was added in gcc 4.3.
See gnu documentation for further information. https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-hot-function-attribute
#define likely | ( | x | ) | (x) |
Symbolic call to __builtin_expect'ed branch.
#define STATE_CRITICAL 2 |
Referenced by output_alarming().
#define STATE_OK 0 |
Nagios alarm exit value.
Referenced by output_alarming().
#define STATE_WARNING 1 |
Referenced by output_alarming().
#define unlikely | ( | x | ) | (x) |
Symbolic call to not-__builtin_expect'ed branch.
Referenced by do_counting(), and parse_config().
comparer_t |
Function pointer holding sort algorithm.
enum color_mode |
enum dhcp_version |
enum limbits |
enum ltype |
enum prefix_t |
Enumeration of interesting data in dhcpd.leases file, that has to be further examined, and saved.
Functions xstrstr_v4() and xstrstr_v6() return one of these values to parse_leases().
void __attribute__ | ( | (noreturn) | ) |
Referenced by set_ipv_functions().
void clean_up | ( | struct conf_t * | state | ) |
Compare two range_t by their current usage.
r1,r2 | Pointers to data to compare. |
Referenced by field_selector().
int comp_double | ( | double | f1, |
double | f2 | ||
) |
Compare two doubles.
f1,f2 | Data to compare. |
Referenced by comp_cur(), comp_max(), comp_percent(), comp_tc(), comp_tcperc(), and comp_touched().
Compare two range_t by their first_ip.
r1,r2 | Pointers to data to compare. |
Referenced by field_selector().
Compare two range_t by their capacity.
r1,r2 | Pointers to data to compare. |
Referenced by field_selector().
Compare two range_t by their current usage percentage.
r1,r2 | Pointers to data to compare. |
Referenced by field_selector().
Compare two range_t by their touched and in use addresses.
r1,r2 | Pointers to data to compare. |
Referenced by field_selector().
Compare two range_t by their touched and in use percentage.
r1,r2 | Pointers to data to compare. |
Referenced by field_selector().
Compare two range_t by their touched addresses.
r1,r2 | Pointers to data to compare. |
Referenced by field_selector().
Referenced by set_ipv_functions().
Referenced by set_ipv_functions().
void delete_all_leases | ( | struct conf_t * | state | ) |
Delete all leases from hash array.
Referenced by clean_up(), and delete_lease().
Delete a lease from hash array.
lease | Pointer to lease hash. |
Referenced by parse_leases().
void do_counting | ( | struct conf_t * | state | ) |
Perform counting.
Join leases with ranges, and update range and shared network counters.
Referenced by main().
void dp_time_tool | ( | FILE * | file, |
const char * | path, | ||
int | epoch | ||
) |
Print a time stamp of a path or now to output file.
Referenced by html_header(), must_put_base(), must_put_range(), must_put_shnet(), and output_json().
comparer_t field_selector | ( | char | c | ) |
Sort field selector.
c | Symbolic name of a sort by character. The sort algorithms are stabile, which means multiple sorts can be specified and they do not mess the result of previous sort. The sort algorithms are used via function pointer, that gets to be reassigned. |
Referenced by parse_command_line_opts().
Referenced by set_ipv_functions().
Referenced by set_ipv_functions().
Referenced by set_ipv_functions().
void flip_ranges | ( | struct conf_t * | state | ) |
Reverse range.
Used before output, if a caller has requested reverse sorting.
Referenced by main().
double get_range_size_init | ( | const struct range_t * | r | ) |
double get_range_size_v4 | ( | const struct range_t * | r | ) |
Referenced by set_ipv_functions().
double get_range_size_v6 | ( | const struct range_t * | r | ) |
Referenced by set_ipv_functions().
Referenced by set_ipv_functions().
Referenced by set_ipv_functions().
Referenced by set_ipv_functions().
int leasecomp_init | ( | const struct leases_t *restrict a | __attribute__(unused), |
const struct leases_t *restrict b | __attribute__(unused) | ||
) |
Compare IP address in leases_t structure, with IPv4/v6 determination.
a | Binary IP address. |
b | Binary IP address. |
Referenced by set_ipv_functions().
Referenced by set_ipv_functions().
Referenced by set_ipv_functions().
int mustach_dhcpd_pools | ( | struct conf_t * | state | ) |
Start mustach processing.
Referenced by output_analysis().
const char* ntop_ipaddr_init | ( | const union ipaddr_t * | ip | ) |
const char* ntop_ipaddr_v4 | ( | const union ipaddr_t * | ip | ) |
Referenced by set_ipv_functions().
const char* ntop_ipaddr_v6 | ( | const union ipaddr_t * | ip | ) |
Referenced by set_ipv_functions().
int output_analysis | ( | struct conf_t * | state, |
const char | output_format | ||
) |
Return output_format_names enum based on single char input.
Referenced by main().
Convert a cidr notated address to a range.
range_p | Pointer to memory where addresses need to be stored. |
word | A range as a cidr string. |
Referenced by parse_config().
int parse_color_mode | ( | const char *restrict | optarg | ) |
Parse option argument color mode.
Color | mode string. |
Referenced by parse_command_line_opts().
void parse_config | ( | struct conf_t * | state, |
const int | is_include, | ||
const char *restrict | config_file, | ||
struct shared_network_t *restrict | shared_p | ||
) |
The dhcpd.conf file parser.
FIXME: This spaghetti monster function needs to be rewrote at least ones more.
Referenced by main().
int parse_ipaddr_init | ( | struct conf_t * | state, |
const char *restrict | src, | ||
union ipaddr_t *restrict | dst | ||
) |
Convert text string IP address from either IPv4 or IPv6 to an integer.
src | An IP string in either format. |
dst | An union which will hold conversion result. |
Referenced by set_ipv_functions().
int parse_ipaddr_v4 | ( | struct conf_t * | state, |
const char *restrict | src, | ||
union ipaddr_t *restrict | dst | ||
) |
int parse_ipaddr_v6 | ( | struct conf_t * | state, |
const char *restrict | src, | ||
union ipaddr_t *restrict | dst | ||
) |
int parse_leases | ( | struct conf_t * | state, |
const int | print_mac_addreses | ||
) |
Lease file parser.
The parser can only read ISC DHCPD dhcpd.leases file format.
Referenced by main().
void prepare_data | ( | struct conf_t * | state | ) |
Prepare data for analysis.
The function will sort leases and ranges.
Referenced by main().
int range_output_helper | ( | struct conf_t * | state, |
struct output_helper_t * | oh, | ||
struct range_t * | range_p | ||
) |
Calculate range percentages and such.
Referenced by must_next_range(), output_alarming(), output_csv(), output_html(), output_json(), output_txt(), and output_xml().
Referenced by prepare_data().
double ret_percent | ( | struct range_t | r | ) |
Percentage in use in range.
r | A range structure. |
Referenced by comp_percent().
double ret_tc | ( | struct range_t | r | ) |
Touched and in use in range.
r | A range structure. |
Referenced by comp_tc(), and ret_tcperc().
double ret_tcperc | ( | struct range_t | r | ) |
Return percentage of addresses touched and in use in range.
r | A range structure. |
Referenced by comp_tcperc().
void set_ipv_functions | ( | struct conf_t * | state, |
int | version | ||
) |
Set function pointers depending on IP version.
ip | IP version. |
Referenced by main(), parse_cidr(), parse_command_line_opts(), parse_ipaddr_init(), and xstrstr_init().
int shnet_output_helper | ( | struct conf_t * | state, |
struct output_helper_t * | oh, | ||
struct shared_network_t * | shared_p | ||
) |
Calculate shared network percentages and such.
Referenced by must_enter(), must_next_shnet(), output_alarming(), output_csv(), output_html(), output_json(), output_txt(), and output_xml().
Return a double floating point value.
str | String to be converted to a double. |
errmesg | Exit error message if conversion fails. |
Referenced by parse_command_line_opts().
Referenced by parse_leases(), and set_ipv_functions().
Referenced by add_lease_v4(), add_lease_v6(), parse_cidr(), parse_config(), and set_ipv_functions().
Referenced by parse_leases(), and set_ipv_functions().
double(* get_range_size) (const struct range_t *r) |
Referenced by comp_max(), do_counting(), range_output_helper(), ret_percent(), ret_tcperc(), and set_ipv_functions().
Referenced by comp_ip(), do_counting(), rangecomp(), reorder_last_first(), and set_ipv_functions().
Referenced by prepare_data(), and set_ipv_functions().
const char*(* ntop_ipaddr) (const union ipaddr_t *ip) |
Referenced by cidr_last_v4(), must_put_range(), output_alarming(), output_csv(), output_html(), output_json(), output_txt(), output_xml(), and set_ipv_functions().
Referenced by parse_cidr(), parse_config(), parse_ipaddr_init(), parse_leases(), and set_ipv_functions().
Referenced by parse_leases(), and set_ipv_functions().