Browse Source

[tftp] Allow fetching larger files by wrapping block number

This patch adds TFTP support for files larger than 65535 blocks by
wrapping the 16-bit block number.

Reported-by: Mark Johnson <johnson.nh@gmail.com>
Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
Signed-off-by: Marty Connor <mdc@etherboot.org>
tags/v1.0.0-rc1
Stefan Hajnoczi 15 years ago
parent
commit
dd99ee95cb
1 changed files with 6 additions and 3 deletions
  1. 6
    3
      src/net/udp/tftp.c

+ 6
- 3
src/net/udp/tftp.c View File

@@ -747,7 +747,7 @@ static int tftp_rx_data ( struct tftp_request *tftp,
747 747
 			  struct io_buffer *iobuf ) {
748 748
 	struct tftp_data *data = iobuf->data;
749 749
 	struct xfer_metadata meta;
750
-	int block;
750
+	unsigned int block;
751 751
 	off_t offset;
752 752
 	size_t data_len;
753 753
 	int rc;
@@ -759,14 +759,17 @@ static int tftp_rx_data ( struct tftp_request *tftp,
759 759
 		rc = -EINVAL;
760 760
 		goto done;
761 761
 	}
762
-	if ( data->block == 0 ) {
762
+
763
+	/* Calculate block number */
764
+	block = ( ( bitmap_first_gap ( &tftp->bitmap ) + 1 ) & ~0xffff );
765
+	if ( data->block == 0 && block == 0 ) {
763 766
 		DBGC ( tftp, "TFTP %p received data block 0\n", tftp );
764 767
 		rc = -EINVAL;
765 768
 		goto done;
766 769
 	}
770
+	block += ( ntohs ( data->block ) - 1 );
767 771
 
768 772
 	/* Extract data */
769
-	block = ( ntohs ( data->block ) - 1 );
770 773
 	offset = ( block * tftp->blksize );
771 774
 	iob_pull ( iobuf, sizeof ( *data ) );
772 775
 	data_len = iob_len ( iobuf );

Loading…
Cancel
Save