3 [ -x /usr
/sbin
/unetd
] ||
exit 0
6 .
/lib
/functions
/network.sh
11 proto_unet_init_config
() {
12 proto_config_add_string device
13 proto_config_add_string
type
14 proto_config_add_string auth_key
15 proto_config_add_string key
16 proto_config_add_string
file
17 proto_config_add_int keepalive
18 proto_config_add_string domain
19 proto_config_add_string
"tunnels:list(string)"
20 proto_config_add_string
"connect:list(string)"
29 local device
type key
file keepalive domain tunnels
30 json_get_vars device
type auth_key key
file keepalive domain tunnels connect
31 device
="${device:-$config}"
33 [ -n "$auth_key" ] && type="${type:-dynamic}"
34 [ -n "$file" ] && type="${type:-file}"
37 json_add_string name
"$device"
38 json_add_string
type "$type"
39 json_add_string interface
"$config"
40 json_add_string auth_key
"$auth_key"
41 json_add_string key
"$key"
42 json_add_string
file "$file"
43 [ -n "$keepalive" ] && json_add_int keepalive
"$keepalive"
44 json_add_string domain
"$domain"
46 json_add_object tunnels
48 local ifname
="${t%%=*}"
49 local service
="${t#*=}"
50 [ -n "$ifname" -a -n "$service" -a "$ifname" != "$t" ] ||
continue
51 json_add_string
"$ifname" "$service"
55 json_add_array auth_connect
57 json_add_string
"" "$c"
61 ip link del dev
"$device" >/dev
/null
2>&1
62 ip link add dev
"$device" type wireguard ||
{
63 echo "Could not create wireguard device $device"
64 proto_setup_failed
"$config"
68 ubus call unetd network_add
"$(json_dump)"
71 proto_unet_teardown
() {
77 device
="${device:-$iface}"
80 json_add_string name
"$device"
82 ip link del dev
"$device"
84 ubus call unetd network_del
"$(json_dump)"