Exemple #1
0
int set_pppoepid_main(int argc, char **argv)
{
	if (argc < 2) return 0;

	TRACE_PT("num=%s\n", argv[1]);

	if (atoi(argv[1]) != 0) return 0;

	nvram_set("pppoe_pid0", getenv("PPPD_PID"));
	nvram_set("pppoe_ifname0", getenv("IFNAME"));
	nvram_set("wan_iface", getenv("IFNAME"));
	
	TRACE_PT("IFNAME=%s DEVICE=%s\n", getenv("IFNAME"), getenv("DEVICE"));
	return 0;
}
Exemple #2
0
int pppevent_main(int argc, char **argv)
{
	int i;
	
	TRACE_PT("begin\n");

	for (i = 1; i < argc; ++i) {
		TRACE_PT("arg%d=%s\n", i, argv[i]);
		if (strcmp(argv[i], "-t") == 0) {
			if (++i >= argc) return 1;
			if ((strcmp(argv[i], "PAP_AUTH_FAIL") == 0) || (strcmp(argv[i], "CHAP_AUTH_FAIL") == 0)) {
				f_write_string("/tmp/ppp/log", argv[i], 0, 0);
				notice_set("wan", "Authentication failed");	// !!!
				return 0;
			}			
		}
	}

	TRACE_PT("end\n");
	return 1;
}
Exemple #3
0
int ipdown_main(int argc, char **argv)
{
	int proto;
	
	TRACE_PT("begin\n");

	if (!wait_action_idle(10)) return -1;

	stop_ddns();	// avoid to trigger DOD
	stop_ntpc();

	unlink("/tmp/ppp/link");

	proto = get_wan_proto();
	if (proto == WP_L2TP || proto == WP_PPTP) {
		/* clear dns from the resolv.conf */
		nvram_set("wan_get_dns","");
		dns_to_resolv();

		if (proto == WP_L2TP) {
			route_del(nvram_safe_get("wan_ifname"), 0, nvram_safe_get("l2tp_server_ip"),
				nvram_safe_get("wan_gateway"), "255.255.255.255"); // fixed routing problem in Israel by kanki
		}

		// Restore the default gateway for WAN interface
		nvram_set("wan_gateway_get", nvram_safe_get("wan_gateway"));

		// Set default route to gateway if specified
		route_del(nvram_safe_get("wan_ifname"), 0, "0.0.0.0", nvram_safe_get("wan_gateway"), "0.0.0.0");
		route_add(nvram_safe_get("wan_ifname"), 0, "0.0.0.0", nvram_safe_get("wan_gateway"), "0.0.0.0");
	}

	if (nvram_get_int("ppp_demand")) {
		killall("listen", SIGKILL);
		eval("listen", nvram_safe_get("lan_ifname"));
	}

	TRACE_PT("end\n");
	return 1;
}
Exemple #4
0
int pppevent_main(int argc, char **argv)
{
	int i;
	
	TRACE_PT("begin\n");

	for (i = 1; i < argc; ++i) {
		TRACE_PT("arg%d=%s\n", i, argv[i]);
		if (strcmp(argv[i], "-t") == 0) {
			if (++i >= argc) return 1;
			if ((strcmp(argv[i], "PAP_AUTH_FAIL") == 0) || (strcmp(argv[i], "CHAP_AUTH_FAIL") == 0)) {
				f_write_string("/tmp/ppp/log", argv[i], 0, 0);
				return 0;
			}
			if ((strcmp(argv[i], "PADO_TIMEOUT") == 0) || (strcmp(argv[i], "PADS_TIMEOUT") == 0)) {
				f_write_string("/tmp/ppp/log", argv[i], 0, 0);
				return 0;
			}
		}
	}

	TRACE_PT("end\n");
	return 1;
}
Exemple #5
0
int pppoe_down_main(int argc, char **argv)
{
	if (argc < 2) return 0;

	TRACE_PT("num=%s\n", argv[1]);

	if (atoi(argv[1]) != 0) return 0;

	if ((nvram_get_int("ppp_demand")) && (nvram_match("action_service", "")))	{
		stop_singe_pppoe(0);
		start_pppoe(0);
		
		stop_dnsmasq();
		dns_to_resolv();
		start_dnsmasq();
	}
	return 0;
}
Exemple #6
0
static int config_pppd(int wan_proto, int num)
{
	TRACE_PT("begin\n");

	FILE *fp;
	FILE *cfp;
	char *p;
	int demand;

	mkdir("/tmp/ppp", 0777);
	symlink("/sbin/rc", "/tmp/ppp/ip-up");
	symlink("/sbin/rc", "/tmp/ppp/ip-down");
#ifdef TCONFIG_IPV6
	symlink("/sbin/rc", "/tmp/ppp/ipv6-up");
	symlink("/sbin/rc", "/tmp/ppp/ipv6-down");
#endif
	symlink("/dev/null", "/tmp/ppp/connect-errors");

	demand = nvram_get_int("ppp_demand");

	// Generate options file
	if ((fp = fopen(ppp_optfile, "w")) == NULL) {
		perror(ppp_optfile);
		return -1;
	}

#ifdef LINUX26
#ifdef TCONFIG_USB
	if (nvram_match("wan_proto", "ppp3g") ) {
		fprintf(fp,
			"/dev/%s\n"
			"460800\n"
			"connect \"/usr/sbin/chat -V -t 60 -f %s\"\n"
			"noipdefault\n"
			"lock\n"
			"crtscts\n"
			"modem\n"
			"ipcp-accept-local\n",
			nvram_safe_get("modem_dev"),
			ppp3g_chatfile);

		if (strlen(nvram_get("ppp_username")) >0 )
			fprintf(fp, "user '%s'\n", nvram_get("ppp_username"));
	} else {
#endif
#endif
		fprintf(fp,
			"unit %d\n"
			"user '%s'\n"
			"lcp-echo-adaptive\n",	// Suppress LCP echo-requests if traffic was received
			num,
			nvram_safe_get("ppp_username"));
#ifdef LINUX26
#ifdef TCONFIG_USB
	}
#endif
#endif

	fprintf(fp,
		"defaultroute\n"	// Add a default route to the system routing tables, using the peer as the gateway
		"usepeerdns\n"		// Ask the peer for up to 2 DNS server addresses
		"default-asyncmap\n"	// Disable  asyncmap  negotiation
		"novj\n"		// Disable Van Jacobson style TCP/IP header compression
		"nobsdcomp\n"		// Disable BSD-Compress  compression
		"nodeflate\n"		// Disable Deflate compression
		"noauth\n"		// Do not authenticate peer
		"refuse-eap\n"		// Do not use eap
		"maxfail 0\n"		// Never give up
		"lcp-echo-interval %d\n"// Interval between LCP echo-requests
		"lcp-echo-failure %d\n"	// Tolerance to unanswered echo-requests
		"%s",			// Debug
		nvram_get_int("pppoe_lei") ? : 10,
		nvram_get_int("pppoe_lef") ? : 5,
		nvram_get_int("debug_ppp") ? "debug\n" : "");

#ifdef LINUX26
#ifdef TCONFIG_USB
	if (nvram_match("wan_proto", "ppp3g") && nvram_match("modem_dev", "ttyACM0") ) {
		//don`t write nopcomp and noaccomp options
	} else {
#endif
#endif
		fprintf(fp,
			"nopcomp\n"		// Disable protocol field compression
			"noaccomp\n"		// Disable Address/Control compression
			);
#ifdef LINUX26
#ifdef TCONFIG_USB
	}
#endif
#endif


	if (wan_proto != WP_L2TP) {
		fprintf(fp,
			"persist\n"
			"holdoff %d\n",
			demand ? 30 : (nvram_get_int("ppp_redialperiod") ? : 30));
	}
Exemple #7
0
int ipup_main(int argc, char **argv)
{
	char *wan_ifname;
	char *value;
	char buf[256];
	const char *p;

	TRACE_PT("begin\n");

	killall("listen", SIGKILL);
	
	if (!wait_action_idle(10)) return -1;

	wan_ifname = safe_getenv("IFNAME");
	if ((!wan_ifname) || (!*wan_ifname)) return -1;
	nvram_set("wan_iface", wan_ifname);	// ppp#

	// ipup receives six arguments:
	//   <interface name>  <tty device>  <speed> <local IP address> <remote IP address> <ipparam>
	//   ppp1 vlan1 0 71.135.98.32 151.164.184.87 0

	f_write_string("/tmp/ppp/link", argv[1], 0, 0);
	
	if ((p = getenv("IPREMOTE"))) {
		nvram_set("wan_gateway_get", p);
		TRACE_PT("IPREMOTE=%s\n", p);
	}

	if ((value = getenv("IPLOCAL"))) {
		_dprintf("IPLOCAL=%s\n", value);

		switch (get_wan_proto()) {
		case WP_PPPOE:
		case WP_PPP3G:
			nvram_set("wan_ipaddr_buf", nvram_safe_get("wan_ipaddr"));		// store last ip address
			nvram_set("wan_ipaddr", value);
			nvram_set("wan_netmask", "255.255.255.255");
			break;
		case WP_PPTP:
		case WP_L2TP:
			nvram_set("wan_ipaddr_buf", nvram_safe_get("ppp_get_ip"));
			break;
		}

		if (!nvram_match("ppp_get_ip", value)) {
			ifconfig(wan_ifname, IFUP, "0.0.0.0", NULL);
			nvram_set("ppp_get_ip", value);
		}

		_ifconfig(wan_ifname, IFUP, value, "255.255.255.255", (p && (*p)) ? p : NULL);
	}

	buf[0] = 0;
	if ((p = getenv("DNS1")) != NULL) strlcpy(buf, p, sizeof(buf));
	if ((p = getenv("DNS2")) != NULL) {
		if (buf[0]) strlcat(buf, " ", sizeof(buf));
		strlcat(buf, p, sizeof(buf));
	}
	nvram_set("wan_get_dns", buf);
	TRACE_PT("DNS=%s\n", buf);

	if ((value = getenv("AC_NAME"))) nvram_set("ppp_get_ac", value);
	if ((value = getenv("SRV_NAME"))) nvram_set("ppp_get_srv", value);
	if ((value = getenv("MTU"))) nvram_set("wan_run_mtu", value);

	start_wan_done(wan_ifname);

	TRACE_PT("end\n");
	return 0;
}
Exemple #8
0
// used for various testing
static int rctest_main(int argc, char *argv[])
{
	int on;

	if (argc < 3) {
		_dprintf("test what?\n");
	}
	else if (strcmp(argv[1], "rc_service")==0) {
		notify_rc(argv[2]);
	}
	else if(strcmp(argv[1], "get_phy_status")==0) {
		int mask;
		mask = atoi(argv[2]);
		TRACE_PT("debug for phy_status %x\n", get_phy_status(mask));
	}
	else if(strcmp(argv[1], "get_phy_speed")==0) {
		int mask;
		mask = atoi(argv[2]);
		TRACE_PT("debug for phy_speed %x\n", get_phy_speed(mask));
	}
	else if(strcmp(argv[1], "set_phy_ctrl")==0) {
		int mask, ctrl;
		mask = atoi(argv[2]);
		ctrl = atoi(argv[3]);
		TRACE_PT("debug for phy_speed %x\n", set_phy_ctrl(mask, ctrl));
	}
	else if(strcmp(argv[1], "handle_notifications")==0) {
		handle_notifications();
	}
	else if(strcmp(argv[1], "check_action")==0) {
		_dprintf("check: %d\n", check_action());
	}
	else if(strcmp(argv[1], "nvramhex")==0) {
		int i;
		char *nv;

		nv = nvram_safe_get(argv[2]);

		_dprintf("nvram %s(%d): ", nv, strlen(nv));
		for(i=0;i<strlen(nv);i++) {
			_dprintf(" %x", (unsigned char)*(nv+i));
		}
		_dprintf("\n");
	}
	else {
		on = atoi(argv[2]);
		_dprintf("%s %d\n", argv[1], on);

		if (strcmp(argv[1], "vlan") == 0)
		{	
			if(on) start_vlan();
			else stop_vlan();
		}
		else if (strcmp(argv[1], "lan") == 0) {
			if(on) start_lan();
			else stop_lan();
		}
		else if (strcmp(argv[1], "wl") == 0) {
			if(on) 
			{
				start_wl();
				lanaccess_wl();
			}
		}
		else if (strcmp(argv[1], "wan") == 0) {
			if(on) start_wan();
			else stop_wan();
		}
		else if (strcmp(argv[1], "firewall") == 0) {
			//if(on) start_firewall();
			//else stop_firewall();
		}
		else if (strcmp(argv[1], "watchdog") == 0) {
			if(on) start_watchdog();
			else stop_watchdog();
		}
#ifdef RTCONFIG_FANCTRL
		else if (strcmp(argv[1], "phy_tempsense") == 0) {
			if(on) start_phy_tempsense();
			else stop_phy_tempsense();
		}
#endif
#ifdef RTCONFIG_BCMWL6
#ifdef RTCONFIG_PROXYSTA
		else if (strcmp(argv[1], "psta_monitor") == 0) {
			if(on) start_psta_monitor();
			else stop_psta_monitor();
		}
#endif
#endif
		else if (strcmp(argv[1], "qos") == 0) {//qos test
			if(on){
#ifdef RTCONFIG_RALINK
				if (module_loaded("hw_nat"))
				{
					modprobe_r("hw_nat");
					sleep(1);
#if 0
					system("echo 0 > /proc/sys/net/ipv4/conf/default/force_igmp_version");
					system("echo 0 > /proc/sys/net/ipv4/conf/all/force_igmp_version");
#endif
				}
#endif
				add_iQosRules(get_wan_ifname(0));
				start_iQos();
			}
			else 
			{
#ifdef RTCONFIG_RALINK
				if (nvram_get_int("hwnat") &&
					/* TODO: consider RTCONFIG_DUALWAN case */
//					!nvram_match("wan0_proto", "l2tp") &&
//					!nvram_match("wan0_proto", "pptp") &&
//					!(nvram_get_int("fw_pt_l2tp") || nvram_get_int("fw_pt_ipsec") &&
//					(nvram_match("wl0_radio", "0") || nvram_get_int("wl0_mrate_x")) &&
//					(nvram_match("wl1_radio", "0") || nvram_get_int("wl1_mrate_x")) &&
					!module_loaded("hw_nat"))
				{
#if 0
					system("echo 2 > /proc/sys/net/ipv4/conf/default/force_igmp_version");
					system("echo 2 > /proc/sys/net/ipv4/conf/all/force_igmp_version");
#endif
					modprobe("hw_nat");
					sleep(1);
				}
#endif
				stop_iQos();
				del_iQosRules();
			}
		}
#ifdef RTCONFIG_WEBDAV
		else if (strcmp(argv[1], "webdav") == 0) {
			if(on)
				start_webdav();
		}
#endif
		else if (strcmp(argv[1], "gpiow") == 0) {
			if(argc>=4) set_gpio(atoi(argv[2]), atoi(argv[3]));
		}
		else if (strcmp(argv[1], "gpior") == 0) {
			_dprintf("%d\n", get_gpio(atoi(argv[2])));
		}
		else if (strcmp(argv[1], "gpiod") == 0) {
			if(argc>=4) gpio_dir(atoi(argv[2]), atoi(argv[3]));
		}
		else if (strcmp(argv[1], "init_switch") == 0) {
			init_switch(on);
		}
		else if (strcmp(argv[1], "set_action") == 0) {
			set_action(on);
		}
		else if (strcmp(argv[1], "pwr_usb") == 0) {
			set_pwr_usb(atoi(argv[2]));
			_dprintf("done.\n");
		}
		else {
			printf("what?\n");
		}
	}
	return 0;
}
Exemple #9
0
// used for various testing
static int rctest_main(int argc, char *argv[])
{
	int on;

	if (argc < 2) {
		_dprintf("test what?\n");
	}
	else if (strcmp(argv[1], "rc_service")==0) {
		notify_rc(argv[2]);
	}
	else if(strcmp(argv[1], "get_phy_status")==0) {
		int mask;
		mask = atoi(argv[2]);
		TRACE_PT("debug for phy_status %x\n", get_phy_status(mask));
	}
	else if(strcmp(argv[1], "get_phy_speed")==0) {
		int mask;
		mask = atoi(argv[2]);
		TRACE_PT("debug for phy_speed %x\n", get_phy_speed(mask));
	}
	else if(strcmp(argv[1], "set_phy_ctrl")==0) {
		int mask, ctrl;
		mask = atoi(argv[2]);
		ctrl = atoi(argv[3]);
		TRACE_PT("debug for phy_speed %x\n", set_phy_ctrl(mask, ctrl));
	}
	else if(strcmp(argv[1], "handle_notifications")==0) {
		handle_notifications();
	}
	else if(strcmp(argv[1], "check_action")==0) {
		_dprintf("check: %d\n", check_action());
	}
	else if(strcmp(argv[1], "nvramhex")==0) {
		int i;
		char *nv;

		nv = nvram_safe_get(argv[2]);

		_dprintf("nvram %s(%d): ", nv, strlen(nv));
		for(i=0;i<strlen(nv);i++) {
			_dprintf(" %x", (unsigned char)*(nv+i));
		}
		_dprintf("\n");
	}
	else {
		on = atoi(argv[2]);
		_dprintf("%s %d\n", argv[1], on);

		if (strcmp(argv[1], "vlan") == 0)
		{
			if(on) start_vlan();
			else stop_vlan();
		}
		else if (strcmp(argv[1], "lan") == 0) {
			if(on) start_lan();
			else stop_lan();
		}
		else if (strcmp(argv[1], "wl") == 0) {
			if(on)
			{
				start_wl();
				lanaccess_wl();
			}
		}
		else if (strcmp(argv[1], "wan") == 0) {
			if(on) start_wan();
			else stop_wan();
		}
		else if (strcmp(argv[1], "wan_port") == 0) {
			if(on) start_wan_port();
			else stop_wan_port();
		}
		else if (strcmp(argv[1], "firewall") == 0) {
			//if(on) start_firewall();
			//else stop_firewall();
		}
		else if (strcmp(argv[1], "watchdog") == 0) {
			if(on) start_watchdog();
			else stop_watchdog();
		}
#if ! (defined(RTCONFIG_QCA) || defined(RTCONFIG_RALINK))
		else if (strcmp(argv[1], "watchdog02") == 0) {
			if(on) start_watchdog02();
			else stop_watchdog02();
		}
#endif  /* ! (RTCONFIG_QCA || RTCONFIG_RALINK) */
		else if (strcmp(argv[1], "sw_devled") == 0) {
			if(on) start_sw_devled();
			else stop_sw_devled();
		}
#ifdef RTCONFIG_FANCTRL
		else if (strcmp(argv[1], "phy_tempsense") == 0) {
			if(on) start_phy_tempsense();
			else stop_phy_tempsense();
		}
#endif
#ifdef RTCONFIG_BCMWL6
#ifdef RTCONFIG_PROXYSTA
		else if (strcmp(argv[1], "psta_monitor") == 0) {
			if(on) start_psta_monitor();
			else stop_psta_monitor();
		}
#endif
#endif
#ifdef RTCONFIG_IPERF
		else if (strcmp(argv[1], "monitor") == 0) {
			if(on) start_monitor();
			else stop_monitor();
		}
#endif
		else if (strcmp(argv[1], "qos") == 0) {//qos test
			if(on){
#ifdef RTCONFIG_RALINK
				if (module_loaded("hw_nat"))
				{
					modprobe_r("hw_nat");
					sleep(1);
#if 0
					f_write_string("/proc/sys/net/ipv4/conf/default/force_igmp_version", "0", 0, 0);
					f_write_string("/proc/sys/net/ipv4/conf/all/force_igmp_version", "0", 0, 0);
#endif
				}
#endif
			add_iQosRules(get_wan_ifname(wan_primary_ifunit()));
#ifdef RTCONFIG_BWDPI
				if(nvram_get_int("qos_type") == 1) {
					start_dpi_engine_service();
					// force to rebuild firewall to avoid some loopback issue
					if (nvram_match("fw_nat_loopback", "2"))
						start_firewall(wan_primary_ifunit(), 0);
				}
				else
#endif
				start_iQos();
			}
			else
			{
#ifdef RTCONFIG_RALINK
				if (nvram_get_int("hwnat") &&
					/* TODO: consider RTCONFIG_DUALWAN case */
//					!nvram_match("wan0_proto", "l2tp") &&
//					!nvram_match("wan0_proto", "pptp") &&
//					!(nvram_get_int("fw_pt_l2tp") || nvram_get_int("fw_pt_ipsec") &&
//					(nvram_match("wl0_radio", "0") || nvram_get_int("wl0_mrate_x")) &&
//					(nvram_match("wl1_radio", "0") || nvram_get_int("wl1_mrate_x")) &&
					!module_loaded("hw_nat"))
				{
#if 0
					f_write_string("/proc/sys/net/ipv4/conf/default/force_igmp_version", "2", 0, 0);
					f_write_string("/proc/sys/net/ipv4/conf/all/force_igmp_version", "2", 0, 0);
#endif

#if defined(RTN14U) || defined(RTAC52U) || defined(RTAC51U) || defined(RTN11P) || defined(RTN300) || defined(RTN54U) || defined(RTAC1200HP) || defined(RTN56UB1) || defined(RTAC54U) || defined(RTN56UB2)
					if (!(!nvram_match("switch_wantag", "none")&&!nvram_match("switch_wantag", "")))
#endif
					{
						modprobe("hw_nat");
						sleep(1);
					}
				}
#endif
#ifdef RTCONFIG_BWDPI
				if(nvram_get_int("qos_type") == 1){
					stop_dpi_engine_service(1);
				}
				else
#endif
				stop_iQos();
				del_iQosRules();
			}
		}
#ifdef RTCONFIG_WEBDAV
		else if (strcmp(argv[1], "webdav") == 0) {
			if(on)
				start_webdav();
		}
#endif
#ifdef RTCONFIG_TUNNEL
		else if (strcmp(argv[1], "mastiff") == 0) {
			if(on)
				start_mastiff();
		}
#endif
		else if (strcmp(argv[1], "gpiow") == 0) {
			if(argc>=4) set_gpio(atoi(argv[2]), atoi(argv[3]));
		}
		else if (strcmp(argv[1], "gpior") == 0) {
			printf("%d\n", get_gpio(atoi(argv[2])));
		}
		else if (strcmp(argv[1], "gpiod") == 0) {
			if(argc>=4) gpio_dir(atoi(argv[2]), atoi(argv[3]));
		}
		else if (strcmp(argv[1], "init_switch") == 0) {
			init_switch();
		}
		else if (strcmp(argv[1], "set_action") == 0) {
			set_action(on);
		}
		else if (strcmp(argv[1], "pwr_usb") == 0) {
			set_pwr_usb(atoi(argv[2]));
			_dprintf("done.\n");
		}
		else if (strcmp(argv[1], "enc_chk") == 0) {
        		unsigned char enc_buf[ENC_WORDS_LEN];
        		unsigned char dec_buf[DATA_WORDS_LEN + 1];

			_dprintf("get enc str:[%s]\n", enc_str(argv[2], (char *) enc_buf));
			_dprintf("get dec str:[%s]\n", dec_str((char *) enc_buf, (char *) dec_buf));

			_dprintf("done(%d)\n", strcmp(argv[2], (const char *) dec_buf));
		}
#ifdef RTCONFIG_BCMFA
		else if (strcmp(argv[1], "fa_rev") == 0) {
			_dprintf("(%d) done.\n", get_fa_rev());
		}
		else if (strcmp(argv[1], "fa_dump") == 0) {
			_dprintf("(%d) done.\n", get_fa_dump());
		}
#endif
		else {
			printf("what?\n");
		}
	}
	return 0;
}