Minimum message size is now 300 bytes for crappy DHCP servers :/

This commit is contained in:
Roy Marples 2007-04-11 19:44:37 +00:00
parent 378dcbd5d5
commit 750bc1d4f8
3 changed files with 55 additions and 44 deletions

View File

@ -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

8
dhcp.c
View File

@ -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,

8
dhcp.h
View File

@ -31,6 +31,7 @@
#include "dhcpcd.h"
#include "interface.h"
/* Max MTU - defines dhcp option length */
#define MTU_MAX 1500
#define MTU_MIN 576
@ -40,6 +41,7 @@
#define DHCP_CLIENT_PORT 68
#define MAGIC_COOKIE 0x63825363
#define BROADCAST_FLAG 0x8000
/* DHCP message OP code */
#define DHCP_BOOTREQUEST 1
@ -55,7 +57,6 @@
#define DHCP_RELEASE 7
#define DHCP_INFORM 8
/* DHCP options */
enum DHCP_OPTIONS
{
@ -152,6 +153,8 @@ typedef struct dhcp_t
char *rootpath;
} dhcp_t;
/* Sizes for DHCP options */
#define DHCP_CHADDR_LEN 16
#define SERVERNAME_LEN 64
@ -164,6 +167,9 @@ typedef struct dhcp_t
#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
{
unsigned char op; /* message type */