public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Michael Trimarchi <michael@amarulasolutions.com>
To: Fabio Estevam <festevam@gmail.com>
Cc: linux-amarula@amarulasolutions.com, u-boot@lists.denx.de,
	Michael Trimarchi <michael@amarulasolutions.com>
Subject: [RFC PATCH] net: wget: Take in account tcp sequence number wrap around
Date: Sun,  7 Jan 2024 17:34:24 +0100	[thread overview]
Message-ID: <20240107163424.25074-1-michael@amarulasolutions.com> (raw)

Coming from some discussion on mailing about wget unconsistent. It's
just and idea to play around

Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
---

I'm on a train ;). No board to test

---
 include/net/tcp.h | 10 ++++++++++
 net/wget.c        |  8 ++++----
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/include/net/tcp.h b/include/net/tcp.h
index c29d4ce24a..584813b637 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -88,6 +88,16 @@ struct ip_tcp_hdr {
 #define TCP_MSS		1460		/* Max segment size		*/
 #define TCP_SCALE	0x01		/* Scale			*/
 
+/*
+ * The next routines deal with comparing 32 bit unsigned ints
+ * and worry about wraparound (automatic with unsigned arithmetic).
+ */
+static inline bool before(__u32 seq1, __u32 seq2)
+{
+	return (__s32)(seq1-seq2) < 0;
+}
+#define after(seq2, seq1)	before(seq1, seq2)
+
 /**
  * struct tcp_mss - TCP option structure for MSS (Max segment size)
  * @kind: Field ID
diff --git a/net/wget.c b/net/wget.c
index 8bb4d72db1..99a688846f 100644
--- a/net/wget.c
+++ b/net/wget.c
@@ -260,8 +260,8 @@ static void wget_connected(uchar *pkt, unsigned int tcp_seq_num,
 					(phys_addr_t)(pkt_q[i].pkt),
 					pkt_q[i].len);
 				store_block(ptr1,
-					    pkt_q[i].tcp_seq_num -
-					    initial_data_seq_num,
+					    (unsigned int)((s32)pkt_q[i].tcp_seq_num -
+					    (s32)initial_data_seq_num),
 					    pkt_q[i].len);
 				unmap_sysmem(ptr1);
 				debug_cond(DEBUG_WGET,
@@ -333,8 +333,8 @@ static void wget_handler(uchar *pkt, u16 dport,
 			   "wget: Transferring, seq=%x, ack=%x,len=%x\n",
 			   tcp_seq_num, tcp_ack_num, len);
 
-		if (tcp_seq_num >= initial_data_seq_num &&
-		    store_block(pkt, tcp_seq_num - initial_data_seq_num,
+		if (!before(initial_data_seq_num, tcp_seq_num) &&
+		    store_block(pkt, (unsigned int)((s32)tcp_seq_num - (s32)initial_data_seq_num),
 				len) != 0) {
 			wget_fail("wget: store error\n",
 				  tcp_seq_num, tcp_ack_num, action);
-- 
2.40.1


                 reply	other threads:[~2024-01-07 16:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240107163424.25074-1-michael@amarulasolutions.com \
    --to=michael@amarulasolutions.com \
    --cc=festevam@gmail.com \
    --cc=linux-amarula@amarulasolutions.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox