chiark / gitweb /
sd-dhcp6-lease: Add helper function to compute remaining expiry time
authorPatrik Flykt <patrik.flykt@linux.intel.com>
Wed, 25 Jun 2014 12:37:58 +0000 (15:37 +0300)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Thu, 26 Jun 2014 13:10:21 +0000 (16:10 +0300)
Create a helper function to compute the remaining time in seconds from
time T2 to the IPv6 address with the longest lifetime. The computed
time is used as the Maximum Retransmission Duration in Rebinding state.
See RFC 3315, section 18.1.4. for details.

src/libsystemd-network/dhcp6-lease-internal.h
src/libsystemd-network/sd-dhcp6-lease.c

index 295c22320750c47bf2e97c5714b35a6d84418cf4..62c16c5b6d284e30d872f7d0d238e0f180c1bbdd 100644 (file)
@@ -42,6 +42,7 @@ struct sd_dhcp6_lease {
 };
 
 int dhcp6_lease_clear_timers(DHCP6IA *ia);
 };
 
 int dhcp6_lease_clear_timers(DHCP6IA *ia);
+int dhcp6_lease_ia_rebind_expire(const DHCP6IA *ia, uint32_t *expire);
 DHCP6IA *dhcp6_lease_free_ia(DHCP6IA *ia);
 
 int dhcp6_lease_set_serverid(sd_dhcp6_lease *lease, const uint8_t *id,
 DHCP6IA *dhcp6_lease_free_ia(DHCP6IA *ia);
 
 int dhcp6_lease_set_serverid(sd_dhcp6_lease *lease, const uint8_t *id,
index cbda7d8c84bb8932ce811c474d625feaf7c7b38a..17a4b64063160fd1ee6ca754b3eddd9c1a773a62 100644 (file)
@@ -33,6 +33,28 @@ int dhcp6_lease_clear_timers(DHCP6IA *ia) {
         return 0;
 }
 
         return 0;
 }
 
+int dhcp6_lease_ia_rebind_expire(const DHCP6IA *ia, uint32_t *expire) {
+        DHCP6Address *addr;
+        uint32_t valid = 0, t;
+
+        assert_return(ia, -EINVAL);
+        assert_return(expire, -EINVAL);
+
+        LIST_FOREACH(addresses, addr, ia->addresses) {
+                t = be32toh(addr->lifetime_valid);
+                if (valid < t)
+                        valid = t;
+        }
+
+        t = be32toh(ia->lifetime_t2);
+        if (t > valid)
+                return -EINVAL;
+
+        *expire = valid - t;
+
+        return 0;
+}
+
 DHCP6IA *dhcp6_lease_free_ia(DHCP6IA *ia) {
         DHCP6Address *address;
 
 DHCP6IA *dhcp6_lease_free_ia(DHCP6IA *ia) {
         DHCP6Address *address;