Ejemplo n.º 1
0
void start_pppoe(int pppoe_num)
{
	char idletime[20], retry_num[20], param[4];
	char username[80], passwd[80];

	char ppp_username[2][20] = { "ppp_username", "ppp_username_1" };
	char ppp_passwd[2][20] = { "ppp_passwd", "ppp_passwd_1" };
	char ppp_demand[2][20] = { "ppp_demand", "ppp_demand_1" };
	char ppp_service[2][20] = { "ppp_service", "ppp_service_1" };
	char ppp_ac[2][10] = { "ppp_ac", "ppp_ac_1" };
	// char wanip[2][15] = { "wan_ipaddr", "wan_ipaddr_1" };
	// char wanmask[2][15] = { "wan_netmask", "wan_netmask_1" };
	// char wangw[2][15] = { "wan_gateway", "wan_gateway_1" };
	char pppoeifname[15];
	char *wan_ifname = nvram_safe_get("wan_ifname");

	if (isClient()) {
		wan_ifname = getSTA();
	}

	pid_t pid;

	sprintf(pppoeifname, "pppoe_ifname%d", pppoe_num);
	nvram_set(pppoeifname, "");

	cprintf("start session %d\n", pppoe_num);
	sprintf(idletime, "%d", atoi(nvram_safe_get("ppp_idletime")) * 60);
	snprintf(retry_num, sizeof(retry_num), "%d",
		 (atoi(nvram_safe_get("ppp_redialperiod")) / 5) - 1);

	snprintf(username, sizeof(username), "%s",
		 nvram_safe_get(ppp_username[pppoe_num]));
	snprintf(passwd, sizeof(passwd), "%s",
		 nvram_safe_get(ppp_passwd[pppoe_num]));
	sprintf(param, "%d", pppoe_num);
	/*
	 * add here 
	 */
	char *pppoe_argv[] = { "pppoecd",
		wan_ifname,
		"-u", username,
		"-p", passwd,
		"-r", nvram_safe_get("wan_mtu"),  // del by honor, add by tallest.
		"-t", nvram_safe_get("wan_mtu"),
		"-i", nvram_match(ppp_demand[pppoe_num], "1") ? idletime : "0",
		"-I", "10",	// Send an LCP echo-request frame to the
				// server every 10 seconds
		"-T", "20",	// pppd will presume the server to be dead if 
				// 20 LCP echo-requests are sent without
				//-> timeout 1 min
		// receiving a valid LCP echo-reply
		"-P", param,	// PPPOE session number.
		"-N", retry_num,	// To avoid kill pppd when pppd has been
		// connecting.
#if LOG_PPPOE == 2
		"-d",
#endif
		"-C", "disconnected_pppoe",	// by tallest 0407
		NULL,		/* set default route */
		NULL, NULL,	/* pppoe_service */
		NULL, NULL,	/* pppoe_ac */
		NULL,		/* pppoe_keepalive */
		NULL
	}, **arg;
	/*
	 * Add optional arguments 
	 */
	for (arg = pppoe_argv; *arg; arg++) ;

	/*
	 * Removed by AhMan 
	 */

	if (pppoe_num == PPPOE0) {	// PPPOE0 must set default route.
		*arg++ = "-R";
	}

	if (nvram_invmatch(ppp_service[pppoe_num], "")) {
		*arg++ = "-s";
		*arg++ = nvram_safe_get(ppp_service[pppoe_num]);
	}
	if (nvram_invmatch(ppp_ac[pppoe_num], "")) {
		*arg++ = "-a";
		*arg++ = nvram_safe_get(ppp_ac[pppoe_num]);
	}
	if (nvram_match("ppp_static", "1")) {
		*arg++ = "-L";
		*arg++ = nvram_safe_get("ppp_static_ip");
	}
	// if (nvram_match("pppoe_demand", "1") || nvram_match("pppoe_keepalive", 
	// "1"))
	*arg++ = "-k";

	mkdir("/tmp/ppp", 0777);
	symlink("/sbin/rc", "/tmp/ppp/ip-up");
	symlink("/sbin/rc", "/tmp/ppp/ip-down");
	symlink("/sbin/rc", "/tmp/ppp/set-pppoepid");	// tallest 1219
	unlink("/tmp/ppp/log");

	// Clean rpppoe client files - Added by ice-man (Wed Jun 1)
	unlink("/tmp/ppp/options.pppoe");
	unlink("/tmp/ppp/connect-errors");

	_evalpid(pppoe_argv, NULL, 0, &pid);

	if (nvram_match(ppp_demand[pppoe_num], "1")) {
		// int timeout = 5;
		start_tmp_ppp(pppoe_num);

		// This should be handled in start_wan_done
		// while (ifconfig (nvram_safe_get (pppoeifname), IFUP, NULL, NULL)
		// && timeout--)
		// sleep (1);
		// route_add (nvram_safe_get ("wan_iface"), 0, "0.0.0.0",
		// "10.112.112.112",
		// "0.0.0.0");

	}
	cprintf("done. session %d\n", pppoe_num);
	return;
}
Ejemplo n.º 2
0
void start_pptp(int status)
{
	int ret;
	FILE *fp;
	char *pptp_argv[] = { "pppd",
		NULL
	};
	char username[80], passwd[80];

	stop_dhcpc();
#ifdef HAVE_PPPOE
	stop_pppoe();
#endif
	stop_vpn_modules();

	snprintf(username, sizeof(username), "%s",
		 nvram_safe_get("ppp_username"));
	snprintf(passwd, sizeof(passwd), "%s", nvram_safe_get("ppp_passwd"));

	if (status != REDIAL) {
		create_pptp_config(nvram_safe_get("pptp_server_name"),
				   username);
		/*
		 * Generate pap-secrets file 
		 */
		if (!(fp = fopen("/tmp/ppp/pap-secrets", "w"))) {
			perror("/tmp/ppp/pap-secrets");
			return;
		}
		fprintf(fp, "\"%s\" * \"%s\" *\n", username, passwd);
		fclose(fp);
		chmod("/tmp/ppp/pap-secrets", 0600);

		/*
		 * Generate chap-secrets file 
		 */
		if (!(fp = fopen("/tmp/ppp/chap-secrets", "w"))) {
			perror("/tmp/ppp/chap-secrets");
			return;
		}
		fprintf(fp, "\"%s\" * \"%s\" *\n", username, passwd);
		fclose(fp);
		chmod("/tmp/ppp/chap-secrets", 0600);

		/*
		 * Enable Forwarding 
		 */
		if ((fp = fopen("/proc/sys/net/ipv4/ip_forward", "r+"))) {
			fputc('1', fp);
			fclose(fp);
		} else
			perror("/proc/sys/net/ipv4/ip_forward");
	}
	char *wan_ifname = nvram_safe_get("wan_ifname");

	if (isClient()) {
		wan_ifname = getSTA();
	}

	nvram_set("pptp_ifname", wan_ifname);
	/*
	 * Bring up WAN interface 
	 */
	if (nvram_match("pptp_use_dhcp", "1")) {
		// pid_t pid;
		// char *wan_ipaddr;
		// char *wan_netmask;
		// char *wan_gateway;

		// char *pptp_server_ip = nvram_safe_get ("pptp_server_ip");
		// char *wan_hostname = nvram_safe_get ("wan_hostname");

		nvram_set("wan_get_dns", "");
		nvram_unset("dhcpc_done");
		//dirty hack
		start_dhcpc(wan_ifname, NULL, NULL, 1);
		int timeout;

		for (timeout = 60; !nvram_match("dhcpc_done", "1") && timeout > 0; --timeout) {	/* wait for info from dhcp server */
			sleep(1);
		}
		stop_dhcpc();	/* we don't need dhcp client anymore */
		create_pptp_config(nvram_safe_get("pptp_server_ip"), username);

	} else {
		ifconfig(wan_ifname, IFUP, nvram_safe_get("wan_ipaddr"),
			 nvram_safe_get("wan_netmask"));
		struct dns_lists *dns_list = NULL;
		dns_to_resolv();
		dns_list = get_dns_list();
		int i = 0;

		if (dns_list) {
			for (i = 0; i < dns_list->num_servers; i++)
				route_add(wan_ifname, 0,
					  dns_list->dns_server[i],
					  nvram_safe_get("pptp_wan_gateway"),
					  "255.255.255.255");
		}
		route_add(wan_ifname, 0, "0.0.0.0",
			  nvram_safe_get("pptp_wan_gateway"), "0.0.0.0");
		char pptpip[64];
		getIPFromName(nvram_safe_get("pptp_server_name"), pptpip);
		route_del(wan_ifname, 0, "0.0.0.0",
			  nvram_safe_get("pptp_wan_gateway"), "0.0.0.0");
		if (dns_list) {
			for (i = 0; i < dns_list->num_servers; i++)
				route_del(wan_ifname, 0,
					  dns_list->dns_server[i],
					  nvram_safe_get("pptp_wan_gateway"),
					  "255.255.255.255");
			free(dns_list);
		}
		
		nvram_set("pptp_server_ip", pptpip);
		if (!nvram_match("pptp_wan_gateway", "0.0.0.0"))
			route_add(wan_ifname, 0,
				  nvram_safe_get("pptp_server_ip"),
				  nvram_safe_get("pptp_wan_gateway"),
				  "255.255.255.255");
	}
	ret = _evalpid(pptp_argv, NULL, 0, NULL);

	if (nvram_match("ppp_demand", "1")) {
		/*
		 * Trigger Connect On Demand if user press Connect button in Status
		 * page 
		 */
		if (nvram_match("action_service", "start_pptp")
		    || nvram_match("action_service", "start_l2tp")) {
			start_force_to_dial();
			// force_to_dial(nvram_safe_get("action_service"));
			nvram_unset("action_service");
		}
		/*
		 * Trigger Connect On Demand if user ping pptp server 
		 */
		else {
			eval("listen", nvram_safe_get("lan_ifname"));
		}
	}
	stop_wland();
	start_wshaper();
	start_wland();
	cprintf("done\n");
	return;
}
Ejemplo n.º 3
0
void start_dhcpfwd(void)
{
	if (getWET())		// dont 
		// start 
		// any 
		// dhcp 
		// services 
		// in 
		// bridge 
		// mode
	{
		nvram_set("lan_proto", "static");
		return;
	}
#ifdef HAVE_DHCPFORWARD
	FILE *fp;

	if (nvram_match("dhcpfwd_enable", "1")) {
		mkdir("/tmp/dhcp-fwd", 0700);
		mkdir("/var/run/dhcp-fwd", 0700);
		fp = fopen("/tmp/dhcp-fwd/dhcp-fwd.conf", "wb");
		fprintf(fp, "user		root\n"
			"group		root\n"
			"chroot		/var/run/dhcp-fwd\n"
			"logfile		/tmp/dhcp-fwd.log\n"
			"loglevel	1\n"
			"pidfile		/var/run/dhcp-fwd.pid\n"
			"ulimit core	0\n"
			"ulimit stack	64K\n"
			"ulimit data	32K\n" "ulimit rss	200K\n" "ulimit nproc	0\n" "ulimit nofile	0\n" "ulimit as	0\n" "if	%s	true	false	true\n", nvram_safe_get("lan_ifname"));

		char *wan_proto = nvram_safe_get("wan_proto");
		char *wan_ifname = nvram_safe_get("wan_ifname");

		if (getSTA()) {
			wan_ifname = getSTA();	// returns eth1/eth2 for broadcom and 
			// ath0 for atheros
		}
#ifdef HAVE_PPPOE
		if (strcmp(wan_proto, "pppoe") == 0) {
			fprintf(fp, "if	ppp0	false	true	true\n");
		}
#else
		if (0) {
		}
#endif
		else if (getWET()) {
			// nothing
		} else if (strcmp(wan_proto, "dhcp") == 0 || strcmp(wan_proto, "static") == 0) {
			fprintf(fp, "if	%s	false	true	true\n", wan_ifname);
		}
#ifdef HAVE_3G
		else if (strcmp(wan_proto, "3g") == 0 && nvram_match("3gdata", "qmi")) {
			fprintf(fp, "if	wwan0	false	true	true\n");
		} else if (strcmp(wan_proto, "3g") == 0) {
			fprintf(fp, "if	ppp0	false	true	true\n");
		}
#endif
#ifdef HAVE_PPTP
		else if (strcmp(wan_proto, "pptp") == 0) {
			fprintf(fp, "if	ppp0	false	true	true\n");
		}
#endif
#ifdef HAVE_IPETH
		else if (strcmp(wan_proto, "iphone") == 0) {
			fprintf(fp, "if	iph0	false	true	true\n");
		}
#endif
#ifdef HAVE_L2TP
		else if (strcmp(wan_proto, "l2tp") == 0) {
			fprintf(fp, "if	ppp0	false	true	true\n");
		}
#endif
#ifdef HAVE_HEARTBEAT
		else if (strcmp(wan_proto, "heartbeat") == 0) {
			fprintf(fp, "if	ppp0	false	true	true\n");
		}
#endif
		else {
			fprintf(fp, "if	%s	false	true	true\n", wan_ifname);
		}

		fprintf(fp, "name	%s	ws-c\n" "server	ip	%s\n", nvram_safe_get("lan_ifname"), nvram_safe_get("dhcpfwd_ip"));
		fclose(fp);
		eval("dhcpfwd", "-c", "/tmp/dhcp-fwd/dhcp-fwd.conf");
		syslog(LOG_INFO, "dhcpfwd : dhcp forwarder daemon successfully started\n");
		return;
	}
#endif
#ifdef HAVE_DHCPRELAY
	if (nvram_match("dhcpfwd_enable", "1")) {
		eval("dhcrelay", "-i", nvram_safe_get("lan_ifname"), nvram_safe_get("dhcpfwd_ip"));
		syslog(LOG_INFO, "dhcrelay : dhcp relay successfully started\n");
	}
#endif
	return;
}