コード例 #1
0
void start_setup_vlans(void)
{
#if defined(HAVE_RB500) || defined(HAVE_XSCALE) || defined(HAVE_LAGUNA) || defined(HAVE_MAGICBOX) || defined(HAVE_RB600) || defined(HAVE_FONERA) || defined(HAVE_WHRAG108) || defined(HAVE_LS2) || defined(HAVE_CA8) || defined(HAVE_TW6600) || defined(HAVE_PB42) || defined(HAVE_LS5) || defined(HAVE_LSX) || defined(HAVE_DANUBE) || defined(HAVE_STORM) || defined(HAVE_ADM5120) || defined(HAVE_RT2880) || defined(HAVE_SOLO51) || defined(HAVE_OPENRISC) || defined(HAVE_NORTHSTAR)
	return;
#else
	/*
	 * VLAN #16 is just a convieniant way of storing tagging info.  There is
	 * no VLAN #16 
	 */

	if (!nvram_get("port5vlans") || nvram_match("vlans", "0"))
		return;		// for some reason VLANs are not set up, and
	// we don't want to disable everything!

	if (nvram_match("wan_vdsl", "1") && !nvram_match("fromvdsl", "1")) {
		nvram_set("vdsl_state", "0");
		enable_dtag_vlan(1);
		return;
	}

	int i, j, ret = 0, tmp, workaround = 0, found;
	char *vlans, *next, vlan[4], buff[70], buff2[16];
	FILE *fp;
	char portsettings[16][64];
	char tagged[16];
	unsigned char mac[20];;
	struct ifreq ifr;
	int s;
	char *phy = getPhyDev();

	s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
	strcpy(mac, nvram_safe_get("et0macaddr"));

	int vlanmap[6] = { 0, 1, 2, 3, 4, 5 };	// 0=wan; 1,2,3,4=lan;
	// 5=internal 

	if (nvram_match("vlan1ports", "0 5")) {
		vlanmap[0] = 0;
		vlanmap[5] = 5;
		if (nvram_match("vlan0ports", "4 3 2 1 5*")) {
			vlanmap[1] = 4;
			vlanmap[2] = 3;
			vlanmap[3] = 2;
			vlanmap[4] = 1;
		} else if (nvram_match("vlan0ports", "4 1 2 3 5*")) {
			vlanmap[1] = 4;
			vlanmap[2] = 1;
			vlanmap[3] = 2;
			vlanmap[4] = 3;
		} else		// nvram_match ("vlan0ports", "1 2 3 4 5*")
			// nothing to do
		{
		}
	} else if (nvram_match("vlan1ports", "4 5")) {
		vlanmap[0] = 4;
		vlanmap[5] = 5;
		if (nvram_match("vlan0ports", "0 1 2 3 5*")) {
			vlanmap[1] = 0;
			vlanmap[2] = 1;
			vlanmap[3] = 2;
			vlanmap[4] = 3;
		} else		// nvram_match ("vlan0ports", "3 2 1 0 5*")
		{
			vlanmap[1] = 3;
			vlanmap[2] = 2;
			vlanmap[3] = 1;
			vlanmap[4] = 0;
		}
	} else if (nvram_match("vlan1ports", "1 5")) {	// Linksys WTR54GS
		vlanmap[5] = 5;
		vlanmap[0] = 1;
		vlanmap[1] = 0;
	} else if (nvram_match("vlan2ports", "0 8")) {
		vlanmap[0] = 0;
		vlanmap[5] = 8;
		if (nvram_match("vlan1ports", "4 3 2 1 8*")) {
			vlanmap[1] = 4;
			vlanmap[2] = 3;
			vlanmap[3] = 2;
			vlanmap[4] = 1;
		}
	} else if (nvram_match("vlan2ports", "4 8")) {
		vlanmap[0] = 4;
		vlanmap[5] = 8;
		if (nvram_match("vlan1ports", "0 1 2 3 8*")) {
			vlanmap[1] = 0;
			vlanmap[2] = 1;
			vlanmap[3] = 2;
			vlanmap[4] = 3;
		} else		// "3 2 1 0 8*"
		{
			vlanmap[1] = 3;
			vlanmap[2] = 2;
			vlanmap[3] = 1;
			vlanmap[4] = 0;
		}
	} else if (nvram_match("vlan1ports", "4 8")) {
		vlanmap[0] = 4;
		vlanmap[5] = 8;
		if (nvram_match("vlan2ports", "0 1 2 3 8*")) {
			vlanmap[1] = 0;
			vlanmap[2] = 1;
			vlanmap[3] = 2;
			vlanmap[4] = 3;
		}
	} else if (nvram_match("vlan2ports", "4 5")) {
		vlanmap[0] = 4;
		vlanmap[5] = 5;
		if (nvram_match("vlan1ports", "0 1 2 3 5*")) {
			vlanmap[1] = 0;
			vlanmap[2] = 1;
			vlanmap[3] = 2;
			vlanmap[4] = 3;
		} else		// nvram_match ("vlan1ports", "3 2 1 0 5*")
		{
			vlanmap[1] = 3;
			vlanmap[2] = 2;
			vlanmap[3] = 1;
			vlanmap[4] = 0;
		}

	}
	// else ....

	int ast = 0;
	char *asttemp;
	char *lanifnames = nvram_safe_get("lan_ifnames");

	if (strstr(lanifnames, "vlan1") && !strstr(lanifnames, "vlan0"))
		asttemp = nvram_safe_get("vlan1ports");
	else if (strstr(lanifnames, "vlan2") && !strstr(lanifnames, "vlan0")
		 && !strstr(lanifnames, "vlan1"))
		asttemp = nvram_safe_get("vlan2ports");
	else
		asttemp = nvram_safe_get("vlan0ports");

	if (strstr(asttemp, "5*") || strstr(asttemp, "8*"))
		ast = 1;

	memset(&portsettings[0][0], 0, 16 * 64);
	memset(&tagged[0], 0, 16);
	for (i = 0; i < 6; i++) {
		vlans = nvram_nget("port%dvlans", i);
		int use = vlanmap[i];

		if (vlans) {
			int lastvlan = 0;
			int portmask = 3;
			int mask = 0;

			foreach(vlan, vlans, next) {
				tmp = atoi(vlan);
				if (tmp < 16) {
					lastvlan = tmp;
					if (i == 5) {
						snprintf(buff, 9, "%d", tmp);
						eval("vconfig", "set_name_type",
						     "VLAN_PLUS_VID_NO_PAD");
						eval("vconfig", "add", phy,
						     buff);
						snprintf(buff, 9, "vlan%d",
							 tmp);
						if (strcmp
						    (nvram_safe_get
						     ("wan_ifname"), buff)) {
							if (strlen
							    (nvram_nget
							     ("%s_ipaddr",
							      buff)) > 0)
								eval("ifconfig",
								     buff,
								     nvram_nget
								     ("%s_ipaddr",
								      buff),
								     "netmask",
								     nvram_nget
								     ("%s_netmask",
								      buff),
								     "up");
							else
								eval("ifconfig",
								     buff,
								     "0.0.0.0",
								     "up");
						}
					}

					sprintf((char *)&portsettings[tmp][0],
						"%s %d",
						(char *)&portsettings[tmp][0],
						use);
				} else {
					if (tmp == 16)	// vlan tagged
						tagged[use] = 1;
					if (tmp == 17)	// no auto negotiate
						mask |= 4;
					if (tmp == 18)	// no full speed
						mask |= 1;
					if (tmp == 19)	// no full duplex
						mask |= 2;
					if (tmp == 20)	// disabled
						mask |= 8;
					if (tmp == 21)	// no gigabit
						mask |= 16;

				}
			}
			if (mask & 8 && use < 5) {
				writevaproc("0",
					    "/proc/switch/%s/port/%d/enable",
					    phy, use);
			} else {
				writevaproc("1",
					    "/proc/switch/%s/port/%d/enable",
					    phy, use);
			}
			if (use < 5) {
				snprintf(buff, 69,
					 "/proc/switch/%s/port/%d/media", phy,
					 use);
				if ((fp = fopen(buff, "r+"))) {
					if ((mask & 4) == 4) {
						if (!(mask & 16)) {
							if (mask & 2)
								fputs("1000HD",
								      fp);
							else
								fputs("1000FD",
								      fp);

						} else {
							switch (mask & 3) {
							case 0:
								fputs("100FD",
								      fp);
								break;
							case 1:
								fputs("10FD",
								      fp);
								break;
							case 2:
								fputs("100HD",
								      fp);
								break;
							case 3:
								fputs("10HD",
								      fp);
								break;
							}
						}
					} else {
						fprintf(stderr,
							"set port %d to AUTO\n",
							use);
						fputs("AUTO", fp);
					}
					fclose(fp);
				}
			}

		}
	}
コード例 #2
0
int svqos_set_ports(void)
{
#ifndef HAVE_XSCALE
#ifndef HAVE_MAGICBOX
#ifndef HAVE_RB600
#ifndef HAVE_FONERA
#ifndef HAVE_RT2880
#ifndef HAVE_LS2
#ifndef HAVE_LS5
#ifndef HAVE_WHRAG108
#ifndef HAVE_CA8
#ifndef HAVE_SOLO51
#ifndef HAVE_X86
#ifndef HAVE_LAGUNA
#ifndef HAVE_VENTANA
#ifndef HAVE_TW6600
#ifndef HAVE_PB42
#ifndef HAVE_LSX
#ifndef HAVE_DANUBE
#ifndef HAVE_STORM
#ifndef HAVE_OPENRISC
#ifndef HAVE_ADM5120
	if (nvram_match("portprio_support", "1")) {
		int loop = 1;
		char nvram_var[32] = {
			0
		}, *level;

		svqos_reset_ports();

		for (loop = 1; loop < 5; loop++) {
			snprintf(nvram_var, 31, "svqos_port%dbw", loop);

			if (strcmp("0", nvram_safe_get(nvram_var)))
				writevaproc(nvram_safe_get(nvram_var), "/proc/switch/eth0/port/%d/bandwidth", loop);
			else
				writevaproc("0", "/proc/switch/eth0/port/%d/enable", loop);

			writevaproc("1", "/proc/switch/eth0/port/%d/prio-enable", loop);
			level = nvram_nget("svqos_port%dprio", loop);
			char lvl[32];
			sprintf(lvl, "%d", atoi(level) / 10 - 1);
			writevaproc(lvl, "/proc/switch/eth0/port/%d/prio", loop);
		}
	}
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif

	return 0;
}
コード例 #3
0
/*
 * configure vlan interface(s) based on nvram settings 
 */
void start_config_vlan(void)
{
	int s;
	struct ifreq ifr;
	int i, j;
	char ea[ETHER_ADDR_LEN];
	char *phy = getPhyDev();

	// configure ports
	writevaproc("1", "/proc/switch/%s/reset", phy);
	writevaproc("1", "/proc/switch/%s/enable_vlan", phy);
	for (i = 0; i < 16; i++) {
		char vlanb[16];

		sprintf(vlanb, "vlan%dports", i);
		if (nvram_get(vlanb) == NULL || nvram_match(vlanb, ""))
			continue;
		writevaproc(nvram_safe_get(vlanb),
			    "/proc/switch/%s/vlan/%d/ports", phy, i);
	}

	/*
	 * set vlan i/f name to style "vlan<ID>" 
	 */

	eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD");

	/*
	 * create vlan interfaces 
	 */
	if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
		return;

	for (i = 0; i < MAX_VLAN_GROUPS; i++) {
		char vlan_id[16];
		char *hwname, *hwaddr;

		if (!(hwname = nvram_nget("vlan%dhwname", i))) {
			continue;
		}
		if (!(hwaddr = nvram_nget("%smacaddr", hwname))) {
			continue;
		}
		if (strlen(hwname) == 0 || strlen(hwaddr) == 0) {
			continue;
		}
		ether_atoe(hwaddr, ea);
		for (j = 1; j <= MAX_DEV_IFINDEX; j++) {
			ifr.ifr_ifindex = j;
			if (ioctl(s, SIOCGIFNAME, &ifr)) {
				continue;
			}
			if (ioctl(s, SIOCGIFHWADDR, &ifr)) {
				continue;
			}
			if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
				continue;
			}
			if (!bcmp(ifr.ifr_hwaddr.sa_data, ea, ETHER_ADDR_LEN)) {
				break;
			}
		}
		if (j > MAX_DEV_IFINDEX) {
			continue;
		}
		if (ioctl(s, SIOCGIFFLAGS, &ifr))
			continue;
		if (!(ifr.ifr_flags & IFF_UP))
			eval("ifconfig", ifr.ifr_name, "0.0.0.0", "up");
		snprintf(vlan_id, sizeof(vlan_id), "%d", i);
		eval("vconfig", "add", ifr.ifr_name, vlan_id);
	}

	close(s);

	return;
}