commit:     66af4525ff3a4530a165443f459134f1f60283f8
Author:     Jason A. Donenfeld <zx2c4 <AT> gentoo <DOT> org>
AuthorDate: Sun May 27 23:56:51 2018 +0000
Commit:     Jason Donenfeld <zx2c4 <AT> gentoo <DOT> org>
CommitDate: Tue Jul 10 21:10:22 2018 +0000
URL:        https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=66af4525

net/wireguard: import from ebuild

Signed-off-by: Jason A. Donenfeld <zx2c4 <AT> gentoo.org>

 net/Makefile     |  2 +-
 net/wireguard.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 1 deletion(-)

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
+}

Reply via email to