network 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/bin/sh /etc/rc.common
  2. START=20
  3. STOP=90
  4. USE_PROCD=1
  5. init_switch() {
  6. setup_switch() { return 0; }
  7. include /lib/network
  8. setup_switch
  9. }
  10. start_service() {
  11. init_switch
  12. procd_open_instance
  13. procd_set_param command /sbin/netifd
  14. procd_set_param respawn
  15. procd_set_param watch network.interface
  16. [ -e /proc/sys/kernel/core_pattern ] && {
  17. procd_set_param limits core="unlimited"
  18. }
  19. procd_close_instance
  20. }
  21. reload_service() {
  22. local rv=0
  23. init_switch
  24. ubus call network reload || rv=1
  25. /sbin/wifi reload_legacy
  26. return $rv
  27. }
  28. stop_service() {
  29. /sbin/wifi down
  30. ifdown -a
  31. sleep 1
  32. }
  33. service_running() {
  34. ubus -t 30 wait_for network.interface
  35. /sbin/wifi reload_legacy
  36. }
  37. validate_atm_bridge_section()
  38. {
  39. uci_validate_section network "atm-bridge" "${1}" \
  40. 'unit:uinteger:0' \
  41. 'vci:range(32, 65535):35' \
  42. 'vpi:range(0, 255):8' \
  43. 'atmdev:uinteger:0' \
  44. 'encaps:or("llc", "vc"):llc' \
  45. 'payload:or("bridged", "routed"):bridged'
  46. }
  47. validate_route_section()
  48. {
  49. uci_validate_section network route "${1}" \
  50. 'interface:string' \
  51. 'target:cidr4' \
  52. 'netmask:netmask4' \
  53. 'gateway:ip4addr' \
  54. 'metric:uinteger' \
  55. 'mtu:uinteger' \
  56. 'table:or(range(0,65535),string)'
  57. }
  58. validate_route6_section()
  59. {
  60. uci_validate_section network route6 "${1}" \
  61. 'interface:string' \
  62. 'target:cidr6' \
  63. 'gateway:ip6addr' \
  64. 'metric:uinteger' \
  65. 'mtu:uinteger' \
  66. 'table:or(range(0,65535),string)'
  67. }
  68. validate_rule_section()
  69. {
  70. uci_validate_section network rule "${1}" \
  71. 'in:string' \
  72. 'out:string' \
  73. 'src:cidr4' \
  74. 'dest:cidr4' \
  75. 'tos:range(0,31)' \
  76. 'mark:string' \
  77. 'invert:bool' \
  78. 'lookup:or(range(0,65535),string)' \
  79. 'goto:range(0,65535)' \
  80. 'action:or("prohibit", "unreachable", "blackhole", "throw")'
  81. }
  82. validate_rule6_section()
  83. {
  84. uci_validate_section network rule6 "${1}" \
  85. 'in:string' \
  86. 'out:string' \
  87. 'src:cidr6' \
  88. 'dest:cidr6' \
  89. 'tos:range(0,31)' \
  90. 'mark:string' \
  91. 'invert:bool' \
  92. 'lookup:or(range(0,65535),string)' \
  93. 'goto:range(0,65535)' \
  94. 'action:or("prohibit", "unreachable", "blackhole", "throw")'
  95. }
  96. validate_switch_section()
  97. {
  98. uci_validate_section network switch "${1}" \
  99. 'name:string' \
  100. 'enable:bool' \
  101. 'enable_vlan:bool' \
  102. 'reset:bool'
  103. }
  104. validate_switch_vlan()
  105. {
  106. uci_validate_section network switch_vlan "${1}" \
  107. 'device:string' \
  108. 'vlan:uinteger' \
  109. 'ports:list(ports)'
  110. }
  111. service_triggers()
  112. {
  113. procd_add_reload_trigger network wireless
  114. procd_open_validate
  115. validate_atm_bridge_section
  116. validate_route_section
  117. validate_route6_section
  118. validate_rule_section
  119. validate_rule6_section
  120. validate_switch_section
  121. validate_switch_vlan
  122. procd_close_validate
  123. }
  124. shutdown() {
  125. ifdown -a
  126. sleep 1
  127. }