diff --git a/ChangeLog b/ChangeLog index 6619da8b..20f7224c 100644 --- 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 2f58e77c..ae9b85df 100644 --- 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 95ac66df..92ee7efd 100644 --- a/dhcp.h +++ b/dhcp.h @@ -31,15 +31,17 @@ #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 @@ -47,55 +49,54 @@ /* 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 {