[systemd-commits] 3 commits - TODO src/libsystemd-network

Patrik Flykt pflykt at kemper.freedesktop.org
Wed Sep 10 03:02:49 PDT 2014


 TODO                                       |    1 
 src/libsystemd-network/sd-dhcp6-client.c   |   40 +++++++++++++++++++++--------
 src/libsystemd-network/test-dhcp6-client.c |   32 ++++++++++++++++++++---
 3 files changed, 58 insertions(+), 15 deletions(-)

New commits:
commit e9385929c8eb591b64e657a5d53d187af418a3f7
Author: Patrik Flykt <patrik.flykt at linux.intel.com>
Date:   Mon Sep 1 13:21:35 2014 +0300

    TODO: Remove Elapsed Time DHCPv6 option as it is done

diff --git a/TODO b/TODO
index f036430..9ac6fac 100644
--- a/TODO
+++ b/TODO
@@ -703,7 +703,6 @@ Features:
    - implement reconfigure support, see 5.3., 15.11. and 22.20.
    - implement information request, see 1.2. and 18.1.5.
    - implement support for temporary adressess (IA_TA)
-   - implement elapsed time option
    - implement dhcpv6 authentication
    - investigate the usefulness of Confirm messages; i.e. are there any
      situations where the link changes without any loss in carrier detection

commit d63be95a306bf1e262c7e1c7ad4b2c12b49d371e
Author: Patrik Flykt <patrik.flykt at linux.intel.com>
Date:   Mon Sep 1 13:21:34 2014 +0300

    test-dhcp6-client: Add checks for Elapsed Time option
    
    Verify that the Elapsed Time option is present.

diff --git a/src/libsystemd-network/test-dhcp6-client.c b/src/libsystemd-network/test-dhcp6-client.c
index d102a79..37ddfc2 100644
--- a/src/libsystemd-network/test-dhcp6-client.c
+++ b/src/libsystemd-network/test-dhcp6-client.c
@@ -269,6 +269,11 @@ static int test_advertise_option(sd_event *e) {
                                                              *optval) >= 0);
                         break;
 
+                case DHCP6_OPTION_ELAPSED_TIME:
+                        assert_se(optlen == 2);
+
+                        break;
+
                 default:
                         break;
                 }
@@ -361,7 +366,8 @@ static int test_client_verify_request(DHCP6Message *request, uint8_t *option,
         uint8_t *optval;
         uint16_t optcode;
         size_t optlen;
-        bool found_clientid = false, found_iana = false, found_serverid = false;
+        bool found_clientid = false, found_iana = false, found_serverid = false,
+                found_elapsed_time = false;
         int r;
         struct in6_addr addr;
         be32_t val;
@@ -410,11 +416,20 @@ static int test_client_verify_request(DHCP6Message *request, uint8_t *option,
                         assert_se(!memcmp(&msg_advertise[179], optval, optlen));
 
                         break;
+
+                case DHCP6_OPTION_ELAPSED_TIME:
+                        assert_se(!found_elapsed_time);
+                        found_elapsed_time = true;
+
+                        assert_se(optlen == 2);
+
+                        break;
                 }
         }
 
         assert_se(r == -ENOMSG);
-        assert_se(found_clientid && found_iana && found_serverid);
+        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);
@@ -452,7 +467,8 @@ static int test_client_verify_solicit(DHCP6Message *solicit, uint8_t *option,
         uint8_t *optval;
         uint16_t optcode;
         size_t optlen;
-        bool found_clientid = false, found_iana = false;
+        bool found_clientid = false, found_iana = false,
+                found_elapsed_time = false;
         int r;
 
         assert_se(solicit->type == DHCP6_SOLICIT);
@@ -478,11 +494,19 @@ static int test_client_verify_solicit(DHCP6Message *solicit, uint8_t *option,
                         memcpy(&test_iaid, optval, sizeof(test_iaid));
 
                         break;
+
+                case DHCP6_OPTION_ELAPSED_TIME:
+                        assert_se(!found_elapsed_time);
+                        found_elapsed_time = true;
+
+                        assert_se(optlen == 2);
+
+                        break;
                 }
         }
 
         assert_se(r == -ENOMSG);
-        assert_se(found_clientid && found_iana);
+        assert_se(found_clientid && found_iana && found_elapsed_time);
 
         return 0;
 }

commit 346e13a25dc6f76d3bc9d8decd40dc4782b02d2a
Author: Patrik Flykt <patrik.flykt at linux.intel.com>
Date:   Mon Sep 1 13:21:33 2014 +0300

    sd-dhcp6-client: Implement Elapsed Time option
    
    Implement Elapsed Time option as it is defined as MUST in RFC 3315,
    section 22.9. The elapsed time value is a 1/100th of a second with
    a max value of 0xffff, i.e. 655.35 seconds.
    
    As the main loop might not be running yet when sd_dhcp6_client_start() is
    called, fetch the monotonic time directly and not from the event loop
    while in state DHCP6_STATE_STOPPED.

diff --git a/src/libsystemd-network/sd-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c
index 6860c66..c190b56 100644
--- a/src/libsystemd-network/sd-dhcp6-client.c
+++ b/src/libsystemd-network/sd-dhcp6-client.c
@@ -49,6 +49,7 @@ struct sd_dhcp6_client {
         struct ether_addr mac_addr;
         DHCP6IA ia_na;
         be32_t transaction_id;
+        usec_t transaction_start;
         struct sd_dhcp6_lease *lease;
         int fd;
         be16_t *req_opts;
@@ -203,6 +204,7 @@ static int client_reset(sd_dhcp6_client *client) {
         client->fd = safe_close(client->fd);
 
         client->transaction_id = 0;
+        client->transaction_start = 0;
 
         client->ia_na.timeout_t1 =
                 sd_event_source_unref(client->ia_na.timeout_t1);
@@ -230,13 +232,15 @@ static void client_stop(sd_dhcp6_client *client, int error) {
         client_reset(client);
 }
 
-static int client_send_message(sd_dhcp6_client *client) {
+static int client_send_message(sd_dhcp6_client *client, usec_t time_now) {
         _cleanup_free_ DHCP6Message *message = NULL;
         struct in6_addr all_servers =
                 IN6ADDR_ALL_DHCP6_RELAY_AGENTS_AND_SERVERS_INIT;
         size_t len, optlen = 512;
         uint8_t *opt;
         int r;
+        usec_t elapsed_usec;
+        be16_t elapsed_time;
 
         len = sizeof(DHCP6Message) + optlen;
 
@@ -308,6 +312,17 @@ static int client_send_message(sd_dhcp6_client *client) {
         if (r < 0)
                 return r;
 
+        elapsed_usec = time_now - client->transaction_start;
+        if (elapsed_usec < 0xffff * USEC_PER_MSEC * 10)
+                elapsed_time = htobe16(elapsed_usec / USEC_PER_MSEC / 10);
+        else
+                elapsed_time = 0xffff;
+
+        r = dhcp6_option_append(&opt, &optlen, DHCP6_OPTION_ELAPSED_TIME,
+                                sizeof(elapsed_time), &elapsed_time);
+        if (r < 0)
+                return r;
+
         r = dhcp6_network_send_udp_socket(client->fd, &all_servers, message,
                                           len - optlen);
         if (r < 0)
@@ -455,15 +470,14 @@ static int client_timeout_resend(sd_event_source *s, uint64_t usec,
                 return 0;
         }
 
-        r = client_send_message(client);
-        if (r >= 0)
-                client->retransmit_count++;
-
-
         r = sd_event_now(client->event, clock_boottime_or_monotonic(), &time_now);
         if (r < 0)
                 goto error;
 
+        r = client_send_message(client, time_now);
+        if (r >= 0)
+                client->retransmit_count++;
+
         if (!client->retransmit_time) {
                 client->retransmit_time =
                         client_timeout_compute_random(init_retransmit_time);
@@ -882,6 +896,15 @@ static int client_start(sd_dhcp6_client *client, enum DHCP6State state)
         client->retransmit_time = 0;
         client->retransmit_count = 0;
 
+        if (client->state == DHCP6_STATE_STOPPED) {
+                time_now = now(clock_boottime_or_monotonic());
+        } else {
+                r = sd_event_now(client->event, clock_boottime_or_monotonic(),
+                                 &time_now);
+                if (r < 0)
+                        return r;
+        }
+
         switch (state) {
         case DHCP6_STATE_STOPPED:
         case DHCP6_STATE_SOLICITATION:
@@ -926,10 +949,6 @@ static int client_start(sd_dhcp6_client *client, enum DHCP6State state)
 
         case DHCP6_STATE_BOUND:
 
-                r = sd_event_now(client->event, clock_boottime_or_monotonic(), &time_now);
-                if (r < 0)
-                        return r;
-
                 if (client->lease->ia.lifetime_t1 == 0xffffffff ||
                     client->lease->ia.lifetime_t2 == 0xffffffff) {
 
@@ -996,6 +1015,7 @@ static int client_start(sd_dhcp6_client *client, enum DHCP6State state)
         }
 
         client->transaction_id = random_u32() & htobe32(0x00ffffff);
+        client->transaction_start = time_now;
 
         r = sd_event_add_time(client->event, &client->timeout_resend,
                               clock_boottime_or_monotonic(), 0, 0, client_timeout_resend,



More information about the systemd-commits mailing list