summaryrefslogtreecommitdiff
path: root/src/libsystemd-network
diff options
context:
space:
mode:
authorPatrik Flykt <patrik.flykt@linux.intel.com>2014-06-25 15:37:58 +0300
committerPatrik Flykt <patrik.flykt@linux.intel.com>2014-06-26 16:10:21 +0300
commit709d6710d047566c71f03e579a02c3d99fe15a3e (patch)
treea7d4386d9a0d2b20f15779f29d91e83a6eda287f /src/libsystemd-network
parentda6fe470e17fa02f3adedc779585caf8669252bd (diff)
sd-dhcp6-lease: Add helper function to compute remaining expiry time
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.
Diffstat (limited to 'src/libsystemd-network')
-rw-r--r--src/libsystemd-network/dhcp6-lease-internal.h1
-rw-r--r--src/libsystemd-network/sd-dhcp6-lease.c22
2 files changed, 23 insertions, 0 deletions
diff --git a/src/libsystemd-network/dhcp6-lease-internal.h b/src/libsystemd-network/dhcp6-lease-internal.h
index 295c223207..62c16c5b6d 100644
--- a/src/libsystemd-network/dhcp6-lease-internal.h
+++ b/src/libsystemd-network/dhcp6-lease-internal.h
@@ -42,6 +42,7 @@ struct sd_dhcp6_lease {
};
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,
diff --git a/src/libsystemd-network/sd-dhcp6-lease.c b/src/libsystemd-network/sd-dhcp6-lease.c
index cbda7d8c84..17a4b64063 100644
--- a/src/libsystemd-network/sd-dhcp6-lease.c
+++ b/src/libsystemd-network/sd-dhcp6-lease.c
@@ -33,6 +33,28 @@ int dhcp6_lease_clear_timers(DHCP6IA *ia) {
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;