1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006 OpenWrt.org
7 [ -e /etc/config/network ] && {
18 append batch "delete network.eth0.${1}${N}"
19 append batch "set network.eth0_${id}=switch_vlan${N}"
20 append batch "set network.eth0_${id}.device=eth0${N}"
21 append batch "set network.eth0_${id}.vlan=${id}${N}"
22 append batch "set network.eth0_${id}.ports='${ports}'${N}"
37 logger -t netconfig "migrating switch config to new format ..."
38 echo "$batch${N}commit network" | uci batch
47 [ -e /sbin/swconfig ] && cpuport=$(swconfig dev switch0 help 2>/dev/null | sed -ne "s|.*cpu @ \([0-9]*\).*|\1|p")
49 [ -e /sbin/swconfig ] && switchname=$(swconfig dev switch0 help 2>/dev/null | sed -ne "s|switch0: \([^\\\\(]*\).*|\1|p")
50 local model=$(awk 'BEGIN{FS="[ \t]+:[ \t]"} /machine/ {print $2}' /proc/cpuinfo)
53 if grep -E 'mtd0: 000(6|a)0000' /proc/mtd 2>&- >&-; then
55 echo boardtype=wgt634u
57 strings "$(find_mtd_part nvram)"
59 ) | awk -v cpuport="$cpuport" -v model="$model" '
60 function macinc(mac, maca, i, result) {
62 for (i = 1; i <= 6; i++) maca[i] = "0x" maca[i]
63 if (++maca[6] > 0xff) {
67 for (i = 1; i <= 6; i++) {
68 if (i != 1) result = result ":"
69 result = result sprintf("%02x", maca[i])
76 c["lan_ifname"]="eth0.1"
77 c["wan_ifname"]="eth0.2"
78 c["vlan1ports"]="1 2 3 4 5t"
79 c["vlan2ports"]="0 5t"
80 for (i = 0; i < 6; i++) {
81 if (mac_check != "") mac_check = mac_check ":"
82 mac_check = mac_check "[0-9a-fA-F][0-9a-fA-F]"
85 c["vlan1ports"]="1 2 3 4 8t"
86 c["vlan2ports"]="0 8t"
90 ($1 == "boardnum") || ($1 == "boardtype") || ($1 == "boardflags") || ($1 ~ /macaddr/) || \
91 ($1 ~ /^vlan[0-9]{1,2}ports$/) {
96 if (((nvram["vlan0ports"] ~ /^0 1 2 3 8/ ) && (nvram["vlan1ports"] ~ /^4 8/ && (cpuport == "8"))) || \
97 ((nvram["vlan1ports"] ~ /^0 1 2 3 8/ ) && (nvram["vlan2ports"] ~ /^4 8/ && (cpuport == "8"))) || \
98 ((nvram["vlan2ports"] ~ /^0 1 2 3 8/ ) && (nvram["vlan1ports"] ~ /^4 8/ && (cpuport == "8")))) {
99 c["vlan1ports"] = "0 1 2 3 8t"
100 c["vlan2ports"] = "4 8t"
102 if (((nvram["vlan0ports"] ~ /^0 1 2 3 5/ ) && (nvram["vlan1ports"] ~ /^4 5/ && (cpuport == "5"))) || \
103 ((nvram["vlan1ports"] ~ /^0 1 2 3 5/ ) && (nvram["vlan2ports"] ~ /^4 5/ && (cpuport == "5"))) || \
104 ((nvram["vlan2ports"] ~ /^0 1 2 3 5/ ) && (nvram["vlan1ports"] ~ /^4 5/ && (cpuport == "5")))) {
105 c["vlan1ports"] = "0 1 2 3 5t"
106 c["vlan2ports"] = "4 5t"
108 if ((model == "Asus WLHDD") || (model == "Asus WL300G")) {
110 c["lan_ifname"] = "eth1"
112 if (model == "Asus WL330GE") {
114 c["lan_ifname"] = "eth0.1"
115 c["vlan1ports"] = "4 5t"
118 if ((model == "Asus WL500G") || (model == "Microsoft MN-700")) {
119 c["wan_ifname"] = "eth1"
120 c["lan_ifname"] = "eth0"
122 if ((model == "Asus WL500GP V2") || (model == "Buffalo WHR-G125")) {
123 c["vlan1ports"] = "0 1 2 3 5t"
124 c["vlan2ports"] = "4 5t"
126 if (model == "Dell TrueMobile 2300") {
127 c["lan_ifname"] = "eth0"
128 c["wan_ifname"] = "eth1"
129 c["vlan1ports"] = "0 1 2 3 4 5"
132 if (nvram["boardtype"] == "bcm94710r4") {
134 c["lan_ifname"] = "eth0"
135 c["wan_ifname"] = "eth1"
137 if ((nvram["boardtype"] == "wgt634u") || (nvram["boardtype"] == "0x0467")) {
138 c["vlan1ports"] = "0 1 2 3 5t"
139 c["vlan2ports"] = "4 5t"
141 if ((nvram["boardtype"] == "0x042f") || (nvram["boardtype"] == "0x0472")) {
142 if (nvram["boardnum"] == "45") {
144 c["vlan1ports"] = "1 2 3 4 5t"
145 c["vlan2ports"] = "0 5t"
148 c["vlan1ports"] = "0 1 2 3 4 5"
150 c["lan_ifname"] = "eth0"
151 c["wan_ifname"] = "eth1"
153 # MAC addresses on 4704 tend to be screwed up. Add a workaround here
154 if (nvram["et0macaddr"] ~ mac_check) {
155 c["lan_macaddr"] = nvram["et0macaddr"]
156 c["wan_macaddr"] = macinc(c["lan_macaddr"])
160 # Buffalo WBR-B11 and Buffalo WBR-G54
161 if (nvram["boardtype"] == "bcm94710ap") {
162 c["vlan1ports"] = "0 1 2 3 4 5"
164 c["lan_ifname"] = "eth0"
165 c["wan_ifname"] = "eth1"
169 if ((nvram["boardnum"] == "2") || \
170 (nvram["boardnum"] == "1024")) {
171 c["lan_ifname"]="eth0"
176 if ((nvram["boardum"] == "2") && \
177 (nvram["GemtekPmonVer"] == "1")) {
178 c["lan_ifname"]="eth0"
183 # These are actually same as defaults above. For some reason this script applies
184 # Generic BCM94704 settings instead so we revert to proper settings here.
185 # Hopefully someone will fix this properly soon.
186 if (model == "Asus WL700") {
187 c["lan_ifname"]="eth0.1"
188 c["wan_ifname"]="eth0.2"
189 c["vlan1ports"]="1 2 3 4 5t"
190 c["vlan2ports"]="0 5t"
192 if ((model == "Motorola WR850G") || (model == "Siemens SE505 V2")) {
193 c["vlan1ports"]="0 1 2 3 5t"
194 c["vlan2ports"]="4 5t"
196 if (model == "Asus WL500W") {
197 c["lan_ifname"] = "eth0"
198 c["wan_ifname"] = "eth1"
199 c["vlan1ports"] = "0 1 2 3 4 5"
202 print "local vlan1ports=\"" c["vlan1ports"] "\";"
203 print "local vlan2ports=\"" c["vlan2ports"] "\";"
204 print "local lan_ifname=\"" c["lan_ifname"] "\";"
205 print "local lan_macaddr=\"" c["lan_macaddr"] "\";"
206 print "local wan_ifname=\"" c["wan_ifname"] "\";"
207 print "local wan_macaddr=\"" c["wan_macaddr"] "\";"
210 . /lib/functions/uci-defaults.sh
212 touch /etc/config/network
216 [ -n "$vlan1ports" -o -n "$vlan2ports" ] && {
217 local cfg=`ucidef_add_switch "$switchname" 1 1`
218 [ -n "$cfg" ] && uci rename network.$cfg=eth0
219 [ -n "$vlan1ports" ] && {
220 cfg=`ucidef_add_switch_vlan "$switchname" 1 "$vlan1ports"`
221 [ -n "$cfg" ] && uci rename network.$cfg=eth0_1
223 [ -n "$vlan2ports" ] && {
224 cfg=`ucidef_add_switch_vlan "$switchname" 2 "$vlan2ports"`
225 [ -n "$cfg" ] && uci rename network.$cfg=eth0_2
229 ucidef_set_interface_loopback
231 ucidef_set_interface_lan "$lan_ifname"
232 [ -n "$lan_macaddr" ] && ucidef_set_interface_macaddr lan "$lan_macaddr"
234 [ -n "$wan_ifname" ] && {
235 ucidef_set_interface_wan "$wan_ifname"
236 [ -n "$wan_macaddr" ] && ucidef_set_interface_macaddr wan "$wan_macaddr"