[PATCH RFC] udhcpc: pad packets to work around broken routers
Vladislav Grishenko
themiron at mail.ru
Sat Oct 26 11:45:02 UTC 2013
Hi, have sent here similar patch in August,
http://lists.busybox.net/pipermail/busybox/2013-August/079727.html
> We've discovered a number of dhcp servers and relays check minimal dhcp
> packet size and drops anything less than 300 octets long as per RFC 1542.
> After commit "b8b72f02 dhcp: truncate packets instead of padding them to
574
> bytes. closes bug 1849" dhcpc/dhcpd could generate packets with size less
> than 300 bytes (bootp header + options), and under the circumstances above
> they all will be dropped by that servers/firewalls/relays.
> Refer patch against master attached.
From: Vladislav Grishenko <themiron at mail.ru>
Date: Fri, 30 Aug 2013 13:25:17 +0600
Subject: [PATCH] dhcp: keep padding packets to 300 bytes as per RFC 1542
function old new delta
udhcp_send_kernel_packet 251 272 +21
udhcp_send_raw_packet 445 448 +3
Signed-off-by: Vladislav Grishenko <themiron at mail.ru>
---
networking/udhcp/common.h | 3 +++
networking/udhcp/packet.c | 2 ++
2 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h
index 0e8e45f..bc44b84 100644
--- a/networking/udhcp/common.h
+++ b/networking/udhcp/common.h
@@ -25,6 +25,9 @@ extern const uint8_t MAC_BCAST_ADDR[6] ALIGN2; /* six
all-ones */
#define BOOTREQUEST 1
#define BOOTREPLY 2
+/* Minimal BOOTP message size. See RFC 1542 */
+#define DHCP_MIN_SIZE 300
+
//TODO: rename ciaddr/yiaddr/chaddr
struct dhcp_packet {
uint8_t op; /* BOOTREQUEST or BOOTREPLY */
diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c
index 33c9585..277887c 100644
--- a/networking/udhcp/packet.c
+++ b/networking/udhcp/packet.c
@@ -145,6 +145,7 @@ int FAST_FUNC udhcp_send_raw_packet(struct dhcp_packet
*dhcp_pkt,
* we truncate packets after end option byte.
*/
padding = DHCP_OPTIONS_BUFSIZE - 1 -
udhcp_end_option(packet.data.options);
+ padding = MIN(DHCP_SIZE - DHCP_MIN_SIZE, padding);
packet.ip.protocol = IPPROTO_UDP;
packet.ip.saddr = source_nip;
@@ -215,6 +216,7 @@ int FAST_FUNC udhcp_send_kernel_packet(struct
dhcp_packet *dhcp_pkt,
udhcp_dump_packet(dhcp_pkt);
padding = DHCP_OPTIONS_BUFSIZE - 1 -
udhcp_end_option(dhcp_pkt->options);
+ padding = MIN(DHCP_SIZE - DHCP_MIN_SIZE, padding);
result = safe_write(fd, dhcp_pkt, DHCP_SIZE - padding);
msg = "write";
ret_close:
--
1.7.2.5
Best Regards, Vladislav Grishenko
> -----Original Message-----
> From: busybox-bounces at busybox.net [mailto:busybox-
> bounces at busybox.net] On Behalf Of Johannes Stezenbach
> Sent: Wednesday, October 23, 2013 4:21 PM
> To: busybox at busybox.net
> Subject: [PATCH RFC] udhcpc: pad packets to work around broken routers
>
> Commit b8b72f02 removed all padding from DHCP packets to fix operation
> with buggy servers which can't handle maximum sized packets. But it
> introduced a regression with buggy routers which drop DHCP packets smaller
> than 300 bytes (i.e. 342 byte ethernet packets).
> Add back some padding to work around.
>
> Signed-off-by: Johannes Stezenbach <js at sig21.net>
> ---
> This is the minimal patch which fixes the issue, but I'm not sure about
> hardcoding the 300 byte size.
> Maybe add a commandline parameter?
>
>
> diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c index
> 33c9585..efee970 100644
> --- a/networking/udhcp/packet.c
> +++ b/networking/udhcp/packet.c
> @@ -146,6 +146,12 @@ int FAST_FUNC udhcp_send_raw_packet(struct
> dhcp_packet *dhcp_pkt,
> */
> padding = DHCP_OPTIONS_BUFSIZE - 1 -
> udhcp_end_option(packet.data.options);
>
> + /* work around issue with some routers which drop DHCP packets
> + * smaller than 300 bytes (342 byte eth packet)
> + */
> + if (DHCP_SIZE - padding < 300)
> + padding = DHCP_SIZE - 300;
> +
> packet.ip.protocol = IPPROTO_UDP;
> packet.ip.saddr = source_nip;
> packet.ip.daddr = dest_nip;
> @@ -215,6 +221,13 @@ int FAST_FUNC udhcp_send_kernel_packet(struct
> dhcp_packet *dhcp_pkt,
>
> udhcp_dump_packet(dhcp_pkt);
> padding = DHCP_OPTIONS_BUFSIZE - 1 -
> udhcp_end_option(dhcp_pkt->options);
> +
> + /* work around issue with some routers which drop DHCP packets
> + * smaller than 300 bytes (342 byte eth packet)
> + */
> + if (DHCP_SIZE - padding < 300)
> + padding = DHCP_SIZE - 300;
> +
> result = safe_write(fd, dhcp_pkt, DHCP_SIZE - padding);
> msg = "write";
> ret_close:
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-dhcp-keep-padding-packets-to-300-bytes-as-per-RFC-15.patch
Type: application/octet-stream
Size: 2000 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20131026/06f1c867/attachment-0001.obj>
More information about the busybox
mailing list