From: Hans Dedecker Date: Thu, 11 May 2017 09:08:48 +0000 (+0200) Subject: config: fix dhcpv4 server being started X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=29cb2ff9ebce36884ee517cbe39b440d5eb57914;p=project%2Fodhcpd.git config: fix dhcpv4 server being started In case maindhcp is set to disabled in global config one expect the DHCPv4 server not being started irrespective if the dhcpv4 interface config is set to server. Fix this by keeping maindhcp config apart from the legacy config parameter as already documented in the README. Signed-off-by: Hans Dedecker --- diff --git a/README b/README index ebb2d99..9119071 100644 --- a/README +++ b/README @@ -60,6 +60,8 @@ Section of type odhcpd Option Type Default Description legacy bool 0 Enable DHCPv4 if start but no dhcpv4 option set +maindhcp bool 0 Use odhcpd as the main DHCPv4 + service leasefile string DHCP/v6 lease/hostfile leasetrigger string Lease trigger script loglevel integer 6 Syslog level priority (0-7) diff --git a/src/config.c b/src/config.c index 943f243..acf30de 100644 --- a/src/config.c +++ b/src/config.c @@ -17,8 +17,9 @@ static struct blob_buf b; static int reload_pipe[2]; struct list_head leases = LIST_HEAD_INIT(leases); struct list_head interfaces = LIST_HEAD_INIT(interfaces); -struct config config = {.legacy = false, .dhcp_cb = NULL, - .dhcp_statefile = NULL, .log_level = LOG_INFO}; +struct config config = {.legacy = false, .main_dhcpv4 = false, + .dhcp_cb = NULL, .dhcp_statefile = NULL, + .log_level = LOG_INFO}; enum { IFACE_ATTR_INTERFACE, @@ -128,6 +129,7 @@ const struct uci_blob_param_list lease_attr_list = { }; enum { + ODHCPD_ATTR_LEGACY, ODHCPD_ATTR_MAINDHCP, ODHCPD_ATTR_LEASEFILE, ODHCPD_ATTR_LEASETRIGGER, @@ -136,6 +138,7 @@ enum { }; static const struct blobmsg_policy odhcpd_attrs[LEASE_ATTR_MAX] = { + [ODHCPD_ATTR_LEGACY] = { .name = "legacy", .type = BLOBMSG_TYPE_BOOL }, [ODHCPD_ATTR_MAINDHCP] = { .name = "maindhcp", .type = BLOBMSG_TYPE_BOOL }, [ODHCPD_ATTR_LEASEFILE] = { .name = "leasefile", .type = BLOBMSG_TYPE_STRING }, [ODHCPD_ATTR_LEASETRIGGER] = { .name = "leasetrigger", .type = BLOBMSG_TYPE_STRING }, @@ -249,9 +252,12 @@ static void set_config(struct uci_section *s) uci_to_blob(&b, s, &odhcpd_attr_list); blobmsg_parse(odhcpd_attrs, ODHCPD_ATTR_MAX, tb, blob_data(b.head), blob_len(b.head)); - if ((c = tb[ODHCPD_ATTR_MAINDHCP])) + if ((c = tb[ODHCPD_ATTR_LEGACY])) config.legacy = blobmsg_get_bool(c); + if ((c = tb[ODHCPD_ATTR_MAINDHCP])) + config.main_dhcpv4 = blobmsg_get_bool(c); + if ((c = tb[ODHCPD_ATTR_LEASEFILE])) { free(config.dhcp_statefile); config.dhcp_statefile = strdup(blobmsg_get_string(c)); @@ -433,7 +439,7 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr if ((c = tb[IFACE_ATTR_START])) { iface->dhcpv4_start.s_addr = htonl(blobmsg_get_u32(c)); - if (config.legacy) + if (config.main_dhcpv4 && config.legacy) iface->dhcpv4 = RELAYD_SERVER; } @@ -471,8 +477,10 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr } if ((c = tb[IFACE_ATTR_DHCPV4])) { - if ((mode = parse_mode(blobmsg_get_string(c))) >= 0) - iface->dhcpv4 = mode; + if ((mode = parse_mode(blobmsg_get_string(c))) >= 0) { + if (config.main_dhcpv4) + iface->dhcpv4 = mode; + } else goto err; } diff --git a/src/odhcpd.h b/src/odhcpd.h index 4ddadbe..334276e 100644 --- a/src/odhcpd.h +++ b/src/odhcpd.h @@ -95,6 +95,7 @@ enum odhcpd_assignment_flags { struct config { bool legacy; + bool main_dhcpv4; char *dhcp_cb; char *dhcp_statefile; int log_level;