aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--net/Makefile2
-rw-r--r--net/wireguard.sh53
2 files changed, 54 insertions, 1 deletions
diff --git a/net/Makefile b/net/Makefile
index 347e89c..390f8d8 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -14,7 +14,7 @@ INC-Linux= adsl.sh apipa.sh arping.sh bonding.sh br2684ctl.sh bridge.sh \
ccwgroup.sh clip.sh ethtool.sh iproute2.sh ifplugd.sh ip6to4.sh \
ipppd.sh iwconfig.sh netplugd.sh pppd.sh pump.sh tuntap.sh udhcpc.sh \
vlan.sh macvlan.sh ip6rd.sh firewalld.sh dummy.sh hsr.sh l2tp.sh \
- iw.sh
+ iw.sh wireguard.sh
SRCS-NetBSD= ifwatchd.sh.in
INC-NetBSD= ifwatchd.sh
diff --git a/net/wireguard.sh b/net/wireguard.sh
new file mode 100644
index 0000000..efa45b0
--- /dev/null
+++ b/net/wireguard.sh
@@ -0,0 +1,53 @@
+# Copyright (c) 2016 Gentoo Foundation
+# Released under the 2-clause BSD license.
+
+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
+}