X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=dummy%2Fnetifd-proto.sh;h=297e90498703d259ed3dc2226f0f3643b572b4c1;hp=e10f6015f90d00e414e7f6eba7e54ada800a4676;hb=e22d6c5ce7b579a3af3a5da7d692aaf952a8f651;hpb=faa537e2f7bf53a087379adcd3527262491aa575 diff --git a/dummy/netifd-proto.sh b/dummy/netifd-proto.sh index e10f601..297e904 100755 --- a/dummy/netifd-proto.sh +++ b/dummy/netifd-proto.sh @@ -28,14 +28,14 @@ add_default_handler() { _proto_do_teardown() { json_load "$data" - eval "$1_teardown \"$interface\" \"$ifname\"" + eval "proto_$1_teardown \"$interface\" \"$ifname\"" } _proto_do_setup() { json_load "$data" _EXPORT_VAR=0 _EXPORT_VARS= - eval "$1_setup \"$interface\" \"$ifname\"" + eval "proto_$1_setup \"$interface\" \"$ifname\"" } proto_init_update() { @@ -43,11 +43,15 @@ proto_init_update() { local up="$2" local external="$3" + PROTO_KEEP=0 PROTO_INIT=1 + PROTO_TUNNEL_OPEN= PROTO_IPADDR= PROTO_IP6ADDR= PROTO_ROUTE= PROTO_ROUTE6= + PROTO_DNS= + PROTO_DNS_SEARCH= json_init json_add_int action 0 [ -n "$ifname" -a "*" != "$ifname" ] && json_add_string "ifname" "$ifname" @@ -55,6 +59,36 @@ proto_init_update() { [ -n "$3" ] && json_add_boolean "address-external" "$external" } +proto_set_keep() { + PROTO_KEEP="$1" +} + +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() { + proto_close_nested +} + +proto_add_data() { + proto_add_nested "data" +} + +proto_close_data() { + proto_close_nested +} + proto_add_dns_server() { local address="$1" @@ -70,8 +104,10 @@ proto_add_dns_search() { proto_add_ipv4_address() { local address="$1" local mask="$2" + local broadcast="$3" + local ptp="$4" - jshn_append PROTO_IPADDR "$address/$mask" + jshn_append PROTO_IPADDR "$address/$mask/$broadcast/$ptp" } proto_add_ipv6_address() { @@ -97,7 +133,41 @@ proto_add_ipv6_route() { jshn_append PROTO_ROUTE6 "$target/$mask/$gw" } -_proto_push_ip() { +_proto_push_ipv4_addr() { + local str="$1" + local address mask broadcast ptp + + address="${str%%/*}" + str="${str#*/}" + mask="${str%%/*}" + str="${str#*/}" + broadcast="${str%%/*}" + str="${str#*/}" + ptp="$str" + + json_add_object "" + json_add_string ipaddr "$address" + [ -n "$mask" ] && json_add_string mask "$mask" + [ -n "$broadcast" ] && json_add_string broadcast "$broadcast" + [ -n "$ptp" ] && json_add_string ptp "$ptp" + json_close_object +} + +_proto_push_ipv6_addr() { + local str="$1" + local address mask + + address="${str%%/*}" + str="${str#*/}" + mask="$str" + + json_add_object "" + json_add_string ipaddr "$address" + [ -n "$mask" ] && json_add_string mask "$mask" + json_close_object +} + +_proto_push_string() { json_add_string "" "$1" } @@ -108,11 +178,11 @@ _proto_push_route() { local mask="${str%%/*}" local gw="${str#*/}" - json_add_table "" + json_add_object "" json_add_string target "$target" - json_add_string mask "$mask" - json_add_string gateway "$gw" - json_close_table + json_add_string netmask "$mask" + [ -n "$gw" ] && json_add_string gateway "$gw" + json_close_object } _proto_push_array() { @@ -130,18 +200,21 @@ _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_push_array "ipaddr" "$PROTO_IPADDR" _proto_push_ip - _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_push_array "dns" "$PROTO_DNS" _proto_push_ip - _proto_push_array "dns_search" "$PROTO_DNS_SEARCH" _proto_push_ip + proto_close_nested + json_add_boolean keep "$PROTO_KEEP" + _proto_push_array "ipaddr" "$PROTO_IPADDR" _proto_push_ipv4_addr + _proto_push_array "ip6addr" "$PROTO_IP6ADDR" _proto_push_ipv6_addr + _proto_push_array "routes" "$PROTO_ROUTE" _proto_push_route + _proto_push_array "routes6" "$PROTO_ROUTE6" _proto_push_route + _proto_push_array "dns" "$PROTO_DNS" _proto_push_string + _proto_push_array "dns_search" "$PROTO_DNS_SEARCH" _proto_push_string _proto_notify "$interface" } @@ -182,6 +255,58 @@ proto_kill_command() { _proto_notify "$interface" } +proto_notify_error() { + local interface="$1"; shift + + json_init + json_add_int action 3 + json_add_array error + while [ $# -gt 0 ]; do + json_add_string "" "$1" + shift + done + json_close_array + _proto_notify "$interface" +} + +proto_block_restart() { + local interface="$1"; shift + + json_init + json_add_int action 4 + _proto_notify "$interface" +} + +proto_set_available() { + local interface="$1" + local state="$2" + json_init + json_add_int action 5 + json_add_boolean available "$state" + _proto_notify "$interface" +} + +proto_add_host_dependency() { + local interface="$1" + local host="$2" + + # execute in subshell to not taint callers env + # see tickets #11046, #11545, #11570 + ( + json_init + json_add_int action 6 + json_add_string host "$host" + _proto_notify "$interface" -S + ) +} + +proto_setup_failed() { + local interface="$1" + json_init + json_add_int action 7 + _proto_notify "$interface" +} + init_proto() { proto="$1"; shift cmd="$1"; shift @@ -192,16 +317,15 @@ init_proto() { no_device=0 available=0 - add_default_handler "$1_init_config" + add_default_handler "proto_$1_init_config" json_init json_add_string "name" "$1" - eval "$1_init" - json_add_boolean no-device "$no_device" - json_add_boolean available "$available" json_add_array "config" - eval "$1_init_config" + eval "proto_$1_init_config" json_close_array + json_add_boolean no-device "$no_device" + json_add_boolean available "$available" json_dump } ;;