ports/76874: New Ports: net/vde

Craig Boston craig at yekse.gank.org
Sun Jan 30 23:30:25 UTC 2005


>Number:         76874
>Category:       ports
>Synopsis:       New Ports: net/vde
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Jan 30 23:30:22 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator:     Craig Boston
>Release:        FreeBSD 5.3-STABLE i386
>Organization:
>Environment:
System: FreeBSD aldaris 5.3-STABLE FreeBSD 5.3-STABLE #0: Sat Jan 29 00:43:03 CST 2005 root at aldaris:/usr/obj/usr/src/sys/ALDARIS i386
>Description:
	VDE is a user-mode ethernet simulation.  It's quite useful for
	hooking together multiple qemu instances into a single virtual
	network without needing root access.  It can also be used for
	tunneling or other network simulation tasks.
>How-To-Repeat:
	n/a
>Fix:

--- vde.shar begins here ---
# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	vde
#	vde/files
#	vde/files/patch-Makefile
#	vde/files/patch-hash.c
#	vde/files/patch-port.c
#	vde/files/patch-qemu::vdeq.c
#	vde/files/patch-slirpvde::ip.h
#	vde/files/patch-slirpvde::slirp_config.h
#	vde/files/patch-slirpvde::slirpvde.c
#	vde/files/patch-slirpvde::tcp.h
#	vde/files/patch-tuntap.c
#	vde/files/patch-vde.h
#	vde/files/patch-vde_plug.c
#	vde/files/patch-vde_switch.c
#	vde/files/patch-vdetaplib::Makefile
#	vde/files/patch-vdetaplib::libvdetap.c
#	vde/files/patch-vdetaplib::test.c
#	vde/files/patch-vdetaplib::vdetap.c
#	vde/files/patch-qemu::Makefile
#	vde/files/patch-slirpvde::Makefile
#	vde/files/patch-slirpvde::libslirp.h
#	vde/Makefile
#	vde/distinfo
#	vde/pkg-descr
#	vde/pkg-plist
#
echo c - vde
mkdir -p vde > /dev/null 2>&1
echo c - vde/files
mkdir -p vde/files > /dev/null 2>&1
echo x - vde/files/patch-Makefile
sed 's/^X//' >vde/files/patch-Makefile << 'END-of-vde/files/patch-Makefile'
X--- Makefile	Sat Jan 29 15:02:08 2005
X+++ Makefile	Sun Jan 30 13:46:59 2005
X@@ -1,14 +1,15 @@
X-TUNTAP = $(shell [ -e /usr/include/linux/if_tun.h ] && echo -DTUNTAP)
X+TUNTAP = $(shell [ -e /usr/include/net/if_tun.h ] && echo -DTUNTAP)
X 
X OBJSSW = hash.o port.o vde_switch.o tuntap.o
X BINSW = vde_switch
X BIN = $(BINSW) dpipe vde_plug
X #CFLAGS = -g -Wall $(TUNTAP) -DINFO -O3
X-CFLAGS = -Wall $(TUNTAP) -O3
X+CFLAGS += -Wall $(TUNTAP) -O
X 
X-BIN_DIR ?= /usr/local/bin
X-LIB_DIR ?= /usr/local/lib
X-MAN_DIR ?= /usr/local/man
X+PREFIX ?= /usr/local
X+BIN_DIR ?= $(PREFIX)/bin
X+LIB_DIR ?= $(PREFIX)/lib
X+MAN_DIR ?= $(PREFIX)/man
X 
X ifneq ($(TUNTAP),)
X 	OBJS += tuntap.o
X@@ -30,13 +31,13 @@
X vde_switch.o: vde_switch.c vde.h switch.h hash.h port.h tuntap.h
X 
X $(BINSW) : $(OBJSSW)
X-	$(CC) $(CFLAGS) -o $(BINSW) $(OBJSSW)
X+	$(CC) $(CFLAGS) $(LDFLAGS) -o $(BINSW) $(OBJSSW)
X 
X dpipe: dpipe.o 
X-	$(CC) $(CFLAGS) -o dpipe dpipe.o	
X+	$(CC) $(CFLAGS) $(LDFLAGS) -o dpipe dpipe.o	
X 	
X vde_plug: vde_plug.o
X-	$(CC) $(CFLAGS) -o vde_plug vde_plug.o
X+	$(CC) $(CFLAGS) $(LDFLAGS) -o vde_plug vde_plug.o
X 
X clean : 
X 	rm -f $(BIN) *.o *~ 
END-of-vde/files/patch-Makefile
echo x - vde/files/patch-hash.c
sed 's/^X//' >vde/files/patch-hash.c << 'END-of-vde/files/patch-hash.c'
X--- hash.c	Sat Jan 29 15:02:08 2005
X+++ hash.c	Sat Jan 29 15:08:18 2005
X@@ -14,7 +14,11 @@
X #include <syslog.h>
X #include <sys/types.h>
X #include <sys/time.h>
X+#ifdef __FreeBSD__
X+#include <signal.h>
X+#else
X #include <sys/signal.h>
X+#endif
X #include "switch.h"
X #include "hash.h"
X 
X@@ -129,7 +133,7 @@
X   printf("Hash: %d Addr: %02x:%02x:%02x:%02x:%02x:%02x to port: %s  " 
X 	 "age %ld secs\n", calc_hash(e->dst),
X 	 e->dst[0], e->dst[1], e->dst[2], e->dst[3], e->dst[4], e->dst[5],
X-	 (*p->port_id)(e->port), (int) p->now - e->last_seen);
X+	 (*p->port_id)(e->port), (long) p->now - e->last_seen);
X }
X 
X void print_hash(char *(*port_id)(void *))
END-of-vde/files/patch-hash.c
echo x - vde/files/patch-port.c
sed 's/^X//' >vde/files/patch-port.c << 'END-of-vde/files/patch-port.c'
X--- port.c	Sat Jan 29 15:02:08 2005
X+++ port.c	Sun Jan 30 11:36:03 2005
X@@ -10,6 +10,9 @@
X #include <syslog.h>
X #include <sys/socket.h>
X #include <sys/un.h>
X+#ifdef __FreeBSD__
X+#include <string.h>
X+#endif
X #include "switch.h"
X #include "hash.h"
X #include "port.h"
X@@ -316,10 +319,19 @@
X 		    port=p->data;
X 		    //if(match_sock(p->control, fd, p->data, p->data_len, &data)) break;
X 		    if(p->data_len == sizeof(struct sock_data) &&
X-				    !(memcmp(&(port->sock), &mine->sock, sizeof(mine->sock)))) break;
X+#ifdef __FreeBSD__
X+				    port->sock.sun_family == mine->sock.sun_family &&
X+				    !(strcmp(port->sock.sun_path, mine->sock.sun_path)))
X+#else
X+				    !(memcmp(&(port->sock), &mine->sock, sizeof(mine->sock))))
X+#endif
X+			    break;
X 	    }
X   }
X-  handle_direct_data(p,hub,&packet,len);
X+  if (i < g_nfds)
X+	handle_direct_data(p,hub,&packet,len);
X+  else
X+	printlog(LOG_WARNING, "No port associated with descriptor %d", fd);
X   return 0;
X }
X 
END-of-vde/files/patch-port.c
echo x - vde/files/patch-qemu::vdeq.c
sed 's/^X//' >vde/files/patch-qemu::vdeq.c << 'END-of-vde/files/patch-qemu::vdeq.c'
X--- qemu/vdeq.c	Sat Jan 29 15:02:08 2005
X+++ qemu/vdeq.c	Sun Jan 30 13:31:46 2005
X@@ -7,14 +7,20 @@
X #include <signal.h>
X #include <errno.h>
X #include <unistd.h>
X+#ifndef __FreeBSD__
X #include <stdint.h>
X+#endif
X #include <libgen.h>
X #include <sys/ioctl.h>
X #include <sys/socket.h>
X #include <sys/un.h>
X #include <sys/uio.h>
X #include <sys/poll.h>
X+#ifdef __FreeBSD__
X+#include <string.h>
X+#include <sys/time.h>
X #include "../vde.h"
X+#endif
X 
X #define SWITCH_MAGIC 0xfeedface
X #define BUFSIZE 2048
X@@ -29,6 +35,15 @@
X   struct sockaddr_un sock;
X };
X 
X+#ifdef __FreeBSD__
X+static char *data_socket = NULL;
X+
X+static void cleanup()
X+{
X+    if(data_socket != NULL)
X+        unlink(data_socket);
X+}
X+#endif
X 
X static int send_fd(char *name, int fddata, struct sockaddr_un *datasock, int intno, int group)
X {
X@@ -37,6 +52,9 @@
X   int fdctl;
X 
X   struct sockaddr_un sock;
X+#ifdef __FreeBSD__
X+  struct timeval tv;
X+#endif
X 
X   if((fdctl = socket(AF_UNIX, SOCK_STREAM, 0)) < 0){
X     perror("socket");
X@@ -56,7 +74,14 @@
X   
X   req.sock.sun_family=AF_UNIX;
X   memset(req.sock.sun_path, 0, sizeof(req.sock.sun_path));
X+#ifdef __FreeBSD__
X+  gettimeofday(&tv, NULL);
X+  snprintf(req.sock.sun_path, sizeof(req.sock.sun_path), "%s.%i.%li",
X+          VDEDATSOCK, pid, tv.tv_usec);
X+  data_socket = strdup(req.sock.sun_path);
X+#else
X   sprintf(&req.sock.sun_path[1], "%5d-%2d", pid, intno);
X+#endif
X 
X   if(bind(fddata, (struct sockaddr *) &req.sock, sizeof(req.sock)) < 0){
X     perror("bind");
X@@ -111,20 +136,23 @@
X static void leave()
X {
X 	fprintf(stderr,"qemu exited: %s quits\n", vdeqname);
X+#ifdef __FreeBSD__
X+	cleanup(0, NULL);
X+#endif
X 	exit(0);
X }
X 
X int main(int argc, char **argv)
X {
X   int *fddata;
X-  char *argsock,**sockname;
X+  char *argsock = NULL,**sockname;
X   struct sockaddr_un *dataout,datain;
X   int datainsize;
X   int result;
X   int group=0;
X   int *connected_fd;
X   register ssize_t nx;
X-  int args;
X+  int args = 0;
X   int newargc;
X   char **newargv;
X   typedef int pair[2];
X@@ -154,10 +182,10 @@
X 		  )) {
X 	  usage();
X   } else if (argc > args+1 && 
X-		  (strcmp(argv[args],"-vdesock")==0) ||
X+		  ((strcmp(argv[args],"-vdesock")==0) ||
X 		  (strcmp(argv[args],"-sock")==0) ||
X 		  (strcmp(argv[args],"-unix")==0) ||
X-		  (strcmp(argv[args],"-s")==0)
X+		  (strcmp(argv[args],"-s")==0))
X 	    ){
X 	  argsock=argv[args+1];
X 	  args+=2;
END-of-vde/files/patch-qemu::vdeq.c
echo x - vde/files/patch-slirpvde::ip.h
sed 's/^X//' >vde/files/patch-slirpvde::ip.h << 'END-of-vde/files/patch-slirpvde::ip.h'
X--- slirpvde/ip.h	Sat Jan 29 15:02:08 2005
X+++ slirpvde/ip.h	Sun Jan 30 14:00:32 2005
X@@ -37,6 +37,31 @@
X #ifndef _IP_H_
X #define _IP_H_
X 
X+#ifdef __FreeBSD__
X+#include <sys/endian.h>
X+
X+#if !defined(__BYTE_ORDER)
X+#if defined(_BYTE_ORDER)
X+#define __BYTE_ORDER _BYTE_ORDER
X+#elif defined(BYTE_ORDER)
X+#define __BYTE_ORDER BYTE_ORDER
X+#else
X+#error BYTE_ORDER not defined
X+#endif
X+#endif /* !defined(__BYTE_ORDER) */
X+
X+#if !defined(__BIG_ENDIAN)
X+#if defined(_BIG_ENDIAN)
X+#define __BIG_ENDIAN _BIG_ENDIAN
X+#elif defined(BIG_ENDIAN)
X+#define __BIG_ENDIAN BIG_ENDIAN
X+#else
X+#error BIG_ENDIAN not defined
X+#endif
X+#endif /* !defined(__BIG_ENDIAN) */
X+
X+#endif /* __FreeBSD__ */
X+
X #if __BYTE_ORDER == __BIG_ENDIAN
X # ifndef NTOHL
X #  define NTOHL(d)
END-of-vde/files/patch-slirpvde::ip.h
echo x - vde/files/patch-slirpvde::slirp_config.h
sed 's/^X//' >vde/files/patch-slirpvde::slirp_config.h << 'END-of-vde/files/patch-slirpvde::slirp_config.h'
X--- slirpvde/slirp_config.h	Sat Jan 29 15:02:08 2005
X+++ slirpvde/slirp_config.h	Sat Jan 29 15:15:18 2005
X@@ -61,10 +61,18 @@
X #define HAVE_STDLIB_H
X 
X /* Define if you have sys/ioctl.h */
X+#ifdef __FreeBSD__
X+#define HAVE_SYS_IOCTL_H
X+#else
X #undef HAVE_SYS_IOCTL_H
X+#endif
X 
X /* Define if you have sys/filio.h */
X+#ifdef __FreeBSD__
X+#define HAVE_SYS_FILIO_H
X+#else
X #undef HAVE_SYS_FILIO_H
X+#endif
X 
X /* Define if you have strerror */
X #define HAVE_STRERROR
X@@ -162,7 +170,11 @@
X #define HAVE_MEMMOVE
X 
X /* Define if you have <termios.h> */
X+#ifdef __FreeBSD__
X+#define HAVE_TERMIOS_H
X+#else
X #undef HAVE_TERMIOS_H
X+#endif
X 
X /* Define if you have gethostid */
X #undef HAVE_GETHOSTID
END-of-vde/files/patch-slirpvde::slirp_config.h
echo x - vde/files/patch-slirpvde::slirpvde.c
sed 's/^X//' >vde/files/patch-slirpvde::slirpvde.c << 'END-of-vde/files/patch-slirpvde::slirpvde.c'
X--- slirpvde/slirpvde.c	Sat Jan 29 15:02:08 2005
X+++ slirpvde/slirpvde.c	Sun Jan 30 14:24:33 2005
X@@ -7,7 +7,9 @@
X #include <signal.h>
X #include <errno.h>
X #include <unistd.h>
X+#ifndef __FreeBSD__
X #include <stdint.h>
X+#endif
X #include <libgen.h>
X #include <sys/ioctl.h>
X #include <sys/socket.h>
X@@ -16,6 +18,10 @@
X #include <sys/poll.h>
X #include <libslirp.h>
X #include <getopt.h>
X+#ifdef __FreeBSD__
X+#include <string.h>
X+#include <sys/time.h>
X+#endif
X 
X #define SWITCH_MAGIC 0xfeedface
X #define BUFSIZE 2048
X@@ -32,6 +38,25 @@
X   struct sockaddr_un sock;
X };
X 
X+#ifdef __FreeBSD__
X+#include "../vde.h"
X+static char *data_socket = NULL;
X+
X+static void cleanup()
X+{
X+    if(data_socket != NULL)
X+        unlink(data_socket);
X+}
X+
X+static void sig_handler(int sig)
X+{
X+  fprintf(stderr, "Caught signal %d, cleaning up and exiting\n", sig);
X+  cleanup(1,NULL);
X+  signal(sig, SIG_DFL);
X+  kill(getpid(), sig);
X+}
X+#endif
X+
X static int send_fd(char *name, int fddata, struct sockaddr_un *datasock, int group)
X {
X   int pid = getpid();
X@@ -39,6 +64,9 @@
X   int fdctl;
X 
X   struct sockaddr_un sock;
X+#ifdef __FreeBSD__
X+  struct timeval tv;
X+#endif
X 
X   if((fdctl = socket(AF_UNIX, SOCK_STREAM, 0)) < 0){
X     perror("socket");
X@@ -58,7 +86,14 @@
X   
X   req.sock.sun_family=AF_UNIX;
X   memset(req.sock.sun_path, 0, sizeof(req.sock.sun_path));
X+#ifdef __FreeBSD__
X+  gettimeofday(&tv, NULL);
X+  snprintf(req.sock.sun_path, sizeof(req.sock.sun_path), "%s.%i.%li",
X+          VDEDATSOCK, pid, tv.tv_usec);
X+  data_socket = strdup(req.sock.sun_path);
X+#else
X   sprintf(&req.sock.sun_path[1], "%5d", pid);
X+#endif
X 
X   if(bind(fddata, (struct sockaddr *) &req.sock, sizeof(req.sock)) < 0){
X     perror("bind");
X@@ -149,7 +184,6 @@
X   int group=0;
X   int connected_fd;
X   register ssize_t nx;
X-  register int i;
X   fd_set rs,ws,xs;
X   int opt,longindx;
X   char *netw=NULL;
X@@ -175,6 +209,12 @@
X     exit(1);
X   }
X   connected_fd=send_fd(sockname, fddata, &dataout, group);
X+#ifdef __FreeBSD__
X+  if(signal(SIGINT, sig_handler) < 0) {
X+        perror("signal");
X+  }
X+  signal(SIGPIPE, SIG_IGN); /* FreeBSD 4.x sends SIGPIPE on reset sockets */
X+#endif
X   slirp_init(netw);
X 
X   for(;;) {
END-of-vde/files/patch-slirpvde::slirpvde.c
echo x - vde/files/patch-slirpvde::tcp.h
sed 's/^X//' >vde/files/patch-slirpvde::tcp.h << 'END-of-vde/files/patch-slirpvde::tcp.h'
X--- slirpvde/tcp.h	Sat Jan 29 15:02:08 2005
X+++ slirpvde/tcp.h	Sun Jan 30 14:00:50 2005
X@@ -37,6 +37,31 @@
X #ifndef _TCP_H_
X #define _TCP_H_
X 
X+#ifdef __FreeBSD__
X+#include <sys/endian.h>
X+
X+#if !defined(__BYTE_ORDER)
X+#if defined(_BYTE_ORDER)
X+#define __BYTE_ORDER _BYTE_ORDER
X+#elif defined(BYTE_ORDER)
X+#define __BYTE_ORDER BYTE_ORDER
X+#else
X+#error BYTE_ORDER not defined
X+#endif
X+#endif /* !defined(__BYTE_ORDER) */
X+
X+#if !defined(__BIG_ENDIAN)
X+#if defined(_BIG_ENDIAN)
X+#define __BIG_ENDIAN _BIG_ENDIAN
X+#elif defined(BIG_ENDIAN)
X+#define __BIG_ENDIAN BIG_ENDIAN
X+#else
X+#error BIG_ENDIAN not defined
X+#endif
X+#endif /* !defined(__BIG_ENDIAN) */
X+
X+#endif /* __FreeBSD__ */
X+
X typedef	u_int32_t	tcp_seq;
X 
X #define      PR_SLOWHZ       2               /* 2 slow timeouts per second (approx) */
END-of-vde/files/patch-slirpvde::tcp.h
echo x - vde/files/patch-tuntap.c
sed 's/^X//' >vde/files/patch-tuntap.c << 'END-of-vde/files/patch-tuntap.c'
X--- tuntap.c	Sat Jan 29 15:02:08 2005
X+++ tuntap.c	Sun Jan 30 00:27:23 2005
X@@ -11,8 +11,16 @@
X #include <unistd.h>
X #include <syslog.h>
X #include <sys/ioctl.h>
X+#ifdef __FreeBSD__
X+#include <sys/types.h>
X+#include <sys/socket.h>
X+#endif
X #include <net/if.h>
X+#ifdef __FreeBSD__
X+#include <net/if_tun.h>
X+#else
X #include <linux/if_tun.h>
X+#endif
X #include "port.h"
X #include "switch.h"
X 
X@@ -28,13 +36,16 @@
X 
X int open_tap(char *dev)
X {
X+#ifndef __FreeBSD__
X   struct ifreq ifr;
X+#endif
X   int fd;
X 
X-  if((fd = open("/dev/net/tun", O_RDWR)) < 0){
X-    printlog(LOG_ERR,"Failed to open /dev/net/tun %s",strerror(errno));
X+  if((fd = open(dev, O_RDWR)) < 0){
X+    printlog(LOG_ERR,"Failed to open %s %s", dev, strerror(errno));
X     return(-1);
X   }
X+#ifndef __FreeBSD__
X   memset(&ifr, 0, sizeof(ifr));
X   ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
X   strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name) - 1);
X@@ -43,5 +54,6 @@
X     close(fd);
X     return(-1);
X   }
X+#endif
X   return(fd);
X }
END-of-vde/files/patch-tuntap.c
echo x - vde/files/patch-vde.h
sed 's/^X//' >vde/files/patch-vde.h << 'END-of-vde/files/patch-vde.h'
X--- vde.h	Sat Jan 29 15:02:08 2005
X+++ vde.h	Sun Jan 30 11:39:43 2005
X@@ -2,6 +2,12 @@
X #define VDESTDSOCK	"/tmp/vde.ctl"
X #endif
X 
X+#ifdef __FreeBSD__
X+#ifndef VDEDATSOCK
X+#define VDEDATSOCK	"/tmp/.vde.data"
X+#endif
X+#endif
X+
X #define DO_SYSLOG
X #define VDE_IP_LOG
X 
END-of-vde/files/patch-vde.h
echo x - vde/files/patch-vde_plug.c
sed 's/^X//' >vde/files/patch-vde_plug.c << 'END-of-vde/files/patch-vde_plug.c'
X--- vde_plug.c	Sat Jan 29 15:02:08 2005
X+++ vde_plug.c	Sun Jan 30 13:52:57 2005
X@@ -7,7 +7,9 @@
X #include <signal.h>
X #include <errno.h>
X #include <unistd.h>
X+#ifndef __FreeBSD__
X #include <stdint.h>
X+#endif
X #include <getopt.h>
X #include <sys/ioctl.h>
X #include <sys/socket.h>
X@@ -15,6 +17,11 @@
X #include <sys/uio.h>
X #include <sys/poll.h>
X #include <sys/utsname.h>
X+#ifdef __FreeBSD__
X+#include <sys/time.h>
X+#include <netinet/in.h>
X+#include <string.h>
X+#endif
X #include "vde.h"
X #ifdef VDE_IP_LOG
X #define DO_SYSLOG
X@@ -47,6 +54,24 @@
X static struct passwd *callerpwd;
X static char host[256];
X 
X+#ifdef __FreeBSD__
X+static char *data_socket = NULL;
X+
X+static void cleanup()
X+{
X+    if(data_socket != NULL)
X+	unlink(data_socket);
X+}
X+
X+static void sig_handler(int sig)
X+{
X+  fprintf(stderr, "Caught signal %d, cleaning up and exiting\n", sig);
X+  cleanup(1,NULL);
X+  signal(sig, SIG_DFL);
X+  kill(getpid(), sig);
X+}
X+#endif
X+
X void write_syslog_entry(char *message)
X {
X 	char *ssh_client;
X@@ -183,6 +208,9 @@
X   int fdctl;
X 
X   struct sockaddr_un sock;
X+#ifdef __FreeBSD__
X+  struct timeval tv;
X+#endif
X 
X   if((fdctl = socket(AF_UNIX, SOCK_STREAM, 0)) < 0){
X     perror("socket");
X@@ -202,7 +230,14 @@
X   
X   req.sock.sun_family=AF_UNIX;
X   memset(req.sock.sun_path, 0, sizeof(req.sock.sun_path));
X+#ifdef __FreeBSD__
X+  gettimeofday(&tv, NULL);
X+  snprintf(req.sock.sun_path, sizeof(req.sock.sun_path), "%s.%i.%li",
X+	  VDEDATSOCK, pid, tv.tv_usec);
X+  data_socket = strdup(req.sock.sun_path);
X+#else
X   sprintf(&req.sock.sun_path[1], "%5d", pid);
X+#endif
X 
X   if(bind(fddata, (struct sockaddr *) &req.sock, sizeof(req.sock)) < 0){
X     perror("bind");
X@@ -309,6 +344,10 @@
X   int connected_fd;
X   register ssize_t nx;
X 
X+#ifdef __FreeBSD__
X+  atexit(cleanup);
X+#endif
X+  
X   uname(&me);
X   if (argv[0][0] == '-')
X 	  netusage(); //implies exit
X@@ -383,6 +422,12 @@
X   }
X   connected_fd=send_fd(sockname, fddata, &dataout, group);
X   pollv[1].fd=fddata;
X+
X+#ifdef __FreeBSD__
X+  if(signal(SIGINT, sig_handler) < 0) {
X+	perror("signal");
X+  }
X+#endif
X 
X   for(;;) {
X 	  result=poll(pollv,2,-1);
END-of-vde/files/patch-vde_plug.c
echo x - vde/files/patch-vde_switch.c
sed 's/^X//' >vde/files/patch-vde_switch.c << 'END-of-vde/files/patch-vde_switch.c'
X--- vde_switch.c	Sat Jan 29 15:02:08 2005
X+++ vde_switch.c	Sun Jan 30 13:33:00 2005
X@@ -8,7 +8,9 @@
X #include <stdlib.h>
X #include <signal.h>
X #include <fcntl.h>
X+#ifndef __FreeBSD__
X #include <stdint.h>
X+#endif
X #include <getopt.h>
X #include <sys/socket.h>
X #include <sys/un.h>
X@@ -17,7 +19,11 @@
X #include <unistd.h>
X #include <syslog.h>
X #include <libgen.h>
X+#ifdef __FreeBSD__
X+#include <string.h>
X+#else
X #include <endian.h>
X+#endif
X #include "vde.h"
X #include "switch.h"
X #include "port.h"
X@@ -95,6 +101,13 @@
X   }
X }
X 
X+#ifdef __FreeBSD__
X+static void cleanupwrapper()
X+{
X+    cleanup(0, NULL);
X+}
X+#endif
X+
X void **g_fdsdata = NULL;
X int g_nfds = 0;
X int g_minfds = 0;
X@@ -276,19 +289,27 @@
X 
X void bind_data_socket(int fd, struct sockaddr_un *sun)
X {
X+  struct timeval tv;
X+
X+  sun->sun_family = AF_UNIX;
X+#ifdef __FreeBSD__
X+  gettimeofday(&tv, NULL);
X+  snprintf(sun->sun_path, sizeof(sun->sun_path), "%s.%i.%li",
X+	  VDEDATSOCK, getpid(), tv.tv_usec);
X+  data_socket = strdup(sun->sun_path);
X+#else
X   struct {
X     char zero;
X     int pid;
X     int usecs;
X   } name;
X-  struct timeval tv;
X 
X   name.zero = 0;
X   name.pid = getpid();
X   gettimeofday(&tv, NULL);
X   name.usecs = tv.tv_usec;
X-  sun->sun_family = AF_UNIX;
X   memcpy(sun->sun_path, &name, sizeof(name));
X+#endif
X   if(bind(fd, (struct sockaddr *) sun, sizeof(*sun)) < 0){
X     printlog(LOG_ERR,"Binding to data socket %s",strerror(errno));
X     exit(1);
X@@ -338,7 +359,11 @@
X   int tap_fd  = -1;
X #endif
X 
X+#ifdef __FreeBSD__
X+  atexit(cleanupwrapper);
X+#else
X   on_exit(cleanup, NULL);
X+#endif
X   prog = argv[0];
X   /* option parsing */
X   {
END-of-vde/files/patch-vde_switch.c
echo x - vde/files/patch-vdetaplib::Makefile
sed 's/^X//' >vde/files/patch-vdetaplib::Makefile << 'END-of-vde/files/patch-vdetaplib::Makefile'
X--- vdetaplib/Makefile	Sat Jan 29 15:02:08 2005
X+++ vdetaplib/Makefile	Sun Jan 30 12:21:39 2005
X@@ -9,7 +9,7 @@
X all: vdetap libvdetap.so
X 
X libvdetap.so: libvdetap.a
X-	$(LD) -E -o $@ -L./ -ldl -shared -export-dynamic -Bdynamic \
X+	$(LD) -E -o $@ -L./ -shared -export-dynamic -Bdynamic \
X 	              --whole-archive libvdetap.a
X 
X libvdetap.a: libvdetap.o
END-of-vde/files/patch-vdetaplib::Makefile
echo x - vde/files/patch-vdetaplib::libvdetap.c
sed 's/^X//' >vde/files/patch-vdetaplib::libvdetap.c << 'END-of-vde/files/patch-vdetaplib::libvdetap.c'
X--- vdetaplib/libvdetap.c	Sat Jan 29 15:02:08 2005
X+++ vdetaplib/libvdetap.c	Sun Jan 30 13:29:07 2005
X@@ -5,26 +5,39 @@
X #include <sys/socket.h>
X #include <sys/syscall.h>
X #include <sys/stat.h>
X+#include <limits.h>
X+#include <dlfcn.h>
X #include <stdarg.h>
X #include <string.h>
X #include <unistd.h>
X #include <stdlib.h>
X-#define __USE_LARGEFILE64
X #include <fcntl.h>
X #include <errno.h>
X #include <signal.h>
X-#include <linux/ioctl.h>
X-#include <linux/if.h>
X-#include <linux/if_tun.h>
X+#include <stdio.h>
X+#include <sys/ioctl.h>
X+#include <net/if.h>
X+#include <net/if_tun.h>
X 
X-#define TUNTAPPATH "/dev/net/tun"
X+#define TUNTAPPATH "/dev/tap"
X #define VDETAPEXEC "vdetap"
X #define VDEALLTAP "VDEALLTAP"
X #define MAX 10
X 
X+#if defined(RTLD_NEXT)
X+#define REAL_LIBC RTLD_NEXT
X+#else
X+#define REAL_LIBC ((void *) -1L)
X+#endif
X+
X+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__bsdi__)
X+typedef unsigned long request_t;
X+#else
X+typedef int request_t;
X+#endif
X+
X int tapfd[2] = {-1,-1};
X static int tapcount=0;
X-static int tuncount=0;
X 
X static struct pidlist {
X 	pid_t pid;
X@@ -39,11 +52,6 @@
X 	return rv;
X }
X 
X-static void plfree (struct pidlist *el) {
X-	el->next=flh;
X-	flh=el;
X-}
X-
X static int addpid(int pid) {
X 	struct pidlist *plp;
X 	if ((plp=plmalloc ()) != NULL) {
X@@ -74,105 +82,41 @@
X 	}
X }
X 
X-	int
X-native_open(const char *pathname, int flags, mode_t data)
X-{
X-	return (syscall(SYS_open, pathname, flags, data));
X-}
X-
X-	int
X-native_ioctl(int fd, unsigned long int command, char *data)
X-{
X-	return (syscall(SYS_ioctl, fd, command, data));
X-}
X-
X-
X int open(const char *path, int flags, ...)
X {
X-	static char buf[PATH_MAX];
X+	static int (*func) (const char *, int, mode_t) = NULL;
X+	char *vdesock;
X+	int pid;
X 	va_list ap;
X 	mode_t data;
X 
X-	va_start(ap, flags);
X-	data = va_arg(ap, mode_t);
X-	va_end(ap);
X-
X-	if (strcmp(path,TUNTAPPATH)==0 && tapfd[0] == -1) {
X-		if (socketpair(PF_UNIX, SOCK_DGRAM, 0,tapfd) == 0) {
X-			return tapfd[0];
X-		}
X-		else
X-			return -1;
X-
X-	} else
X-		return native_open(path, flags, data);
X-}
X-
X-int open64(const char *path, int flags, ...)
X-{
X-	static char buf[PATH_MAX];
X-	va_list ap;
X-	mode_t data;
X+	if (!func)
X+		func = (int (*) (const char *, int, mode_t))
X+		       dlsym (REAL_LIBC, "open");
X 
X 	va_start(ap, flags);
X-	data = va_arg(ap, mode_t);
X+	data = va_arg(ap, int);
X 	va_end(ap);
X 
X 	if (strcmp(path,TUNTAPPATH)==0 && tapfd[0] == -1) {
X 		if (socketpair(PF_UNIX, SOCK_DGRAM, 0,tapfd) == 0) {
X-			return tapfd[0];
X-		}
X-		else
X-			return -1;
X-
X-	} else
X-		return native_open(path, flags | O_LARGEFILE, data);
X-}
X-
X-int ioctl(int fd, unsigned long int command, ...)
X-{
X-	va_list ap;
X-	char *data;
X-	char *vdesock;
X-	int pid;
X-
X-	va_start(ap, command);
X-	data = va_arg(ap, char *);
X-	va_end(ap);
X-
X-	if (fd == tapfd[0]) {
X-		if (command == TUNSETIFF) {
X-			struct ifreq *ifr = (struct ifreq *) data;
X 			char num[5];
X 			char name[10];
X-
X-			ifr->ifr_name[IFNAMSIZ-1] = '\0';
X-			if (ifr->ifr_name[0] == 0) {
X-				if (ifr->ifr_flags & IFF_TAP) 
X-					sprintf(name,"tap%d",tapcount++);
X-				else
X-					sprintf(name,"tun%d",tuncount++);
X-				strncpy(ifr->ifr_name,name,IFNAMSIZ);
X-			}
X-			else if (strchr(ifr->ifr_name, '%') != NULL) {
X-				sprintf(name,ifr->ifr_name,tapcount++);
X-				strncpy(ifr->ifr_name,name,IFNAMSIZ);
X-			}
X-			if (ifr->ifr_flags & IFF_TAP &&
X-					((vdesock=getenv(ifr->ifr_name)) != NULL)
X-					||(vdesock=getenv(VDEALLTAP)) != NULL){
X+			sprintf(name,"tap%d",tapcount++);
X+			if (((vdesock=getenv(name)) != NULL)
X+				||(vdesock=getenv(VDEALLTAP)) != NULL){
X 				if ((pid=fork()) < 0) { 
X 					close(tapfd[1]);
X 					errno=EINVAL;
X 					return -1;
X 				} else if (pid > 0) { /*father*/
X-					if(pid=addpid(pid) < 0) {
X+					if((pid=addpid(pid)) < 0) {
X 						close(tapfd[0]);
X 						close(tapfd[1]);
X 						return -1;
X 					} else {
X 						close(tapfd[1]);
X-						return 0;
X+						return tapfd[0];
X 					}
X 				} else { /*son*/
X 					plh=NULL;
X@@ -181,34 +125,53 @@
X 					execlp(VDETAPEXEC,"-",num,vdesock,(char *) 0);
X 				}
X 			}
X-			else /*roll back to the native tuntap*/
X-			{
X-				int newfd;
X-				int saverrno;
X-				int resultioctl;
X-				close(tapfd[1]);
X-				if ((newfd=native_open(TUNTAPPATH,  O_RDWR, 0)) < 0) {
X-					saverrno=errno;
X-					close(tapfd[0]);
X-					errno=saverrno;
X-					return -1;
X-				} else
X-				{
X-					resultioctl=native_ioctl(fd, command, data);
X-					if (resultioctl < 0) {
X-						saverrno=errno;
X-						close(tapfd[0]);
X-						errno=saverrno;
X-						return -1;
X-					} else {
X-						dup2(newfd,tapfd[0]);
X-						return resultioctl;
X-					}
X-				}
X-			}
X-		}			else 
X-			return 0;
X+			return tapfd[0];
X+		}
X+		else
X+			return -1;
X+
X 	} else
X-		return (native_ioctl(fd, command, data));
X+		return (*func)(path, flags, data);
X+}
X+
X+int ioctl(int fd, unsigned long int command, ...)
X+{
X+	static int (*func) (int, request_t, void *) = NULL;
X+	int dummy;
X+	va_list ap;
X+	char *data;
X+	struct ifstat *ifs;
X+
X+	if (!func)
X+		func = (int (*) (int, request_t, void *))
X+			dlsym (REAL_LIBC, "ioctl");
X+
X+	va_start(ap, command);
X+	data = va_arg(ap, char *);
X+	va_end(ap);
X+
X+	if (fd == tapfd[0]) {
X+		switch(command) {
X+			case SIOCSIFFLAGS:
X+			case SIOCADDMULTI:
X+			case SIOCDELMULTI:
X+				break;
X+
X+			case SIOCGIFSTATUS:
X+				ifs = (struct ifstat *)data;
X+				dummy = strlen(ifs->ascii);
X+				if(plh && dummy < sizeof(ifs->ascii))
X+					snprintf(ifs->ascii + dummy,
X+						sizeof(ifs->ascii) - dummy,
X+						"\tOpened by PID %d\n",
X+						plh[0].pid);
X+				break;
X+
X+			default:
X+				return (*func) (fd, command, data);
X+		}
X+	}
X+
X+	return (*func) (fd, command, data);
X }
X 
END-of-vde/files/patch-vdetaplib::libvdetap.c
echo x - vde/files/patch-vdetaplib::test.c
sed 's/^X//' >vde/files/patch-vdetaplib::test.c << 'END-of-vde/files/patch-vdetaplib::test.c'
X--- vdetaplib/test.c	Sat Jan 29 15:02:08 2005
X+++ vdetaplib/test.c	Sun Jan 30 12:27:35 2005
X@@ -6,35 +6,28 @@
X #include <errno.h>
X #include <string.h>
X #include <unistd.h>
X+#include <sys/types.h>
X #include <sys/ioctl.h>
X+#include <sys/socket.h>
X #include <net/if.h>
X-#include <linux/if_tun.h>
X+#include <net/if_tun.h>
X 
X static int tun_alloc(char *dev)
X {
X-	struct ifreq ifr;
X+	struct ifstat ifs;
X 	int fd, err;
X 
X-	if( (fd = open("/dev/net/tun", O_RDWR)) < 0 )
X+	if( (fd = open("/dev/tap", O_RDWR)) < 0 )
X 		return (-1);
X 
X-	memset(&ifr, 0, sizeof(ifr));
X+	memset(&ifs, 0, sizeof(ifs));
X 
X-	/* Flags: IFF_TUN   - TUN device (no Ethernet headers) 
X-	 *        IFF_TAP   - TAP device  
X-	 *
X-	 *        IFF_NO_PI - Do not provide packet information  
X-	 */ 
X-	ifr.ifr_flags = IFF_TAP; 
X-	if( *dev )
X-		strncpy(ifr.ifr_name, dev, IFNAMSIZ);
X-
X-	if( (err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ){
X+	if( (err = ioctl(fd, SIOCGIFSTATUS, (void *) &ifs)) < 0 ){
X 		close(fd);
X 		return err;
X 	}
X 	printf("ioctl returns\n");
X-	strcpy(dev, ifr.ifr_name);
X+	puts(ifs.ascii);
X 	printf("ioctl idev\n");
X 	return fd;
X }              
END-of-vde/files/patch-vdetaplib::test.c
echo x - vde/files/patch-vdetaplib::vdetap.c
sed 's/^X//' >vde/files/patch-vdetaplib::vdetap.c << 'END-of-vde/files/patch-vdetaplib::vdetap.c'
X--- vdetaplib/vdetap.c	Sat Jan 29 15:02:08 2005
X+++ vdetaplib/vdetap.c	Sun Jan 30 14:05:26 2005
X@@ -2,11 +2,25 @@
X  * Reseased under the GPLv2 */
X 
X #include <stdio.h>
X+#ifndef __FreeBSD__
X #include <stdint.h>
X+#endif
X+#ifdef __FreeBSD__
X+#include <sys/types.h>
X+#include <sys/time.h>
X+#include <unistd.h>
X+#else
X #include <sys/select.h>
X+#endif
X #include <sys/poll.h>
X #include <sys/socket.h>
X #include <sys/un.h>
X+#ifdef __FreeBSD__
X+#include "../vde.h"
X+#include <signal.h>
X+#include <stdlib.h>
X+#include <string.h>
X+#endif
X 
X #define SWITCH_MAGIC 0xfeedface
X #define BUFSIZE 2048
X@@ -21,6 +35,23 @@
X 
X static unsigned char bufin[BUFSIZE];
X 
X+#ifdef __FreeBSD__
X+static char *data_socket = NULL;
X+
X+static void cleanup()
X+{
X+    if(data_socket != NULL)
X+        unlink(data_socket);
X+}
X+
X+static void sig_handler(int sig)
X+{
X+    cleanup(1, NULL);
X+    signal(sig, SIG_DFL);
X+    kill(getpid(), sig);
X+}
X+#endif
X+
X static int send_fd(char *name, int fddata, struct sockaddr_un *datasock, int intno, int group)
X {
X 	int pid = getpid();
X@@ -28,6 +59,9 @@
X 	int fdctl;
X 
X 	struct sockaddr_un sock;
X+#ifdef __FreeBSD__
X+  struct timeval tv;
X+#endif
X 
X 	if((fdctl = socket(AF_UNIX, SOCK_STREAM, 0)) < 0){
X 		perror("socket");
X@@ -47,7 +81,14 @@
X 
X 	req.sock.sun_family=AF_UNIX;
X 	memset(req.sock.sun_path, 0, sizeof(req.sock.sun_path));
X+#ifdef __FreeBSD__
X+	gettimeofday(&tv, NULL);
X+	snprintf(req.sock.sun_path, sizeof(req.sock.sun_path), "%s.%i.%li",
X+	    VDEDATSOCK, pid, tv.tv_usec);
X+	data_socket = strdup(req.sock.sun_path);
X+#else
X 	sprintf(&req.sock.sun_path[1], "%5d-%2d", pid, intno);
X+#endif
X 
X 	if(bind(fddata, (struct sockaddr *) &req.sock, sizeof(req.sock)) < 0){
X 		perror("bind");
X@@ -69,7 +110,7 @@
X 
X static struct pollfd pollv[]={{0,POLLIN|POLLHUP,0},{0,POLLIN|POLLHUP,0}};
X 
X-main(int argc,char *argv[])
X+int main(int argc,char *argv[])
X {
X 	int fd,fddata;
X 	struct sockaddr_un dataout,datain;
X@@ -96,6 +137,12 @@
X 	send_fd(argv[2],fddata,&dataout,0,0);
X 	pollv[0].fd=fd;
X 	pollv[1].fd=fddata;
X+
X+#ifdef __FreeBSD__
X+	if(signal(SIGINT, sig_handler) < 0) {
X+		perror("signal");
X+	}
X+#endif
X 	for(;;) {
X 		result=poll(pollv,2,-1);
X 		if (pollv[0].revents & POLLHUP || pollv[1].revents & POLLHUP)
X@@ -113,5 +160,7 @@
X 			write(fd,bufin,nx);
X 		}
X 	}
X+	cleanup(0, NULL);
X+	return 0;
X }
X 
END-of-vde/files/patch-vdetaplib::vdetap.c
echo x - vde/files/patch-qemu::Makefile
sed 's/^X//' >vde/files/patch-qemu::Makefile << 'END-of-vde/files/patch-qemu::Makefile'
X--- qemu/Makefile	Sat Jan 29 15:02:08 2005
X+++ qemu/Makefile	Sun Jan 30 12:59:52 2005
X@@ -1,4 +1,4 @@
X-ALL: vdeq
X+all: vdeq
X 
X vdeq.o: vdeq.c ../vde.h
X 
END-of-vde/files/patch-qemu::Makefile
echo x - vde/files/patch-slirpvde::Makefile
sed 's/^X//' >vde/files/patch-slirpvde::Makefile << 'END-of-vde/files/patch-slirpvde::Makefile'
X--- slirpvde/Makefile	Sat Jan 29 15:02:08 2005
X+++ slirpvde/Makefile	Sun Jan 30 14:02:57 2005
X@@ -3,7 +3,7 @@
X tcp_timer.o udp.o \
X bootp.o
X 
X-CFLAGS=-I. -DVDE
X+CFLAGS+=-I. -DVDE
X 
X all: libslirp.a slirpvde
X 
X@@ -34,7 +34,7 @@
X udp.o: udp.c ip_icmp.h
X 
X slirpvde: slirpvde.o libslirp.a
X-	$(CC) -o slirpvde slirpvde.o libslirp.a
X+	$(CC) $(LDFLAGS) -o slirpvde slirpvde.o libslirp.a
X 
X clean:
X 	rm -rf *.o slirpvde libslirp.a
END-of-vde/files/patch-slirpvde::Makefile
echo x - vde/files/patch-slirpvde::libslirp.h
sed 's/^X//' >vde/files/patch-slirpvde::libslirp.h << 'END-of-vde/files/patch-slirpvde::libslirp.h'
X--- slirpvde/libslirp.h	Sat Jan 29 15:02:08 2005
X+++ slirpvde/libslirp.h	Sun Jan 30 13:55:31 2005
X@@ -2,7 +2,11 @@
X #define _LIBSLIRP_H
X 
X #include <sys/select.h>
X+#ifdef __FreeBSD__
X+#include <sys/types.h>
X+#else
X #include <stdint.h>
X+#endif
X 
X void slirp_init(char *network);
X 
END-of-vde/files/patch-slirpvde::libslirp.h
echo x - vde/Makefile
sed 's/^X//' >vde/Makefile << 'END-of-vde/Makefile'
X# New ports collection makefile for:   vde
X# Date created:        30 Janurary 2005
X# Whom:                Craig Boston <craig at yekse.gank.org>
X#
X# $FreeBSD$
X#
X
XPORTNAME=	vde
XPORTVERSION=	1.5.7
XCATEGORIES=	net
XMASTER_SITES=	${MASTER_SITE_SOURCEFORGE}
XMASTER_SITE_SUBDIR=	vde
XEXTRACT_SUFX=	.tgz
X
XMAINTAINER=	craig at yekse.gank.org
XCOMMENT=	User-mode virtual ethernet infrastructure
X
XUSE_GMAKE=	yes
XUSE_GETOPT_LONG=yes
X
X.include <bsd.port.pre.mk>
X
XCFLAGS+=	${CPPFLAGS}
XMAKE_ENV+=	LDFLAGS="${LDFLAGS}"
X
XMAN1=		dpipe.1 slirpvde.1 vdetaplib.1 vdeq.1 vde_plug.1 vde_switch.1
X
X.include <bsd.port.post.mk>
END-of-vde/Makefile
echo x - vde/distinfo
sed 's/^X//' >vde/distinfo << 'END-of-vde/distinfo'
XMD5 (vde-1.5.7.tgz) = f89a958a6997114b46abd66c00e217c8
XSIZE (vde-1.5.7.tgz) = 139314
END-of-vde/distinfo
echo x - vde/pkg-descr
sed 's/^X//' >vde/pkg-descr << 'END-of-vde/pkg-descr'
XVirtual Distributed Ethernet is a user-mode virtual network (layer
X2) infrastructure.  It can be used for network simulations, joining
Xmultiple qemu instances together in a shared virtual network, or
Xtunneling over the Internet.  Physical hosts can be joined to the
Xvirtual network by means of the tap(4) driver.
X
XWWW: http://vde.sourceforge.net/
END-of-vde/pkg-descr
echo x - vde/pkg-plist
sed 's/^X//' >vde/pkg-plist << 'END-of-vde/pkg-plist'
Xbin/dpipe
Xbin/slirpvde
Xbin/vdeq
Xbin/vdetap
Xbin/vde_plug
Xbin/vde_switch
Xlib/libvdetap.so
END-of-vde/pkg-plist
exit
--- vde.shar ends here ---

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the freebsd-ports-bugs mailing list