From aa1bc0bfdb1480c2641666dec2111c71be7c09ac Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Sat, 12 Feb 2005 21:27:38 +0000 Subject: [PATCH] 2005-02-12 Dan Williams * dhcpcd/buildmsg.c - Pad DHCP packets until they are at least 300 bytes in size. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@441 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 5 +++++ dhcpcd/buildmsg.c | 43 +++++++++++++++++++++++++++---------------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 19ed7ddd5..b37cdb7d5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-02-12 Dan Williams + + * dhcpcd/buildmsg.c + - Pad DHCP packets until they are at least 300 bytes in size. + 2005-02-11 Dan Williams * dhcpcd/client.c diff --git a/dhcpcd/buildmsg.c b/dhcpcd/buildmsg.c index 79b8ec755..9fb06336c 100644 --- a/dhcpcd/buildmsg.c +++ b/dhcpcd/buildmsg.c @@ -138,7 +138,8 @@ unsigned char *fill_server_id (unsigned int *server_id, unsigned char *p) /*****************************************************************************/ unsigned char *fill_message_type (unsigned char request, unsigned char *p) { - const unsigned short dhcpMsgSize = htons (sizeof (dhcpMessage)); +#define MAX_DHCP_MSG_SIZE 576 + const unsigned short dhcpMsgSize = htons (MAX_DHCP_MSG_SIZE); *p++ = dhcpMessageType; *p++ = 1; @@ -150,6 +151,15 @@ unsigned char *fill_message_type (unsigned char request, unsigned char *p) return p; } /*****************************************************************************/ +unsigned char *fill_padding (dhcpMessage *start, unsigned char *p) +{ +#define PAD_STOP 304 /* DHCP messages must be at least 300 bytes long. +4 for good measure */ + + while ((char *)p - (char *)start < PAD_STOP) + *p++ = 0; + return p; +} +/*****************************************************************************/ udpipMessage *build_dhcp_discover (dhcp_interface *iface, int *msg_len) { udpipMessage *udp_msg = calloc (1, sizeof (udpipMessage)); @@ -171,9 +181,9 @@ udpipMessage *build_dhcp_discover (dhcp_interface *iface, int *msg_len) p = fill_param_request (p); p = fill_host_and_class_id (iface, p); *p++ = endOption; + p = fill_padding (dhcp_msg, p); /* build UDP/IP header */ - p++; dhcp_msg_len = (char *)p - (char *)dhcp_msg; udpipgen ((udpiphdr *)(udp_msg->udpipmsg), 0, INADDR_BROADCAST, &iface->ip_id, dhcp_msg_len); *msg_len = (char *)p - (char *)udp_msg; @@ -198,10 +208,10 @@ udpipMessage *build_dhcp_request (dhcp_interface *iface, int *msg_len) p = fill_lease_time (iface->dhcp_options.val[dhcpIPaddrLeaseTime], p); p = fill_param_request (p); p = fill_host_and_class_id (iface, p); - *p = endOption; + *p++ = endOption; + p = fill_padding (dhcp_msg, p); /* build UDP/IP header */ - p++; dhcp_msg_len = (char *)p - (char *)dhcp_msg; udpipgen ((udpiphdr *)(udp_msg->udpipmsg), 0, INADDR_BROADCAST, &iface->ip_id, dhcp_msg_len); *msg_len = (char *)(p++) - (char *)udp_msg; @@ -224,9 +234,10 @@ udpipMessage *build_dhcp_renew (dhcp_interface *iface, int *msg_len) #endif p = fill_param_request (p); p = fill_host_and_class_id (iface, p); - *p = endOption; + *p++ = endOption; + p = fill_padding (dhcp_msg, p); - p++; + /* build UDP/IP header */ dhcp_msg_len = (char *)p - (char *)dhcp_msg; udpipgen ((udpiphdr *)(udp_msg->udpipmsg), iface->ciaddr, iface->siaddr, &iface->ip_id, dhcp_msg_len); *msg_len = (char *)(p++) - (char *)udp_msg; @@ -247,10 +258,10 @@ udpipMessage *build_dhcp_rebind (dhcp_interface *iface, int *msg_len) p = fill_lease_time (iface->dhcp_options.val[dhcpIPaddrLeaseTime], p); p = fill_param_request (p); p = fill_host_and_class_id (iface, p); - *p = endOption; + *p++ = endOption; + p = fill_padding (dhcp_msg, p); /* build UDP/IP header */ - p++; dhcp_msg_len = (char *)p - (char *)dhcp_msg; udpipgen ((udpiphdr *)(udp_msg->udpipmsg), iface->ciaddr, INADDR_BROADCAST, &iface->ip_id, dhcp_msg_len); *msg_len = (char *)(p++) - (char *)udp_msg; @@ -274,10 +285,10 @@ udpipMessage *build_dhcp_reboot (dhcp_interface *iface, int *msg_len) p = fill_lease_time (&lease_time, p); p = fill_param_request (p); p = fill_host_and_class_id (iface, p); - *p = endOption; + *p++ = endOption; + p = fill_padding (dhcp_msg, p); /* build UDP/IP header */ - p++; dhcp_msg_len = (char *)p - (char *)dhcp_msg; udpipgen ((udpiphdr *)(udp_msg->udpipmsg), 0, INADDR_BROADCAST, &iface->ip_id, dhcp_msg_len); *msg_len = (char *)(p++) - (char *)udp_msg; @@ -299,10 +310,10 @@ udpipMessage *build_dhcp_release (dhcp_interface *iface, int *msg_len) p = fill_server_id (iface->dhcp_options.val[dhcpServerIdentifier], p); memcpy(p, iface->cli_id, iface->cli_id_len); p += iface->cli_id_len; - *p = endOption; + *p++ = endOption; + p = fill_padding (dhcp_msg, p); /* build UDP/IP header */ - p++; dhcp_msg_len = (char *)p - (char *)dhcp_msg; udpipgen ((udpiphdr *)(udp_msg->udpipmsg), iface->ciaddr, iface->siaddr, &iface->ip_id, dhcp_msg_len); *msg_len = (char *)(p++) - (char *)udp_msg; @@ -328,10 +339,10 @@ udpipMessage *build_dhcp_decline (dhcp_interface *iface, int *msg_len) p = fill_requested_ipaddr (iface, p); memcpy (p, iface->cli_id, iface->cli_id_len); p += iface->cli_id_len; - *p = endOption; + *p++ = endOption; + p = fill_padding (dhcp_msg, p); /* build UDP/IP header */ - p++; dhcp_msg_len = (char *)p - (char *)dhcp_msg; udpipgen ((udpiphdr *)(udp_msg->udpipmsg), 0, iface->siaddr, &iface->ip_id, dhcp_msg_len); *msg_len = (char *)(p++) - (char *)udp_msg; @@ -351,10 +362,10 @@ udpipMessage *build_dhcp_inform (dhcp_interface *iface, int *msg_len) p = fill_message_type (DHCP_INFORM, p); p = fill_param_request (p); p = fill_host_and_class_id (iface, p); - *p = endOption; + *p++ = endOption; + p = fill_padding (dhcp_msg, p); /* build UDP/IP header */ - p++; dhcp_msg_len = (char *)p - (char *)dhcp_msg; udpipgen((udpiphdr *)(udp_msg->udpipmsg), 0, INADDR_BROADCAST, &iface->ip_id, dhcp_msg_len); *msg_len = (char *)(p++) - (char *)udp_msg;