[systemd-devel] [PATCH 6/6] libsystemd-dhcp: Update secs field only when sending Discover
Patrik Flykt
patrik.flykt at linux.intel.com
Fri Jan 31 01:31:25 PST 2014
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.
---
src/libsystemd-dhcp/sd-dhcp-client.c | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/src/libsystemd-dhcp/sd-dhcp-client.c b/src/libsystemd-dhcp/sd-dhcp-client.c
index fd32994..f5b4b7d 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;
@@ -318,6 +319,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) {
@@ -550,12 +552,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);
@@ -615,11 +623,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;
@@ -631,7 +640,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;
@@ -641,7 +652,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;
@@ -1207,6 +1218,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);
}
--
1.8.5.2
More information about the systemd-devel
mailing list