mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-17 08:16:59 +00:00
clean up: move global variables to config structure
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
b59e980cab
commit
d3ee104a59
7 changed files with 21 additions and 25 deletions
|
|
@ -113,7 +113,7 @@ int main(int argc, char **argv)
|
|||
config.output_limit[0] = (*tmp - '0');
|
||||
tmp++;
|
||||
config.output_limit[1] = (*tmp - '0');
|
||||
fullhtml = false;
|
||||
config.fullhtml = false;
|
||||
|
||||
/* Make sure some output format is selected by default */
|
||||
strncpy(config.output_format, OUTPUT_FORMAT, (size_t)1);
|
||||
|
|
@ -215,7 +215,7 @@ int main(int argc, char **argv)
|
|||
break;
|
||||
case 'H':
|
||||
output_analysis = output_html;
|
||||
fullhtml = true;
|
||||
config.fullhtml = true;
|
||||
break;
|
||||
case 'x':
|
||||
output_analysis = output_xml;
|
||||
|
|
@ -270,7 +270,7 @@ int prepare_memory(void)
|
|||
prefix_length[i][j] = strlen(prefixes[i][j]);
|
||||
}
|
||||
}
|
||||
dhcp_version = VERSION_UNKNOWN;
|
||||
config.dhcp_version = VERSION_UNKNOWN;
|
||||
RANGES = 64;
|
||||
num_ranges = num_shared_networks = 0;
|
||||
shared_networks =
|
||||
|
|
|
|||
|
|
@ -95,11 +95,13 @@ enum prefix_t {
|
|||
*/
|
||||
struct configuration_t {
|
||||
char dhcpv6;
|
||||
enum dhcp_version dhcp_version;
|
||||
char *dhcpdconf_file;
|
||||
char *dhcpdlease_file;
|
||||
char output_format[2];
|
||||
bool fullhtml;
|
||||
char sort[6];
|
||||
int reverse_order;
|
||||
bool reverse_order;
|
||||
char *output_file;
|
||||
int output_limit[2];
|
||||
bool backups_found;
|
||||
|
|
@ -150,9 +152,6 @@ struct leases_t {
|
|||
int prefix_length[2][NUM_OF_PREFIX];
|
||||
/* \var config Runtime configuration. */
|
||||
struct configuration_t config;
|
||||
/* \var dhcp_version Version of IP in use.
|
||||
* FIXME: move to runtime configuration. */
|
||||
enum dhcp_version dhcp_version;
|
||||
/* \var output_limit_bit_1 Bit mask what is printed.
|
||||
* FIXME: These should probably be enum with hex assignments. */
|
||||
static int const output_limit_bit_1 = 1;
|
||||
|
|
@ -160,9 +159,6 @@ static int const output_limit_bit_1 = 1;
|
|||
static int const output_limit_bit_2 = 2;
|
||||
/* \var output_limit_bit_3 see output_limit_bit_1 */
|
||||
static int const output_limit_bit_3 = 4;
|
||||
/* \var fullhtml Setting if full html is been requested by user.
|
||||
* FIXME: move to config. */
|
||||
unsigned int fullhtml;
|
||||
/* \var shared_networks Pointer holding shared network count results. */
|
||||
struct shared_network_t *shared_networks;
|
||||
/* \var num_shared_networks Number of shared networks found. */
|
||||
|
|
|
|||
|
|
@ -103,8 +103,8 @@ int parse_leases(void)
|
|||
ethernets = true;
|
||||
}
|
||||
|
||||
const char **p = prefixes[dhcp_version];
|
||||
int *l = prefix_length[dhcp_version];
|
||||
const char **p = prefixes[config.dhcp_version];
|
||||
int *l = prefix_length[config.dhcp_version];
|
||||
|
||||
/*! \def HAS_PREFIX(line, type)
|
||||
* \brief A macro to match IPv4 and IPv6 lease lines.
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ void add_lease(union ipaddr_t *addr, enum ltype type)
|
|||
l = xmalloc(sizeof(struct leases_t));
|
||||
copy_ipaddr(&l->ip, addr);
|
||||
l->type = type;
|
||||
if (dhcp_version == VERSION_6) {
|
||||
if (config.dhcp_version == VERSION_6) {
|
||||
HASH_ADD_V6(leases, ip.v6, l);
|
||||
} else {
|
||||
HASH_ADD_INT(leases, ip.v4, l);
|
||||
|
|
@ -69,7 +69,7 @@ struct leases_t *find_lease(union ipaddr_t *addr)
|
|||
{
|
||||
struct leases_t *l;
|
||||
|
||||
if (dhcp_version == VERSION_6) {
|
||||
if (config.dhcp_version == VERSION_6) {
|
||||
HASH_FIND_V6(leases, &addr->v6, l);
|
||||
} else {
|
||||
HASH_FIND_INT(leases, &addr->v4, l);
|
||||
|
|
|
|||
14
src/other.c
14
src/other.c
|
|
@ -59,18 +59,18 @@
|
|||
int parse_ipaddr(const char *restrict src, union ipaddr_t *restrict dst)
|
||||
{
|
||||
int rv;
|
||||
if (dhcp_version == VERSION_UNKNOWN) {
|
||||
if (config.dhcp_version == VERSION_UNKNOWN) {
|
||||
struct in_addr addr;
|
||||
struct in6_addr addr6;
|
||||
if (inet_aton(src, &addr) == 1) {
|
||||
dhcp_version = VERSION_4;
|
||||
config.dhcp_version = VERSION_4;
|
||||
} else if (inet_pton(AF_INET6, src, &addr6) == 1) {
|
||||
dhcp_version = VERSION_6;
|
||||
config.dhcp_version = VERSION_6;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (dhcp_version == VERSION_6) {
|
||||
if (config.dhcp_version == VERSION_6) {
|
||||
struct in6_addr addr;
|
||||
rv = inet_pton(AF_INET6, src, &addr);
|
||||
memcpy(&dst->v6, addr.s6_addr, sizeof(addr.s6_addr));
|
||||
|
|
@ -89,7 +89,7 @@ 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)
|
||||
{
|
||||
if (dhcp_version == VERSION_6) {
|
||||
if (config.dhcp_version == VERSION_6) {
|
||||
memcpy(&dst->v6, &src->v6, sizeof(src->v6));
|
||||
} else {
|
||||
dst->v4 = src->v4;
|
||||
|
|
@ -108,7 +108,7 @@ const char *ntop_ipaddr(const union ipaddr_t *ip)
|
|||
{
|
||||
static char
|
||||
buffer[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
|
||||
if (dhcp_version == VERSION_6) {
|
||||
if (config.dhcp_version == VERSION_6) {
|
||||
struct in6_addr addr;
|
||||
memcpy(addr.s6_addr, ip->v6, sizeof(addr.s6_addr));
|
||||
return inet_ntop(AF_INET6, &addr, buffer, sizeof(buffer));
|
||||
|
|
@ -127,7 +127,7 @@ const char *ntop_ipaddr(const union ipaddr_t *ip)
|
|||
*/
|
||||
unsigned long get_range_size(const struct range_t *r)
|
||||
{
|
||||
if (dhcp_version == VERSION_6) {
|
||||
if (config.dhcp_version == VERSION_6) {
|
||||
unsigned long size = 0;
|
||||
int i;
|
||||
/* When calculating the size of an IPv6 range overflow may
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ int output_txt(void)
|
|||
struct shared_network_t *shared_p;
|
||||
int ret;
|
||||
FILE *outfile;
|
||||
int max_ipaddr_length = dhcp_version == VERSION_6 ? 39 : 16;
|
||||
int max_ipaddr_length = config.dhcp_version == VERSION_6 ? 39 : 16;
|
||||
|
||||
if (config.output_file[0]) {
|
||||
outfile = fopen(config.output_file, "w+");
|
||||
|
|
@ -695,7 +695,7 @@ int output_html(void)
|
|||
range_p = ranges;
|
||||
range_size = get_range_size(range_p);
|
||||
shared_p = shared_networks;
|
||||
if (fullhtml) {
|
||||
if (config.fullhtml) {
|
||||
html_header(outfile);
|
||||
}
|
||||
table_start(outfile);
|
||||
|
|
@ -845,7 +845,7 @@ int output_html(void)
|
|||
endrow(outfile);
|
||||
}
|
||||
table_end(outfile);
|
||||
if (fullhtml) {
|
||||
if (config.fullhtml) {
|
||||
html_footer(outfile);
|
||||
}
|
||||
if (outfile == stdout) {
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@
|
|||
*/
|
||||
int ipcomp(const union ipaddr_t *restrict a, const union ipaddr_t *restrict b)
|
||||
{
|
||||
if (dhcp_version == VERSION_6) {
|
||||
if (config.dhcp_version == VERSION_6) {
|
||||
return memcmp(&a->v6, &b->v6, sizeof(a->v6));
|
||||
} else {
|
||||
if (a->v4 < b->v4)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue