netifd: fix stopping netifd + interfaces
[openwrt/openwrt.git] / package / network / config / netifd / files / etc / init.d / network
index 848336f4faa056f0461e49dd02b24c775add7022..a825dfd31fbc805feae2ede556ddef7f728dfb72 100755 (executable)
@@ -18,9 +18,9 @@ start_service() {
        procd_open_instance
        procd_set_param command /sbin/netifd
        procd_set_param respawn
+       procd_set_param watch network.interface
        [ -e /proc/sys/kernel/core_pattern ] && {
                procd_set_param limits core="unlimited"
-               echo '/tmp/%e.%p.%s.%t.core' > /proc/sys/kernel/core_pattern
        }
        procd_close_instance
 }
@@ -33,10 +33,12 @@ reload_service() {
 
 stop_service() {
        /sbin/wifi down
+       ifdown -a
+       sleep 1
 }
 
 service_running() {
-       sleep 5
+       ubus -t 30 wait_for network.interface
        /sbin/wifi reload_legacy
 }
 
@@ -49,35 +51,29 @@ validate_atm_bridge_section()
                'atmdev:uinteger:0' \
                'encaps:or("llc", "vc"):llc' \
                'payload:or("bridged", "routed"):bridged'
-
-       return $?
 }
 
 validate_route_section()
 {
        uci_validate_section network route "${1}" \
                'interface:string' \
-               'target:ip4addr' \
-               'netmask:ip4prefix' \
+               'target:cidr4' \
+               'netmask:netmask4' \
                'gateway:ip4addr' \
                'metric:uinteger' \
                'mtu:uinteger' \
-               'table:range(0,65535)'
-
-       return $?
+               'table:or(range(0,65535),string)'
 }
 
 validate_route6_section()
 {
        uci_validate_section network route6 "${1}" \
                'interface:string' \
-               'target:ip6addr' \
+               'target:cidr6' \
                'gateway:ip6addr' \
                'metric:uinteger' \
                'mtu:uinteger' \
-               'table:range(0,65535)'
-
-       return $?
+               'table:or(range(0,65535),string)'
 }
 
 validate_rule_section()
@@ -85,16 +81,14 @@ validate_rule_section()
        uci_validate_section network rule "${1}" \
                'in:string' \
                'out:string' \
-               'src:ip4prefix' \
-               'dest:ip4prefix' \
-               'tos:rage(0.31)' \
-               'string:mark' \
+               'src:cidr4' \
+               'dest:cidr4' \
+               'tos:range(0,31)' \
+               'mark:string' \
                'invert:bool' \
-               'lookup:range(0,65535)' \
+               'lookup:or(range(0,65535),string)' \
                'goto:range(0,65535)' \
                'action:or("prohibit", "unreachable", "blackhole", "throw")'
-
-       return $?
 }
 
 validate_rule6_section()
@@ -102,16 +96,14 @@ validate_rule6_section()
        uci_validate_section network rule6 "${1}" \
                'in:string' \
                'out:string' \
-               'src:ip4prefix' \
-               'dest:ip4prefix' \
-               'tos:rage(0.31)' \
-               'string:mark' \
+               'src:cidr6' \
+               'dest:cidr6' \
+               'tos:range(0,31)' \
+               'mark:string' \
                'invert:bool' \
-               'lookup:range(0,65535)' \ 
+               'lookup:or(range(0,65535),string)' \
                'goto:range(0,65535)' \
                'action:or("prohibit", "unreachable", "blackhole", "throw")'
-
-       return $?
 }
 
 validate_switch_section()
@@ -121,8 +113,6 @@ validate_switch_section()
                'enable:bool' \
                'enable_vlan:bool' \
                'reset:bool'
-
-       return $?
 }
 
 validate_switch_vlan()
@@ -131,16 +121,11 @@ validate_switch_vlan()
                'device:string' \
                'vlan:uinteger' \
                'ports:list(ports)'
-
-       return $?
 }
 
 service_triggers()
 {
-       procd_open_trigger
-       procd_add_config_trigger "config.change" "network" /etc/init.d/network reload
-       procd_add_config_trigger "config.change" "wireless" /etc/init.d/network reload
-       procd_close_trigger
+       procd_add_reload_trigger network wireless
 
        procd_open_validate
        validate_atm_bridge_section
@@ -153,15 +138,7 @@ service_triggers()
        procd_close_validate
 }
 
-restart() {
-       ifdown -a
-       sleep 1
-       trap '' TERM
-       stop "$@"
-       start "$@"
-}
-
 shutdown() {
        ifdown -a
-       stop
+       sleep 1
 }