[systemd-commits] 3 commits - src/libsystemd-dhcp

Tom Gundersen tomegun at kemper.freedesktop.org
Sun Feb 23 14:00:48 PST 2014


 src/libsystemd-dhcp/dhcp-internal.h  |    2 +-
 src/libsystemd-dhcp/dhcp-packet.c    |   19 ++++++++-----------
 src/libsystemd-dhcp/sd-dhcp-client.c |   12 +++++++++---
 3 files changed, 18 insertions(+), 15 deletions(-)

New commits:
commit 279efc700764ebe5c9bb81e3843e61f7798e1794
Author: Tom Gundersen <teg at jklm.no>
Date:   Sun Feb 23 22:09:23 2014 +0100

    sd-dhcp-client: fix max size of REQUEST message

diff --git a/src/libsystemd-dhcp/sd-dhcp-client.c b/src/libsystemd-dhcp/sd-dhcp-client.c
index 01397cf..ee6e89e 100644
--- a/src/libsystemd-dhcp/sd-dhcp-client.c
+++ b/src/libsystemd-dhcp/sd-dhcp-client.c
@@ -303,7 +303,7 @@ static int client_send_request(sd_dhcp_client *client, uint16_t secs) {
         uint8_t *opt;
 
         optlen = DHCP_MIN_OPTIONS_SIZE;
-        len = DHCP_MESSAGE_SIZE + optlen;
+        len = sizeof(DHCPPacket) + optlen;
 
         request = malloc0(len);
         if (!request)

commit 0a1b6da82109c3b08b1f966a1625a77cc312135a
Author: Tom Gundersen <teg at jklm.no>
Date:   Sun Feb 23 22:07:07 2014 +0100

    sd-dhcp: message_init - only set secs in the client

diff --git a/src/libsystemd-dhcp/dhcp-internal.h b/src/libsystemd-dhcp/dhcp-internal.h
index 9a997c1..7b2e35c 100644
--- a/src/libsystemd-dhcp/dhcp-internal.h
+++ b/src/libsystemd-dhcp/dhcp-internal.h
@@ -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);
 
diff --git a/src/libsystemd-dhcp/dhcp-packet.c b/src/libsystemd-dhcp/dhcp-packet.c
index 13881ea..1937de4 100644
--- a/src/libsystemd-dhcp/dhcp-packet.c
+++ b/src/libsystemd-dhcp/dhcp-packet.c
@@ -37,10 +37,11 @@
 #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;
diff --git a/src/libsystemd-dhcp/sd-dhcp-client.c b/src/libsystemd-dhcp/sd-dhcp-client.c
index 63b7b24..01397cf 100644
--- a/src/libsystemd-dhcp/sd-dhcp-client.c
+++ b/src/libsystemd-dhcp/sd-dhcp-client.c
@@ -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 ||

commit 8fa2eeace7beecedb01c82811e28949cacec1236
Author: Tom Gundersen <teg at jklm.no>
Date:   Sun Feb 23 19:21:50 2014 +0100

    sd-dhcp: don't reject packets with the 'wrong' source port
    
    The RFC does not specify that the packets from the DHCP server must come from
    the DHCP server port, only that that's where they should be sent.
    
    This fixes a problem when running networkd in VirtualBox.
    
    Thanks to Sébastien Luttringer for reporting the bug and very patiently testing
    various fixes.

diff --git a/src/libsystemd-dhcp/dhcp-packet.c b/src/libsystemd-dhcp/dhcp-packet.c
index 8f9ec43..13881ea 100644
--- a/src/libsystemd-dhcp/dhcp-packet.c
+++ b/src/libsystemd-dhcp/dhcp-packet.c
@@ -164,7 +164,7 @@ int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len) {
                 return -EINVAL;
         }
 
-        if (hdrlen + be16toh(packet->udp.len) > len) {
+        if (len < hdrlen + be16toh(packet->udp.len)) {
                 log_dhcp_client(client, "ignoring packet: packet (%zu bytes) "
                                 "smaller than expected (%zu) by UDP header", len,
                                 hdrlen + be16toh(packet->udp.len));
@@ -182,10 +182,10 @@ int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len) {
                 }
         }
 
-        if (be16toh(packet->udp.source) != DHCP_PORT_SERVER ||
-            be16toh(packet->udp.dest) != DHCP_PORT_CLIENT) {
-                log_dhcp_client(client, "ignoring packet: wrong ports (source: %u, destination: %u)",
-                                be16toh(packet->udp.source), be16toh(packet->udp.dest));
+        if (be16toh(packet->udp.dest) != DHCP_PORT_CLIENT) {
+                log_dhcp_client(client, "ignoring packet: to port %u, which "
+                                "is not the DHCP client port (%u)",
+                                be16toh(packet->udp.dest), DHCP_PORT_CLIENT);
                 return -EINVAL;
         }
 



More information about the systemd-commits mailing list