コード例 #1
0
struct pico_device *pico_vde_create(char *sock, char *name, uint8_t *mac)
{
    struct pico_device_vde *vde = PICO_ZALLOC(sizeof(struct pico_device_vde));
    struct vde_open_args open_args = {
        .mode = 0700
    };
    char vdename[] = "picotcp";

    if (!vde)
        return NULL;

    if( 0 != pico_device_init((struct pico_device *)vde, name, mac)) {
        dbg ("Vde init failed.\n");
        pico_vde_destroy((struct pico_device *)vde);
        return NULL;
    }

    vde->dev.overhead = 0;
    vde->sock = PICO_ZALLOC(strlen(sock) + 1);
    memcpy(vde->sock, sock, strlen(sock));
    vde->conn = vde_open(sock, vdename, &open_args);
    if (!vde->conn) {
        pico_vde_destroy((struct pico_device *)vde);
        return NULL;
    }

    vde->dev.send = pico_vde_send;
    vde->dev.poll = pico_vde_poll;
    vde->dev.destroy = pico_vde_destroy;
    //printf("Device %s created.\n", vde->dev.name);
    return (struct pico_device *)vde;
}
コード例 #2
0
ファイル: vde.c プロジェクト: 01org/KVMGT-qemu
static int net_vde_init(NetClientState *peer, const char *model,
                        const char *name, const char *sock,
                        int port, const char *group, int mode)
{
    NetClientState *nc;
    VDEState *s;
    VDECONN *vde;
    char *init_group = (char *)group;
    char *init_sock = (char *)sock;

    struct vde_open_args args = {
        .port = port,
        .group = init_group,
        .mode = mode,
    };

    vde = vde_open(init_sock, (char *)"QEMU", &args);
    if (!vde){
        return -1;
    }

    nc = qemu_new_net_client(&net_vde_info, peer, model, name);

    snprintf(nc->info_str, sizeof(nc->info_str), "sock=%s,fd=%d",
             sock, vde_datafd(vde));

    s = DO_UPCAST(VDEState, nc, nc);

    s->vde = vde;

    qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s);

    return 0;
}
コード例 #3
0
ファイル: cryptcab.c プロジェクト: mwilliamson/vde
void
vde_plug(struct peer *p, char *plugname)
{
	p->plug=vde_open(plugname,"vde_cryptcab",&open_args);
	if(!p->plug)
	{
		perror ("libvdeplug");
		exit(1);
	}
	vc_printlog(3,"Socket to local switch created: fd=%d",vde_datafd(p->plug));
}
コード例 #4
0
void *
create_midi_nodes_threads() { /*creates all threads*/
	int *p = NULL;
	int ris;
	int t = 0;
	void *ptr;
	int error;
	struct vde_open_args open_args={.port=0,.group=NULL,.mode=0700};
	conn = vde_open("/tmp/xxx", "test", &open_args);


	for(t = 0; t < THREADS_NUM ; t++) {
		p = malloc(sizeof(int));
		if(p == NULL) {
			printf("Malloc for the index of a thread failed\n");
			exit(0);
		}
		*p = t;
		ris = pthread_create(&midi_nodes_threads[t], NULL, midi_nodes_Thread, p);

		if(ris) {
			printf("ERROR; return code from pthread_create() is %d\n", ris);
			exit(-1);
		}
	}
	for(t = 0; t < THREADS_NUM; t++) {

		error = pthread_join(midi_nodes_threads[t], (void*) &ptr);
		if(error != 0){
			printf("pthread_join() failed: error= %d\n", error);
			exit(-1);
		} else {
			printf("bridge thread %d is dying\n", *((int*)ptr));
			free(ptr); /*deallocating structure in which pthread_join returns value*/
		}
	}
	return NULL;
}


midi_node*
return_midi_nodes() {
	return node_root;
}


void
set_end_to_zero() {
	end = 0;
	return;
}
コード例 #5
0
static int vde_user_init(void *data, void *dev)
{
	struct vde_data *pri = data;
	VDECONN *conn = NULL;
	int err = -EINVAL;

	pri->dev = dev;

	conn = vde_open(pri->vde_switch, pri->descr, pri->args);

	if (conn == NULL) {
		err = -errno;
		printk(UM_KERN_ERR "vde_user_init: vde_open failed, "
		       "errno = %d\n", errno);
		return err;
	}

	printk(UM_KERN_INFO "vde backend - connection opened\n");

	pri->conn = conn;

	return 0;
}
コード例 #6
0
ファイル: vde_plug2tap.c プロジェクト: mwilliamson/vde
int main(int argc, char **argv)
{
	static char *sockname=NULL;
	static char *tapname=NULL;
	int daemonize=0;
	int tapfd;
	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;

		static struct option long_options[] = {
			{"sock", 1, 0, 's'},
			{"port", 1, 0, 'p'},
			{"help",0,0,'h'},
			{"mod",1,0,'m'},
			{"group",1,0,'g'},
			{"daemon",0,0,'d'},
			{"pidfile", 1, 0, 'P'},
			{0, 0, 0, 0}
		};
		c = GETOPT_LONG (argc, argv, "hdP:p:s:m:g:",
				long_options, &option_index);
		if (c == -1)
			break;

		switch (c) {
			case 'p':
				open_args.port=atoi(optarg);
				if (open_args.port <= 0)
					usage(); //implies exit
				break;

			case 'h':
				usage(); //implies exit
				break;

			case 's':
				sockname=strdup(optarg);
				break;

			case 'm':
				sscanf(optarg,"%o",(unsigned int *)&(open_args.mode));
				break;

			case 'g':
				open_args.group=strdup(optarg);
				break;

			case 'd':
				daemonize=1;
				break;

			case 'P':
				pidfile=strdup(optarg);
				break;

			default:
				usage(); //implies exit
		}
	}

	if (daemonize) {
		openlog(basename(prog), LOG_PID, 0);
		logok=1;
		syslog(LOG_INFO,"VDE_PLUG2TAP started");
	}
	/* saves current path in pidfile_path, because otherwise with daemonize() we
	 * forget it */
	if(getcwd(pidfile_path, PATH_MAX-1) == NULL) {
		printlog(LOG_ERR, "getcwd: %s", strerror(errno));
		exit(1);
	}
	strcat(pidfile_path, "/");
	if (daemonize && daemon(0, 0)) {
		printlog(LOG_ERR,"daemon: %s",strerror(errno));
		exit(1);
	}

	/* once here, we're sure we're the true process which will continue as a
	 * server: save PID file if needed */
	if(pidfile) save_pidfile();

	if (optind < argc)
		tapname=argv[optind];
	else
		usage(); // implies exit
	
	atexit(cleanup);
	setsighandlers();

	tapfd=open_tap(tapname);
	if(tapfd<0)
		exit(1);
	pollv[0].fd=tapfd;

	if (sockname==NULL || strcmp(sockname,"-") != 0) {
		conn=vde_open(sockname,"vde_plug2tap:",&open_args);
		if (conn == NULL) {
			printlog(LOG_ERR,"vde_open %s: %s",sockname?sockname:"DEF_SWITCH",strerror(errno));
			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(;;) {
		poll(pollv,3,-1);
		if ((pollv[0].revents | pollv[1].revents | pollv[2].revents) & POLLHUP ||
				(npollv > 2 && pollv[2].revents & POLLIN)) 
			break;
		if (pollv[0].revents & POLLIN) {
			nx=read(tapfd,bufin,sizeof(bufin));
			/* if POLLIN but not data it means that the stream has been
			 * closed at the other end */
			//fprintf(stderr,"%s: RECV %d %x %x \n",prog,nx,bufin[0],bufin[1]);
			if (nx<=0)
				break;
			if (conn != NULL)
				vde_send(conn,bufin,nx,0);
			else
				vdestream_send(vdestream, bufin, nx);
		}
		if (pollv[1].revents & POLLIN) {
			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]);
		}

	}
	return(0);
}
コード例 #7
0
ファイル: vde_plug.c プロジェクト: bringhurst/vde
int main(int argc, char **argv)
{
	static char *sockname=NULL;
	register ssize_t nx;
	struct vde_open_args open_args={.port=0,.group=NULL,.mode=0700};

	uname(&me);
	//get the login name
	callerpwd=getpwuid(getuid());

	if (argv[0][0] == '-')
		netusage(); //implies exit
	/* option parsing */
	{
		int c;
		while (1) {
			int option_index = 0;

			static struct option long_options[] = {
				{"sock", 1, 0, 's'},
				{"vdesock", 1, 0, 's'},
				{"unix", 1, 0, 's'},
				{"port", 1, 0, 'p'},
				{"help",0,0,'h'},
				{"mod",1,0,'m'},
				{"group",1,0,'g'},
				{0, 0, 0, 0}
			};
			c = GETOPT_LONG (argc, argv, "hc:p:s:m:g:l",
					long_options, &option_index);
			if (c == -1)
				break;

			switch (c) {
				case 'c':
					if (strcmp(optarg,"vde_plug")==0) {
#ifdef DO_SYSLOG
						write_syslog_entry("START");
						atexit(write_syslog_close);
#ifdef VDE_IP_LOG
						vde_ip_log=1;
#endif
#endif

					}
					else
						netusage(); //implies exit
					break;

				case 'p':
					open_args.port=atoi(optarg);
					if (open_args.port <= 0)
						usage(argv[0]); //implies exit
					break;

				case 'h':
					usage(argv[0]); //implies exit
					break;

				case 's':
					sockname=strdup(optarg);
					break;

				case 'm': 
					sscanf(optarg,"%o",(unsigned int *)&(open_args.mode));
					break;

				case 'g':
					open_args.group=strdup(optarg);
					break;

				case 'l':
#ifdef VDE_IP_LOG
					write_syslog_entry("START");
					atexit(write_syslog_close);
					vde_ip_log=1;
					break;
#endif

				default:
					usage(argv[0]); //implies exit
			}
		}

		if (optind < argc && sockname==NULL)
			sockname=argv[optind];
	}
	atexit(cleanup);
	setsighandlers();
	conn=vde_open(sockname,"vde_plug:",&open_args);
	if (conn == NULL) {
		fprintf(stderr,"vde_open %s: %s\n",sockname?sockname:"DEF_SWITCH",strerror(errno));
		exit(1);
	}

	vdestream=vdestream_open(conn,STDOUT_FILENO,vdeplug_recv,vdeplug_err);

	pollv[1].fd=vde_datafd(conn);
	pollv[2].fd=vde_ctlfd(conn);

	for(;;) {
		poll(pollv,3,-1);
		if ((pollv[0].revents | pollv[1].revents | pollv[2].revents) & POLLHUP ||
				pollv[2].revents & POLLIN)
			break;
		if (pollv[0].revents & POLLIN) {
			nx=read(STDIN_FILENO,bufin,sizeof(bufin));
			/* if POLLIN but not data it means that the stream has been
			 * closed at the other end */
			/*fprintf(stderr,"%s: RECV %d %x %x \n",myname,nx,bufin[0],bufin[1]);*/
			if (nx==0)
				break;
			vdestream_recv(vdestream, bufin, nx);
		}
		if (pollv[1].revents & POLLIN) {
			nx=vde_recv(conn,bufin,BUFSIZE-2,0);
			if (nx<0)
				perror("vde_plug: recvfrom ");
			else
			{
				vdestream_send(vdestream, bufin, nx);
				/*fprintf(stderr,"%s: SENT %d %x %x \n",myname,nx,bufin[0],bufin[1]);*/
			}
		}
	}

	return(0);
}