router: don't announce prefixes with valid lifetime equal to 0
[project/odhcpd.git] / src / config.c
index b621c75..689d4ce 100644 (file)
@@ -48,6 +48,7 @@ enum {
        IFACE_ATTR_RA_MININTERVAL,
        IFACE_ATTR_RA_MAXINTERVAL,
        IFACE_ATTR_RA_LIFETIME,
+       IFACE_ATTR_RA_USELEASETIME,
        IFACE_ATTR_PD_MANAGER,
        IFACE_ATTR_PD_CER,
        IFACE_ATTR_NDPROXY_ROUTING,
@@ -85,6 +86,7 @@ static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = {
        [IFACE_ATTR_RA_MININTERVAL] = { .name = "ra_mininterval", .type = BLOBMSG_TYPE_INT32 },
        [IFACE_ATTR_RA_MAXINTERVAL] = { .name = "ra_maxinterval", .type = BLOBMSG_TYPE_INT32 },
        [IFACE_ATTR_RA_LIFETIME] = { .name = "ra_lifetime", .type = BLOBMSG_TYPE_INT32 },
+       [IFACE_ATTR_RA_USELEASETIME] = { .name = "ra_useleasetime", .type = BLOBMSG_TYPE_BOOL },
        [IFACE_ATTR_NDPROXY_ROUTING] = { .name = "ndproxy_routing", .type = BLOBMSG_TYPE_BOOL },
        [IFACE_ATTR_NDPROXY_SLAVE] = { .name = "ndproxy_slave", .type = BLOBMSG_TYPE_BOOL },
 };
@@ -192,6 +194,7 @@ static void set_interface_defaults(struct interface *iface)
 {
        iface->managed = 1;
        iface->learn_routes = 1;
+       iface->dhcpv4_leasetime = 43200;
        iface->ra_maxinterval = 600;
        iface->ra_mininterval = iface->ra_maxinterval/3;
        iface->ra_lifetime = -1;
@@ -288,10 +291,10 @@ static double parse_leasetime(struct blob_attr *c) {
                        goto err;
        }
 
-       if (time >= 60)
-               return time;
+       if (time < 60)
+               time = 60;
 
-       return 0;
+       return time;
 
 err:
        return -1;
@@ -351,8 +354,7 @@ static int set_lease(struct uci_section *s)
                if (time < 0)
                        goto err;
 
-               if (time >= 60)
-                       lease->dhcpv4_leasetime = time;
+               lease->dhcpv4_leasetime = time;
        }
 
        list_add(&lease->head, &leases);
@@ -425,8 +427,7 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
                if (time < 0)
                        goto err;
 
-               if (time >= 60)
-                       iface->dhcpv4_leasetime = time;
+               iface->dhcpv4_leasetime = time;
        }
 
        if ((c = tb[IFACE_ATTR_START])) {
@@ -600,6 +601,9 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
        if ((c = tb[IFACE_ATTR_RA_LIFETIME]))
                iface->ra_lifetime = blobmsg_get_u32(c);
 
+       if ((c = tb[IFACE_ATTR_RA_USELEASETIME]))
+               iface->ra_useleasetime = blobmsg_get_bool(c);
+
        if ((c = tb[IFACE_ATTR_RA_PREFERENCE])) {
                const char *prio = blobmsg_get_string(c);