use leaetime as base for T1 and T2 upper bound
[project/odhcpd.git] / src / config.c
index 7f51585..068d1a7 100644 (file)
@@ -32,10 +32,14 @@ enum {
        IFACE_ATTR_NDP,
        IFACE_ATTR_DNS,
        IFACE_ATTR_DOMAIN,
        IFACE_ATTR_NDP,
        IFACE_ATTR_DNS,
        IFACE_ATTR_DOMAIN,
+       IFACE_ATTR_FILTER_CLASS,
+       IFACE_ATTR_DHCPV6_RAW,
        IFACE_ATTR_RA_DEFAULT,
        IFACE_ATTR_RA_MANAGEMENT,
        IFACE_ATTR_RA_OFFLINK,
        IFACE_ATTR_RA_PREFERENCE,
        IFACE_ATTR_RA_DEFAULT,
        IFACE_ATTR_RA_MANAGEMENT,
        IFACE_ATTR_RA_OFFLINK,
        IFACE_ATTR_RA_PREFERENCE,
+       IFACE_ATTR_PD_MANAGER,
+       IFACE_ATTR_PD_CER,
        IFACE_ATTR_NDPROXY_ROUTING,
        IFACE_ATTR_NDPROXY_SLAVE,
        IFACE_ATTR_NDPROXY_STATIC,
        IFACE_ATTR_NDPROXY_ROUTING,
        IFACE_ATTR_NDPROXY_SLAVE,
        IFACE_ATTR_NDPROXY_STATIC,
@@ -59,6 +63,10 @@ static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = {
        [IFACE_ATTR_NDP] = { .name = "ndp", .type = BLOBMSG_TYPE_STRING },
        [IFACE_ATTR_DNS] = { .name = "dns", .type = BLOBMSG_TYPE_ARRAY },
        [IFACE_ATTR_DOMAIN] = { .name = "domain", .type = BLOBMSG_TYPE_ARRAY },
        [IFACE_ATTR_NDP] = { .name = "ndp", .type = BLOBMSG_TYPE_STRING },
        [IFACE_ATTR_DNS] = { .name = "dns", .type = BLOBMSG_TYPE_ARRAY },
        [IFACE_ATTR_DOMAIN] = { .name = "domain", .type = BLOBMSG_TYPE_ARRAY },
+       [IFACE_ATTR_FILTER_CLASS] = { .name = "filter_class", .type = BLOBMSG_TYPE_STRING },
+       [IFACE_ATTR_DHCPV6_RAW] = { .name = "dhcpv6_raw", .type = BLOBMSG_TYPE_STRING },
+       [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_OFFLINK] = { .name = "ra_offlink", .type = BLOBMSG_TYPE_BOOL },
        [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_OFFLINK] = { .name = "ra_offlink", .type = BLOBMSG_TYPE_BOOL },
@@ -145,6 +153,8 @@ static void clean_interface(struct interface *iface)
        free(iface->upstream);
        free(iface->static_ndp);
        free(iface->dhcpv4_dns);
        free(iface->upstream);
        free(iface->static_ndp);
        free(iface->dhcpv4_dns);
+       free(iface->dhcpv6_raw);
+       free(iface->filter_class);
        memset(&iface->ra, 0, sizeof(*iface) - offsetof(struct interface, ra));
 }
 
        memset(&iface->ra, 0, sizeof(*iface) - offsetof(struct interface, ra));
 }
 
@@ -245,10 +255,12 @@ static int set_lease(struct uci_section *s)
                lease->duid_len = len;
        }
 
                lease->duid_len = len;
        }
 
-       if ((c = tb[LEASE_ATTR_HOSTID]))
-               if (odhcpd_unhexlify((uint8_t*)&lease->hostid, sizeof(lease->hostid),
-                               blobmsg_get_string(c)) < 0)
+       if ((c = tb[LEASE_ATTR_HOSTID])) {
+               errno = 0;
+               lease->hostid = strtoul(blobmsg_get_string(c), NULL, 16);
+               if (errno)
                        goto err;
                        goto err;
+       }
 
        list_add(&lease->head, &leases);
        return 0;
 
        list_add(&lease->head, &leases);
        return 0;
@@ -281,6 +293,7 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
 
                strncpy(iface->name, name, sizeof(iface->name) - 1);
                list_add(&iface->head, &interfaces);
 
                strncpy(iface->name, name, sizeof(iface->name) - 1);
                list_add(&iface->head, &interfaces);
+               overwrite = true;
        }
 
        const char *ifname = NULL;
        }
 
        const char *ifname = NULL;
@@ -436,7 +449,13 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
                                continue;
 
                        uint8_t buf[256];
                                continue;
 
                        uint8_t buf[256];
-                       int len = dn_comp(blobmsg_get_string(cur), buf, sizeof(buf), NULL, NULL);
+                       char *domain = blobmsg_get_string(cur);
+                       size_t domainlen = strlen(domain);
+                       if (domainlen > 0 && domain[domainlen - 1] == '.')
+                               domain[domainlen - 1] = 0;
+
+                       int len = dn_comp(domain, buf, sizeof(buf), NULL, NULL);
+                       free(domain);
                        if (len <= 0)
                                goto err;
 
                        if (len <= 0)
                                goto err;
 
@@ -449,6 +468,17 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
                }
        }
 
                }
        }
 
+       if ((c = tb[IFACE_ATTR_FILTER_CLASS])) {
+               iface->filter_class = realloc(iface->filter_class, blobmsg_data_len(c) + 1);
+               memcpy(iface->filter_class, blobmsg_get_string(c), blobmsg_data_len(c) + 1);
+       }
+
+       if ((c = tb[IFACE_ATTR_DHCPV6_RAW])) {
+               iface->dhcpv6_raw_len = blobmsg_data_len(c) / 2;
+               iface->dhcpv6_raw = realloc(iface->dhcpv6_raw, iface->dhcpv6_raw_len);
+               odhcpd_unhexlify(iface->dhcpv6_raw, iface->dhcpv6_raw_len, blobmsg_get_string(c));
+       }
+
        if ((c = tb[IFACE_ATTR_RA_DEFAULT]))
                iface->default_router = blobmsg_get_u32(c);
 
        if ((c = tb[IFACE_ATTR_RA_DEFAULT]))
                iface->default_router = blobmsg_get_u32(c);
 
@@ -473,6 +503,14 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
                        goto err;
        }
 
                        goto err;
        }
 
+       if ((c = tb[IFACE_ATTR_PD_MANAGER]))
+               strncpy(iface->dhcpv6_pd_manager, blobmsg_get_string(c),
+                               sizeof(iface->dhcpv6_pd_manager) - 1);
+
+       if ((c = tb[IFACE_ATTR_PD_CER]) &&
+                       inet_pton(AF_INET6, blobmsg_get_string(c), &iface->dhcpv6_pd_cer) < 1)
+               goto err;
+
        if ((c = tb[IFACE_ATTR_NDPROXY_ROUTING]))
                iface->learn_routes = blobmsg_get_bool(c);
        else if (overwrite)
        if ((c = tb[IFACE_ATTR_NDPROXY_ROUTING]))
                iface->learn_routes = blobmsg_get_bool(c);
        else if (overwrite)