Exemplo n.º 1
0
static void
config_ipv4(const char *ifname, const char *method,
	const char *addr, const char *mask, const char *gw)
{
	int rv;

	if (strcmp(method, "dhcp") == 0) {
		if ((rv = rump_pub_netconfig_dhcp_ipv4_oneshot(ifname)) != 0)
			errx(1, "configuring dhcp for %s failed: %d",
			    ifname, rv);
	} else {
		if (strcmp(method, "static") != 0) {
			errx(1, "method \"static\" or \"dhcp\" expected, "
			    "got \"%s\"", method);
		}

		if (!addr || !mask) {
			errx(1, "static net cfg missing addr or mask");
		}

		if ((rv = rump_pub_netconfig_ipv4_ifaddr_cidr(ifname,
		    addr, atoi(mask))) != 0) {
			errx(1, "ifconfig \"%s\" for \"%s/%s\" failed",
			    ifname, addr, mask);
		}
		if (gw && (rv = rump_pub_netconfig_ipv4_gw(gw)) != 0) {
			errx(1, "gw \"%s\" addition failed", gw);
		}
	}
}
Exemplo n.º 2
0
static void
config_client(void)
{
	int rv;

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

	NOFAIL_RV(rump_pub_netconfig_ipv4_gw("1.0.1.2"));
}
Exemplo n.º 3
0
static void
config_server(void)
{
	int rv;

	/* configure interface 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.1", "255.255.255.0"));

	NOFAIL_RV(rump_pub_netconfig_ipv4_gw("1.0.0.2"));
}
Exemplo n.º 4
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);
}