From patchwork Fri Sep 8 13:53:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 720816 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp778797wrp; Fri, 8 Sep 2023 06:56:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEhQcDwvn51LjxXI6lKUkdMGVCQTDWh8y57wu/xOdEYgk4k5Eue88+RmnH/H+9VXb8myl8T X-Received: by 2002:adf:e645:0:b0:317:417e:a467 with SMTP id b5-20020adfe645000000b00317417ea467mr4401779wrn.6.1694181364705; Fri, 08 Sep 2023 06:56:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694181364; cv=none; d=google.com; s=arc-20160816; b=ZgXGG8JJW09mqlppdJeqOzVfaEwfdCnDZnMlhb1emA+4UBDdnQwnpKz6fvjbPABTHf FSR42g9OXX0JSE/eeJIAsfmVR46CKtqFir0xKsDNHcYwbxlSbSTqHtFVHVra79y73hVP LzyHj4SKv1dno6GaW3xcURlyVK49+65cJlnougpdNVR2DFS1KnDEvzgSEhFqUVii+4d+ 87MchC1WcmzXYHYrdupF9vzUpfFOsClS4CBqz/t4i3wq7eYLlg2EBHncDDopHdhlPSw/ jwbsl9aMWHWwzQv/Qu+zX18AURvI3XmDWMFyYDMP3dRqzXkizjyl07BplP+IpLhqQvpD xHfg== 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=kTROnAHtoOcj9HwLA+i64O3iQOqf+PBBq8BxgaJV7hY=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=ny9pVswYwr0dZ5q9bSrecv1j77XWapbJbvoVk37FWdsZmwqXqj6/0m6jaGTgn8X4zN oRfFJ18unXC9XxQeZguyJJ6xZuOJ4j9/u3VcHlkNaLyi916z7ehelGVtwbtiVg4SivSm QEQocJAFVDgjvI6fK0aJqd4e2NBR4xjpY1Ld4dtZyQZ0NRjBZSkbo+5POCvrsI6uIh6K 1QJOawKWyV7XF+dkhVyUZnNrQavjyyGnbexu1rxqS7MARh9A8ppyHCuHcu2xGAFhRdUL zec1GqogZ/6J3zL6i3Y8E95XDacgMBWF6paJP1zy3xtXJlNa5HYbOoS2f13FD23FSGsY y0Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=f+88xNSB; 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 l7-20020a05600c1d0700b003fbc722b14asi896507wms.135.2023.09.08.06.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:56:04 -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=f+88xNSB; 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 D3D3E86A40; Fri, 8 Sep 2023 15:55:41 +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="f+88xNSB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5AF0F86A43; Fri, 8 Sep 2023 15:55:41 +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-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) (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 BD77A86A63 for ; Fri, 8 Sep 2023 15:55:37 +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-x22f.google.com with SMTP id 38308e7fff4ca-2be5e2a3c86so38309531fa.0 for ; Fri, 08 Sep 2023 06:55:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694181337; x=1694786137; darn=lists.denx.de; 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=kTROnAHtoOcj9HwLA+i64O3iQOqf+PBBq8BxgaJV7hY=; b=f+88xNSBoh3xNDVqTlFJ17zdO6TTgMUp+znf2m3Oo361liT2VbFwlGefOzcOS2oDfv Qi44mMbdVytSNCLYcRonHKh1YPDgyE9zKmOcCYM2soul7SwTgvyu5BebR7Pcx3nX1f+M 9g/cH/zMd6u1tRZw/+bqbP0o7S2GTRzIyKXy8YwHQM494wDJTwD6Ho3wUVRHiQ0ZWjdA muPbq61/1cn3d74EkTHrNkDXQwgCAMMWkGb3c8ucOnlCMJRtA/Ink7LK/R9geT9xx5bU KIYyi0uLnjbHDf25b3DPt+oByY9gx7U5Esw44G7suU5hg1So2VyscH/QHJCPltgxRyiT Qm8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694181337; x=1694786137; 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=kTROnAHtoOcj9HwLA+i64O3iQOqf+PBBq8BxgaJV7hY=; b=DE5wdgnSz+teXQR3a0Gz9JfBFkKH7uJ5YVsQ5eX/K32hXZqOECiRwZx98tu+zWH/7o g2yr1WBxlnC64JcSi6/0r+Azjw+ogd0Om/VKSvJGWBcXuUL2GZyIOgYe77aO7FvEdA+i ZUJHRtzrtxXe7qW0ri6cqoJupACjbQl3HxTSRHHTp2/e8q8ISSB26nnM6LpJgo0DQFvC i/7ECqe6bCdEcK4bOWf4n+FSW8h8MAlbXV5qo1bkJxffad0A3wN4XimXo81/mNTDJKIx cM5CpB86/vd/KDRU4N3PufSJeI3YtvZxs1lDiV/ryKlAS5b+xRQgYhp26eZUmBfc3vBW 8Egg== X-Gm-Message-State: AOJu0YxrXLoBQz5oRKuFVv3y+rhikgvUmy1qUAAmaeD1pvkvIGUzeeaq m9TXI+Nxaku0ROvnYh+HkkX9qPRiFw46qJDKmwqtjA== X-Received: by 2002:a2e:8285:0:b0:2b6:eceb:9b8 with SMTP id y5-20020a2e8285000000b002b6eceb09b8mr960059ljg.10.1694181336766; Fri, 08 Sep 2023 06:55:36 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id u14-20020a2e9f0e000000b002bcbae4c21fsm306907ljk.50.2023.09.08.06.55.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:55:36 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@gmail.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, Maxim Uvarov Subject: [PATCHv8 03/15] net/lwip: implement dns cmd Date: Fri, 8 Sep 2023 19:53:08 +0600 Message-Id: <20230908135320.7066-4-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230908135320.7066-1-maxim.uvarov@linaro.org> References: <20230908135320.7066-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 U-Boot recently got support for an alternative network stack using LWIP. Replace dns command with the LWIP variant while keeping the output and error messages identical. Signed-off-by: Maxim Uvarov --- include/net/lwip.h | 19 +++++++++++ net/lwip/Makefile | 2 ++ net/lwip/apps/dns/lwip-dns.c | 63 ++++++++++++++++++++++++++++++++++++ 3 files changed, 84 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..ab3db1a214 --- /dev/null +++ b/include/net/lwip.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]); + +/** + * ulwip_dns() - creates the DNS request to resolve a domain host name + * + * 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 + * Returns: ERR_OK(0) for fetching entry from the cache + * -EINPROGRESS 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 3fd5d34564..5d8d5527c6 100644 --- a/net/lwip/Makefile +++ b/net/lwip/Makefile @@ -62,3 +62,5 @@ obj-$(CONFIG_NET) += lwip-external/src/netif/ethernet.o obj-$(CONFIG_NET) += port/if.o obj-$(CONFIG_NET) += port/sys-arch.o + +obj-y += 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..b340302f2c --- /dev/null +++ b/net/lwip/apps/dns/lwip-dns.c @@ -0,0 +1,63 @@ +// 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; + char *ipstr = ip4addr_ntoa(ipaddr); + + if (varname) + env_set(varname, ipstr); + log_info("resolved %s to %s\n", name, ipstr); + 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; + char *dnsenv = env_get("dnsip"); + char *dns2env = env_get("dnsip2"); + + if (!dnsenv && !dns2env) { + log_err("nameserver is not set with dnsip and dnsip2 vars\n"); + return -ENOENT; + } + + if (!dnsenv) + log_warning("dnsip var is not set\n"); + if (!dns2env) + log_warning("dnsip2 var is not set\n"); + + dns_init(); + + if (ipaddr_aton(dnsenv, &dns1)) + dns_setserver(0, &dns1); + + if (ipaddr_aton(dns2env, &dns2)) + dns_setserver(1, &dns2); + + err = dns_gethostbyname(name, &ipaddr, dns_found_cb, varname); + if (err == ERR_OK) + dns_found_cb(name, &ipaddr, varname); + + /* convert lwIP ERR_INPROGRESS to U-Boot -EINPROGRESS */ + if (err == ERR_INPROGRESS) + err = -EINPROGRESS; + + return err; +}