summaryrefslogtreecommitdiff
path: root/src/libsystemd-network
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsystemd-network')
-rw-r--r--src/libsystemd-network/dhcp6-lease-internal.h2
-rw-r--r--src/libsystemd-network/sd-dhcp6-client.c12
-rw-r--r--src/libsystemd-network/sd-dhcp6-lease.c39
3 files changed, 53 insertions, 0 deletions
diff --git a/src/libsystemd-network/dhcp6-lease-internal.h b/src/libsystemd-network/dhcp6-lease-internal.h
index f4f1488f4d..295c223207 100644
--- a/src/libsystemd-network/dhcp6-lease-internal.h
+++ b/src/libsystemd-network/dhcp6-lease-internal.h
@@ -37,6 +37,8 @@ struct sd_dhcp6_lease {
uint8_t preference;
DHCP6IA ia;
+
+ DHCP6Address *addr_iter;
};
int dhcp6_lease_clear_timers(DHCP6IA *ia);
diff --git a/src/libsystemd-network/sd-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c
index 431801d6f0..65679b7301 100644
--- a/src/libsystemd-network/sd-dhcp6-client.c
+++ b/src/libsystemd-network/sd-dhcp6-client.c
@@ -129,6 +129,18 @@ int sd_dhcp6_client_set_mac(sd_dhcp6_client *client,
return 0;
}
+int sd_dhcp6_client_get_lease(sd_dhcp6_client *client, sd_dhcp6_lease **ret) {
+ assert_return(client, -EINVAL);
+ assert_return(ret, -EINVAL);
+
+ if (!client->lease)
+ return -ENOMSG;
+
+ *ret = sd_dhcp6_lease_ref(client->lease);
+
+ return 0;
+}
+
static sd_dhcp6_client *client_notify(sd_dhcp6_client *client, int event) {
if (client->cb) {
client = sd_dhcp6_client_ref(client);
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);