dhcpv6-ia: use dhcp leasetime to set preferred/valid statefull lifetimes
authorHans Dedecker <dedeckeh@gmail.com>
Tue, 14 Jan 2020 20:16:48 +0000 (21:16 +0100)
committerHans Dedecker <dedeckeh@gmail.com>
Thu, 16 Jan 2020 19:29:53 +0000 (20:29 +0100)
Allow to set the preferred/valid lifetimes of IA_NA/IA_PD options based
on the configured dhcp leasetime.
DHCP leqasetime will be used to set the preferred/valid lifetimes in the
IA_NA/IA_PD options unless the preferred/valid lifetimes of the IPv6
address are smaller then the DHCP leasetime.
This will avoid IA_NA/IA_PD options being sent with infinite lifetimes
due to the IPv6 address having infinite preferred/valid lifetimes
like IPv6 ULA addresses.
While at it rename dhcpv4_leasetime into dhcp_leasetime as the leasetime
is used both for DHCPv4 and DHCPv6

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
src/config.c
src/dhcpv4.c
src/dhcpv6-ia.c
src/odhcpd.h
src/router.c

index f3ba3e85f55a1b46a51dd4ac7af47f48bc686ee4..3d41e130f50b7308dc545e01b6104c7c1cc25eb0 100644 (file)
@@ -229,7 +229,7 @@ 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;
@@ -547,7 +547,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])) {
index 1deb097899f5f1d2156c7fdbf9396e8f4a2142c5..24a4fea08bb0df787142dae6574671a7258a44cd 100644 (file)
@@ -1072,7 +1072,7 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg msg, const uint8_t *mac,
                        if (a->leasetime)
                                my_leasetime = a->leasetime;
                        else
-                               my_leasetime = iface->dhcpv4_leasetime;
+                               my_leasetime = iface->dhcp_leasetime;
 
                        if ((*leasetime == 0) || (my_leasetime < *leasetime))
                                *leasetime = my_leasetime;
index ee0acafe5c38cef5fd04ccd4fcbf76c32a6e0f7d..d8187ffeb8dd50fd998ef3a9771c04080bcc9a34 100644 (file)
@@ -823,7 +823,7 @@ static size_t build_ia(uint8_t *buf, size_t buflen, uint16_t status,
                if (a->leasetime)
                        leasetime = a->leasetime;
                else
-                       leasetime = iface->dhcpv4_leasetime;
+                       leasetime = iface->dhcp_leasetime;
 
                uint32_t pref = leasetime;
                uint32_t valid = leasetime;
@@ -842,9 +842,15 @@ static size_t build_ia(uint8_t *buf, size_t buflen, uint16_t status,
                        if (prefix_pref != UINT32_MAX)
                                prefix_pref -= now;
 
+                       if (prefix_pref > leasetime)
+                               prefix_pref = leasetime;
+
                        if (prefix_valid != UINT32_MAX)
                                prefix_valid -= now;
 
+                       if (prefix_valid > leasetime)
+                               prefix_valid = leasetime;
+
                        if (a->flags & OAF_DHCPV6_PD) {
                                struct dhcpv6_ia_prefix o_ia_p = {
                                        .type = htons(DHCPV6_OPT_IA_PREFIX),
index ae4826e3c2c72ee95a1acf00157fab44411c69cd..072a148727bb3d9d11a3667ed36afca2aa15294f 100644 (file)
@@ -272,6 +272,9 @@ struct interface {
        uint32_t ra_hoplimit;
        int ra_mtu;
 
+       // DHCP
+       uint32_t dhcp_leasetime;
+
        // DHCPv4
        struct in_addr dhcpv4_start;
        struct in_addr dhcpv4_end;
@@ -284,7 +287,6 @@ struct interface {
        size_t dhcpv4_router_cnt;
        struct in_addr *dhcpv4_dns;
        size_t dhcpv4_dns_cnt;
-       uint32_t dhcpv4_leasetime;
        bool dhcpv4_forcereconf;
 
        // DNS
index 7c976722c78ed6f38fcb290242e23a3855c0fec6..295bdfbb11fa363af7a223a5c329472f9d57825e 100644 (file)
@@ -552,13 +552,13 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr
                        preferred = TIME_LEFT(addr->preferred, now);
 
                        if (iface->ra_useleasetime &&
-                                       preferred > iface->dhcpv4_leasetime)
-                               preferred = iface->dhcpv4_leasetime;
+                           preferred > iface->dhcp_leasetime)
+                               preferred = iface->dhcp_leasetime;
                }
 
                valid = TIME_LEFT(addr->valid, now);
-               if (iface->ra_useleasetime && valid > iface->dhcpv4_leasetime)
-                       valid = iface->dhcpv4_leasetime;
+               if (iface->ra_useleasetime && valid > iface->dhcp_leasetime)
+                       valid = iface->dhcp_leasetime;
 
                if (minvalid > valid)
                        minvalid = valid;