fbba9ecb1ccc8673bc0d88be385dbba022126c6b
[openwrt/staging/chunkeey.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() {
36 /sbin/wifi down
37 procd_kill network ''
38 }
39
40 service_running() {
41 ubus -t 30 wait_for network.interface
42 /sbin/wifi reload_legacy
43 }
44
45 validate_atm_bridge_section()
46 {
47 uci_validate_section network "atm-bridge" "${1}" \
48 'unit:uinteger:0' \
49 'vci:range(32, 65535):35' \
50 'vpi:range(0, 255):8' \
51 'atmdev:uinteger:0' \
52 'encaps:or("llc", "vc"):llc' \
53 'payload:or("bridged", "routed"):bridged'
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
68 validate_route6_section()
69 {
70 uci_validate_section network route6 "${1}" \
71 'interface:string' \
72 'target:cidr6' \
73 'gateway:ip6addr' \
74 'metric:uinteger' \
75 'mtu:uinteger' \
76 'table:or(range(0,65535),string)'
77 }
78
79 validate_rule_section()
80 {
81 uci_validate_section network rule "${1}" \
82 'in:string' \
83 'out:string' \
84 'src:cidr4' \
85 'dest:cidr4' \
86 'tos:range(0,31)' \
87 'mark:string' \
88 'invert:bool' \
89 'lookup:or(range(0,65535),string)' \
90 'goto:range(0,65535)' \
91 'action:or("prohibit", "unreachable", "blackhole", "throw")'
92 }
93
94 validate_rule6_section()
95 {
96 uci_validate_section network rule6 "${1}" \
97 'in:string' \
98 'out:string' \
99 'src:cidr6' \
100 'dest:cidr6' \
101 'tos:range(0,31)' \
102 'mark:string' \
103 'invert:bool' \
104 'lookup:or(range(0,65535),string)' \
105 'goto:range(0,65535)' \
106 'action:or("prohibit", "unreachable", "blackhole", "throw")'
107 }
108
109 validate_switch_section()
110 {
111 uci_validate_section network switch "${1}" \
112 'name:string' \
113 'enable:bool' \
114 'enable_vlan:bool' \
115 'reset:bool'
116 }
117
118 validate_switch_vlan()
119 {
120 uci_validate_section network switch_vlan "${1}" \
121 'device:string' \
122 'vlan:uinteger' \
123 'ports:list(ports)'
124 }
125
126 service_triggers()
127 {
128 procd_add_reload_trigger network wireless
129
130 procd_open_validate
131 validate_atm_bridge_section
132 validate_route_section
133 validate_route6_section
134 validate_rule_section
135 validate_rule6_section
136 validate_switch_section
137 validate_switch_vlan
138 procd_close_validate
139 }
140
141 restart() {
142 ifdown -a
143 sleep 1
144 trap '' TERM
145 stop "$@"
146 start "$@"
147 }
148
149 shutdown() {
150 ifdown -a
151 stop
152 }