diff options
author | Patrik Flykt <patrik.flykt@linux.intel.com> | 2014-06-19 15:39:45 +0300 |
---|---|---|
committer | Patrik Flykt <patrik.flykt@linux.intel.com> | 2014-06-19 15:44:44 +0300 |
commit | ea3b3a75abb3f8b853f7da454b9b8e258a120eea (patch) | |
tree | 82d44fc73fc8c36cced35de7e70d152a629fb8d0 /src/libsystemd-network/sd-dhcp6-lease.c | |
parent | 631bbe71298ec892f77f44f94feb612646fe6853 (diff) |
sd-dhcp6-lease: Add functions for accessing lease and addresses
Add support functions for accessing the current client lease as well
as iterating over the addresses and get their preferred and valid
lifetimes.
Diffstat (limited to 'src/libsystemd-network/sd-dhcp6-lease.c')
-rw-r--r-- | src/libsystemd-network/sd-dhcp6-lease.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/libsystemd-network/sd-dhcp6-lease.c b/src/libsystemd-network/sd-dhcp6-lease.c index 41d6a5aa1a..cbda7d8c84 100644 --- a/src/libsystemd-network/sd-dhcp6-lease.c +++ b/src/libsystemd-network/sd-dhcp6-lease.c @@ -105,6 +105,45 @@ int dhcp6_lease_get_iaid(sd_dhcp6_lease *lease, be32_t *iaid) { return 0; } +int sd_dhcp6_lease_get_next_address(sd_dhcp6_lease *lease, + struct in6_addr *addr, + uint32_t *lifetime_preferred, + uint32_t *lifetime_valid) { + assert_return(lease, -EINVAL); + assert_return(addr, -EINVAL); + assert_return(lifetime_preferred, -EINVAL); + assert_return(lifetime_valid, -EINVAL); + + if (!lease->addr_iter) + return -ENOMSG; + + memcpy(addr, &lease->addr_iter->address, sizeof(struct in6_addr)); + *lifetime_preferred = be32toh(lease->addr_iter->lifetime_preferred); + *lifetime_valid = be32toh(lease->addr_iter->lifetime_valid); + + lease->addr_iter = lease->addr_iter->addresses_next; + + return 0; +} + +int sd_dhcp6_lease_get_first_address(sd_dhcp6_lease *lease, + struct in6_addr *addr, + uint32_t *lifetime_preferred, + uint32_t *lifetime_valid) { + assert_return(lease, -EINVAL); + assert_return(addr, -EINVAL); + assert_return(lifetime_preferred, -EINVAL); + assert_return(lifetime_valid, -EINVAL); + + if (!lease->ia.addresses) + return -ENOMSG; + + lease->addr_iter = lease->ia.addresses; + + return sd_dhcp6_lease_get_next_address(lease, addr, lifetime_preferred, + lifetime_valid); +} + sd_dhcp6_lease *sd_dhcp6_lease_ref(sd_dhcp6_lease *lease) { if (lease) assert_se(REFCNT_INC(lease->n_ref) >= 2); |