[systemd-devel] [PATCH 23/28] dhcp: Add maximum message size option

Patrik Flykt patrik.flykt at linux.intel.com
Wed Nov 13 13:22:51 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   |   10 ++++++++++
 src/dhcp/protocol.h |    1 +
 2 files changed, 11 insertions(+)

diff --git a/src/dhcp/client.c b/src/dhcp/client.c
index 4b316dc..45c62f3 100644
--- a/src/dhcp/client.c
+++ b/src/dhcp/client.c
@@ -206,6 +206,7 @@ static int client_packet_init(DHCPClient *client, uint8_t type,
                               uint8_t **opt, int *optlen)
 {
         int err;
+        uint16_t max_size;
 
         *opt = (uint8_t *)(message + 1);
 
@@ -245,6 +246,15 @@ static int client_packet_init(DHCPClient *client, uint8_t type,
                                            client->req_opts);
                 if (err < 0)
                         return err;
+
+                max_size = htons(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 014a6f8..6503931 100644
--- a/src/dhcp/protocol.h
+++ b/src/dhcp/protocol.h
@@ -99,5 +99,6 @@ typedef enum DHCPState DHCPState;
 #define DHCP_OPTION_MESSAGE_TYPE                53
 #define DHCP_OPTION_SERVER_IDENTIFIER           54
 #define DHCP_OPTION_PARAMETER_REQUEST_LIST      55
+#define DHCP_OPTION_MAXIMUM_MESSAGE_SIZE        57
 #define DHCP_OPTION_CLIENT_IDENTIFIER           61
 #define DHCP_OPTION_END                         255
-- 
1.7.10.4



More information about the systemd-devel mailing list