dhcpd-pools  2.28
ISC dhcpd lease usage analyser
Classes | Macros | Typedefs | Enumerations | Functions | Variables
dhcpd-pools.h File Reference

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>
Include dependency graph for dhcpd-pools.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

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  leases_t
 An individual lease. More...
 
struct  output_sort
 Linked list of sort functions. More...
 
struct  configuration_t
 Runtime configuration. 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_PURE   /* empty */
 
#define _DP_ATTRIBUTE_CONST   /* empty */
 
#define _DP_ATTRIBUTE_HOT   /* empty */
 
#define STATE_OK   0
 Nagios alarm exit values. 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  isc_conf_parser {
  ITS_NOTHING_INTERESTING, ITS_A_RANGE_FIRST_IP, ITS_A_RANGE_SECOND_IP, ITS_A_SHAREDNET,
  ITS_AN_INCLUCE
}
 Configuration file parsing state flags. 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: R_BIT ranges, S_BIT shared networks, A_BIT all. More...
 

Functions

void prepare_memory (void)
 Run time initialization. More...
 
void set_ipv_functions (int version)
 Set function pointers depending on IP version. More...
 
int parse_leases (void)
 Lease file parser. More...
 
void parse_config (int, const char *__restrict, struct shared_network_t *__restrict) __attribute__((nonnull(2
 
void void prepare_data (void)
 Prepare data for analysis. More...
 
void do_counting (void)
 Perform counting. More...
 
void flip_ranges (struct range_t *__restrict ranges, struct range_t *__restrict tmp_ranges) __attribute__((nonnull(1
 
int parse_ipaddr_init (const char *restrict src, union ipaddr_t *restrict dst) _DP_ATTRIBUTE_CONST
 Convert text string IP address from either IPv4 or IPv6 to an integer. More...
 
int parse_ipaddr_v4 (const char *restrict src, union ipaddr_t *restrict dst)
 
int parse_ipaddr_v6 (const char *restrict src, union ipaddr_t *restrict dst)
 
void copy_ipaddr_init (union ipaddr_t *restrict dst, const union ipaddr_t *restrict src) _DP_ATTRIBUTE_CONST
 
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) _DP_ATTRIBUTE_CONST
 
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) _DP_ATTRIBUTE_CONST
 
double get_range_size_v4 (const struct range_t *r) _DP_ATTRIBUTE_PURE
 
double get_range_size_v6 (const struct range_t *r) _DP_ATTRIBUTE_PURE
 
int xstrstr_init (const char *__restrict str) _DP_ATTRIBUTE_CONST
 
int xstrstr_v4 (const char *__restrict str) _DP_ATTRIBUTE_HOT _DP_ATTRIBUTE_PURE
 
int xstrstr_v6 (const char *__restrict str) _DP_ATTRIBUTE_HOT _DP_ATTRIBUTE_PURE
 
double strtod_or_err (const char *__restrict str, const char *__restrict errmesg)
 
void print_version (void) __attribute__((noreturn))
 
void usage (int status) __attribute__((noreturn))
 
int ipcomp_init (const union ipaddr_t *restrict a, const union ipaddr_t *restrict b) _DP_ATTRIBUTE_CONST
 
int ipcomp_v4 (const union ipaddr_t *restrict a, const union ipaddr_t *restrict b) _DP_ATTRIBUTE_PURE
 
int ipcomp_v6 (const union ipaddr_t *restrict a, const union ipaddr_t *restrict b) _DP_ATTRIBUTE_PURE
 
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 comp_cur (struct range_t *r1, struct range_t *r2) _DP_ATTRIBUTE_PURE
 Compare two range_t by their current usage. More...
 
int comp_double (double f1, double f2) _DP_ATTRIBUTE_CONST
 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) _DP_ATTRIBUTE_PURE
 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) _DP_ATTRIBUTE_PURE
 Compare two range_t by their touched addresses. More...
 
int rangecomp (const void *__restrict r1, const void *__restrict r2) __attribute__((nonnull(1
 
int 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) _DP_ATTRIBUTE_CONST
 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...
 
void mergesort_ranges (struct range_t *__restrict orig, int size, struct range_t *__restrict temp) __attribute__((nonnull(1
 
int output_txt (void)
 Text output format, which is the default. More...
 
int output_html (void)
 Output html format. More...
 
int output_xml (void)
 The xml output formats. More...
 
int output_json (void)
 The json output formats. More...
 
int output_csv (void)
 Output cvs format. More...
 
int output_alarming (void)
 Output alarm text, and return program exit value. More...
 
void clean_up (void)
 Free memory, flush buffers etc. More...
 
void add_lease_init (union ipaddr_t *ip, enum ltype type) _DP_ATTRIBUTE_CONST
 
void add_lease_v4 (union ipaddr_t *ip, enum ltype type)
 
void add_lease_v6 (union ipaddr_t *ip, enum ltype type)
 
struct leases_tfind_lease_init (union ipaddr_t *ip) _DP_ATTRIBUTE_CONST
 
struct leases_tfind_lease_v4 (union ipaddr_t *ip) _DP_ATTRIBUTE_PURE
 
struct leases_tfind_lease_v6 (union ipaddr_t *ip) _DP_ATTRIBUTE_PURE
 
void delete_lease (struct leases_t *lease)
 Delete a lease from hash array. More...
 
void delete_all_leases (void)
 Delete all leases from hash array. More...
 

Variables

int prefix_length [2][NUM_OF_PREFIX]
 
struct configuration_t config
 
struct shared_network_tshared_networks
 
unsigned int num_shared_networks
 
struct range_tranges
 
unsigned int num_ranges
 
struct leases_tleases
 
unsigned int RANGES
 
void int(* parse_ipaddr )(const char *restrict src, union ipaddr_t *restrict dst)
 
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(* xstrstr )(const char *__restrict str)
 
int(* ipcomp )(const union ipaddr_t *restrict a, const union ipaddr_t *restrict b)
 
int(* leasecomp )(const struct leases_t *restrict a, const struct leases_t *restrict b)
 
void int(* output_analysis )(void)
 
void(* add_lease )(union ipaddr_t *ip, enum ltype type)
 
struct leases_t *(* find_lease )(union ipaddr_t *ip)
 

Detailed Description

Global definitions of structures, enums, and function prototypes.

FIXME: The file has too many global variables. Most of them should be removed, if not all.

Macro Definition Documentation

#define _DP_ATTRIBUTE_CONST   /* empty */
#define _DP_ATTRIBUTE_HOT   /* empty */
#define _DP_ATTRIBUTE_PURE   /* empty */
#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 values.

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 parse_config().

Typedef Documentation

comparer_t

Function pointer holding sort algorithm.

Enumeration Type Documentation

The IP version, IPv4 or IPv6, served by the dhcpd.

Enumerator
IPvUNKNOWN 
IPv4 
IPv6 

Configuration file parsing state flags.

Enumerator
ITS_NOTHING_INTERESTING 
ITS_A_RANGE_FIRST_IP 
ITS_A_RANGE_SECOND_IP 
ITS_A_SHAREDNET 
ITS_AN_INCLUCE 
enum limbits

Output limit bits: R_BIT ranges, S_BIT shared networks, A_BIT all.

Enumerator
R_BIT 
S_BIT 
A_BIT 
enum ltype

Lease state types.

Enumerator
ACTIVE 
FREE 
BACKUP 
enum prefix_t

Enumeration of interesting data in dhcpd.leases file, that has to be further examined, and saved.

Enumerator
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 

Function Documentation

void add_lease_init ( union ipaddr_t ip,
enum ltype  type 
)

Referenced by set_ipv_functions().

void add_lease_v4 ( union ipaddr_t ip,
enum ltype  type 
)

Referenced by set_ipv_functions().

Here is the call graph for this function:

void add_lease_v6 ( union ipaddr_t ip,
enum ltype  type 
)

Referenced by set_ipv_functions().

Here is the call graph for this function:

void clean_up ( void  )

Free memory, flush buffers etc.

Referenced by field_selector(), main(), and return_limit().

Here is the call graph for this function:

int comp_cur ( struct range_t r1,
struct range_t r2 
)

Compare two range_t by their current usage.

Parameters
r1,r2Pointers to data to compare.
Returns
Like strcmp.

Referenced by field_selector().

Here is the call graph for this function:

int comp_double ( double  f1,
double  f2 
)

Compare two doubles.

Parameters
f1,f2Data to compare.
Returns
Like strcmp.

Referenced by comp_cur(), comp_max(), comp_percent(), comp_tc(), comp_tcperc(), and comp_touched().

int comp_ip ( struct range_t r1,
struct range_t r2 
)

Compare two range_t by their first_ip.

Parameters
r1,r2Pointers to data to compare.
Returns
Like strcmp.

Referenced by field_selector().

int comp_max ( struct range_t r1,
struct range_t r2 
)

Compare two range_t by their capacity.

Parameters
r1,r2Pointers to data to compare.
Returns
Like strcmp.

Referenced by field_selector().

Here is the call graph for this function:

int comp_percent ( struct range_t r1,
struct range_t r2 
)

Compare two range_t by their current usage percentage.

Parameters
r1,r2Pointers to data to compare.
Returns
Like strcmp.

Referenced by field_selector().

Here is the call graph for this function:

int comp_tc ( struct range_t r1,
struct range_t r2 
)

Compare two range_t by their touched and in use addresses.

Parameters
r1,r2Pointers to data to compare.
Returns
Like strcmp.

Referenced by field_selector().

Here is the call graph for this function:

int comp_tcperc ( struct range_t r1,
struct range_t r2 
)

Compare two range_t by their touched and in use percentage.

Parameters
r1,r2Pointers to data to compare.
Returns
Like strcmp.

Referenced by field_selector().

Here is the call graph for this function:

int comp_touched ( struct range_t r1,
struct range_t r2 
)

Compare two range_t by their touched addresses.

Parameters
r1,r2Pointers to data to compare.
Returns
Like strcmp.

Referenced by field_selector().

Here is the call graph for this function:

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 
)

Referenced by set_ipv_functions().

void copy_ipaddr_v6 ( union ipaddr_t *restrict  dst,
const union ipaddr_t *restrict  src 
)

Referenced by set_ipv_functions().

void delete_all_leases ( void  )

Delete all leases from hash array.

Referenced by clean_up().

void delete_lease ( struct leases_t lease)

Delete a lease from hash array.

Parameters
leasePointer to lease hash.

Referenced by parse_leases().

void do_counting ( void  )

Perform counting.

Join leases with ranges, and update counters.

Referenced by main().

int comparer_t field_selector ( char  c)

Sort field selector.

Parameters
cSymbolic 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.
Returns
Return the selected compare function.

Referenced by main().

Here is the call graph for this function:

struct leases_t* find_lease_init ( union ipaddr_t ip)

Referenced by set_ipv_functions().

struct leases_t* find_lease_v4 ( union ipaddr_t ip)

Referenced by set_ipv_functions().

struct leases_t* find_lease_v6 ( union ipaddr_t ip)

Referenced by set_ipv_functions().

void flip_ranges ( struct range_t *__restrict  ranges,
struct range_t *__restrict  tmp_ranges 
)

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().

int ipcomp_init ( const union ipaddr_t *restrict  a,
const union ipaddr_t *restrict  b 
)

Referenced by set_ipv_functions().

int ipcomp_v4 ( const union ipaddr_t *restrict  a,
const union ipaddr_t *restrict  b 
)

Referenced by set_ipv_functions().

int ipcomp_v6 ( const union ipaddr_t *restrict  a,
const union ipaddr_t *restrict  b 
)

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.

Parameters
aBinary IP address.
bBinary IP address.
Returns
If a < b return -1, if a < b return 1, when they are equal return 0.

Referenced by set_ipv_functions().

int leasecomp_v4 ( const struct leases_t *restrict  a,
const struct leases_t *restrict  b 
)

Referenced by set_ipv_functions().

int leasecomp_v6 ( const struct leases_t *restrict  a,
const struct leases_t *restrict  b 
)

Referenced by set_ipv_functions().

void mergesort_ranges ( struct range_t *__restrict  orig,
int  size,
struct range_t *__restrict  temp 
)

Referenced by main().

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_alarming ( void  )

Output alarm text, and return program exit value.

Referenced by main().

Here is the call graph for this function:

int output_csv ( void  )

Output cvs format.

Referenced by main().

Here is the call graph for this function:

int output_html ( void  )

Output html format.

Referenced by main().

Here is the call graph for this function:

int output_json ( void  )

The json output formats.

Referenced by main().

Here is the call graph for this function:

int output_txt ( void  )

Text output format, which is the default.

Referenced by main().

Here is the call graph for this function:

int output_xml ( void  )

The xml output formats.

Referenced by main().

Here is the call graph for this function:

void parse_config ( int  ,
const char *  __restrict,
struct shared_network_t __restrict 
)

Referenced by main().

int parse_ipaddr_init ( const char *restrict  src,
union ipaddr_t *restrict  dst 
)

Convert text string IP address from either IPv4 or IPv6 to an integer.

Parameters
srcAn IP string in either format.
dstAn union which will hold conversion result.
Returns
Was parsing successful.

Referenced by set_ipv_functions().

Here is the call graph for this function:

int parse_ipaddr_v4 ( const char *restrict  src,
union ipaddr_t *restrict  dst 
)

Referenced by set_ipv_functions().

int parse_ipaddr_v6 ( const char *restrict  src,
union ipaddr_t *restrict  dst 
)

Referenced by set_ipv_functions().

Here is the call graph for this function:

int parse_leases ( void  )

Lease file parser.

The parser can only read ISC DHCPD dhcpd.leases file format.

Referenced by main().

Here is the call graph for this function:

void void prepare_data ( void  )

Prepare data for analysis.

The function will sort leases and ranges.

Referenced by main().

Here is the call graph for this function:

void prepare_memory ( void  )

Run time initialization.

Global allocations, counter initializations, etc are here.

Referenced by main().

Here is the call graph for this function:

void print_version ( void  )

Referenced by main().

int rangecomp ( const void *__restrict  r1,
const void *__restrict  r2 
)

Referenced by prepare_data().

double ret_percent ( struct range_t  r)

Percentage in use in range.

Parameters
rA range structure.
Returns
Usage percentage of the given range.

Referenced by comp_percent().

double ret_tc ( struct range_t  r)

Touched and in use in range.

Parameters
rA range structure.
Returns
Number of touched or in use addresses in the given range.

Referenced by comp_tc(), and ret_tcperc().

double ret_tcperc ( struct range_t  r)

Return percentage of addresses touched and in use in range.

Parameters
rA range structure.
Returns
Percentage of touched or in use addresses in the given range.

Referenced by comp_tcperc().

Here is the call graph for this function:

void set_ipv_functions ( int  version)

Set function pointers depending on IP version.

Parameters
ipIP version.

Referenced by main(), parse_ipaddr_init(), and xstrstr_init().

Here is the call graph for this function:

double strtod_or_err ( const char *__restrict  str,
const char *__restrict  errmesg 
)

Referenced by main().

void usage ( int  status)

Referenced by main().

int xstrstr_init ( const char *__restrict  str)
int xstrstr_v4 ( const char *__restrict  str)
int xstrstr_v6 ( const char *__restrict  str)

Variable Documentation

void(* add_lease) (union ipaddr_t *ip, enum ltype type)

Referenced by parse_leases(), and set_ipv_functions().

struct configuration_t config
void(* copy_ipaddr) (union ipaddr_t *restrict dst, const union ipaddr_t *restrict src)
struct leases_t*(* find_lease) (union ipaddr_t *ip)

Referenced by parse_leases(), and set_ipv_functions().

double(* get_range_size) (const struct range_t *r)
int(* ipcomp) (const union ipaddr_t *restrict a, const union ipaddr_t *restrict b)
int(* leasecomp) (const struct leases_t *restrict a, const struct leases_t *restrict b)

Referenced by prepare_data(), and set_ipv_functions().

struct leases_t* leases
const char*(* ntop_ipaddr) (const union ipaddr_t *ip)
unsigned int num_ranges
unsigned int num_shared_networks
void int(* output_analysis) (void)

Referenced by main().

void int(* parse_ipaddr) (const char *restrict src, union ipaddr_t *restrict dst)
int prefix_length[2][NUM_OF_PREFIX]
struct range_t* ranges
unsigned int RANGES

Referenced by parse_config(), and prepare_memory().

struct shared_network_t* shared_networks
int(* xstrstr) (const char *__restrict str)

Referenced by parse_leases(), and set_ipv_functions().