From patchwork Mon Aug 14 13:32:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 713472 Delivered-To: patch@linaro.org Received: by 2002:a5d:4012:0:b0:317:ecd7:513f with SMTP id n18csp1242028wrp; Mon, 14 Aug 2023 06:35:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEBncqjVummn5V1wSKdnbZg1m5FQVmjwSfRG+MDU4j4N2TrI2z7+M8Oue7Oxn9TydZZ0QJi X-Received: by 2002:a1c:7210:0:b0:3fc:182:7eac with SMTP id n16-20020a1c7210000000b003fc01827eacmr8583705wmc.33.1692020145673; Mon, 14 Aug 2023 06:35:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692020145; cv=none; d=google.com; s=arc-20160816; b=nTYLIy/W8k8P6Y9U31TqqdmKhM1I479dC3/yEsMysP9IgaB/oT5AfxHrsJzA7HCJjQ 2gxUdcSRCVEHmlrp7bh9a/Q/0p9ZJGbtKpFnvrVJh/qZkcSoYMIzNqp97n16sl7AJfGR TSdkrOVQfqnPfip+OWVFDxOcgyxmYiDw52aGB3KmXAO9zKWpqKzxE55jjZRYTDaLIiFI unVBm64yR0V1+CPxQF8P+pzsnQvuTbI3s8iXp/vsU3mkL3UJoFpc2qEvIwFjHRByO/vt gkTAuVNWR3aHRZhEqwQAnKYn1EEwf1VLZpAJ98LcCZX3tfF/lewJlGpKKEwesywNftp9 tp+Q== 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=i7fYJuYnoDdTqIbqyJAYF/Jw5jvYcvNcYushZkJLvN4=; fh=KONqw1VFBW9nCv9imase+52c+XJ0MeVkzLj6SOLcJqQ=; b=Q5eb3G+B5iwepl6BD+Dz/5o9F54ZXbphZF8u6eTZt82laU/sEjCdv994MAMMOxjVMc A0hgzyYTrrcw1yuM+FwWpDh9NtYewCEKnO9HLqNsGkvNmUIWc9zCVq/0+kfv3C2SN/Xv 4fEKOpb0mIf7qr8x/PrFvDzzIq6mB6s2QWXgG9MX+KFdWq88hgWCn8E6+PGOXwpuRr8Y vxE9TwEHfzH69m1kn8AdMm+EU4JQN/jDejp+7gNVwI4dfqHVZzdYecLuvr8wqxzewwjy 4O4qUrpwtwKQeHIVPlOvEhCE1Q25tz2xm9U/eHuP10AHcNxQhJaUNCBsKkZQlpwLTex3 Cn8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DOjsmfnQ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id k7-20020a05600c0b4700b003fe1cdbc344si7060715wmr.96.2023.08.14.06.35.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 06:35:45 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DOjsmfnQ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 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) 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 autolearn=ham autolearn_force=no version=3.4.2 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-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 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; +}