mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	BAREBOX <barebox@lists.infradead.org>
Cc: "Claude Opus 4.6" <noreply@anthropic.com>
Subject: Re: [PATCH 08/10] net: fastboot: use net_eth_to_udp() for packet parsing
Date: Fri, 17 Apr 2026 12:14:15 +0200	[thread overview]
Message-ID: <f22a767d-0a4c-457a-9e5b-f571a2203b45@pengutronix.de> (raw)
In-Reply-To: <20260402-net-eth-do-udp-v1-8-af5d9fd6beec@pengutronix.de>

On 4/2/26 8:36 AM, Sascha Hauer wrote:
> Replace the separate net_eth_to_udplen(), net_eth_to_udphdr() and
> net_eth_to_udp_payload() calls with the new consolidated
> net_eth_to_udp() helper.
> 
> The direct net_eth_to_iphdr() call is kept because fastboot needs
> access to the IP header for source address handling and tot_len based
> fragment detection.
> 
> 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/fastboot.c | 21 ++++++++++++++-------
>  1 file changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/net/fastboot.c b/net/fastboot.c
> index 263d8abaa2..506af00cb8 100644
> --- a/net/fastboot.c
> +++ b/net/fastboot.c
> @@ -351,17 +351,24 @@ static void fastboot_check_retransmit(struct fastboot_net *fbn,
>  
>  static void fastboot_handler(void *ctx, char *packet, unsigned int raw_len)
>  {
> -	unsigned int len = net_eth_to_udplen(packet);
>  	struct ethernet *eth_header = (struct ethernet *)packet;
>  	struct iphdr *ip_header = net_eth_to_iphdr(packet);
> -	struct udphdr *udp_header = net_eth_to_udphdr(packet);
> -	char *payload = net_eth_to_udp_payload(packet);
>  	struct fastboot_net *fbn = ctx;
> +	struct net_udp_pkt udp;
>  	struct fastboot_header header;
> -	char *fastboot_data = payload + sizeof(header);
> -	u16 tot_len = ntohs(ip_header->tot_len);
> +	char *payload, *fastboot_data;
> +	unsigned int len;
> +	u16 tot_len;
>  	int ret;
>  
> +	if (net_eth_to_udp(packet, raw_len, &udp))
> +		return;
> +
> +	payload = udp.payload;
> +	len = udp.len;
> +	fastboot_data = payload + sizeof(header);
> +	tot_len = ntohs(ip_header->tot_len);
> +
>  	/* catch bogus tot_len values */
>  	if ((char *)ip_header - packet + tot_len > raw_len)
>  		return;
> @@ -392,7 +399,7 @@ static void fastboot_handler(void *ctx, char *packet, unsigned int raw_len)
>  
>  	memcpy(fbn->net_con->et->et_dest, eth_header->et_src, ETH_ALEN);
>  	net_copy_ip(&fbn->net_con->ip->daddr, &ip_header->saddr);
> -	fbn->net_con->udp->uh_dport = udp_header->uh_sport;
> +	fbn->net_con->udp->uh_dport = udp.udp->uh_sport;
>  
>  	switch (header.id) {
>  	case FASTBOOT_QUERY:
> @@ -404,7 +411,7 @@ static void fastboot_handler(void *ctx, char *packet, unsigned int raw_len)
>  			break;
>  		}
>  		fbn->host_addr = net_read_ip(&ip_header->saddr);
> -		fbn->host_port = udp_header->uh_sport;
> +		fbn->host_port = udp.udp->uh_sport;
>  		memcpy(fbn->host_mac, eth_header->et_src, ETH_ALEN);
>  		fastboot_net_abort(fbn);
>  		/* poller just unregistered in fastboot_net_abort() */
> 

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




  reply	other threads:[~2026-04-17 10:14 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-02  6:36 [PATCH 00/10] net: prevent buffer overflows in UDP packets Sascha Hauer
2026-04-02  6:36 ` [PATCH 01/10] net: add net_eth_to_udp() helper for validated UDP extraction Sascha Hauer
2026-04-17 10:04   ` Ahmad Fatoum
2026-04-02  6:36 ` [PATCH 02/10] fs: tftp: use net_eth_to_udp() for packet parsing Sascha Hauer
2026-04-17 10:05   ` Ahmad Fatoum
2026-04-02  6:36 ` [PATCH 03/10] net: dhcp: " Sascha Hauer
2026-04-17 10:07   ` Ahmad Fatoum
2026-04-02  6:36 ` [PATCH 04/10] fs: nfs: " Sascha Hauer
2026-04-17 10:10   ` Ahmad Fatoum
2026-04-02  6:36 ` [PATCH 05/10] net: dns: " Sascha Hauer
2026-04-17 10:10   ` Ahmad Fatoum
2026-04-02  6:36 ` [PATCH 06/10] net: sntp: " Sascha Hauer
2026-04-17 10:12   ` Ahmad Fatoum
2026-04-02  6:36 ` [PATCH 07/10] net: netconsole: " Sascha Hauer
2026-04-17 10:12   ` Ahmad Fatoum
2026-04-02  6:36 ` [PATCH 08/10] net: fastboot: " Sascha Hauer
2026-04-17 10:14   ` Ahmad Fatoum [this message]
2026-04-02  6:36 ` [PATCH 09/10] net: fastboot: stop using net_eth_to_udp_payload() for PACKET_SIZE Sascha Hauer
2026-04-17 10:17   ` Ahmad Fatoum
2026-04-02  6:36 ` [PATCH 10/10] net: remove unused net_eth_to_udp{hdr,_payload,len}() helpers Sascha Hauer
2026-04-17 10:17   ` Ahmad Fatoum
2026-04-17 10:21 ` [PATCH 00/10] net: prevent buffer overflows in UDP packets Ahmad Fatoum
2026-04-17 10:40 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f22a767d-0a4c-457a-9e5b-f571a2203b45@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=noreply@anthropic.com \
    --cc=s.hauer@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox