コード例 #1
0
ファイル: net_wan6.c プロジェクト: PterX/rt-n56u
void store_ip6rd_from_dhcp(const char *env_value, const char *prefix)
{
	int i;
	char tmp[100];
	char ip6rd[64];
	char addr6[INET6_ADDRSTRLEN];
	char *value, *values[4];

	// "32 128 FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF 255.255.255.255 "

	if (nvram_match("ip6_6rd_dhcp", "0"))
		return;

	strncpy(ip6rd, env_value, sizeof(ip6rd));
	value = ip6rd;
	for (i = 0; i < 4 && value; i++)
		values[i] = strsep(&value, " ");
	if (i == 4)
	{
		snprintf(addr6, sizeof(addr6), "%s/%s", values[2], values[1]);
		nvram_set_temp(strcat_r(prefix, "addr6", tmp), addr6);
		nvram_set_temp(strcat_r(prefix, "6rd_size", tmp), values[0]);
		nvram_set_temp(strcat_r(prefix, "6rd_relay", tmp), values[3]);
	}
}
コード例 #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);
}
コード例 #3
0
ファイル: asuscomm.c プロジェクト: PterX/rt-n56u
static int response_register(http_trans_t *trans, ddns_info_t *UNUSED(info), ddns_alias_t *UNUSED(alias))
{
	char *p, *p_rsp, *ret_key;
	char ret_buf[64], domain[256] = {0};

	ret_key = "ddns_return_code";

	p_rsp = trans->p_rsp_body;

	if ((p = strchr(p_rsp, '|')) && (p = strchr(++p, '|')))
		sscanf(p, "|%255[^|\r\n]", domain);

	if (trans->status >= 500 && trans->status < 600) {
		nvram_set_temp(ret_key, "unknown_error");
		return RC_DYNDNS_RSP_RETRY_LATER;
	}

	snprintf(ret_buf, sizeof(ret_buf), "%s,%d", "register", trans->status);
	nvram_set_temp(ret_key, ret_buf);

	switch (trans->status) {
	case 200:		/* registration success */
	case 220:		/* registration same domain success*/
		return RC_OK;
	case 203:		/* registration failed */
		logit(LOG_WARNING, "Domain already in use, suggested domain '%s'", domain);
		return RC_DYNDNS_RSP_NOTOK;
	case 230:		/* registration new domain success */
		logit(LOG_WARNING, "Registration success, previous domain '%s'", domain);
		return RC_OK;
	case 233:		/* registration failed */
		logit(LOG_WARNING, "Domain already in use, current domain '%s'", domain);
		return RC_DYNDNS_RSP_NOTOK;
	case 297:		/* invalid hostname */
	case 298:		/* invalid domain name */
	case 299:		/* invalid ip format */
	case 401:		/* authentication failure */
	case 407:		/* proxy authentication required */
		return RC_DYNDNS_RSP_NOTOK;
	}

	if (trans->status < 500)		/* shutdown */
		nvram_set_temp(ret_key, "time_out");

	return RC_DYNDNS_RSP_NOTOK;
}
コード例 #4
0
ファイル: vpn_client.c プロジェクト: jing-git/rt-n56u
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);
	}
}
コード例 #5
0
ファイル: vpn_openvpn.c プロジェクト: PterX/rt-n56u
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");
}
コード例 #6
0
ファイル: net_lan6.c プロジェクト: schidler/flyzjhz-rt-n56u
int store_lan_addr6(char *lan_addr6_new)
{
	char *lan_addr6_old;
	
	if (!lan_addr6_new)
		return 0;
	
	if (!(*lan_addr6_new))
		return 0;
	
	lan_addr6_old = nvram_safe_get("lan_addr6");
	if (strcmp(lan_addr6_new, lan_addr6_old) != 0) {
		nvram_set_temp("lan_addr6", lan_addr6_new);
		return 1;
	}

	return 0;
}
コード例 #7
0
ファイル: vpn_client.c プロジェクト: jing-git/rt-n56u
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;
}
コード例 #8
0
ファイル: net_lan6.c プロジェクト: schidler/flyzjhz-rt-n56u
void reset_lan6_vars(void)
{
	struct in6_addr addr6;
	char addr6s[INET6_ADDRSTRLEN] = {0};
	char *lan_addr6;
	int lan_size6;
	
	if (is_lan_addr6_static() == 1)
	{
		lan_addr6 = nvram_safe_get("ip6_lan_addr");
		lan_size6 = nvram_get_int("ip6_lan_size");
		if (*lan_addr6) {
			memset(&addr6, 0, sizeof(addr6));
			ipv6_from_string(lan_addr6, &addr6);
			inet_ntop(AF_INET6, &addr6, addr6s, INET6_ADDRSTRLEN);
			if (lan_size6 < 48 || lan_size6 > 80)
				lan_size6 = 64;
			sprintf(addr6s, "%s/%d", addr6s, lan_size6);
		}
	}

	nvram_set_temp("lan_addr6", addr6s);
}
コード例 #9
0
ファイル: rc.c プロジェクト: clockzhong/RouterN56U
static void
set_wan0_vars(void)
{
	struct nvram_pair *np;
	char *v;
	char tmp[100], prefix[16];

	snprintf(prefix, sizeof(prefix), "wan%d_", 0);

	/* Write through to wan0_ variable set */
	for (np = router_defaults; np->name; np++) {
		if (!strncmp(np->name, "wan_", 4)) {
			if (nvram_get(strcat_r(prefix, &np->name[4], tmp)))
				continue;
			v = nvram_get(np->name);
			nvram_set_temp(tmp, v ? v : np->value);
		}
	}

	set_wan_unit_value(0, "unit", "0");
	set_wan_unit_value(0, "primary", "1");
	set_wan_unit_value(0, "ifname", IFNAME_WAN);
}
コード例 #10
0
ファイル: lpd.c プロジェクト: schidler/flyzjhz-rt-n56u
int main(int argc, char *argv[])
{
    int                 sockfd , clisockfd;
    unsigned int        clilen;
    int                 childpid;
    struct sockaddr_in  serv_addr,cli_addr;
    int err_select;//JY1113

#ifdef LPR_with_ASUS//JY1112
    int 		LPRflag = 0;
    fd_set		rfds, afds;
    int			nfds;
    int			sockfd_ASUS;
    unsigned int        clilen_ASUS;
    int                 childpid_ASUS;
    struct sockaddr_in  serv_addr_ASUS,cli_addr_ASUS;
#endif
#ifdef Raw_Printing_with_ASUS  //Lisa
	int		netfd, fd, clientlen, one = 1;
	struct sockaddr_in	netaddr, client;
#endif
	int lock;
	int pid = 0;
	FILE *fp;

	fp = fopen("/var/run/lpdparent.pid", "r");
	if (fp) {
		fscanf(fp, "%d", &pid);
		fclose(fp);
	}

	if ((pid > 1) && (kill(pid, 0) == 0 || errno != ESRCH)) {
		syslog(LOGOPTS, "another lpd daemon exists!!\n");
		exit(0);
	}

	update_pidfile();

    //Initial the server the not busy
    lptstatus.busy = FALSE;

    sigset_t sigs_to_catch;
    sigemptyset(&sigs_to_catch);
    sigaddset(&sigs_to_catch, SIGCLD);
    sigaddset(&sigs_to_catch, SIGINT);
    sigaddset(&sigs_to_catch, SIGQUIT);
    sigaddset(&sigs_to_catch, SIGKILL);
    sigaddset(&sigs_to_catch, SIGUSR2);
    sigprocmask(SIG_UNBLOCK, &sigs_to_catch, NULL);

    //Setup the signal handler
    signal(SIGCLD, sig_child); 
    signal(SIGINT, sig_cleanup); 
    signal(SIGQUIT, sig_cleanup); 
    signal(SIGKILL, sig_cleanup);
    signal(SIGUSR2, sig_remove);//JY1110 
    
    if((sockfd = socket(AF_INET,SOCK_STREAM,0)) < 0 )
    {
        syslog(LOGOPTS, "can't open stream socket: %m");
        exit(0);
    }
    
    bzero((char *)&serv_addr , sizeof(serv_addr));
    serv_addr.sin_family        = AF_INET;
    serv_addr.sin_addr.s_addr   = htonl(INADDR_ANY);
    serv_addr.sin_port          = htons(PNT_SVR_PORT_LPR);

    
    if(bind(sockfd,(struct sockaddr *)&serv_addr , sizeof(serv_addr)) < 0 )
    {
        syslog(LOGOPTS, "can't bind socket with port %d: %m", PNT_SVR_PORT_LPR);
        exit(0);
    }
    /*JY1111*/
    int windowsize=2920;
    setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, (char *)&windowsize, sizeof(windowsize));
    int no_delay=1;
    setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &no_delay, sizeof(no_delay));	// by Jiahao. 20080808.

    listen(sockfd , 15);

#ifdef Raw_Printing_with_ASUS //Lisa
	if ((netfd = socket(AF_INET, SOCK_STREAM, IPPROTO_IP)) < 0)
	{
		syslog(LOGOPTS, "cannot open stream socket for raw printing: %m\n");
		exit(1);
	}
	if (setsockopt(netfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0)
	{
		syslog(LOGOPTS, "cannot setsocketopt for raw printing: %m\n");
		exit(1);
	}
	netaddr.sin_family = AF_INET;
	netaddr.sin_port = htons(BASEPORT);
	netaddr.sin_addr.s_addr = htonl(INADDR_ANY);
	memset(netaddr.sin_zero, 0, sizeof(netaddr.sin_zero));
	if (bind(netfd, (struct sockaddr*) &netaddr, sizeof(netaddr)) < 0)
	{
		syslog(LOGOPTS, "cannot bind socket with port %d for raw printing: %m\n", BASEPORT);
		exit(1);
	}
	if (listen(netfd, 5) < 0)
	{
		syslog(LOGOPTS, "cannot listen socket for raw printing: %m\n");
		exit(1);
	}
	//clientlen = sizeof(client);
	//memset(&client, 0, sizeof(client));
#endif

#ifdef LPR_with_ASUS//JY1112
	if((sockfd_ASUS = socket(AF_INET,SOCK_STREAM,0)) < 0 )
	{
	        syslog(LOG_ERR, "can't open stream socket for LPR: %m");
	        exit(0);
	}
    	bzero((char *)&serv_addr_ASUS , sizeof(serv_addr_ASUS));
    	serv_addr_ASUS.sin_family        = AF_INET;
    	serv_addr_ASUS.sin_addr.s_addr   = htonl(INADDR_ANY);
    	serv_addr_ASUS.sin_port          = htons(PNT_SVR_PORT_ASUS);

    	if(bind(sockfd_ASUS,(struct sockaddr *)&serv_addr_ASUS , sizeof(serv_addr_ASUS)) < 0 )
    	{
		syslog(LOG_ERR, "can't bind socket for LPR: %m");
		exit(0);
   	}

    	setsockopt(sockfd_ASUS, SOL_SOCKET, SO_RCVBUF, (char *)&windowsize, sizeof(windowsize));

    	listen(sockfd_ASUS , 15);
    
    	/*set the fds*/
    	nfds=MAX(sockfd, sockfd_ASUS);
    	FD_ZERO(&afds);
#endif
    
    while(TRUE)
    {
	//if (busy) syslog(LOG_NOTICE, "busying %d %d\n", lptstatus.busy, busy);

	lock = file_lock("printer");				// by Jiahao for U2EC. 20080808.
	if (lptstatus.busy==FALSE && nvram_invmatch("MFP_busy", "2"))
	{
		busy=FALSE;
		nvram_set_int_temp("MFP_busy", 0);

		nvram_set_temp("u2ec_busyip", "");
	}
	file_unlock(lock);

#ifdef Raw_Printing_with_ASUS //Lisa
	FD_SET(netfd, &afds);
#endif
#ifdef LPR_with_ASUS//JY1112
	FD_SET(sockfd, &afds);
	FD_SET(sockfd_ASUS, &afds);
	memcpy(&rfds, &afds, sizeof(rfds));

	if((err_select=select(nfds+1, &rfds, (fd_set *)0, (fd_set *)0, (struct timeval *)0 )) < 0) 
	{
//JY1120	printf("select error on sockfd: error=%d\n", errno);
		/**/
//		printf("sockfd_FD_ISSET=%d\n", FD_ISSET(sockfd, &rfds));
//JY1120		printf("sockfd_ASUS FD_ISSET=%d\n", FD_ISSET(sockfd_ASUS, &rfds));
		/**/
//		if(errno != 4)//JY1113: delete
		//syslog(LOG_NOTICE, "select error %d\n", err_select);
		continue;
	}
#endif
        clilen = sizeof(cli_addr);

	if(FD_ISSET(sockfd_ASUS, &rfds))
	{
		LPRflag = 0;
		clisockfd   = accept(sockfd_ASUS,(struct sockaddr *)&cli_addr, &clilen);
	}
#ifdef LPR_with_ASUS//JY1112 
	else if(FD_ISSET(sockfd, &rfds))
	{
		LPRflag = 1;
		clisockfd   = accept(sockfd,(struct sockaddr *)&cli_addr, &clilen);
	}
#endif
#ifdef Raw_Printing_with_ASUS //Lisa
//	else if(FD_ISSET(netfd, &rfds) && busy==FALSE)
	else if(FD_ISSET(netfd, &rfds))
	{
		lock = file_lock("printer");	// by Jiahao for U2EC. 20080808.
		if (nvram_match("MFP_busy", "0"))
		{
			file_unlock(lock);
			LPRflag = 2;
			clisockfd = accept(netfd, (struct sockaddr*) &cli_addr, &clilen);
		}
		else
		{
			file_unlock(lock);
			sleep(2);
			continue;
		}
	}
#endif
	else
        {
		//syslog(LOG_NOTICE, "No select\n");
		sleep(2);
		continue;
	}

	strcpy(clientaddr , inet_ntoa(cli_addr.sin_addr));
	
	if(clisockfd < 0)
        {
	     //syslog(LOG_NOTICE, "LPD error: No clisockfd %d\n", LPRflag);
             continue;
        }

	lock = file_lock("printer");
//	if (busy!=FALSE)	/* 2004/09/10 by Joey, process nack in parent for LPR and Remote Prot */
	if (nvram_invmatch("MFP_busy", "0"))		// by Jiahao for U2EC. 20080808.
	{
		file_unlock(lock);
		//syslog(LOG_NOTICE, "Printing others 1 %d %d\n", LPRflag, clisockfd);
		if (LPRflag==0) processReq(clisockfd);
		else if (LPRflag==1) processReq_LPR(clisockfd, 0);
		//syslog(LOG_NOTICE, "Printing others %d %d\n", LPRflag, clisockfd);
		close(clisockfd);
		// For Raw printing, don't resonse to client while busy
		sleep(5);
		continue;
	}

	nvram_set_int_temp("MFP_busy", 1);

	if (nvram_match("lan_ipaddr_t", ""))
		nvram_set_temp("u2ec_busyip", nvram_safe_get("lan_ipaddr"));
	else
		nvram_set_temp("u2ec_busyip", nvram_safe_get("lan_ipaddr_t"));

	file_unlock(lock);

        if( (childpid = fork() ) < 0)
        {
        }
        else if(childpid == 0) 
        {
		//syslog(LOG_NOTICE, "Printing %d\n", LPRflag);

		if(LPRflag==0) processReq(clisockfd); 
#ifdef LPR_with_ASUS//JY1114 
		else if(LPRflag==1) processReq_LPR(clisockfd, 1);
#endif
#ifdef Raw_Printing_with_ASUS //Lisa
		else if(LPRflag == 2) processReq_Raw(clisockfd);
#endif
		close(sockfd);
		close(sockfd_ASUS);
#ifdef Raw_Printing_with_ASUS
		close(netfd);
#endif
        	exit(0);
        }
              
	//syslog(0, "Printing Process %d %d %d\n", busy, lptstatus.busy, childpid);

        //parents process goes on here
        //remark PRINT("fork -- childpid %d\n",childpid);

	if(lptstatus.busy == FALSE)
	{
		lptstatus.busy = TRUE;
//		busy = TRUE;				// remarked by Jiahao for U2EC. 20080808.
		strcpy(lptstatus.addr , inet_ntoa(cli_addr.sin_addr));
		lptstatus.pid = childpid;
	}

        close(clisockfd);
    }

}
コード例 #11
0
ファイル: rc.c プロジェクト: clockzhong/RouterN56U
static void
nvram_convert_misc_values(void)
{
	char buff[64];
	int sw_mode;

	/* check router mode */
	sw_mode = nvram_get_int("sw_mode");
	if (sw_mode == 1) {
		/* Internet gateway mode */
		nvram_set_int("wan_nat_x", 1);
		nvram_set("wan_route_x", "IP_Routed");
	} else if (sw_mode == 4) {
		/* Pure router mode */
		nvram_set_int("wan_nat_x", 0);
		nvram_set("wan_route_x", "IP_Routed");
	} else if (sw_mode == 3) {
		/* AP mode (Ethernet convertor) */
		nvram_set_int("wan_nat_x", 0);
		nvram_set("wan_route_x", "IP_Bridged");
	} else {
		nvram_set_int("sw_mode", 1);
		nvram_set_int("wan_nat_x", 1);
		nvram_set("wan_route_x", "IP_Routed");
	}

	if (strlen(nvram_wlan_get("wl", "ssid")) < 1)
		nvram_wlan_set("wl", "ssid", DEF_WLAN_5G_SSID);

	if (strlen(nvram_wlan_get("rt", "ssid")) < 1)
		nvram_wlan_set("rt", "ssid", DEF_WLAN_5G_SSID);

	memset(buff, 0, sizeof(buff));
	char_to_ascii(buff, nvram_wlan_get("wl", "ssid"));
	nvram_wlan_set("wl", "ssid2", buff);

	memset(buff, 0, sizeof(buff));
	char_to_ascii(buff, nvram_wlan_get("rt", "ssid"));
	nvram_wlan_set("rt", "ssid2", buff);

	if (strlen(nvram_safe_get("wl_wpa_mode")) < 1)
		nvram_set_int("wl_wpa_mode", 0);

	if (strlen(nvram_safe_get("wl_gmode")) < 1)
		nvram_set_int("wl_gmode", 2); // a/n Mixed

	if (strlen(nvram_safe_get("rt_gmode")) < 1)
		nvram_set_int("rt_gmode", 2); // b/g/n Mixed

	if (nvram_get_int("wl_HT_BW") > 1)
		nvram_set_int("wl_HT_BW", 1);

	if (nvram_get_int("rt_HT_BW") > 1)
		nvram_set_int("rt_HT_BW", 1);

	if (nvram_get_int("wl_stream_tx") > BOARD_NUM_ANT_5G_TX)
		nvram_set_int("wl_stream_tx", BOARD_NUM_ANT_5G_TX);

	if (nvram_get_int("wl_stream_rx") > BOARD_NUM_ANT_5G_RX)
		nvram_set_int("wl_stream_rx", BOARD_NUM_ANT_5G_RX);

	if (nvram_get_int("rt_stream_tx") > BOARD_NUM_ANT_2G_TX)
		nvram_set_int("rt_stream_tx", BOARD_NUM_ANT_2G_TX);

	if (nvram_get_int("rt_stream_rx") > BOARD_NUM_ANT_2G_RX)
		nvram_set_int("rt_stream_rx", BOARD_NUM_ANT_2G_RX);

	nvram_set_temp("ntpc_counter", "0000000000");
	nvram_set_temp("login_timestamp", "0000000000");

	nvram_set_int_temp("networkmap_fullscan", 0);
	nvram_set_int_temp("link_internet", 2);
	nvram_set_int_temp("link_wan", 0);

	nvram_set_int_temp("reload_svc_wl", 0);
	nvram_set_int_temp("reload_svc_rt", 0);

	nvram_set_int_temp("usb_hotplug_ms", 0);
	nvram_set_int_temp("usb_hotplug_lp", 0);
	nvram_set_int_temp("usb_hotplug_md", 0);
	nvram_set_int_temp("usb_unplug_lp", 0);
	nvram_set_int_temp("usb_unplug_md", 0);
	nvram_set_int_temp("usb_opt_start", 0);

	nvram_set_int_temp("l2tp_wan_t", 0);
	nvram_set_int_temp("l2tp_cli_t", 0);
	nvram_set_int_temp("l2tp_srv_t", 0);
	nvram_set_int_temp("vpnc_state_t", 0);
	nvram_set_temp("deferred_wanup_t", "0000000000");
	nvram_set_temp("vpnc_dns_t", "");
	nvram_set_temp("viptv_ifname", "");

	/* setup wan0 variables */
	set_wan0_vars();
	set_wan_unit_value(0, "uptime", "0000000000");
	set_wan_unit_value(0, "dltime", "0000000000");
	set_wan_unit_value(0, "bytes_rx", "00000000000000000000");
	set_wan_unit_value(0, "bytes_tx", "00000000000000000000");
	set_wan_unit_value(0, "ifname_t", "");
	set_usb_modem_dev_wan(0, 0);
	reset_wan_vars();

	/* setup lan variables */
	reset_lan_vars();
	reset_lan_temp();

	time_zone_x_mapping();
}
コード例 #12
0
ファイル: nvram.c プロジェクト: jing-git/rt-n56u
/* NVRAM utility */
int
main(int argc, char **argv)
{
	char *name, *value;
	int ret = 0;

	/* Skip program name */
	--argc;
	++argv;

	if (!*argv)
		usage();

	/* Process the remaining arguments. */
	for (; *argv; argv++) {
		if (!strcmp(*argv, "get")) {
			if (*++argv) {
				if ((value = nvram_get(*argv)))
					puts(value);
			}
		}
		else if (!strcmp(*argv, "settmp")) {
			if (*++argv) {
				char buf[1024];
				strncpy(value = buf, *argv, sizeof(buf)-1);
				name = strsep(&value, "=");
				nvram_set_temp(name, value);
			}
		}
		else if (!strcmp(*argv, "set")) {
			if (*++argv) {
				char buf[1024];
				strncpy(value = buf, *argv, sizeof(buf)-1);
				name = strsep(&value, "=");
				nvram_set(name, value);
			}
		}
		else if (!strcmp(*argv, "unset")) {
			if (*++argv)
				nvram_unset(*argv);
		}
		else if (!strcmp(*argv, "clear")) {
			nvram_clear();
		}
		else if (!strcmp(*argv, "commit")) {
			nvram_commit();
			break;
		}
		else if (!strcmp(*argv, "save")) {
			if (*++argv)
				ret |= nvram_save(*argv);
			break;
		}
		else if (!strcmp(*argv, "restore")) {
			if (*++argv)
				ret |= nvram_restore(*argv);
			break;
		}
		else if (!strcmp(*argv, "show")) {
			ret |= nvram_show(0);
			break;
		}
		else if (!strcmp(*argv, "showall")) {
			ret |= nvram_show(1);
			break;
		}
		if (!*argv)
			break;
	}

	return ret;
}
コード例 #13
0
ファイル: rc.c プロジェクト: ff94315/rt-n56u
static void
nvram_convert_misc_values(void)
{
	char buff[64];
	int sw_mode;
#if defined (BOARD_GPIO_BTN_ROUTER)
	int i_router_switch = BTN_PRESSED;

	if (cpu_gpio_get_pin(BOARD_GPIO_BTN_ROUTER, &i_router_switch) >= 0) {
		if (i_router_switch != BTN_PRESSED)
			nvram_set_int("sw_mode", 3);
	}
#endif

	/* check router mode */
	sw_mode = nvram_get_int("sw_mode");
	if (sw_mode == 1) {
		/* Internet gateway mode */
		nvram_set_int("wan_nat_x", 1);
		nvram_set("wan_route_x", "IP_Routed");
	} else if (sw_mode == 4) {
		/* Pure router mode */
		nvram_set_int("wan_nat_x", 0);
		nvram_set("wan_route_x", "IP_Routed");
	} else if (sw_mode == 3) {
		/* AP mode (Ethernet convertor) */
		nvram_set_int("wan_nat_x", 0);
		nvram_set("wan_route_x", "IP_Bridged");
	} else {
		sw_mode = 1;
		nvram_set_int("sw_mode", 1);
		nvram_set_int("wan_nat_x", 1);
		nvram_set("wan_route_x", "IP_Routed");
	}

#if defined (BOARD_GPIO_LED_ROUTER)
	if (sw_mode != 3)
		LED_CONTROL(BOARD_GPIO_LED_ROUTER, LED_ON);
#endif

#if BOARD_HAS_5G_RADIO
	if (strlen(nvram_wlan_get(1, "ssid")) < 1)
		nvram_wlan_set(1, "ssid", DEF_WLAN_5G_SSID);

	memset(buff, 0, sizeof(buff));
	char_to_ascii(buff, nvram_wlan_get(1, "ssid"));
	nvram_wlan_set(1, "ssid2", buff);

	if (strlen(nvram_wlan_get(1, "wpa_mode")) < 1)
		nvram_wlan_set_int(1, "wpa_mode", 0);

#if BOARD_HAS_5G_11AC
	if (strlen(nvram_wlan_get(1, "gmode")) < 1)
		nvram_wlan_set_int(1, "gmode", 4); // a/n/ac Mixed

	if (nvram_wlan_get_int(1, "HT_BW") > 2)
		nvram_wlan_set_int(1, "HT_BW", 2);
#else
	if (strlen(nvram_wlan_get(1, "gmode")) < 1)
		nvram_wlan_set_int(1, "gmode", 2); // a/n Mixed

	if (nvram_wlan_get_int(1, "HT_BW") > 1)
		nvram_wlan_set_int(1, "HT_BW", 1);
#endif

	if (nvram_wlan_get_int(1, "stream_tx") > BOARD_NUM_ANT_5G_TX)
		nvram_wlan_set_int(1, "stream_tx", BOARD_NUM_ANT_5G_TX);

	if (nvram_wlan_get_int(1, "stream_rx") > BOARD_NUM_ANT_5G_RX)
		nvram_wlan_set_int(1, "stream_rx", BOARD_NUM_ANT_5G_RX);
#endif

	if (strlen(nvram_wlan_get(0, "ssid")) < 1)
		nvram_wlan_set(0, "ssid", DEF_WLAN_2G_SSID);

	memset(buff, 0, sizeof(buff));
	char_to_ascii(buff, nvram_wlan_get(0, "ssid"));
	nvram_wlan_set(0, "ssid2", buff);

	if (strlen(nvram_wlan_get(0, "gmode")) < 1)
		nvram_wlan_set_int(0, "gmode", 2); // b/g/n Mixed

	if (nvram_wlan_get_int(0, "HT_BW") > 1)
		nvram_wlan_set_int(0, "HT_BW", 1);

	if (nvram_wlan_get_int(0, "stream_tx") > BOARD_NUM_ANT_2G_TX)
		nvram_wlan_set_int(0, "stream_tx", BOARD_NUM_ANT_2G_TX);

	if (nvram_wlan_get_int(0, "stream_rx") > BOARD_NUM_ANT_2G_RX)
		nvram_wlan_set_int(0, "stream_rx", BOARD_NUM_ANT_2G_RX);

	nvram_set_temp("ntpc_counter", "0000000000");
	nvram_set_temp("login_timestamp", "0000000000");

	nvram_set_int_temp("networkmap_fullscan", 0);
	nvram_set_int_temp("link_internet", 2);
	nvram_set_int_temp("link_wan", 0);

	nvram_set_int_temp("reload_svc_wl", 0);
	nvram_set_int_temp("reload_svc_rt", 0);

	nvram_set_int_temp("usb_hotplug_ms", 0);
	nvram_set_int_temp("usb_hotplug_lp", 0);
	nvram_set_int_temp("usb_hotplug_md", 0);
	nvram_set_int_temp("usb_unplug_lp", 0);
	nvram_set_int_temp("usb_unplug_md", 0);
	nvram_set_int_temp("usb_opt_start", 0);

	nvram_set_int_temp("l2tp_wan_t", 0);
	nvram_set_int_temp("l2tp_cli_t", 0);
	nvram_set_int_temp("l2tp_srv_t", 0);
	nvram_set_int_temp("vpnc_state_t", 0);
	nvram_set_temp("deferred_wanup_t", "0000000000");
	nvram_set_temp("vpnc_dns_t", "");
	nvram_set_temp("vpnc_dom_t", "");
	nvram_set_temp("viptv_ifname", "");

	nvram_set_temp(RSTATS_NVKEY_24, (sw_mode != 3) ? IFDESC_WAN : IFDESC_LAN);
	nvram_set_temp(RSTATS_NVKEY_DM, IFDESC_WAN);

	/* setup wan0 variables */
	set_wan0_vars();
	set_wan_unit_value(0, "uptime", "0000000000");
	set_wan_unit_value(0, "dltime", "0000000000");
	set_wan_unit_value(0, "bytes_rx", "00000000000000000000");
	set_wan_unit_value(0, "bytes_tx", "00000000000000000000");
	set_wan_unit_value(0, "ifname_t", "");
	set_usb_modem_dev_wan(0, 0);
	reset_wan_vars();

	/* setup lan variables */
	reset_lan_vars();
	reset_lan_temp();

	time_zone_x_mapping();
}
コード例 #14
0
ファイル: vpn_client.c プロジェクト: jing-git/rt-n56u
int
start_vpn_client(void)
{
	FILE *fp;
	int i_type, i_mppe, i_auth;
	char *vpnc_peer, *vpnc_opt, tmp[256];

	if (nvram_invmatch("vpnc_enable", "1") || get_ap_mode())
		return 1;

	vpnc_peer = nvram_safe_get("vpnc_peer");
	if (strlen(vpnc_peer) < 1) {
		logmessage(VPNC_LOG_NAME, "Unable to start - remote server host is not defined!");
		return 1;
	}

	nvram_set_temp("vpnc_dns_t", "");
	nvram_set_temp("vpnc_dom_t", "");
	nvram_set_int_temp("vpnc_state_t", 0);

	i_type = nvram_get_int("vpnc_type");
#if defined(APP_OPENVPN)
	if (i_type == 2)
		return start_openvpn_client();
#endif
	vpnc_opt = VPN_CLIENT_PPPD_OPTIONS;

	mkdir("/tmp/ppp", 0777);
	symlink("/sbin/rc", VPNC_PPP_UP_SCRIPT);
	symlink("/sbin/rc", VPNC_PPP_DW_SCRIPT);

	i_auth = nvram_get_int("vpnc_auth");
	i_mppe = nvram_get_int("vpnc_mppe");

	// Create options for pppd
	if (!(fp = fopen(vpnc_opt, "w"))) {
		return -1;
	}
	
	fprintf(fp, "noauth\n");
	fprintf(fp, "user '%s'\n", safe_pppd_line(nvram_safe_get("vpnc_user"), tmp, sizeof(tmp)));
	fprintf(fp, "password '%s'\n", safe_pppd_line(nvram_safe_get("vpnc_pass"), tmp, sizeof(tmp)));
	fprintf(fp, "refuse-eap\n");

	if (i_auth == 1) {
		/* MS-CHAPv2 */
		fprintf(fp, "refuse-pap\n");
		fprintf(fp, "refuse-chap\n");
		fprintf(fp, "refuse-mschap\n");
	}
	else if (i_auth == 2) {
		/* CHAP */
		fprintf(fp, "refuse-pap\n");
		fprintf(fp, "refuse-mschap\n");
		fprintf(fp, "refuse-mschap-v2\n");
	}
	else if (i_auth == 3) {
		/* PAP */
		fprintf(fp, "refuse-chap\n");
		fprintf(fp, "refuse-mschap\n");
		fprintf(fp, "refuse-mschap-v2\n");
	}

	if (i_type != 1)
	{
		fprintf(fp, "plugin pptp.so\n");
		fprintf(fp, "pptp_server '%s'\n", vpnc_peer);
		fprintf(fp, "route_rdgw %d\n", (nvram_match("vpnc_dgw", "1")) ? 2 : 0);
		fprintf(fp, "persist\n");
		fprintf(fp, "linkname %s\n", VPNC_PPP_LINK_NAME);
	}

	fprintf(fp, "mtu %d\n", nvram_safe_get_int("vpnc_mtu", 1450, 1000, 1460));
	fprintf(fp, "mru %d\n", nvram_safe_get_int("vpnc_mru", 1450, 1000, 1460));

	fprintf(fp, "maxfail %d\n", 0);		// pppd re-call count (0=infinite)
	fprintf(fp, "holdoff %d\n", 10);	// pppd re-call time (10s)

	fprintf(fp, "ipcp-accept-remote ipcp-accept-local\n");
	fprintf(fp, "noipdefault\n");
	fprintf(fp, "usepeerdns\n");

	fprintf(fp, "default-asyncmap\n");

	/* looks like pptp also likes them */
	fprintf(fp, "nopcomp noaccomp\n");

	/* ccp should still be enabled - mppe/mppc requires this */
	fprintf(fp, "novj nobsdcomp nodeflate\n");

	if (i_mppe == 3) {
		fprintf(fp, "nomppe nomppc\n");
	} else {
		if (i_mppe == 1) {
			fprintf(fp, "+mppe\n");
			fprintf(fp, "-mppe-40\n");
			fprintf(fp, "+mppe-128\n");
		} else if (i_mppe == 2) {
			fprintf(fp, "+mppe\n");
			fprintf(fp, "+mppe-40\n");
			fprintf(fp, "-mppe-128\n");
		} else {
			fprintf(fp, "+mppe-40\n");
			fprintf(fp, "+mppe-128\n");
		}
		fprintf(fp, "nomppe-stateful\n");
	}

	if (i_type == 1)
	{
		// Don't wait for LCP term responses; exit immediately when killed
		fprintf(fp, "lcp-max-terminate %d\n", 0);
	}

	/* echo failures (6*20s) */
	fprintf(fp, "lcp-echo-interval %d\n", 20);
	fprintf(fp, "lcp-echo-failure %d\n", 6);
	fprintf(fp, "lcp-echo-adaptive\n");

	fprintf(fp, "ip-up-script %s\n", VPNC_PPP_UP_SCRIPT);
	fprintf(fp, "ip-down-script %s\n", VPNC_PPP_DW_SCRIPT);

	fprintf(fp, "minunit %d\n", VPNC_PPP_UNIT);
	fprintf(fp, "ktune\n");

	/* user specific options */
	fprintf(fp, "%s\n", nvram_safe_get("vpnc_pppd"));

	fclose(fp);

	chmod(vpnc_opt, 0600);

	if (i_type == 1)
	{
		nvram_set_int_temp("l2tp_cli_t", 1);
		
		if (safe_start_xl2tpd() != 0)
			control_xl2tpd("c", "VPNC");
	}
	else
	{
		nvram_set_int_temp("l2tp_cli_t", 0);
		
		return eval("/usr/sbin/pppd", "file", vpnc_opt);
	}

	return 0;
}
コード例 #15
0
ファイル: vpn_openvpn.c プロジェクト: andy-padavan/rt-n56u
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");
}