summaryrefslogtreecommitdiff
path: root/net/lwip/net-lwip.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/lwip/net-lwip.c')
-rw-r--r--net/lwip/net-lwip.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/net/lwip/net-lwip.c b/net/lwip/net-lwip.c
index f05c4cd3f64..3918d57d7e5 100644
--- a/net/lwip/net-lwip.c
+++ b/net/lwip/net-lwip.c
@@ -3,18 +3,23 @@
/* Copyright (C) 2024 Linaro Ltd. */
#include <command.h>
+#include <env.h>
#include <dm/device.h>
#include <dm/uclass.h>
#include <hexdump.h>
+#include <linux/kernel.h>
#include <lwip/ip4_addr.h>
+#include <lwip/dns.h>
#include <lwip/err.h>
#include <lwip/netif.h>
#include <lwip/pbuf.h>
#include <lwip/etharp.h>
#include <lwip/init.h>
#include <lwip/prot/etharp.h>
+#include <lwip/timeouts.h>
#include <net.h>
#include <timer.h>
+#include <u-boot/schedule.h>
/* xx:xx:xx:xx:xx:xx\0 */
#define MAC_ADDR_STRLEN 18
@@ -138,6 +143,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)
@@ -284,6 +323,11 @@ int net_lwip_rx(struct udevice *udev, struct netif *netif)
int len;
int i;
+ /* lwIP timers */
+ sys_check_timeouts();
+ /* Other tasks and actions */
+ schedule();
+
if (!eth_is_active(udev))
return -EINVAL;
@@ -315,6 +359,44 @@ int net_lwip_rx(struct udevice *udev, struct netif *netif)
return len;
}
+/**
+ * net_lwip_dns_resolve() - find IP address from name or IP
+ *
+ * @name_or_ip: host name or IP address
+ * @ip: output IP address
+ *
+ * Return value: 0 on success, -1 on failure.
+ */
+int net_lwip_dns_resolve(char *name_or_ip, ip_addr_t *ip)
+{
+#if defined(CONFIG_CMD_DNS)
+ char *var = "_dnsres";
+ char *argv[] = { "dns", name_or_ip, var, NULL };
+ int argc = ARRAY_SIZE(argv) - 1;
+#endif
+
+ if (ipaddr_aton(name_or_ip, ip))
+ return 0;
+
+#if defined(CONFIG_CMD_DNS)
+ if (do_dns(NULL, 0, argc, argv) != CMD_RET_SUCCESS)
+ return -1;
+
+ name_or_ip = env_get(var);
+ if (!name_or_ip)
+ return -1;
+
+ if (!ipaddr_aton(name_or_ip, ip))
+ return -1;
+
+ env_set(var, NULL);
+
+ return 0;
+#else
+ return -1;
+#endif
+}
+
void net_process_received_packet(uchar *in_packet, int len)
{
#if defined(CONFIG_API) || defined(CONFIG_EFI_LOADER)