X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=dummy%2Fnetifd-proto.sh;h=74265818218847a20dba28fbb8fd10f466ad150b;hp=69aa27d4eda34b7eee940691f74f57d2559c008b;hb=8e4a99716364e92cef9d7870149d75a57163f537;hpb=2cc1190666ddfb2dc2a5fbf4febe7a4579d0c2f5 diff --git a/dummy/netifd-proto.sh b/dummy/netifd-proto.sh index 69aa27d..7426581 100755 --- a/dummy/netifd-proto.sh +++ b/dummy/netifd-proto.sh @@ -43,6 +43,7 @@ proto_init_update() { local up="$2" local external="$3" + PROTO_KEEP=0 PROTO_INIT=1 PROTO_TUNNEL_OPEN= PROTO_IPADDR= @@ -58,17 +59,34 @@ proto_init_update() { [ -n "$3" ] && json_add_boolean "address-external" "$external" } -proto_add_tunnel() { - proto_close_tunnel +proto_set_keep() { + PROTO_KEEP="$1" +} - PROTO_TUNNEL_OPEN=1 - json_add_object "tunnel" +proto_close_nested() { + [ -n "$PROTO_NESTED_OPEN" ] && json_close_object + PROTO_NESTED_OPEN= +} + +proto_add_nested() { + PROTO_NESTED_OPEN=1 + json_add_object "$1" +} + +proto_add_tunnel() { + proto_add_nested "tunnel" } proto_close_tunnel() { - [ -n "$PROTO_TUNNEL_OPEN" ] || return - json_close_object - PROTO_TUNNEL_OPEN= + proto_close_nested +} + +proto_add_data() { + proto_add_nested "data" +} + +proto_close_data() { + proto_close_nested } proto_add_dns_server() { @@ -127,7 +145,7 @@ _proto_push_route() { json_add_object "" json_add_string target "$target" json_add_string netmask "$mask" - json_add_string gateway "$gw" + [ -n "$gw" ] && json_add_string gateway "$gw" json_close_object } @@ -146,13 +164,15 @@ _proto_push_array() { _proto_notify() { local interface="$1" - ubus call network.interface."$interface" notify_proto "$(json_dump)" + local options="$2" + ubus $options call network.interface."$interface" notify_proto "$(json_dump)" } proto_send_update() { local interface="$1" - proto_close_tunnel + proto_close_nested + json_add_boolean keep "$PROTO_KEEP" _proto_push_array "ipaddr" "$PROTO_IPADDR" _proto_push_ip _proto_push_array "ip6addr" "$PROTO_IP6ADDR" _proto_push_ip _proto_push_array "routes" "$PROTO_ROUTE" _proto_push_route @@ -230,6 +250,16 @@ proto_set_available() { _proto_notify "$interface" } +proto_add_host_dependency() { + local interface="$1" + local host="$2" + + json_init + json_add_int action 6 + json_add_string host "$host" + _proto_notify "$interface" -S +} + init_proto() { proto="$1"; shift cmd="$1"; shift