1 . /usr/share/libubox/jshn.sh
3 proto_config_add_generic() {
5 json_add_string "" "$1"
10 proto_config_add_int() {
11 proto_config_add_generic "$1" 5
14 proto_config_add_string() {
15 proto_config_add_generic "$1" 3
18 proto_config_add_boolean() {
19 proto_config_add_generic "$1" 7
22 add_default_handler() {
23 case "$(type $1 2>/dev/null)" in
25 *) eval "$1() { return; }"
29 _proto_do_teardown() {
31 eval "$1_teardown \"$interface\" \"$ifname\""
36 eval "$1_setup \"$interface\" \"$ifname\""
51 json_add_string "ifname" "$ifname"
52 json_add_boolean "link-up" "$up"
53 [ -n "$3" ] && json_add_boolean "address-external" "$external"
56 proto_add_ipv4_address() {
60 jshn_append PROTO_IPADDR "$address/$mask"
63 proto_add_ipv6_address() {
67 jshn_append PROTO_IP6ADDR "$address/$mask"
70 proto_add_ipv4_route() {
75 jshn_append PROTO_ROUTE "$target/$mask/$gw"
78 proto_add_ipv6_route() {
83 jshn_append PROTO_ROUTE6 "$target/$mask/$gw"
87 json_add_string "" "$1"
92 local target="${str%%/*}"
94 local mask="${str%%/*}"
98 json_add_string target "$target"
99 json_add_integer mask "$mask"
100 json_add_string gateway "$gw"
104 _proto_push_array() {
109 [ -n "$val" ] || return 0
110 json_add_array "$name"
112 eval "$cb \"\$item\""
118 ubus call network.interface."$interface" notify_proto "$(json_dump)"
121 proto_send_update() {
124 _proto_push_array "ipaddr" "$PROTO_IPADDR" _proto_push_ip
125 _proto_push_array "ip6addr" "$PROTO_IP6ADDR" _proto_push_ip
126 _proto_push_array "route" "$PROTO_ROUTE" _proto_push_route
127 _proto_push_array "route6" "$PROTO_ROUTE6" _proto_push_route
131 proto_run_command() {
133 json_add_int action 1
134 json_add_array command
135 while [ $# -gt 0 ]; do
136 json_add_string "" "$1"
152 add_default_handler "$1_init_config"
155 json_add_string "name" "$1"
157 json_add_boolean no-device "$no_device"
158 json_add_boolean available "$available"
159 json_add_array "config"
160 eval "$1_init_config"
166 interface="$1"; shift
171 [[ "$proto" == "$1" ]] || return 0
174 setup) _proto_do_setup "$1";;
175 teardown) _proto_do_teardown "$1" ;;