Example #1
0
static void transport_vlan_on_brpat (struct node *n, vlan_t v, struct node *prev)
{
    struct linklist *ll ;
    struct node *bridgenode ;

    if (vlan_isset (n->vlanset, v))
	return ;
    vlan_set (n->vlanset, v) ;

    /*
     * Instanciate this brpat into a bridge
     */

    bridgenode = create_node (new_nodename (n->eq->name), n->eq,  NT_BRIDGE) ;
    (void) create_link (NULL, prev->name, bridgenode->name) ;
    vlan_set (bridgenode->vlanset, v) ;

    for (ll = n->linklist ; ll != NULL ; ll = ll->next)
    {
	struct link *l ;
	struct node *other ;

	l = ll->link ;
	other = getlinkpeer (l, n) ;

	switch (other->nodetype)
	{
	    case NT_L1 :
		inconsistency ("BRPAT-L1 : Should not happen") ;
		exit (2) ;
		break ;
	    case NT_L2 :
		if (other->u.l2.vlan == v && other != prev)
		{
		    (void) create_link (NULL, bridgenode->name, other->name) ;
		    transport_vlan_on_L2 (other, v) ;
		}
		break ;
	    case NT_L3 :
		inconsistency ("BRPAT-L3 : Should not happen") ;
		exit (2) ;
		break ;
	    case NT_BRIDGE :
		inconsistency ("BRPAT-BRIDGE : Should not happen") ;
		exit (2) ;
		break ;
	    case NT_ROUTER :
		inconsistency ("BRPAT-ROUTER : Should not happen") ;
		exit (2) ;
		break ;
	    case NT_L2PAT :
		if (match_vlan (v, other->u.l2pat.allowed))
		    transport_vlan_on_L2pat (other, v, bridgenode) ;
		break ;
	    case NT_BRPAT :
		inconsistency ("BRPAT-BRPAT : Should not happen") ;
		exit (2) ;
		break ;
	}
    }
}
Example #2
0
void fs_private_dev(void){
	int rv;
	// install a new /dev directory
	if (arg_debug)
		printf("Mounting tmpfs on /dev\n");

	int have_dri = 0;
	struct stat s;
	if (stat("/dev/dri", &s) == 0)
		have_dri = 1;

	// create DRI_DIR
	fs_build_mnt_dir();
	if (have_dri) {
		/* coverity[toctou] */
		rv = mkdir(RUN_DRI_DIR, 0755);
		if (rv == -1)
			errExit("mkdir");
		if (chown(RUN_DRI_DIR, 0, 0) < 0)
			errExit("chown");
		if (chmod(RUN_DRI_DIR, 0755) < 0)
			errExit("chmod");
	
		// keep a copy of /dev/dri under DRI_DIR
		if (mount("/dev/dri", RUN_DRI_DIR, NULL, MS_BIND|MS_REC, NULL) < 0)
			errExit("mounting /dev/dri");
	}
	
	// restore /dev/log
	int have_devlog = 0;
	if (stat("/dev/log", &s) == 0) {
		have_devlog = 1;
		FILE *fp = fopen(RUN_DEVLOG_FILE, "w");
		if (!fp)
			have_devlog = 0;
		else {
			fprintf(fp, "\n");
			fclose(fp);
			if (mount("/dev/log", RUN_DEVLOG_FILE, NULL, MS_BIND|MS_REC, NULL) < 0)
				errExit("mounting /dev/log");
		}
	}

	// mount tmpfs on top of /dev
	if (mount("tmpfs", "/dev", "tmpfs", MS_NOSUID | MS_STRICTATIME | MS_REC,  "mode=777,gid=0") < 0)
		errExit("mounting /dev");
	fs_logger("mount tmpfs on /dev");

	// bring back /dev/log
	if (have_devlog) {
		FILE *fp = fopen("/dev/log", "w");
		if (fp) {
			fprintf(fp, "\n");
			fclose(fp);
			if (mount(RUN_DEVLOG_FILE, "/dev/log", NULL, MS_BIND|MS_REC, NULL) < 0)
				errExit("mounting /dev/log");
			fs_logger("clone /dev/log");
		}
	}		

	// bring back the /dev/dri directory
	if (have_dri) {
		/* coverity[toctou] */
		rv = mkdir("/dev/dri", 0755);
		if (rv == -1)
			errExit("mkdir");
		if (chown("/dev/dri", 0, 0) < 0)
			errExit("chown");
		if (chmod("/dev/dri",0755) < 0)
			errExit("chmod");
		if (mount(RUN_DRI_DIR, "/dev/dri", NULL, MS_BIND|MS_REC, NULL) < 0)
			errExit("mounting /dev/dri");
		fs_logger("clone /dev/dri");
	}
	
	// create /dev/shm
	if (arg_debug)
		printf("Create /dev/shm directory\n");
	rv = mkdir("/dev/shm", 0777);
	if (rv == -1)
		errExit("mkdir");
	if (chown("/dev/shm", 0, 0) < 0)
		errExit("chown");
	if (chmod("/dev/shm", 0777) < 0)
		errExit("chmod");
	fs_logger("mkdir /dev/shm");

	// create devices
	create_char_dev("/dev/zero", 0666, 1, 5); // mknod -m 666 /dev/zero c 1 5
	fs_logger("mknod /dev/zero");
	create_char_dev("/dev/null", 0666, 1, 3); // mknod -m 666 /dev/null c 1 3
	fs_logger("mknod /dev/null");
	create_char_dev("/dev/full", 0666, 1, 7); // mknod -m 666 /dev/full c 1 7
	fs_logger("mknod /dev/full");
	create_char_dev("/dev/random", 0666, 1, 8); // Mknod -m 666 /dev/random c 1 8
	fs_logger("mknod /dev/random");
	create_char_dev("/dev/urandom", 0666, 1, 9); // mknod -m 666 /dev/urandom c 1 9
	fs_logger("mknod /dev/urandom");
	create_char_dev("/dev/tty", 0666,  5, 0); // mknod -m 666 /dev/tty c 5 0
	fs_logger("mknod /dev/tty");
#if 0
	create_dev("/dev/tty0", "mknod -m 666 /dev/tty0 c 4 0");
	create_dev("/dev/console", "mknod -m 622 /dev/console c 5 1");
#endif

	// pseudo-terminal
	rv = mkdir("/dev/pts", 0755);
	if (rv == -1)
		errExit("mkdir");
	if (chown("/dev/pts", 0, 0) < 0)
		errExit("chown");
	if (chmod("/dev/pts", 0755) < 0)
		errExit("chmod");
	fs_logger("mkdir /dev/pts");
	create_char_dev("/dev/pts/ptmx", 0666, 5, 2); //"mknod -m 666 /dev/pts/ptmx c 5 2");
	fs_logger("mknod /dev/pts/ptmx");
	create_link("/dev/pts/ptmx", "/dev/ptmx");
	// mount -vt devpts -o newinstance -o ptmxmode=0666 devpts //dev/pts
	if (mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL,  "newinstance,ptmxmode=0666") < 0)
		errExit("mounting /dev/pts");
	fs_logger("mount devpts");

#if 0
	// stdin, stdout, stderr
	create_link("/proc/self/fd", "/dev/fd");
	create_link("/proc/self/fd/0", "/dev/stdin");
	create_link("/proc/self/fd/1", "/dev/stdout");
	create_link("/proc/self/fd/2", "/dev/stderr");
#endif
}
Example #3
0
static void transport_vlan_on_L2pat (struct node *n, vlan_t v, struct node *prev)
{
    struct linklist *ll ;
    struct node *l2node ;

    if (vlan_isset (n->vlanset, v))
	return ;
    vlan_set (n->vlanset, v) ;

    /*
     * Instanciate this L2pat into a L2
     */

    l2node = create_node (new_nodename (n->eq->name), n->eq,  NT_L2) ;
    l2node->u.l2.vlan = v ;
    l2node->u.l2.stat = NULL ;
    l2node->u.l2.native = (n->u.l2pat.native == v) ;
    (void) create_link (NULL, prev->name, l2node->name) ;

    vlan_set (l2node->vlanset, v) ;
    MK_SET (l2node, MK_L2TRANSPORT) ;
    for (ll = n->linklist ; ll != NULL ; ll = ll->next)
    {
	struct link *l ;
	struct node *other ;

	l = ll->link ;
	other = getlinkpeer (l, n) ;

	switch (other->nodetype)
	{
	    case NT_L1 :
		if (other->u.l1.l1type == L1T_TRUNK)
		{
		    if (other != prev)
			(void) create_link (NULL, l2node->name, other->name) ;
		    transport_vlan_on_L1 (other, v) ;
		}
		else
		{
		    inconsistency ("L2PAT-L1(ether) : Should not happen") ;
		    exit (2) ;
		}
		break ;
	    case NT_L2 :
		inconsistency ("L2PAT-L2 : Should not happen") ;
		exit (2) ;
		break ;
	    case NT_L3 :
		inconsistency ("L2PAT-L3 : Should not happen") ;
		exit (2) ;
		break ;
	    case NT_BRIDGE :
		inconsistency ("L2PAT-BRIDGE : Should not happen") ;
		exit (2) ;
		break ;
	    case NT_ROUTER :
		inconsistency ("L2PAT-ROUTER : Should not happen") ;
		exit (2) ;
		break ;
	    case NT_L2PAT :
		inconsistency ("L2PAT-L2PAT : Should not happen") ;
		exit (2) ;
		break ;
	    case NT_BRPAT :
		/*
		 *			 brpat
		 *			 |      vlan transported
		 *			 |      |  L2 just created
		 *			 |      |  |
		 *			 v      v  v
		 */
		transport_vlan_on_brpat (other, v, l2node) ;
		break ;
	}
    }
}
Example #4
0
int main(int argc, char **argv)
{
	short revents;
	int i, listenfd, sockfd;
	int ret = 0;
	struct link *ln;
	struct addrinfo *server_ai = NULL;
	struct addrinfo *local_ai = NULL;
	struct addrinfo hint;

	check_ss_option(argc, argv, "client");

	memset(&hint, 0, sizeof(hint));
	hint.ai_family = AF_UNSPEC;
	hint.ai_socktype = SOCK_STREAM;

	ret = getaddrinfo(ss_opt.server_addr, ss_opt.server_port,
			  &hint, &server_ai);
	if (ret != 0) {
		pr_warn("getaddrinfo error: %s\n", gai_strerror(ret));
		goto out;
	}

	pr_ai_notice(server_ai, "server address");

	ret = getaddrinfo(ss_opt.local_addr, ss_opt.local_port, &hint, &local_ai);
	if (ret != 0) {
		pr_warn("getaddrinfo error: %s\n", gai_strerror(ret));
		goto out;
	}

	pr_ai_notice(local_ai, "listening address");

	if (crypto_init(ss_opt.password, ss_opt.method) == -1) {
		ret = -1;
		goto out;
	}

	ss_init();
	listenfd = do_listen(local_ai, "tcp");
	clients[0].fd = listenfd;
	clients[0].events = POLLIN;

	while (1) {
		pr_debug("start polling\n");
		ret = poll(clients, nfds, TCP_INACTIVE_TIMEOUT * 1000);
		if (ret == -1)
			err_exit("poll error");
		else if (ret == 0) {
			reaper();
			continue;
		}

		if (clients[0].revents & POLLIN) {
			sockfd = accept(clients[0].fd, NULL, NULL);
			if (sockfd == -1) {
				pr_warn("accept error\n");
			} else if (poll_set(sockfd, POLLIN) == -1) {
				close(sockfd);
			} else {
				ln = create_link(sockfd, "client");
				if (ln == NULL) {
					poll_del(sockfd);
					close(sockfd);
				} else {
					ln->server = server_ai;
				}
			}
		}

		for (i = 1; i < nfds; i++) {
			sockfd = clients[i].fd;
			if (sockfd == -1)
				continue;

			revents = clients[i].revents;
			if (revents == 0)
				continue;

			ln = get_link(sockfd);
			if (ln == NULL) {
				sock_warn(sockfd, "close: can't get link");
				close(sockfd);
				continue;
			}
			
			if (revents & POLLIN) {
				client_do_pollin(sockfd, ln);
			}

			if (revents & POLLOUT) {
				client_do_pollout(sockfd, ln);
			}

			/* suppress the noise */
			/* if (revents & POLLPRI) { */
			/* 	sock_warn(sockfd, "POLLPRI"); */
			/* } else if (revents & POLLERR) { */
			/* 	sock_warn(sockfd, "POLLERR"); */
			/* } else if (revents & POLLHUP) { */
			/* 	sock_warn(sockfd, "POLLHUP"); */
			/* } else if (revents & POLLNVAL) { */
			/* 	sock_warn(sockfd, "POLLNVAL"); */
			/* } */
		}

		reaper();
	}

out:
	crypto_exit();

	if (server_ai)
		freeaddrinfo(server_ai);

	if (local_ai)
		freeaddrinfo(local_ai);

	ss_exit();

	if (ret == -1)
		exit(EXIT_FAILURE);
	else
		exit(EXIT_SUCCESS);
}