Skip to contentSkip to conversation

bug in pcnet patch?

Qemu-devel Zhai, Edwin 1 participant 1 message Sep 5, 2005

lore
Share & tools
lore
#0 lore raw

hi,

i have found that guest and host can't communicate with each other with pcnet patch, but ne2000 is okey.
(http://dad-answers.com/qemu/patches/AMD-PCNET-II/qemu-pcnet.patch6.gz)

reproduce steps --
use attached qemu-ifup and do a "ifconfig eth0 172.20.0.2 up" in guest after boot. the ping between guest and host doesn't work.

root cause is that arp packet from tun interface (42 bytes) is small than the minimal size(60 bytes) and is droped by guest pcnet driver.

attached patch(borrowed from ne2000) just expend the packet when size < 60.

any comments?

thanks,
edwin

#!/bin/sh

echo $*

#test for pcnet's bug
ifconfig $1 172.20.0.1 up
route add -net 172.20.0.0 netmask 255.255.0.0 gw 172.20.0.1 dev $1

hw/pcnet.c +11 -0
@@ -380,10 +380,13 @@
     return sizeof(s->buffer)-16;
 }
 
+#define MIN_BUF_SIZE 60
+
 static void pcnet_receive(void *opaque, const uint8_t *buf, int size)
 {
     PCNetState *s = opaque;
     int is_padr = 0, is_bcast = 0, is_ladr = 0;
+    uint8_t buf1[60];
 
     if (CSR_DRX(s) || CSR_STOP(s) || CSR_SPND(s) || !size)
         return;
@@ -391,6 +394,14 @@
 #ifdef PCNET_DEBUG
     printf("pcnet_receive size=%d\n", size);
 #endif
+
+    /* if too small buffer, then expand it */
+    if (size < MIN_BUF_SIZE) {
+        memcpy(buf1, buf, size);
+        memset(buf1 + size, 0, MIN_BUF_SIZE - size);
+        buf = buf1;
+        size = MIN_BUF_SIZE;
+    }
 
     if (CSR_PROM(s) 
         || (is_padr=padr_match(s, buf, size))