From a383869d6b58b3d66a91460a8b1a6fdcc09a1fe9 Mon Sep 17 00:00:00 2001 From: Tim Harvey Date: Fri, 30 May 2025 08:38:25 -0700 Subject: net: lwip: move dns init to common function 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 [jf: add CMD_DNS conditional to support NET_LWIP && !CMD_DNS] Reviewed-by: Jerome Forissier --- net/lwip/net-lwip.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'net/lwip/net-lwip.c') diff --git a/net/lwip/net-lwip.c b/net/lwip/net-lwip.c index ff4d634d1d1..040b51e8852 100644 --- a/net/lwip/net-lwip.c +++ b/net/lwip/net-lwip.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -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 */ -- cgit v1.2.3