02_network 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/sh
  2. #
  3. # Copyright (C) 2011 OpenWrt.org
  4. #
  5. . /lib/functions/system.sh
  6. . /lib/functions/uci-defaults.sh
  7. board_config_update
  8. board=$(cat /proc/device-tree/compatible | tr '\0' '\t' | cut -f 1)
  9. case "$board" in
  10. tenda,ac9)
  11. ucidef_add_switch "switch0" \
  12. "1:lan" "2:lan" "3:lan" "4:lan" "8@eth0" "0:wan" "5@eth1"
  13. board_config_flush
  14. exit 0
  15. ;;
  16. buffalo,wxr-1900dhp| \
  17. buffalo,wzr-1750dhp)
  18. ucidef_add_switch "switch0" \
  19. "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "4:wan:5" "5@eth0"
  20. board_config_flush
  21. exit 0
  22. ;;
  23. esac
  24. wan_macaddr="$(nvram get wan_hwaddr)"
  25. case "$board" in
  26. asus,rt-ac87u)
  27. ifname=eth1
  28. etXmacaddr=$(nvram get et1macaddr)
  29. ;;
  30. dlink,dir-885l | \
  31. netgear,r7900 | \
  32. netgear,r8000 | \
  33. netgear,r8500)
  34. ifname=eth2
  35. etXmacaddr=$(nvram get et2macaddr)
  36. ;;
  37. *)
  38. ifname=eth0
  39. etXmacaddr=$(nvram get et0macaddr)
  40. ;;
  41. esac
  42. # If WAN MAC isn't explicitly set, calculate it using base MAC as reference.
  43. [ -z "$wan_macaddr" -a -n "$etXmacaddr" ] && wan_macaddr=$(macaddr_add "$etXmacaddr" 1)
  44. # Workaround for devices using eth2 connected to (CPU) switch port 8
  45. case "$board" in
  46. dlink,dir-885l | \
  47. netgear,r7900 | \
  48. netgear,r8000 | \
  49. netgear,r8500)
  50. ifname=eth0
  51. ucidef_add_switch "switch0" \
  52. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5t@$ifname"
  53. # These devices should use eth2 so their eth0 interface often has no MAC
  54. # assigned. Manually assign eth2's MAC to the LAN.
  55. et2macaddr="$(nvram get et2macaddr)"
  56. [ -n "$et2macaddr" ] && ucidef_set_interface_macaddr "lan" "$et2macaddr"
  57. [ -n "$wan_macaddr" ] && ucidef_set_interface_macaddr "wan" "$wan_macaddr"
  58. board_config_flush
  59. exit 0
  60. ;;
  61. esac
  62. # NVRAM entries may contain unsorted ports, e.g. Netgear R6250 uses
  63. # vlan1ports=3 2 1 0 5*
  64. # vlan2ports=4 5u
  65. # and early Netgear R8000 was using
  66. # vlan1ports=3 2 1 0 5 7 8*
  67. vlan1ports="$(echo $(nvram get vlan1ports | tr " " "\n" | sort))"
  68. vlan2ports="$(echo $(nvram get vlan2ports | tr " " "\n" | sort))"
  69. if echo "$vlan1ports" | egrep -q "^1 2 3 4 5" && \
  70. echo "$vlan2ports" | egrep -q "^0 5"; then
  71. ucidef_add_switch "switch0" \
  72. "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5t@$ifname"
  73. elif echo "$vlan1ports" | egrep -q "^1 2 3 5 7" && \
  74. echo "$vlan2ports" | egrep -q "^0 7"; then
  75. ucidef_add_switch "switch0" \
  76. "1:lan" "2:lan" "3:lan" "5:lan" "0:wan" "7t@$ifname"
  77. elif echo "$vlan1ports" | egrep -q "^0 1 2 3 5 7 8" && \
  78. echo "$vlan2ports" | egrep -q "^4 8"; then
  79. ucidef_add_switch "switch0" \
  80. "0:lan" "1:lan" "2:lan" "3:lan" "5:lan" "7:lan" "4:wan" "8t@$ifname"
  81. else
  82. ucidef_add_switch "switch0" \
  83. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5t@$ifname"
  84. fi
  85. [ -n "$wan_macaddr" ] && ucidef_set_interface_macaddr "wan" "$wan_macaddr"
  86. board_config_flush
  87. exit 0