Skip to contentSkip to conversation

net: lwip: Command fixes and improvements

PATCH In review Jonas Karlman 2 participants 14 messages Jan 17 – Jan 19 Networking

lore
Share & tools
lore
#0 lore raw

cover net: lwip: Command fixes and improvements

This series fixes a minor issue with the lwIP dns command, print device name from udevice in nfs command, changes to use ipaddr helper functions instead of accessing the internal addr field.

It also ensure the DHCP siaddr field is saved to the 'tftpserverip' env var so that correct next server is used for bootstrap.

Finally it make the nfs command behave in similar way as tftp in that it will prefer to use 'nfsserverip' env var before falling back to use 'serverip' env var.

Jonas Karlman (6):
net: lwip: dns: Fix print of resolved IP address
net: lwip: nfs: Print device name based on current udevice
net: lwip: dns: Call env_set() from dns loop instead of found callback
net: lwip: Use ipaddr helpers
net: lwip: dhcp: Save DHCP siaddr field to tftpserverip env var
net: lwip: nfs: Prefer nfsserverip over serverip when set

 cmd/lwip/ping.c |  2 +-
 net/lwip/dhcp.c |  7 +++++--
 net/lwip/dns.c  | 24 +++++++++---------------
 net/lwip/nfs.c  | 13 ++++++++-----
 net/lwip/tftp.c |  2 +-
 5 files changed, 24 insertions(+), 24 deletions(-)
Signature · 1 line
2.52.0
#1 lore raw

PATCH 1/6 net: lwip: dns: Fix print of resolved IP address

The lwIP dns command only prints out cached resolved IP addresses.

When a hostname is first resolved and ERR_INPROGRESS is returned the dns command prints out 0.0.0.0 instead of the resolved IP address.

Fix this by printing out host_ipaddr instead of the temporary ipaddr that only is valid when ERR_OK is returned.

Fixes 1361d9f4f00a ("lwip: dns: do not print IP address when a variable is specified")
---
 net/lwip/dns.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/lwip/dns.c +1 -1
index 9964003195f8..2b2a5947a2b8 100644
@@ -86,7 +86,7 @@ static int dns_loop(struct udevice *udev, const char *name, const char *var)
 
 	if (dns_cb_arg.done && dns_cb_arg.host_ipaddr.addr != 0) {
 		if (!var)
-			printf("%s\n", ipaddr_ntoa(&ipaddr));
+			printf("%s\n", ipaddr_ntoa(&dns_cb_arg.host_ipaddr));
 		return CMD_RET_SUCCESS;
 	}
 
Signature · 1 line
2.52.0
Reviewed-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] net: lwip: dns: Fix print of resolved IP address

Quoted 19 lines · Jonas Karlman

The lwIP dns command only prints out cached resolved IP addresses.

When a hostname is first resolved and ERR_INPROGRESS is returned the dns command prints out 0.0.0.0 instead of the resolved IP address.

Fix this by printing out host_ipaddr instead of the temporary ipaddr that only is valid when ERR_OK is returned.

Fixes 1361d9f4f00a ("lwip: dns: do not print IP address when a variable is specified")
---
 net/lwip/dns.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/lwip/dns.c +0 -0
index 9964003195f8..2b2a5947a2b8 100644

net/lwip/dns.c static int dns_loop(struct udevice *udev, const char *name, const char *var) · line 91

Quoted 7 lines
net/lwip/dns.c +1 -1
@@ -86,7 +86,7 @@ static int dns_loop(struct udevice *udev, const char *name, const char *var)
 
 	if (dns_cb_arg.done && dns_cb_arg.host_ipaddr.addr != 0) {
 		if (!var)
-			printf("%s\n", ipaddr_ntoa(&ipaddr));
+			printf("%s\n", ipaddr_ntoa(&dns_cb_arg.host_ipaddr));
 		return CMD_RET_SUCCESS;
 	}

Thanks,

Signature · 1 line
Jerome
#3 lore raw

PATCH 2/6 net: lwip: nfs: Print device name based on current udevice

In reply to Jonas Karlman

Use udevice name, similar to other lwip commands, instead of using the legacy eth_get_name() when printing out the device being used.

Fixes 230cf3bc2776 ("net: lwip: nfs: Port the NFS code to work with lwIP")
---
 net/lwip/nfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/lwip/nfs.c +2 -1
index 27579af8f1fe..5fc2d3bd8736 100644
@@ -3,6 +3,7 @@
 
 #include <console.h>
 #include <display_options.h>
+#include <dm/device.h>
 #include <env.h>
 #include <image.h>
 #include <linux/kconfig.h>
@@ -116,7 +117,7 @@ static int nfs_loop(struct udevice *udev, ulong addr, char *fname,
 	nfs_filename = nfs_basename(fname);
 	nfs_path     = nfs_dirname(fname);
 
-	printf("Using %s device\n", eth_get_name());
+	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"));
Signature · 1 line
2.52.0
Reviewed-by on v1 2/6
#4 lore raw

Re: [PATCH 2/6] net: lwip: nfs: Print device name based on current udevice

Quoted 22 lines · Jonas Karlman

Use udevice name, similar to other lwip commands, instead of using the legacy eth_get_name() when printing out the device being used.

Fixes 230cf3bc2776 ("net: lwip: nfs: Port the NFS code to work with lwIP")
---
 net/lwip/nfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/lwip/nfs.c +1 -0
index 27579af8f1fe..5fc2d3bd8736 100644
@@ -3,6 +3,7 @@
 
 #include <console.h>
 #include <display_options.h>
+#include <dm/device.h>
 #include <env.h>
 #include <image.h>
 #include <linux/kconfig.h>

net/lwip/nfs.c static int nfs_loop(struct udevice *udev, ulong addr, char *fname, · line 123

Quoted 8 lines
net/lwip/nfs.c +1 -1
@@ -116,7 +117,7 @@ static int nfs_loop(struct udevice *udev, ulong addr, char *fname,
 	nfs_filename = nfs_basename(fname);
 	nfs_path     = nfs_dirname(fname);
 
-	printf("Using %s device\n", eth_get_name());
+	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"));

Thanks,

Signature · 1 line
Jerome
#5 lore raw

PATCH 3/6 net: lwip: dns: Call env_set() from dns loop instead of found callback

In reply to Jonas Karlman

The lwIP dns command handle env_set() calls from the found callback and printf() to console in the dns loop. Making it more complex than it needs to be.

Simplify and ensure any environment variable that is being set is the same value that would have been printed on console.

There should not be any intended change in behavior, besides the change from using ip4addr helper to using version less ipaddr helper.

---
 net/lwip/dns.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
net/lwip/dns.c +6 -9
index 2b2a5947a2b8..2222e2b0b045 100644
@@ -14,7 +14,6 @@
 
 struct dns_cb_arg {
 	ip_addr_t host_ipaddr;
-	const char *var;
 	bool done;
 };
 
@@ -26,7 +25,6 @@ static void do_dns_tmr(void *arg)
 static void dns_cb(const char *name, const ip_addr_t *ipaddr, void *arg)
 {
 	struct dns_cb_arg *dns_cb_arg = arg;
-	char *ipstr = ip4addr_ntoa(ipaddr);
 
 	dns_cb_arg->done = true;
 
@@ -37,21 +35,17 @@ static void dns_cb(const char *name, const ip_addr_t *ipaddr, void *arg)
 	}
 
 	dns_cb_arg->host_ipaddr.addr = ipaddr->addr;
-
-	if (dns_cb_arg->var)
-		env_set(dns_cb_arg->var, ipstr);
 }
 
 static int dns_loop(struct udevice *udev, const char *name, const char *var)
 {
 	struct dns_cb_arg dns_cb_arg = { };
 	struct netif *netif;
+	const char *ipstr;
 	ip_addr_t ipaddr;
 	ulong start;
 	int ret;
 
-	dns_cb_arg.var = var;
-
 	netif = net_lwip_new_netif(udev);
 	if (!netif)
 		return CMD_RET_FAILURE;
@@ -85,8 +79,11 @@ 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 (!var)
-			printf("%s\n", ipaddr_ntoa(&dns_cb_arg.host_ipaddr));
+		ipstr = ipaddr_ntoa(&dns_cb_arg.host_ipaddr);
+		if (var)
+			env_set(var, ipstr);
+		else
+			printf("%s\n", ipstr);
 		return CMD_RET_SUCCESS;
 	}
 
Signature · 1 line
2.52.0
Reviewed-by on v1 3/6
#6 lore raw

Re: [PATCH 3/6] net: lwip: dns: Call env_set() from dns loop instead of found callback

Quoted 62 lines · Jonas Karlman

The lwIP dns command handle env_set() calls from the found callback and printf() to console in the dns loop. Making it more complex than it needs to be.

Simplify and ensure any environment variable that is being set is the same value that would have been printed on console.

There should not be any intended change in behavior, besides the change from using ip4addr helper to using version less ipaddr helper.

---
 net/lwip/dns.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
net/lwip/dns.c +1 -7
index 2b2a5947a2b8..2222e2b0b045 100644
@@ -14,7 +14,6 @@
 
 struct dns_cb_arg {
 	ip_addr_t host_ipaddr;
-	const char *var;
 	bool done;
 };
 
@@ -26,7 +25,6 @@ static void do_dns_tmr(void *arg)
 static void dns_cb(const char *name, const ip_addr_t *ipaddr, void *arg)
 {
 	struct dns_cb_arg *dns_cb_arg = arg;
-	char *ipstr = ip4addr_ntoa(ipaddr);
 
 	dns_cb_arg->done = true;
 
@@ -37,21 +35,17 @@ static void dns_cb(const char *name, const ip_addr_t *ipaddr, void *arg)
 	}
 
 	dns_cb_arg->host_ipaddr.addr = ipaddr->addr;
-
-	if (dns_cb_arg->var)
-		env_set(dns_cb_arg->var, ipstr);
 }
 
 static int dns_loop(struct udevice *udev, const char *name, const char *var)
 {
 	struct dns_cb_arg dns_cb_arg = { };
 	struct netif *netif;
+	const char *ipstr;
 	ip_addr_t ipaddr;
 	ulong start;
 	int ret;
 
-	dns_cb_arg.var = var;
-
 	netif = net_lwip_new_netif(udev);
 	if (!netif)
 		return CMD_RET_FAILURE;
@@ -85,8 +79,11 @@ 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) {

net/lwip/dns.c static int dns_loop(struct udevice *udev, const char *name, const char *var) · line 89

Quoted 10 lines
net/lwip/dns.c +5 -2
-		if (!var)
-			printf("%s\n", ipaddr_ntoa(&dns_cb_arg.host_ipaddr));
+		ipstr = ipaddr_ntoa(&dns_cb_arg.host_ipaddr);
+		if (var)
+			env_set(var, ipstr);
+		else
+			printf("%s\n", ipstr);
 		return CMD_RET_SUCCESS;
 	}
 

Thanks,

Signature · 1 line
Jerome
#7 lore raw

PATCH 4/6 net: lwip: Use ipaddr helpers

In reply to Jonas Karlman

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.

---
 cmd/lwip/ping.c | 2 +-
 net/lwip/dhcp.c | 4 ++--
 net/lwip/dns.c  | 9 +++------
 net/lwip/nfs.c  | 6 +++---
 net/lwip/tftp.c | 2 +-
 5 files changed, 10 insertions(+), 13 deletions(-)
cmd/lwip/ping.c +1 -1
index 6d090fc530d6..fc4cf7bde5f9 100644
@@ -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))) &&
net/lwip/dhcp.c +2 -2
index 731b57de3ba4..4cd4184c42bb 100644
@@ -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
net/lwip/dns.c +3 -6
index 2222e2b0b045..8b7b3b7f970f 100644
@@ -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);
net/lwip/nfs.c +3 -3
index 5fc2d3bd8736..1812bbda68e5 100644
@@ -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();
 
net/lwip/tftp.c +1 -1
index 6c7ffba661e5..86516e662732 100644
@@ -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: ");
Signature · 1 line
2.52.0
Reviewed-by on v1 4/6
#8 lore raw

Re: [PATCH 4/6] net: lwip: Use ipaddr helpers

Quoted 118 lines · Jonas Karlman

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.

---
 cmd/lwip/ping.c | 2 +-
 net/lwip/dhcp.c | 4 ++--
 net/lwip/dns.c  | 9 +++------
 net/lwip/nfs.c  | 6 +++---
 net/lwip/tftp.c | 2 +-
 5 files changed, 10 insertions(+), 13 deletions(-)
cmd/lwip/ping.c +1 -1
index 6d090fc530d6..fc4cf7bde5f9 100644
@@ -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))) &&
net/lwip/dhcp.c +2 -2
index 731b57de3ba4..4cd4184c42bb 100644
@@ -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
net/lwip/dns.c +3 -6
index 2222e2b0b045..8b7b3b7f970f 100644
@@ -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);
net/lwip/nfs.c +3 -3
index 5fc2d3bd8736..1812bbda68e5 100644
@@ -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();
 
net/lwip/tftp.c +0 -0
index 6c7ffba661e5..86516e662732 100644

net/lwip/tftp.c static int tftp_loop(struct udevice *udev, ulong addr, char *fname, · line 186

Quoted 8 lines
net/lwip/tftp.c +1 -1
@@ -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: ");

Thanks,

Signature · 1 line
Jerome
#9 lore raw

PATCH 5/6 net: lwip: dhcp: Save DHCP siaddr field to tftpserverip env var

In reply to Jonas Karlman

The DHCP siaddr field contains the IP address of next server to use in bootstrap. Typically this will be the IP address of a TFTP server or the IP address of the DHCP server itself.

RFC 2131, 2. Protocol Summary, Page 10:

DHCP clarifies the interpretation of the 'siaddr' field as the address of the server to use in the next step of the client's bootstrap process. A DHCP server may return its own address in the 'siaddr' field, if the server is prepared to supply the next bootstrap service (e.g., delivery of an operating system executable image). A DHCP server always returns its own address in the 'server identifier' option.

Set the 'tftpserverip' env variable when the siaddr field contains an IP address that is different compared to the DHCP server IP address.

---
 net/lwip/dhcp.c | 3 +++
 1 file changed, 3 insertions(+)
net/lwip/dhcp.c +3 -0
index 4cd4184c42bb..acdf601d7eb5 100644
@@ -101,6 +101,9 @@ static int dhcp_loop(struct udevice *udev)
 	env_set("serverip", ip4addr_ntoa(&dhcp->server_ip_addr));
 	if (!ip4_addr_isany(&dhcp->offered_gw_addr))
 		env_set(gwstr, ip4addr_ntoa(&dhcp->offered_gw_addr));
+	if (!ip4_addr_isany(&dhcp->offered_si_addr) &&
+	    !ip4_addr_eq(&dhcp->offered_si_addr, &dhcp->server_ip_addr))
+		env_set("tftpserverip", ip4addr_ntoa(&dhcp->offered_si_addr));
 
 #ifdef CONFIG_PROT_DNS_LWIP
 	env_set("dnsip", ip4addr_ntoa(dns_getserver(0)));
Signature · 1 line
2.52.0
Reviewed-by on v1 5/6
#10 lore raw

Re: [PATCH 5/6] net: lwip: dhcp: Save DHCP siaddr field to tftpserverip env var

Quoted 27 lines · Jonas Karlman

The DHCP siaddr field contains the IP address of next server to use in bootstrap. Typically this will be the IP address of a TFTP server or the IP address of the DHCP server itself.

RFC 2131, 2. Protocol Summary, Page 10:

DHCP clarifies the interpretation of the 'siaddr' field as the address of the server to use in the next step of the client's bootstrap process. A DHCP server may return its own address in the 'siaddr' field, if the server is prepared to supply the next bootstrap service (e.g., delivery of an operating system executable image). A DHCP server always returns its own address in the 'server identifier' option.

Set the 'tftpserverip' env variable when the siaddr field contains an IP address that is different compared to the DHCP server IP address.

---
 net/lwip/dhcp.c | 3 +++
 1 file changed, 3 insertions(+)
net/lwip/dhcp.c +0 -0
index 4cd4184c42bb..acdf601d7eb5 100644

net/lwip/dhcp.c static int dhcp_loop(struct udevice *udev) · line 109

Quoted 9 lines
net/lwip/dhcp.c +3 -0
@@ -101,6 +101,9 @@ static int dhcp_loop(struct udevice *udev)
 	env_set("serverip", ip4addr_ntoa(&dhcp->server_ip_addr));
 	if (!ip4_addr_isany(&dhcp->offered_gw_addr))
 		env_set(gwstr, ip4addr_ntoa(&dhcp->offered_gw_addr));
+	if (!ip4_addr_isany(&dhcp->offered_si_addr) &&
+	    !ip4_addr_eq(&dhcp->offered_si_addr, &dhcp->server_ip_addr))
+		env_set("tftpserverip", ip4addr_ntoa(&dhcp->offered_si_addr));
 
 #ifdef CONFIG_PROT_DNS_LWIP
 	env_set("dnsip", ip4addr_ntoa(dns_getserver(0)));

Thanks,

Signature · 1 line
Jerome
#11 lore raw

PATCH 6/6 net: lwip: nfs: Prefer nfsserverip over serverip when set

In reply to Jonas Karlman

Prefer use of a 'nfsserverip' env var before falling back to 'serverip' when using the nfs command. Similar to how the 'tftpserverip' env var is preferred over 'serverip' by the tftp command.

This also updates the error message to closer match the error message used by the lwIP tftp command when a server ip is not set.

---
 net/lwip/nfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/lwip/nfs.c +3 -1
index 1812bbda68e5..c3b819a091ec 100644
@@ -247,10 +247,12 @@ int do_nfs(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 		}
 	}
 
+	if (!server_ip)
+		server_ip = env_get("nfsserverip");
 	if (!server_ip)
 		server_ip = env_get("serverip");
 	if (!server_ip) {
-		log_err("*** ERROR: 'serverip' not set\n");
+		log_err("error: nfsserverip/serverip not set\n");
 		ret = CMD_RET_FAILURE;
 		goto out;
 	}
Signature · 1 line
2.52.0
Reviewed-by on v1 6/6
#12 lore raw

Re: [PATCH 6/6] net: lwip: nfs: Prefer nfsserverip over serverip when set

Quoted 20 lines · Jonas Karlman

Prefer use of a 'nfsserverip' env var before falling back to 'serverip' when using the nfs command. Similar to how the 'tftpserverip' env var is preferred over 'serverip' by the tftp command.

This also updates the error message to closer match the error message used by the lwIP tftp command when a server ip is not set.

---
 net/lwip/nfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/lwip/nfs.c +0 -0
index 1812bbda68e5..c3b819a091ec 100644
@@ -247,10 +247,12 @@ int do_nfs(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 		}
 	}
 

net/lwip/nfs.c int do_nfs(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) · line 258

Quoted 10 lines
net/lwip/nfs.c +3 -1
+	if (!server_ip)
+		server_ip = env_get("nfsserverip");
 	if (!server_ip)
 		server_ip = env_get("serverip");
 	if (!server_ip) {
-		log_err("*** ERROR: 'serverip' not set\n");
+		log_err("error: nfsserverip/serverip not set\n");
 		ret = CMD_RET_FAILURE;
 		goto out;
 	}

Thanks,

Signature · 1 line
Jerome
#13 lore raw
In reply to Jonas Karlman

Hi Jonas,

Quoted 19 lines · Jonas Karlman

This series fixes a minor issue with the lwIP dns command, print device name from udevice in nfs command, changes to use ipaddr helper functions instead of accessing the internal addr field.

It also ensure the DHCP siaddr field is saved to the 'tftpserverip' env var so that correct next server is used for bootstrap.

Finally it make the nfs command behave in similar way as tftp in that it will prefer to use 'nfsserverip' env var before falling back to use 'serverip' env var.

Jonas Karlman (6):
net: lwip: dns: Fix print of resolved IP address
net: lwip: nfs: Print device name based on current udevice
net: lwip: dns: Call env_set() from dns loop instead of found callback
net: lwip: Use ipaddr helpers
net: lwip: dhcp: Save DHCP siaddr field to tftpserverip env var
net: lwip: nfs: Prefer nfsserverip over serverip when set

Quoted 6 lines
 cmd/lwip/ping.c |  2 +-
 net/lwip/dhcp.c |  7 +++++--
 net/lwip/dns.c  | 24 +++++++++---------------
 net/lwip/nfs.c  | 13 ++++++++-----
 net/lwip/tftp.c |  2 +-
 5 files changed, 24 insertions(+), 24 deletions(-)

Nice cleanup, thanks!

Signature · 1 line
Jerome