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 "proto_$1_teardown \"$interface\" \"$ifname\""
38 eval "proto_$1_setup \"$interface\" \"$ifname\""
57 [ -n "$ifname" -a "*" != "$ifname" ] && json_add_string
"ifname" "$ifname"
58 json_add_boolean
"link-up" "$up"
59 [ -n "$3" ] && json_add_boolean
"address-external" "$external"
66 proto_close_nested
() {
67 [ -n "$PROTO_NESTED_OPEN" ] && json_close_object
77 proto_add_nested
"tunnel"
80 proto_close_tunnel
() {
85 proto_add_nested
"data"
92 proto_add_dns_server
() {
95 jshn_append PROTO_DNS
"$address"
98 proto_add_dns_search
() {
101 jshn_append PROTO_DNS_SEARCH
"$address"
104 proto_add_ipv4_address
() {
110 jshn_append PROTO_IPADDR
"$address/$mask/$broadcast/$ptp"
113 proto_add_ipv6_address
() {
117 jshn_append PROTO_IP6ADDR
"$address/$mask"
120 proto_add_ipv4_route
() {
125 jshn_append PROTO_ROUTE
"$target/$mask/$gw"
128 proto_add_ipv6_route
() {
133 jshn_append PROTO_ROUTE6
"$target/$mask/$gw"
136 _proto_push_ipv4_addr
() {
138 local address mask broadcast ptp
144 broadcast
="${str%%/*}"
149 json_add_string ipaddr
"$address"
150 [ -n "$mask" ] && json_add_string mask
"$mask"
151 [ -n "$broadcast" ] && json_add_string broadcast
"$broadcast"
152 [ -n "$ptp" ] && json_add_string ptp
"$ptp"
156 _proto_push_ipv6_addr
() {
165 json_add_string ipaddr
"$address"
166 [ -n "$mask" ] && json_add_string mask
"$mask"
170 _proto_push_string
() {
171 json_add_string
"" "$1"
174 _proto_push_route
() {
176 local target
="${str%%/*}"
178 local mask
="${str%%/*}"
182 json_add_string target
"$target"
183 json_add_string netmask
"$mask"
184 [ -n "$gw" ] && json_add_string gateway
"$gw"
188 _proto_push_array
() {
193 [ -n "$val" ] ||
return 0
194 json_add_array
"$name"
196 eval "$cb \"\$item\""
204 ubus
$options call network.interface.
"$interface" notify_proto
"$(json_dump)"
207 proto_send_update
() {
211 json_add_boolean keep
"$PROTO_KEEP"
212 _proto_push_array
"ipaddr" "$PROTO_IPADDR" _proto_push_ipv4_addr
213 _proto_push_array
"ip6addr" "$PROTO_IP6ADDR" _proto_push_ipv6_addr
214 _proto_push_array
"routes" "$PROTO_ROUTE" _proto_push_route
215 _proto_push_array
"routes6" "$PROTO_ROUTE6" _proto_push_route
216 _proto_push_array
"dns" "$PROTO_DNS" _proto_push_string
217 _proto_push_array
"dns_search" "$PROTO_DNS_SEARCH" _proto_push_string
218 _proto_notify
"$interface"
222 local var
="VAR${_EXPORT_VAR}"
223 _EXPORT_VAR
="$(($_EXPORT_VAR + 1))"
225 jshn_append _EXPORT_VARS
"$var"
228 proto_run_command
() {
229 local interface
="$1"; shift
232 json_add_int action
1
233 json_add_array
command
234 while [ $# -gt 0 ]; do
235 json_add_string
"" "$1"
239 [ -n "$_EXPORT_VARS" ] && {
241 for var
in $_EXPORT_VARS; do
242 eval "json_add_string \"\" \"\${$var}\""
246 _proto_notify
"$interface"
249 proto_kill_command
() {
250 local interface
="$1"; shift
253 json_add_int action
2
254 [ -n "$1" ] && json_add_int signal
"$1"
255 _proto_notify
"$interface"
258 proto_notify_error
() {
259 local interface
="$1"; shift
262 json_add_int action
3
264 while [ $# -gt 0 ]; do
265 json_add_string
"" "$1"
269 _proto_notify
"$interface"
272 proto_block_restart
() {
273 local interface
="$1"; shift
276 json_add_int action
4
277 _proto_notify
"$interface"
280 proto_set_available
() {
284 json_add_int action
5
285 json_add_boolean available
"$state"
286 _proto_notify
"$interface"
289 proto_add_host_dependency
() {
294 json_add_int action
6
295 json_add_string
host "$host"
296 _proto_notify
"$interface" -S
299 proto_setup_failed
() {
302 json_add_int action
7
303 _proto_notify
"$interface"
316 add_default_handler
"proto_$1_init_config"
319 json_add_string
"name" "$1"
320 json_add_array
"config"
321 eval "proto_$1_init_config"
323 json_add_boolean no-device
"$no_device"
324 json_add_boolean available
"$available"
329 interface
="$1"; shift
334 [[ "$proto" == "$1" ]] ||
return 0
337 setup
) _proto_do_setup
"$1";;
338 teardown
) _proto_do_teardown
"$1" ;;