net: wget: Take in account tcp sequence number wrap around
Subsystems (2)
RFC PATCH 1/1 net: wget: Take in account tcp sequence number wrap around
Coming from some discussion on mailing about wget unconsistent. It's just and idea to play around
Signed-off-by Michael Trimarchi <[email protected]>
---
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(-)
include/net/tcp.h +10 -0
@@ -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
net/wget.c +4 -4
@@ -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);
Signature · 1 line
2.40.1