Revert "dhcpv6: add a minimum valid lifetime for IA_PD updates"
[project/odhcp6c.git] / src / dhcpv6.c
index d9df23977067a8ff37fb3280d25177a42f33301d..793b3be567f03d5b1e3c2530cf219aed1c54f840 100644 (file)
@@ -114,9 +114,6 @@ static uint8_t reconf_key[16];
 // client options
 static unsigned int client_options = 0;
 
-// Minimum valid lifetime for IA_PD updates
-static unsigned int pd_safe_valid = 0;
-
 static uint32_t ntohl_unaligned(const uint8_t *data)
 {
        uint32_t buf;
@@ -196,11 +193,10 @@ static char *dhcpv6_status_code_to_str(uint16_t code)
        return "Unknown";
 }
 
-int init_dhcpv6(const char *ifname, unsigned int options, int sol_timeout, unsigned int ia_pd_safe_valid)
+int init_dhcpv6(const char *ifname, unsigned int options, int sol_timeout)
 {
        client_options = options;
        dhcpv6_retx[DHCPV6_MSG_SOLICIT].max_timeo = sol_timeout;
-       pd_safe_valid = ia_pd_safe_valid;
 
        sock = socket(AF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, IPPROTO_UDP);
        if (sock < 0)
@@ -1067,7 +1063,7 @@ static int dhcpv6_handle_reply(enum dhcpv6_msg orig, _unused const int rc,
        unsigned int updated_IAs = 0;
        bool handled_status_codes[_DHCPV6_Status_Max] = { false, };
 
-       odhcp6c_expire();
+       odhcp6c_expire(true);
 
        if (orig == DHCPV6_MSG_UNKNOWN) {
                static time_t last_update = 0;
@@ -1417,7 +1413,7 @@ static unsigned int dhcpv6_parse_ia(void *opt, void *end)
                        }
 
                        if (ok) {
-                               if (odhcp6c_update_entry(STATE_IA_PD, &entry, pd_safe_valid, 0))
+                               if (odhcp6c_update_entry(STATE_IA_PD, &entry, 0, 0))
                                        updated_IAs++;
 
                                syslog(LOG_INFO, "%s/%d preferred %d valid %d",
@@ -1462,12 +1458,19 @@ static unsigned int dhcpv6_calc_refresh_timers(void)
 {
        struct odhcp6c_entry *e;
        size_t ia_na_entries, ia_pd_entries, i;
+       size_t invalid_entries = 0;
        int64_t l_t1 = UINT32_MAX, l_t2 = UINT32_MAX, l_t3 = 0;
 
        e = odhcp6c_get_state(STATE_IA_NA, &ia_na_entries);
        ia_na_entries /= sizeof(*e);
 
        for (i = 0; i < ia_na_entries; i++) {
+               /* Exclude invalid IA_NA entries */
+               if (!e[i].valid) {
+                       invalid_entries++;
+                       continue;
+               }
+
                if (e[i].t1 < l_t1)
                        l_t1 = e[i].t1;
 
@@ -1482,6 +1485,12 @@ static unsigned int dhcpv6_calc_refresh_timers(void)
        ia_pd_entries /= sizeof(*e);
 
        for (i = 0; i < ia_pd_entries; i++) {
+               /* Exclude invalid IA_PD entries */
+               if (!e[i].valid) {
+                       invalid_entries++;
+                       continue;
+               }
+
                if (e[i].t1 < l_t1)
                        l_t1 = e[i].t1;
 
@@ -1492,7 +1501,7 @@ static unsigned int dhcpv6_calc_refresh_timers(void)
                        l_t3 = e[i].valid;
        }
 
-       if (ia_pd_entries || ia_na_entries) {
+       if (ia_pd_entries + ia_na_entries - invalid_entries) {
                t1 = l_t1;
                t2 = l_t2;
                t3 = l_t3;