summaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenys Vlasenko2010-05-31 00:45:09 +0200
committerDenys Vlasenko2010-05-31 00:45:09 +0200
commitb8b72f02f01017d0f9584666fa572221f2b58613 (patch)
tree544348ff496fbba3f0c4c49d131cdeff8bb217c9 /networking
parente58c6e2e13030bea91f7cd41a62229b0f5927d51 (diff)
downloadbusybox-b8b72f02f01017d0f9584666fa572221f2b58613.zip
busybox-b8b72f02f01017d0f9584666fa572221f2b58613.tar.gz
dhcp: truncate packets instead of padding them to 574 bytes. closes bug 1849
function old new delta udhcp_send_raw_packet 411 456 +45 udhcp_send_kernel_packet 259 271 +12 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking')
-rw-r--r--networking/udhcp/packet.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c
index c01fb7d..4badc9c 100644
--- a/networking/udhcp/packet.c
+++ b/networking/udhcp/packet.c
@@ -173,6 +173,7 @@ int FAST_FUNC udhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt,
{
struct sockaddr_ll dest_sll;
struct ip_udp_dhcp_packet packet;
+ unsigned padding;
int fd;
int result = -1;
const char *msg;
@@ -198,34 +199,40 @@ int FAST_FUNC udhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt,
goto ret_close;
}
+ /* We were sending full-sized DHCP packets (zero padded),
+ * but some badly configured servers were seen dropping them.
+ * Apparently they drop all DHCP packets >576 *ethernet* octets big,
+ * whereas they may only drop packets >576 *IP* octets big
+ * (which for typical Ethernet II means 590 octets: 6+6+2 + 576).
+ *
+ * In order to work with those buggy servers,
+ * we truncate packets after end option byte.
+ */
+ padding = DHCP_OPTIONS_BUFSIZE - 1 - udhcp_end_option(packet.data.options);
+
packet.ip.protocol = IPPROTO_UDP;
packet.ip.saddr = source_nip;
packet.ip.daddr = dest_nip;
packet.udp.source = htons(source_port);
packet.udp.dest = htons(dest_port);
/* size, excluding IP header: */
- packet.udp.len = htons(UPD_DHCP_SIZE);
+ packet.udp.len = htons(UPD_DHCP_SIZE - padding);
/* for UDP checksumming, ip.len is set to UDP packet len */
packet.ip.tot_len = packet.udp.len;
- packet.udp.check = udhcp_checksum(&packet, IP_UPD_DHCP_SIZE);
+ packet.udp.check = udhcp_checksum(&packet, IP_UPD_DHCP_SIZE - padding);
/* but for sending, it is set to IP packet len */
- packet.ip.tot_len = htons(IP_UPD_DHCP_SIZE);
+ packet.ip.tot_len = htons(IP_UPD_DHCP_SIZE - padding);
packet.ip.ihl = sizeof(packet.ip) >> 2;
packet.ip.version = IPVERSION;
packet.ip.ttl = IPDEFTTL;
packet.ip.check = udhcp_checksum(&packet.ip, sizeof(packet.ip));
- /* Currently we send full-sized DHCP packets (zero padded).
- * If you need to change this: last byte of the packet is
- * packet.data.options[udhcp_end_option(packet.data.options)]
- */
udhcp_dump_packet(dhcp_pkt);
- result = sendto(fd, &packet, IP_UPD_DHCP_SIZE, 0,
+ result = sendto(fd, &packet, IP_UPD_DHCP_SIZE - padding, /*flags:*/ 0,
(struct sockaddr *) &dest_sll, sizeof(dest_sll));
msg = "sendto";
ret_close:
close(fd);
- /* FIXME: and if result >= 0 but != IP_UPD_DHCP_SIZE? */
if (result < 0) {
ret_msg:
bb_perror_msg(msg, "PACKET");
@@ -239,6 +246,7 @@ int FAST_FUNC udhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt,
uint32_t dest_nip, int dest_port)
{
struct sockaddr_in client;
+ unsigned padding;
int fd;
int result = -1;
const char *msg;
@@ -268,13 +276,13 @@ int FAST_FUNC udhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt,
goto ret_close;
}
- /* Currently we send full-sized DHCP packets (see above) */
udhcp_dump_packet(dhcp_pkt);
- result = safe_write(fd, dhcp_pkt, DHCP_SIZE);
+
+ padding = DHCP_OPTIONS_BUFSIZE - 1 - udhcp_end_option(dhcp_pkt->options);
+ result = safe_write(fd, dhcp_pkt, DHCP_SIZE - padding);
msg = "write";
ret_close:
close(fd);
- /* FIXME: and if result >= 0 but != DHCP_SIZE? */
if (result < 0) {
ret_msg:
bb_perror_msg(msg, "UDP");