netifd: replace the sleep 5 with an ubus wait_for call to speed up init script
[openwrt/openwrt.git] / package / network / config / netifd / files / etc / init.d / network
1 #!/bin/sh /etc/rc.common
2
3 START=20
4 STOP=90
5
6 USE_PROCD=1
7
8 init_switch() {
9 setup_switch() { return 0; }
10
11 include /lib/network
12 setup_switch
13 }
14
15 start_service() {
16 init_switch
17
18 procd_open_instance
19 procd_set_param command /sbin/netifd
20 procd_set_param respawn
21 [ -e /proc/sys/kernel/core_pattern ] && {
22 procd_set_param limits core="unlimited"
23 echo '/tmp/%e.%p.%s.%t.core' > /proc/sys/kernel/core_pattern
24 }
25 procd_close_instance
26 }
27
28 reload_service() {
29 init_switch
30 ubus call network reload
31 /sbin/wifi reload_legacy
32 }
33
34 stop_service() {
35 /sbin/wifi down
36 }
37
38 service_running() {
39 ubus -t 30 wait_for network.interface
40 /sbin/wifi reload_legacy
41 }
42
43 validate_atm_bridge_section()
44 {
45 uci_validate_section network "atm-bridge" "${1}" \
46 'unit:uinteger:0' \
47 'vci:range(32, 65535):35' \
48 'vpi:range(0, 255):8' \
49 'atmdev:uinteger:0' \
50 'encaps:or("llc", "vc"):llc' \
51 'payload:or("bridged", "routed"):bridged'
52
53 return $?
54 }
55
56 validate_route_section()
57 {
58 uci_validate_section network route "${1}" \
59 'interface:string' \
60 'target:cidr4' \
61 'netmask:netmask4' \
62 'gateway:ip4addr' \
63 'metric:uinteger' \
64 'mtu:uinteger' \
65 'table:or(range(0,65535),string)'
66
67 return $?
68 }
69
70 validate_route6_section()
71 {
72 uci_validate_section network route6 "${1}" \
73 'interface:string' \
74 'target:cidr6' \
75 'gateway:ip6addr' \
76 'metric:uinteger' \
77 'mtu:uinteger' \
78 'table:or(range(0,65535),string)'
79
80 return $?
81 }
82
83 validate_rule_section()
84 {
85 uci_validate_section network rule "${1}" \
86 'in:string' \
87 'out:string' \
88 'src:cidr4' \
89 'dest:cidr4' \
90 'tos:range(0,31)' \
91 'mark:string' \
92 'invert:bool' \
93 'lookup:or(range(0,65535),string)' \
94 'goto:range(0,65535)' \
95 'action:or("prohibit", "unreachable", "blackhole", "throw")'
96
97 return $?
98 }
99
100 validate_rule6_section()
101 {
102 uci_validate_section network rule6 "${1}" \
103 'in:string' \
104 'out:string' \
105 'src:cidr6' \
106 'dest:cidr6' \
107 'tos:range(0,31)' \
108 'mark:string' \
109 'invert:bool' \
110 'lookup:or(range(0,65535),string)' \
111 'goto:range(0,65535)' \
112 'action:or("prohibit", "unreachable", "blackhole", "throw")'
113
114 return $?
115 }
116
117 validate_switch_section()
118 {
119 uci_validate_section network switch "${1}" \
120 'name:string' \
121 'enable:bool' \
122 'enable_vlan:bool' \
123 'reset:bool'
124
125 return $?
126 }
127
128 validate_switch_vlan()
129 {
130 uci_validate_section network switch_vlan "${1}" \
131 'device:string' \
132 'vlan:uinteger' \
133 'ports:list(ports)'
134
135 return $?
136 }
137
138 service_triggers()
139 {
140 procd_open_trigger
141 procd_add_config_trigger "config.change" "network" /etc/init.d/network reload
142 procd_add_config_trigger "config.change" "wireless" /etc/init.d/network reload
143 procd_close_trigger
144
145 procd_open_validate
146 validate_atm_bridge_section
147 validate_route_section
148 validate_route6_section
149 validate_rule_section
150 validate_rule6_section
151 validate_switch_section
152 validate_switch_vlan
153 procd_close_validate
154 }
155
156 restart() {
157 ifdown -a
158 sleep 1
159 trap '' TERM
160 stop "$@"
161 start "$@"
162 }
163
164 shutdown() {
165 ifdown -a
166 stop
167 }