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

Signed-off-by: Michael Trimarchi <mich...@amarulasolutions.com>
---
RFC V1 -> RFC V2:
        - drop random train change in unsigned difference

---
 include/net/tcp.h | 10 ++++++++++
 net/wget.c        |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)

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..020503b763 100644
--- a/net/wget.c
+++ b/net/wget.c
@@ -333,7 +333,7 @@ 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 &&
+               if (!before(initial_data_seq_num, tcp_seq_num) &&
                    store_block(pkt, tcp_seq_num - initial_data_seq_num,
                                len) != 0) {
                        wget_fail("wget: store error\n",
-- 
2.40.1

Reply via email to