summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/lwip/wget.c28
-rw-r--r--net/net-common.c2
-rw-r--r--net/wget.c45
3 files changed, 44 insertions, 31 deletions
diff --git a/net/lwip/wget.c b/net/lwip/wget.c
index 46858cb5dd3..b76f6c0f1d9 100644
--- a/net/lwip/wget.c
+++ b/net/lwip/wget.c
@@ -40,8 +40,13 @@ struct wget_ctx {
static void wget_lwip_fill_info(struct pbuf *hdr, u16_t hdr_len, u32_t hdr_cont_len)
{
- if (wget_info->headers && hdr_len < MAX_HTTP_HEADERS_SIZE)
- pbuf_copy_partial(hdr, (void *)wget_info->headers, hdr_len, 0);
+ if (wget_info->headers) {
+ if (hdr_len < MAX_HTTP_HEADERS_SIZE)
+ pbuf_copy_partial(hdr, (void *)wget_info->headers, hdr_len, 0);
+ else
+ hdr_len = 0;
+ wget_info->headers[hdr_len] = 0;
+ }
wget_info->hdr_cont_len = (u32)hdr_cont_len;
}
@@ -175,7 +180,7 @@ static int parse_legacy_arg(char *arg, char *nurl, size_t rem)
if (rem < n)
return -1;
- strlcpy(p, server, n);
+ strncpy(p, server, n);
p += n;
rem -= n;
if (rem < 1)
@@ -186,7 +191,7 @@ static int parse_legacy_arg(char *arg, char *nurl, size_t rem)
n = strlen(path);
if (rem < n)
return -1;
- strlcpy(p, path, n);
+ strncpy(p, path, n);
p += n;
rem -= n;
if (rem < 1)
@@ -255,10 +260,9 @@ static void httpc_result_cb(void *arg, httpc_result_t httpc_result,
printf("%u bytes transferred in %lu ms (", rx_content_len, elapsed);
print_size(rx_content_len / elapsed * 1000, "/s)\n");
printf("Bytes transferred = %lu (%lx hex)\n", ctx->size, ctx->size);
- if (wget_info->set_bootdev) {
- efi_set_bootdev("Net", "", ctx->path, map_sysmem(ctx->saved_daddr, 0),
+ if (wget_info->set_bootdev)
+ efi_set_bootdev("Http", ctx->server_name, ctx->path, map_sysmem(ctx->saved_daddr, 0),
rx_content_len);
- }
wget_lwip_set_file_size(rx_content_len);
if (env_set_hex("filesize", rx_content_len) ||
env_set_hex("fileaddr", ctx->saved_daddr)) {
@@ -283,7 +287,6 @@ static err_t httpc_headers_done_cb(httpc_state_t *connection, void *arg, struct
static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
{
- char server_name[SERVER_NAME_SIZE];
#if defined CONFIG_WGET_HTTPS
altcp_allocator_t tls_allocator;
#endif
@@ -292,7 +295,6 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
struct netif *netif;
struct wget_ctx ctx;
char *path;
- u16 port;
bool is_https;
ctx.daddr = dst_addr;
@@ -302,7 +304,7 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
ctx.prevsize = 0;
ctx.start_time = 0;
- if (parse_url(uri, server_name, &port, &path, &is_https))
+ if (parse_url(uri, ctx.server_name, &ctx.port, &path, &is_https))
return CMD_RET_USAGE;
netif = net_lwip_new_netif(udev);
@@ -314,7 +316,7 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
if (is_https) {
tls_allocator.alloc = &altcp_tls_alloc;
tls_allocator.arg =
- altcp_tls_create_config_client(NULL, 0, server_name);
+ altcp_tls_create_config_client(NULL, 0, ctx.server_name);
if (!tls_allocator.arg) {
log_err("error: Cannot create a TLS connection\n");
@@ -350,7 +352,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();
@@ -384,7 +386,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;
diff --git a/net/net-common.c b/net/net-common.c
index 45288fe5f80..e01b0da7d7b 100644
--- a/net/net-common.c
+++ b/net/net-common.c
@@ -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);
}
diff --git a/net/wget.c b/net/wget.c
index 3bc2522cde5..d338eaf4ef3 100644
--- a/net/wget.c
+++ b/net/wget.c
@@ -208,8 +208,13 @@ static void wget_fill_info(const uchar *pkt, int hlen)
const char *second_space;
char *pos, *end;
- if (wget_info->headers && hlen < MAX_HTTP_HEADERS_SIZE)
- strncpy(wget_info->headers, pkt, hlen);
+ if (wget_info->headers) {
+ if (hlen < MAX_HTTP_HEADERS_SIZE)
+ strncpy(wget_info->headers, pkt, hlen);
+ else
+ hlen = 0;
+ wget_info->headers[hlen] = 0;
+ }
//Get status code
first_space = strchr(pkt, ' ');
@@ -442,7 +447,7 @@ static void wget_handler(uchar *pkt, u16 dport,
net_set_state(wget_loop_state);
wget_info->file_size = net_boot_file_size;
if (wget_info->method == WGET_HTTP_METHOD_GET && wget_info->set_bootdev) {
- efi_set_bootdev("Net", "", image_url,
+ efi_set_bootdev("Http", NULL, image_url,
map_sysmem(image_load_addr, 0),
net_boot_file_size);
env_set_hex("filesize", net_boot_file_size);
@@ -530,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;
@@ -550,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));
@@ -581,7 +593,6 @@ out:
return ret < 0 ? ret : 0;
}
-#endif
/**
* wget_validate_uri() - validate the uri for wget