netconfig 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2006 OpenWrt.org
  3. START=05
  4. start() {
  5. [ -e /etc/config/network ] && exit 0
  6. mkdir -p /etc/config
  7. (
  8. if grep -E 'mtd0: 000(6|a)0000' /proc/mtd 2>&- >&-; then
  9. # WGT634u
  10. echo boardtype=wgt634u
  11. else
  12. strings "$(find_mtd_part nvram)"
  13. fi
  14. ) | awk '
  15. function p(cfgname, name) {
  16. if (c[name] != "") print " option " cfgname " \"" c[name] "\""
  17. }
  18. function macinc(mac, maca, i, result) {
  19. split(mac, maca, ":")
  20. for (i = 1; i <= 6; i++) maca[i] = "0x" maca[i]
  21. if (++maca[6] > 0xff) {
  22. maca[5]++
  23. maca[6] = 0
  24. }
  25. for (i = 1; i <= 6; i++) {
  26. if (i != 1) result = result ":"
  27. result = result sprintf("%02x", maca[i])
  28. }
  29. return result
  30. }
  31. BEGIN {
  32. FS="="
  33. c["lan_ifname"]="eth0.0"
  34. c["wan_ifname"]="eth0.1"
  35. c["vlan0ports"]="1 2 3 4 5*"
  36. c["vlan1ports"]="0 5"
  37. getline < "/proc/diag/model"
  38. model=$0
  39. for (i = 0; i < 6; i++) {
  40. if (mac_check != "") mac_check = mac_check ":"
  41. mac_check = mac_check "[0-9a-fA-F][0-9a-fA-F]"
  42. }
  43. }
  44. ($1 == "boardnum") || ($1 == "boardtype") || ($1 == "boardflags") || ($1 ~ /macaddr/) {
  45. nvram[$1] = $2
  46. }
  47. END {
  48. if ((model == "ASUS WL-HDD") || (model == "ASUS WL-300g") || (model == "Linksys WAP54G V1")) {
  49. c["wan_ifname"] = ""
  50. c["lan_ifname"] = "eth1"
  51. }
  52. if (model == "ASUS WL-500g") {
  53. c["wan_ifname"] = "eth1"
  54. c["lan_ifname"] = "eth0"
  55. }
  56. if (model == "ASUS WL-500g Premium V2") {
  57. c["vlan0ports"] = "0 1 2 3 5*"
  58. c["vlan1ports"] = "4 5"
  59. }
  60. if (model == "Dell TrueMobile 2300") {
  61. c["vlan0ports"] = "0 1 2 3 5*"
  62. c["vlan1ports"] = "4 5"
  63. }
  64. if (nvram["boardtype"] == "bcm94710r4") {
  65. # Toshiba WRC-1000
  66. c["lan_ifname"] = "eth0"
  67. c["wan_ifname"] = "eth1"
  68. }
  69. if (nvram["boardtype"] == "wgt634u") {
  70. c["vlan0ports"] = "0 1 2 3 5*"
  71. c["vlan1ports"] = "4 5"
  72. }
  73. if (nvram["boardtype"] == "0x0467") {
  74. c["vlan0ports"] = "0 1 2 3 5*"
  75. c["vlan1ports"] = "4 5"
  76. }
  77. if ((nvram["boardtype"] == "0x042f") || (nvram["boardtype"] == "0x0472")) {
  78. if (nvram["boardnum"] == "45") {
  79. # WL-500gP
  80. c["vlan0ports"] = "1 2 3 4 5*"
  81. c["vlan1ports"] = "0 5"
  82. } else {
  83. # Generic BCM94704
  84. c["vlan0ports"] = "0 1 2 3 4 5u"
  85. c["vlan1ports"] = ""
  86. c["lan_ifname"] = "eth0"
  87. c["wan_ifname"] = "eth1"
  88. # MAC addresses on 4704 tend to be screwed up. Add a workaround here
  89. if (nvram["et0macaddr"] ~ mac_check) {
  90. c["lan_macaddr"] = nvram["et0macaddr"]
  91. c["wan_macaddr"] = macinc(c["lan_macaddr"])
  92. }
  93. }
  94. }
  95. if (nvram["boardtype"] == "0x478") {
  96. # generic broadcom 4785 processor with 5397 switch?
  97. c["vlan0ports"] = "1 2 3 4 8*"
  98. c["vlan1ports"] = "0 8"
  99. }
  100. # WAP54G
  101. if ((nvram["boardnum"] == "2") || \
  102. (nvram["boardnum"] == "1024")) {
  103. c["lan_ifname"]="eth0"
  104. c["wan_ifname"]=""
  105. }
  106. # Sitecom WL-105b
  107. if ((nvram["boardum"] == "2") && \
  108. (nvram["GemtekPmonVer"] == "1")) {
  109. c["lan_ifname"]="eth0"
  110. c["wan_ifname"]=""
  111. }
  112. # ASUS WL-700gE
  113. # These are actually same as defaults above. For some reason this script applies
  114. # Generic BCM94704 settings instead so we revert to proper settings here.
  115. # Hopefully someone will fix this properly soon.
  116. if (model == "ASUS WL-700gE") {
  117. c["lan_ifname"]="eth0.0"
  118. c["wan_ifname"]="eth0.1"
  119. c["vlan0ports"]="1 2 3 4 5*"
  120. c["vlan1ports"]="0 5"
  121. }
  122. if (model == "Motorola WR850G V2/V3") {
  123. c["vlan0ports"]="0 1 2 3 5*"
  124. c["vlan1ports"]="4 5"
  125. }
  126. if (model == "ASUS WL-500W") {
  127. c["lan_ifname"] = "eth0"
  128. c["wan_ifname"] = "eth1"
  129. c["vlan0ports"] = "0 1 2 3 4 5u"
  130. c["vlan1ports"] = ""
  131. }
  132. print "#### VLAN configuration "
  133. print "config switch eth0"
  134. p("vlan0", "vlan0ports")
  135. p("vlan1", "vlan1ports")
  136. print ""
  137. print ""
  138. print "#### Loopback configuration"
  139. print "config interface loopback"
  140. print " option ifname \"lo\""
  141. print " option proto static"
  142. print " option ipaddr 127.0.0.1"
  143. print " option netmask 255.0.0.0"
  144. print ""
  145. print ""
  146. print "#### LAN configuration"
  147. print "config interface lan"
  148. print " option type bridge"
  149. p("ifname", "lan_ifname")
  150. p("macaddr", "lan_macaddr")
  151. print " option proto static"
  152. print " option ipaddr 192.168.1.1"
  153. print " option netmask 255.255.255.0"
  154. print ""
  155. print ""
  156. print "#### WAN configuration"
  157. print "config interface wan"
  158. p("ifname", "wan_ifname")
  159. p("macaddr", "wan_macaddr")
  160. print " option proto dhcp"
  161. }' > /etc/config/network
  162. }