From patchwork Wed Aug 2 14:06:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 709167 Delivered-To: patch@linaro.org Received: by 2002:a5d:55c5:0:b0:317:2194:b2bc with SMTP id i5csp930764wrw; Wed, 2 Aug 2023 07:10:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlHowz8aR4AVeOptjmtK7Dod0NEVNQ/RkwpySKvqTWsojBZzXplPKmh0WW87e+dduKO1extM X-Received: by 2002:a5d:4f05:0:b0:314:4237:8832 with SMTP id c5-20020a5d4f05000000b0031442378832mr4471822wru.48.1690985399861; Wed, 02 Aug 2023 07:09:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690985399; cv=none; d=google.com; s=arc-20160816; b=ThKaHY8zNuPWOuf68drTcT6tzgmnqM3rq/eRxJXLvJpBNyRxqcZCjcs4OlbztCuSPb rz59OXpCk6r9gO9lc/inV0M36xpGBWflUWBmJAJqsblVhuKbtl6KXWzuTmnvMKWr8KO7 DNNmAJnRTGWE32c1r+EFWNCPpdurIB4LF9huydEJwAGxHtqtWebfTaoVtd8J0CFMwbSg sOZRZraEr/9IL/NollWE7+PU/4T8Rceqk8ypxrC9Uh97Lu9I7w+yQHfvjYuM808r7IL8 P7fe01QOQtU0nIkE2bvtZBNiExPJuhMtx5FN8F1giiLt0BKzvlTRHI0W5v62NRgDoaqM fD2Q== 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=6B44LyKd9A4OLaev2STKf6CieJjPEVRQf7Ar7OKN0V4=; fh=KONqw1VFBW9nCv9imase+52c+XJ0MeVkzLj6SOLcJqQ=; b=IsD/Dn0D5v5H3LelaC6xSNmrh4RF2s4nmzqfuFU3wRZbvgTyROBQUzsueVzoAvFmD6 44cPL5TVoDWms5HDQ46eVO9Q0WLZWcdu70Jso3vxeBz9nmT7Uv3xDvNSsTjqhloyWXQd 01G8rjBHU3JrtUvtQo73YlYIoCWKz1B81FUqfmXS9sQO7qMn91Ak2fYkwyJCdfZkAO9v F/e0j+ioEbn0LueJzZUooyf5ATl7kNJKfB0IxaZeZJaZXWWoMxLnmYU6W4BS+3OChHfT WvahDnGExBEg7UQbv8bH4TnwMSQ10k7flX7uiqE3WyAWLYNRd6yTLQ9QSF6Y03fie44B CeLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=E1VThjlm; 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 j19-20020a5d4533000000b00316f251cd51si1198387wra.877.2023.08.02.07.09.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 07:09:59 -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=E1VThjlm; 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 CB63E86A8D; Wed, 2 Aug 2023 16:09:32 +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="E1VThjlm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D451486A8D; Wed, 2 Aug 2023 16:09:31 +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-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) (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 99C2086898 for ; Wed, 2 Aug 2023 16:09:26 +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-x131.google.com with SMTP id 2adb3069b0e04-4fe27849e6aso7007617e87.1 for ; Wed, 02 Aug 2023 07:09:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690985366; x=1691590166; 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=6B44LyKd9A4OLaev2STKf6CieJjPEVRQf7Ar7OKN0V4=; b=E1VThjlmeNX/62cPbUfnWCCCXLWI5j37Zc26jIT8tTaD7AtnZ6ovbglA8cLsvE85hf UBfyX2aPM/yOYokRvrxQoMV3nYxbnmKKs+GQq4eJuu3B0PiMAxzInMxq6Q+8ZKXNba+i c8F1Uw4F7ML58rNgDKkPdDu9enmUGB+pncj4hkPpy2sci6ThEm1DQUdcNl18sRO6ociD iTRpbIcOIH7YYtQa+WRuG3j5/dwiUJf8cculQUSCcQ4P9xNewUpymoWbnROUBV6weUb1 eF7DzIa1ebTKxNnyNbsML7oHO2eIPy1YzT+3buAXTgFSTaBhcgfZDNqEgZKHTW4qR7uj XA2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690985366; x=1691590166; 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=6B44LyKd9A4OLaev2STKf6CieJjPEVRQf7Ar7OKN0V4=; b=d1KhnxgyDkBvfQTzEuhmOTJ5OUAL+feWJwXjIUcdcwDE8wIHrk8z5GXzE8frg4q8ZM gOQcyyhlZxluLO571FJaABroseVGFaHahe+0qHtZ7gzv6x4P7qjRRvNJFe87G5p+u/Uh AvqXJSRJ/OxqtIriT8e1TH//endBXPQgC5iJ7NFJR3QFMPc3TOYIFpHKmjjKlFEagzjE 1Csvkfyy1dDWzIkHWe1I+zVespG5n80mGakoqwfzyhT91Ic0DdkmZOP8z+R+8Ejc1qYn 2Hv5Q3pPkHRNgS+MLxzr8q2m3oFPi50z9l+pdfD40WdugHRpTFvK+rApsrvb3bCHZUVp jEng== X-Gm-Message-State: ABy/qLZ1YQTGNKRZTeuJ+if8tySBFPbmxePjbTFDcKb8sDziwyzQF1zf 6mp1IHOT+B4YQ5TR98mN4ubWtRIusBUwf1/hOGXp/g== X-Received: by 2002:ac2:504d:0:b0:4fd:bc33:e508 with SMTP id a13-20020ac2504d000000b004fdbc33e508mr4802241lfm.49.1690985365812; Wed, 02 Aug 2023 07:09:25 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id a12-20020a056512020c00b004fbbef8d4dbsm2982026lfo.121.2023.08.02.07.09.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 07:09:25 -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: [PATCHv5 03/13] net/lwip: implement dns cmd Date: Wed, 2 Aug 2023 20:06:48 +0600 Message-Id: <20230802140658.10319-4-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230802140658.10319-1-maxim.uvarov@linaro.org> References: <20230802140658.10319-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 Signed-off-by: Maxim Uvarov --- lib/lwip/Makefile | 2 ++ lib/lwip/apps/dns/lwip-dns.c | 46 ++++++++++++++++++++++++++++++++++++ lib/lwip/apps/dns/lwip-dns.h | 3 +++ 3 files changed, 51 insertions(+) create mode 100644 lib/lwip/apps/dns/lwip-dns.c create mode 100644 lib/lwip/apps/dns/lwip-dns.h diff --git a/lib/lwip/Makefile b/lib/lwip/Makefile index 35f34d7afa..2815662093 100644 --- a/lib/lwip/Makefile +++ b/lib/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/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);