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>
Mon, 2 Oct 2017 16:35:03 +0000 (18:35 +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 93c7f54178354b086e2f64bd2da9b55704ac3e14..fe6af57db06c3653e23d49469499fd924f51d014 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 e89ac0e275b6faf209a0f1083b93e8ec9eeb2af4..858362ac3eb85c9c90890ba65d8b3859a194c91a 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,
@@ -130,6 +131,7 @@ const struct uci_blob_param_list lease_attr_list = {
 };
 
 enum {
+       ODHCPD_ATTR_LEGACY,
        ODHCPD_ATTR_MAINDHCP,
        ODHCPD_ATTR_LEASEFILE,
        ODHCPD_ATTR_LEASETRIGGER,
@@ -138,6 +140,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 },
@@ -252,9 +255,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));
@@ -436,7 +442,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;
        }
 
@@ -474,8 +480,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 f1a11199f4c04c8ff20daa912f15eae44894f633..98bc5658950b3b6d21dea1483e9afab28d1cb572 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;