Browse Source

[tcp] Allow sufficient headroom for TCP headers

TCP currently neglects to allow sufficient space for its own headers
when allocating I/O buffers.  This problem is masked by the fact that
the maximum link-layer header size (802.11) is substantially larger
than the common Ethernet link-layer header.

Fix by allowing sufficient space for any TCP headers, as well as the
network-layer and link-layer headers.

Reported-by: Scott K Logan <logans@cottsay.net>
Debugged-by: Scott K Logan <logans@cottsay.net>
Tested-by: Scott K Logan <logans@cottsay.net>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 years ago
parent
commit
469bd11f39
2 changed files with 14 additions and 4 deletions
  1. 10
    0
      src/include/ipxe/tcp.h
  2. 4
    4
      src/net/tcp.c

+ 10
- 0
src/include/ipxe/tcp.h View File

308
  */
308
  */
309
 #define TCP_MSL ( 2 * 60 * TICKS_PER_SEC )
309
 #define TCP_MSL ( 2 * 60 * TICKS_PER_SEC )
310
 
310
 
311
+/**
312
+ * TCP maximum header length
313
+ *
314
+ */
315
+#define TCP_MAX_HEADER_LEN					\
316
+	( MAX_LL_NET_HEADER_LEN +				\
317
+	  sizeof ( struct tcp_header ) +			\
318
+	  sizeof ( struct tcp_mss_option ) +			\
319
+	  sizeof ( struct tcp_timestamp_padded_option ) )
320
+
311
 /**
321
 /**
312
  * Compare TCP sequence numbers
322
  * Compare TCP sequence numbers
313
  *
323
  *

+ 4
- 4
src/net/tcp.c View File

509
 		start_timer ( &tcp->timer );
509
 		start_timer ( &tcp->timer );
510
 
510
 
511
 	/* Allocate I/O buffer */
511
 	/* Allocate I/O buffer */
512
-	iobuf = alloc_iob ( len + MAX_LL_NET_HEADER_LEN );
512
+	iobuf = alloc_iob ( len + TCP_MAX_HEADER_LEN );
513
 	if ( ! iobuf ) {
513
 	if ( ! iobuf ) {
514
 		DBGC ( tcp, "TCP %p could not allocate iobuf for %08x..%08x "
514
 		DBGC ( tcp, "TCP %p could not allocate iobuf for %08x..%08x "
515
 		       "%08x\n", tcp, tcp->snd_seq, ( tcp->snd_seq + seq_len ),
515
 		       "%08x\n", tcp, tcp->snd_seq, ( tcp->snd_seq + seq_len ),
516
 		       tcp->rcv_ack );
516
 		       tcp->rcv_ack );
517
 		return -ENOMEM;
517
 		return -ENOMEM;
518
 	}
518
 	}
519
-	iob_reserve ( iobuf, MAX_LL_NET_HEADER_LEN );
519
+	iob_reserve ( iobuf, TCP_MAX_HEADER_LEN );
520
 
520
 
521
 	/* Fill data payload from transmit queue */
521
 	/* Fill data payload from transmit queue */
522
 	tcp_process_tx_queue ( tcp, len, iobuf, 0 );
522
 	tcp_process_tx_queue ( tcp, len, iobuf, 0 );
653
 	int rc;
653
 	int rc;
654
 
654
 
655
 	/* Allocate space for dataless TX buffer */
655
 	/* Allocate space for dataless TX buffer */
656
-	iobuf = alloc_iob ( MAX_LL_NET_HEADER_LEN );
656
+	iobuf = alloc_iob ( TCP_MAX_HEADER_LEN );
657
 	if ( ! iobuf ) {
657
 	if ( ! iobuf ) {
658
 		DBGC ( tcp, "TCP %p could not allocate iobuf for RST "
658
 		DBGC ( tcp, "TCP %p could not allocate iobuf for RST "
659
 		       "%08x..%08x %08x\n", tcp, ntohl ( in_tcphdr->ack ),
659
 		       "%08x..%08x %08x\n", tcp, ntohl ( in_tcphdr->ack ),
660
 		       ntohl ( in_tcphdr->ack ), ntohl ( in_tcphdr->seq ) );
660
 		       ntohl ( in_tcphdr->ack ), ntohl ( in_tcphdr->seq ) );
661
 		return -ENOMEM;
661
 		return -ENOMEM;
662
 	}
662
 	}
663
-	iob_reserve ( iobuf, MAX_LL_NET_HEADER_LEN );
663
+	iob_reserve ( iobuf, TCP_MAX_HEADER_LEN );
664
 
664
 
665
 	/* Construct RST response */
665
 	/* Construct RST response */
666
 	tcphdr = iob_push ( iobuf, sizeof ( *tcphdr ) );
666
 	tcphdr = iob_push ( iobuf, sizeof ( *tcphdr ) );

Loading…
Cancel
Save