Revision: 439
http://vde.svn.sourceforge.net/vde/?rev=439&view=rev
Author: rd235
Date: 2010-08-04 14:42:59 +0000 (Wed, 04 Aug 2010)
Log Message:
-----------
stream mgmt to libvdeplug_dyn and vde_plug2tap added
Modified Paths:
--------------
trunk/vde-2/include/libvdeplug_dyn.h
trunk/vde-2/man/vde_plug2tap.1
trunk/vde-2/src/vde_plug2tap.c
Modified: trunk/vde-2/include/libvdeplug_dyn.h
===================================================================
--- trunk/vde-2/include/libvdeplug_dyn.h 2010-07-25 18:32:30 UTC (rev
438)
+++ trunk/vde-2/include/libvdeplug_dyn.h 2010-08-04 14:42:59 UTC (rev
439)
@@ -58,9 +58,11 @@
#define LIBVDEPLUG_INTERFACE_VERSION 1
struct vdeconn;
-
typedef struct vdeconn VDECONN;
+struct vdestream;
+typedef struct vdestream VDESTREAM;
+
/* Open a VDE connection.
* vde_open_options:
* port: connect to a specific port of the switch (0=any)
@@ -89,12 +91,27 @@
int (* vde_datafd)(VDECONN *conn);
int (* vde_ctlfd)(VDECONN *conn);
int (* vde_close)(VDECONN *conn);
+ VDESTREAM * (* vdestream_open)(void *opaque, int fdout,
+ ssize_t (* frecv)(void *opaque, void *buf, size_t
count),
+ void (* ferr)(void *opaque, int type, char *format, ...)
+ );
+ ssize_t (* vdestream_send)(VDESTREAM *vdestream, const void *buf,
size_t len);
+ void (* vdestream_recv)(VDESTREAM *vdestream, unsigned char *buf,
size_t len);
+ void (* vdestream_close)(VDESTREAM *vdestream);
};
typedef VDECONN * (* VDE_OPEN_REAL_T)(const char *vde_switch,char *descr,int
interface_version, struct vde_open_args *open_args);
typedef size_t (* VDE_RECV_T)(VDECONN *conn,void *buf,size_t len,int flags);
typedef size_t (* VDE_SEND_T)(VDECONN *conn,const void *buf,size_t len,int
flags);
typedef int (* VDE_INT_FUN)(VDECONN *conn);
+typedef VDESTREAM * (* VDESTREAM_OPEN_T)(void *opaque, int fdout,
+ ssize_t (* frecv)(void *opaque, void *buf, size_t
count),
+ void (* ferr)(void *opaque, int type, char *format, ...)
+ );
+typedef ssize_t (* VDESTREAM_SEND_T)(VDESTREAM *vdestream, const void *buf,
size_t len);
+typedef void (* VDESTREAM_RECV_T)(VDESTREAM *vdestream, unsigned char *buf,
size_t len);
+typedef void (* VDESTREAM_CLOSE_T)(VDESTREAM *vdestream);
+
#define libvdeplug_dynopen(x) ({ \
(x).dl_handle=dlopen("libvdeplug.so",RTLD_NOW); \
if ((x).dl_handle) { \
@@ -104,11 +121,19 @@
(x).vde_datafd=(VDE_INT_FUN) dlsym((x).dl_handle,"vde_datafd");
\
(x).vde_ctlfd=(VDE_INT_FUN) dlsym((x).dl_handle,"vde_ctlfd"); \
(x).vde_close=(VDE_INT_FUN) dlsym((x).dl_handle,"vde_close"); \
+ (x).vdestream_open=(VDESTREAM_OPEN_T)
dlsym((x).dl_handle,"vdestream_open"); \
+ (x).vdestream_send=(VDESTREAM_SEND_T)
dlsym((x).dl_handle,"vdestream_send"); \
+ (x).vdestream_recv=(VDESTREAM_RECV_T)
dlsym((x).dl_handle,"vdestream_recv"); \
+ (x).vdestream_close=(VDESTREAM_CLOSE_T)
dlsym((x).dl_handle,"vdestream_close"); \
} else { \
(x).vde_open_real=NULL; \
(x).vde_send= NULL; \
(x).vde_recv= NULL; \
(x).vde_datafd= (x).vde_ctlfd= (x).vde_close= NULL; \
+ (x).vdestream_open= NULL; \
+ (x).vdestream_send= NULL; \
+ (x).vdestream_recv= NULL; \
+ (x).vdestream_close= NULL; \
}\
})
Modified: trunk/vde-2/man/vde_plug2tap.1
===================================================================
--- trunk/vde-2/man/vde_plug2tap.1 2010-07-25 18:32:30 UTC (rev 438)
+++ trunk/vde-2/man/vde_plug2tap.1 2010-08-04 14:42:59 UTC (rev 439)
@@ -11,6 +11,13 @@
All the data that is catched by the plug is sent to the tap interface
.I tap_name
and everything from that interface is injected in the switch.
+.br
+Example:
+.in +2
+.B vde_plug2tap tap4
+.in -2
+.br
+connects the default switch (/var/run/vde.ctl) to the tap4 interface.
.SH OPTIONS
.TP
@@ -35,7 +42,16 @@
.TP
\fB\-s\fP, \fB\-\-sock\fP=\fIsocket\fP
specify the UNIX socket to be used by local programs for joining the VDE.
-The default value is "/tmp/vde.ctl".
+The default value is "/var/run/vde.ctl".
+When '-' is used in place of the VDE switch directory, \fBvde_plug2tap\fP
+works as a plug (see vde_plug(1)).
+The command:
+.br
+.in +2
+.B dpipe vde_plug = ssh remote.machine.org vde_plug2tap -s - tapx
+.in -2
+.br
+connects the default local switch to a remote tapx interface.
.TP
\fB\-d\fP, \fB\-\-daemon\fP
start vde_plug2tap as a background process
Modified: trunk/vde-2/src/vde_plug2tap.c
===================================================================
--- trunk/vde-2/src/vde_plug2tap.c 2010-07-25 18:32:30 UTC (rev 438)
+++ trunk/vde-2/src/vde_plug2tap.c 2010-08-04 14:42:59 UTC (rev 439)
@@ -1,5 +1,7 @@
/* Copyright 2006 Renzo Davoli
* from vde_plug Davoli Gardenghi
+ * Modified 2010 Renzo Davoli, vdestream added
+ * Licensed under the GPLv2
*/
#include <stdio.h>
@@ -50,6 +52,7 @@
#endif
VDECONN *conn;
+VDESTREAM *vdestream;
char *prog;
int logok;
@@ -78,7 +81,10 @@
printlog(LOG_WARNING,"Couldn't remove pidfile '%s': %s",
pidfile, strerror(errno));
}
- vde_close(conn);
+ if (vdestream != NULL)
+ vdestream_close(vdestream);
+ if (conn != NULL)
+ vde_close(conn);
}
static void sig_handler(int sig)
@@ -128,8 +134,6 @@
perror("Setting handler");
}
-struct pollfd
pollv[]={{0,POLLIN|POLLHUP},{0,POLLIN|POLLHUP},{0,POLLIN|POLLHUP}};
-
static void usage(void) {
fprintf(stderr, "Usage: %s [OPTION]... tap_name\n\n", prog);
fprintf(stderr, " -p, --port=portnum Port number in the VDE
switch\n"
@@ -227,6 +231,12 @@
fclose(f);
}
+static ssize_t vde_plug2tap_recv(void *opaque, void *buf, size_t count)
+{
+ int *tapfdp=opaque;
+ return write(*tapfdp,buf,count);
+}
+
int main(int argc, char **argv)
{
static char *sockname=NULL;
@@ -237,6 +247,11 @@
register ssize_t nx;
struct vde_open_args open_args={.port=0,.group=NULL,.mode=0700};
int c;
+ static struct pollfd pollv[]={{0,POLLIN|POLLHUP},
+ {0,POLLIN|POLLHUP},
+ {0,POLLIN|POLLHUP}};
+ int npollv;
+
prog=argv[0];
while (1) {
int option_index = 0;
@@ -324,18 +339,27 @@
tapfd=open_tap(tapname);
if(tapfd<0)
exit(1);
- conn=vde_open(sockname,"vde_plug:",&open_args);
- if (conn == NULL)
- exit(1);
-
pollv[0].fd=tapfd;
- pollv[1].fd=vde_datafd(conn);
- pollv[2].fd=vde_ctlfd(conn);
+ if (sockname==NULL || strcmp(sockname,"-") != 0) {
+ conn=vde_open(sockname,"vde_plug:",&open_args);
+ if (conn == NULL)
+ exit(1);
+ pollv[1].fd=vde_datafd(conn);
+ pollv[2].fd=vde_ctlfd(conn);
+ npollv=3;
+ } else {
+
vdestream=vdestream_open(&tapfd,STDOUT_FILENO,vde_plug2tap_recv,NULL);
+ if (vdestream == NULL)
+ exit(1);
+ pollv[1].fd=STDIN_FILENO;
+ npollv=2;
+ }
+
for(;;) {
result=poll(pollv,3,-1);
if ((pollv[0].revents | pollv[1].revents | pollv[2].revents) &
POLLHUP ||
- pollv[2].revents & POLLIN)
+ (npollv > 2 && pollv[2].revents & POLLIN))
break;
if (pollv[0].revents & POLLIN) {
nx=read(tapfd,bufin,sizeof(bufin));
@@ -344,13 +368,23 @@
//fprintf(stderr,"%s: RECV %d %x %x
\n",prog,nx,bufin[0],bufin[1]);
if (nx<=0)
break;
- vde_send(conn,bufin,nx,0);
+ if (conn != NULL)
+ vde_send(conn,bufin,nx,0);
+ else
+ vdestream_send(vdestream, bufin, nx);
}
if (pollv[1].revents & POLLIN) {
- nx=vde_recv(conn,bufin,sizeof(bufin),0);
- if (nx<=0)
- break;
- write(tapfd,bufin,nx);
+ if (conn != NULL) {
+ nx=vde_recv(conn,bufin,sizeof(bufin),0);
+ if (nx<=0)
+ break;
+ write(tapfd,bufin,nx);
+ } else {
+ nx=read(STDIN_FILENO,bufin,sizeof(bufin));
+ if (nx<=0)
+ break;
+ vdestream_recv(vdestream,bufin,nx);
+ }
//fprintf(stderr,"%s: SENT %d %x %x
\n",prog,nx,bufin[0],bufin[1]);
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm
_______________________________________________
vde-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vde-users