From: florian Date: Mon, 22 Mar 2021 16:28:25 +0000 (+0000) Subject: BOOTP has a minimum packet length of 300 bytes. Since DHCP is X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=2d2edb0e3ca50fe71a66c867079a162d6456111e;p=openbsd BOOTP has a minimum packet length of 300 bytes. Since DHCP is interoperable with BOOTP we should also send packets that have a minimum size of 300. I haven't seen a DHCP server that actually enforces this except the one in vmd(8), but it doesn't cost us much and prevents hair pulling later on when we find one in the wild. OK deraadt --- diff --git a/sbin/dhcpleased/frontend.c b/sbin/dhcpleased/frontend.c index 0c5d187e4c5..76313923dc8 100644 --- a/sbin/dhcpleased/frontend.c +++ b/sbin/dhcpleased/frontend.c @@ -1,4 +1,4 @@ -/* $OpenBSD: frontend.c,v 1.7 2021/03/19 07:43:27 florian Exp $ */ +/* $OpenBSD: frontend.c,v 1.8 2021/03/22 16:28:25 florian Exp $ */ /* * Copyright (c) 2017, 2021 Florian Obser @@ -57,6 +57,7 @@ #include "checksum.h" #define ROUTE_SOCKET_BUF_SIZE 16384 +#define BOOTP_MIN_LEN 300 /* fixed bootp packet adds up to 300 */ struct bpf_ev { struct event ev; @@ -783,6 +784,7 @@ build_packet(uint8_t message_type, uint32_t xid, struct ether_addr *hw_address, static uint8_t dhcp_server_identifier[] = {DHO_DHCP_SERVER_IDENTIFIER, 4, 0, 0, 0, 0}; struct dhcp_hdr *hdr; + ssize_t len; uint8_t *p; char *c; @@ -834,7 +836,13 @@ build_packet(uint8_t message_type, uint32_t xid, struct ether_addr *hw_address, *p = DHO_END; p += 1; - return (p - dhcp_packet); + len = p - dhcp_packet; + + /* dhcp_packet is initialized with DHO_PADs */ + if (len < BOOTP_MIN_LEN) + len = BOOTP_MIN_LEN; + + return (len); } void