]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
net: wget: let wget_with_dns work with dns disabled
authorAdriano Cordova <adrianox@gmail.com>
Wed, 4 Dec 2024 03:05:16 +0000 (00:05 -0300)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Wed, 4 Dec 2024 11:24:37 +0000 (12:24 +0100)
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>
include/net-common.h
lib/efi_loader/efi_bootmgr.c
net/lwip/wget.c
net/net-common.c
net/wget.c

index c5e314b360db8e13e638e0b418e33b5e9b177c65..8fc1bac47f5db04f12857e24dac0af287be62bbe 100644 (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[]);
 
 /**
- * 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
  * @uri:       uri string of target file of wget
  * 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
  *
index 8c51a6ef2edfd4551777ec8fdc48044699eba354..c6124c590d97e803398921e90ae20f619986e2bd 100644 (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);
-       err = wget_with_dns(image_addr, uridp->uri);
+       err = wget_do_request(image_addr, uridp->uri);
        if (err < 0) {
                ret = EFI_INVALID_PARAMETER;
                goto err;
index 263d6dab26c9f44f70ad3d322ea750a010e20905..669eded0f38c05ab24fecaec291f937790cab191 100644 (file)
@@ -353,7 +353,7 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
        return -1;
 }
 
-int wget_with_dns(ulong dst_addr, char *uri)
+int wget_do_request(ulong dst_addr, char *uri)
 {
        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;
 
        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_SUCCESS;
index 45288fe5f80298a6099347eb86bf01b7a6e9c5ce..e01b0da7d7b2268079084e4495b5fd6bc5023e29 100644 (file)
@@ -23,5 +23,5 @@ struct wget_http_info *wget_info;
 int wget_request(ulong dst_addr, char *uri, struct wget_http_info *info)
 {
        wget_info = info ? info : &default_wget_info;
-       return wget_with_dns(dst_addr, uri);
+       return wget_do_request(dst_addr, uri);
 }
index 5d70b7a82e006cfe1f6b14c06f237084b0c20564..f3b43b06b8b53f03f9bda091147185dcc23ad085 100644 (file)
@@ -535,8 +535,7 @@ void wget_start(void)
        wget_send(TCP_SYN, 0, 0, 0);
 }
 
-#if (IS_ENABLED(CONFIG_CMD_DNS))
-int wget_with_dns(ulong dst_addr, char *uri)
+int wget_do_request(ulong dst_addr, char *uri)
 {
        int ret;
        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://");
        host_name = strsep(&s, "/");
        if (!s) {
-               log_err("Error: invalied uri, no file path\n");
                ret = -EINVAL;
                goto out;
        }
        file_name = s;
 
-       /* TODO: If the given uri has ip address for the http server, skip dns */
-       net_dns_resolve = host_name;
-       net_dns_env_var = "httpserverip";
-       if (net_loop(DNS) < 0) {
-               log_err("Error: dns lookup of %s failed, check setup\n", net_dns_resolve);
-               ret = -EINVAL;
-               goto out;
-       }
-       s = env_get("httpserverip");
-       if (!s) {
+       host_name = strsep(&host_name, ":");
+
+       if (string_to_ip(host_name).s_addr) {
+               s = host_name;
+       } else {
+#if IS_ENABLED(CONFIG_CMD_DNS)
+               net_dns_resolve = host_name;
+               net_dns_env_var = "httpserverip";
+               if (net_loop(DNS) < 0) {
+                       ret = -EINVAL;
+                       goto out;
+               }
+               s = env_get("httpserverip");
+               if (!s) {
+                       ret = -EINVAL;
+                       goto out;
+               }
+#else
                ret = -EINVAL;
                goto out;
+#endif
        }
 
        strlcpy(net_boot_file_name, s, sizeof(net_boot_file_name));
@@ -586,7 +593,6 @@ out:
 
        return ret < 0 ? ret : 0;
 }
-#endif
 
 /**
  * wget_validate_uri() - validate the uri for wget