[PATCH 08/10] net: fastboot: use net_eth_to_udp() for packet parsing
Ahmad Fatoum
a.fatoum at pengutronix.de
Fri Apr 17 03:14:15 PDT 2026
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 at pengutronix.de>
> Co-Authored-By: Claude Opus 4.6 <noreply at anthropic.com>
Reviewed-by: Ahmad Fatoum <a.fatoum at 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 |
More information about the barebox
mailing list