Parcourir la source

[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 il y a 9 ans
Parent
révision
2e72d100af
1 fichiers modifiés avec 11 ajouts et 1 suppressions
  1. 11
    1
      src/drivers/net/ncm.c

+ 11
- 1
src/drivers/net/ncm.c Voir le fichier

390
 	size_t ndp_len;
390
 	size_t ndp_len;
391
 	size_t pkt_offset;
391
 	size_t pkt_offset;
392
 	size_t pkt_len;
392
 	size_t pkt_len;
393
+	size_t headroom;
393
 	size_t len;
394
 	size_t len;
394
 
395
 
395
 	/* Profile overall bulk IN completion */
396
 	/* Profile overall bulk IN completion */
460
 		 * while the device is running.  We therefore copy the
461
 		 * while the device is running.  We therefore copy the
461
 		 * data to a new I/O buffer even if this is the only
462
 		 * data to a new I/O buffer even if this is the only
462
 		 * (or last) packet within the buffer.
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
 		if ( ! pkt ) {
474
 		if ( ! pkt ) {
466
 			/* Record error and continue */
475
 			/* Record error and continue */
467
 			netdev_rx_err ( netdev, NULL, -ENOMEM );
476
 			netdev_rx_err ( netdev, NULL, -ENOMEM );
468
 			continue;
477
 			continue;
469
 		}
478
 		}
479
+		iob_reserve ( pkt, headroom );
470
 		memcpy ( iob_put ( pkt, pkt_len ),
480
 		memcpy ( iob_put ( pkt, pkt_len ),
471
 			 ( iobuf->data + pkt_offset ), pkt_len );
481
 			 ( iobuf->data + pkt_offset ), pkt_len );
472
 
482
 

Chargement…
Annuler
Enregistrer