[systemd-devel] [PATCH 17/28] dhcp: Support seconds elapsed since start of DHCP negotiation

Patrik Flykt patrik.flykt at linux.intel.com
Wed Nov 13 13:22:45 PST 2013


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."
---
 src/dhcp/client.c |   11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/dhcp/client.c b/src/dhcp/client.c
index 1d4d957..dc92880 100644
--- a/src/dhcp/client.c
+++ b/src/dhcp/client.c
@@ -134,8 +134,8 @@ int dhcp_client_set_mac(DHCPClient *client, struct ether_addr *addr)
 }
 
 static int client_packet_init(DHCPClient *client, uint8_t type,
-                              DHCPMessage *message, uint8_t **opt,
-                              int *optlen)
+                              DHCPMessage *message, uint16_t secs,
+                              uint8_t **opt, int *optlen)
 {
         int err;
 
@@ -149,6 +149,7 @@ static int client_packet_init(DHCPClient *client, uint8_t type,
         message->htype = 1;
         message->hlen = ETHER_ADDR_LEN;
         message->xid = htonl(client->xid);
+        message->secs = htons(secs);
 
         memcpy(&message->chaddr, &client->mac_addr, ETH_ALEN);
         (*opt)[0] = 0x63;
@@ -202,7 +203,7 @@ static uint16_t client_checksum(void *buf, int len)
         return ~((sum & 0xffff) + (sum >> 16));
 }
 
-static int client_send_discover(DHCPClient *client)
+static int client_send_discover(DHCPClient *client, uint16_t secs)
 {
         int err = 0;
         DHCPPacket *discover;
@@ -218,7 +219,7 @@ static int client_send_discover(DHCPClient *client)
                 return -ENOBUFS;
 
         err = client_packet_init(client, DHCP_DISCOVER, &discover->dhcp,
-                                 &opt, &optlen);
+                                 secs, &opt, &optlen);
         if (err < 0)
                 goto error;
 
@@ -274,7 +275,7 @@ int dhcp_client_start(DHCPClient *client)
 
         client->xid = random_u();
 
-        return client_send_discover(client);
+        return client_send_discover(client, 0);
 }
 
 DHCPClient *dhcp_client_new(void)
-- 
1.7.10.4



More information about the systemd-devel mailing list