Example #1
0
int dhcp6c_main(int argc, char **argv)
{
	int ipv6_type, dns6_auto, lan6_auto, is_need_notify_radvd;
	char *dns6_new, *lan_addr6_new;
	char addr6s[INET6_ADDRSTRLEN];

//	char *wan_ifname = safe_getenv("interface");

	ipv6_type = get_ipv6_type();
	if (ipv6_type != IPV6_NATIVE_DHCP6)
		return 0;

	is_need_notify_radvd = 0;
	lan6_auto = nvram_get_int("ip6_lan_auto");
	if (lan6_auto) {
		lan_addr6_new = get_ifaddr6(IFNAME_BR, 0, addr6s);
		if (store_lan_addr6(lan_addr6_new))
			is_need_notify_radvd = 1;
	}

	dns6_auto = nvram_get_int("ip6_dns_auto");
	if (dns6_auto) {
		dns6_new = getenv("new_domain_name_servers");
		if (store_wan_dns6(dns6_new)) {
			update_resolvconf(0, 0);
			is_need_notify_radvd = 1;
		}
	}

	if (is_need_notify_radvd || !pids("radvd"))
		reload_radvd();

	return 0;
}
Example #2
0
static void
on_client_ifup(void)
{
	char buf[256];

	nvram_set_int_temp("vpnc_state_t", 1);

	buf[0] = 0;
	if (nvram_get_int("vpnc_pdns") > 0) {
		int i, i_dns, buf_len;
		char *value;
		char foption[32], fdns[128];
		
		for (i=0, i_dns=0; i < 20 && i_dns < 3; i++) {
			sprintf(foption, "foreign_option_%d", i);
			value = getenv(foption);
			if (value) {
				fdns[0] = 0;
				if (sscanf(value, "dhcp-option DNS %s", fdns) == 1) {
					buf_len = strlen(buf);
					snprintf(buf + buf_len, sizeof(buf) - buf_len, "%s%s", (buf_len) ? " " : "", fdns);
					i_dns++;
				}
			}
		}
	}

	nvram_set_temp("vpnc_dns_t", buf);
	if (strlen(buf) > 0)
		update_resolvconf(0, 0);
}
Example #3
0
void
restore_dns_from_vpnc(void)
{
	char *vpnc_dns = nvram_safe_get("vpnc_dns_t");
	if (*vpnc_dns) {
		nvram_set_temp("vpnc_dns_t", "");
		update_resolvconf(0, 0);
	}
}
Example #4
0
/*
 * renew: This argument is used when a DHCP lease is renewed. All of
 * the paramaters are set in enviromental variables. This argument is
 * used when the interface is already configured, so the IP address,
 * will not change, however, the other DHCP paramaters, such as the
 * default gateway, subnet mask, and dns server may change.
 */
static int
renew(void)
{
	char *wan_ifname = safe_getenv("interface");
	char *value;
	char tmp[100], prefix[] = "wanXXXXXXXXXX_";
	int unit;

	if ((unit = wan_ifunit(wan_ifname)) < 0)
		strcpy(prefix, "wanx_");
	else
		snprintf(prefix, sizeof(prefix), "wan%d_", unit);

	if (!(value = getenv("subnet")) || !nvram_match(strcat_r(prefix, "netmask", tmp), trim_r(value)))
		return bound();
	if (!(value = getenv("router")) || !nvram_match(strcat_r(prefix, "gateway", tmp), trim_r(value)))
		return bound();

	if ((value = getenv("dns")) && !nvram_match(strcat_r(prefix, "dns", tmp), trim_r(value))) {
		nvram_set(strcat_r(prefix, "dns", tmp), trim_r(value));
#if 0
		update_resolvconf();
#else
		add_dns(wan_ifname);
#endif
	}

	if ((value = getenv("wins")))
		nvram_set(strcat_r(prefix, "wins", tmp), trim_r(value));
#if 0
	if ((value = getenv("hostname")))
		sethostname(trim_r(value), strlen(value) + 1);
#endif
	if ((value = getenv("domain")))
		nvram_set(strcat_r(prefix, "domain", tmp), trim_r(value));
	if ((value = getenv("lease"))) {
		nvram_set(strcat_r(prefix, "lease", tmp), trim_r(value));
		expires(wan_ifname, atoi(value));
	}

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

	if (unit == 0)
		update_wan_status(1);

	wanmessage("");

	dprintf("done\n");
	return 0;
}
Example #5
0
static void
on_client_ifup(void)
{
	int i, i_dns = 0;
	char buf[256];
	char *script_name = VPN_CLIENT_UPDOWN_SCRIPT;

	nvram_set_int_temp("vpnc_state_t", 1);

	buf[0] = 0;
	if (nvram_get_int("vpnc_pdns") > 0) {
		int buf_len;
		char *value;
		char foption[32], fdns[128];
		
		for (i = 0; i < 20 && i_dns < 3; i++) {
			sprintf(foption, "foreign_option_%d", i);
			value = getenv(foption);
			if (value) {
				fdns[0] = 0;
				if (sscanf(value, "dhcp-option DNS %s", fdns) == 1) {
					buf_len = strlen(buf);
					snprintf(buf + buf_len, sizeof(buf) - buf_len, "%s%s", (buf_len) ? " " : "", fdns);
					i_dns++;
					if (i_dns == 1)
						setenv("DNS1", fdns, 1);
					else if (i_dns == 2)
						setenv("DNS2", fdns, 1);
				}
			}
		}
	}

	nvram_set_temp("vpnc_dns_t", buf);
	if (strlen(buf) > 0)
		update_resolvconf(0, 0);

	if (check_if_file_exist(script_name)) {
		for (i = 0; i < ARRAY_SIZE(env_ovpn); i++)
			setenv(env_pppd[i], safe_getenv(env_ovpn[i]), 1);
		doSystem("%s %s", script_name, "up");
		for (i = 0; i < ARRAY_SIZE(env_ovpn); i++)
			unsetenv(env_pppd[i]);
	}

	if (i_dns > 1)
		unsetenv("DNS2");
	if (i_dns > 0)
		unsetenv("DNS1");
}
Example #6
0
void full_restart_ipv6(int ipv6_type_old)
{
	int ipv6_type = get_ipv6_type();
	int ipv6_toggled = ((ipv6_type == IPV6_DISABLED || ipv6_type_old == IPV6_DISABLED) && (ipv6_type != ipv6_type_old)) ? 1 : 0;

	if (ipv6_toggled) {
		stop_lltd();
		stop_httpd();
	}

	stop_upnp();
	stop_dhcp6c();
	stop_dns_dhcpd();

	if (ipv6_type == IPV6_DISABLED) {
		clear_all_route6();
		clear_all_addr6();
		clear_if_neigh6(IFNAME_BR);
		stop_sit_tunnel();
		reset_lan6_vars();
		reset_wan6_vars();
		control_if_ipv6_all(0);
		set_libc_gai(1);
		update_resolvconf(0, 1);
		reload_nat_modules();
		restart_firewall();
		start_dns_dhcpd(0);
	} else {
		set_libc_gai(0);
		control_if_ipv6_all(1);
		clear_all_addr6();
		reset_lan6_vars();
		reload_lan_addr6();
		full_restart_wan();
		if (!is_dns_dhcpd_run())
			start_dns_dhcpd(0);
	}

	if (ipv6_toggled) {
		start_httpd(0);
		start_lltd();
	}
}
Example #7
0
int
ipup_vpnc_main(int argc, char **argv)
{
	char buf[256];
	char *script_name = VPN_CLIENT_UPDOWN_SCRIPT;
	char *ifname = safe_getenv("IFNAME");
	char *gw = getenv("IPREMOTE");

	umask(0000);

	vpnc_route_to_remote_lan(ifname, gw, 1);
	vpnc_route_dgw(ifname, gw, 1);

	set_vpn_balancing(ifname);

	nvram_set_int_temp("vpnc_state_t", 1);

	buf[0] = 0;
	if (nvram_get_int("vpnc_pdns") > 0) {
		char *value;
		
		value = getenv("DNS1");
		if (value)
			snprintf(buf, sizeof(buf), "%s", value);
		value = getenv("DNS2");
		if (value && strcmp(value, buf) != 0) {
			int buf_len = strlen(buf);
			snprintf(buf + buf_len, sizeof(buf) - buf_len, "%s%s", (buf_len) ? " " : "", value);
		}
	}

	nvram_set_temp("vpnc_dns_t", buf);
	if (strlen(buf) > 0)
		update_resolvconf(0, 0);

	if (check_if_file_exist(script_name))
		doSystem("%s %s", script_name, "up");

	return 0;
}
Example #8
0
static void
on_client_ifup(void)
{
#define ENV_SCAN_MAX 20
    int i, i_dns = 0, i_wins = 0, i_dom = 0, vpnc_pdns;
    char buf[256], foption[32], fvalue[128], *value;

    nvram_set_int_temp("vpnc_state_t", 1);

    vpnc_pdns = nvram_get_int("vpnc_pdns");

    buf[0] = 0;
    for (i = 0; i < ENV_SCAN_MAX; i++) {
        snprintf(foption, sizeof(foption), "foreign_option_%d", i);
        value = getenv(foption);
        if (value) {
            memset(fvalue, 0, sizeof(fvalue));
            if (sscanf(value, "dhcp-option DNS %127s", fvalue) == 1) {
                if (vpnc_pdns > 0) {
                    int buf_len = strlen(buf);
                    snprintf(buf + buf_len, sizeof(buf) - buf_len, "%s%s", (buf_len) ? " " : "", fvalue);
                }
                i_dns++;
                if (i_dns == 1)
                    setenv("DNS1", fvalue, 1);
                else if (i_dns == 2)
                    setenv("DNS2", fvalue, 1);
            } else if (sscanf(value, "dhcp-option WINS %127s", fvalue) == 1) {
                i_wins++;
                if (i_wins == 1)
                    setenv("WINS1", fvalue, 1);
                else if (i_wins == 2)
                    setenv("WINS2", fvalue, 1);
            } else if (sscanf(value, "dhcp-option DOMAIN %127s", fvalue) == 1) {
                i_dom++;
                if (i_dom == 1) {
                    if (vpnc_pdns > 0)
                        nvram_set_temp("vpnc_dom_t", fvalue);
                    setenv("DOMAIN", fvalue, 1);
                }
            }
        }
        if (i_dom >= 1 && i_wins >= 2 && i_dns >= 2)
            break;
    }

    nvram_set_temp("vpnc_dns_t", buf);
    if (strlen(buf) > 0)
        update_resolvconf(0, 0);

    call_client_script(VPN_CLIENT_UPDOWN_SCRIPT, "up");

    if (i_dom > 0)
        unsetenv("DOMAIN");
    if (i_wins > 1)
        unsetenv("WINS2");
    if (i_wins > 0)
        unsetenv("WINS1");
    if (i_dns > 1)
        unsetenv("DNS2");
    if (i_dns > 0)
        unsetenv("DNS1");
}