X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=dummy%2Fnetifd-proto.sh;h=de1961d8e3779760bca0edfb68b0671cc455d9e3;hp=c50d776a6b0f4fa7d8a036709a0a9dcfc1e0a074;hb=bdc880a9cbfb421696c505463dba5f1cd4221999;hpb=10c7565766962a876844c71dd3a230aefeaf193b diff --git a/dummy/netifd-proto.sh b/dummy/netifd-proto.sh index c50d776..de1961d 100755 --- a/dummy/netifd-proto.sh +++ b/dummy/netifd-proto.sh @@ -33,6 +33,8 @@ _proto_do_teardown() { _proto_do_setup() { json_load "$data" + _EXPORT_VAR=0 + _EXPORT_VARS= eval "$1_setup \"$interface\" \"$ifname\"" } @@ -48,11 +50,23 @@ proto_init_update() { PROTO_ROUTE6= json_init json_add_int action 0 - json_add_string "ifname" "$ifname" + [ -n "$ifname" -a "*" != "$ifname" ] && json_add_string "ifname" "$ifname" json_add_boolean "link-up" "$up" [ -n "$3" ] && json_add_boolean "address-external" "$external" } +proto_add_dns_server() { + local address="$1" + + jshn_append PROTO_DNS "$address" +} + +proto_add_dns_search() { + local address="$1" + + jshn_append PROTO_DNS_SEARCH "$address" +} + proto_add_ipv4_address() { local address="$1" local mask="$2" @@ -96,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() { @@ -115,6 +129,7 @@ _proto_push_array() { } _proto_notify() { + local interface="$1" ubus call network.interface."$interface" notify_proto "$(json_dump)" } @@ -125,10 +140,21 @@ proto_send_update() { _proto_push_array "ip6addr" "$PROTO_IP6ADDR" _proto_push_ip _proto_push_array "route" "$PROTO_ROUTE" _proto_push_route _proto_push_array "route6" "$PROTO_ROUTE6" _proto_push_route - _proto_notify + _proto_push_array "dns" "$PROTO_DNS" _proto_push_ip + _proto_push_array "dns_search" "$PROTO_DNS_SEARCH" _proto_push_ip + _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 + json_init json_add_int action 1 json_add_array command @@ -136,7 +162,24 @@ proto_run_command() { json_add_string "" "$1" shift done - _proto_notify + 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" +} + +proto_kill_command() { + local interface="$1"; shift + + json_init + json_add_int action 2 + [ -n "$1" ] && json_add_int signal "$1" + _proto_notify "$interface" } init_proto() {