Re: [PATCH 03/10] net: dhcp: use net_eth_to_udp() for packet parsing

Ahmad Fatoum
2026-04-17T10:08:05Z

On 4/2/26 8:36 AM, Sascha Hauer wrote:
> 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@pengutronix.de>
> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

> ---
> 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) {
>

--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |