diff options
author | Tim Harvey <tharvey@gateworks.com> | 2025-05-30 08:38:25 -0700 |
---|---|---|
committer | Jerome Forissier <jerome.forissier@linaro.org> | 2025-07-08 11:05:29 +0200 |
commit | a383869d6b58b3d66a91460a8b1a6fdcc09a1fe9 (patch) | |
tree | 09b85b5d95f66bf1f8d02c9605386e8e61816bde /net/lwip/net-lwip.c | |
parent | e4e97f70526dd9f367f54a38f38115726336cd6a (diff) |
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 <tharvey@gateworks.com>
[jf: add CMD_DNS conditional to support NET_LWIP && !CMD_DNS]
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Diffstat (limited to 'net/lwip/net-lwip.c')
-rw-r--r-- | net/lwip/net-lwip.c | 35 |
1 files changed, 35 insertions, 0 deletions
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 <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> @@ -141,6 +142,40 @@ static int get_udev_ipv4_info(struct udevice *dev, ip4_addr_t *ip, } /* + * 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 */ int net_lwip_eth_start(void) |