From patchwork Fri Jul 14 14:19:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 702725 Delivered-To: patch@linaro.org Received: by 2002:adf:db4e:0:b0:314:25da:8dc4 with SMTP id f14csp1114279wrj; Fri, 14 Jul 2023 07:23:08 -0700 (PDT) X-Google-Smtp-Source: APBJJlGmwYN2d4BpQOdv7LSWRqIz9hYs5MGqmigwqUWf2U8ztJ/vXXx+sg9gED9fXhGHSH+SuyN8 X-Received: by 2002:a17:906:74db:b0:992:42d4:a7dc with SMTP id z27-20020a17090674db00b0099242d4a7dcmr4475223ejl.21.1689344588220; Fri, 14 Jul 2023 07:23:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689344588; cv=none; d=google.com; s=arc-20160816; b=MROaUHrHqx2noeQfvEVUFo+gZ8th/XuYmB9H4R8xyqucZK1nFG7JqPv5vKbPPu5Z0U nO6ZICFXIxNgYTTpfNqMnrU7AOzFi0QP3rUImolfbsSvn8lp+LRrIH6oeUfWqArm/NHk BxCd0zsqxh2Ja5TFTGzpIfj1uHjCV3oHL3oqBTlCiDzS2vbC89AxL4MluAbn4ypQ/0de aUlhghW7M+jxr1vLnXhNsAQkAa1F1yhJe5fNaEnLraNNAJdfYWLIlFTHYaENS1SaxMJd uccApjyWFokN1kgCTkEomU4XEqWhs6Ji2rAwJS9iKWM6MFmwSQgsxmh4Sd6Zc1cce5vK HXtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3v87f7cM/ERrbjQrT2cSQg9G1XnEhUz63Ih+ldOPrzs=; fh=KONqw1VFBW9nCv9imase+52c+XJ0MeVkzLj6SOLcJqQ=; b=VdW0A2iVcRxjEl3+LVz9kEe1srfgwSr0RoXWh6rMbRMFYYDDfsrUqlMykwlhnglg24 8ivf3FjW4yY1QbGy1LLoncA+Zethgu3aSevFGaiZJCbLzdktNa0UNTqWJ5yxyY9yDpv3 3nAye8a5ke02xVxPNG45WTHI75AebUBTlBBrHmhMevBk/iHR64D3ALQ4HbUdwJ6YkNpL iKg5r0M7ZugWB+sD/Hj7sLH74dfb4Qbbl4rOZqGfAajOwnilFkePqtmUSJv0BHyyljzi ck6hEtUXy23haurIJYsAcCtETExMKGOdDWmQKFc8EbZEo+ZTmJ8lzxafxs7PGvHMs/Gj I0uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bXwNoIUT; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id u13-20020a170906c40d00b00992bf74c31csi1509892ejz.1005.2023.07.14.07.23.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 07:23:08 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bXwNoIUT; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1837886DAA; Fri, 14 Jul 2023 16:22:30 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="bXwNoIUT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 92C2986D9F; Fri, 14 Jul 2023 16:22:27 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7BCCA86D8E for ; Fri, 14 Jul 2023 16:22:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=maxim.uvarov@linaro.org Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-4fbc0314a7bso3321820e87.2 for ; Fri, 14 Jul 2023 07:22:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689344542; x=1691936542; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3v87f7cM/ERrbjQrT2cSQg9G1XnEhUz63Ih+ldOPrzs=; b=bXwNoIUTTKkR636YUuxO3S1/ScDiy2FTx8xX0UTahOSRKtju+7cTdF1UxnlPkgsjC0 Syv/IiKbIhT3YeEECHZeVgdRFWorkaci15x57f/u3qfkWGe0N9mSSfZkXVMMTElvt3E+ BItco0GxGVd6qXtUj50Zqct2HB66qx14ZI66v0NLlLvguIHjChIIedzQ4e40nbl4ylVp CMD5JVPwnxPMGd1foOTLjK+Tfi5U6LGbK8Hd/naiYGRXYq9Sk7sEMwOj3sn8g2cwuIUA EviOQpwSw2s0H/G3q4LgI1abPd1G0myw6bLJdgK7dZN0iA3kUnClwWgFhABS3q82IN16 vV/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689344542; x=1691936542; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3v87f7cM/ERrbjQrT2cSQg9G1XnEhUz63Ih+ldOPrzs=; b=RqQtiMrSpWMeF7tShj8CzIZV8EOXURZPXRhHP4aQz8m+GWZzoykskD4Q6wdNr4Wlql QEu/eRGRzGXNL6NA23LLcFA2EIaIvucVccN0z66k+xOo5hp/zemRA1cC8ZjMOJhXrDYY yb4u8qLnHzf5gPDLFuXunqz1bQutfAHACV/FZhlsXRqHqa5CbReiP6RlMew4CtHtTb41 peHS9ywJqOw94R0BZ6Yp5pAgi11Ihx4dTr/4ZX2GaMa55/ReWRDIRcMuQO+M+Yq8zo9i YC1ojXHfxf9bit1bX73+s/KwINa2x32JLocJs1FeUiGMmT8sob5TDTYcnsDk0rJZM1va 0f9Q== X-Gm-Message-State: ABy/qLaVXgEIA+Soap/wzbs08M/dqtLZ+iw04MbvWp/YbA2/FL/azpRD UBCOhuvJIOGEEs7f3pWmr1KfmN+I7zREW3Gh4jOyxA== X-Received: by 2002:a19:9117:0:b0:4f9:b649:23d2 with SMTP id t23-20020a199117000000b004f9b64923d2mr3637234lfd.42.1689344542601; Fri, 14 Jul 2023 07:22:22 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id w28-20020ac2599c000000b004fb759964a9sm1504703lfn.168.2023.07.14.07.22.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 07:22:22 -0700 (PDT) From: Maxim Uvarov 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 Subject: [PATCHv4 4/5] net/lwip: add dns command Date: Fri, 14 Jul 2023 20:19:59 +0600 Message-Id: <20230714142000.5534-5-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230714142000.5534-1-maxim.uvarov@linaro.org> References: <20230714142000.5534-1-maxim.uvarov@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean dns lwip version of the command. This commmit might be good example how to enable new network command. Signed-off-by: Maxim Uvarov --- cmd/net.c | 41 +++----------------------------- lib/lwip/Kconfig | 2 +- lib/lwip/Makefile | 2 ++ lib/lwip/apps/dns/lwip-dns.c | 46 ++++++++++++++++++++++++++++++++++++ lib/lwip/apps/dns/lwip-dns.h | 3 +++ lib/lwip/cmd-lwip.c | 39 ++++++++++++++++++++++++++++++ lib/lwip/lwipopts.h | 2 +- 7 files changed, 95 insertions(+), 40 deletions(-) create mode 100644 lib/lwip/apps/dns/lwip-dns.c create mode 100644 lib/lwip/apps/dns/lwip-dns.h diff --git a/cmd/net.c b/cmd/net.c index 6d704fba86..2a68477aae 100644 --- a/cmd/net.c +++ b/cmd/net.c @@ -491,45 +491,10 @@ U_BOOT_CMD( #endif #if defined(CONFIG_CMD_DNS) -int do_dns(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) -{ - if (argc == 1) - return CMD_RET_USAGE; - - /* - * We should check for a valid hostname: - * - Each label must be between 1 and 63 characters long - * - the entire hostname has a maximum of 255 characters - * - only the ASCII letters 'a' through 'z' (case-insensitive), - * the digits '0' through '9', and the hyphen - * - cannot begin or end with a hyphen - * - no other symbols, punctuation characters, or blank spaces are - * permitted - * but hey - this is a minimalist implmentation, so only check length - * and let the name server deal with things. - */ - if (strlen(argv[1]) >= 255) { - printf("dns error: hostname too long\n"); - return CMD_RET_FAILURE; - } - - net_dns_resolve = argv[1]; - - if (argc == 3) - net_dns_env_var = argv[2]; - else - net_dns_env_var = NULL; - - if (net_loop(DNS) < 0) { - printf("dns lookup of %s failed, check setup\n", argv[1]); - return CMD_RET_FAILURE; - } - - return CMD_RET_SUCCESS; -} - +extern int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]); U_BOOT_CMD( - dns, 3, 1, do_dns, + dns, 3, 1, do_lwip_dns, "lookup the IP of a hostname", "hostname [envvar]" ); diff --git a/lib/lwip/Kconfig b/lib/lwip/Kconfig index 3688ac3305..5e9062a6da 100644 --- a/lib/lwip/Kconfig +++ b/lib/lwip/Kconfig @@ -26,7 +26,7 @@ config LWIP_LIB_UDP config LWIP_LIB_DNS bool "dns" - default n + default y config LWIP_LIB_DHCP bool "dhcp" diff --git a/lib/lwip/Makefile b/lib/lwip/Makefile index e1a8a2a7b7..d6e511dff1 100644 --- a/lib/lwip/Makefile +++ b/lib/lwip/Makefile @@ -99,3 +99,5 @@ obj-$(CONFIG_CMD_TFTPBOOT) += apps/tftp/tftp.o obj-$(CONFIG_CMD_TFTPBOOT) += apps/tftp/lwip-tftp.o obj-$(CONFIG_CMD_DHCP) += apps/dhcp/lwip-dhcp.o + +obj-$(CONFIG_CMD_DNS) += apps/dns/lwip-dns.o diff --git a/lib/lwip/apps/dns/lwip-dns.c b/lib/lwip/apps/dns/lwip-dns.c new file mode 100644 index 0000000000..04fd53bfcb --- /dev/null +++ b/lib/lwip/apps/dns/lwip-dns.c @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * (C) Copyright 2023 Linaro Ltd. + */ + +#include +#include +#include + +#include +#include + +#include "../../../lwip/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)); + + printf("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; +} diff --git a/lib/lwip/apps/dns/lwip-dns.h b/lib/lwip/apps/dns/lwip-dns.h new file mode 100644 index 0000000000..c59f99e099 --- /dev/null +++ b/lib/lwip/apps/dns/lwip-dns.h @@ -0,0 +1,3 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +int ulwip_dns(char *name, char *varname); diff --git a/lib/lwip/cmd-lwip.c b/lib/lwip/cmd-lwip.c index 625c8c53b8..86b35ccff8 100644 --- a/lib/lwip/cmd-lwip.c +++ b/lib/lwip/cmd-lwip.c @@ -12,6 +12,7 @@ #include #include +#include "apps/dns/lwip-dns.h" #include "apps/ping/lwip_ping.h" #include "ulwip.h" @@ -208,6 +209,39 @@ static int _do_lwip_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, } #endif /* CONFIG_CMD_DHCP */ +#if defined(CONFIG_CMD_DNS) +int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + int ret; + char *name; + char *varname; + int LWIP_ERR_INPROGRESS = -5; + + if (argc == 1) + return CMD_RET_USAGE; + + name = argv[1]; + + if (argc == 3) + varname = argv[2]; + else + varname = NULL; + + uboot_lwip_init(); + + ret = ulwip_dns(name, varname); + if (ret == 0) + return CMD_RET_SUCCESS; + if (ret != LWIP_ERR_INPROGRESS) + return CMD_RET_FAILURE; + + net_set_timeout_handler(1000UL, ulwip_timeout_handler); + + return ulwip_loop(); +} +#endif /* CONFIG_CMD_DNS */ + static struct cmd_tbl cmds[] = { U_BOOT_CMD_MKENT(info, 1, 0, do_lwip_info, "Info and stats", ""), U_BOOT_CMD_MKENT(init, 1, 0, do_lwip_init, @@ -230,6 +264,11 @@ static struct cmd_tbl cmds[] = { "boot image via network using DHCP/TFTP protocol", ""), #endif +#if defined(CONFIG_CMD_DNS) + U_BOOT_CMD_MKENT(dns, 3, 0, do_lwip_dns, + "lookup dns name [and store address at variable]", + ""), +#endif }; static int do_ops(struct cmd_tbl *cmdtp, int flag, int argc, diff --git a/lib/lwip/lwipopts.h b/lib/lwip/lwipopts.h index b943d7b9be..7f99a536ee 100644 --- a/lib/lwip/lwipopts.h +++ b/lib/lwip/lwipopts.h @@ -43,7 +43,7 @@ #define SLIP_DEBUG LWIP_DBG_OFF #define DHCP_DEBUG LWIP_DBG_ON #define AUTOIP_DEBUG LWIP_DBG_ON -#define DNS_DEBUG LWIP_DBG_OFF +#define DNS_DEBUG LWIP_DBG_ON #define IP6_DEBUG LWIP_DBG_OFF #define DHCP6_DEBUG LWIP_DBG_OFF #else