summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPatrik Flykt <patrik.flykt@linux.intel.com>2013-12-09 23:43:22 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-12-12 11:43:34 -0500
commitf5a70de7a9a9e8a37ba96f89ad75fcc31336bfa3 (patch)
treebc4d77516a61aa98f29a9bc95a9eaad54bf27cf6 /src
parent290c7324ca6ed22bcb6f4d644765aefeb47dc9de (diff)
dhcp: Support seconds elapsed since start of DHCP negotiation
It was noticed by Grant Erickson in ConnMan commit 95e15c09350acf58d4707056ae2614570883ef66 that: "Certain DHCP servers, such as that implemented in Mac OS X (< 10.7) for its "Internet Sharing" feature, refuse to issue a DHCP lease to clients that have not set a non-zero value in their DISCOVER or REQUEST packets."
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd-dhcp/dhcp-client.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/libsystemd-dhcp/dhcp-client.c b/src/libsystemd-dhcp/dhcp-client.c
index 4d1722f5b3..181c6f8348 100644
--- a/src/libsystemd-dhcp/dhcp-client.c
+++ b/src/libsystemd-dhcp/dhcp-client.c
@@ -120,8 +120,8 @@ int sd_dhcp_client_set_mac(sd_dhcp_client *client,
}
static int client_packet_init(sd_dhcp_client *client, uint8_t type,
- DHCPMessage *message, uint8_t **opt,
- size_t *optlen)
+ DHCPMessage *message, uint16_t secs,
+ uint8_t **opt, size_t *optlen)
{
int err;
@@ -136,6 +136,10 @@ static int client_packet_init(sd_dhcp_client *client, uint8_t type,
message->hlen = ETHER_ADDR_LEN;
message->xid = htobe32(client->xid);
+ /* Although 'secs' field is a SHOULD in RFC 2131, certain DHCP servers
+ refuse to issue an DHCP lease if 'secs' is set to zero */
+ message->secs = htobe16(secs);
+
memcpy(&message->chaddr, &client->mac_addr, ETH_ALEN);
(*opt)[0] = 0x63;
(*opt)[1] = 0x82;
@@ -189,7 +193,7 @@ static uint16_t client_checksum(void *buf, int len)
return ~((sum & 0xffff) + (sum >> 16));
}
-static int client_send_discover(sd_dhcp_client *client)
+static int client_send_discover(sd_dhcp_client *client, uint16_t secs)
{
int err = 0;
_cleanup_free_ DHCPPacket *discover;
@@ -205,7 +209,7 @@ static int client_send_discover(sd_dhcp_client *client)
return -ENOMEM;
err = client_packet_init(client, DHCP_DISCOVER, &discover->dhcp,
- &opt, &optlen);
+ secs, &opt, &optlen);
if (err < 0)
return err;
@@ -256,7 +260,7 @@ int sd_dhcp_client_start(sd_dhcp_client *client)
client->xid = random_u();
- return client_send_discover(client);
+ return client_send_discover(client, 0);
}
sd_dhcp_client *sd_dhcp_client_new(void)