2020-09-14 23:15:18 +00:00
|
|
|
/*
|
|
|
|
* libifupdown/config-file.c
|
|
|
|
* Purpose: config file loading
|
|
|
|
*
|
|
|
|
* Copyright (c) 2020 Ariadne Conill <ariadne@dereferenced.org>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* This software is provided 'as is' and without any warranty, express or
|
|
|
|
* implied. In no event shall the authors be liable for any damages arising
|
|
|
|
* from the use of this software.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "libifupdown/libifupdown.h"
|
|
|
|
|
|
|
|
struct lif_config_file lif_config = {
|
|
|
|
.allow_addon_scripts = true,
|
2020-09-23 17:34:35 +00:00
|
|
|
.allow_any_iface_as_template = true,
|
2020-11-04 18:16:47 +00:00
|
|
|
.auto_executor_selection = true,
|
2020-10-18 03:14:03 +00:00
|
|
|
.compat_create_interfaces = true,
|
2020-10-18 02:58:23 +00:00
|
|
|
.compat_ifupdown2_bridge_ports_inherit_vlans = true,
|
2020-09-24 21:36:22 +00:00
|
|
|
.implicit_template_conversion = true,
|
2020-10-14 11:15:58 +00:00
|
|
|
.use_hostname_for_dhcp = true,
|
2020-09-14 23:15:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
set_bool_value(const char *key, const char *value, void *opaque)
|
|
|
|
{
|
|
|
|
(void) key;
|
|
|
|
|
|
|
|
if (*value == '1' ||
|
2020-10-18 02:58:23 +00:00
|
|
|
*value == 'Y' || *value == 'y' ||
|
2020-09-14 23:15:18 +00:00
|
|
|
*value == 'T' || *value == 't')
|
|
|
|
*(bool *) opaque = true;
|
|
|
|
else if (*value == '0' ||
|
|
|
|
*value == 'N' || *value == 'n' ||
|
|
|
|
*value == 'F' || *value == 'f')
|
|
|
|
*(bool *) opaque = false;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct lif_config_handler handlers[] = {
|
|
|
|
{"allow_addon_scripts", set_bool_value, &lif_config.allow_addon_scripts},
|
2020-09-23 17:34:35 +00:00
|
|
|
{"allow_any_iface_as_template", set_bool_value, &lif_config.allow_any_iface_as_template},
|
2020-11-04 18:16:47 +00:00
|
|
|
{"auto_executor_selection", set_bool_value, &lif_config.auto_executor_selection},
|
2020-10-18 03:14:03 +00:00
|
|
|
{"compat_create_interfaces", set_bool_value, &lif_config.compat_create_interfaces},
|
2020-10-18 02:58:23 +00:00
|
|
|
{"compat_ifupdown2_bridge_ports_inherit_vlans", set_bool_value, &lif_config.compat_ifupdown2_bridge_ports_inherit_vlans},
|
2020-09-24 01:07:52 +00:00
|
|
|
{"implicit_template_conversion", set_bool_value, &lif_config.implicit_template_conversion},
|
2020-10-14 11:15:58 +00:00
|
|
|
{"use_hostname_for_dhcp", set_bool_value, &lif_config.use_hostname_for_dhcp},
|
2020-09-14 23:15:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
bool
|
|
|
|
lif_config_load(const char *filename)
|
|
|
|
{
|
|
|
|
FILE *fd = fopen(filename, "r");
|
|
|
|
|
|
|
|
if (fd == NULL)
|
|
|
|
{
|
2020-09-14 23:17:03 +00:00
|
|
|
#if 0
|
2020-09-14 23:15:18 +00:00
|
|
|
fprintf(stderr, "ifupdown-ng: cannot open config %s: %s\n",
|
|
|
|
filename, strerror(errno));
|
2020-09-14 23:17:03 +00:00
|
|
|
#endif
|
2020-09-14 23:15:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lif_config_parse_file(fd, filename, handlers, ARRAY_SIZE(handlers));
|
|
|
|
}
|