]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
net: lwip: move dns init to common function
authorTim Harvey <tharvey@gateworks.com>
Fri, 30 May 2025 15:38:25 +0000 (08:38 -0700)
committerJerome Forissier <jerome.forissier@linaro.org>
Tue, 8 Jul 2025 09:05:29 +0000 (11:05 +0200)
move the dns init including setting the dns servers from env vars to a
common function as other commands that support hostname lookups will
need this.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
[jf: add CMD_DNS conditional to support NET_LWIP && !CMD_DNS]
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
include/net-lwip.h
net/lwip/dns.c
net/lwip/net-lwip.c

index b762956e8fdab983d3f84d67e08e3b6f4c2494aa..6b5eb1990fbf93131e8057a28ed4dd9dc6620f08 100644 (file)
@@ -17,6 +17,7 @@ static inline int eth_is_on_demand_init(void)
 
 int eth_init_state_only(void); /* Set active state */
 
+int net_lwip_dns_init(void);
 int net_lwip_eth_start(void);
 struct netif *net_lwip_new_netif(struct udevice *udev);
 struct netif *net_lwip_new_netif_noip(struct udevice *udev);
index 3c9867902db953a239f086881bef84c1abf5bec1..fe70bdb48289001842568835b985476c7bc81be9 100644 (file)
@@ -45,12 +45,9 @@ static void dns_cb(const char *name, const ip_addr_t *ipaddr, void *arg)
 static int dns_loop(struct udevice *udev, const char *name, const char *var)
 {
        struct dns_cb_arg dns_cb_arg = { };
-       bool has_server = false;
        struct netif *netif;
        ip_addr_t ipaddr;
-       ip_addr_t ns;
        ulong start;
-       char *nsenv;
        int ret;
 
        dns_cb_arg.var = var;
@@ -59,22 +56,7 @@ static int dns_loop(struct udevice *udev, const char *name, const char *var)
        if (!netif)
                return CMD_RET_FAILURE;
 
-       dns_init();
-
-       nsenv = env_get("dnsip");
-       if (nsenv && ipaddr_aton(nsenv, &ns)) {
-               dns_setserver(0, &ns);
-               has_server = true;
-       }
-
-       nsenv = env_get("dnsip2");
-       if (nsenv && ipaddr_aton(nsenv, &ns)) {
-               dns_setserver(1, &ns);
-               has_server = true;
-       }
-
-       if (!has_server) {
-               log_err("No valid name server (dnsip/dnsip2)\n");
+       if (net_lwip_dns_init()) {
                net_lwip_remove_netif(netif);
                return CMD_RET_FAILURE;
        }
index ff4d634d1d14317db0aa79a0dd4b3d86db34d160..040b51e8852ab1890066c401c1c792a8f04b811f 100644 (file)
@@ -8,6 +8,7 @@
 #include <dm/uclass.h>
 #include <hexdump.h>
 #include <lwip/ip4_addr.h>
+#include <lwip/dns.h>
 #include <lwip/err.h>
 #include <lwip/netif.h>
 #include <lwip/pbuf.h>
@@ -140,6 +141,40 @@ static int get_udev_ipv4_info(struct udevice *dev, ip4_addr_t *ip,
        return 0;
 }
 
+/*
+ * Initialize DNS via env
+ */
+int net_lwip_dns_init(void)
+{
+#if CONFIG_IS_ENABLED(CMD_DNS)
+       bool has_server = false;
+       ip_addr_t ns;
+       char *nsenv;
+
+       nsenv = env_get("dnsip");
+       if (nsenv && ipaddr_aton(nsenv, &ns)) {
+               dns_setserver(0, &ns);
+               has_server = true;
+       }
+
+       nsenv = env_get("dnsip2");
+       if (nsenv && ipaddr_aton(nsenv, &ns)) {
+               dns_setserver(1, &ns);
+               has_server = true;
+       }
+
+       if (!has_server) {
+               log_err("No valid name server (dnsip/dnsip2)\n");
+               return -EINVAL;
+       }
+
+       return 0;
+#else
+       log_err("DNS disabled\n");
+       return -EINVAL;
+#endif
+}
+
 /*
  * Initialize the network stack if needed and start the current device if valid
  */