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 30E5EC04A6A for ; Wed, 2 Aug 2023 14:09:55 +0000 (UTC) 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) 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-Google-Smtp-Source: APBJJlHAPRjjsapVLdHT5zzKYhe4GtsP1iQr3dl503TR5FcZw8HdDN/FPIBdvSf/Lj/MkDGdv+0deg== 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 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 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); -- 2.30.2