proto-shell: allow proto setups without ifname (if interface main dev is present)
[project/netifd.git] / dummy / netifd-proto.sh
index c50d776..0af99b2 100755 (executable)
@@ -48,11 +48,17 @@ 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_ipv4_address() {
        local address="$1"
        local mask="$2"
@@ -115,6 +121,7 @@ _proto_push_array() {
 }
 
 _proto_notify() {
+       local interface="$1"
        ubus call network.interface."$interface" notify_proto "$(json_dump)"
 }
 
@@ -125,10 +132,13 @@ 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_notify "$interface"
 }
 
 proto_run_command() {
+       local interface="$1"; shift
+
        json_init
        json_add_int action 1
        json_add_array command
@@ -136,7 +146,16 @@ proto_run_command() {
                json_add_string "" "$1"
                shift
        done
-       _proto_notify
+       _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() {