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