proto-shell: allow running protocols without proto_task.
[project/netifd.git] / scripts / netifd-proto.sh
index 9f062d8..447f0f6 100644 (file)
@@ -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,19 @@ 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"
+       local metric="$5"
 
-       append PROTO_ROUTE "$target/$mask/$gw//"
+       append PROTO_ROUTE "$target/$mask/$gw/$metric///$source"
 }
 
 proto_add_ipv6_route() {
@@ -125,8 +133,9 @@ proto_add_ipv6_route() {
        local metric="$4"
        local valid="$5"
        local source="$6"
+       local table="$7"
 
-       append PROTO_ROUTE6 "$target/$mask/$gw/$metric/$valid/$source"
+       append PROTO_ROUTE6 "$target/$mask/$gw/$metric/$valid/$table/$source"
 }
 
 proto_add_ipv6_prefix() {
@@ -175,6 +184,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 +193,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
 }
 
@@ -201,6 +213,8 @@ _proto_push_route() {
        str="${str#*/}"
        local valid="${str%%/*}"
        str="${str#*/}"
+       local table="${str%%/*}"
+       str="${str#*/}"
        local source="${str}"
 
        json_add_object ""
@@ -210,6 +224,7 @@ _proto_push_route() {
        [ -n "$metric" ] && json_add_int metric "$metric"
        [ -n "$valid" ] && json_add_int valid "$valid"
        [ -n "$source" ] && json_add_string source "$source"
+       [ -n "$table" ] && json_add_string table "$table"
        json_close_object
 }
 
@@ -347,7 +362,9 @@ init_proto() {
                dump)
                        add_protocol() {
                                no_device=0
+                               no_proto_task=0
                                available=0
+                               renew_handler=0
 
                                add_default_handler "proto_$1_init_config"
 
@@ -357,11 +374,14 @@ init_proto() {
                                eval "proto_$1_init_config"
                                json_close_array
                                json_add_boolean no-device "$no_device"
+                               json_add_boolean no-proto-task "$no_proto_task"
                                json_add_boolean available "$available"
+                               json_add_boolean renew-handler "$renew_handler"
+                               json_add_boolean lasterror "$lasterror"
                                json_dump
                        }
                ;;
-               setup|teardown)
+               setup|teardown|renew)
                        interface="$1"; shift
                        data="$1"; shift
                        ifname="$1"; shift
@@ -372,6 +392,7 @@ init_proto() {
                                case "$cmd" in
                                        setup) _proto_do_setup "$1";;
                                        teardown) _proto_do_teardown "$1" ;;
+                                       renew) _proto_do_renew "$1" ;;
                                        *) return 1 ;;
                                esac
                        }