bdadbbce6db6f9383a0e2c7fab25e7f5d8823091
[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         }
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() {
35         /sbin/wifi down
36         procd_kill network ''
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
55 validate_route_section()
56 {
57         uci_validate_section network route "${1}" \
58                 'interface:string' \
59                 'target:cidr4' \
60                 'netmask:netmask4' \
61                 'gateway:ip4addr' \
62                 'metric:uinteger' \
63                 'mtu:uinteger' \
64                 'table:or(range(0,65535),string)'
65 }
66
67 validate_route6_section()
68 {
69         uci_validate_section network route6 "${1}" \
70                 'interface:string' \
71                 'target:cidr6' \
72                 'gateway:ip6addr' \
73                 'metric:uinteger' \
74                 'mtu:uinteger' \
75                 'table:or(range(0,65535),string)'
76 }
77
78 validate_rule_section()
79 {
80         uci_validate_section network rule "${1}" \
81                 'in:string' \
82                 'out:string' \
83                 'src:cidr4' \
84                 'dest:cidr4' \
85                 'tos:range(0,31)' \
86                 'mark:string' \
87                 'invert:bool' \
88                 'lookup:or(range(0,65535),string)' \
89                 'goto:range(0,65535)' \
90                 'action:or("prohibit", "unreachable", "blackhole", "throw")'
91 }
92
93 validate_rule6_section()
94 {
95         uci_validate_section network rule6 "${1}" \
96                 'in:string' \
97                 'out:string' \
98                 'src:cidr6' \
99                 'dest:cidr6' \
100                 'tos:range(0,31)' \
101                 'mark:string' \
102                 'invert:bool' \
103                 'lookup:or(range(0,65535),string)' \
104                 'goto:range(0,65535)' \
105                 'action:or("prohibit", "unreachable", "blackhole", "throw")'
106 }
107
108 validate_switch_section()
109 {
110         uci_validate_section network switch "${1}" \
111                 'name:string' \
112                 'enable:bool' \
113                 'enable_vlan:bool' \
114                 'reset:bool'
115 }
116
117 validate_switch_vlan()
118 {
119         uci_validate_section network switch_vlan "${1}" \
120                 'device:string' \
121                 'vlan:uinteger' \
122                 'ports:list(ports)'
123 }
124
125 service_triggers()
126 {
127         procd_add_reload_trigger network wireless
128
129         procd_open_validate
130         validate_atm_bridge_section
131         validate_route_section
132         validate_route6_section
133         validate_rule_section
134         validate_rule6_section
135         validate_switch_section
136         validate_switch_vlan
137         procd_close_validate
138 }
139
140 restart() {
141         ifdown -a
142         sleep 1
143         trap '' TERM
144         stop "$@"
145         start "$@"
146 }
147
148 shutdown() {
149         ifdown -a
150         sleep 1
151 }