]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Minimum message size is now 300 bytes for crappy DHCP servers :/
authorRoy Marples <roy@marples.name>
Wed, 11 Apr 2007 19:44:37 +0000 (19:44 +0000)
committerRoy Marples <roy@marples.name>
Wed, 11 Apr 2007 19:44:37 +0000 (19:44 +0000)
ChangeLog
dhcp.c
dhcp.h

index 6619da8b78268e05a8b5554389fcd294557ccece..20f7224c056838b79ae1e85a406851a4bf8db1a6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+Minimum message size is now 300 bytes for crappy DHCP servers :/
 Compile ok on OpenBSD (thanks to icezimm and reb in #gentoo-bsd for testing)
 We check gcc supports -Wextra and friends before using them.
 We now restore the starting MTU value when we exit OR we don't receive a
diff --git a/dhcp.c b/dhcp.c
index 2f58e77c18f756bf2df06f23fa67e6c048b31a44..ae9b85dfc6d09146aa91730f8b2ac7fad0334f14 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -38,8 +38,6 @@
 #include "logger.h"
 #include "socket.h"
 
-#define BROADCAST_FLAG 0x8000
-
 static const char *dhcp_message[] = {
        [DHCP_DISCOVER]         = "DHCP_DISCOVER",
        [DHCP_OFFER]            = "DHCP_OFFER",
@@ -248,7 +246,13 @@ size_t send_message (const interface_t *iface, const dhcp_t *dhcp,
 
        *p++ = DHCP_END;
 
+#ifdef DHCP_MESSAGE_LENTH_MIN
+       while (p - m < DHCP_MESSAGE_LENTH_MIN)
+               *p++ = DHCP_PAD;
+#endif
+
        message_length = p - m;
+       logger (LOG_DEBUG, "xx %d\n", message_length);
 
        memset (&packet, 0, sizeof (struct udp_dhcp_packet));
        make_dhcp_packet (&packet, (unsigned char *) &message, message_length,
diff --git a/dhcp.h b/dhcp.h
index 95ac66dffc37c9d2a1133ba90a738b01812485a0..92ee7efd5e7e22701d7cef9a29a7ab590193833f 100644 (file)
--- a/dhcp.h
+++ b/dhcp.h
 #include "dhcpcd.h"
 #include "interface.h"
 
+
 /* Max MTU - defines dhcp option length */
-#define MTU_MAX                        1500
-#define MTU_MIN                        576
+#define MTU_MAX                                1500
+#define MTU_MIN                                576
 
 /* UDP port numbers for DHCP */
-#define DHCP_SERVER_PORT 67
-#define DHCP_CLIENT_PORT 68
+#define DHCP_SERVER_PORT       67
+#define DHCP_CLIENT_PORT       68
 
-#define MAGIC_COOKIE 0x63825363
+#define MAGIC_COOKIE           0x63825363
+#define BROADCAST_FLAG                 0x8000
 
 /* DHCP message OP code */
 #define DHCP_BOOTREQUEST       1
 
 /* DHCP message type */
 #define        DHCP_DISCOVER           1
-#define DHCP_OFFER             2
+#define DHCP_OFFER                     2
 #define        DHCP_REQUEST            3
 #define        DHCP_DECLINE            4
-#define        DHCP_ACK                5
-#define DHCP_NAK               6
+#define        DHCP_ACK                        5
+#define DHCP_NAK                       6
 #define        DHCP_RELEASE            7
-#define DHCP_INFORM            8
-
+#define DHCP_INFORM                    8
 
 /* DHCP options */
 enum DHCP_OPTIONS
 {
-       DHCP_PAD                                =       0,
+       DHCP_PAD                                        =       0,
        DHCP_NETMASK                            =       1,
        DHCP_TIMEROFFSET                        =       2,
        DHCP_ROUTERS                            =       3,
-       DHCP_TIMESERVER                 =       4,
-       DHCP_NAMESERVER                 =       5,
-       DHCP_DNSSERVER                  =       6,
-       DHCP_LOGSERVER                  =       7,
+       DHCP_TIMESERVER                         =       4,
+       DHCP_NAMESERVER                         =       5,
+       DHCP_DNSSERVER                          =       6,
+       DHCP_LOGSERVER                          =       7,
        DHCP_COOKIESERVER                       =       8,
        DHCP_HOSTNAME                           =       12,
-       DHCP_DNSDOMAIN                  =       15,
+       DHCP_DNSDOMAIN                          =       15,
        DHCP_ROOTPATH                           =       17,
        DHCP_DEFAULTIPTTL                       =       23,
-       DHCP_MTU                                =       26,
-       DHCP_BROADCAST                  =       28,
+       DHCP_MTU                                        =       26,
+       DHCP_BROADCAST                          =       28,
        DHCP_MASKDISCOVERY                      =       29,
-       DHCP_ROUTERDISCOVERY                    =       31,
+       DHCP_ROUTERDISCOVERY            =       31,
        DHCP_STATICROUTE                        =       33,
-       DHCP_NISDOMAIN                  =       40,
-       DHCP_NISSERVER                  =       41,
-       DHCP_NTPSERVER                  =       42,
+       DHCP_NISDOMAIN                          =       40,
+       DHCP_NISSERVER                          =       41,
+       DHCP_NTPSERVER                          =       42,
        DHCP_ADDRESS                            =       50,
-       DHCP_LEASETIME                  =       51,
+       DHCP_LEASETIME                          =       51,
        DHCP_MESSAGETYPE                        =       53,
-       DHCP_SERVERIDENTIFIER                   =       54,
-       DHCP_PARAMETERREQUESTLIST               =       55,
+       DHCP_SERVERIDENTIFIER           =       54,
+       DHCP_PARAMETERREQUESTLIST       =       55,
        DHCP_MESSAGE                            =       56,
        DHCP_MAXMESSAGESIZE                     =       57,
        DHCP_RENEWALTIME                        =       58,
-       DHCP_REBINDTIME                 =       59,
+       DHCP_REBINDTIME                         =       59,
        DHCP_CLASSID                            =       60,
        DHCP_CLIENTID                           =       61,
-       DHCP_USERCLASS                  =       77,  /* RFC 3004 */
-       DHCP_FQDN                               =       81,
-       DHCP_DNSSEARCH                  =       119, /* RFC 3397 */
-       DHCP_CSR                                =       121, /* RFC 3442 */
-       DHCP_END                                =       255
+       DHCP_USERCLASS                          =       77,  /* RFC 3004 */
+       DHCP_FQDN                                       =       81,
+       DHCP_DNSSEARCH                          =       119, /* RFC 3397 */
+       DHCP_CSR                                        =       121, /* RFC 3442 */
+       DHCP_END                                        =       255
 };
 
 /* SetFQDNHostName values - lsnybble used in flags
@@ -103,7 +104,7 @@ enum DHCP_OPTIONS
  * and to allow 0x00 to mean disable
  */
 enum FQQN {
-       FQDN_DISABLE                            =       0x00,
+       FQDN_DISABLE                    =       0x00,
        FQDN_NONE                               =       0x18,
        FQDN_PTR                                =       0x20,
        FQDN_BOTH                               =       0x31
@@ -152,17 +153,22 @@ typedef struct dhcp_t
        char *rootpath;
 } dhcp_t;
 
+
+
 /* Sizes for DHCP options */
-#define DHCP_CHADDR_LEN                16
-#define SERVERNAME_LEN         64
-#define BOOTFILE_LEN           128
-#define DHCP_UDP_LEN           (20 + 8)
-#define DHCP_BASE_LEN          (4 + 4 + 2 + 2 + 4 + 4 + 4 + 4 + 4)
-#define DHCP_RESERVE_LEN       (4 + 4 + 4 + 4 + 2)
-#define DHCP_FIXED_LEN         (DHCP_BASE_LEN + DHCP_CHADDR_LEN + \
-                                                        + SERVERNAME_LEN + BOOTFILE_LEN)
-#define DHCP_OPTION_LEN                (MTU_MAX - DHCP_FIXED_LEN - DHCP_UDP_LEN \
-                                                        - DHCP_RESERVE_LEN)
+#define DHCP_CHADDR_LEN                        16
+#define SERVERNAME_LEN                 64
+#define BOOTFILE_LEN                   128
+#define DHCP_UDP_LEN                   (20 + 8)
+#define DHCP_BASE_LEN                  (4 + 4 + 2 + 2 + 4 + 4 + 4 + 4 + 4)
+#define DHCP_RESERVE_LEN               (4 + 4 + 4 + 4 + 2)
+#define DHCP_FIXED_LEN                 (DHCP_BASE_LEN + DHCP_CHADDR_LEN + \
+                                                               + SERVERNAME_LEN + BOOTFILE_LEN)
+#define DHCP_OPTION_LEN                        (MTU_MAX - DHCP_FIXED_LEN - DHCP_UDP_LEN \
+                                                               - DHCP_RESERVE_LEN)
+
+/* Some crappy DHCP servers require the BOOTP minimum length */
+#define DHCP_MESSAGE_LENTH_MIN 300
 
 typedef struct dhcpmessage_t
 {