[PATCH 03/10] net: dhcp: use net_eth_to_udp() for packet parsing
Sascha Hauer
s.hauer at pengutronix.de
Wed Apr 1 23:36:42 PDT 2026
Replace the separate net_eth_to_udp_payload(), net_eth_to_udphdr() and
net_eth_to_udplen() calls with the new consolidated net_eth_to_udp()
helper. This validates the packet length before accessing any headers.
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
Co-Authored-By: Claude Opus 4.6 <noreply at anthropic.com>
---
net/dhcp.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/net/dhcp.c b/net/dhcp.c
index e25b64842d..39168a2d53 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -391,16 +391,18 @@ static void dhcp_send_request_packet(struct bootp *bp_offer)
*/
static void dhcp_handler(void *ctx, char *packet, unsigned int len)
{
- char *pkt = net_eth_to_udp_payload(packet);
- struct udphdr *udp = net_eth_to_udphdr(packet);
- struct bootp *bp = (struct bootp *)pkt;
+ struct net_udp_pkt udp;
+ struct bootp *bp;
+
+ if (net_eth_to_udp(packet, len, &udp))
+ return;
- len = net_eth_to_udplen(packet);
+ bp = udp.payload;
- debug("DHCPHandler: got packet: (len=%d) state: %d\n",
- len, dhcp_state);
+ debug("DHCPHandler: got packet: (len=%u) state: %d\n",
+ udp.len, dhcp_state);
- if (bootp_check_packet(pkt, ntohs(udp->uh_sport), len)) /* Filter out pkts we don't want */
+ if (bootp_check_packet(udp.payload, ntohs(udp.udp->uh_sport), udp.len))
return;
switch (dhcp_state) {
--
2.47.3
More information about the barebox
mailing list