All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maxim Uvarov <maxim.uvarov@linaro.org>
To: u-boot@lists.denx.de
Cc: pbrobinson@redhat.com, ilias.apalodimas@linaro.org,
	joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com,
	goldsimon@gmx.de, lwip-devel@nongnu.org,
	Maxim Uvarov <maxim.uvarov@linaro.org>
Subject: [PATCHv6 03/14] net/lwip: implement dns cmd
Date: Mon, 14 Aug 2023 19:32:42 +0600	[thread overview]
Message-ID: <20230814133253.4150-4-maxim.uvarov@linaro.org> (raw)
In-Reply-To: <20230814133253.4150-1-maxim.uvarov@linaro.org>

Implement function for dns command with lwIP variant. Usage and output is
the same as the original command. This code called by compatibility code
between U-Boot and lwIP.

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
---
 include/net/lwip.h           | 17 +++++++++++++
 net/lwip/Makefile            |  2 ++
 net/lwip/apps/dns/lwip-dns.c | 46 ++++++++++++++++++++++++++++++++++++
 3 files changed, 65 insertions(+)
 create mode 100644 include/net/lwip.h
 create mode 100644 net/lwip/apps/dns/lwip-dns.c

diff --git a/include/net/lwip.h b/include/net/lwip.h
new file mode 100644
index 0000000000..c83b5c8231
--- /dev/null
+++ b/include/net/lwip.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc,
+		char *const argv[]);
+
+/*
+* This function creates the DNS request to resolve a domain host name. Function
+* can return immediately if previous request was cached or it might require
+* entering the polling loop for a request to a remote server.
+*
+* @name  dns name to resolve
+* @varname (optional) U-Boot variable name to store the result
+* Return: ERR_OK(0) for fetching entry from the cache
+*         ERR_INPROGRESS(-5) success, can go to the polling loop
+*         Other value < 0, if error
+*/
+int ulwip_dns(char *name, char *varname);
diff --git a/net/lwip/Makefile b/net/lwip/Makefile
index d1161bea78..6d2c00605b 100644
--- a/net/lwip/Makefile
+++ b/net/lwip/Makefile
@@ -64,3 +64,5 @@ obj-$(CONFIG_NET) += $(LWIPDIR)/netif/ethernet.o
 
 obj-$(CONFIG_NET) += port/if.o
 obj-$(CONFIG_NET) += port/sys-arch.o
+
+obj-$(CONFIG_CMD_DNS) += apps/dns/lwip-dns.o
diff --git a/net/lwip/apps/dns/lwip-dns.c b/net/lwip/apps/dns/lwip-dns.c
new file mode 100644
index 0000000000..6e205c1153
--- /dev/null
+++ b/net/lwip/apps/dns/lwip-dns.c
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * (C) Copyright 2023 Linaro Ltd. <maxim.uvarov@linaro.org>
+ */
+
+#include <common.h>
+#include <command.h>
+#include <console.h>
+
+#include <lwip/dns.h>
+#include <lwip/ip_addr.h>
+
+#include <net/ulwip.h>
+
+static void dns_found_cb(const char *name, const ip_addr_t *ipaddr, void *callback_arg)
+{
+	char *varname = (char *)callback_arg;
+
+	if (varname)
+		env_set(varname, ip4addr_ntoa(ipaddr));
+
+	log_info("resolved %s to %s\n",  name, ip4addr_ntoa(ipaddr));
+	ulwip_exit(0);
+}
+
+int ulwip_dns(char *name, char *varname)
+{
+	int err;
+	ip_addr_t ipaddr; /* not used */
+	ip_addr_t dns1;
+	ip_addr_t dns2;
+
+	ipaddr_aton(env_get("dnsip"), &dns1);
+	ipaddr_aton(env_get("dnsip2"), &dns2);
+
+	dns_init();
+	dns_setserver(0, &dns1);
+	dns_setserver(1, &dns2);
+
+	err = dns_gethostbyname(name, &ipaddr, dns_found_cb, varname);
+	if (err == ERR_OK)
+		dns_found_cb(name, &ipaddr, varname);
+
+	return err;
+}
-- 
2.30.2


  parent reply	other threads:[~2023-08-14 13:35 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-14 13:32 [PATCHv6 00/14] net/lwip: add lwip library for the network stack Maxim Uvarov
2023-08-14 13:32 ` [PATCHv6 01/14] net/lwip: add doc/develop/net_lwip.rst Maxim Uvarov
2023-08-14 14:10   ` Ilias Apalodimas
2023-08-14 13:32 ` [PATCHv6 02/14] net/lwip: integrate lwIP library Maxim Uvarov
2023-08-14 14:13   ` Ilias Apalodimas
2023-08-14 13:32 ` Maxim Uvarov [this message]
2023-08-14 14:19   ` [PATCHv6 03/14] net/lwip: implement dns cmd Ilias Apalodimas
2023-08-14 15:15     ` Maxim Uvarov
2023-08-15 12:42     ` Maxim Uvarov
2023-08-15 14:42       ` Tom Rini
2023-08-16 10:26         ` Ilias Apalodimas
2023-08-16 11:01           ` Maxim Uvarov
2023-08-16 11:54             ` Ilias Apalodimas
2023-08-16 12:24               ` Maxim Uvarov
2023-08-14 13:32 ` [PATCHv6 04/14] net/lwip: implement dhcp cmd Maxim Uvarov
2023-08-14 14:21   ` Ilias Apalodimas
2023-08-14 15:18     ` Maxim Uvarov
2023-08-14 15:29       ` Tom Rini
2023-08-17 13:46         ` Maxim Uvarov
2023-08-17 14:04           ` Peter Robinson
2023-08-17 14:55             ` Maxim Uvarov
2023-08-17 15:10               ` Tom Rini
2023-08-18  9:39                 ` Maxim Uvarov
2023-08-18 11:14                   ` Peter Robinson
2023-08-18 14:24                     ` Tom Rini
2023-08-14 13:32 ` [PATCHv6 05/14] net/lwip: implement tftp cmd Maxim Uvarov
2023-08-14 14:25   ` Ilias Apalodimas
2023-08-14 18:54     ` Maxim Uvarov
2023-08-14 13:32 ` [PATCHv6 06/14] net/lwip: implement wget cmd Maxim Uvarov
2023-08-16  8:38   ` Ilias Apalodimas
2023-08-14 13:32 ` [PATCHv6 07/14] net/lwip: implement ping cmd Maxim Uvarov
2023-08-16  8:42   ` Ilias Apalodimas
2023-08-16  9:09     ` Maxim Uvarov
2023-08-16 14:39       ` Simon Glass
2023-08-16 20:15         ` Maxim Uvarov
2023-08-18  3:10           ` Simon Glass
2023-08-18  9:27             ` Maxim Uvarov
2023-08-22 18:56               ` Simon Glass
2023-08-14 13:32 ` [PATCHv6 08/14] net/lwip: add lwIP configuration Maxim Uvarov
2023-08-14 13:32 ` [PATCHv6 09/14] net/lwip: implement lwIP port to U-Boot Maxim Uvarov
2023-08-16  9:01   ` Ilias Apalodimas
2023-08-18 12:53     ` Maxim Uvarov
2023-08-18 18:21       ` Simon Goldschmidt
2023-08-14 13:32 ` [PATCHv6 10/14] net/lwip: update .gitignore with lwIP Maxim Uvarov
2023-08-14 13:32 ` [PATCHv6 11/14] net/lwip: connection between cmd and lwip apps Maxim Uvarov
2023-08-16  9:12   ` Ilias Apalodimas
2023-08-14 13:32 ` [PATCHv6 12/14] net/lwip: replace original net commands with lwip Maxim Uvarov
2023-08-14 13:32 ` [PATCHv6 13/14] net/lwip: split net.h to net.h, arp.h and eth.h Maxim Uvarov
2023-08-14 13:32 ` [PATCHv6 14/14] net/lwip: drop old net/wget Maxim Uvarov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230814133253.4150-4-maxim.uvarov@linaro.org \
    --to=maxim.uvarov@linaro.org \
    --cc=goldsimon@gmx.de \
    --cc=ilias.apalodimas@linaro.org \
    --cc=joe.hershberger@ni.com \
    --cc=lwip-devel@nongnu.org \
    --cc=pbrobinson@redhat.com \
    --cc=rfried.dev@gmail.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.