summaryrefslogtreecommitdiffhomepage
path: root/src/config.c
diff options
context:
space:
mode:
authorDainis Jonitis <dainis.jonitis@ubnt.com>2019-04-12 13:46:43 +0300
committerHans Dedecker <dedeckeh@gmail.com>2019-05-15 10:57:12 +0200
commit41a74cba1bec349d1e1c5be4442e7fddb2d4adf7 (patch)
treec6366d63948eabae512b225c5f149c9306bcee5a /src/config.c
parentc0c8034bc17519c7960f40f6d796b5485cfc4cdb (diff)
config: remove 'ignore' config optionbp
1. Remove 'ignore' config option for interface. Interface is still used if any of 'ra', 'ndp', 'dhcpv4' or 'dhcpv6' options are different from default 'disabled' mode. In config_parse_interface() update runtime ignore value according to all mode values. 2. Reset ignore, ra, ndp, dhcpv4 and dhcpv6 values in set_interface_defaults(). Otherwise if option is deleted from config file and config is reloaded, it will use the value from old config, potentiallly not turning services off. 3. Do not use implicit checks that 0 server mode means MODE_DISABLED. 4. Simplify code of all service setup functions if passed enabled = true argument, but service mode is disabled. Signed-off-by: Dainis Jonitis <dainis.jonitis@ubnt.com> Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c45
1 files changed, 29 insertions, 16 deletions
diff --git a/src/config.c b/src/config.c
index 40f18a4..3f64d16 100644
--- a/src/config.c
+++ b/src/config.c
@@ -40,7 +40,6 @@ enum {
IFACE_ATTR_IFNAME,
IFACE_ATTR_NETWORKID,
IFACE_ATTR_DYNAMICDHCP,
- IFACE_ATTR_IGNORE,
IFACE_ATTR_LEASETIME,
IFACE_ATTR_LIMIT,
IFACE_ATTR_START,
@@ -86,7 +85,6 @@ static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = {
[IFACE_ATTR_IFNAME] = { .name = "ifname", .type = BLOBMSG_TYPE_STRING },
[IFACE_ATTR_NETWORKID] = { .name = "networkid", .type = BLOBMSG_TYPE_STRING },
[IFACE_ATTR_DYNAMICDHCP] = { .name = "dynamicdhcp", .type = BLOBMSG_TYPE_BOOL },
- [IFACE_ATTR_IGNORE] = { .name = "ignore", .type = BLOBMSG_TYPE_BOOL },
[IFACE_ATTR_LEASETIME] = { .name = "leasetime", .type = BLOBMSG_TYPE_STRING },
[IFACE_ATTR_START] = { .name = "start", .type = BLOBMSG_TYPE_INT32 },
[IFACE_ATTR_LIMIT] = { .name = "limit", .type = BLOBMSG_TYPE_INT32 },
@@ -211,6 +209,11 @@ static int mkdir_p(char *dir, mode_t mask)
static void set_interface_defaults(struct interface *iface)
{
+ iface->ignore = true;
+ iface->dhcpv4 = MODE_DISABLED;
+ iface->dhcpv6 = MODE_DISABLED;
+ iface->ra = MODE_DISABLED;
+ iface->ndp = MODE_DISABLED;
iface->learn_routes = 1;
iface->dhcpv4_leasetime = 43200;
iface->dhcpv4_start.s_addr = htonl(START_DEFAULT);
@@ -496,9 +499,6 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
if ((c = tb[IFACE_ATTR_DYNAMICDHCP]))
iface->no_dynamic_dhcp = !blobmsg_get_bool(c);
- if (overwrite && (c = tb[IFACE_ATTR_IGNORE]))
- iface->ignore = blobmsg_get_bool(c);
-
if ((c = tb[IFACE_ATTR_LEASETIME])) {
double time = parse_leasetime(c);
if (time < 0)
@@ -543,32 +543,45 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
int mode;
if ((c = tb[IFACE_ATTR_RA])) {
- if ((mode = parse_mode(blobmsg_get_string(c))) >= 0)
+ if ((mode = parse_mode(blobmsg_get_string(c))) >= 0) {
iface->ra = mode;
- else
+
+ if (iface->ra != MODE_DISABLED)
+ iface->ignore = false;
+ } else
goto err;
}
if ((c = tb[IFACE_ATTR_DHCPV4])) {
if ((mode = parse_mode(blobmsg_get_string(c))) >= 0) {
- if (config.main_dhcpv4)
+ if (config.main_dhcpv4) {
iface->dhcpv4 = mode;
+
+ if (iface->dhcpv4 != MODE_DISABLED)
+ iface->ignore = false;
+ }
}
else
goto err;
}
if ((c = tb[IFACE_ATTR_DHCPV6])) {
- if ((mode = parse_mode(blobmsg_get_string(c))) >= 0)
+ if ((mode = parse_mode(blobmsg_get_string(c))) >= 0) {
iface->dhcpv6 = mode;
- else
+
+ if (iface->dhcpv6 != MODE_DISABLED)
+ iface->ignore = false;
+ } else
goto err;
}
if ((c = tb[IFACE_ATTR_NDP])) {
- if ((mode = parse_mode(blobmsg_get_string(c))) >= 0)
+ if ((mode = parse_mode(blobmsg_get_string(c))) >= 0) {
iface->ndp = mode;
- else
+
+ if (iface->ndp != MODE_DISABLED)
+ iface->ignore = false;
+ } else
goto err;
}
@@ -1067,11 +1080,11 @@ void odhcpd_reload(void)
i->ndp = (master && master->ndp == MODE_RELAY) ?
MODE_RELAY : MODE_DISABLED;
- router_setup_interface(i, !i->ignore || i->ra != MODE_DISABLED);
- dhcpv6_setup_interface(i, !i->ignore || i->dhcpv6 != MODE_DISABLED);
- ndp_setup_interface(i, !i->ignore || i->ndp != MODE_DISABLED);
+ router_setup_interface(i, i->ra != MODE_DISABLED);
+ dhcpv6_setup_interface(i, i->dhcpv6 != MODE_DISABLED);
+ ndp_setup_interface(i, i->ndp != MODE_DISABLED);
#ifdef DHCPV4_SUPPORT
- dhcpv4_setup_interface(i, !i->ignore || i->dhcpv4 != MODE_DISABLED);
+ dhcpv4_setup_interface(i, i->dhcpv4 != MODE_DISABLED);
#endif
} else
close_interface(i);