summaryrefslogtreecommitdiffhomepage
path: root/src
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
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')
-rw-r--r--src/config.c45
-rw-r--r--src/dhcpv4.c6
-rw-r--r--src/dhcpv6-ia.c19
-rw-r--r--src/dhcpv6.c4
-rw-r--r--src/ndp.c6
-rw-r--r--src/router.c8
6 files changed, 55 insertions, 33 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);
diff --git a/src/dhcpv4.c b/src/dhcpv4.c
index 2634f65..34d925c 100644
--- a/src/dhcpv4.c
+++ b/src/dhcpv4.c
@@ -77,13 +77,15 @@ int dhcpv4_setup_interface(struct interface *iface, bool enable)
{
int ret = 0;
+ enable = enable && (iface->dhcpv4 != MODE_DISABLED);
+
if (iface->dhcpv4_event.uloop.fd >= 0) {
uloop_fd_delete(&iface->dhcpv4_event.uloop);
close(iface->dhcpv4_event.uloop.fd);
iface->dhcpv4_event.uloop.fd = -1;
}
- if (iface->dhcpv4 && enable) {
+ if (enable) {
struct sockaddr_in bind_addr = {AF_INET, htons(DHCPV4_SERVER_PORT),
{INADDR_ANY}, {0}};
int val = 1;
@@ -592,7 +594,7 @@ static void handle_dhcpv4(void *addr, void *data, size_t len,
{
struct dhcpv4_message *req = data;
- if (!iface->dhcpv4)
+ if (iface->dhcpv4 == MODE_DISABLED)
return;
if (len < offsetof(struct dhcpv4_message, options) + 4 ||
diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c
index 9559b96..c0dfa2d 100644
--- a/src/dhcpv6-ia.c
+++ b/src/dhcpv6-ia.c
@@ -62,16 +62,9 @@ int dhcpv6_ia_init(void)
int dhcpv6_ia_setup_interface(struct interface *iface, bool enable)
{
- if (!enable) {
- struct dhcp_assignment *c;
-
- while (!list_empty(&iface->ia_assignments)) {
- c = list_first_entry(&iface->ia_assignments, struct dhcp_assignment, head);
- free_assignment(c);
- }
- }
+ enable = enable && (iface->dhcpv6 == MODE_SERVER);
- if (enable && iface->dhcpv6 == MODE_SERVER) {
+ if (enable) {
struct dhcp_assignment *border;
if (list_empty(&iface->ia_assignments)) {
@@ -88,7 +81,15 @@ int dhcpv6_ia_setup_interface(struct interface *iface, bool enable)
border = list_last_entry(&iface->ia_assignments, struct dhcp_assignment, head);
set_border_assignment_size(iface, border);
+ } else {
+ struct dhcp_assignment *c;
+
+ while (!list_empty(&iface->ia_assignments)) {
+ c = list_first_entry(&iface->ia_assignments, struct dhcp_assignment, head);
+ free_assignment(c);
+ }
}
+
return 0;
}
diff --git a/src/dhcpv6.c b/src/dhcpv6.c
index f71418d..c61a8aa 100644
--- a/src/dhcpv6.c
+++ b/src/dhcpv6.c
@@ -47,6 +47,8 @@ int dhcpv6_setup_interface(struct interface *iface, bool enable)
{
int ret = 0;
+ enable = enable && (iface->dhcpv6 != MODE_DISABLED);
+
if (iface->dhcpv6_event.uloop.fd >= 0) {
uloop_fd_delete(&iface->dhcpv6_event.uloop);
close(iface->dhcpv6_event.uloop.fd);
@@ -54,7 +56,7 @@ int dhcpv6_setup_interface(struct interface *iface, bool enable)
}
/* Configure multicast settings */
- if (enable && iface->dhcpv6) {
+ if (enable) {
struct sockaddr_in6 bind_addr = {AF_INET6, htons(DHCPV6_SERVER_PORT),
0, IN6ADDR_ANY_INIT, 0};
struct ipv6_mreq mreq;
diff --git a/src/ndp.c b/src/ndp.c
index 64a6c1c..aaaa69c 100644
--- a/src/ndp.c
+++ b/src/ndp.c
@@ -71,6 +71,8 @@ int ndp_setup_interface(struct interface *iface, bool enable)
bool dump_neigh = false;
char procbuf[64];
+ enable = enable && (iface->ndp == MODE_RELAY);
+
snprintf(procbuf, sizeof(procbuf), "/proc/sys/net/ipv6/conf/%s/proxy_ndp", iface->ifname);
procfd = open(procbuf, O_WRONLY);
@@ -89,13 +91,13 @@ int ndp_setup_interface(struct interface *iface, bool enable)
close(iface->ndp_event.uloop.fd);
iface->ndp_event.uloop.fd = -1;
- if (!enable || iface->ndp != MODE_RELAY)
+ if (!enable)
if (write(procfd, "0\n", 2) < 0) {}
dump_neigh = true;
}
- if (enable && iface->ndp == MODE_RELAY) {
+ if (enable) {
struct sockaddr_ll ll;
struct packet_mreq mreq;
struct icmp6_filter filt;
diff --git a/src/router.c b/src/router.c
index 3a6b121..63571a3 100644
--- a/src/router.c
+++ b/src/router.c
@@ -74,13 +74,15 @@ int router_setup_interface(struct interface *iface, bool enable)
{
int ret = 0;
+ enable = enable && (iface->ra != MODE_DISABLED);
+
if (!fp_route) {
ret = -1;
goto out;
}
- if ((!enable || iface->ra == MODE_DISABLED) && iface->router_event.uloop.fd >= 0) {
+ if (!enable && iface->router_event.uloop.fd >= 0) {
if (!iface->master) {
uloop_timeout_cancel(&iface->timer_rs);
iface->timer_rs.cb = NULL;
@@ -91,7 +93,7 @@ int router_setup_interface(struct interface *iface, bool enable)
uloop_fd_delete(&iface->router_event.uloop);
close(iface->router_event.uloop.fd);
iface->router_event.uloop.fd = -1;
- } else if (enable && iface->ra != MODE_DISABLED) {
+ } else if (enable) {
struct icmp6_filter filt;
struct ipv6_mreq mreq;
int val = 2;
@@ -434,7 +436,7 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr
if (hlim > 0)
adv.h.nd_ra_curhoplimit = hlim;
- if (iface->dhcpv6) {
+ if (iface->dhcpv6 != MODE_DISABLED) {
adv.h.nd_ra_flags_reserved = ND_RA_FLAG_OTHER;
if (iface->ra_managed >= RA_MANAGED_MFLAG)