[systemd-commits] 5 commits - src/libsystemd-dhcp
Tom Gundersen
tomegun at kemper.freedesktop.org
Fri Jan 31 03:14:02 PST 2014
src/libsystemd-dhcp/sd-dhcp-client.c | 67 +++++++++++++++++------------------
1 file changed, 34 insertions(+), 33 deletions(-)
New commits:
commit 40e39f628308683fda5f77b43afd245b62958641
Author: Patrik Flykt <patrik.flykt at linux.intel.com>
Date: Fri Jan 31 11:31:25 2014 +0200
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.
diff --git a/src/libsystemd-dhcp/sd-dhcp-client.c b/src/libsystemd-dhcp/sd-dhcp-client.c
index 4038785..3b37858 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);
}
commit f8fdefe4f50c5b1b34cd018e649deddd7af2519f
Author: Patrik Flykt <patrik.flykt at linux.intel.com>
Date: Fri Jan 31 11:31:24 2014 +0200
libsystemd-dhcp: Fix stopping of DHCP client
Go back to Init state independent of the current state the client
is in.
diff --git a/src/libsystemd-dhcp/sd-dhcp-client.c b/src/libsystemd-dhcp/sd-dhcp-client.c
index 37fad9a..4038785 100644
--- a/src/libsystemd-dhcp/sd-dhcp-client.c
+++ b/src/libsystemd-dhcp/sd-dhcp-client.c
@@ -302,24 +302,8 @@ static int client_stop(sd_dhcp_client *client, int error) {
client_notify(client, error);
- switch (client->state) {
-
- case DHCP_STATE_INIT:
- case DHCP_STATE_SELECTING:
- case DHCP_STATE_REQUESTING:
- case DHCP_STATE_BOUND:
-
- client->start_time = 0;
- client->state = DHCP_STATE_INIT;
- break;
-
- case DHCP_STATE_INIT_REBOOT:
- case DHCP_STATE_REBOOTING:
- case DHCP_STATE_RENEWING:
- case DHCP_STATE_REBINDING:
-
- break;
- }
+ client->start_time = 0;
+ client->state = DHCP_STATE_INIT;
if (client->lease) {
lease_free(client->lease);
commit 1aed1cbc10d33e5bf5836e6838ac16add2002152
Author: Patrik Flykt <patrik.flykt at linux.intel.com>
Date: Fri Jan 31 11:31:23 2014 +0200
libsystemd-dhcp: Compute UDP checksum only if set
A checksum field with value zero means no UDP checksum has been
computed for the packet.
diff --git a/src/libsystemd-dhcp/sd-dhcp-client.c b/src/libsystemd-dhcp/sd-dhcp-client.c
index 130a61d..37fad9a 100644
--- a/src/libsystemd-dhcp/sd-dhcp-client.c
+++ b/src/libsystemd-dhcp/sd-dhcp-client.c
@@ -838,13 +838,18 @@ static int client_verify_headers(sd_dhcp_client *client, DHCPPacket *message,
hdrlen))
return -EINVAL;
- message->ip.check = message->udp.len;
- message->ip.ttl = 0;
-
- if (hdrlen + be16toh(message->udp.len) > len ||
- client_checksum(&message->ip.ttl, be16toh(message->udp.len) + 12))
+ if (hdrlen + be16toh(message->udp.len) > len)
return -EINVAL;
+ if (message->udp.check) {
+ message->ip.check = message->udp.len;
+ message->ip.ttl = 0;
+
+ if (client_checksum(&message->ip.ttl,
+ be16toh(message->udp.len) + 12))
+ return -EINVAL;
+ }
+
if (be16toh(message->udp.source) != DHCP_PORT_SERVER ||
be16toh(message->udp.dest) != DHCP_PORT_CLIENT)
return -EINVAL;
commit e44127018aaae2126734aca65a3e46dc14bf1825
Author: Patrik Flykt <patrik.flykt at linux.intel.com>
Date: Fri Jan 31 11:31:21 2014 +0200
libsystemd-dhcp: Rename function to be clearer that options are parsed
diff --git a/src/libsystemd-dhcp/sd-dhcp-client.c b/src/libsystemd-dhcp/sd-dhcp-client.c
index 8115b7f..130a61d 100644
--- a/src/libsystemd-dhcp/sd-dhcp-client.c
+++ b/src/libsystemd-dhcp/sd-dhcp-client.c
@@ -726,7 +726,7 @@ static int client_timeout_t1(sd_event_source *s, uint64_t usec, void *userdata)
return client_initialize_events(client, usec);
}
-static int client_parse_offer(uint8_t code, uint8_t len, const uint8_t *option,
+static int client_parse_options(uint8_t code, uint8_t len, const uint8_t *option,
void *user_data) {
DHCPLease *lease = user_data;
be32_t val;
@@ -876,7 +876,7 @@ static int client_receive_offer(sd_dhcp_client *client, DHCPPacket *offer,
return -ENOMEM;
len = len - DHCP_IP_UDP_SIZE;
- r = dhcp_option_parse(&offer->dhcp, len, client_parse_offer,
+ r = dhcp_option_parse(&offer->dhcp, len, client_parse_options,
lease);
if (r != DHCP_OFFER)
return -ENOMSG;
@@ -919,7 +919,7 @@ static int client_receive_ack(sd_dhcp_client *client, const uint8_t *buf,
if (!lease)
return -ENOMEM;
- r = dhcp_option_parse(dhcp, len, client_parse_offer, lease);
+ r = dhcp_option_parse(dhcp, len, client_parse_options, lease);
if (r == DHCP_NAK)
return DHCP_EVENT_NO_LEASE;
commit 74e22380ed1d753130e9194186aefdf58449050e
Author: Patrik Flykt <patrik.flykt at linux.intel.com>
Date: Fri Jan 31 11:31:20 2014 +0200
libsystemd-dhcp: DNS name option must be a multiple of 4 bytes
diff --git a/src/libsystemd-dhcp/sd-dhcp-client.c b/src/libsystemd-dhcp/sd-dhcp-client.c
index 7e5c36a..8115b7f 100644
--- a/src/libsystemd-dhcp/sd-dhcp-client.c
+++ b/src/libsystemd-dhcp/sd-dhcp-client.c
@@ -760,7 +760,7 @@ static int client_parse_offer(uint8_t code, uint8_t len, const uint8_t *option,
break;
case DHCP_OPTION_DOMAIN_NAME_SERVER:
- if (len >= 4) {
+ if (len && !(len % 4)) {
unsigned i;
lease->dns_size = len / 4;
More information about the systemd-commits
mailing list