diff mbox series

net: wget: Support non-default HTTP port

Message ID 20231104151012.51516-1-marex@denx.de
State Changes Requested
Delegated to: Tom Rini
Headers show
Series net: wget: Support non-default HTTP port | expand

Commit Message

Marek Vasut Nov. 4, 2023, 3:09 p.m. UTC
Currently the wget command is hard wired to HTTP port 80. This is
inconvenient, as it is extremely easy to start trivial HTTP server
as an unprivileged user using e.g. python http module to serve the
files, but such a server has to run on one of the higher ports:
"
$ python3 -m http.server -d $(pwd) 8080
"

Make it possible to configure HTTP server port the same way it is
possible to configure TFTP server port, using environment variable
'httpdstp' (similar to 'tftpdstp'). Retain port 80 as the default
fallback port. This way, users can start their own trivial server
and conveniently download whatever files they need into U-Boot.

Signed-off-by: Marek Vasut <marex@denx.de>
---
Cc: "Ying-Chun Liu (PaulLiu)" <paul.liu@linaro.org>
Cc: Duncan Hare <DuncanCHare@yahoo.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Marek Vasut <marex@denx.de>
Cc: Ramon Fried <rfried.dev@gmail.com>
Cc: Simon Glass <sjg@chromium.org>
---
 include/net/wget.h |  1 -
 net/wget.c         | 14 ++++++++++----
 2 files changed, 10 insertions(+), 5 deletions(-)

Comments

Tom Rini Dec. 13, 2023, 2:55 p.m. UTC | #1
On Sat, Nov 04, 2023 at 04:09:54PM +0100, Marek Vasut wrote:

> Currently the wget command is hard wired to HTTP port 80. This is
> inconvenient, as it is extremely easy to start trivial HTTP server
> as an unprivileged user using e.g. python http module to serve the
> files, but such a server has to run on one of the higher ports:
> "
> $ python3 -m http.server -d $(pwd) 8080
> "
> 
> Make it possible to configure HTTP server port the same way it is
> possible to configure TFTP server port, using environment variable
> 'httpdstp' (similar to 'tftpdstp'). Retain port 80 as the default
> fallback port. This way, users can start their own trivial server
> and conveniently download whatever files they need into U-Boot.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> ---
> Cc: "Ying-Chun Liu (PaulLiu)" <paul.liu@linaro.org>
> Cc: Duncan Hare <DuncanCHare@yahoo.com>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Marek Vasut <marex@denx.de>
> Cc: Ramon Fried <rfried.dev@gmail.com>
> Cc: Simon Glass <sjg@chromium.org>
> ---
>  include/net/wget.h |  1 -
>  net/wget.c         | 14 ++++++++++----
>  2 files changed, 10 insertions(+), 5 deletions(-)

Sorry for the late review, can you please update the docs as well with
this? For example 'tftpdstp' is documented in both the environment doc
and the tftp command doc.
diff mbox series

Patch

diff --git a/include/net/wget.h b/include/net/wget.h
index da0920de118..6714f7ea573 100644
--- a/include/net/wget.h
+++ b/include/net/wget.h
@@ -17,6 +17,5 @@  enum wget_state {
 };
 
 #define DEBUG_WGET		0	/* Set to 1 for debug messages */
-#define SERVER_PORT		80
 #define WGET_RETRY_COUNT	30
 #define WGET_TIMEOUT		2000UL
diff --git a/net/wget.c b/net/wget.c
index 8bb4d72db1a..e1e580c8351 100644
--- a/net/wget.c
+++ b/net/wget.c
@@ -14,6 +14,9 @@ 
 #include <net/tcp.h>
 #include <net/wget.h>
 
+/* The default, change with environment variable 'httpdstp' */
+#define SERVER_PORT		80
+
 static const char bootfile1[] = "GET ";
 static const char bootfile3[] = " HTTP/1.0\r\n\r\n";
 static const char http_eom[] = "\r\n\r\n";
@@ -91,19 +94,22 @@  static void wget_send_stored(void)
 	int len = retry_len;
 	unsigned int tcp_ack_num = retry_tcp_seq_num + (len == 0 ? 1 : len);
 	unsigned int tcp_seq_num = retry_tcp_ack_num;
+	unsigned int server_port;
 	uchar *ptr, *offset;
 
+	server_port = env_get_ulong("httpdstp", 10, SERVER_PORT) & 0xffff;
+
 	switch (current_wget_state) {
 	case WGET_CLOSED:
 		debug_cond(DEBUG_WGET, "wget: send SYN\n");
 		current_wget_state = WGET_CONNECTING;
-		net_send_tcp_packet(0, SERVER_PORT, our_port, action,
+		net_send_tcp_packet(0, server_port, our_port, action,
 				    tcp_seq_num, tcp_ack_num);
 		packets = 0;
 		break;
 	case WGET_CONNECTING:
 		pkt_q_idx = 0;
-		net_send_tcp_packet(0, SERVER_PORT, our_port, action,
+		net_send_tcp_packet(0, server_port, our_port, action,
 				    tcp_seq_num, tcp_ack_num);
 
 		ptr = net_tx_packet + net_eth_hdr_size() +
@@ -118,14 +124,14 @@  static void wget_send_stored(void)
 
 		memcpy(offset, &bootfile3, strlen(bootfile3));
 		offset += strlen(bootfile3);
-		net_send_tcp_packet((offset - ptr), SERVER_PORT, our_port,
+		net_send_tcp_packet((offset - ptr), server_port, our_port,
 				    TCP_PUSH, tcp_seq_num, tcp_ack_num);
 		current_wget_state = WGET_CONNECTED;
 		break;
 	case WGET_CONNECTED:
 	case WGET_TRANSFERRING:
 	case WGET_TRANSFERRED:
-		net_send_tcp_packet(0, SERVER_PORT, our_port, action,
+		net_send_tcp_packet(0, server_port, our_port, action,
 				    tcp_seq_num, tcp_ack_num);
 		break;
 	}