net: wget: let wget_with_dns work with dns disabled

This was marked as TODO in the code:
 - Enable use of wget_with_dns even if CMD_DNS is disabled if
   the given uri has the ip address for the http server.
 - Move the check for CMD_DNS inside wget_with_dns.
 - Rename wget_with_dns to wget_do_request

Signed-off-by: Adriano Cordova <adrianox@gmail.com>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
This commit is contained in:
Adriano Cordova 2024-12-04 00:05:16 -03:00 committed by Heinrich Schuchardt
parent dc7c8a2532
commit 9bab7d2a7c
5 changed files with 29 additions and 20 deletions

View file

@ -501,13 +501,16 @@ int dhcp_run(ulong addr, const char *fname, bool autoload);
int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
/** /**
* wget_with_dns() - runs dns host IP address resulution before wget * wget_do_request() - sends a wget request
*
* Sends a wget request, if DNS resolution is enabled it resolves the
* given uri.
* *
* @dst_addr: destination address to download the file * @dst_addr: destination address to download the file
* @uri: uri string of target file of wget * @uri: uri string of target file of wget
* Return: zero on success, negative if failed * Return: zero on success, negative if failed
*/ */
int wget_with_dns(ulong dst_addr, char *uri); int wget_do_request(ulong dst_addr, char *uri);
/** /**
* wget_validate_uri() - varidate the uri * wget_validate_uri() - varidate the uri
* *

View file

@ -479,7 +479,7 @@ static efi_status_t try_load_from_uri_path(struct efi_device_path_uri *uridp,
} }
image_addr = hextoul(s, NULL); image_addr = hextoul(s, NULL);
err = wget_with_dns(image_addr, uridp->uri); err = wget_do_request(image_addr, uridp->uri);
if (err < 0) { if (err < 0) {
ret = EFI_INVALID_PARAMETER; ret = EFI_INVALID_PARAMETER;
goto err; goto err;

View file

@ -353,7 +353,7 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
return -1; return -1;
} }
int wget_with_dns(ulong dst_addr, char *uri) int wget_do_request(ulong dst_addr, char *uri)
{ {
eth_set_current(); eth_set_current();
@ -387,7 +387,7 @@ int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
return CMD_RET_FAILURE; return CMD_RET_FAILURE;
wget_info = &default_wget_info; wget_info = &default_wget_info;
if (wget_with_dns(dst_addr, nurl)) if (wget_do_request(dst_addr, nurl))
return CMD_RET_FAILURE; return CMD_RET_FAILURE;
return CMD_RET_SUCCESS; return CMD_RET_SUCCESS;

View file

@ -23,5 +23,5 @@ struct wget_http_info *wget_info;
int wget_request(ulong dst_addr, char *uri, struct wget_http_info *info) int wget_request(ulong dst_addr, char *uri, struct wget_http_info *info)
{ {
wget_info = info ? info : &default_wget_info; wget_info = info ? info : &default_wget_info;
return wget_with_dns(dst_addr, uri); return wget_do_request(dst_addr, uri);
} }

View file

@ -535,8 +535,7 @@ void wget_start(void)
wget_send(TCP_SYN, 0, 0, 0); wget_send(TCP_SYN, 0, 0, 0);
} }
#if (IS_ENABLED(CONFIG_CMD_DNS)) int wget_do_request(ulong dst_addr, char *uri)
int wget_with_dns(ulong dst_addr, char *uri)
{ {
int ret; int ret;
char *s, *host_name, *file_name, *str_copy; char *s, *host_name, *file_name, *str_copy;
@ -555,24 +554,32 @@ int wget_with_dns(ulong dst_addr, char *uri)
s = str_copy + strlen("http://"); s = str_copy + strlen("http://");
host_name = strsep(&s, "/"); host_name = strsep(&s, "/");
if (!s) { if (!s) {
log_err("Error: invalied uri, no file path\n");
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
file_name = s; file_name = s;
/* TODO: If the given uri has ip address for the http server, skip dns */ host_name = strsep(&host_name, ":");
net_dns_resolve = host_name;
net_dns_env_var = "httpserverip"; if (string_to_ip(host_name).s_addr) {
if (net_loop(DNS) < 0) { s = host_name;
log_err("Error: dns lookup of %s failed, check setup\n", net_dns_resolve); } else {
ret = -EINVAL; #if IS_ENABLED(CONFIG_CMD_DNS)
goto out; net_dns_resolve = host_name;
} net_dns_env_var = "httpserverip";
s = env_get("httpserverip"); if (net_loop(DNS) < 0) {
if (!s) { ret = -EINVAL;
goto out;
}
s = env_get("httpserverip");
if (!s) {
ret = -EINVAL;
goto out;
}
#else
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
#endif
} }
strlcpy(net_boot_file_name, s, sizeof(net_boot_file_name)); strlcpy(net_boot_file_name, s, sizeof(net_boot_file_name));
@ -586,7 +593,6 @@ out:
return ret < 0 ? ret : 0; return ret < 0 ? ret : 0;
} }
#endif
/** /**
* wget_validate_uri() - validate the uri for wget * wget_validate_uri() - validate the uri for wget