[brcm-2.4] change switch config to swconfig style format to remain consistent accross...
[openwrt.git] / target / linux / brcm-2.4 / base-files / etc / init.d / netconfig
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006 OpenWrt.org
3
4 START=05
5
6 start() {
7 [ -e /etc/config/network ] && exit 0
8
9 mkdir -p /etc/config
10
11 (
12 if grep -E 'mtd0: 000(6|a)0000' /proc/mtd 2>&- >&-; then
13 # WGT634u
14 echo boardtype=wgt634u
15 else
16 strings "$(find_mtd_part nvram)"
17 fi
18 ) | awk '
19 function p(cfgname, name) {
20 if (c[name] != "") print " option " cfgname " \"" c[name] "\""
21 }
22
23 function vlan(id, name) {
24 if (c[name] != "") {
25 print "config switch_vlan eth0_" id
26 print " option device \"eth0\""
27 print " option vlan " id
28 print " option ports \"" c[name] "\""
29 print ""
30 }
31 }
32
33 function macinc(mac, maca, i, result) {
34 split(mac, maca, ":")
35 for (i = 1; i <= 6; i++) maca[i] = "0x" maca[i]
36 if (++maca[6] > 0xff) {
37 maca[5]++
38 maca[6] = 0
39 }
40 for (i = 1; i <= 6; i++) {
41 if (i != 1) result = result ":"
42 result = result sprintf("%02x", maca[i])
43 }
44 return result
45 }
46
47 BEGIN {
48 FS="="
49 c["lan_ifname"]="eth0.0"
50 c["wan_ifname"]="eth0.1"
51 c["vlan0ports"]="1 2 3 4 5*"
52 c["vlan1ports"]="0 5"
53 getline < "/proc/diag/model"
54 model=$0
55 for (i = 0; i < 6; i++) {
56 if (mac_check != "") mac_check = mac_check ":"
57 mac_check = mac_check "[0-9a-fA-F][0-9a-fA-F]"
58 }
59 }
60
61 ($1 == "boardnum") || ($1 == "boardtype") || ($1 == "boardflags") || ($1 ~ /macaddr/) {
62 nvram[$1] = $2
63 }
64
65 END {
66 if ((model == "ASUS WL-HDD") || (model == "ASUS WL-300g") || (model == "Linksys WAP54G V1")) {
67 c["wan_ifname"] = ""
68 c["lan_ifname"] = "eth1"
69 }
70 if (model == "ASUS WL-330gE") {
71 c["wan_ifname"] = ""
72 c["lan_ifname"] = "eth0"
73 c["vlan0ports"] = ""
74 c["vlan1ports"] = ""
75 }
76 if (model == "ASUS WL-500g") {
77 c["wan_ifname"] = "eth1"
78 c["lan_ifname"] = "eth0"
79 }
80 if (model == "ASUS WL-500g Premium V2") {
81 c["vlan0ports"] = "0 1 2 3 5*"
82 c["vlan1ports"] = "4 5"
83 }
84 if (model == "Dell TrueMobile 2300") {
85 c["lan_ifname"] = "eth0"
86 c["wan_ifname"] = "eth1"
87 c["vlan0ports"] = "0 1 2 3 4 5u"
88 c["vlan1ports"] = ""
89 }
90 if (model == "Dell TrueMobile 2300 v2") {
91 c["vlan0ports"] = "0 1 2 3 5*"
92 c["vlan1ports"] = "4 5"
93 }
94 if (nvram["boardtype"] == "bcm94710r4") {
95 # Toshiba WRC-1000
96 c["lan_ifname"] = "eth0"
97 c["wan_ifname"] = "eth1"
98 }
99 if (nvram["boardtype"] == "wgt634u") {
100 c["vlan0ports"] = "0 1 2 3 5*"
101 c["vlan1ports"] = "4 5"
102 }
103 if (nvram["boardtype"] == "0x0467") {
104 c["vlan0ports"] = "0 1 2 3 5*"
105 c["vlan1ports"] = "4 5"
106 }
107 if ((nvram["boardtype"] == "0x042f") || (nvram["boardtype"] == "0x0472")) {
108 if (nvram["boardnum"] == "45") {
109 # WL-500gP
110 c["vlan0ports"] = "1 2 3 4 5*"
111 c["vlan1ports"] = "0 5"
112 } else {
113 # Generic BCM94704
114 c["vlan0ports"] = "0 1 2 3 4 5u"
115 c["vlan1ports"] = ""
116 c["lan_ifname"] = "eth0"
117 c["wan_ifname"] = "eth1"
118
119 # MAC addresses on 4704 tend to be screwed up. Add a workaround here
120 if (nvram["et0macaddr"] ~ mac_check) {
121 c["lan_macaddr"] = nvram["et0macaddr"]
122 c["wan_macaddr"] = macinc(c["lan_macaddr"])
123 }
124 }
125 }
126 # Buffalo WBR-B11 and Buffalo WBR-G54
127 if (nvram["boardtype"] == "bcm94710ap") {
128 c["vlan0ports"] = "0 1 2 3 4 5u"
129 c["vlan1ports"] = ""
130 c["lan_ifname"] = "eth0"
131 c["wan_ifname"] = "eth1"
132 }
133 if (nvram["boardtype"] == "0x478") {
134 # generic broadcom 4785 processor with 5397 switch?
135 c["vlan0ports"] = "1 2 3 4 8*"
136 c["vlan1ports"] = "0 8"
137 }
138
139 # WAP54G
140 if ((nvram["boardnum"] == "2") || \
141 (nvram["boardnum"] == "1024")) {
142 c["lan_ifname"]="eth0"
143 c["wan_ifname"]=""
144 }
145
146 # Sitecom WL-105b
147 if ((nvram["boardum"] == "2") && \
148 (nvram["GemtekPmonVer"] == "1")) {
149 c["lan_ifname"]="eth0"
150 c["wan_ifname"]=""
151 }
152
153 # ASUS WL-700gE
154 # These are actually same as defaults above. For some reason this script applies
155 # Generic BCM94704 settings instead so we revert to proper settings here.
156 # Hopefully someone will fix this properly soon.
157 if (model == "ASUS WL-700gE") {
158 c["lan_ifname"]="eth0.0"
159 c["wan_ifname"]="eth0.1"
160 c["vlan0ports"]="1 2 3 4 5*"
161 c["vlan1ports"]="0 5"
162 }
163
164 if (model == "Motorola WR850G V2/V3") {
165 c["vlan0ports"]="0 1 2 3 5*"
166 c["vlan1ports"]="4 5"
167 }
168 if (model == "ASUS WL-500W") {
169 c["lan_ifname"] = "eth0"
170 c["wan_ifname"] = "eth1"
171 c["vlan0ports"] = "0 1 2 3 4 5u"
172 c["vlan1ports"] = ""
173 }
174
175 if (c["vlan0ports"] || c["vlan1ports"]) {
176 print "#### VLAN configuration "
177 print "config switch eth0"
178 print " option enable 1"
179 print ""
180 vlan(0, "vlan0ports")
181 vlan(1, "vlan1ports")
182 }
183 print "#### Loopback configuration"
184 print "config interface loopback"
185 print " option ifname \"lo\""
186 print " option proto static"
187 print " option ipaddr 127.0.0.1"
188 print " option netmask 255.0.0.0"
189 print ""
190 print ""
191 print "#### LAN configuration"
192 print "config interface lan"
193 print " option type bridge"
194 p("ifname", "lan_ifname")
195 p("macaddr", "lan_macaddr")
196 print " option proto static"
197 print " option ipaddr 192.168.1.1"
198 print " option netmask 255.255.255.0"
199 print ""
200 print ""
201 if (c["wan_ifname"]) {
202 print "#### WAN configuration"
203 print "config interface wan"
204 p("ifname", "wan_ifname")
205 p("macaddr", "wan_macaddr")
206 print " option proto dhcp"
207 } else {
208 print "#### WAN configuration (disabled)"
209 print "#config interface wan"
210 print "# option proto dhcp"
211 }
212 }' > /etc/config/network
213 }
This page took 0.053129 seconds and 5 git commands to generate.