Пример #1
0
static void init_switch_ralink(void)
{
	generate_switch_para();

	// TODO: replace to nvram controlled procedure later
	eval("ifconfig", "eth2", "hw", "ether", nvram_safe_get("et0macaddr"));
#ifdef RTCONFIG_RALINK_RT3052
	if(is_routing_enabled()) config_3052(nvram_get_int("switch_stb_x"));
#else
	if(strlen(nvram_safe_get("wan0_ifname"))) {
		if (!nvram_match("et1macaddr", ""))
			eval("ifconfig", nvram_safe_get("wan0_ifname"), "hw", "ether", nvram_safe_get("et1macaddr"));
		else
			eval("ifconfig", nvram_safe_get("wan0_ifname"), "hw", "ether", nvram_safe_get("et0macaddr"));
	}
	config_switch();
#endif

#ifdef RTCONFIG_SHP
	if(nvram_get_int("qos_enable") || nvram_get_int("macfilter_enable_x") || nvram_get_int("lfp_disable_force")) {
		nvram_set("lfp_disable", "1");
	}
	else {
		nvram_set("lfp_disable", "0");
	}

	if(nvram_get_int("lfp_disable")==0) {
		restart_lfp();
	}
#endif
//	reinit_hwnat();

}
Пример #2
0
void config_switch_dsl()
{
    int stbport;
    dbG("config ethernet switch IC\n");

    if (is_routing_enabled())
    {
        stbport = atoi(nvram_safe_get("switch_stb_x"));
        if (stbport < 0 || stbport > 6) stbport = 0;
        dbG("STB port: %d\n", stbport);

#ifdef RTCONFIG_DUALWAN
        if (stbport == 0)
        {
            if (get_dualwan_secondary()==WANS_DUALWAN_IF_LAN)
            {
                config_switch_dsl_set_lan();
            }
            else
            {
                if (get_dualwan_primary()==WANS_DUALWAN_IF_LAN)
                {
                    config_switch_dsl_set_lan();
                }
                else
                {
                    config_switch_dsl_set_dsl();
                }
            }
        }
        else
        {
            if (get_dualwan_secondary()==WANS_DUALWAN_IF_LAN)
            {
                config_switch_dsl_set_lan_iptv(stbport);
            }
            else
            {
                if (get_dualwan_primary()==WANS_DUALWAN_IF_LAN)
                {
                    config_switch_dsl_set_lan_iptv(stbport);
                }
                else
                {
                    config_switch_dsl_set_dsl();
                }
            }
        }
#else
        if (stbport == 0)
        {
            config_switch_dsl_set_dsl();
        }
        else
        {
            config_switch_dsl_set_iptv(stbport);
        }
#endif
    }
}
Пример #3
0
static void ntp_service()
{
	static int first_sync = 1;

	if (first_sync) {
		first_sync = 0;

		nvram_set("reload_svc_radio", "1");
		nvram_set("svc_ready", "1");

		setup_timezone();

		if (is_routing_enabled())
			notify_rc("restart_upnp");
#ifdef RTCONFIG_IPV6
#ifdef RTCONFIG_WIDEDHCP6
/* switch to monotonic clock usage *//*
		if (get_ipv6_service() != IPV6_DISABLED) {
			notify_rc("restart_dhcp6s");
			notify_rc("restart_radvd");
		}
*/
#endif /* RTCONFIG_WIDEDHCP6 */
#endif
#ifdef RTCONFIG_DISK_MONITOR
		notify_rc("restart_diskmon");
#endif
	}
}
Пример #4
0
void generate_switch_para(void)
{
	int model;

	// generate nvram nvram according to system setting
	model = get_model();

	switch(model) {
		case MODEL_RTN13U:
			if(!is_routing_enabled()) {
				// override boardflags with no VLAN flag
				nvram_set_int("boardflags", nvram_get_int("boardflags")&(~BFL_ENETVLAN));
				nvram_set("lan_ifnames", "eth2 ra0");
			}
			else if(nvram_match("switch_stb_x", "1")) {
				nvram_set("vlan0ports", "0 1 2 5*");
				nvram_set("vlan1ports", "3 4 5u");
			}
			else if(nvram_match("swtich_stb_x", "2")) {
				nvram_set("vlan0ports", "0 1 3 5*");
				nvram_set("vlan1ports", "2 4 5u");
			}
			else if(nvram_match("switch_stb_x", "3")) {
				nvram_set("vlan0ports", "0 2 3 5*");
				nvram_set("vlan1ports", "1 4 5u");
			}
			else if(nvram_match("switch_stb_x", "4")) {
				nvram_set("vlan0ports", "1 2 3 5*");
				nvram_set("vlan1ports", "0 4 5u");
			}
			else if(nvram_match("switch_stb_x", "5")) {
				nvram_set("vlan0ports", "2 3 5*");
				nvram_set("vlan1ports", "0 1 4 5u");
			}
			else {	// default for 0
				nvram_set("vlan0ports", "0 1 2 3 5*");
				nvram_set("vlan1ports", "4 5u");
			}
			break;
	}
}
Пример #5
0
void config_switch()
{
	int model;
	int stbport;
	int controlrate_unknown_unicast;
	int controlrate_unknown_multicast;
	int controlrate_multicast;
	int controlrate_broadcast;

	dbG("link down all ports\n");
	eval("rtkswitch", "17");	// link down all ports

	if (config_switch_for_first_time)
		config_switch_for_first_time = 0;
	else
	{
		dbG("software reset\n");
		eval("rtkswitch", "27");	// software reset
	}
#if defined(RTN14U) || defined(RTAC52U)
	system("rtkswitch 8 0"); //Barton add
#endif

	if (is_routing_enabled())
	{
		char parm_buf[] = "XXX";

		stbport = atoi(nvram_safe_get("switch_stb_x"));
		if (stbport < 0 || stbport > 6) stbport = 0;
		dbG("STB port: %d\n", stbport);
		/* stbport:	unifi_malaysia=1	otherwise
		 * ----------------------------------------------
		 *	0:	LLLLW			LLLLW
		 *	1:	LLLTW			LLLWW
		 *	2:	LLTLW			LLWLW
		 *	3:	LTLLW			LWLLW
		 *	4:	TLLLW			WLLLW
		 *	5:	TTLLW			WWLLW
		 *	6:	LLTTW			LLWWW
		 */
		if(!nvram_match("switch_wantag", "none")&&!nvram_match("switch_wantag", ""))//2012.03 Yau modify
		{
			char tmp[128];
			int voip_port = 0;
			int vlan_val;/* VID and PRIO */

//			voip_port = atoi(nvram_safe_get("voip_port"));
			voip_port = 3;
			if (voip_port < 0 || voip_port > 4)
				voip_port = 0;		

			/* Fixed Ports Now*/
			stbport = 4;	
			voip_port = 3;
	
			sprintf(tmp, "rtkswitch 29 %d", voip_port);	
			system(tmp);	

			if(!strncmp(nvram_safe_get("switch_wantag"), "unifi", 5))/* Added for Unifi. Cherry Cho modified in 2011/6/28.*/
			{
				if(strstr(nvram_safe_get("switch_wantag"), "home"))
				{					
					system("rtkswitch 38 1");/* IPTV: P0 */
					/* Internet */
					system("rtkswitch 36 500");
					system("rtkswitch 37 0");
					system("rtkswitch 39 0x02000210");
					/* IPTV */
					system("rtkswitch 36 600");
					system("rtkswitch 37 0");
					system("rtkswitch 39 0x00010011");
				}
				else/* No IPTV. Business package */
				{
					/* Internet */
					system("rtkswitch 38 0");
					system("rtkswitch 36 500");
					system("rtkswitch 37 0");
					system("rtkswitch 39 0x02000210");
				}
			}
			else if(!strncmp(nvram_safe_get("switch_wantag"), "singtel", 7))/* Added for SingTel's exStream issues. Cherry Cho modified in 2011/7/19. */
			{		
				if(strstr(nvram_safe_get("switch_wantag"), "mio"))/* Connect Singtel MIO box to P3 */
				{
					system("rtkswitch 40 1");
					system("rtkswitch 38 3");/* IPTV: P0  VoIP: P1 */
					/* Internet */
					system("rtkswitch 36 10");
					system("rtkswitch 37 0");
					system("rtkswitch 39 0x02000210");
					/* VoIP */
					system("rtkswitch 36 30");
					system("rtkswitch 37 4");				
					system("rtkswitch 39 0x00000012");//VoIP Port: P1 tag
				}
				else//Connect user's own ATA to lan port and use VoIP by Singtel WAN side VoIP gateway at voip.singtel.com
				{
					system("rtkswitch 38 1");/* IPTV: P0 */
					/* Internet */
					system("rtkswitch 36 10");
					system("rtkswitch 37 0");
					system("rtkswitch 39 0x02000210");
				}

				/* IPTV */
				system("rtkswitch 36 20");
				system("rtkswitch 37 4");
				system("rtkswitch 39 0x00010011");
			}
			else if(!strcmp(nvram_safe_get("switch_wantag"), "m1_fiber"))//VoIP: P1 tag. Cherry Cho added in 2012/1/13.
			{
				system("rtkswitch 40 1");
				system("rtkswitch 38 2");/* VoIP: P1  2 = 0x10 */
				/* Internet */
				system("rtkswitch 36 1103");
				system("rtkswitch 37 1");
				system("rtkswitch 39 0x02000210");
				/* VoIP */
				system("rtkswitch 36 1107");
				system("rtkswitch 37 1");				
				system("rtkswitch 39 0x00000012");//VoIP Port: P1 tag
			}
			else if(!strcmp(nvram_safe_get("switch_wantag"), "maxis_fiber"))//VoIP: P1 tag. Cherry Cho added in 2012/11/6.
			{
				system("rtkswitch 40 1");
				system("rtkswitch 38 2");/* VoIP: P1  2 = 0x10 */
				/* Internet */
				system("rtkswitch 36 621");
				system("rtkswitch 37 0");
				system("rtkswitch 39 0x02000210");
				/* VoIP */
				system("rtkswitch 36 821");
				system("rtkswitch 37 0");				
				system("rtkswitch 39 0x00000012");//VoIP Port: P1 tag

				system("rtkswitch 36 822");
				system("rtkswitch 37 0");				
				system("rtkswitch 39 0x00000012");//VoIP Port: P1 tag
			}
			else if(!strcmp(nvram_safe_get("switch_wantag"), "maxis_fiber_sp"))//VoIP: P1 tag. Cherry Cho added in 2012/11/6.
			{
				system("rtkswitch 40 1");
				system("rtkswitch 38 2");/* VoIP: P1  2 = 0x10 */
				/* Internet */
				system("rtkswitch 36 11");
				system("rtkswitch 37 0");
				system("rtkswitch 39 0x02000210");
				/* VoIP */
				system("rtkswitch 36 14");
				system("rtkswitch 37 0");				
				system("rtkswitch 39 0x00000012");//VoIP Port: P1 tag
			}
			else/* Cherry Cho added in 2011/7/11. */
			{
				/* Initialize VLAN and set Port Isolation */
				if(strcmp(nvram_safe_get("switch_wan1tagid"), "") && strcmp(nvram_safe_get("switch_wan2tagid"), ""))
					system("rtkswitch 38 3");// 3 = 0x11 IPTV: P0  VoIP: P1
				else if(strcmp(nvram_safe_get("switch_wan1tagid"), ""))
					system("rtkswitch 38 1");// 1 = 0x01 IPTV: P0 
				else if(strcmp(nvram_safe_get("switch_wan2tagid"), ""))
					system("rtkswitch 38 2");// 2 = 0x10 VoIP: P1
				else
					system("rtkswitch 38 0");//No IPTV and VoIP ports

				/*++ Get and set Vlan Information */
				if(strcmp(nvram_safe_get("switch_wan0tagid"), "") != 0)	// Internet on WAN (port 4)
				{
					vlan_val = atoi(nvram_safe_get("switch_wan0tagid"));
					if((vlan_val >= 2) && (vlan_val <= 4094))
					{											
						sprintf(tmp, "rtkswitch 36 %d", vlan_val);
						system(tmp);
					}

					if(strcmp(nvram_safe_get("switch_wan0prio"), "") != 0)
					{
						vlan_val = atoi(nvram_safe_get("switch_wan0prio"));
						if((vlan_val >= 0) && (vlan_val <= 7))
						{
							sprintf(tmp, "rtkswitch 37 %d", vlan_val);
							system(tmp);
						}
						else
							system("rtkswitch 37 0");
					}

					system("rtkswitch 39 0x02000210");
				}

				if(strcmp(nvram_safe_get("switch_wan1tagid"), "") != 0)	// IPTV on LAN4 (port 0)
				{
					vlan_val = atoi(nvram_safe_get("switch_wan1tagid"));
					if((vlan_val >= 2) && (vlan_val <= 4094))
					{								
						sprintf(tmp, "rtkswitch 36 %d", vlan_val);	
						system(tmp);
					}

					if(strcmp(nvram_safe_get("switch_wan1prio"), "") != 0)
					{
						vlan_val = atoi(nvram_safe_get("switch_wan1prio"));
						if((vlan_val >= 0) && (vlan_val <= 7))
						{
							sprintf(tmp, "rtkswitch 37 %d", vlan_val);	
							system(tmp);
						}
						else
							system("rtkswitch 37 0");
					}	

					if(!strcmp(nvram_safe_get("switch_wan1tagid"), nvram_safe_get("switch_wan2tagid")))
						system("rtkswitch 39 0x00030013"); //IPTV=VOIP
					else
						system("rtkswitch 39 0x00010011");//IPTV Port: P0 untag 65553 = 0x10 011
				}	

				if(strcmp(nvram_safe_get("switch_wan2tagid"), "") != 0)	// VoIP on LAN3 (port 1)
				{
					vlan_val = atoi(nvram_safe_get("switch_wan2tagid"));
					if((vlan_val >= 2) && (vlan_val <= 4094))
					{					
						sprintf(tmp, "rtkswitch 36 %d", vlan_val);	
						system(tmp);
					}

					if(strcmp(nvram_safe_get("switch_wan2prio"), "") != 0)
					{
						vlan_val = atoi(nvram_safe_get("switch_wan2prio"));
						if((vlan_val >= 0) && (vlan_val <= 7))
						{
							sprintf(tmp, "rtkswitch 37 %d", vlan_val);	
							system(tmp);		
						}
						else
							system("rtkswitch 37 0");
					}
	
					if(!strcmp(nvram_safe_get("switch_wan1tagid"), nvram_safe_get("switch_wan2tagid")))
						system("rtkswitch 39 0x00030013"); //IPTV=VOIP
					else
						system("rtkswitch 39 0x00020012");//VoIP Port: P1 untag
				}

			}
		}
		else
		{
			sprintf(parm_buf, "%d", stbport);
			if (stbport)
				eval("rtkswitch", "8", parm_buf);
		}

		/* unknown unicast storm control */
		if (!nvram_get("switch_ctrlrate_unknown_unicast"))
			controlrate_unknown_unicast = 0;
		else
			controlrate_unknown_unicast = atoi(nvram_get("switch_ctrlrate_unknown_unicast"));
		if (controlrate_unknown_unicast < 0 || controlrate_unknown_unicast > 1024)
			controlrate_unknown_unicast = 0;
		if (controlrate_unknown_unicast)
		{
			sprintf(parm_buf, "%d", controlrate_unknown_unicast);
			eval("rtkswitch", "22", parm_buf);
		}
	
		/* unknown multicast storm control */
		if (!nvram_get("switch_ctrlrate_unknown_multicast"))
			controlrate_unknown_multicast = 0;
		else
			controlrate_unknown_multicast = atoi(nvram_get("switch_ctrlrate_unknown_multicast"));
		if (controlrate_unknown_multicast < 0 || controlrate_unknown_multicast > 1024)
			controlrate_unknown_multicast = 0;
		if (controlrate_unknown_multicast)
		{
			sprintf(parm_buf, "%d", controlrate_unknown_multicast);
			eval("rtkswitch", "23", parm_buf);
		}
	
		/* multicast storm control */
		if (!nvram_get("switch_ctrlrate_multicast"))
			controlrate_multicast = 0;
		else
			controlrate_multicast = atoi(nvram_get("switch_ctrlrate_multicast"));
		if (controlrate_multicast < 0 || controlrate_multicast > 1024)
			controlrate_multicast = 0;
		if (controlrate_multicast)
		{
			sprintf(parm_buf, "%d", controlrate_multicast);
			eval("rtkswitch", "24", parm_buf);
		}
	
		/* broadcast storm control */
		if (!nvram_get("switch_ctrlrate_broadcast"))
			controlrate_broadcast = 0;
		else
			controlrate_broadcast = atoi(nvram_get("switch_ctrlrate_broadcast"));
		if (controlrate_broadcast < 0 || controlrate_broadcast > 1024)
			controlrate_broadcast = 0;
		if (controlrate_broadcast)
		{
			sprintf(parm_buf, "%d", controlrate_broadcast);
			eval("rtkswitch", "25", parm_buf);
		}
	}
	else if (is_apmode_enabled())
	{
		model = get_model();
		if (model == MODEL_RTN65U || model == MODEL_RTN36U3)
			eval("rtkswitch", "8", "100");
	}

#ifdef RTCONFIG_DSL
	dbG("link up all ports\n");
	eval("rtkswitch", "16");	// link up all ports
#else
	dbG("link up wan port(s)\n");
	eval("rtkswitch", "114");	// link up wan port(s)
#endif
}
Пример #6
0
int main(int argc, char *argv[])
{
	FILE *fp;
	char *nv;
	int n=0;
	char *p_computer_name = NULL;
	disk_info_t *follow_disk, *disks_info = NULL;
	partition_info_t *follow_partition;
	char *mount_folder;
	int result, node_layer, samba_right;
	int sh_num;
	char **folder_list = NULL;
	int acc_num;
	char **account_list;
	int dup, same_m_pt = 0;
	char unique_share_name[PATH_MAX];

	unlink("/var/log.samba");

	if ((fp=fopen(SAMBA_CONF, "r"))) {
		fclose(fp);
		unlink(SAMBA_CONF);
	}

	if((fp = fopen(SAMBA_CONF, "w")) == NULL)
		goto confpage;

	fprintf(fp, "[global]\n");
	if (nvram_safe_get("st_samba_workgroup"))
		fprintf(fp, "workgroup = %s\n", nvram_safe_get("st_samba_workgroup"));
#if 0
	if (nvram_safe_get("computer_name")) {
		fprintf(fp, "netbios name = %s\n", nvram_safe_get("computer_name"));
		fprintf(fp, "server string = %s\n", nvram_safe_get("computer_name"));
	}
#else
	p_computer_name = nvram_get("computer_name") && is_valid_netbios_name(nvram_get("computer_name")) ? nvram_get("computer_name") : get_productid();
	if (p_computer_name) {
		fprintf(fp, "netbios name = %s\n", p_computer_name);
		fprintf(fp, "server string = %s\n", p_computer_name);
	}
#endif

	fprintf(fp, "unix charset = UTF8\n");		// ASUS add
	fprintf(fp, "display charset = UTF8\n");	// ASUS add
	fprintf(fp, "log file = /var/log.samba\n");
	fprintf(fp, "log level = 0\n");
	fprintf(fp, "max log size = 5\n");

	// account mode
	if(nvram_match("st_samba_mode", "2") || nvram_match("st_samba_mode", "4")
			|| (nvram_match("st_samba_mode", "1") && nvram_get("st_samba_force_mode") == NULL)
			){
		fprintf(fp, "security = USER\n");
		fprintf(fp, "guest ok = no\n");
		fprintf(fp, "map to guest = Bad User\n");
	}
	// share mode
	else if (nvram_match("st_samba_mode", "1") || nvram_match("st_samba_mode", "3")) {
#if 0
//#if defined(RTCONFIG_TFAT) || defined(RTCONFIG_TUXERA_NTFS) || defined(RTCONFIG_TUXERA_HFS)
		if(nvram_get_int("enable_samba_tuxera") == 1){
			fprintf(fp, "auth methods = guest\n");
			fprintf(fp, "guest account = admin\n");
			fprintf(fp, "map to guest = Bad Password\n");
			fprintf(fp, "guest ok = yes\n");
		}
		else{
			fprintf(fp, "security = SHARE\n");
			fprintf(fp, "guest only = yes\n");
		}
#else
		fprintf(fp, "security = SHARE\n");
		fprintf(fp, "guest only = yes\n");
#endif
	}
	else{
		usb_dbg("samba mode: no\n");
		goto confpage;
	}

	fprintf(fp, "encrypt passwords = yes\n");
	fprintf(fp, "pam password change = no\n");
	fprintf(fp, "null passwords = yes\n");		// ASUS add
#ifdef RTCONFIG_SAMBA_MODERN
	if (nvram_get_int("smbd_enable_smb2"))
		fprintf(fp, "max protocol = SMB2\n");
	else
		fprintf(fp, "max protocol = NT1\n");

	fprintf(fp, "passdb backend = smbpasswd\n");
	fprintf(fp, "smb encrypt = disabled\n");
	fprintf(fp, "smb passwd file = /etc/samba/smbpasswd\n");
#endif
#if 0
#ifdef RTCONFIG_RECVFILE
	fprintf(fp, "use recvfile = yes\n");
#endif
#endif
	fprintf(fp, "force directory mode = 0777\n");
	fprintf(fp, "force create mode = 0777\n");

	/* max users */
	if (strcmp(nvram_safe_get("st_max_user"), "") != 0)
		fprintf(fp, "max connections = %s\n", nvram_safe_get("st_max_user"));

        /* remove socket options due to NIC compatible issue */
	if(!nvram_get_int("stop_samba_speedup")){
#ifdef RTCONFIG_BCMARM
#ifdef RTCONFIG_BCM_7114
		fprintf(fp, "socket options = IPTOS_LOWDELAY TCP_NODELAY SO_RCVBUF=131072 SO_SNDBUF=131072\n");
#endif
#else
		fprintf(fp, "socket options = TCP_NODELAY SO_KEEPALIVE SO_RCVBUF=65536 SO_SNDBUF=65536\n");
#endif
	}
	fprintf(fp, "obey pam restrictions = no\n");
	fprintf(fp, "use spnego = no\n");		// ASUS add
	fprintf(fp, "client use spnego = no\n");	// ASUS add
//	fprintf(fp, "client use spnego = yes\n");  // ASUS add
	fprintf(fp, "disable spoolss = yes\n");		// ASUS add
	fprintf(fp, "host msdfs = no\n");		// ASUS add
	fprintf(fp, "strict allocate = No\n");		// ASUS add
//	fprintf(fp, "mangling method = hash2\n");	// ASUS add
	fprintf(fp, "bind interfaces only = yes\n");    // ASUS add

#ifndef RTCONFIG_BCMARM
	fprintf(fp, "interfaces = lo br0 %s\n", (is_routing_enabled() && nvram_get_int("smbd_wanac")) ? nvram_safe_get("wan0_ifname") : "");
#else
	fprintf(fp, "interfaces = br0 %s/%s %s\n", nvram_safe_get("lan_ipaddr"), nvram_safe_get("lan_netmask"), (is_routing_enabled() && nvram_get_int("smbd_wanac")) ? nvram_safe_get("wan0_ifname") : "");
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36)
	fprintf(fp, "use sendfile = no\n");
#else
	fprintf(fp, "use sendfile = yes\n");
#endif
	if (!strcmp(nvram_safe_get("smbd_wins"), "1")) {
		fprintf(fp, "wins support = yes\n");
	}

	if (!strcmp(nvram_safe_get("smbd_master"), "1")) {
		fprintf(fp, "os level = 255\n");
		fprintf(fp, "domain master = yes\n");
		fprintf(fp, "local master = yes\n");
		fprintf(fp, "preferred master = yes\n");
	}

	fprintf(fp, "map archive = no\n");
	fprintf(fp, "map hidden = no\n");
	fprintf(fp, "map read only = no\n");
	fprintf(fp, "map system = no\n");
	fprintf(fp, "store dos attributes = yes\n");
	fprintf(fp, "dos filemode = yes\n");
	fprintf(fp, "oplocks = yes\n");
	fprintf(fp, "level2 oplocks = yes\n");
	fprintf(fp, "kernel oplocks = no\n");
	fprintf(fp, "wide links = no\n");

	// If we only want name services then skip share definition
	if (nvram_match("enable_samba", "0"))
		goto confpage;

	disks_info = read_disk_data();
	if (disks_info == NULL) {
		usb_dbg("Couldn't get disk list when writing smb.conf!\n");
		goto confpage;
	}

	/* share */
	if (nvram_match("st_samba_mode", "0") || !strcmp(nvram_safe_get("st_samba_mode"), "")) {
		;
	}
	else if (nvram_match("st_samba_mode", "1") && nvram_match("st_samba_force_mode", "1")) {
		usb_dbg("samba mode: share\n");

		for (follow_disk = disks_info; follow_disk != NULL; follow_disk = follow_disk->next) {
			for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) {
				if (follow_partition->mount_point == NULL)
					continue;
				
				strcpy(unique_share_name, follow_partition->mount_point);
				do {
					dup = check_mount_point_icase(disks_info, follow_partition, follow_disk, follow_partition->partition_order, unique_share_name);
					if (dup)
						sprintf(unique_share_name, "%s(%d)", follow_partition->mount_point, ++same_m_pt);
				} while (dup);
				mount_folder = strrchr(unique_share_name, '/')+1;

				fprintf(fp, "[%s]\n", mount_folder);
				fprintf(fp, "comment = %s's %s\n", follow_disk->tag, mount_folder);
				fprintf(fp, "veto files = /.__*.txt*/asus_lighttpdpasswd/\n");
				fprintf(fp, "path = %s\n", follow_partition->mount_point);
				fprintf(fp, "writeable = yes\n");

				fprintf(fp, "dos filetimes = yes\n");
				fprintf(fp, "fake directory create times = yes\n");
			}
		}
	}
	else if (nvram_match("st_samba_mode", "2")) {
		usb_dbg("samba mode: share\n");

		for (follow_disk = disks_info; follow_disk != NULL; follow_disk = follow_disk->next) {
			for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) {
				if (follow_partition->mount_point == NULL)
					continue;

				strcpy(unique_share_name, follow_partition->mount_point);
				do {
					dup = check_mount_point_icase(disks_info, follow_partition, follow_disk, follow_partition->partition_order, unique_share_name);
					if (dup)
						sprintf(unique_share_name, "%s(%d)", follow_partition->mount_point, ++same_m_pt);
				} while (dup);
				mount_folder = strrchr(unique_share_name, '/')+1;

				node_layer = get_permission(NULL, follow_partition->mount_point, NULL, "cifs");
				if(node_layer == 3){
					fprintf(fp, "[%s]\n", mount_folder);
					fprintf(fp, "comment = %s's %s\n", follow_disk->tag, mount_folder);
					fprintf(fp, "path = %s\n", follow_partition->mount_point);
					fprintf(fp, "writeable = yes\n");

					fprintf(fp, "dos filetimes = yes\n");
					fprintf(fp, "fake directory create times = yes\n");
				}
				else{
					//result = get_all_folder(follow_partition->mount_point, &sh_num, &folder_list);
					result = get_folder_list(follow_partition->mount_point, &sh_num, &folder_list);
					if (result < 0){
						free_2_dimension_list(&sh_num, &folder_list);
						continue;
					}

					for (n = 0; n < sh_num; ++n){
						samba_right = get_permission(NULL, follow_partition->mount_point, folder_list[n], "cifs");
						if (samba_right < 0 || samba_right > 3)
							samba_right = DEFAULT_SAMBA_RIGHT;

						if(samba_right > 0){
							int count = get_list_strings_count(folder_list, sh_num, folder_list[n]);
							if ((!strcmp(nvram_safe_get("smbd_simpler_naming"), "1")) && (count <= 1)) {
								fprintf(fp, "[%s]\n", folder_list[n]);
							} else {
								fprintf(fp, "[%s (at %s)]\n", folder_list[n], mount_folder);
							}
							fprintf(fp, "comment = %s's %s in %s\n", mount_folder, folder_list[n], follow_disk->tag);
							fprintf(fp, "path = %s/%s\n", follow_partition->mount_point, folder_list[n]);
							if(samba_right == 3)
								fprintf(fp, "writeable = yes\n");
							else
								fprintf(fp, "writeable = no\n");

							fprintf(fp, "dos filetimes = yes\n");
							fprintf(fp, "fake directory create times = yes\n");
						}
					}

					free_2_dimension_list(&sh_num, &folder_list);
				}
			}
		}
	}
	else if (nvram_match("st_samba_mode", "3")) {
		usb_dbg("samba mode: user\n");

		// get the account list
		if (get_account_list(&acc_num, &account_list) < 0) {
			usb_dbg("Can't read the account list.\n");
			free_2_dimension_list(&acc_num, &account_list);
			goto confpage;
		}

		for (follow_disk = disks_info; follow_disk != NULL; follow_disk = follow_disk->next) {
			for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) {
				if (follow_partition->mount_point == NULL)
					continue;

				mount_folder = strrchr(follow_partition->mount_point, '/')+1;

				// 1. get the folder list
				if (get_folder_list(follow_partition->mount_point, &sh_num, &folder_list) < 0) {
					free_2_dimension_list(&sh_num, &folder_list);
				}

				// 2. start to get every share
				for (n = -1; n < sh_num; ++n) {
					int i, first;

					if(n == -1){
						fprintf(fp, "[%s]\n", mount_folder);
						fprintf(fp, "comment = %s's %s\n", follow_disk->tag, mount_folder);
						fprintf(fp, "path = %s\n", follow_partition->mount_point);
					}
					else{
						int count = get_list_strings_count(folder_list, sh_num, folder_list[n]);
						if ((!strcmp(nvram_safe_get("smbd_simpler_naming"), "1")) && (count <= 1)) {
							fprintf(fp, "[%s]\n", folder_list[n]);
						} else {
							fprintf(fp, "[%s (at %s)]\n", folder_list[n], mount_folder);
						}
						fprintf(fp, "comment = %s's %s in %s\n", mount_folder, folder_list[n], follow_disk->tag);
						fprintf(fp, "path = %s/%s\n", follow_partition->mount_point, folder_list[n]);
					}

					fprintf(fp, "dos filetimes = yes\n");
					fprintf(fp, "fake directory create times = yes\n");

					fprintf(fp, "valid users = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						if(n == -1)
							samba_right = get_permission(account_list[i], follow_partition->mount_point, NULL, "cifs");
						else
							samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");

						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");

					fprintf(fp, "invalid users = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						if(n == -1)
							samba_right = get_permission(account_list[i], follow_partition->mount_point, NULL, "cifs");
						else
							samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (samba_right >= 1)
							continue;
						
						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");

						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");

					fprintf(fp, "read list = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						if(n == -1)
							samba_right = get_permission(account_list[i], follow_partition->mount_point, NULL, "cifs");
						else
							samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (samba_right < 1)
							continue;

						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");

						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");

					fprintf(fp, "write list = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						if(n == -1)
							samba_right = get_permission(account_list[i], follow_partition->mount_point, NULL, "cifs");
						else
							samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (samba_right < 2)
							continue;

						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");

						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");
				}

				free_2_dimension_list(&sh_num, &folder_list);
			}
		}

		free_2_dimension_list(&acc_num, &account_list);
	}
	else if (nvram_match("st_samba_mode", "4")
			|| (nvram_match("st_samba_mode", "1") && nvram_get("st_samba_force_mode") == NULL)
			) {
		usb_dbg("samba mode: user\n");

		// get the account list
		if (get_account_list(&acc_num, &account_list) < 0) {
			usb_dbg("Can't read the account list.\n");
			free_2_dimension_list(&acc_num, &account_list);
			goto confpage;
		}

		for (follow_disk = disks_info; follow_disk != NULL; follow_disk = follow_disk->next) {
			for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) {
				if (follow_partition->mount_point == NULL)
					continue;

				mount_folder = strrchr(follow_partition->mount_point, '/')+1;

				// 1. get the folder list
				if (get_folder_list(follow_partition->mount_point, &sh_num, &folder_list) < 0) {
					free_2_dimension_list(&sh_num, &folder_list);
				}

				// 2. start to get every share
				for (n = 0; n < sh_num; ++n) {
					int i, first;

					int count = get_list_strings_count(folder_list, sh_num, folder_list[n]);
					if ((!strcmp(nvram_safe_get("smbd_simpler_naming"), "1")) && (count <= 1)) {
						fprintf(fp, "[%s]\n", folder_list[n]);
					} else {
						fprintf(fp, "[%s (at %s)]\n", folder_list[n], mount_folder);
					}
					fprintf(fp, "comment = %s's %s in %s\n", mount_folder, folder_list[n], follow_disk->tag);
					fprintf(fp, "path = %s/%s\n", follow_partition->mount_point, folder_list[n]);

					fprintf(fp, "dos filetimes = yes\n");
					fprintf(fp, "fake directory create times = yes\n");

					fprintf(fp, "valid users = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						if(n == -1)
							samba_right = get_permission(account_list[i], follow_partition->mount_point, NULL, "cifs");
						else
							samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");

						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");

					fprintf(fp, "invalid users = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (samba_right >= 1)
							continue;
						
						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");

						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");

					fprintf(fp, "read list = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (samba_right < 1)
							continue;

						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");

						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");

					fprintf(fp, "write list = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (samba_right < 2)
							continue;

						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");

						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");
				}

				free_2_dimension_list(&sh_num, &folder_list);
			}
		}

		free_2_dimension_list(&acc_num, &account_list);
	}

confpage:
	if(fp != NULL) {

		append_custom_config("smb.conf", fp);
		fclose(fp);

		use_custom_config("smb.conf", SAMBA_CONF);
		run_postconf("smb", SAMBA_CONF);
	}

	free_disk_data(&disks_info);
	return 0;
}
Пример #7
0
int
ej_ipv6_pinhole_array(int eid, webs_t wp, int argc, char_t **argv)
{
    FILE *fp;
    char *ipt_argv[] = {"ip6tables", "-nxL", "UPNP", NULL};
    char line[256], tmp[256];
    char target[16], proto[16];
    char src[45];
    char dst[45];
    char *sport, *dport, *ptr, *val;
    int ret = 0;

    ret += websWrite(wp, "var pinholes = ");

    if (!(ipv6_enabled() && is_routing_enabled())) {
        ret += websWrite(wp, "[];\n");
        return ret;
    }

    _eval(ipt_argv, ">/tmp/pinhole.log", 10, NULL);

    fp = fopen("/tmp/pinhole.log", "r");
    if (fp == NULL) {
        ret += websWrite(wp, "[];\n");
        return ret;
    }

    ret += websWrite(wp, "[");

    while (fgets(line, sizeof(line), fp) != NULL)
    {
        tmp[0] = '\0';
        if (sscanf(line,
                   "%15s%*[ \t]"		// target
                   "%15s%*[ \t]"		// prot
                   "%44[^/]/%*d%*[ \t]"	// source
                   "%44[^/]/%*d%*[ \t]"	// destination
                   "%255[^\n]",		// options
                   target, proto, src, dst, tmp) < 5) continue;

        if (strcmp(target, "ACCEPT")) continue;

        /* uppercase proto */
        for (ptr = proto; *ptr; ptr++)
            *ptr = toupper(*ptr);

        /* parse source */
        if (strcmp(src, "::") == 0)
            strcpy(src, "ALL");

        /* parse destination */
        if (strcmp(dst, "::") == 0)
            strcpy(dst, "ALL");

        /* parse options */
        sport = dport = "";
        ptr = tmp;
        while ((val = strsep(&ptr, " ")) != NULL) {
            if (strncmp(val, "dpt:", 4) == 0)
                dport = val + 4;
            if (strncmp(val, "spt:", 4) == 0)
                sport = val + 4;
            else if (strncmp(val, "dpts:", 5) == 0)
                dport = val + 5;
            else if (strncmp(val, "spts:", 5) == 0)
                sport = val + 5;
        }

        ret += websWrite(wp,
                         "[\"%s\", \"%s\", \"%s\", \"%s\", \"%s\"],\n",
                         src, sport, dst, dport, proto);
    }
    ret += websWrite(wp, "[]];\n");

    fclose(fp);
    unlink("/tmp/pinhole.log");

    return ret;

}
Пример #8
0
ej_lan_ipv6_network_array(int eid, webs_t wp, int argc, char_t **argv)
{
    FILE *fp;
    char buf[64+32+8192+1];
    char *hostname, *macaddr, ipaddrs[8192+1];
    char ipv6_dns_str[1024];
    char *wan_type, *wan_dns, *p;
    int service, i, ret = 0;

    ret += websWrite(wp, "var ipv6cfgarray = [");

    if (!(ipv6_enabled() && is_routing_enabled())) {
        ret += websWrite(wp, "[]];\n");
        ret += websWrite(wp, "var ipv6clientarray = [");
        ret += websWrite(wp, "[]];\n");
        return ret;
    }

    service = get_ipv6_service();
    switch (service) {
    case IPV6_NATIVE_DHCP:
        wan_type = "Native with DHCP-PD";
        break;
    case IPV6_6TO4:
        wan_type = "Tunnel 6to4";
        break;
    case IPV6_6IN4:
        wan_type = "Tunnel 6in4";
        break;
    case IPV6_6RD:
        wan_type = "Tunnel 6rd";
        break;
    case IPV6_MANUAL:
        wan_type = "Static";
        break;
    default:
        wan_type = "Disabled";
        break;
    }

    ret += websWrite(wp, "[\"IPv6 Connection Type\",\"%s\"],", wan_type);

    ret += websWrite(wp, "[\"WAN IPv6 Address\",\"%s\"],",
                     getifaddr((char *) get_wan6face(), AF_INET6, GIF_PREFIXLEN) ? : nvram_safe_get("ipv6_rtr_addr"));


    ret += websWrite(wp, "[\"WAN IPv6 Gateway\",\"%s\"],",
                     ipv6_gateway_address() ? : "");

    ret += websWrite(wp, "[\"LAN IPv6 Address\",\"%s/%d\"],",
                     nvram_safe_get("ipv6_rtr_addr"), nvram_get_int("ipv6_prefix_length"));

    ret += websWrite(wp, "[\"LAN IPv6 Link-Local Address\",\"%s\"],",
                     getifaddr(nvram_safe_get("lan_ifname"), AF_INET6, GIF_LINKLOCAL | GIF_PREFIXLEN) ? : "");

    if (service == IPV6_NATIVE_DHCP) {
        ret += websWrite(wp, "[\"DHCP-PD\",\"%s\"],",
                         nvram_get_int("ipv6_dhcp_pd") ? "Enabled" : "Disabled");
    }

    ret += websWrite(wp, "[\"LAN IPv6 Prefix\",\"%s/%d\"],",
                     nvram_safe_get("ipv6_prefix"), nvram_get_int("ipv6_prefix_length"));

    if (service == IPV6_NATIVE_DHCP &&
            nvram_get_int("ipv6_dnsenable")) {
        wan_dns = nvram_safe_get("ipv6_get_dns");
    } else {
        char nvname[sizeof("ipv6_dnsXXX")];
        char *next = ipv6_dns_str;

        ipv6_dns_str[0] = '\0';
        for (i = 1; i <= 3; i++) {
            snprintf(nvname, sizeof(nvname), "ipv6_dns%d", i);
            wan_dns = nvram_safe_get(nvname);
            if (*wan_dns)
                next += sprintf(next, *ipv6_dns_str ? " %s" : "%s", wan_dns);
        }
        wan_dns = ipv6_dns_str;
    }

    ret += websWrite(wp, "[\"DNS Address\",\"%s\"],", wan_dns);
    ret += websWrite(wp, "[]];\n");

    ret += websWrite(wp, "var ipv6clientarray = [");

    /* Refresh lease file to get actual expire time */
    killall("dnsmasq", SIGUSR2);
    usleep(100 * 1000);

    get_ipv6_client_info();
    get_ipv6_client_list();

    if ((fp = fopen(IPV6_CLIENT_LIST, "r")) == NULL) {
        _dprintf("can't open %s: %s", IPV6_CLIENT_LIST, strerror(errno));
        return ret;
    }

    while (fgets(buf, sizeof(buf), fp) != NULL) {
        char *ptr = buf;

        ptr = strsep(&ptr, "\n");
        hostname = strsep(&ptr, " ");
        macaddr = strsep(&ptr, " ");
        if (!macaddr || *macaddr == '\0' ||
                !ptr || *ptr == '\0')
            continue;

        if (strlen(hostname) > 32)
            sprintf(hostname + 29, "...");

        ipaddrs[0] = '\0';
        p = ipaddrs;
        while (ptr && *ptr) {
            char *next = strsep(&ptr, ",\n");
            if (next && *next)
                p += snprintf(p, sizeof(ipaddrs) + ipaddrs - p, "%s%s", *ipaddrs ? ", " : "", next);
        }

        ret += websWrite(wp, "[\"%s\", \"%s\", \"%s\"],",
                         hostname, macaddr, ipaddrs);
    }
    fclose(fp);

    ret += websWrite(wp, "[]];\n");
    return ret;
}
Пример #9
0
void init_switch_dsl()
{
	// vlan1 => LAN PORT
	// vlan2 => WAN to modem , send packet to modem , used on modem driver
	// vlan3 => IPTV port
	// vlan4 => WAN to Ethernet this is ethernet WAN ifname
	int stbport;
	int enable_dsl_wan_dsl_if = 0;
	int enable_dsl_wan_eth_if = 0;
	int enable_dsl_wan_iptv_if = 0;

#ifdef RTCONFIG_DUALWAN
	if (get_dualwan_secondary()==WANS_DUALWAN_IF_NONE)
	{
		if (get_dualwan_primary()==WANS_DUALWAN_IF_DSL)
		{
			enable_dsl_wan_dsl_if = 1;
		}
		else if (get_dualwan_primary()==WANS_DUALWAN_IF_LAN)
		{
			enable_dsl_wan_eth_if = 1;
		}
	}
	else
	{
		if (get_dualwan_primary()==WANS_DUALWAN_IF_DSL)
		{
			enable_dsl_wan_dsl_if = 1;
		}
		else if (get_dualwan_primary()==WANS_DUALWAN_IF_LAN)
		{
			enable_dsl_wan_eth_if = 1;
		}

		if (get_dualwan_secondary()==WANS_DUALWAN_IF_DSL)
		{
			enable_dsl_wan_dsl_if = 1;
		}
		else if (get_dualwan_secondary()==WANS_DUALWAN_IF_LAN)
		{
			enable_dsl_wan_eth_if = 1;
		}
	}
#else
	enable_dsl_wan_dsl_if = 1;
#endif

	if (is_routing_enabled())
	{
		stbport = atoi(nvram_safe_get("switch_stb_x"));
		if (stbport < 0 || stbport > 6) stbport = 0;
		dbG("STB port: %d\n", stbport);

		if (stbport > 0)
		{
			enable_dsl_wan_iptv_if = 1;
		}
	}

	eval("ifconfig", "eth0", "up");
	// vlan2 = WAN
	eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD");
	eval("vconfig", "add", "eth0", "2");
	eval("ifconfig", "vlan2", "up");

	if (enable_dsl_wan_dsl_if)
	{
		// DSL WAN MODE
		eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD");
		eval("vconfig", "add", "eth0", "100");
		eval("ifconfig", "vlan100", "up");
		eval("ifconfig", "vlan100", "hw", "ether", nvram_safe_get("et0macaddr"));
	}

	if (enable_dsl_wan_eth_if)
	{
		// vlan4 = ethenet WAN
		eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD");
		eval("vconfig", "add", "eth0", "4");
		eval("ifconfig", "vlan4", "up");
		// ethernet WAN , it needs to use another MAC address
		eval("ifconfig", "vlan4", "hw", "ether", nvram_safe_get("et1macaddr"));
	}

	if (enable_dsl_wan_iptv_if)
	{
		// vlan3 = IPTV
		eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD");
		eval("vconfig", "add", "eth0", "3");
		eval("ifconfig", "vlan3", "up");
		// bypass , no need to have another MAC address
	}

}
Пример #10
0
void init_switch_dsl()
{
    // DSLTODO

    // Eth2 => SoC RGMII 0 => Because we use VLAN, we do not use this interface directly
    // Eth2.1 => WAN to modem , send packet to modem , used on modem driver
    // Eth2.2 => LAN PORT
    // Eth 2.1.50 => for stats, ethernet driver modify modem packets to this VLAN ID
    // Eth 2.1.51 => bridge for Ethernet and modem, ethernet driver modify modem packet to VLAN ID (51)
    // and then bridge eth2.2 and eth2.1.51. thus, PC could control modem from LAN port
    // Eth2.3 => IPTV port
    // Eth2.4 => WAN to Ethernet this is ethernet WAN ifname
    int stbport;
    int enable_dsl_wan_dsl_if = 0;
    int enable_dsl_wan_eth_if = 0;
    int enable_dsl_wan_iptv_if = 0;


    eval("ifconfig", "eth2", "up");
    // eth2.1 = WAN
    eval("vconfig", "add", "eth2", "1");
    eval("ifconfig", "eth2.1", "up");
    // eth2.2 = LAN
    eval("vconfig", "add", "eth2", "2");
    eval("ifconfig", "eth2.2", "up");
    // eth2.3 = IPTV

#ifdef RTCONFIG_DUALWAN
    if (get_dualwan_secondary()==WANS_DUALWAN_IF_NONE)
    {
        if (get_dualwan_primary()==WANS_DUALWAN_IF_DSL)
        {
            enable_dsl_wan_dsl_if = 1;
        }
        else if (get_dualwan_primary()==WANS_DUALWAN_IF_LAN)
        {
            enable_dsl_wan_eth_if = 1;
        }
    }
    else
    {
        if (get_dualwan_primary()==WANS_DUALWAN_IF_DSL)
        {
            enable_dsl_wan_dsl_if = 1;
        }
        else if (get_dualwan_primary()==WANS_DUALWAN_IF_LAN)
        {
            enable_dsl_wan_eth_if = 1;
        }

        if (get_dualwan_secondary()==WANS_DUALWAN_IF_DSL)
        {
            enable_dsl_wan_dsl_if = 1;
        }
        else if (get_dualwan_secondary()==WANS_DUALWAN_IF_LAN)
        {
            enable_dsl_wan_eth_if = 1;
        }
    }
#else
    enable_dsl_wan_dsl_if = 1;
#endif

    if (is_routing_enabled())
    {
        stbport = atoi(nvram_safe_get("switch_stb_x"));
        if (stbport < 0 || stbport > 6) stbport = 0;
        dbG("STB port: %d\n", stbport);

        if (stbport > 0)
        {
            enable_dsl_wan_iptv_if = 1;
        }
    }


    if (enable_dsl_wan_dsl_if)
    {
        // DSL WAN MODE
        eval("vconfig", "add", "eth2.1", "1");
        eval("ifconfig", "eth2.1.1", "up");
        eval("ifconfig", "eth2.1", "hw", "ether", nvram_safe_get("et0macaddr"));
    }

    if (enable_dsl_wan_eth_if)
    {
        // eth2.4 = ethenet WAN
        eval("vconfig", "add", "eth2", "4");
        eval("ifconfig", "eth2.4", "up");
        // ethernet WAN , it needs to use another MAC address
        eval("ifconfig", "eth2.4", "hw", "ether", nvram_safe_get("et1macaddr"));
    }

    if (enable_dsl_wan_iptv_if)
    {
        // eth2.3 = IPTV
        eval("vconfig", "add", "eth2", "3");
        eval("ifconfig", "eth2.3", "up");
        // bypass , no need to have another MAC address
    }

    // for a dummy interface from trendchip
    // this is only for stats viewing , non-necessary
    // do not power up dummay interface. If so, it will send packet out
    eval("vconfig", "add", "eth2.1", "50");
    eval("vconfig", "add", "eth2.1", "51");

}