02_network 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. #!/bin/sh
  2. . /lib/functions.sh
  3. . /lib/ramips.sh
  4. . /lib/functions/uci-defaults.sh
  5. . /lib/functions/system.sh
  6. ramips_setup_rt3x5x_vlans()
  7. {
  8. if [ ! -x /sbin/swconfig ]; then
  9. # legacy default
  10. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  11. return
  12. fi
  13. local wanports=""
  14. local lanports=""
  15. for port in 5 4 3 2 1 0; do
  16. if [ `swconfig dev rt305x port $port get disable` = "1" ]; then
  17. continue
  18. fi
  19. if [ `swconfig dev rt305x port $port get lan` = "0" ]; then
  20. wanports="$port:wan $wanports"
  21. else
  22. lanports="$port:lan $lanports"
  23. fi
  24. done
  25. ucidef_add_switch "rt305x" $lanports $wanports "6t@eth0"
  26. }
  27. ramips_setup_interfaces()
  28. {
  29. local board="$1"
  30. case $board in
  31. 11acnas|\
  32. w2914nsv2)
  33. ucidef_add_switch "switch0" \
  34. "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4:wan:5" "6@eth0"
  35. ;;
  36. 3g150b|\
  37. 3g300m|\
  38. a5-v11|\
  39. all0256n|\
  40. all5002|\
  41. all5003|\
  42. broadway|\
  43. dcs-930|\
  44. dcs-930l-b1|\
  45. ht-tm02|\
  46. linkits7688 | \
  47. linkits7688d | \
  48. m2m|\
  49. microwrt|\
  50. mpr-a2|\
  51. ncs601w|\
  52. omega2 | \
  53. omega2p | \
  54. timecloud|\
  55. w150m|\
  56. widora-neo|\
  57. wnce2001|\
  58. zbt-cpe102|\
  59. zte-q7)
  60. ucidef_add_switch "switch0"
  61. ucidef_add_switch_attr "switch0" "enable" "false"
  62. ucidef_set_interface_lan "eth0"
  63. ;;
  64. mlw221|\
  65. mr-102n)
  66. ucidef_set_interface_lan "eth0.2"
  67. ;;
  68. 3g-6200n|\
  69. ac1200pro|\
  70. ai-br100|\
  71. d240|\
  72. db-wrt01|\
  73. dir-300-b7|\
  74. dir-320-b1|\
  75. dir-610-a1|\
  76. dir-615-h1|\
  77. firewrt|\
  78. hlk-rm04|\
  79. mac1200rv2|\
  80. miwifi-mini|\
  81. miwifi-nano|\
  82. mt7621|\
  83. mt7628|\
  84. mzk-750dhp|\
  85. mzk-w300nh2|\
  86. nixcore|\
  87. oy-0001|\
  88. pbr-m1|\
  89. psg1208|\
  90. psg1218|\
  91. sap-g3200u3|\
  92. sk-wb8|\
  93. vr500|\
  94. wf-2881|\
  95. witi|\
  96. wl-wn575a3|\
  97. wndr3700v5|\
  98. wt1520|\
  99. youku-yk1|\
  100. zbt-ape522ii|\
  101. zbt-we826|\
  102. zbt-wg2626|\
  103. zbt-wg3526|\
  104. zbt-wr8305rt)
  105. ucidef_add_switch "switch0" \
  106. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
  107. ;;
  108. whr-300hp2|\
  109. whr-600d|\
  110. wsr-1166|\
  111. wsr-600)
  112. ucidef_add_switch "switch0" \
  113. "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "4:wan:5" "6@eth0"
  114. ;;
  115. ar670w|\
  116. ar725w|\
  117. rt-n15|\
  118. wl-351)
  119. ucidef_add_switch "switch0" \
  120. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
  121. ;;
  122. asl26555|\
  123. rp-n53)
  124. ucidef_add_switch "switch0" \
  125. "1:lan" "2:lan" "3:lan" "4:lan" "6t@eth0"
  126. ;;
  127. atp-52b|\
  128. awm002-evb|\
  129. awm003-evb|\
  130. c20i|\
  131. dir-645|\
  132. f5d8235-v2|\
  133. gl-mt300a|\
  134. gl-mt300n|\
  135. gl-mt750|\
  136. hg255d|\
  137. jhr-n805r|\
  138. jhr-n825r|\
  139. jhr-n926r|\
  140. mzk-wdpr|\
  141. rb750gr3|\
  142. rt-n14u|\
  143. ubnt-erx|\
  144. ur-326n4g|\
  145. wrtnode|\
  146. wrtnode2p | \
  147. wrtnode2r | \
  148. wt3020|\
  149. zbt-wa05)
  150. ucidef_add_switch "switch0" \
  151. "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "6@eth0"
  152. ;;
  153. awapn2403)
  154. ucidef_add_switch "switch0" \
  155. "0:lan" "1:wan" "6@eth0"
  156. ;;
  157. b2c|\
  158. nw718|\
  159. psr-680w|\
  160. sl-r7205|\
  161. ur-336un|\
  162. w502u|\
  163. wr6202)
  164. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  165. ;;
  166. br-6475nd)
  167. ucidef_add_switch "switch0" \
  168. "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
  169. ;;
  170. cf-wr800n|\
  171. ex2700)
  172. ucidef_add_switch "switch0" \
  173. "4:lan" "6t@eth0"
  174. ;;
  175. cy-swr1100)
  176. ucidef_add_switch "switch0" \
  177. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "9@eth0"
  178. ;;
  179. cs-qr10|\
  180. d105|\
  181. dch-m225|\
  182. hpm|\
  183. mzk-ex300np|\
  184. mzk-ex750np|\
  185. na930|\
  186. pbr-d1|\
  187. wli-tx4-ag300n|\
  188. wmr-300|\
  189. wn3000rpv3|\
  190. wrh-300cr)
  191. ucidef_set_interface_lan "eth0"
  192. ;;
  193. c50)
  194. ucidef_add_switch "switch0" \
  195. "1:lan:3" "2:lan:4" "3:lan:1" "4:lan:2" "0:wan" "6@eth0"
  196. ;;
  197. dir-860l-b1)
  198. ucidef_add_switch "switch0" \
  199. "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "0:wan" "6@eth0"
  200. ;;
  201. duzun-dm06)
  202. ucidef_add_switch "switch0" \
  203. "1:lan" "0:wan" "6@eth0"
  204. ;;
  205. e1700|\
  206. mt7620a_mt7530)
  207. ucidef_add_switch "switch1" \
  208. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
  209. ;;
  210. hc5*61|\
  211. y1s)
  212. ucidef_add_switch "switch0" \
  213. "1:lan" "2:lan" "3:lan" "4:lan" "5:lan" "0:wan" "6@eth0"
  214. ;;
  215. kn_rc|\
  216. kn_rf)
  217. ucidef_add_switch "switch0" \
  218. "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "6@eth0"
  219. ;;
  220. kng_rc)
  221. ucidef_add_switch "switch1" \
  222. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "7t@eth0"
  223. ;;
  224. mlwg2|\
  225. wizard8800|\
  226. wl-330n)
  227. ucidef_set_interface_lan "eth0.1"
  228. ;;
  229. mr200)
  230. ucidef_add_switch "switch0" \
  231. "0:lan" "1:lan" "2:lan" "3:lan" "6t@eth0"
  232. ucidef_set_interface_wan "usb0"
  233. ;;
  234. mzk-dp150n|\
  235. vocore)
  236. ucidef_add_switch "switch0" \
  237. "0:lan" "4:lan" "6t@eth0"
  238. ;;
  239. newifi-d1)
  240. ucidef_add_switch "switch0" \
  241. "1:lan:2" "2:lan:1" "4:wan" "6@eth0"
  242. ;;
  243. re6500)
  244. ucidef_add_switch "switch0" \
  245. "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "6@eth0"
  246. ;;
  247. rt-n56u)
  248. ucidef_add_switch "switch0" \
  249. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "8@eth0"
  250. ;;
  251. tew-691gr|\
  252. tew-692gr|\
  253. wlr-6000)
  254. ucidef_add_switch "switch0" \
  255. "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "0@eth0"
  256. ;;
  257. vocore2)
  258. ucidef_add_switch "switch0" \
  259. "0:lan" "2:lan" "6t@eth0"
  260. ;;
  261. f5d8235-v1|\
  262. tew-714tru|\
  263. v11st-fe|\
  264. wzr-agl300nh)
  265. ucidef_add_switch "switch0" \
  266. "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
  267. ;;
  268. wcr-150gn)
  269. ucidef_add_switch "switch0" \
  270. "0:lan" "6t@eth0"
  271. ;;
  272. whr-1166d)
  273. ucidef_add_switch "switch0" \
  274. "0:lan" "1:lan" "2:lan" "3:lan" "5:wan" "6@eth0"
  275. ;;
  276. wizfi630a)
  277. ucidef_add_switch "switch0" \
  278. "1:lan" "2:lan" "0:wan" "6@eth0"
  279. ;;
  280. y1)
  281. ucidef_add_switch "switch0" \
  282. "0:lan:2" "1:lan:1" "4:wan" "6@eth0"
  283. ;;
  284. *)
  285. RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
  286. if [ -n "${RT3X5X}" ]; then
  287. ramips_setup_rt3x5x_vlans
  288. else
  289. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  290. fi
  291. ;;
  292. esac
  293. }
  294. ramips_setup_macs()
  295. {
  296. local board="$1"
  297. local lan_mac=""
  298. local wan_mac=""
  299. case $board in
  300. a5-v11|\
  301. ht-tm02)
  302. lan_mac=$(cat /sys/class/net/eth0/address)
  303. ;;
  304. all0239-3g|\
  305. carambola|\
  306. freestation5|\
  307. w502u|\
  308. wnce2001)
  309. wan_mac=$(mtd_get_mac_binary factory 46)
  310. ;;
  311. bc2|\
  312. broadway|\
  313. d105|\
  314. dir-300-b7|\
  315. dir-320-b1|\
  316. dir-620-a1|\
  317. esr-9753|\
  318. freestation5|\
  319. hlk-rm04|\
  320. mpr-a1|\
  321. psr-680w|\
  322. sl-r7205|\
  323. y1|\
  324. y1s)
  325. lan_mac=$(cat /sys/class/net/eth0/address)
  326. lan_mac=$(macaddr_setbit_la "$lan_mac")
  327. wan_mac=$(macaddr_add "$lan_mac" 1)
  328. ;;
  329. br-6475nd)
  330. lan_mac=$(cat /sys/class/net/eth0/address)
  331. wan_mac=$(mtd_get_mac_binary devdata 7)
  332. ;;
  333. cy-swr1100|\
  334. dch-m225)
  335. lan_mac=$(mtd_get_mac_ascii factory lanmac)
  336. ;;
  337. dir-645)
  338. lan_mac=$(mtd_get_mac_ascii nvram lanmac)
  339. wan_mac=$(mtd_get_mac_ascii nvram wanmac)
  340. ;;
  341. dir-860l-b1)
  342. lan_mac=$(mtd_get_mac_ascii factory lanmac)
  343. wan_mac=$(mtd_get_mac_ascii factory wanmac)
  344. ;;
  345. e1700)
  346. wan_mac=$(mtd_get_mac_ascii config WAN_MAC_ADDR)
  347. ;;
  348. hc5*61)
  349. lan_mac=`mtd_get_mac_ascii bdinfo "Vfac_mac "`
  350. [ -n "$lan_mac" ] || lan_mac=$(cat /sys/class/net/eth0/address)
  351. wan_mac=$(macaddr_add "$lan_mac" 1)
  352. ;;
  353. kn_rc|\
  354. kn_rf|\
  355. kng_rc)
  356. wan_mac=$(mtd_get_mac_binary factory 40)
  357. ;;
  358. linkits7688 | \
  359. linkits7688d)
  360. wan_mac=$(mtd_get_mac_binary factory 4)
  361. lan_mac=$(mtd_get_mac_binary factory 46)
  362. ;;
  363. mac1200rv2)
  364. lan_mac=$(mtd_get_mac_binary factory_info 13)
  365. wan_mac=$(macaddr_add "$lan_mac" 1)
  366. ;;
  367. miwifi-mini)
  368. wan_mac=$(cat /sys/class/net/eth0/address)
  369. lan_mac=$(macaddr_setbit_la "$wan_mac")
  370. ;;
  371. m3|\
  372. m4|\
  373. x5|\
  374. x8)
  375. lan_mac=$(cat /sys/class/net/eth0/address)
  376. lan_mac=$(macaddr_add "$lan_mac" -2)
  377. ;;
  378. newifi-d1)
  379. lan_mac=$(cat /sys/class/net/eth0/address)
  380. lan_mac=$(macaddr_add "$lan_mac" 2)
  381. ;;
  382. omega2|\
  383. omega2p)
  384. wan_mac=$(mtd_get_mac_binary factory 4)
  385. lan_mac=$(mtd_get_mac_binary factory 46)
  386. ;;
  387. oy-0001)
  388. lan_mac=$(mtd_get_mac_binary factory 40)
  389. wan_mac=$(mtd_get_mac_binary factory 46)
  390. ;;
  391. rt-n56u)
  392. lan_mac=$(cat /sys/class/net/eth0/address)
  393. lan_mac=$(macaddr_setbit_la "$lan_mac")
  394. wan_mac=$(mtd_get_mac_binary factory 32772)
  395. ;;
  396. sk-wb8)
  397. wan_mac=$(mtd_get_mac_binary factory 57350)
  398. ;;
  399. tew-691gr)
  400. wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 4)" 3)
  401. ;;
  402. tew-692gr)
  403. wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 4)" 1)
  404. ;;
  405. tiny-ac)
  406. lan_mac=$(mtd_get_mac_ascii u-boot-env LAN_MAC_ADDR)
  407. wan_mac=$(mtd_get_mac_ascii u-boot-env WAN_MAC_ADDR)
  408. ;;
  409. vr500)
  410. lan_mac=$(mtd_get_mac_binary factory 57344)
  411. wan_mac=$(mtd_get_mac_binary factory 57350)
  412. ;;
  413. w306r-v20)
  414. lan_mac=$(cat /sys/class/net/eth0/address)
  415. wan_mac=$(macaddr_add "$lan_mac" 5)
  416. ;;
  417. wcr-150gn)
  418. wan_mac=$(mtd_get_mac_binary factory 40)
  419. ;;
  420. whr-1166d|\
  421. whr-300hp2|\
  422. whr-600d|\
  423. wsr-600)
  424. wan_mac=$(mtd_get_mac_binary factory 4)
  425. lan_mac=$wan_mac
  426. ;;
  427. wizfi630a)
  428. lan_mac=$(mtd_get_mac_binary factory 4)
  429. wan_mac=$(mtd_get_mac_binary factory 40)
  430. ;;
  431. wlr-6000)
  432. wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 32772)" 2)
  433. ;;
  434. wsr-1166)
  435. local index="$(find_mtd_index "board_data")"
  436. wan_mac="$(grep -m1 mac= "/dev/mtd${index}" | cut -d= -f2)"
  437. lan_mac=$wan_mac
  438. ;;
  439. *)
  440. lan_mac=$(cat /sys/class/net/eth0/address)
  441. wan_mac=$(macaddr_add "$lan_mac" 1)
  442. ;;
  443. esac
  444. [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
  445. [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
  446. }
  447. board_config_update
  448. board=$(ramips_board_name)
  449. ramips_setup_interfaces $board
  450. ramips_setup_macs $board
  451. board_config_flush
  452. exit 0