]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
net: lwip: Use ipaddr helpers
authorJonas Karlman <jonas@kwiboo.se>
Sat, 17 Jan 2026 00:24:40 +0000 (00:24 +0000)
committerJerome Forissier <jerome.forissier@arm.com>
Wed, 4 Feb 2026 08:04:36 +0000 (09:04 +0100)
The ip_addr_t of lwIP has support for both IPv6 and IPv4 addresses.
Some lwIP commans is directly accessing the internal addr field of the
ip_addr_t instead of using ipaddr helper functions.

Change to use ipaddr helper functions where appropriate to remove direct
access of the internal addr field. Also change a few instances from ip4
to the version less ipaddr helpers.

There is no intended functional change, besides the change from using
ip4 addr helper to using version less ipaddr helper.

Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
Reviewed-by: Jerome Forissier <jerome.forissier@arm.com>
cmd/lwip/ping.c
net/lwip/dhcp.c
net/lwip/dns.c
net/lwip/nfs.c
net/lwip/tftp.c

index 6d090fc530d600a40fbfbc77f22a8738dcd38f3a..fc4cf7bde5f96d4052d754355c4f572a003741ec 100644 (file)
@@ -35,7 +35,7 @@ static u8_t ping_recv(void *arg, struct raw_pcb *pcb, struct pbuf *p,
        struct ping_ctx *ctx = arg;
        struct icmp_echo_hdr *iecho = ctx->iecho;
 
-       if (addr->addr != ctx->target.addr)
+       if (!ip_addr_eq(addr, &ctx->target))
                return 0;
 
        if ((p->tot_len >= (IP_HLEN + sizeof(struct icmp_echo_hdr))) &&
index 731b57de3ba4336a22fee5957b6e2163360d78a1..4cd4184c42bb546770985e2d43291e87a2c2bd7a 100644 (file)
@@ -93,13 +93,13 @@ static int dhcp_loop(struct udevice *udev)
                sprintf(maskstr, "netmask%d", idx);
                sprintf(gwstr, "gatewayip%d", idx);
        } else {
-               net_ip.s_addr = dhcp->offered_ip_addr.addr;
+               net_ip.s_addr = ip_addr_get_ip4_u32(&dhcp->offered_ip_addr);
        }
 
        env_set(ipstr, ip4addr_ntoa(&dhcp->offered_ip_addr));
        env_set(maskstr, ip4addr_ntoa(&dhcp->offered_sn_mask));
        env_set("serverip", ip4addr_ntoa(&dhcp->server_ip_addr));
-       if (dhcp->offered_gw_addr.addr != 0)
+       if (!ip4_addr_isany(&dhcp->offered_gw_addr))
                env_set(gwstr, ip4addr_ntoa(&dhcp->offered_gw_addr));
 
 #ifdef CONFIG_PROT_DNS_LWIP
index 2222e2b0b0453b41cf36ea9b25061d9e3b6e8841..8b7b3b7f970f3072cba4722cf7876a273dc21e8a 100644 (file)
@@ -28,13 +28,10 @@ static void dns_cb(const char *name, const ip_addr_t *ipaddr, void *arg)
 
        dns_cb_arg->done = true;
 
-       if (!ipaddr) {
+       if (!ipaddr)
                printf("DNS: host not found\n");
-               dns_cb_arg->host_ipaddr.addr = 0;
-               return;
-       }
 
-       dns_cb_arg->host_ipaddr.addr = ipaddr->addr;
+       ip_addr_set(&dns_cb_arg->host_ipaddr, ipaddr);
 }
 
 static int dns_loop(struct udevice *udev, const char *name, const char *var)
@@ -78,7 +75,7 @@ static int dns_loop(struct udevice *udev, const char *name, const char *var)
 
        net_lwip_remove_netif(netif);
 
-       if (dns_cb_arg.done && dns_cb_arg.host_ipaddr.addr != 0) {
+       if (dns_cb_arg.done && !ip_addr_isany(&dns_cb_arg.host_ipaddr)) {
                ipstr = ipaddr_ntoa(&dns_cb_arg.host_ipaddr);
                if (var)
                        env_set(var, ipstr);
index 5fc2d3bd8736fccb3959a220e4eabb103ec38ff9..1812bbda68e51a9922aab4eda65ce06af510e6a2 100644 (file)
@@ -59,7 +59,7 @@ static void nfs_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p,
        int plen;
        struct rpc_t rpc_pkt;
 
-       if (addr->addr != ctx->nfs_server.addr)
+       if (!ip_addr_eq(addr, &ctx->nfs_server))
                goto exitfree;
 
        if (p->tot_len > sizeof(struct rpc_t))
@@ -120,7 +120,7 @@ static int nfs_loop(struct udevice *udev, ulong addr, char *fname,
        printf("Using %s device\n", udev->name);
 
        printf("File transfer via NFS from server %s; our IP address is %s\n",
-              ip4addr_ntoa(&srvip), env_get("ipaddr"));
+              ipaddr_ntoa(&srvip), env_get("ipaddr"));
 
        printf("\nFilename '%s/%s'.", nfs_path, nfs_filename);
 
@@ -144,7 +144,7 @@ static int nfs_loop(struct udevice *udev, ulong addr, char *fname,
 
        net_set_state(NETLOOP_CONTINUE);
 
-       sess_ctx.nfs_server.addr = srvip.addr;
+       ip_addr_set(&sess_ctx.nfs_server, &srvip);
 
        nfs_send();
 
index 6c7ffba661e5903b6b3a6349edf2c8b22eb0d36b..86516e662732e6ca84aabb8be1fb35ae19f7f8eb 100644 (file)
@@ -180,7 +180,7 @@ static int tftp_loop(struct udevice *udev, ulong addr, char *fname,
 
        printf("Using %s device\n", udev->name);
        printf("TFTP from server %s; our IP address is %s\n",
-              ip4addr_ntoa(&srvip), env_get("ipaddr"));
+              ipaddr_ntoa(&srvip), env_get("ipaddr"));
        printf("Filename '%s'.\n", fname);
        printf("Load address: 0x%lx\n", ctx.daddr);
        printf("Loading: ");