Example #1
0
int
launch_wan_usbnet(int unit)
{
	int modem_devnum = 0;
	char ndis_ifname[16] = {0};

	if (get_modem_ndis_ifname(ndis_ifname, &modem_devnum) && is_interface_exist(ndis_ifname)) {
		int ndis_mtu = nvram_safe_get_int("modem_mtu", 1500, 1000, 1500);
		
		check_upnp_wanif_changed(ndis_ifname);
		set_wan_unit_value(unit, "proto_t", "NDIS Modem");
		set_wan_unit_value(unit, "ifname_t", ndis_ifname);
		
		/* bring up NDIS interface */
		doSystem("ifconfig %s mtu %d up %s", ndis_ifname, ndis_mtu, "0.0.0.0");
		
		/* re-build iptables rules (first stage w/o WAN IP) */
		start_firewall_ex();
		
		if (ndis_control_network(ndis_ifname, modem_devnum, 1) == 0)
			sleep(1);
		
		start_udhcpc_wan(ndis_ifname, unit, 0);
		
		return 0;
	}

	set_wan_unit_value(unit, "ifname_t", "");
	return -1;
}
Example #2
0
void
stop_modem_ndis(void)
{
	int i, modem_devnum = 0;
	char node_fname[64];
	char ndis_ifname[16] = {0};
	
	system("killall -q usb_modeswitch");
	system("killall -q eject");
	
	if (get_modem_ndis_ifname(ndis_ifname, &modem_devnum)) {
		disconnect_ndis(modem_devnum);
		if (is_interface_exist(ndis_ifname))
			ifconfig(ndis_ifname, 0, "0.0.0.0", NULL);
	}

	for (i=0; i<MAX_USB_NODE; i++)
	{
		sprintf(node_fname, "%s/ttyUSB%d", MODEM_NODE_DIR, i);
		unlink(node_fname);
		
		sprintf(node_fname, "%s/cdc-wdm%d", MODEM_NODE_DIR, i);
		unlink(node_fname);
		
		sprintf(node_fname, "%s/weth%d", MODEM_NODE_DIR, i);
		unlink(node_fname);
		
		sprintf(node_fname, "%s/wwan%d", MODEM_NODE_DIR, i);
		unlink(node_fname);
	}
}
Example #3
0
static void
openvpn_tunif_start(const char *ifname)
{
    if (!is_interface_exist(ifname))
        doSystem("%s %s --dev %s", OPENVPN_EXE, "--mktun", ifname);
    set_vpn_balancing(ifname);
}
Example #4
0
static void
openvpn_tunif_stop(const char *ifname)
{
	if (is_interface_exist(ifname)) {
		doSystem("ifconfig %s %s", ifname, "down");
		doSystem("%s %s --dev %s", OPENVPN_EXE, "--rmtun", ifname);
	}
}
Example #5
0
static void
openvpn_tapif_stop(const char *ifname)
{
	if (is_interface_exist(ifname)) {
		doSystem("ifconfig %s %s", ifname, "down");
		doSystem("brctl %s %s %s 2>/dev/null", "delif", IFNAME_BR, ifname);
		doSystem("%s %s --dev %s", OPENVPN_EXE, "--rmtun", ifname);
	}
}
Example #6
0
static void
openvpn_tapif_start(const char *ifname, int insert_to_bridge)
{
	if (!is_interface_exist(ifname))
		doSystem("%s %s --dev %s", OPENVPN_EXE, "--mktun", ifname);
	if (insert_to_bridge)
		doSystem("brctl %s %s %s", "addif", IFNAME_BR, ifname);
	doSystem("ifconfig %s %s %s", ifname, "0.0.0.0", "promisc up");
}
Example #7
0
static void
openvpn_tapif_stop(const char *ifname)
{
    if (is_interface_exist(ifname)) {
        ifconfig(ifname, 0, NULL, NULL);
        br_add_del_if(IFNAME_BR, ifname, 0);
        doSystem("%s %s --dev %s", OPENVPN_EXE, "--rmtun", ifname);
    }
}
Example #8
0
static int
is_ready_modem_ndis(int *devnum_out)
{
	char ndis_ifname[16];

	if (get_modem_ndis_ifname(ndis_ifname, devnum_out) && is_interface_exist(ndis_ifname))
		return 1;

	return 0;
}
Example #9
0
static void
openvpn_tapif_start(const char *ifname, int insert_to_bridge)
{
    if (!is_interface_exist(ifname))
        doSystem("%s %s --dev %s", OPENVPN_EXE, "--mktun", ifname);

    if (insert_to_bridge)
        br_add_del_if(IFNAME_BR, ifname, 1);
    doSystem("ifconfig %s %s %s", ifname, "0.0.0.0", "promisc up");
    set_vpn_balancing(ifname);
}
Example #10
0
void
stop_wan_usbnet(void)
{
	int modem_devnum = 0;
	char ndis_ifname[16] = {0};

	if (get_modem_ndis_ifname(ndis_ifname, &modem_devnum)) {
		ndis_control_network(ndis_ifname, modem_devnum, 0);
		if (is_interface_exist(ndis_ifname))
			ifconfig(ndis_ifname, 0, "0.0.0.0", NULL);
	}
}
Example #11
0
void wan6_down(char *wan_ifname)
{
	int ipv6_type;
	char *wan6_ifname;

	ipv6_type = get_ipv6_type();
	if (ipv6_type == IPV6_DISABLED)
		return;

	stop_radvd();
	stop_dhcp6c();
	control_if_ipv6_radv(wan_ifname, 0);
	control_if_ipv6_autoconf(wan_ifname, 0);

	if (ipv6_type == IPV6_6IN4 || ipv6_type == IPV6_6TO4 || ipv6_type == IPV6_6RD)
	{
		wan6_ifname = IFNAME_SIT;
		if (is_interface_exist(IFNAME_SIT))
			doSystem("ip link set dev %s down", IFNAME_SIT);
	}
	else
	{
		wan6_ifname = wan_ifname;
	}

	// clear WAN routes6
	clear_if_route6(wan6_ifname);

	// clear WAN addr6
	clear_if_addr6(wan6_ifname);

	// delete SIT tunnel
	stop_sit_tunnel();

	// clear DNS6 for resolv.conf
	nvram_set("wan0_dns6", "");
}
Example #12
0
void stop_sit_tunnel(void)
{
	if (is_interface_exist(IFNAME_SIT))
		doSystem("ip tunnel del %s", IFNAME_SIT);
}
Example #13
0
void start_sit_tunnel(int ipv6_type, char *wan_addr4, char *wan_addr6)
{
	int sit_ttl, sit_mtu, size4, size6;
	char *sit_remote, *sit_relay, *wan_gate6;
	char addr6s[INET6_ADDRSTRLEN];
	struct in_addr addr4;
	struct in6_addr addr6;

	size4 = 0;
	addr4.s_addr = inet_addr_(wan_addr4);
	if (addr4.s_addr == INADDR_ANY)
		return; // cannot start SIT tunnel w/o IPv4 WAN addr

	sit_mtu = nvram_get_int("ip6_sit_mtu");
	sit_ttl = nvram_get_int("ip6_sit_ttl");
	if (sit_mtu < 1280) sit_mtu = 1280;
	if (sit_ttl < 1) sit_ttl = 1;
	if (sit_ttl > 255) sit_ttl = 255;

	memset(&addr6, 0, sizeof(addr6));
	size6 = ipv6_from_string(wan_addr6, &addr6);
	if (size6 < 0) size6 = 0;

	sit_relay = "";
	sit_remote = "any";
	if (ipv6_type == IPV6_6IN4)
		sit_remote = nvram_safe_get("ip6_6in4_remote");
	
	if (is_interface_exist(IFNAME_SIT))
		doSystem("ip tunnel del %s", IFNAME_SIT);
	
	doSystem("ip tunnel %s %s mode sit remote %s local %s ttl %d", "add", IFNAME_SIT, sit_remote, wan_addr4, sit_ttl);
	
	if (ipv6_type == IPV6_6TO4) {
		size6 = 16;
		memset(&addr6, 0, sizeof(addr6));
		addr6.s6_addr16[0] = htons(0x2002);
		ipv6_to_ipv4_map(&addr6, size6, &addr4, 0);
		addr6.s6_addr16[7] = htons(0x0001);
		sit_relay = nvram_safe_get("ip6_6to4_relay");
	}
	else if (ipv6_type == IPV6_6RD) {
		struct in_addr net4;
		struct in6_addr net6;
		char sit_6rd_prefix[INET6_ADDRSTRLEN], sit_6rd_relay_prefix[32];
		
		memcpy(&net6, &addr6, sizeof(addr6));
		ipv6_to_net(&net6, size6);
		inet_ntop(AF_INET6, &net6, sit_6rd_prefix, INET6_ADDRSTRLEN);
		sprintf(sit_6rd_prefix, "%s/%d", sit_6rd_prefix, size6);
		
		strcpy(sit_6rd_relay_prefix, "0.0.0.0/0");
		size4 = nvram_get_int("wan0_6rd_size");
		if (size4 > 0 && size4 <= 32)
		{
			net4.s_addr = addr4.s_addr & htonl(0xffffffffUL << (32 - size4));
			sprintf(sit_6rd_relay_prefix, "%s/%d", inet_ntoa(net4), size4);
		}
		
		doSystem("ip tunnel 6rd dev %s 6rd-prefix %s 6rd-relay_prefix %s", IFNAME_SIT, sit_6rd_prefix, sit_6rd_relay_prefix);
		
		ipv6_to_ipv4_map(&addr6, size6, &addr4, size4);
		addr6.s6_addr16[7] = htons(0x0001);
		sit_relay = nvram_safe_get("wan0_6rd_relay");
	}

	// WAN IPv6 address
	inet_ntop(AF_INET6, &addr6, addr6s, INET6_ADDRSTRLEN);
	if (size6 > 0)
		sprintf(addr6s, "%s/%d", addr6s, size6);

	control_if_ipv6_radv(IFNAME_SIT, 0);
	doSystem("ip link set mtu %d dev %s up", sit_mtu, IFNAME_SIT);
	control_if_ipv6(IFNAME_SIT, 1);
	clear_if_addr6(IFNAME_SIT);
	doSystem("ip -6 addr add %s dev %s", addr6s, IFNAME_SIT);

	/* WAN IPv6 gateway (auto-generate for 6to4/6rd) */
	if (ipv6_type == IPV6_6TO4 || ipv6_type == IPV6_6RD) {
		sprintf(addr6s, "::%s", sit_relay);
		wan_gate6 = addr6s;
		/* add direct default gateway for workaround "No route to host" on new kernel */
		doSystem("ip -6 route add default dev %s metric %d", IFNAME_SIT, 2048);
	}
	else {
		wan_gate6 = nvram_safe_get("wan0_gate6");
	}
	if (*wan_gate6)
		doSystem("ip -6 route add default via %s dev %s metric %d", wan_gate6, IFNAME_SIT, 1);

	/* LAN IPv6 address (auto-generate for 6to4/6rd) */
	if (ipv6_type == IPV6_6TO4 || ipv6_type == IPV6_6RD) {
		memset(&addr6, 0, sizeof(addr6));
		if (ipv6_type == IPV6_6TO4) {
			addr6.s6_addr16[0] = htons(0x2002);
			ipv6_to_ipv4_map(&addr6, 16, &addr4, 0);
			addr6.s6_addr16[3] = htons(0x0001);
			addr6.s6_addr16[7] = htons(0x0001);
		}
		else {
			ipv6_from_string(wan_addr6, &addr6);
			ipv6_to_ipv4_map(&addr6, size6, &addr4, size4);
			addr6.s6_addr16[7] = htons(0x0001);
		}
		
		inet_ntop(AF_INET6, &addr6, addr6s, INET6_ADDRSTRLEN);
		sprintf(addr6s, "%s/%d", addr6s, 64);
		
		clear_if_addr6(IFNAME_BR);
		doSystem("ip -6 addr add %s dev %s", addr6s, IFNAME_BR);
		
		store_lan_addr6(addr6s);
	}
}
Example #14
0
void clear_if_neigh6(char *ifname)
{
	if (is_interface_exist(ifname))
		doSystem("ip -6 neigh flush dev %s", ifname);
}
Example #15
0
void clear_if_route6(char *ifname)
{
	if (is_interface_exist(ifname))
		doSystem("ip -6 route flush dev %s", ifname);
}
Example #16
0
void clear_if_addr6(char *ifname)
{
	if (is_interface_exist(ifname))
		doSystem("ip -6 addr flush dev %s scope global", ifname);
}