chiark / gitweb /
sd-dhcp6-lease: Add functions for accessing lease and addresses
authorPatrik Flykt <patrik.flykt@linux.intel.com>
Thu, 19 Jun 2014 12:39:45 +0000 (15:39 +0300)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Thu, 19 Jun 2014 12:44:44 +0000 (15:44 +0300)
Add support functions for accessing the current client lease as well
as iterating over the addresses and get their preferred and valid
lifetimes.

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

index f4f1488f4d879a7d3202df3ccb0ca117b67e836b..295c22320750c47bf2e97c5714b35a6d84418cf4 100644 (file)
@@ -37,6 +37,8 @@ struct sd_dhcp6_lease {
         uint8_t preference;
 
         DHCP6IA ia;
+
+        DHCP6Address *addr_iter;
 };
 
 int dhcp6_lease_clear_timers(DHCP6IA *ia);
index 431801d6f0e76d992e9f66e9dd9d81583559d649..65679b730125771d173580c8775f34859b4bec6c 100644 (file)
@@ -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);
index 41d6a5aa1adbcaaec8207212e6cbe245df99dfd8..cbda7d8c84bb8932ce811c474d625feaf7c7b38a 100644 (file)
@@ -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);
index 72267f908ca3caaf54b18185c900df1f2e0a4d2a..92ea8b88322b53108987fc88de70f8144f33ad67 100644 (file)
@@ -26,6 +26,8 @@
 
 #include "sd-event.h"
 
+#include "sd-dhcp6-lease.h"
+
 enum {
         DHCP6_EVENT_STOP                        = 0,
         DHCP6_EVENT_RESEND_EXPIRE               = 10,
@@ -43,6 +45,8 @@ int sd_dhcp6_client_set_index(sd_dhcp6_client *client, int interface_index);
 int sd_dhcp6_client_set_mac(sd_dhcp6_client *client,
                             const struct ether_addr *mac_addr);
 
+int sd_dhcp6_client_get_lease(sd_dhcp6_client *client, sd_dhcp6_lease **ret);
+
 int sd_dhcp6_client_stop(sd_dhcp6_client *client);
 int sd_dhcp6_client_start(sd_dhcp6_client *client);
 int sd_dhcp6_client_attach_event(sd_dhcp6_client *client, sd_event *event,
index 0b2765cbe52a161c2f8ba7489107f4bb3e49cd6f..1126f1ac2e98ccbd6be656bcee06bc911cf81103 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include <netinet/in.h>
+
 typedef struct sd_dhcp6_lease sd_dhcp6_lease;
 
+int sd_dhcp6_lease_get_first_address(sd_dhcp6_lease *lease,
+                                     struct in6_addr *addr,
+                                     uint32_t *lifetime_preferred,
+                                     uint32_t *lifetime_valid);
+int sd_dhcp6_lease_get_next_address(sd_dhcp6_lease *lease,
+                                    struct in6_addr *addr,
+                                    uint32_t *lifetime_preferred,
+                                    uint32_t *lifetime_valid);
+
 sd_dhcp6_lease *sd_dhcp6_lease_ref(sd_dhcp6_lease *lease);
 sd_dhcp6_lease *sd_dhcp6_lease_unref(sd_dhcp6_lease *lease);