[PATCHv6 03/14] net/lwip: implement dns cmd

Ilias Apalodimas ilias.apalodimas at linaro.org
Mon Aug 14 16:19:38 CEST 2023


On Mon, Aug 14, 2023 at 07:32:42PM +0600, Maxim Uvarov wrote:
> 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.

What's compatibility code?
I think something along the lines of 

'U-Boot recently got support for an alternative network stack using LWIP.  
Replace XXXX command with the LWIP variant while keeping the output and
error messages identical"

> +
> +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

You need the name of the function as well.  Please have a look at how the
rest of the code is documented. 

> +* 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

@name: etc

> +* @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
> + */
> +
> +#include <common.h>
> +#include <command.h>
> +#include <console.h>
> +
> +#include <lwip/dns.h>
> +#include <lwip/ip_addr.h>
> +
> +#include <net/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));

Why do we have to set the varname to the resolved address?  Is this
something the dns command already does?

> +
> +	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
> 

Thanks
/Ilias


More information about the U-Boot mailing list