X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=dummy%2Fnetifd-proto.sh;h=6f20de91a7ce464fa4612dae7a2bff83f01b1ba5;hp=99ad11edee0a496fd790c9727f62a2b9035e3ba2;hb=e93c42c036c4b4df1f65f261def31cf1a429e942;hpb=139b16ed4c7511f076ec4f5735c76954e4d3ea33 diff --git a/dummy/netifd-proto.sh b/dummy/netifd-proto.sh index 99ad11e..6f20de9 100755 --- a/dummy/netifd-proto.sh +++ b/dummy/netifd-proto.sh @@ -1,5 +1,13 @@ . /usr/share/libubox/jshn.sh +append() { + local var="$1" + local value="$2" + local sep="${3:- }" + + eval "export -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\"" +} + proto_config_add_generic() { json_add_array "" json_add_string "" "$1" @@ -50,6 +58,7 @@ proto_init_update() { PROTO_IP6ADDR= PROTO_ROUTE= PROTO_ROUTE6= + PROTO_PREFIX6= PROTO_DNS= PROTO_DNS_SEARCH= json_init @@ -92,28 +101,32 @@ proto_close_data() { proto_add_dns_server() { local address="$1" - jshn_append PROTO_DNS "$address" + append PROTO_DNS "$address" } proto_add_dns_search() { local address="$1" - jshn_append PROTO_DNS_SEARCH "$address" + append PROTO_DNS_SEARCH "$address" } proto_add_ipv4_address() { local address="$1" local mask="$2" local broadcast="$3" + local ptp="$4" - jshn_append PROTO_IPADDR "$address/$mask/$broadcast" + append PROTO_IPADDR "$address/$mask/$broadcast/$ptp" } proto_add_ipv6_address() { local address="$1" local mask="$2" + local preferred="$3" + local valid="$4" + local offlink="$5" - jshn_append PROTO_IP6ADDR "$address/$mask" + append PROTO_IP6ADDR "$address/$mask/$preferred/$valid/$offlink" } proto_add_ipv4_route() { @@ -121,45 +134,73 @@ proto_add_ipv4_route() { local mask="$2" local gw="$3" - jshn_append PROTO_ROUTE "$target/$mask/$gw" + append PROTO_ROUTE "$target/$mask/$gw//" } proto_add_ipv6_route() { local target="$1" local mask="$2" local gw="$3" + local metric="$4" + local valid="$5" + local source="$6" + + append PROTO_ROUTE6 "$target/$mask/$gw/$metric/$valid/$source" +} - jshn_append PROTO_ROUTE6 "$target/$mask/$gw" +proto_add_ipv6_prefix() { + local prefix="$1" + local valid="$2" + local preferred="$3" + + if [ -z "$valid" ]; then + append PROTO_PREFIX6 "$prefix" + else + [ -z "$preferred" ] && preferred="$valid" + append PROTO_PREFIX6 "$prefix,$valid,$preferred" + fi } _proto_push_ipv4_addr() { local str="$1" - local address mask broadcast + local address mask broadcast ptp address="${str%%/*}" str="${str#*/}" mask="${str%%/*}" str="${str#*/}" - broadcast="$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 + local address mask preferred valid offlink address="${str%%/*}" str="${str#*/}" - mask="$str" + mask="${str%%/*}" + str="${str#*/}" + preferred="${str%%/*}" + str="${str#*/}" + valid="${str%%/*}" + str="${str#*/}" + offlink="${str%%/*}" json_add_object "" json_add_string ipaddr "$address" [ -n "$mask" ] && json_add_string mask "$mask" + [ -n "$preferred" ] && json_add_int preferred "$preferred" + [ -n "$valid" ] && json_add_int valid "$valid" + [ -n "$offlink" ] && json_add_boolean offlink "$offlink" json_close_object } @@ -172,12 +213,22 @@ _proto_push_route() { local target="${str%%/*}" str="${str#*/}" local mask="${str%%/*}" - local gw="${str#*/}" + str="${str#*/}" + local gw="${str%%/*}" + str="${str#*/}" + local metric="${str%%/*}" + str="${str#*/}" + local valid="${str%%/*}" + str="${str#*/}" + local source="${str}" json_add_object "" json_add_string target "$target" json_add_string netmask "$mask" [ -n "$gw" ] && json_add_string gateway "$gw" + [ -n "$metric" ] && json_add_int metric "$metric" + [ -n "$valid" ] && json_add_int valid "$valid" + [ -n "$source" ] && json_add_string source "$source" json_close_object } @@ -197,7 +248,8 @@ _proto_push_array() { _proto_notify() { local interface="$1" local options="$2" - ubus $options call network.interface."$interface" notify_proto "$(json_dump)" + json_add_string "interface" "$interface" + ubus $options call network.interface notify_proto "$(json_dump)" } proto_send_update() { @@ -209,6 +261,7 @@ proto_send_update() { _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 "ip6prefix" "$PROTO_PREFIX6" _proto_push_string _proto_push_array "dns" "$PROTO_DNS" _proto_push_string _proto_push_array "dns_search" "$PROTO_DNS_SEARCH" _proto_push_string _proto_notify "$interface" @@ -218,7 +271,7 @@ proto_export() { local var="VAR${_EXPORT_VAR}" _EXPORT_VAR="$(($_EXPORT_VAR + 1))" export -- "$var=$1" - jshn_append _EXPORT_VARS "$var" + append _EXPORT_VARS "$var" } proto_run_command() { @@ -285,11 +338,24 @@ proto_set_available() { proto_add_host_dependency() { local interface="$1" local host="$2" + local ifname="$3" + # 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" + [ -n "$ifname" ] && json_add_string ifname "$ifname" + _proto_notify "$interface" -S + ) +} + +proto_setup_failed() { + local interface="$1" json_init - json_add_int action 6 - json_add_string host "$host" - _proto_notify "$interface" -S + json_add_int action 7 + _proto_notify "$interface" } init_proto() {