config: add option to indicate dns service presence
[project/odhcpd.git] / src / config.c
index 53528a0137cb285a92d1a77a2d5d3579fa56b6df..8a6f573399493d980312b3942e51c7683432a526 100644 (file)
@@ -35,6 +35,8 @@ struct config config = {.legacy = false, .main_dhcpv4 = false,
 #define START_DEFAULT  100
 #define LIMIT_DEFAULT  150
 
+#define OAF_DHCPV6     (OAF_DHCPV6_NA | OAF_DHCPV6_PD)
+
 enum {
        IFACE_ATTR_INTERFACE,
        IFACE_ATTR_IFNAME,
@@ -51,6 +53,7 @@ enum {
        IFACE_ATTR_NDP,
        IFACE_ATTR_ROUTER,
        IFACE_ATTR_DNS,
+       IFACE_ATTR_DNS_SERVICE,
        IFACE_ATTR_DOMAIN,
        IFACE_ATTR_FILTER_CLASS,
        IFACE_ATTR_DHCPV4_FORCERECONF,
@@ -59,6 +62,7 @@ enum {
        IFACE_ATTR_DHCPV6_PD,
        IFACE_ATTR_DHCPV6_NA,
        IFACE_ATTR_RA_DEFAULT,
+       IFACE_ATTR_RA_MANAGEMENT,
        IFACE_ATTR_RA_FLAGS,
        IFACE_ATTR_RA_SLAAC,
        IFACE_ATTR_RA_OFFLINK,
@@ -97,6 +101,7 @@ static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = {
        [IFACE_ATTR_NDP] = { .name = "ndp", .type = BLOBMSG_TYPE_STRING },
        [IFACE_ATTR_ROUTER] = { .name = "router", .type = BLOBMSG_TYPE_ARRAY },
        [IFACE_ATTR_DNS] = { .name = "dns", .type = BLOBMSG_TYPE_ARRAY },
+       [IFACE_ATTR_DNS_SERVICE] = { .name = "dns_service", .type = BLOBMSG_TYPE_BOOL },
        [IFACE_ATTR_DOMAIN] = { .name = "domain", .type = BLOBMSG_TYPE_ARRAY },
        [IFACE_ATTR_FILTER_CLASS] = { .name = "filter_class", .type = BLOBMSG_TYPE_STRING },
        [IFACE_ATTR_DHCPV4_FORCERECONF] = { .name = "dhcpv4_forcereconf", .type = BLOBMSG_TYPE_BOOL },
@@ -107,6 +112,7 @@ static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = {
        [IFACE_ATTR_PD_MANAGER] = { .name = "pd_manager", .type = BLOBMSG_TYPE_STRING },
        [IFACE_ATTR_PD_CER] = { .name = "pd_cer", .type = BLOBMSG_TYPE_STRING },
        [IFACE_ATTR_RA_DEFAULT] = { .name = "ra_default", .type = BLOBMSG_TYPE_INT32 },
+       [IFACE_ATTR_RA_MANAGEMENT] = { .name = "ra_management", .type = BLOBMSG_TYPE_INT32 },
        [IFACE_ATTR_RA_FLAGS] = { .name = "ra_flags", . type = BLOBMSG_TYPE_ARRAY },
        [IFACE_ATTR_RA_SLAAC] = { .name = "ra_slaac", .type = BLOBMSG_TYPE_BOOL },
        [IFACE_ATTR_RA_OFFLINK] = { .name = "ra_offlink", .type = BLOBMSG_TYPE_BOOL },
@@ -225,12 +231,13 @@ static void set_interface_defaults(struct interface *iface)
        iface->ra = MODE_DISABLED;
        iface->ndp = MODE_DISABLED;
        iface->learn_routes = 1;
-       iface->dhcpv4_leasetime = 43200;
+       iface->dhcp_leasetime = 43200;
        iface->dhcpv4_start.s_addr = htonl(START_DEFAULT);
        iface->dhcpv4_end.s_addr = htonl(START_DEFAULT + LIMIT_DEFAULT - 1);
        iface->dhcpv6_assignall = true;
        iface->dhcpv6_pd = true;
        iface->dhcpv6_na = true;
+       iface->dns_service = true;
        iface->ra_flags = ND_RA_FLAG_OTHER;
        iface->ra_slaac = true;
        iface->ra_maxinterval = 600;
@@ -543,7 +550,7 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
                if (time < 0)
                        goto err;
 
-               iface->dhcpv4_leasetime = time;
+               iface->dhcp_leasetime = time;
        }
 
        if ((c = tb[IFACE_ATTR_START])) {
@@ -681,6 +688,9 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
                }
        }
 
+       if ((c = tb[IFACE_ATTR_DNS_SERVICE]))
+               iface->dns_service = blobmsg_get_bool(c);
+
        if ((c = tb[IFACE_ATTR_DOMAIN])) {
                struct blob_attr *cur;
                unsigned rem;
@@ -734,6 +744,26 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
        if ((c = tb[IFACE_ATTR_RA_DEFAULT]))
                iface->default_router = blobmsg_get_u32(c);
 
+       if (!tb[IFACE_ATTR_RA_FLAGS] && !tb[IFACE_ATTR_RA_SLAAC] &&
+           (c = tb[IFACE_ATTR_RA_MANAGEMENT])) {
+               switch (blobmsg_get_u32(c)) {
+               case 0:
+                       iface->ra_flags = ND_RA_FLAG_OTHER;
+                       iface->ra_slaac = true;
+                       break;
+               case 1:
+                       iface->ra_flags = ND_RA_FLAG_OTHER|ND_RA_FLAG_MANAGED;
+                       iface->ra_slaac = true;
+                       break;
+               case 2:
+                       iface->ra_flags = ND_RA_FLAG_OTHER|ND_RA_FLAG_MANAGED;
+                       iface->ra_slaac = false;
+                       break;
+               default:
+                       break;
+               }
+       }
+
        if ((c = tb[IFACE_ATTR_RA_FLAGS])) {
                iface->ra_flags = 0;
                if (parse_ra_flags(&iface->ra_flags, c) < 0)