summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrik Flykt <patrik.flykt@linux.intel.com>2014-01-31 11:31:25 +0200
committerTom Gundersen <teg@jklm.no>2014-01-31 12:04:51 +0100
commit40e39f628308683fda5f77b43afd245b62958641 (patch)
treecc032063a837828c5146e20bc4d83c27a300b9e3
parentf8fdefe4f50c5b1b34cd018e649deddd7af2519f (diff)
libsystemd-dhcp: Update secs field only when sending Discover
Compute the 'secs' field as seconds since start of lease acquisition procedure. Start off with a value of zero and increase it only for each resent DHCP discover message. See the discussion before and after http://www.ietf.org/mail-archive/web/dhcwg/current/msg05836.html and Section 3.1 of RFC 2131.
-rw-r--r--src/libsystemd-dhcp/sd-dhcp-client.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/libsystemd-dhcp/sd-dhcp-client.c b/src/libsystemd-dhcp/sd-dhcp-client.c
index 4038785079..3b3785809e 100644
--- a/src/libsystemd-dhcp/sd-dhcp-client.c
+++ b/src/libsystemd-dhcp/sd-dhcp-client.c
@@ -75,6 +75,7 @@ struct sd_dhcp_client {
struct ether_addr mac_addr;
uint32_t xid;
usec_t start_time;
+ uint16_t secs;
unsigned int attempt;
usec_t request_sent;
sd_event_source *timeout_t1;
@@ -303,6 +304,7 @@ static int client_stop(sd_dhcp_client *client, int error) {
client_notify(client, error);
client->start_time = 0;
+ client->secs = 0;
client->state = DHCP_STATE_INIT;
if (client->lease) {
@@ -515,12 +517,18 @@ static int client_send_request(sd_dhcp_client *client, uint16_t secs) {
return err;
}
+static uint16_t client_update_secs(sd_dhcp_client *client, usec_t time_now)
+{
+ client->secs = (time_now - client->start_time) / USEC_PER_SEC;
+
+ return client->secs;
+}
+
static int client_timeout_resend(sd_event_source *s, uint64_t usec,
void *userdata) {
sd_dhcp_client *client = userdata;
usec_t next_timeout = 0;
uint32_t time_left;
- uint16_t secs;
int r = 0;
assert(s);
@@ -575,11 +583,12 @@ static int client_timeout_resend(sd_event_source *s, uint64_t usec,
if (r < 0)
goto error;
- secs = (usec - client->start_time) / USEC_PER_SEC;
-
switch (client->state) {
case DHCP_STATE_INIT:
- r = client_send_discover(client, secs);
+
+ client_update_secs(client, usec);
+
+ r = client_send_discover(client, client->secs);
if (r >= 0) {
client->state = DHCP_STATE_SELECTING;
client->attempt = 1;
@@ -591,7 +600,9 @@ static int client_timeout_resend(sd_event_source *s, uint64_t usec,
break;
case DHCP_STATE_SELECTING:
- r = client_send_discover(client, secs);
+ client_update_secs(client, usec);
+
+ r = client_send_discover(client, client->secs);
if (r < 0 && client->attempt >= 64)
goto error;
@@ -600,7 +611,7 @@ static int client_timeout_resend(sd_event_source *s, uint64_t usec,
case DHCP_STATE_REQUESTING:
case DHCP_STATE_RENEWING:
case DHCP_STATE_REBINDING:
- r = client_send_request(client, secs);
+ r = client_send_request(client, client->secs);
if (r < 0 && client->attempt >= 64)
goto error;
@@ -1145,6 +1156,7 @@ int sd_dhcp_client_start(sd_dhcp_client *client) {
client->fd = r;
client->start_time = now(CLOCK_MONOTONIC);
+ client->secs = 0;
return client_initialize_events(client, client->start_time);
}