Subject: Re: [PATCH] qemu tap support broken on current 3.99.17
To: None <tech-pkg@netbsd.org>
From: Luciano R. Furtado <lrfurtado@yahoo.com.br>
List: tech-pkg
Date: 04/16/2006 21:32:03
This is a multi-part message in MIME format.
--------------090203080308030405060902
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Quentin Garnier wrote:
> On Sun, Apr 16, 2006 at 05:45:30PM -0300, Luciano Rodrigues Furtado wrote:
> 
>>Quentin Garnier wrote:
>>
>>>On Sun, Apr 16, 2006 at 05:27:17PM -0300, Luciano Rodrigues Furtado wrote:
>>>
>>>>Quentin Garnier wrote:
>>>>
>>>>>On Sun, Apr 16, 2006 at 09:43:55PM +0200, Hubert Feyrer wrote:
>>>>>
>>>>>>On Sun, 16 Apr 2006, Luciano R. Furtado wrote:
>>>>>>
>>>>>>>qemu when started with -net tap is crashing on tap_open on 
>>>>>>>NetBSD-current, I had to apply the following patch to get it to work
>>>>>>
>>>>>>What will this do on NetBSD 2.x and 3.0?
>>>>>
>>>>>It's a workaround, not a fix.
>>>>>
>>>>
>>>>should I send-pr so somebody can provide a final solution later on?
>>>
>>>What qemu is this?  The one we have in pkgsrc doesn't have support for
>>>our clonable tap(4), and hopefully no NetBSD developer is responsible
>>>for code that doesn't check the return value of an ioctl() call.
>>>
>>
>>That was just a workaround I tried , in order to get qemu working on 
>>current? because it crashes for me on tap_open! What am I  missing here?
> 
> 
> You mean the ioctl() call is your workaround?  Then your diff is
> reversed...  Save the part where you don't check the return value for
> the ioctl(), it is fine, but you have to #ifdef __NetBSD__ it, and leave
> the horrid code it replaces in the #else part of that.
> 
> Thanks for looking at this.  Looking at qemu code is very dangerous for
> the eyes, which is why I never got around adding proper support for
> tap(4) in it.
> 

I have attached what I have here.

--------------090203080308030405060902
Content-Type: text/plain;
 name="vl.c.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="vl.c.patch"

--- vl.c	2006-04-16 16:14:32.000000000 +0000
+++ /tmp/vl.c	2006-04-16 21:23:46.000000000 +0000
@@ -45,6 +45,10 @@
 #include <netinet/in.h>
 #include <dirent.h>
 #include <netdb.h>
+#ifdef __NetBSD__
+#include <net/if.h>
+#include <net/if_tap.h>
+#endif
 #ifdef _BSD
 #include <sys/stat.h>
 #ifndef __APPLE__
@@ -2048,19 +2052,29 @@
 static int tap_open(char *ifname, int ifname_size)
 {
     int fd;
+#ifdef __NetBSD__
+    struct ifreq ifinfo;
+#else
     char *dev;
     struct stat s;
+#endif    
 
     fd = open("/dev/tap", O_RDWR);
     if (fd < 0) {
         fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation\n");
         return -1;
     }
-
+#ifdef __NetBSD__
+     if(ioctl(fd,TAPGIFNAME, &ifinfo) < 0) {
+	 fprintf(stderr, "TAPGIFNAME ioctl failed\n");    
+	 return -1;
+     }
+     pstrcpy(ifname, ifname_size, ifinfo.ifr_name); 
+#else
     fstat(fd, &s);
     dev = devname(s.st_rdev, S_IFCHR);
     pstrcpy(ifname, ifname_size, dev);
-
+#endif
     fcntl(fd, F_SETFL, O_NONBLOCK);
     return fd;
 }

--------------090203080308030405060902--