use json_close_object instead of json_close_table
[project/netifd.git] / dummy / netifd-proto.sh
index 0f703a2..de1961d 100755 (executable)
@@ -33,6 +33,8 @@ _proto_do_teardown() {
 
 _proto_do_setup() {
        json_load "$data"
+       _EXPORT_VAR=0
+       _EXPORT_VARS=
        eval "$1_setup \"$interface\" \"$ifname\""
 }
 
@@ -108,9 +110,9 @@ _proto_push_route() {
 
        json_add_table ""
        json_add_string target "$target"
-       json_add_integer mask "$mask"
+       json_add_string mask "$mask"
        json_add_string gateway "$gw"
-       json_close_table
+       json_close_object
 }
 
 _proto_push_array() {
@@ -143,6 +145,13 @@ proto_send_update() {
        _proto_notify "$interface"
 }
 
+proto_export() {
+       local var="VAR${_EXPORT_VAR}"
+       _EXPORT_VAR="$(($_EXPORT_VAR + 1))"
+       export -- "$var=$1"
+       jshn_append _EXPORT_VARS "$var"
+}
+
 proto_run_command() {
        local interface="$1"; shift
 
@@ -153,6 +162,14 @@ proto_run_command() {
                json_add_string "" "$1"
                shift
        done
+       json_close_array
+       [ -n "$_EXPORT_VARS" ] && {
+               json_add_array env
+               for var in $_EXPORT_VARS; do
+                       eval "json_add_string \"\" \"\${$var}\""
+               done
+               json_close_array
+       }
        _proto_notify "$interface"
 }