net: tftp: Fixes for tftp rollover
cover net: tftp: Fixes for tftp rollover
This patch series fix the tftp block number rollover bugs when sending and receiving large file (block number greater than 16-bit).
Tested receiving and sending large file with block number greater than 0xffff, verified content is 100% matched. Tested file size 128MB and 256MB.
Ley Foon Tan (3):
net: tftp: Fix tftp_prev_block counter update
net: tftp: Fix store_block offset calculation
net: tftp: Fix load_block offset calculation
net/tftp.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
Signature · 1 line
2.19.0
PATCH 1/3 net: tftp: Fix tftp_prev_block counter update
Fixes missing update to tftp_prev_block counter before increase tftp_cur_block counter when do the tftpput operation.
tftp_prev_block counter is used in update_block_number() function to check whether block number (sequence number) is rollover. This bug cause the tftpput command fail to upload a large file when block number is greater than 16-bit (0xFFFF).
--- net/tftp.c | 1 + 1 file changed, 1 insertion(+)
net/tftp.c +1 -0
@@ -478,6 +478,7 @@ static void tftp_handler(uchar *pkt, unsigned dest, struct in_addr sip,int block =ntohs (*s);int ack_ok = (tftp_cur_block == block); + tftp_prev_block = tftp_cur_block; tftp_cur_block = (unsigned short )(block +1 );update_block_number ();if (ack_ok)
Signature · 1 line
2.19.0
PATCH 1/3 net: tftp: Fix tftp_prev_block counter update
Quoted 27 lines · Ley Foon Tan
Fixes missing update to
tftp_prev_blockcounter before increasetftp_cur_blockcounter when do the tftpput operation.
tftp_prev_blockcounter is used inupdate_block_number()function to check whether block number (sequence number) is rollover. This bug cause the tftpput command fail to upload a large file when block number is greater than 16-bit (0xFFFF).Signed-off-by Ley Foon Tan <[email protected]>--- net/tftp.c | 1 + 1 file changed, 1 insertion(+)net/tftp.c +1
-1@@ -478,6 +478,7 @@ static void tftp_handler(uchar *pkt, unsigned dest, struct in_addr sip,int block =ntohs (*s);int ack_ok = (tftp_cur_block == block); + tftp_prev_block = tftp_cur_block; tftp_cur_block = (unsigned short )(block +1 );update_block_number ();if (ack_ok) --
Quoted 2 lines
2.19.0
PATCH 1/3 net: tftp: Fix tftp_prev_block counter update
In reply to Ley Foon TanQuoted 10 lines · Ley Foon Tan
Fixes missing update to
tftp_prev_blockcounter before increasetftp_cur_blockcounter when do the tftpput operation.
tftp_prev_blockcounter is used inupdate_block_number()function to check whether block number (sequence number) is rollover. This bug cause the tftpput command fail to upload a large file when block number is greater than 16-bit (0xFFFF).Signed-off-by Ley Foon Tan <[email protected]>Reviewed-by Ramon Fried <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201001/cf2da63f/attachment.sig>
PATCH 2/3 net: tftp: Fix store_block offset calculation
In reply to Ley Foon Tantftp_cur_block start with 1 for first block, but tftp_cur_block counter is start with zero when block number is rollover. The existing code "tftp_cur_block - 1" will cause the block number become -1 in store_block() when tftp_cur_block is 0 when tftp_cur_block is rollover.
The fix pass in tftp_cur_block to store_block() and minus the tftp_block_size when do the offset calculation.
--- net/tftp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/tftp.c +3 -2
@@ -143,7 +143,8 @@ static unsigned short tftp_block_size_option = CONFIG_TFTP_BLOCKSIZE;static inline int store_block (int block,uchar *src,unsigned int len) { -ulong offset = block * tftp_block_size + tftp_block_wrap_offset; +ulong offset = block * tftp_block_size + tftp_block_wrap_offset - + tftp_block_size;ulong newsize = offset + len;ulong store_addr = tftp_load_addr + offset;#ifdef CONFIG_SYS_DIRECT_FLASH_TFTP
@@ -597,7 +598,7 @@ static void tftp_handler(uchar *pkt, unsigned dest, struct in_addr sip, timeout_count_max = tftp_timeout_count_max;net_set_timeout_handler (timeout_ms, tftp_timeout_handler); -if (store_block (tftp_cur_block -1 , pkt +2 , len)) { +if (store_block (tftp_cur_block, pkt +2 , len)) {eth_halt ();net_set_state (NETLOOP_FAIL );break ;
Signature · 1 line
2.19.0
PATCH 2/3 net: tftp: Fix store_block offset calculation
Quoted 38 lines · Ley Foon Tan
tftp_cur_blockstart with 1 for first block, buttftp_cur_blockcounter is start with zero when block number is rollover. The existing code "tftp_cur_block- 1" will cause the block number become -1 instore_block()whentftp_cur_blockis 0 whentftp_cur_blockis rollover.The fix pass in
tftp_cur_blocktostore_block()and minus thetftp_block_sizewhen do the offset calculation.Signed-off-by Ley Foon Tan <[email protected]>--- net/tftp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)net/tftp.c +3
-3@@ -143,7 +143,8 @@ static unsigned short tftp_block_size_option = CONFIG_TFTP_BLOCKSIZE;static inline int store_block (int block,uchar *src,unsigned int len) { -ulong offset = block * tftp_block_size + tftp_block_wrap_offset; +ulong offset = block * tftp_block_size + tftp_block_wrap_offset - + tftp_block_size;ulong newsize = offset + len;ulong store_addr = tftp_load_addr + offset;#ifdef CONFIG_SYS_DIRECT_FLASH_TFTP @@ -597,7 +598,7 @@ static void tftp_handler(uchar *pkt, unsigned dest, struct in_addr sip, timeout_count_max = tftp_timeout_count_max;net_set_timeout_handler (timeout_ms, tftp_timeout_handler); -if (store_block (tftp_cur_block -1 , pkt +2 , len)) { +if (store_block (tftp_cur_block, pkt +2 , len)) {eth_halt ();net_set_state (NETLOOP_FAIL );break ; --
Quoted 2 lines
2.19.0
PATCH 2/3 net: tftp: Fix store_block offset calculation
In reply to Ley Foon TanQuoted 10 lines · Ley Foon Tan
tftp_cur_blockstart with 1 for first block, buttftp_cur_blockcounter is start with zero when block number is rollover. The existing code "tftp_cur_block- 1" will cause the block number become -1 instore_block()whentftp_cur_blockis 0 whentftp_cur_blockis rollover.The fix pass in
tftp_cur_blocktostore_block()and minus thetftp_block_sizewhen do the offset calculation.Signed-off-by Ley Foon Tan <[email protected]>Reviewed-by Ramon Fried <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201001/d1f3d5dc/attachment.sig>
PATCH 3/3 net: tftp: Fix load_block offset calculation
In reply to Ley Foon TanWhen load the last block, the "len" might not be a block size. This cause loading the incorrect last block data.
The fix change "len" to tftp_block_size and minus one tftp_block_size for offset calculation.
Use same offset calculation formula as in store_block().
--- net/tftp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/tftp.c +2 -1
@@ -218,7 +218,8 @@ static void new_transfer(void)static int load_block (unsigned block,uchar *dst,unsigned len) {/* We may want to get the final block from the previous set */ -ulong offset = ((int )block -1 ) * len + tftp_block_wrap_offset; +ulong offset = block * tftp_block_size + tftp_block_wrap_offset - + tftp_block_size;ulong tosend = len; tosend =min (net_boot_file_size - offset, tosend);
Signature · 1 line
2.19.0
PATCH 3/3 net: tftp: Fix load_block offset calculation
Quoted 29 lines · Ley Foon Tan
When load the last block, the "len" might not be a block size. This cause loading the incorrect last block data.
The fix change "len" to
tftp_block_sizeand minus onetftp_block_sizefor offset calculation.Use same offset calculation formula as in
store_block().Signed-off-by Ley Foon Tan <[email protected]>--- net/tftp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)net/tftp.c +2
-2@@ -218,7 +218,8 @@ static void new_transfer(void)static int load_block (unsigned block,uchar *dst,unsigned len) {/* We may want to get the final block from the previous set */ -ulong offset = ((int )block -1 ) * len + tftp_block_wrap_offset; +ulong offset = block * tftp_block_size + tftp_block_wrap_offset - + tftp_block_size;ulong tosend = len; tosend =min (net_boot_file_size - offset, tosend); --
Quoted 2 lines
2.19.0
PATCH 3/3 net: tftp: Fix load_block offset calculation
In reply to Ley Foon TanQuoted 10 lines · Ley Foon Tan
When load the last block, the "len" might not be a block size. This cause loading the incorrect last block data.
The fix change "len" to
tftp_block_sizeand minus onetftp_block_sizefor offset calculation.Use same offset calculation formula as in
store_block().Signed-off-by Ley Foon Tan <[email protected]>Reviewed-by Ramon Fried <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201001/6f656cb1/attachment.sig>
Tan
cover net: tftp: Fixes for tftp rollover
In reply to Ley Foon TanQuoted 17 lines
-----Original Message-----
From: Tan, Ley Foon <[email protected]>
Sent: Tuesday, August 25, 2020 10:27 AM
To: u-boot at lists.denx.de
Cc: Joe Hershberger <[email protected]>; Ley Foon Tan <[email protected]>; See, Chin Liang <[email protected]>; Tan, Ley Foon <[email protected]>
Subject: [PATCH 0/3] net: tftp: Fixes for tftp rolloverThis patch series fix the tftp block number rollover bugs when sending and receiving large file (block number greater than 16-bit).
Tested receiving and sending large file with block number greater than
0xffff, verified content is 100% matched. Tested file size 128MB and 256MB.
Quoted 7 lines
Ley Foon Tan (3):
net: tftp: Fixtftp_prev_blockcounter update
net: tftp: Fixstore_blockoffset calculation
net: tftp: Fixload_blockoffset calculationnet/tftp.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
Hi Joe
Any comment for these 3 patches?
Thanks.
Regards
Ley Foon