Rebased from upstream / out of band repository.
[librecmc/librecmc.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         local rv=0
30
31         init_switch
32         ubus call network reload || rv=1
33         /sbin/wifi reload_legacy
34         return $rv
35 }
36
37 stop_service() {
38         /sbin/wifi down
39         ifdown -a
40         sleep 1
41 }
42
43 service_running() {
44         ubus -t 30 wait_for network.interface
45         /sbin/wifi reload_legacy
46 }
47
48 validate_atm_bridge_section()
49 {
50         uci_validate_section network "atm-bridge" "${1}" \
51                 'unit:uinteger:0' \
52                 'vci:range(32, 65535):35' \
53                 'vpi:range(0, 255):8' \
54                 'atmdev:uinteger:0' \
55                 'encaps:or("llc", "vc"):llc' \
56                 'payload:or("bridged", "routed"):bridged'
57 }
58
59 validate_route_section()
60 {
61         uci_validate_section network route "${1}" \
62                 'interface:string' \
63                 'target:cidr4' \
64                 'netmask:netmask4' \
65                 'gateway:ip4addr' \
66                 'metric:uinteger' \
67                 'mtu:uinteger' \
68                 'table:or(range(0,65535),string)'
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
82 validate_rule_section()
83 {
84         uci_validate_section network rule "${1}" \
85                 'in:string' \
86                 'out:string' \
87                 'src:cidr4' \
88                 'dest:cidr4' \
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
97 validate_rule6_section()
98 {
99         uci_validate_section network rule6 "${1}" \
100                 'in:string' \
101                 'out:string' \
102                 'src:cidr6' \
103                 'dest:cidr6' \
104                 'tos:range(0,31)' \
105                 'mark:string' \
106                 'invert:bool' \
107                 'lookup:or(range(0,65535),string)' \
108                 'goto:range(0,65535)' \
109                 'action:or("prohibit", "unreachable", "blackhole", "throw")'
110 }
111
112 validate_switch_section()
113 {
114         uci_validate_section network switch "${1}" \
115                 'name:string' \
116                 'enable:bool' \
117                 'enable_vlan:bool' \
118                 'reset:bool'
119 }
120
121 validate_switch_vlan()
122 {
123         uci_validate_section network switch_vlan "${1}" \
124                 'device:string' \
125                 'vlan:uinteger' \
126                 'ports:list(ports)'
127 }
128
129 service_triggers()
130 {
131         procd_add_reload_trigger network wireless
132
133         procd_open_validate
134         validate_atm_bridge_section
135         validate_route_section
136         [ -e /proc/sys/net/ipv6 ] && validate_route6_section
137         validate_rule_section
138         [ -e /proc/sys/net/ipv6 ] && validate_rule6_section
139         validate_switch_section
140         validate_switch_vlan
141         procd_close_validate
142 }
143
144 shutdown() {
145         ifdown -a
146         sleep 1
147 }