[systemd-devel] [PATCH v2 22/26] dhcp: Add maximum message size option

Patrik Flykt patrik.flykt at linux.intel.com
Sun Nov 24 23:13:38 PST 2013


Add maximum message size option to keep some DHCP server implementations
from sending too big messages. See ConnMan commit
0c5c862749c05193cf4c513628328c6db02b5222.
---
 src/dhcp/client.c   |   12 ++++++++++++
 src/dhcp/protocol.h |    1 +
 2 files changed, 13 insertions(+)

diff --git a/src/dhcp/client.c b/src/dhcp/client.c
index 779c8e0..1c6602c 100644
--- a/src/dhcp/client.c
+++ b/src/dhcp/client.c
@@ -185,6 +185,7 @@ static int client_packet_init(DHCPClient *client, uint8_t type,
                               uint8_t **opt, int *optlen)
 {
         int err;
+        be16_t max_size;
 
         *opt = (uint8_t *)(message + 1);
 
@@ -228,6 +229,17 @@ static int client_packet_init(DHCPClient *client, uint8_t type,
                                          client->req_opts);
                 if (err < 0)
                         return err;
+
+                /* Some DHCP servers will send bigger DHCP packets than the
+                   defined default size unless the Maximum Messge Size option
+                   is explicitely set */
+                max_size = htobe16(DHCP_IP_UDP_SIZE + DHCP_MESSAGE_SIZE +
+                                   DHCP_CLIENT_MIN_OPTIONS_SIZE);
+                err = dhcp_option_append(opt, optlen,
+                                         DHCP_OPTION_MAXIMUM_MESSAGE_SIZE,
+                                         2, &max_size);
+                if (err < 0)
+                        return err;
         }
 
         return 0;
diff --git a/src/dhcp/protocol.h b/src/dhcp/protocol.h
index 95c4f4e..f5f490d 100644
--- a/src/dhcp/protocol.h
+++ b/src/dhcp/protocol.h
@@ -111,6 +111,7 @@ enum {
         DHCP_OPTION_MESSAGE_TYPE                = 53,
         DHCP_OPTION_SERVER_IDENTIFIER           = 54,
         DHCP_OPTION_PARAMETER_REQUEST_LIST      = 55,
+        DHCP_OPTION_MAXIMUM_MESSAGE_SIZE        = 57,
         DHCP_OPTION_CLIENT_IDENTIFIER           = 61,
         DHCP_OPTION_END                         = 255,
 };
-- 
1.7.10.4



More information about the systemd-devel mailing list