commit d3aa8517c648ae1b11fd32290ccc7a86cf711aa2
parent b9b178da3c813f67fcdf9ecfa5cf73b51760b127
Author: Jesus Galan Lopez (yiyus) <yiyu.jgl@gmail.com>
Date: Mon, 7 Jun 2010 23:46:31 +0200
FreeBSD tap device
Diffstat:
2 files changed, 40 insertions(+), 12 deletions(-)
diff --git a/src/9vx/ethertap.c b/src/9vx/ethertap.c
@@ -8,11 +8,9 @@
#include "u.h"
#include <sys/socket.h>
#include <net/if.h>
-#include <netpacket/packet.h>
#include <net/ethernet.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
-#include <linux/if_tun.h>
#include "a/lib.h"
#include "a/mem.h"
@@ -24,11 +22,17 @@
#include "a/etherif.h"
+#ifdef linux
+#include <netpacket/packet.h>
+#include <linux/if_tun.h>
+#elif defined(__FreeBSD__)
+#include <net/if_tun.h>
+#endif
+
extern char *macaddr;
extern char *netdev;
extern int eafrom(char *ma);
-extern void *veerror(char* err);
typedef struct Ctlr Ctlr;
struct Ctlr {
@@ -39,18 +43,18 @@ struct Ctlr {
};
static uchar anyea[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff,};
-static uchar ea[6] = {0x00, 0x48, 0x01, 0x23, 0x45, 0x67};
+static uchar ea[6] = {0x00, 0x48, 0x01, 0x23, 0x45, 0x67};
+#ifdef linux
static int
-setup(void)
+opentap(void)
{
int fd;
- struct ifreq ifr;
char *dev = "tap0";
+ struct ifreq ifr;
if(netdev)
dev = netdev;
-
if((fd = open("/dev/net/tun", O_RDWR)) < 0)
return -1;
memset(&ifr, 0, sizeof ifr);
@@ -60,12 +64,37 @@ setup(void)
close(fd);
return -1;
}
+ // qemu does this:
+ // fcntl(fd, F_SETFL, O_NONBLOCK);
+ return fd;
+}
+#elif defined(__FreeBSD__)
+static int
+opentap(void)
+{
+ int fd;
+ struct stat s;
- if (macaddr && (eafrom(macaddr) == -1))
- return veerror("cannot read mac address");
-
+ if((fd = open("/dev/tap", O_RDWR)) < 0)
+ return -1;
+ fstat(fd, &s);
+ // we don't need the dev name, qemu does
+ // dev = devname(s.st_rdev, S_IFCHR);
+ // qemu does this:
+ // fcntl(fd, F_SETFL, O_NONBLOCK);
return fd;
}
+#endif
+
+static int
+setup(void)
+{
+ if (macaddr && (eafrom(macaddr) == -1)){
+ iprint("ve: cannot read mac address\n");
+ return -1;
+ }
+ return opentap(dev);
+}
Block*
tappkt(Ctlr *c)
@@ -142,7 +171,6 @@ tapattach(Ether* e)
static int
tappnp(Ether* e)
{
- uchar *ea;
Ctlr c;
static int nctlr;
diff --git a/src/9vx/etherve.c b/src/9vx/etherve.c
@@ -48,7 +48,7 @@ eafrom(char *ma)
return 0;
}
-void *
+static void *
veerror(char* err)
{
iprint("ve: %s\n", err);