#!/bin/sh # $FreeBSD: head/net/wireguard-tools/files/wireguard_wgquick.in 569184 2021-03-25 07:34:06Z decke $ # # 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_env (str): Environment variables for the userspace # implementation. (eg: "LOG_LEVEL=debug") . /etc/rc.subr name=wireguard rcvar=wireguard_enable extra_commands="reload" start_cmd="${name}_start" stop_cmd="${name}_stop" reload_cmd="${name}_reload" wireguard_start() { ${wireguard_env:+eval export $wireguard_env} for interface in ${wireguard_interfaces}; do %%PREFIX%%/bin/wg-quick up ${interface} done } wireguard_stop() { for interface in ${wireguard_interfaces}; do %%PREFIX%%/bin/wg-quick down ${interface} done if kldstat -q -n if_wg; then if ! kldunload if_wg > /dev/null 2>&1; then warn "Can't unload if_wg module." return 1 fi fi } wireguard_reload() { ${wireguard_env:+eval export $wireguard_env} for interface in ${wireguard_interfaces}; do tmpfile="`mktemp`" %%PREFIX%%/bin/wg-quick strip ${interface} > ${tmpfile} %%PREFIX%%/bin/wg syncconf ${interface} ${tmpfile} rm -f ${tmpfile} done } load_rc_config $name : ${wireguard_enable="NO"} : ${wireguard_interfaces=""} : ${wireguard_env=""} run_rc_command "$1"