Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DC897C04A6A for ; Mon, 14 Aug 2023 13:35:45 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 642A786975; Mon, 14 Aug 2023 15:35:22 +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="DOjsmfnQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 473D78696C; Mon, 14 Aug 2023 15:35:21 +0200 (CEST) Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) (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 5EFCF807B3 for ; Mon, 14 Aug 2023 15:35:19 +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-lj1-x231.google.com with SMTP id 38308e7fff4ca-2b9ab1725bbso63638821fa.0 for ; Mon, 14 Aug 2023 06:35:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692020118; x=1692624918; 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=i7fYJuYnoDdTqIbqyJAYF/Jw5jvYcvNcYushZkJLvN4=; b=DOjsmfnQVGnBz52a7DPrtE5h4cABQ626xaTCYa3y5T19A3ORqegvt99P+gniYvGPWa YbDkBtSqzBXMsg5I3RKj41n6Kr4bL71sr8fbS2fd8I2ihRF/k5DLxkXwXVUyl2OTqbgJ KY+ZmsExIzxXtK1Vdn13GWGjbjB//0lvcoCXx0Vwq+Yrv5ZAng1lSn80vHnRNHGBpQ0v DIf0XD9Zh9oaCm0+AQa1WnHMH9ywzzo+AFVk3Yn/SqLehEtcNXEH8E5YjZzjaCWgziN1 RCqrJjFKpfwixLtAmRw3gjrAY8nsnrY2Dx6FLNwuc9dUi91tywKvuWQ6aoXrtY3QXBAP 0QAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692020118; x=1692624918; 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=i7fYJuYnoDdTqIbqyJAYF/Jw5jvYcvNcYushZkJLvN4=; b=Og+Xg2CaEsT9d0mOYPIJaIsZNwiNhwvlJ51dzEVSobR3YTw194rHGIsk/z8xRtvyXx v0dOGkh5adN7tMayAtkqvichdMfCFGhUp5OcI/AI9Yg+UBXJkujcA6fSJWisb6tNIybQ S+F07O+XjyHS8heZD9aH95zaR+x4Gzz0caHphL2VOTR4FgnGQPviyEL5PYlN7CeBVy9R vlL8lbxVFWf3TOGtKQRsux+AePvqoTexkGrU2qQIbCCbg4AUX5wfiGAvIHarJtWZZLcf rDqfWzrjYfRypblhscXoB2T3Y5crr0UJs+ElasomNz4zivT/xszp+Pefi9QvFwHrT507 qr0g== X-Gm-Message-State: AOJu0YwMnq0FlvrzOc8nrar/mtyqiAuMMv3laHuzJb6X6YnrGb/xzAmj XH3fRF3RDceLq1G+qwUFRP0MNXHZfppLaQ1Lkps= X-Google-Smtp-Source: AGHT+IE7hz898oUksd8wSdJ40Li1gLQmYum14d9kIroEI9ax2mP1Olir0DLl69J94+MoRzVJO9MjOQ== X-Received: by 2002:a05:651c:145:b0:2b9:ef0a:7d40 with SMTP id c5-20020a05651c014500b002b9ef0a7d40mr6781869ljd.41.1692020118186; Mon, 14 Aug 2023 06:35:18 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id z24-20020a2e9658000000b002b9415597d0sm2411102ljh.78.2023.08.14.06.35.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 06:35:17 -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: [PATCHv6 03/14] net/lwip: implement dns cmd Date: Mon, 14 Aug 2023 19:32:42 +0600 Message-Id: <20230814133253.4150-4-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230814133253.4150-1-maxim.uvarov@linaro.org> References: <20230814133253.4150-1-maxim.uvarov@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 --- 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. + */ + +#include +#include +#include + +#include +#include + +#include + +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