Skip to contentSkip to conversation

fix network interface tap backend

PATCH Applied Christoph Egger 3 participants 4 messages Jun 17, 2011 – Aug 7, 2011 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix network interface tap backend

Fix network interface tap backend work on NetBSD. It uses an ioctl to get the tap name.

From Manuel Bouyer <[email protected]>

net/tap-bsd.c +2 -0
index 2f3efde..577aafe 100644
@@ -28,6 +28,8 @@
 #include "qemu-error.h"
 
 #ifdef __NetBSD__
+#include <sys/ioctl.h>
+#include <net/if.h>
 #include <net/if_tap.h>
 #endif
 
@@ -40,8 +42,12 @@
 int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int 

vnet_hdr_required)

 {
     int fd;
+#ifdef TAPGIFNAME
+    struct ifreq ifr;
+#else
     char *dev;
     struct stat s;

+#endif

#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) ||
defined(__OpenBSD__)

     /* if no ifname is given, always start the search from tap0/tun0. */
@@ -77,14 +83,30 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required
 #else
     TFR(fd = open("/dev/tap", O_RDWR));
     if (fd < 0) {
-        fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation\n");
+        fprintf(stderr,
+            "warning: could not open /dev/tap: no virtual network emulation: %s\n",
+            strerror(errno));
         return -1;
     }

#endif

- fstat(fd, &s);
+#ifdef TAPGIFNAME
+ if (ioctl(fd, TAPGIFNAME, (void *)&ifr) < 0) {
+ fprintf(stderr, "warning: could not get tap name: %s\n",
+ strerror(errno));
+ return -1;
+ }
+ pstrcpy(ifname, ifname_size, ifr.ifr_name);
+#else
+ if (fstat(fd, &s) < 0) {
+ fprintf(stderr,
+ "warning: could not stat /dev/tap: no virtual network emulation: %s\n",
+ strerror(errno));
+ return -1;
+ }

     dev = devname(s.st_rdev, S_IFCHR);
     pstrcpy(ifname, ifname_size, dev);

+#endif

     if (*vnet_hdr) {
         /* BSD doesn't have IFF_VNET_HDR */
Signature · 6 lines
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85689 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
#1 lore raw
Quoted 12 lines · Christoph Egger

Fix network interface tap backend work on NetBSD.
It uses an ioctl to get the tap name.

From Manuel Bouyer <[email protected]>

net/tap-bsd.c +0 -0
index 2f3efde..577aafe 100644

net/tap-bsd.c line 31

Quoted 4 lines
net/tap-bsd.c +1 -0
@@ -28,6 +28,8 @@
 #include "qemu-error.h"
 
 #ifdef __NetBSD__
+#include <sys/ioctl.h>

Your mailer munged this patch.

Regards,

Anthony Liguori

Quoted 56 lines
net/tap-bsd.c +1 -0
+#include <net/if.h>
 #include <net/if_tap.h>
 #endif
 
@@ -40,8 +42,12 @@

int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required)
{
int fd;

net/tap-bsd.c +3 -0
+#ifdef TAPGIFNAME
+ struct ifreq ifr;
+#else

char *dev;
struct stat s;
+#endif

#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
/* if no ifname is given, always start the search from tap0/tun0. */

net/tap-bsd.c +18 -2
@@ -77,14 +83,30 @@ int tap_open(char *ifname, int ifname_size, int
 *vnet_hdr, int vnet_hdr_required
 #else
 TFR(fd = open("/dev/tap", O_RDWR));
 if (fd < 0) {
- fprintf(stderr, "warning: could not open /dev/tap: no virtual network
 emulation\n");
+ fprintf(stderr,
+ "warning: could not open /dev/tap: no virtual network emulation: %s\n",
+ strerror(errno));
 return -1;
 }
 #endif
 
- fstat(fd, &s);
+#ifdef TAPGIFNAME
+ if (ioctl(fd, TAPGIFNAME, (void *)&ifr) < 0) {
+ fprintf(stderr, "warning: could not get tap name: %s\n",
+ strerror(errno));
+ return -1;
+ }
+ pstrcpy(ifname, ifname_size, ifr.ifr_name);
+#else
+ if (fstat(fd, &s) < 0) {
+ fprintf(stderr,
+ "warning: could not stat /dev/tap: no virtual network emulation: %s\n",
+ strerror(errno));
+ return -1;
+ }
 dev = devname(s.st_rdev, S_IFCHR);
 pstrcpy(ifname, ifname_size, dev);
+#endif
 

if (*vnet_hdr) {
/* BSD doesn't have IFF_VNET_HDR */

#2 lore raw
Quoted 15 lines · Anthony Liguori
Quoted 14 lines · Christoph Egger

Fix network interface tap backend work on NetBSD.
It uses an ioctl to get the tap name.

From Manuel Bouyer<[email protected]>

net/tap-bsd.c +0 -0
index 2f3efde..577aafe 100644
@@ -28,6 +28,8 @@
 #include "qemu-error.h"
 
Quoted 4 lines

net/tap-bsd.c line 31

Quoted 2 lines
net/tap-bsd.c +1 -0
 #ifdef __NetBSD__
+#include<sys/ioctl.h>

Your mailer munged this patch.

... or by the MS Exchange Server.

Resending the patch as attachment, the only one way I have that works for everyone. Sorry.

Fix network interface tap backend work on NetBSD. It uses an ioctl to get the tap name.

From Manuel Bouyer<[email protected]>

Signature · 6 lines
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85689 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
net/tap-bsd.c +24 -2
index 2f3efde..577aafe 100644
@@ -28,6 +28,8 @@
 #include "qemu-error.h"
 
 #ifdef __NetBSD__
+#include <sys/ioctl.h>
+#include <net/if.h>
 #include <net/if_tap.h>
 #endif
 
@@ -40,8 +42,12 @@
 int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required)
 {
     int fd;
+#ifdef TAPGIFNAME
+    struct ifreq ifr;
+#else
     char *dev;
     struct stat s;
+#endif
 
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
     /* if no ifname is given, always start the search from tap0/tun0. */
@@ -77,14 +83,30 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required
 #else
     TFR(fd = open("/dev/tap", O_RDWR));
     if (fd < 0) {
-        fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation\n");
+        fprintf(stderr,
+            "warning: could not open /dev/tap: no virtual network emulation: %s\n",
+            strerror(errno));
         return -1;
     }
 #endif
 
-    fstat(fd, &s);
+#ifdef TAPGIFNAME
+    if (ioctl(fd, TAPGIFNAME, (void *)&ifr) < 0) {
+        fprintf(stderr, "warning: could not get tap name: %s\n",
+            strerror(errno));
+        return -1;
+    }
+    pstrcpy(ifname, ifname_size, ifr.ifr_name);
+#else
+    if (fstat(fd, &s) < 0) {
+        fprintf(stderr,
+            "warning: could not stat /dev/tap: no virtual network emulation: %s\n",
+            strerror(errno));
+        return -1;
+    }
     dev = devname(s.st_rdev, S_IFCHR);
     pstrcpy(ifname, ifname_size, dev);
+#endif
 
     if (*vnet_hdr) {
         /* BSD doesn't have IFF_VNET_HDR */
Applied
#3 lore raw
Quoted 22 lines · Christoph Egger
Quoted 16 lines · Anthony Liguori
Quoted 14 lines · Christoph Egger

Fix network interface tap backend work on NetBSD.
It uses an ioctl to get the tap name.

 From Manuel Bouyer<[email protected]>

net/tap-bsd.c +0 -0
index 2f3efde..577aafe 100644
@@ -28,6 +28,8 @@
 #include "qemu-error.h"
 
Quoted 4 lines

net/tap-bsd.c line 31

Quoted 2 lines
net/tap-bsd.c +1 -0
 #ifdef __NetBSD__
+#include<sys/ioctl.h>

Your mailer munged this patch.

Quoted 4 lines

... or by the MS Exchange Server.

Resending the patch as attachment, the only one way I have that works for everyone. Sorry.

Please attach the whole commit for example from 'git show', instead of just the diff. That can be fed to 'git am' directly. Now I had to combine the lines below and the patch by hand.

Thanks, applied.

Quoted 14 lines

Fix network interface tap backend work on NetBSD. It uses an ioctl to get the tap name.

  From Manuel Bouyer<[email protected]>

--
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85689 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen Registergericht Muenchen, HRB Nr. 43632