blob: 301836d3f3a59d4c2decc80683497267c4b9d698 (
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 ip wg
before 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
wg setconf "$IFACE" "$1"
else
eval 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
}
|