blob: df39926c232e57b767114f2c395a05d4477769c9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#!/bin/sh
# PROVIDE: wireguard
# REQUIRE: DAEMON
# KEYWORD: shutdown
#
# wireguard_enable (bool): Set to "YES" to enable wireguard.
# (default: "NO")
#
# wireguard_interfaces (str): List of interfaces to bring up/down
# on start/stop. (eg: "wg0 wg1")
# (default: "")
# wireguard_env (str): Environment variables for the userspace
# implementation. (eg: "LOG_LEVEL=debug")
. /etc/rc.subr
name=wireguard
rcvar=wireguard_enable
extra_commands="reload"
start_cmd="${name}_start"
stop_cmd="${name}_stop"
reload_cmd="${name}_reload"
wireguard_start()
{
${wireguard_env:+eval export $wireguard_env}
for interface in ${wireguard_interfaces}; do
%%PREFIX%%/bin/wg-quick up ${interface}
done
}
wireguard_stop()
{
for interface in ${wireguard_interfaces}; do
%%PREFIX%%/bin/wg-quick down ${interface}
done
if kldstat -q -n if_wg; then
if ! kldunload if_wg > /dev/null 2>&1; then
warn "Can't unload if_wg module."
return 1
fi
fi
}
wireguard_reload()
{
${wireguard_env:+eval export $wireguard_env}
for interface in ${wireguard_interfaces}; do
tmpfile="`mktemp`"
%%PREFIX%%/bin/wg-quick strip ${interface} > ${tmpfile}
%%PREFIX%%/bin/wg syncconf ${interface} ${tmpfile}
rm -f ${tmpfile}
done
}
load_rc_config $name
: ${wireguard_enable="NO"}
: ${wireguard_interfaces=""}
: ${wireguard_env=""}
run_rc_command "$1"
|