/*
 * bound: This argument is used when udhcpc moves from an unbound, to
 * a bound state. All of the paramaters are set in enviromental
 * variables, The script should configure the interface, and set any
 * other relavent parameters (default gateway, dns server, etc).
*/
static int
bound(void)
{
	char *lan_ifname = safe_getenv("interface");
	char *value;
	char tmp[100], prefix[] = "lanXXXXXXXXXX_";

	snprintf(prefix, sizeof(prefix), "lan_");
	
	if ((value = getenv("ip")))
		nvram_set(strcat_r(prefix, "ipaddr", tmp), value);
	if ((value = getenv("subnet")))
		nvram_set(strcat_r(prefix, "netmask", tmp), value);
        if ((value = getenv("router")))
		nvram_set(strcat_r(prefix, "gateway", tmp), value);
	if ((value = getenv("dns")))
		nvram_set(strcat_r(prefix, "dns", tmp), value);
	if ((value = getenv("wins")))
		nvram_set(strcat_r(prefix, "wins", tmp), value);
	if ((value = getenv("hostname")))
		sethostname(value, strlen(value) + 1);
	if ((value = getenv("domain")))
		nvram_set(strcat_r(prefix, "domain", tmp), value);
	if ((value = getenv("lease"))) {
		nvram_set(strcat_r(prefix, "lease", tmp), value);
		expires(lan_ifname, atoi(value));
	}

	ifconfig(lan_ifname, IFUP,
		 nvram_safe_get(strcat_r(prefix, "ipaddr", tmp)),
		 nvram_safe_get(strcat_r(prefix, "netmask", tmp)));

	lan_up(lan_ifname);

	logmessage("dhcp client", "%s IP : %s from %s", 
		udhcpstate, 
		nvram_safe_get(strcat_r(prefix, "ipaddr", tmp)), 
		nvram_safe_get(strcat_r(prefix, "gateway", tmp)));

	//wanmessage("");

	dprintf("done\n");
	return 0;
}
Beispiel #2
0
/*
 * bound: This argument is used when udhcpc moves from an unbound, to
 * a bound state. All of the paramaters are set in enviromental
 * variables, The script should configure the interface, and set any
 * other relavent parameters (default gateway, dns server, etc).
*/
static int
bound_lan(void)
{
	char *lan_ifname = safe_getenv("interface");
	char *value;
	int flags;
	unsigned long addr, netmask;
	struct in_addr in_addr, in_netmask;

	if ((value = getenv("ip")))
		nvram_set("lan_ipaddr", value);
	if ((value = getenv("subnet")))
		nvram_set("lan_netmask", value);
	if ((value = getenv("router")))
		nvram_set("lan_gateway", value);
	if ((value = getenv("lease")))
		expires_lan(lan_ifname, atoi(value));

	/* Check if we do need to do ifconfig */
	if (ifconfig_get(lan_ifname, &flags, &addr, &netmask) == 0) {
		inet_aton(nvram_safe_get("lan_ipaddr"), &in_addr);
		inet_aton(nvram_safe_get("lan_netmask"), &in_netmask);
		if ((flags & IFUP) && addr == in_addr.s_addr && netmask == in_netmask.s_addr)
			goto done;
	}

	ifconfig(lan_ifname, IFUP, nvram_safe_get("lan_ipaddr"),
		nvram_safe_get("lan_netmask"));

	lan_up(lan_ifname);

#ifdef __CONFIG_WPS__
	start_wps();
#endif

done:
	dprintf("done\n");
	return 0;
}