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_array
"tunnels:list(string)"
20 proto_config_add_array
"connect:list(string)"
21 proto_config_add_array
"peer_data:list(string)"
30 local device
type key
file keepalive domain tunnels
31 json_get_vars device
type auth_key key
file keepalive domain
32 json_get_values tunnels tunnels
33 json_get_values connect connect
34 json_get_values peer_data peer_data
35 device
="${device:-$config}"
37 [ -n "$auth_key" ] && type="${type:-dynamic}"
38 [ -n "$file" ] && type="${type:-file}"
41 json_add_string name
"$device"
42 json_add_string
type "$type"
43 json_add_string interface
"$config"
44 json_add_string auth_key
"$auth_key"
45 json_add_string key
"$key"
46 json_add_string
file "$file"
47 [ -n "$keepalive" ] && json_add_int keepalive
"$keepalive"
48 json_add_string domain
"$domain"
50 json_add_object tunnels
52 local ifname
="${t%%=*}"
53 local service
="${t#*=}"
54 [ -n "$ifname" -a -n "$service" -a "$ifname" != "$t" ] ||
continue
55 json_add_string
"$ifname" "$service"
59 json_add_array auth_connect
61 json_add_string
"" "$c"
65 json_add_array peer_data
66 for c
in $peer_data; do
67 json_add_string
"" "$c"
71 ip link del dev
"$device" >/dev
/null
2>&1
72 ip link add dev
"$device" type wireguard ||
{
73 echo "Could not create wireguard device $device"
74 proto_setup_failed
"$config"
78 ubus call unetd network_add
"$(json_dump)"
81 proto_unet_teardown
() {
87 device
="${device:-$iface}"
90 json_add_string name
"$device"
92 ip link del dev
"$device"
94 ubus call unetd network_del
"$(json_dump)"