| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
#ifndef DHCPD_POOLS_H |
| 41 |
# define DHCPD_POOLS_H 1 |
| 42 |
|
| 43 |
# include <config.h> |
| 44 |
# include <arpa/inet.h> |
| 45 |
# include <stddef.h> |
| 46 |
# include <stdio.h> |
| 47 |
# include <string.h> |
| 48 |
# include <uthash.h> |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
# ifdef HAVE_BUILTIN_EXPECT |
| 57 |
# define likely(x) __builtin_expect(!!(x), 1) |
| 58 |
# define unlikely(x) __builtin_expect(!!(x), 0) |
| 59 |
# else |
| 60 |
# define likely(x) (x) |
| 61 |
# define unlikely(x) (x) |
| 62 |
# endif |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) |
| 70 |
# define _DP_ATTRIBUTE_HOT __attribute__ ((__hot__)) |
| 71 |
# else |
| 72 |
# define _DP_ATTRIBUTE_HOT |
| 73 |
# endif |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
union ipaddr_t { |
| 78 |
uint32_t v4; |
| 79 |
unsigned char v6[16]; |
| 80 |
}; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
enum dhcp_version { |
| 86 |
IPvUNKNOWN, |
| 87 |
IPv4, |
| 88 |
IPv6 |
| 89 |
}; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
enum prefix_t { |
| 97 |
PREFIX_LEASE, |
| 98 |
PREFIX_BINDING_STATE_FREE, |
| 99 |
PREFIX_BINDING_STATE_ABANDONED, |
| 100 |
PREFIX_BINDING_STATE_EXPIRED, |
| 101 |
PREFIX_BINDING_STATE_RELEASED, |
| 102 |
PREFIX_BINDING_STATE_ACTIVE, |
| 103 |
PREFIX_BINDING_STATE_BACKUP, |
| 104 |
PREFIX_HARDWARE_ETHERNET, |
| 105 |
NUM_OF_PREFIX |
| 106 |
}; |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
enum color_mode { |
| 112 |
color_unknown, |
| 113 |
color_off, |
| 114 |
color_on, |
| 115 |
color_auto |
| 116 |
}; |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
struct shared_network_t { |
| 123 |
char *name; |
| 124 |
double available; |
| 125 |
double used; |
| 126 |
double touched; |
| 127 |
double backups; |
| 128 |
struct shared_network_t *next; |
| 129 |
int netmask; |
| 130 |
}; |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
struct range_t { |
| 136 |
struct shared_network_t *shared_net; |
| 137 |
union ipaddr_t first_ip; |
| 138 |
union ipaddr_t last_ip; |
| 139 |
double count; |
| 140 |
double touched; |
| 141 |
double backups; |
| 142 |
}; |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
struct output_helper_t { |
| 148 |
double range_size; |
| 149 |
double percent; |
| 150 |
double tc; |
| 151 |
double tcp; |
| 152 |
double bup; |
| 153 |
int status; |
| 154 |
}; |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
struct status_counts_t { |
| 160 |
unsigned int warning; |
| 161 |
unsigned int critical; |
| 162 |
unsigned int ok; |
| 163 |
unsigned int ignored; |
| 164 |
}; |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
enum ltype { |
| 170 |
ACTIVE, |
| 171 |
FREE, |
| 172 |
BACKUP |
| 173 |
}; |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
struct leases_t { |
| 179 |
union ipaddr_t ip; |
| 180 |
char *ethernet; |
| 181 |
UT_hash_handle hh; |
| 182 |
enum ltype type; |
| 183 |
}; |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
enum limbits { |
| 189 |
R_BIT = (1 << 0), |
| 190 |
S_BIT = (1 << 1), |
| 191 |
A_BIT = (1 << 2) |
| 192 |
}; |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
# define STATE_OK 0 |
| 198 |
# define STATE_WARNING 1 |
| 199 |
# define STATE_CRITICAL 2 |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
typedef int (*comparer_t) (struct range_t *r1, struct range_t *r2); |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
struct output_sort { |
| 210 |
comparer_t func; |
| 211 |
struct output_sort *next; |
| 212 |
}; |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
struct conf_t { |
| 218 |
struct shared_network_t *shared_net_root; |
| 219 |
struct shared_network_t *shared_net_head; |
| 220 |
struct range_t *ranges; |
| 221 |
unsigned int num_ranges; |
| 222 |
enum dhcp_version ip_version; |
| 223 |
size_t ranges_size; |
| 224 |
struct leases_t *leases; |
| 225 |
const char *dhcpdconf_file; |
| 226 |
const char *dhcpdlease_file; |
| 227 |
struct output_sort *sorts; |
| 228 |
const char *output_file; |
| 229 |
const char *mustach_template; |
| 230 |
double warning; |
| 231 |
double critical; |
| 232 |
double warn_count; |
| 233 |
double crit_count; |
| 234 |
double minsize; |
| 235 |
int color_format; |
| 236 |
char output_format; |
| 237 |
uint32_t |
| 238 |
print_mac_addreses:1, |
| 239 |
reverse_order:1, |
| 240 |
backups_found:1, |
| 241 |
snet_alarms:1, |
| 242 |
perfdata:1, |
| 243 |
all_as_shared:1, |
| 244 |
header_limit:4, |
| 245 |
number_limit:3, |
| 246 |
skip_ok:1, |
| 247 |
skip_warning:1, |
| 248 |
skip_critical:1, |
| 249 |
skip_minsize:1, |
| 250 |
skip_suppressed:1, |
| 251 |
color_mode:2; |
| 252 |
}; |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
extern void prepare_data(struct conf_t *state); |
| 258 |
extern void do_counting(struct conf_t *state); |
| 259 |
|
| 260 |
|
| 261 |
extern int parse_leases(struct conf_t *state); |
| 262 |
extern void parse_config(struct conf_t *state, const int is_include, |
| 263 |
const char *restrict config_file, |
| 264 |
struct shared_network_t *restrict shared_p); |
| 265 |
|
| 266 |
|
| 267 |
extern void (*add_lease) (struct conf_t *state, union ipaddr_t *addr, enum ltype type); |
| 268 |
extern void add_lease_init(struct conf_t *state, union ipaddr_t *addr, enum ltype type); |
| 269 |
extern void add_lease_v4(struct conf_t *state, union ipaddr_t *addr, enum ltype type); |
| 270 |
extern void add_lease_v6(struct conf_t *state, union ipaddr_t *addr, enum ltype type); |
| 271 |
|
| 272 |
extern struct leases_t *(*find_lease) (struct conf_t *state, union ipaddr_t *addr); |
| 273 |
extern struct leases_t *find_lease_init(struct conf_t *state, union ipaddr_t *addr); |
| 274 |
extern struct leases_t *find_lease_v4(struct conf_t *state, union ipaddr_t *addr); |
| 275 |
extern struct leases_t *find_lease_v6(struct conf_t *state, union ipaddr_t *addr); |
| 276 |
|
| 277 |
extern void delete_lease(struct conf_t *state, struct leases_t *lease); |
| 278 |
extern void delete_all_leases(struct conf_t *state); |
| 279 |
|
| 280 |
|
| 281 |
extern int mustach_dhcpd_pools(struct conf_t *state); |
| 282 |
|
| 283 |
|
| 284 |
extern void set_ipv_functions(struct conf_t *state, int version); |
| 285 |
extern void flip_ranges(struct conf_t *state); |
| 286 |
extern void clean_up(struct conf_t *state); |
| 287 |
extern void parse_cidr(struct conf_t *state, struct range_t *range_p, const char *word); |
| 288 |
extern int parse_color_mode(const char *restrict arg); |
| 289 |
extern double strtod_or_err(const char *restrict str, const char *restrict errmesg); |
| 290 |
extern void __attribute__ ((noreturn)) print_version(void); |
| 291 |
extern void __attribute__ ((noreturn)) usage(int status); |
| 292 |
extern void dp_time_tool(FILE *file, const char *path, int epoch); |
| 293 |
|
| 294 |
extern int (*parse_ipaddr) (struct conf_t *state, const char *restrict src, |
| 295 |
union ipaddr_t *restrict dst); |
| 296 |
extern int parse_ipaddr_init(struct conf_t *state, const char *restrict src, |
| 297 |
union ipaddr_t *restrict dst); |
| 298 |
extern int parse_ipaddr_v4(struct conf_t *state, const char *restrict src, |
| 299 |
union ipaddr_t *restrict dst); |
| 300 |
extern int parse_ipaddr_v6(struct conf_t *state, const char *restrict src, |
| 301 |
union ipaddr_t *restrict dst); |
| 302 |
|
| 303 |
extern int (*xstrstr) (struct conf_t *state, const char *restrict str); |
| 304 |
extern int xstrstr_init(struct conf_t *state, const char *restrict str); |
| 305 |
extern int xstrstr_v4(struct conf_t *state, const char *restrict str); |
| 306 |
extern int xstrstr_v6(struct conf_t *state, const char *restrict str); |
| 307 |
|
| 308 |
extern void (*copy_ipaddr) (union ipaddr_t *restrict dst, const union ipaddr_t *restrict src); |
| 309 |
extern void copy_ipaddr_init(union ipaddr_t *restrict dst, const union ipaddr_t *restrict src); |
| 310 |
extern void copy_ipaddr_v4(union ipaddr_t *restrict dst, const union ipaddr_t *restrict src); |
| 311 |
extern void copy_ipaddr_v6(union ipaddr_t *restrict dst, const union ipaddr_t *restrict src); |
| 312 |
|
| 313 |
extern const char *(*ntop_ipaddr) (const union ipaddr_t *ip); |
| 314 |
extern const char *ntop_ipaddr_init(const union ipaddr_t *ip); |
| 315 |
extern const char *ntop_ipaddr_v4(const union ipaddr_t *ip); |
| 316 |
extern const char *ntop_ipaddr_v6(const union ipaddr_t *ip); |
| 317 |
|
| 318 |
extern double (*get_range_size) (const struct range_t *r); |
| 319 |
extern double get_range_size_init(const struct range_t *r); |
| 320 |
extern double get_range_size_v4(const struct range_t *r); |
| 321 |
extern double get_range_size_v6(const struct range_t *r); |
| 322 |
|
| 323 |
|
| 324 |
extern int range_output_helper(struct conf_t *state, struct output_helper_t *oh, |
| 325 |
struct range_t *range_p); |
| 326 |
extern int shnet_output_helper(struct conf_t *state, struct output_helper_t *oh, |
| 327 |
struct shared_network_t *shared_p); |
| 328 |
extern int output_analysis(struct conf_t *state); |
| 329 |
extern void range_alarms(struct conf_t *state, struct status_counts_t *rangstat); |
| 330 |
extern void shared_net_alarms(struct conf_t *state, struct status_counts_t *sharstat); |
| 331 |
|
| 332 |
|
| 333 |
extern void mergesort_ranges(struct conf_t *state, |
| 334 |
struct range_t *restrict orig, unsigned int size, |
| 335 |
struct range_t *restrict temp, const int root_call); |
| 336 |
|
| 337 |
extern int (*leasecomp) (const struct leases_t *restrict a, const struct leases_t *restrict b); |
| 338 |
extern int leasecomp_init(const struct leases_t *restrict a |
| 339 |
__attribute__ ((unused)), |
| 340 |
const struct leases_t *restrict b __attribute__ ((unused))); |
| 341 |
extern int leasecomp_v4(const struct leases_t *restrict a, const struct leases_t *restrict b); |
| 342 |
extern int leasecomp_v6(const struct leases_t *restrict a, const struct leases_t *restrict b); |
| 343 |
|
| 344 |
extern int (*ipcomp) (const union ipaddr_t *restrict a, const union ipaddr_t *restrict b); |
| 345 |
extern int ipcomp_init(const union ipaddr_t *restrict a, const union ipaddr_t *restrict b); |
| 346 |
extern int ipcomp_v4(const union ipaddr_t *restrict a, const union ipaddr_t *restrict b); |
| 347 |
extern int ipcomp_v6(const union ipaddr_t *restrict a, const union ipaddr_t *restrict b); |
| 348 |
|
| 349 |
extern int rangecomp(const void *restrict r1, const void *restrict r2) |
| 350 |
__attribute__ ((nonnull(1, 2))); |
| 351 |
|
| 352 |
extern int comp_cur(struct range_t *r1, struct range_t *r2); |
| 353 |
extern int comp_double(double f1, double f2); |
| 354 |
extern int comp_ip(struct range_t *r1, struct range_t *r2); |
| 355 |
extern int comp_max(struct range_t *r1, struct range_t *r2); |
| 356 |
extern int comp_percent(struct range_t *r1, struct range_t *r2); |
| 357 |
extern int comp_tc(struct range_t *r1, struct range_t *r2); |
| 358 |
extern int comp_tcperc(struct range_t *r1, struct range_t *r2); |
| 359 |
extern int comp_touched(struct range_t *r1, struct range_t *r2); |
| 360 |
|
| 361 |
extern comparer_t field_selector(char c); |
| 362 |
extern double ret_percent(struct range_t r); |
| 363 |
extern double ret_tc(struct range_t r); |
| 364 |
extern double ret_tcperc(struct range_t r); |
| 365 |
|
| 366 |
#endif |