Kaynağa Gözat

Autopadding was sometimes overwriting the struct list_head at the end

of the packet buffer.  Although pkbuffs are guaranteed to be at least
PKB_ZLEN bytes long, there's no guarantee that the data starts at the
start of the packet buffer.

Since we have to align data for rtl8139 anyway, and since the start of
the packet buffer is guaranteed to be aligned to PKB_ALIGN, we may as
well just shuffle the packet down so that it starts at the start of
the packet buffer.  This simultaneously aligns the packet and ensures
that there is enough room for the zero-padding.
tags/v0.9.3
Michael Brown 18 yıl önce
ebeveyn
işleme
e822bc2a90
1 değiştirilmiş dosya ile 16 ekleme ve 7 silme
  1. 16
    7
      src/drivers/net/rtl8139.c

+ 16
- 7
src/drivers/net/rtl8139.c Dosyayı Görüntüle

@@ -367,8 +367,10 @@ static void rtl_close ( struct net_device *netdev ) {
367 367
  */
368 368
 static int rtl_transmit ( struct net_device *netdev, struct pk_buff *pkb ) {
369 369
 	struct rtl8139_nic *rtl = netdev->priv;
370
-	int align;
371
-	int pad_len;
370
+	void *data;
371
+	size_t len;
372
+	size_t headroom;
373
+	signed int pad_len;
372 374
 
373 375
 	/* Check for space in TX ring */
374 376
 	if ( rtl->tx.pkb[rtl->tx.next] != NULL ) {
@@ -376,11 +378,18 @@ static int rtl_transmit ( struct net_device *netdev, struct pk_buff *pkb ) {
376 378
 		return -ENOBUFS;
377 379
 	}
378 380
 
379
-	/* Align packet data */
380
-	align = ( virt_to_bus ( pkb->data ) & 0x3 );
381
-	pkb_push ( pkb, align );
382
-	memmove ( pkb->data, pkb->data + align, pkb_len ( pkb ) - align );
383
-	pkb_unput ( pkb, align );
381
+	/* Move packet data to start of packet buffer.  This will both
382
+	 * align the data (since packet buffers are aligned to
383
+	 * PKB_ALIGN) and give us sufficient space for the
384
+	 * zero-padding
385
+	 */
386
+	data = pkb->data;
387
+	len = pkb_len ( pkb );
388
+	headroom = pkb_headroom ( pkb );
389
+	pkb_push ( pkb, headroom );
390
+	memmove ( pkb->data, data, len );
391
+	pkb_unput ( pkb, headroom );
392
+	assert ( ( virt_to_bus ( pkb->data ) & 0x3 ) == 0 );
384 393
 
385 394
 	/* Pad to minimum packet length */
386 395
 	pad_len = ( ETH_ZLEN - pkb_len ( pkb ) );

Loading…
İptal
Kaydet