コード例 #1
0
ファイル: vde.c プロジェクト: 01org/KVMGT-qemu
static void vde_to_qemu(void *opaque)
{
    VDEState *s = opaque;
    uint8_t buf[NET_BUFSIZE];
    int size;

    size = vde_recv(s->vde, (char *)buf, sizeof(buf), 0);
    if (size > 0) {
        qemu_send_packet(&s->nc, buf, size);
    }
}
コード例 #2
0
void
wait_for_eth_nodes() { /*thread that waits for (vde) eth nodes*/

	fd_set socketRead;
	char string_remote_address[100];
	union ethframe message;
	mes *msg;
	int result;
	int count;

	int socketfd = vde_datafd(conn);


	if (conn == NULL) {
		printf("error: %s\n",strerror(errno));
	}

	while(end) {

		memset(string_remote_address, 0, 100);
		count = 0;
		do {
			FD_ZERO(&socketRead);
			FD_SET(socketfd, &socketRead);
			result = select(socketfd + 1, &socketRead, 0, 0, 0);
		} while( (result < 0) && (errno == EINTR) );
		if(FD_ISSET(socketfd, &socketRead)) {

			count = vde_recv(conn, message.buffer, ETH_FRAME_LEN, 0);
			msg = &(message.field.data.msg);

		}
		sprintf((char*)string_remote_address,"%s", message.field.header.h_source);

		if(msg->type == HI) {

			printf("ricevuto da socketfd %d  msg: \"%s\" len %d, from host %.6s\n", socketfd, msg->text, count, message.field.header.h_source);
			if(!check_node_is_in(msg->text)) {
				pthread_mutex_lock(&threads_sync_lock);
				create_midi_node(msg->text, string_remote_address, VDE);
				printf("A new (vde) eth device arrived\n");
				pthread_mutex_unlock(&threads_sync_lock);;
			}
			else
				printf("Eth device already in list\n");
		}
	}
	close(socketfd);
}
コード例 #3
0
int vde_user_read(void *conn, void *buf, int len)
{
	VDECONN *vconn = conn;
	int rv;

	if (vconn == NULL)
		return 0;

	rv = vde_recv(vconn, buf, len, 0);
	if (rv < 0) {
		if (errno == EAGAIN)
			return 0;
		return -errno;
	}
	else if (rv == 0)
		return -ENOTCONN;

	return rv;
}
コード例 #4
0
ファイル: pico_dev_vde.c プロジェクト: pepe2k/picotcp
static int pico_vde_poll(struct pico_device *dev, int loop_score)
{
    struct pico_device_vde *vde = (struct pico_device_vde *) dev;
    struct pollfd pfd;
    unsigned char buf[VDE_MTU];
    int len;
    pfd.fd = vde_datafd(vde->conn);
    pfd.events = POLLIN;
    do  {
        if (poll(&pfd, 1, 0) <= 0)
            return loop_score;

        len = vde_recv(vde->conn, buf, VDE_MTU, 0);
        if (len > 0) {
            /* dbg("Received pkt.\n"); */
            loop_score--;
            pico_stack_recv(dev, buf, len);
        }
    } while(loop_score > 0);
    return 0;
}
コード例 #5
0
static int pico_vde_poll(struct pico_device *dev, int loop_score)
{
    struct pico_device_vde *vde = (struct pico_device_vde *) dev;
    struct pollfd pfd;
    unsigned char buf[VDE_MTU];
    int len;
    pfd.fd = vde_datafd(vde->conn);
    pfd.events = POLLIN;
    do  {
        if (poll(&pfd, 1, 0) <= 0)
            return loop_score;

        len = vde_recv(vde->conn, buf, VDE_MTU, 0);
        if (len > 0) {
            //printf("Received pkt.\n");
            if ((vde->lost_in == 0) || ((pico_rand() % 100) > vde->lost_in)) {
                loop_score--;
                pico_stack_recv(dev, buf, (uint32_t)len);
            }
        }
    } while(loop_score > 0);
    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);
}