#!/bin/sh

# $FreeBSD$
#
# 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_impl (str):       Wireguard userspace implementation
#                             (default: "wireguard-go")
#                             Possible choices:
#                                wireguard-go, boringtun

. /etc/rc.subr

name=wireguard
rcvar=wireguard_enable

start_cmd="${name}_start"
stop_cmd="${name}_stop"

wireguard_start()
{
	export WG_QUICK_USERSPACE_IMPLEMENTATION=${wireguard_impl}

	for interface in ${wireguard_interfaces}; do
		/usr/local/bin/wg-quick up ${interface}
	done
}

wireguard_stop()
{
	for interface in ${wireguard_interfaces}; do
		/usr/local/bin/wg-quick down ${interface}
	done
}

load_rc_config $name

: ${wireguard_enable="NO"}
: ${wireguard_interfaces=""}
: ${wireguard_impl="wireguard-go"}

run_rc_command "$1"
