config: fix dhcpv4 server being started
authorHans Dedecker <dedeckeh@gmail.com>
Thu, 11 May 2017 09:08:48 +0000 (11:08 +0200)
committerHans Dedecker <dedeckeh@gmail.com>
Thu, 11 May 2017 10:19:50 +0000 (12:19 +0200)
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 <dedeckeh@gmail.com>
README
src/config.c
src/odhcpd.h

diff --git a/README b/README
index ebb2d994ffc598b7f3527c06f655b4a4119c40b9..9119071792c2b89736bfdccaac4f3f7f63afbf27 100644 (file)
--- 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)
index 943f2430326cb40e251f1dc67e7b0caca2dc333a..acf30de75a2d4efea7a9bb4f6c2b2ba626c15949 100644 (file)
@@ -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;
        }
index 4ddadbee635ae1c7d21c6dfed424b5f5690f05a7..334276ed39c8f07dbec43249fbc92e4724709cd0 100644 (file)
@@ -95,6 +95,7 @@ enum odhcpd_assignment_flags {
 
 struct config {
        bool legacy;
+       bool main_dhcpv4;
        char *dhcp_cb;
        char *dhcp_statefile;
        int log_level;