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_dns_server() {
59 jshn_append PROTO_DNS "$address"
62 proto_add_ipv4_address() {
66 jshn_append PROTO_IPADDR "$address/$mask"
69 proto_add_ipv6_address() {
73 jshn_append PROTO_IP6ADDR "$address/$mask"
76 proto_add_ipv4_route() {
81 jshn_append PROTO_ROUTE "$target/$mask/$gw"
84 proto_add_ipv6_route() {
89 jshn_append PROTO_ROUTE6 "$target/$mask/$gw"
93 json_add_string "" "$1"
98 local target="${str%%/*}"
100 local mask="${str%%/*}"
104 json_add_string target "$target"
105 json_add_integer mask "$mask"
106 json_add_string gateway "$gw"
110 _proto_push_array() {
115 [ -n "$val" ] || return 0
116 json_add_array "$name"
118 eval "$cb \"\$item\""
124 ubus call network.interface."$interface" notify_proto "$(json_dump)"
127 proto_send_update() {
130 _proto_push_array "ipaddr" "$PROTO_IPADDR" _proto_push_ip
131 _proto_push_array "ip6addr" "$PROTO_IP6ADDR" _proto_push_ip
132 _proto_push_array "route" "$PROTO_ROUTE" _proto_push_route
133 _proto_push_array "route6" "$PROTO_ROUTE6" _proto_push_route
134 _proto_push_array "dns" "$PROTO_DNS" _proto_push_ip
138 proto_run_command() {
140 json_add_int action 1
141 json_add_array command
142 while [ $# -gt 0 ]; do
143 json_add_string "" "$1"
159 add_default_handler "$1_init_config"
162 json_add_string "name" "$1"
164 json_add_boolean no-device "$no_device"
165 json_add_boolean available "$available"
166 json_add_array "config"
167 eval "$1_init_config"
173 interface="$1"; shift
178 [[ "$proto" == "$1" ]] || return 0
181 setup) _proto_do_setup "$1";;
182 teardown) _proto_do_teardown "$1" ;;