예제 #1
0
int
main()
{
	struct sockaddr_in client;
	struct sockaddr_in server;
	char msg[500];
	char buf[65535];
	socklen_t clen;
	ssize_t nn;
	ssize_t off;
	int size = 1024 * 1024;
	int s;


	rump_init();
	rump_pub_lwproc_rfork(0);
	if (rump_pub_netconfig_ifcreate(IFNAME) != 0)
		errx(1, "failed to create " IFNAME);

	if (rump_pub_netconfig_ipv4_ifaddr(IFNAME,
	    IF_ADDR, "255.255.255.0") != 0)
		errx(1, "failed to create " IFNAME);

	//rump_pub_netconfig_dhcp_ipv4_oneshot(IFNAME);


	s = rump_sys_socket(PF_INET, SOCK_DGRAM, 0);
	if (s == -1)
		err(1,"socket");

	memset(&server, 0, sizeof(server));
	server.sin_family = AF_INET;
	server.sin_port = htons(ECHOSERVER_RX_PORT);  
	server.sin_addr.s_addr = inet_addr(IF_ADDR);

	rump_sys_setsockopt(s, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));

	if (rump_sys_bind(s, (struct sockaddr *)&server, sizeof(server)) == -1)
		err(1, "binded");
	printf("socket binded\r\n");

	printf("Waiting connection on port = %d\r\n",ECHOSERVER_RX_PORT);

	memset(&client, 0, sizeof(client));

	while(1)
	{
		memset(msg,0,sizeof(msg));
		clen = sizeof(client);

		nn = rump_sys_recvfrom(s,msg,sizeof(msg),0,(struct sockaddr *)&client,&clen);


		if (nn<0) {
			perror("Error receiving data");
		} else {
			rump_sys_sendto(s,buf,nn,0,(struct sockaddr *)&client,clen);
		}
	}
}
예제 #2
0
static void
config_router(void)
{
	int rv;

	/* configure networking using the portable interfaces */
	NOFAIL_RV(rump_pub_netconfig_ifcreate("shmif0"));
	NOFAIL_RV(rump_pub_netconfig_ifsetlinkstr("shmif0", "busmem1"));
	NOFAIL_RV(rump_pub_netconfig_ipv4_ifaddr("shmif0",
	    "1.0.0.2", "255.255.255.0"));

	NOFAIL_RV(rump_pub_netconfig_ifcreate("shmif1"));
	NOFAIL_RV(rump_pub_netconfig_ifsetlinkstr("shmif1", "busmem2"));
	NOFAIL_RV(rump_pub_netconfig_ipv4_ifaddr("shmif1",
	    "1.0.1.2", "255.255.255.0"));
}
예제 #3
0
int
main()
{
	struct sockaddr_in sin;
	char buf[65535];
	struct hostent *hp;
	ssize_t nn;
	ssize_t off;
	int s, e;

	hp = gethostbyname(DESTHOST);
	if (!hp || hp->h_addrtype != AF_INET)
		errx(1, "failed to resolve \"%s\"", DESTHOST);

	rump_init();

#ifndef USE_SOCKIN
	if ((e = rump_pub_netconfig_ifcreate("virt0")) != 0)
		die(e, "create virt0");
	if ((e = rump_pub_netconfig_dhcp_ipv4_oneshot("virt0")) != 0)
		die(e, "dhcp address");
#endif

	s = rump_sys_socket(PF_INET, SOCK_STREAM, 0);
	if (s == -1)
		die(errno, "socket");
	
	memset(&sin, 0, sizeof(sin));
	sin.sin_family = AF_INET;
#if 0
	sin.sin_len = sizeof(sin);
#endif
	sin.sin_port = htons(80);
	memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr));

	if (rump_sys_connect(s, (struct sockaddr *)&sin, sizeof(sin)) == -1)
		die(errno, "connect");
	printf("connected\n");

#define WANTHTML "GET / HTTP/1.1\nHost: www.netbsd.org\n\n"
	nn = rump_sys_write(s, WANTHTML, sizeof(WANTHTML)-1);
	printf("write rv %zd\n", nn);

	for (;;) {
		nn = rump_sys_read(s, buf, sizeof(buf)-1);
		if (nn == -1)
			die(errno, "read failed");
		if (nn == 0)
			break;
		
		buf[nn] = '\0';
		printf("%s", buf);
	}
	rump_sys_close(s);

	die(0, NULL);
}
예제 #4
0
static void
config_client6(void)
{

	/* configure networking using the portable interfaces */
	NOFAIL_RV(rump_pub_netconfig_ifcreate("shmif0"));
	NOFAIL_RV(rump_pub_netconfig_ifsetlinkstr("shmif0", "busmem"));
	NOFAIL_RV(rump_pub_netconfig_ipv6_ifaddr("shmif0", "2001::2", 64));
}
예제 #5
0
static void
config_server(void)
{

	/* configure interface using the portable interfaces */
	NOFAIL_RV(rump_pub_netconfig_ifcreate("shmif0"));
	NOFAIL_RV(rump_pub_netconfig_ifsetlinkstr("shmif0", "busmem"));
	NOFAIL_RV(rump_pub_netconfig_ipv4_ifaddr("shmif0",
	    "1.0.0.1", "255.255.255.0"));
}
예제 #6
0
static void
config_router6(void)
{
	extern int rumpns_ip6_forwarding;
	int rv;

	/* configure networking using the portable interfaces */
	NOFAIL_RV(rump_pub_netconfig_ifcreate("shmif0"));
	NOFAIL_RV(rump_pub_netconfig_ifsetlinkstr("shmif0", "busmem1"));
	NOFAIL_RV(rump_pub_netconfig_ipv6_ifaddr("shmif0", "2001::2", 64));
	NOFAIL_RV(rump_pub_netconfig_ifup("shmif0"));

	NOFAIL_RV(rump_pub_netconfig_ifcreate("shmif1"));
	NOFAIL_RV(rump_pub_netconfig_ifsetlinkstr("shmif1", "busmem2"));
	NOFAIL_RV(rump_pub_netconfig_ipv6_ifaddr("shmif1", "2002::2", 64));
	NOFAIL_RV(rump_pub_netconfig_ifup("shmif1"));

	/* turn ipv6 forwarding on the easy way */
	rumpns_ip6_forwarding = 1;
}
예제 #7
0
static void
config_server6(void)
{
	int rv;

	/* configure networking using the portable interfaces */
	NOFAIL_RV(rump_pub_netconfig_ifcreate("shmif0"));
	NOFAIL_RV(rump_pub_netconfig_ifsetlinkstr("shmif0", "busmem1"));
	NOFAIL_RV(rump_pub_netconfig_ipv6_ifaddr("shmif0", "2001::1", 64));

	NOFAIL_RV(rump_pub_netconfig_ipv6_gw("2001::2"));
}
예제 #8
0
파일: config.c 프로젝트: RWTH-OS/rumprun
static int
handle_net(jsmntok_t *t, int left, char *data)
{
	const char *ifname, *cloner, *type, *method;
	const char *addr, *mask, *gw;
	jsmntok_t *key, *value;
	int i, objsize;
	int rv;
	static int configured;

	T_CHECKTYPE(t, data, JSMN_OBJECT, __func__);

	/* we expect straight key-value pairs (at least for now) */
	objsize = t->size;
	if (left < 2*objsize + 1) {
		return -1;
	}
	t++;

	if (configured) {
		errx(1, "currently only 1 \"net\" configuration is supported");
	}

	ifname = cloner = type = method = NULL;
	addr = mask = gw = NULL;

	for (i = 0; i < objsize; i++, t+=2) {
		const char *valuestr;
		key = t;
		value = t+1;

		T_CHECKTYPE(key, data, JSMN_STRING, __func__);
		T_CHECKSIZE(key, data, 1, __func__);

		T_CHECKTYPE(value, data, JSMN_STRING, __func__);
		T_CHECKSIZE(value, data, 0, __func__);

		/*
		 * XXX: this mimics the structure from Xen.  We probably
		 * want a richer structure, but let's be happy to not
		 * diverge for now.
		 */
		valuestr = token2cstr(value, data);
		if (T_STREQ(key, data, "if")) {
			ifname = valuestr;
		} else if (T_STREQ(key, data, "cloner")) {
			cloner = valuestr;
		} else if (T_STREQ(key, data, "type")) {
			type = valuestr;
		} else if (T_STREQ(key, data, "method")) {
			method = valuestr;
		} else if (T_STREQ(key, data, "addr")) {
			addr = valuestr;
		} else if (T_STREQ(key, data, "mask")) {
			/* XXX: we could also pass mask as a number ... */
			mask = valuestr;
		} else if (T_STREQ(key, data, "gw")) {
			gw = valuestr;
		} else {
			errx(1, "unexpected key \"%.*s\" in \"%s\"",
			    T_PRINTFSTAR(key, data), __func__);
		}
	}

	if (!ifname || !type || !method) {
		errx(1, "net cfg missing vital data, not configuring");
	}

	if (cloner) {
		if ((rv = rump_pub_netconfig_ifcreate(ifname)) != 0) {
			errx(1, "rumprun_config: ifcreate %s failed: %d",
			    ifname, rv);
		}
	}

	if (strcmp(type, "inet") == 0) {
		config_ipv4(ifname, method, addr, mask, gw);
	} else if (strcmp(type, "inet6") == 0) {
		config_ipv6(ifname, method, addr, mask, gw);
	} else {
		errx(1, "network type \"%s\" not supported", type);
	}

	return 2*objsize + 1;
}
예제 #9
0
파일: fdinit.c 프로젝트: asb/frankenlibc
void
__franken_fdinit_create()
{
	int fd, ret, flags;
	int root = 0;
	char key[16], rkey[16], num[16];
	int n_reg = 0, n_block = 0;
	struct ufs_args ufs;

	if (__franken_fd[0].valid) {
		mkkey(key, num, "/dev/vfile", n_reg++, 0);
		rump_pub_etfs_register(key, num, RUMP_ETFS_REG);
		fd = rump___sysimpl_open(key, O_RDONLY);
		if (fd != -1) {
			rump___sysimpl_dup2(fd, 0);
			rump___sysimpl_close(fd);
		}
	}
	if (__franken_fd[1].valid) {
		mkkey(key, num, "/dev/vfile", n_reg++, 1);
		rump_pub_etfs_register(key, num, RUMP_ETFS_REG);
		fd = rump___sysimpl_open(key, O_WRONLY);
		if (fd != -1) {
			rump___sysimpl_dup2(fd, 1);
			rump___sysimpl_close(fd);
		}
	}

	if (__franken_fd[2].valid) {
		mkkey(key, num, "/dev/vfile", n_reg++, 2);
		rump_pub_etfs_register(key, num, RUMP_ETFS_REG);
		fd = rump___sysimpl_open(key, O_WRONLY);
		if (fd != -1) {
			rump___sysimpl_dup2(fd, 2);
			rump___sysimpl_close(fd);
		}
	}

	for (fd = 3; fd < MAXFD; fd++) {
		if (__franken_fd[fd].valid == 0)
			break;
		switch (__franken_fd[fd].st.st_mode & S_IFMT) {
		case S_IFREG:
			mkkey(key, num, "/dev/vfile", n_reg++, fd);
			rump_pub_etfs_register(key, num, RUMP_ETFS_REG);
			flags = __franken_fd[fd].flags & O_ACCMODE;
			rump___sysimpl_open(key, flags);
			break;
		case S_IFBLK:
			mkkey(key, num, "/dev/block", n_block, fd);
			mkkey(rkey, num, "/dev/rblock", n_block, fd);
			n_block++;
			rump_pub_etfs_register_withsize(key, num,
				RUMP_ETFS_BLK, 0, __franken_fd[fd].st.st_size);
			rump_pub_etfs_register_withsize(rkey, num,
				RUMP_ETFS_CHR, 0, __franken_fd[fd].st.st_size);
			if (root == 0) {
				ufs.fspec = key;
				flags = __franken_fd[fd].flags & O_ACCMODE;
				if (flags == O_RDWR)
					flags = MNT_LOG;
				else
					flags = MNT_RDONLY;
				ret = rump___sysimpl_mount50("ffs", "/", flags, &ufs, sizeof(struct ufs_args));
				if (ret == 0) {
					root = 1;
				} else {
					if (flags == MNT_LOG)
						flags = 0;
					ret = rump___sysimpl_mount50("ext2fs", "/", flags, &ufs, sizeof(struct ufs_args));
					if (ret == 0) {
						root = 1;
					}
				}
				if (root == 1)
					atexit(unmount_atexit);
			}
			break;
		case S_IFSOCK:
			mkkey(key, num, "virt", fd, fd);
			ret = rump_pub_netconfig_ifcreate(key);
			if (ret == 0) {
				ret = rump___sysimpl_socket30(AF_INET6, SOCK_STREAM, 0);
				if (ret != -1) {
					rump_pub_netconfig_auto_ipv6(key);
					rump___sysimpl_close(ret);
				}
				ret = rump___sysimpl_socket30(AF_INET, SOCK_STREAM, 0);
				if (ret != -1) {
					rump_pub_netconfig_dhcp_ipv4_oneshot(key);
					rump___sysimpl_close(ret);
				}
			}
			break;
		}
	}
}
예제 #10
0
static void
rumprun_config_net(const char *if_index)
{
	char *if_type = NULL;
	char *if_method = NULL;
	char *if_addr = NULL;
	char *if_mask = NULL;
	char *if_gw = NULL;
	char buf[128];
	int rv;
	
	rv = xs_read_netconfig(if_index, &if_type, &if_method, &if_addr,
		&if_mask, &if_gw);
	if (rv != 0)
		return;
	
	printf("rumprun_config: configuring xenif%s as %s with %s %s\n",
		if_index, if_type, if_method, if_addr ? if_addr : "");
	snprintf(buf, sizeof buf, "xenif%s", if_index);
	if ((rv = rump_pub_netconfig_ifcreate(buf)) != 0) {
		warnx("rumprun_config: %s: ifcreate failed: %s\n", buf,
			strerror(rv));
		goto out;
	}
	if (strcmp(if_type, "inet") == 0 &&
	    strcmp(if_method, "dhcp") == 0) {
		if ((rv = rump_pub_netconfig_dhcp_ipv4_oneshot(buf)) != 0) {
			warnx("rumprun_config: %s: dhcp_ipv4 failed: %s\n", buf,
				strerror(rv));
			goto out;
		}
	}
	else if (strcmp(if_type, "inet") == 0 &&
		 strcmp(if_method, "static") == 0) {
		if (if_addr == NULL || if_mask == NULL) {
			warnx("rumprun_config: %s: missing if_addr/mask\n",
			    buf);
			goto out;
		}
		if ((rv = rump_pub_netconfig_ipv4_ifaddr(buf, if_addr,
			if_mask)) != 0) {
			warnx("rumprun_config: %s: ipv4_ifaddr failed: %s\n",
				buf, strerror(rv));
			goto out;
		}
		if (if_gw &&
			(rv = rump_pub_netconfig_ipv4_gw(if_gw)) != 0) {
			warnx("rumprun_config: %s: ipv4_gw failed: %s\n",
				buf, strerror(rv));
			goto out;
		}
	}
	else {
		warnx("rumprun_config: %s: unknown type/method %s/%s\n",
			buf, if_type, if_method);
	}

out:
	free(if_type);
	free(if_method);
	if (if_addr)
		free(if_addr);
	if (if_mask)
		free(if_mask);
	if (if_gw)
		free(if_gw);
}