Commit aa1bc0bf authored by Dan Williams's avatar Dan Williams
Browse files

2005-02-12 Dan Williams <dcbw@redhat.com>

	* 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
parent 30a4db20
2005-02-12 Dan Williams <dcbw@redhat.com>
* dhcpcd/buildmsg.c
- Pad DHCP packets until they are at least 300 bytes in size.
2005-02-11 Dan Williams <dcbw@redhat.com>
* dhcpcd/client.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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment