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\""
38 eval "$1_setup \"$interface\" \"$ifname\""
55 [ -n "$ifname" -a "*" != "$ifname" ] && json_add_string
"ifname" "$ifname"
56 json_add_boolean
"link-up" "$up"
57 [ -n "$3" ] && json_add_boolean
"address-external" "$external"
60 proto_add_dns_server
() {
63 jshn_append PROTO_DNS
"$address"
66 proto_add_dns_search
() {
69 jshn_append PROTO_DNS_SEARCH
"$address"
72 proto_add_ipv4_address
() {
76 jshn_append PROTO_IPADDR
"$address/$mask"
79 proto_add_ipv6_address
() {
83 jshn_append PROTO_IP6ADDR
"$address/$mask"
86 proto_add_ipv4_route
() {
91 jshn_append PROTO_ROUTE
"$target/$mask/$gw"
94 proto_add_ipv6_route
() {
99 jshn_append PROTO_ROUTE6
"$target/$mask/$gw"
103 json_add_string
"" "$1"
106 _proto_push_route
() {
108 local target
="${str%%/*}"
110 local mask
="${str%%/*}"
114 json_add_string target
"$target"
115 json_add_string netmask
"$mask"
116 json_add_string gateway
"$gw"
120 _proto_push_array
() {
125 [ -n "$val" ] ||
return 0
126 json_add_array
"$name"
128 eval "$cb \"\$item\""
135 ubus call network.interface.
"$interface" notify_proto
"$(json_dump)"
138 proto_send_update
() {
141 _proto_push_array
"ipaddr" "$PROTO_IPADDR" _proto_push_ip
142 _proto_push_array
"ip6addr" "$PROTO_IP6ADDR" _proto_push_ip
143 _proto_push_array
"routes" "$PROTO_ROUTE" _proto_push_route
144 _proto_push_array
"routes6" "$PROTO_ROUTE6" _proto_push_route
145 _proto_push_array
"dns" "$PROTO_DNS" _proto_push_ip
146 _proto_push_array
"dns_search" "$PROTO_DNS_SEARCH" _proto_push_ip
147 _proto_notify
"$interface"
151 local var
="VAR${_EXPORT_VAR}"
152 _EXPORT_VAR
="$(($_EXPORT_VAR + 1))"
154 jshn_append _EXPORT_VARS
"$var"
157 proto_run_command
() {
158 local interface
="$1"; shift
161 json_add_int action
1
162 json_add_array
command
163 while [ $# -gt 0 ]; do
164 json_add_string
"" "$1"
168 [ -n "$_EXPORT_VARS" ] && {
170 for var
in $_EXPORT_VARS; do
171 eval "json_add_string \"\" \"\${$var}\""
175 _proto_notify
"$interface"
178 proto_kill_command
() {
179 local interface
="$1"; shift
182 json_add_int action
2
183 [ -n "$1" ] && json_add_int signal
"$1"
184 _proto_notify
"$interface"
187 proto_notify_error
() {
188 local interface
="$1"; shift
191 json_add_int action
3
193 while [ $# -gt 0 ]; do
194 json_add_string
"" "$1"
198 _proto_notify
"$interface"
201 proto_block_restart
() {
202 local interface
="$1"; shift
205 json_add_int action
4
206 _proto_notify
"$interface"
209 proto_set_available
() {
213 json_add_int action
5
214 json_add_boolean available
"$state"
215 _proto_notify
"$interface"
228 add_default_handler
"$1_init_config"
231 json_add_string
"name" "$1"
233 json_add_boolean no-device
"$no_device"
234 json_add_boolean available
"$available"
235 json_add_array
"config"
236 eval "$1_init_config"
242 interface
="$1"; shift
247 [[ "$proto" == "$1" ]] ||
return 0
250 setup
) _proto_do_setup
"$1";;
251 teardown
) _proto_do_teardown
"$1" ;;