netifd: Fix possible hotplug race conditions
[project/netifd.git] / scripts / netifd-proto.sh
old mode 100755 (executable)
new mode 100644 (file)
index 76dcd8d..b5ef3d1
@@ -4,15 +4,15 @@ NETIFD_MAIN_DIR="${NETIFD_MAIN_DIR:-/lib/netifd}"
 . $NETIFD_MAIN_DIR/utils.sh
 
 proto_config_add_int() {
-       _config_add_generic "$1" 5
+       config_add_int "$@"
 }
 
 proto_config_add_string() {
-       _config_add_generic "$1" 3
+       config_add_string "$@"
 }
 
 proto_config_add_boolean() {
-       _config_add_generic "$1" 7
+       config_add_boolean "$@"
 }
 
 _proto_do_teardown() {
@@ -20,6 +20,11 @@ _proto_do_teardown() {
        eval "proto_$1_teardown \"$interface\" \"$ifname\""
 }
 
+_proto_do_renew() {
+       json_load "$data"
+       eval "proto_$1_renew \"$interface\" \"$ifname\""
+}
+
 _proto_do_setup() {
        json_load "$data"
        _EXPORT_VAR=0
@@ -106,16 +111,18 @@ proto_add_ipv6_address() {
        local preferred="$3"
        local valid="$4"
        local offlink="$5"
+       local class="$6"
 
-       append PROTO_IP6ADDR "$address/$mask/$preferred/$valid/$offlink"
+       append PROTO_IP6ADDR "$address/$mask/$preferred/$valid/$offlink/$class"
 }
 
 proto_add_ipv4_route() {
        local target="$1"
        local mask="$2"
        local gw="$3"
+       local source="$4"
 
-       append PROTO_ROUTE "$target/$mask/$gw//"
+       append PROTO_ROUTE "$target/$mask/$gw///$source"
 }
 
 proto_add_ipv6_route() {
@@ -175,6 +182,8 @@ _proto_push_ipv6_addr() {
        valid="${str%%/*}"
        str="${str#*/}"
        offlink="${str%%/*}"
+       str="${str#*/}"
+       class="${str%%/*}"
 
        json_add_object ""
        json_add_string ipaddr "$address"
@@ -182,6 +191,7 @@ _proto_push_ipv6_addr() {
        [ -n "$preferred" ] && json_add_int preferred "$preferred"
        [ -n "$valid" ] && json_add_int valid "$valid"
        [ -n "$offlink" ] && json_add_boolean offlink "$offlink"
+       [ -n "$class" ] && json_add_string class "$class"
        json_close_object
 }
 
@@ -348,6 +358,7 @@ init_proto() {
                        add_protocol() {
                                no_device=0
                                available=0
+                               renew_handler=0
 
                                add_default_handler "proto_$1_init_config"
 
@@ -358,10 +369,11 @@ init_proto() {
                                json_close_array
                                json_add_boolean no-device "$no_device"
                                json_add_boolean available "$available"
+                               json_add_boolean renew-handler "$renew_handler"
                                json_dump
                        }
                ;;
-               setup|teardown)
+               setup|teardown|renew)
                        interface="$1"; shift
                        data="$1"; shift
                        ifname="$1"; shift
@@ -372,6 +384,7 @@ init_proto() {
                                case "$cmd" in
                                        setup) _proto_do_setup "$1";;
                                        teardown) _proto_do_teardown "$1" ;;
+                                       renew) _proto_do_renew "$1" ;;
                                        *) return 1 ;;
                                esac
                        }