Quellcode durchsuchen

[ncm] Reserve headroom in received packets

Some protocols (such as ARP) may modify the received packet and re-use
the same I/O buffer for transmission of a reply.  To allow this,
reserve sufficient headroom at the start of each received packet
buffer for our transmit datapath headers.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown vor 9 Jahren
Ursprung
Commit
2e72d100af
1 geänderte Dateien mit 11 neuen und 1 gelöschten Zeilen
  1. 11
    1
      src/drivers/net/ncm.c

+ 11
- 1
src/drivers/net/ncm.c Datei anzeigen

@@ -390,6 +390,7 @@ static void ncm_in_complete ( struct usb_endpoint *ep, struct io_buffer *iobuf,
390 390
 	size_t ndp_len;
391 391
 	size_t pkt_offset;
392 392
 	size_t pkt_len;
393
+	size_t headroom;
393 394
 	size_t len;
394 395
 
395 396
 	/* Profile overall bulk IN completion */
@@ -460,13 +461,22 @@ static void ncm_in_complete ( struct usb_endpoint *ep, struct io_buffer *iobuf,
460 461
 		 * while the device is running.  We therefore copy the
461 462
 		 * data to a new I/O buffer even if this is the only
462 463
 		 * (or last) packet within the buffer.
464
+		 *
465
+		 * We reserve enough space at the start of each buffer
466
+		 * to allow for our own transmission header, to
467
+		 * support protocols such as ARP which may modify the
468
+		 * received packet and reuse the same I/O buffer for
469
+		 * transmission.
463 470
 		 */
464
-		pkt = alloc_iob ( pkt_len );
471
+		headroom = ( sizeof ( struct ncm_ntb_header ) +
472
+			     ncm->out.padding );
473
+		pkt = alloc_iob ( headroom + pkt_len );
465 474
 		if ( ! pkt ) {
466 475
 			/* Record error and continue */
467 476
 			netdev_rx_err ( netdev, NULL, -ENOMEM );
468 477
 			continue;
469 478
 		}
479
+		iob_reserve ( pkt, headroom );
470 480
 		memcpy ( iob_put ( pkt, pkt_len ),
471 481
 			 ( iobuf->data + pkt_offset ), pkt_len );
472 482
 

Laden…
Abbrechen
Speichern