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 [ -n "$ifname" -a "*" != "$ifname" ] && 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\""
125 ubus call network.interface.
"$interface" notify_proto
"$(json_dump)"
128 proto_send_update
() {
131 _proto_push_array
"ipaddr" "$PROTO_IPADDR" _proto_push_ip
132 _proto_push_array
"ip6addr" "$PROTO_IP6ADDR" _proto_push_ip
133 _proto_push_array
"route" "$PROTO_ROUTE" _proto_push_route
134 _proto_push_array
"route6" "$PROTO_ROUTE6" _proto_push_route
135 _proto_push_array
"dns" "$PROTO_DNS" _proto_push_ip
136 _proto_notify
"$interface"
139 proto_run_command
() {
140 local interface
="$1"; shift
143 json_add_int action
1
144 json_add_array
command
145 while [ $# -gt 0 ]; do
146 json_add_string
"" "$1"
149 _proto_notify
"$interface"
152 proto_kill_command
() {
153 local interface
="$1"; shift
156 json_add_int action
2
157 [ -n "$1" ] && json_add_int signal
"$1"
158 _proto_notify
"$interface"
171 add_default_handler
"$1_init_config"
174 json_add_string
"name" "$1"
176 json_add_boolean no-device
"$no_device"
177 json_add_boolean available
"$available"
178 json_add_array
"config"
179 eval "$1_init_config"
185 interface
="$1"; shift
190 [[ "$proto" == "$1" ]] ||
return 0
193 setup
) _proto_do_setup
"$1";;
194 teardown
) _proto_do_teardown
"$1" ;;