[PATCH 06/10] net: sntp: use net_eth_to_udp() for packet parsing
Ahmad Fatoum
a.fatoum at pengutronix.de
Fri Apr 17 03:12:00 PDT 2026
On 4/2/26 8:36 AM, Sascha Hauer wrote:
> Replace the separate net_eth_to_udp_payload() and net_eth_to_udplen()
> calls with the new consolidated net_eth_to_udp() helper.
>
> The direct net_eth_to_iphdr() call is kept because SNTP needs to check
> the source IP address before processing the UDP payload.
>
> 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/sntp.c | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/net/sntp.c b/net/sntp.c
> index be361f625d..c7441bc312 100644
> --- a/net/sntp.c
> +++ b/net/sntp.c
> @@ -75,19 +75,23 @@ static int sntp_send(void)
>
> static void sntp_handler(void *ctx, char *pkt, unsigned len)
> {
> - IPaddr_t ip_addr;
> struct iphdr *ip = net_eth_to_iphdr(pkt);
> - struct ntp_packet *ntp =
> - (struct ntp_packet *)net_eth_to_udp_payload(pkt);
> + struct net_udp_pkt udp;
> + struct ntp_packet *ntp;
> + IPaddr_t ip_addr;
>
> ip_addr = net_read_ip((void *)&ip->saddr);
> if (ip_addr != net_sntp_ip)
> return;
>
> - len = net_eth_to_udplen(pkt);
> - if (len < sizeof(struct ntp_packet))
> + if (net_eth_to_udp(pkt, len, &udp))
> return;
>
> + if (udp.len < sizeof(struct ntp_packet))
> + return;
> +
> + ntp = udp.payload;
> +
> pr_debug("received SNTP response\n");
>
> if (ntp->version != VERSION)
>
--
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