diff options
Diffstat (limited to 'emulators/qemu-devel/files/patch-bt')
-rw-r--r-- | emulators/qemu-devel/files/patch-bt | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/emulators/qemu-devel/files/patch-bt b/emulators/qemu-devel/files/patch-bt new file mode 100644 index 000000000000..7ebddc06f332 --- /dev/null +++ b/emulators/qemu-devel/files/patch-bt @@ -0,0 +1,94 @@ +Index: qemu/vl.c +@@ -41,6 +41,9 @@ + #ifdef _BSD + #include <sys/stat.h> + #include <libutil.h> ++#ifdef __FreeBSD__ ++#include <sys/module.h> ++#endif + #else + #include <linux/if.h> + #include <linux/if_tun.h> +@@ -1022,6 +1025,34 @@ + + #endif /* CONFIG_SLIRP */ + ++#ifdef __FreeBSD__ ++#define LOAD_QUIETLY 1 ++#define LOAD_VERBOSLY 2 ++ ++int ++loadmodules(int how, const char *module, ...) ++{ ++ int loaded = 0; ++ va_list ap; ++ ++ va_start(ap, module); ++#ifndef NO_MODULES ++ while (module != NULL) { ++ if (modfind(module) == -1) { ++ if (kldload(module) == -1) { ++ if (how == LOAD_VERBOSLY) ++ fprintf(stderr, "%s: Cannot load module\n", module); ++ } else ++ loaded++; ++ } ++ module = va_arg(ap, const char *); ++ } ++ va_end(ap); ++#endif ++ return loaded; ++} ++#endif ++ + #if !defined(_WIN32) + #ifdef _BSD + static int tun_open(char *ifname, int ifname_size) +@@ -1030,11 +1061,46 @@ + char *dev; + struct stat s; + ++#ifdef __FreeBSD__ ++ int i, kldtried = 0, enoentcount = 0, err = 0; ++ char dname[100]; ++ for (i = -1; i < 10; i++) { ++ if (i == -1) ++ strcpy(dname, "/dev/tap"); ++ else ++ snprintf(dname, sizeof dname, "%s%d", ++ "/dev/tap", i); ++ fd = open(dname, O_RDWR); ++ if (fd >= 0) ++ break; ++ else if (errno == ENXIO || errno == ENOENT) { ++ if (i == 0 && !kldtried++) { ++ /* ++ * Attempt to load the tunnel interface KLD if it isn't loaded ++ * already. ++ */ ++ if (loadmodules(LOAD_VERBOSLY, "if_tap", NULL)) ++ i = -1; ++ continue; ++ } ++ if (errno != ENOENT || ++enoentcount > 3) { ++ err = errno; ++ break; ++ } ++ } else ++ err = errno; ++ } ++ if (fd < 0) { ++ fprintf(stderr, "warning: could not open %s (%s): no virtual network emulation\n", dname, strerror(err)); ++ return -1; ++ } ++#else + 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 (%s): no virtual network emulation\n", strerror(errno)); + return -1; + } ++#endif + + fstat(fd, &s); + dev = devname(s.st_rdev, S_IFCHR); |