[PATCH 1/2] sandbox: Enable wget command

Enable this so that the tests run.
Fix a few warnings in the code so that CI passes.
Signed-off-by: Simon Glass sjg@chromium.org Signed-off-by: Yasuharu Shibata yasuharu.shibata@gmail.com --- cmd/Kconfig | 1 + net/wget.c | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/cmd/Kconfig b/cmd/Kconfig index 978f44eda4..2562701d1e 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -2003,6 +2003,7 @@ config SYS_DISABLE_AUTOLOAD config CMD_WGET bool "wget" select PROT_TCP + default y if SANDBOX help wget is a simple command to download kernel, or other files, from a http server over TCP. diff --git a/net/wget.c b/net/wget.c index f1dd7abeff..945bfd2669 100644 --- a/net/wget.c +++ b/net/wget.c @@ -244,7 +244,7 @@ static void wget_connected(uchar *pkt, unsigned int tcp_seq_num, pkt_in_q = (void *)image_load_addr + PKT_QUEUE_OFFSET + (pkt_q_idx * PKT_QUEUE_PACKET_SIZE);
- ptr1 = map_sysmem((phys_addr_t)pkt_in_q, len); + ptr1 = map_sysmem((ulong)pkt_in_q, len); memcpy(ptr1, pkt, len); unmap_sysmem(ptr1);
@@ -314,9 +314,8 @@ static void wget_connected(uchar *pkt, unsigned int tcp_seq_num, for (i = 0; i < pkt_q_idx; i++) { int err;
- ptr1 = map_sysmem( - (phys_addr_t)(pkt_q[i].pkt), - pkt_q[i].len); + ptr1 = map_sysmem((ulong)pkt_q[i].pkt, + pkt_q[i].len); err = store_block(ptr1, pkt_q[i].tcp_seq_num - initial_data_seq_num,

After applying the following patch, wget test on sandbox failed[1].
Commit: cab7867cff ("net: wget: Support retransmission a dropped packet")
Here are two reasons why the test is failed and how to fix it:
1. tcp_ack is calculated by the wrong value. tcp_ack needs to be calculated by the received TCP payload size. 2. wget command may have a problem that HTTP response from server must be divided into more than two packets. In this commit, HTTP response is divided into two packets.
In addition, I fixed the HTTP response returned at the correct timing.
[1] https://lore.kernel.org/u-boot/CAFLszThEbk2Jr8OZ6Hj21wPSnJjgJhaDe037RqwHvwt1...
Signed-off-by: Yasuharu Shibata yasuharu.shibata@gmail.com Reported-by: Simon Glass sjg@chromium.org --- test/cmd/wget.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-)
diff --git a/test/cmd/wget.c b/test/cmd/wget.c index 356a4dcd8f..11a07c08f4 100644 --- a/test/cmd/wget.c +++ b/test/cmd/wget.c @@ -26,6 +26,8 @@ #define SHIFT_TO_TCPHDRLEN_FIELD(x) ((x) << 4) #define LEN_B_TO_DW(x) ((x) >> 2)
+int net_set_ack_options(union tcp_build_pkt *b); + static int sb_arp_handler(struct udevice *dev, void *packet, unsigned int len) { @@ -105,6 +107,10 @@ static int sb_ack_handler(struct udevice *dev, void *packet, const char *payload1 = "HTTP/1.1 200 OK\r\n" "Content-Length: 30\r\n\r\n\r\n" "<html><body>Hi</body></html>\r\n"; + union tcp_build_pkt *b = (union tcp_build_pkt *)tcp; + const int recv_payload_len = len - net_set_ack_options(b) - IP_HDR_SIZE - ETHER_HDR_SIZE; + static int next_seq; + const int bottom_payload_len = 10;
/* Don't allow the buffer to overrun */ if (priv->recv_packets >= PKTBUFSRX) @@ -119,13 +125,31 @@ static int sb_ack_handler(struct udevice *dev, void *packet, tcp_send->tcp_dst = tcp->tcp_src; data = (void *)tcp_send + IP_TCP_HDR_SIZE;
- if (ntohl(tcp->tcp_seq) == 1 && ntohl(tcp->tcp_ack) == 1) { + if (ntohl(tcp->tcp_seq) == 1 && ntohl(tcp->tcp_ack) == 1 && recv_payload_len == 0) { + // ignore ACK for three-way handshaking + return 0; + } else if (ntohl(tcp->tcp_seq) == 1 && ntohl(tcp->tcp_ack) == 1) { + // recv HTTP request message and reply top half data tcp_send->tcp_seq = htonl(ntohl(tcp->tcp_ack)); - tcp_send->tcp_ack = htonl(ntohl(tcp->tcp_seq) + 1); - payload_len = strlen(payload1); + tcp_send->tcp_ack = htonl(ntohl(tcp->tcp_seq) + recv_payload_len); + + payload_len = strlen(payload1) - bottom_payload_len; memcpy(data, payload1, payload_len); tcp_send->tcp_flags = TCP_ACK; - } else if (ntohl(tcp->tcp_seq) == 2) { + + next_seq = ntohl(tcp_send->tcp_seq) + payload_len; + } else if (ntohl(tcp->tcp_ack) == next_seq) { + // reply bottom half data + const int top_payload_len = strlen(payload1) - bottom_payload_len; + + tcp_send->tcp_seq = htonl(next_seq); + tcp_send->tcp_ack = htonl(ntohl(tcp->tcp_seq) + recv_payload_len); + + payload_len = bottom_payload_len; + memcpy(data, payload1 + top_payload_len, payload_len); + tcp_send->tcp_flags = TCP_ACK; + } else { + // close connection tcp_send->tcp_seq = htonl(ntohl(tcp->tcp_ack)); tcp_send->tcp_ack = htonl(ntohl(tcp->tcp_seq) + 1); payload_len = 0; @@ -148,11 +172,9 @@ static int sb_ack_handler(struct udevice *dev, void *packet, pkt_len, IPPROTO_TCP);
- if (ntohl(tcp->tcp_seq) == 1 || ntohl(tcp->tcp_seq) == 2) { - priv->recv_packet_length[priv->recv_packets] = - ETHER_HDR_SIZE + IP_TCP_HDR_SIZE + payload_len; - ++priv->recv_packets; - } + priv->recv_packet_length[priv->recv_packets] = + ETHER_HDR_SIZE + IP_TCP_HDR_SIZE + payload_len; + ++priv->recv_packets;
return 0; }

Hi Yasuharu,
On Wed, 14 Aug 2024 at 06:48, Yasuharu Shibata yasuharu.shibata@gmail.com wrote:
After applying the following patch, wget test on sandbox failed[1].
Commit: cab7867cff ("net: wget: Support retransmission a dropped packet")
Here are two reasons why the test is failed and how to fix it:
- tcp_ack is calculated by the wrong value. tcp_ack needs to be calculated by the received TCP payload size.
- wget command may have a problem that HTTP response from server must be divided into more than two packets. In this commit, HTTP response is divided into two packets.
In addition, I fixed the HTTP response returned at the correct timing.
[1] https://lore.kernel.org/u-boot/CAFLszThEbk2Jr8OZ6Hj21wPSnJjgJhaDe037RqwHvwt1...
Signed-off-by: Yasuharu Shibata yasuharu.shibata@gmail.com Reported-by: Simon Glass sjg@chromium.org
test/cmd/wget.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org Tested-by: Simon Glass sjg@chromium.org # sandbox
Thanks for sorting this out.
Regards, Simon

On Wed, 14 Aug 2024 at 06:47, Yasuharu Shibata yasuharu.shibata@gmail.com wrote:
Enable this so that the tests run.
Fix a few warnings in the code so that CI passes.
Signed-off-by: Simon Glass sjg@chromium.org Signed-off-by: Yasuharu Shibata yasuharu.shibata@gmail.com
cmd/Kconfig | 1 + net/wget.c | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org
participants (3)
-
Simon Glass
-
Tom Rini
-
Yasuharu Shibata