version 1.1.1.1, 2018/04/24 17:42:32
|
version 1.1.1.4, 2018/04/24 19:32:57
|
Line 25
|
Line 25
|
#include "net/tap.h" |
#include "net/tap.h" |
#include "qemu-common.h" |
#include "qemu-common.h" |
#include "sysemu.h" |
#include "sysemu.h" |
|
#include "qemu-error.h" |
|
|
#ifdef __NetBSD__ |
#ifdef __NetBSD__ |
|
#include <sys/ioctl.h> |
|
#include <net/if.h> |
#include <net/if_tap.h> |
#include <net/if_tap.h> |
#endif |
#endif |
|
|
Line 36
|
Line 39
|
#include <util.h> |
#include <util.h> |
#endif |
#endif |
|
|
#if defined(__OpenBSD__) |
|
#include <util.h> |
|
#endif |
|
|
|
int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required) |
int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required) |
{ |
{ |
int fd; |
int fd; |
|
#ifdef TAPGIFNAME |
|
struct ifreq ifr; |
|
#else |
char *dev; |
char *dev; |
struct stat s; |
struct stat s; |
|
#endif |
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) |
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) |
/* if no ifname is given, always start the search from tap0. */ |
/* if no ifname is given, always start the search from tap0/tun0. */ |
int i; |
int i; |
char dname[100]; |
char dname[100]; |
|
|
Line 55 int tap_open(char *ifname, int ifname_si
|
Line 58 int tap_open(char *ifname, int ifname_si
|
if (*ifname) { |
if (*ifname) { |
snprintf(dname, sizeof dname, "/dev/%s", ifname); |
snprintf(dname, sizeof dname, "/dev/%s", ifname); |
} else { |
} else { |
|
#if defined(__OpenBSD__) |
|
snprintf(dname, sizeof dname, "/dev/tun%d", i); |
|
#else |
snprintf(dname, sizeof dname, "/dev/tap%d", i); |
snprintf(dname, sizeof dname, "/dev/tap%d", i); |
|
#endif |
} |
} |
TFR(fd = open(dname, O_RDWR)); |
TFR(fd = open(dname, O_RDWR)); |
if (fd >= 0) { |
if (fd >= 0) { |
Line 69 int tap_open(char *ifname, int ifname_si
|
Line 76 int tap_open(char *ifname, int ifname_si
|
} |
} |
} |
} |
if (fd < 0) { |
if (fd < 0) { |
qemu_error("warning: could not open %s (%s): no virtual network emulation\n", dname, strerror(errno)); |
error_report("warning: could not open %s (%s): no virtual network emulation", |
|
dname, strerror(errno)); |
return -1; |
return -1; |
} |
} |
#else |
#else |
TFR(fd = open("/dev/tap", O_RDWR)); |
TFR(fd = open("/dev/tap", O_RDWR)); |
if (fd < 0) { |
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; |
return -1; |
} |
} |
#endif |
#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); |
dev = devname(s.st_rdev, S_IFCHR); |
pstrcpy(ifname, ifname_size, dev); |
pstrcpy(ifname, ifname_size, dev); |
|
#endif |
|
|
if (*vnet_hdr) { |
if (*vnet_hdr) { |
/* BSD doesn't have IFF_VNET_HDR */ |
/* BSD doesn't have IFF_VNET_HDR */ |
*vnet_hdr = 0; |
*vnet_hdr = 0; |
|
|
if (vnet_hdr_required && !*vnet_hdr) { |
if (vnet_hdr_required && !*vnet_hdr) { |
qemu_error("vnet_hdr=1 requested, but no kernel " |
error_report("vnet_hdr=1 requested, but no kernel " |
"support for IFF_VNET_HDR available"); |
"support for IFF_VNET_HDR available"); |
close(fd); |
close(fd); |
return -1; |
return -1; |
} |
} |
Line 114 int tap_probe_has_ufo(int fd)
|
Line 138 int tap_probe_has_ufo(int fd)
|
return 0; |
return 0; |
} |
} |
|
|
|
int tap_probe_vnet_hdr_len(int fd, int len) |
|
{ |
|
return 0; |
|
} |
|
|
|
void tap_fd_set_vnet_hdr_len(int fd, int len) |
|
{ |
|
} |
|
|
void tap_fd_set_offload(int fd, int csum, int tso4, |
void tap_fd_set_offload(int fd, int csum, int tso4, |
int tso6, int ecn, int ufo) |
int tso6, int ecn, int ufo) |
{ |
{ |