Fix tap breakage on BSD hosts (no IFF_VNET_HDR)
PATCH 1/3 Fix tap breakage on BSD hosts (no IFF_VNET_HDR)
net/tap-bsd.c was assuming IFF_VNET_HDR was always available, which I think isn't true on any BSD.
net/tap-bsd.c +11 -0
@@ -87,6 +87,17 @@ int tap_open(char *ifname, int ifname_si dev =devname (s.st_rdev,S_IFCHR );pstrcpy (ifname, ifname_size, dev); +if (*vnet_hdr) { +/* BSD doesn't have IFF_VNET_HDR */ + *vnet_hdr =0 ; + +if (vnet_hdr_required && !*vnet_hdr) { +qemu_error ("vnet_hdr=1 requested, but no kernel " +"support for IFF_VNET_HDR available" ); +close (fd); +return -1 ; + } + }fcntl (fd,F_SETFL ,O_NONBLOCK );return fd; }
PATCH 2/3 Avoid segfault on net_tap_init() failure
Check for fd == -1 there.
net/tap.c +3 -0
@@ -400,6 +400,9 @@ int net_init_tap(QemuOpts *opts, Monitor } fd =net_tap_init (opts, &vnet_hdr); +if (fd ==-1 ) { +return -1 ; + } } s =net_tap_fd_init (vlan,"tap" , name, fd, vnet_hdr);
PATCH 3/3 tap-bsd: handle ifname on FreeBSD hosts
In reply to Juergen LockHandle ifname on FreeBSD hosts; if no ifname is given, always start the search from tap0. (Simplified/cleaned up version of what has been in the FreeBSD ports for a long time.)
net/tap-bsd.c +28 -0
@@ -49,11 +49,39 @@ int tap_open(char *ifname, int ifname_sichar *dev;struct stat s; +#ifdef __FreeBSD__ +/* if no ifname is given, always start the search from tap0. */ +int i; +char dname[100 ]; + +for (i =0 ; i <10 ; i++) { +if (*ifname) { +snprintf (dname,sizeof dname,"/dev/%s" , ifname); + }else { +snprintf (dname,sizeof dname,"/dev/tap%d" , i); + } +TFR (fd =open (dname,O_RDWR )); +if (fd >=0 ) { +break ; + } +else if (errno ==ENXIO || errno ==ENOENT ) { +break ; + } +if (*ifname) { +break ; + } + } +if (fd <0 ) { +qemu_error ("warning: could not open %s (%s): no virtual network emulation\n" , dname,strerror (errno)); +return -1 ; + } +#else TFR (fd =open ("/dev/tap" ,O_RDWR ));if (fd <0 ) {fprintf (stderr,"warning: could not open /dev/tap: no virtual network emulation\n" );return -1 ; } +#endif fstat (fd, &s); dev =devname (s.st_rdev,S_IFCHR );
cover Misc tap fixes found on FreeBSD
In reply to Juergen LockHi!
I made another experimental FreeBSD qemu git snapshot port update
(see other mail), and came up with these patches when getting tap back to working order again:
1. Fix tap breakage on BSD hosts (no IFF_VNET_HDR)
2. Avoid segfault on net_tap_init() failure
3. tap-bsd: handle ifname on FreeBSD hosts