chiark / gitweb /
sd-dhcp6-lease: Revise address iteration functions
authorPatrik Flykt <patrik.flykt@linux.intel.com>
Tue, 20 Jan 2015 17:35:56 +0000 (19:35 +0200)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Tue, 27 Jan 2015 07:35:24 +0000 (09:35 +0200)
Revise the address iteration functions so that one helper function
resets the iterator to the start of the address list while the
second one fetches addresses one by one.

The test case is also updated.

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

index 78e1589..2442269 100644 (file)
@@ -146,10 +146,9 @@ int dhcp6_lease_get_iaid(sd_dhcp6_lease *lease, be32_t *iaid) {
         return 0;
 }
 
         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) {
+int sd_dhcp6_lease_get_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(lease, -EINVAL);
         assert_return(addr, -EINVAL);
         assert_return(lifetime_preferred, -EINVAL);
@@ -169,22 +168,9 @@ int sd_dhcp6_lease_get_next_address(sd_dhcp6_lease *lease,
         return 0;
 }
 
         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);
+void sd_dhcp6_lease_reset_address_iter(sd_dhcp6_lease *lease) {
+        if (lease)
+                lease->addr_iter = lease->ia.addresses;
 }
 
 sd_dhcp6_lease *sd_dhcp6_lease_ref(sd_dhcp6_lease *lease) {
 }
 
 sd_dhcp6_lease *sd_dhcp6_lease_ref(sd_dhcp6_lease *lease) {
index 7590839..9386f31 100644 (file)
@@ -286,26 +286,27 @@ static int test_advertise_option(sd_event *e) {
 
         assert_se(opt_clientid);
 
 
         assert_se(opt_clientid);
 
-        assert_se(sd_dhcp6_lease_get_first_address(lease, &addr, &lt_pref,
-                                                   &lt_valid) >= 0);
+        sd_dhcp6_lease_reset_address_iter(lease);
+        assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref,
+                                             &lt_valid) >= 0);
         assert_se(!memcmp(&addr, &msg_advertise[42], sizeof(addr)));
         assert_se(lt_pref == 150);
         assert_se(lt_valid == 180);
         assert_se(!memcmp(&addr, &msg_advertise[42], sizeof(addr)));
         assert_se(lt_pref == 150);
         assert_se(lt_valid == 180);
-        assert_se(sd_dhcp6_lease_get_next_address(lease, &addr, &lt_pref,
-                                                  &lt_valid) == -ENOMSG);
+        assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref,
+                                             &lt_valid) == -ENOMSG);
 
 
-        assert_se(sd_dhcp6_lease_get_first_address(lease, &addr, &lt_pref,
-                                                   &lt_valid) >= 0);
+        sd_dhcp6_lease_reset_address_iter(lease);
+        assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref,
+                                             &lt_valid) >= 0);
         assert_se(!memcmp(&addr, &msg_advertise[42], sizeof(addr)));
         assert_se(!memcmp(&addr, &msg_advertise[42], sizeof(addr)));
-        assert_se(sd_dhcp6_lease_get_next_address(lease, &addr, &lt_pref,
-                                                  &lt_valid) == -ENOMSG);
-        assert_se(sd_dhcp6_lease_get_next_address(lease, &addr, &lt_pref,
-                                                  &lt_valid) == -ENOMSG);
-        assert_se(sd_dhcp6_lease_get_first_address(lease, &addr, &lt_pref,
-                                                   &lt_valid) >= 0);
+        assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref,
+                                             &lt_valid) == -ENOMSG);
+        sd_dhcp6_lease_reset_address_iter(lease);
+        assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref,
+                                             &lt_valid) >= 0);
         assert_se(!memcmp(&addr, &msg_advertise[42], sizeof(addr)));
         assert_se(!memcmp(&addr, &msg_advertise[42], sizeof(addr)));
-        assert_se(sd_dhcp6_lease_get_next_address(lease, &addr, &lt_pref,
-                                                  &lt_valid) == -ENOMSG);
+        assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref,
+                                             &lt_valid) == -ENOMSG);
 
         assert_se(dhcp6_lease_get_serverid(lease, &opt, &len) >= 0);
         assert_se(len == 14);
 
         assert_se(dhcp6_lease_get_serverid(lease, &opt, &len) >= 0);
         assert_se(len == 14);
@@ -439,14 +440,15 @@ static int test_client_verify_request(DHCP6Message *request, uint8_t *option,
         assert_se(found_clientid && found_iana && found_serverid &&
                   found_elapsed_time);
 
         assert_se(found_clientid && found_iana && found_serverid &&
                   found_elapsed_time);
 
-        assert_se(sd_dhcp6_lease_get_first_address(lease, &addr, &lt_pref,
-                                                   &lt_valid) >= 0);
+        sd_dhcp6_lease_reset_address_iter(lease);
+        assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref,
+                                             &lt_valid) >= 0);
         assert_se(!memcmp(&addr, &msg_advertise[42], sizeof(addr)));
         assert_se(lt_pref == 150);
         assert_se(lt_valid == 180);
 
         assert_se(!memcmp(&addr, &msg_advertise[42], sizeof(addr)));
         assert_se(lt_pref == 150);
         assert_se(lt_valid == 180);
 
-        assert_se(sd_dhcp6_lease_get_next_address(lease, &addr, &lt_pref,
-                                                  &lt_valid) == -ENOMSG);
+        assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref,
+                                             &lt_valid) == -ENOMSG);
 
         return 0;
 }
 
         return 0;
 }
@@ -587,11 +589,10 @@ static int test_client_verify_information_request(DHCP6Message *information_requ
         assert_se(r == -ENOMSG);
         assert_se(found_clientid && found_elapsed_time);
 
         assert_se(r == -ENOMSG);
         assert_se(found_clientid && found_elapsed_time);
 
-        assert_se(sd_dhcp6_lease_get_first_address(lease, &addr, &lt_pref,
-                                                   &lt_valid) == -ENOMSG);
+        sd_dhcp6_lease_reset_address_iter(lease);
 
 
-        assert_se(sd_dhcp6_lease_get_next_address(lease, &addr, &lt_pref,
-                                                  &lt_valid) == -ENOMSG);
+        assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref,
+                                             &lt_valid) == -ENOMSG);
 
         return 0;
 }
 
         return 0;
 }
index 1126f1a..716d767 100644 (file)
 
 typedef struct sd_dhcp6_lease sd_dhcp6_lease;
 
 
 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);
+void sd_dhcp6_lease_reset_address_iter(sd_dhcp6_lease *lease);
+int sd_dhcp6_lease_get_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);
 
 sd_dhcp6_lease *sd_dhcp6_lease_ref(sd_dhcp6_lease *lease);
 sd_dhcp6_lease *sd_dhcp6_lease_unref(sd_dhcp6_lease *lease);