blob: a9aac699632f23c10918fd63be52b166d691b1fc (
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
|
# Copyright (c) 2016 Joakim Sindholt (zhasha)
# Copyright (c) 2018 Jason A. Donenfeld,
# Released under the 2-clause BSD license.
# shellcheck shell=sh disable=SC1008
wireguard_depend()
{
program /usr/bin/wg
after interface
}
wireguard_pre_start()
{
[ "${IFACE#wg}" != "$IFACE" ] || return 0
ip link delete dev "$IFACE" type wireguard 2>/dev/null
ebegin "Creating WireGuard interface $IFACE"
if ! ip link add dev "$IFACE" type wireguard; then
e=$?
eend $e
return $e
fi
eend 0
ebegin "Configuring WireGuard interface $IFACE"
set -- $(_get_array "wireguard_$IFVAR")
if [ $# -eq 1 ]; then
/usr/bin/wg setconf "$IFACE" "$1"
else
eval /usr/bin/wg set "$IFACE" "$@"
fi
e=$?
if [ $e -eq 0 ]; then
_up
e=$?
if [ $e -eq 0 ]; then
eend $e
return $e
fi
fi
ip link delete dev "$IFACE" type wireguard 2>/dev/null
eend $e
return $e
}
wireguard_post_stop()
{
[ "${IFACE#wg}" != "$IFACE" ] || return 0
ebegin "Removing WireGuard interface $IFACE"
ip link delete dev "$IFACE" type wireguard
e=$?
eend $e
return $e
}
|