chiark / gitweb /
sd-dhcp: message_init - only set secs in the client
authorTom Gundersen <teg@jklm.no>
Sun, 23 Feb 2014 21:07:07 +0000 (22:07 +0100)
committerTom Gundersen <teg@jklm.no>
Sun, 23 Feb 2014 22:00:18 +0000 (23:00 +0100)
src/libsystemd-dhcp/dhcp-internal.h
src/libsystemd-dhcp/dhcp-packet.c
src/libsystemd-dhcp/sd-dhcp-client.c

index 9a997c1..7b2e35c 100644 (file)
@@ -46,7 +46,7 @@ int dhcp_option_parse(DHCPMessage *message, size_t len,
                       dhcp_option_cb_t cb, void *user_data);
 
 int dhcp_message_init(DHCPMessage *message, uint8_t op, uint32_t xid, uint8_t type,
-                      uint16_t secs, uint8_t **opt, size_t *optlen);
+                      uint8_t **opt, size_t *optlen);
 
 void dhcp_packet_append_ip_headers(DHCPPacket *packet, uint16_t len);
 
index 13881ea..1937de4 100644 (file)
 #define DHCP_CLIENT_MIN_OPTIONS_SIZE            312
 
 int dhcp_message_init(DHCPMessage *message, uint8_t op, uint32_t xid,
-                      uint8_t type, uint16_t secs, uint8_t **opt,
-                      size_t *optlen) {
+                      uint8_t type, uint8_t **opt, size_t *optlen) {
         int err;
 
+        assert(op == BOOTREQUEST || op == BOOTREPLY);
+
         *opt = (uint8_t *)(message + 1);
 
         if (*optlen < 4)
@@ -52,10 +53,6 @@ int dhcp_message_init(DHCPMessage *message, uint8_t op, uint32_t xid,
         message->hlen = ETHER_ADDR_LEN;
         message->xid = htobe32(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);
-
         (*opt)[0] = 0x63;
         (*opt)[1] = 0x82;
         (*opt)[2] = 0x53;
index 63b7b24..01397cf 100644 (file)
@@ -206,11 +206,17 @@ static int client_message_init(sd_dhcp_client *client, DHCPMessage *message,
                                size_t *optlen) {
         int r;
 
-        r = dhcp_message_init(message, BOOTREQUEST, client->xid, type,
-                              secs, opt, optlen);
+        assert(secs);
+
+        r = dhcp_message_init(message, BOOTREQUEST, client->xid, type, opt,
+                              optlen);
         if (r < 0)
                 return r;
 
+        /* 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);
 
         if (client->state == DHCP_STATE_RENEWING ||