ports/net/wireguard-tools/files/wireguard_lite.in
Bernhard Froehlich c83f22d493
net/wireguard-tools: Revert kldunload from rc.d scripts
Unloading if_wg(4) kmod was added to rc.d scripts to make sure that a
service restart also reload the kernel module.

Now we don't have frequent updates anymore and the wireguard-kmod port
will soon be gone but people using this script face issues in VNET jails.

This commit reverts 562d171b9d

PR:		274428
Reported by:	vedad@kajtaz.net
2023-11-06 11:09:20 +00:00

111 lines
2.7 KiB
Bash

#!/bin/sh
# PROVIDE: wireguard
# REQUIRE: NETWORKING
# 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_confdir (str): Config directory that contains wg0.conf
# (default: "%%PREFIX%%/etc/wireguard")
# wireguard_<iface>_ips (str): List of IP Addresses for iface
# wireguard_<iface>_routes (str): List of Routes for this iface
# wireguard_<iface>_mtu (str): MTU for iface (default: "1500")
. /etc/rc.subr
name=wireguard
rcvar=wireguard_enable
extra_commands="reload status"
start_cmd="${name}_start"
stop_cmd="${name}_stop"
reload_cmd="${name}_reload"
status_cmd="${name}_status"
wireguard_start()
{
for interface in ${wireguard_interfaces}; do
load_rc_config wireguard_${interface}
eval wireguard_ips="\${wireguard_${interface}_ips}"
eval wireguard_routes="\${wireguard_${interface}_routes}"
eval wireguard_mtu="\${wireguard_${interface}_mtu}"
ifconfig ${interface} create
%%PREFIX%%/bin/wg setconf ${interface} ${wireguard_confdir}/${interface}.conf
for ip in ${wireguard_ips}; do
if [ "${ip#*:}" != "${ip}" ]; then
ifconfig ${interface} inet6 ${ip} alias
else
ifconfig ${interface} inet ${ip} alias
fi
done
if [ ! -z "${wireguard_mtu}" ]; then
ifconfig ${interface} mtu ${wireguard_mtu}
fi
ifconfig ${interface} up
for route in ${wireguard_routes}; do
if [ "${route#*:}" != "${route}" ]; then
route -q -n add -inet6 ${route} -interface ${interface}
else
route -q -n add -inet ${route} -interface ${interface}
fi
done
done
}
wireguard_stop()
{
for interface in ${wireguard_interfaces}; do
load_rc_config wireguard_${interface}
eval wireguard_routes="\${wireguard_${interface}_routes}"
for route in ${wireguard_routes}; do
if [ "${route#*:}" != "${route}" ]; then
route -q -n delete -inet6 ${route} -interface ${interface}
else
route -q -n delete -inet ${route} -interface ${interface}
fi
done
ifconfig ${interface} down
ifconfig ${interface} destroy
done
}
wireguard_reload()
{
for interface in ${wireguard_interfaces}; do
%%PREFIX%%/bin/wg syncconf ${interface} ${wireguard_confdir}/${interface}.conf
done
}
wireguard_status()
{
wireguard_status="0"
for interface in ${wireguard_interfaces}; do
%%PREFIX%%/bin/wg show ${interface} || wireguard_status="1"
done
return ${wireguard_status}
}
load_rc_config $name
: ${wireguard_enable="NO"}
: ${wireguard_interfaces=""}
: ${wireguard_confdir="%%PREFIX%%/etc/wireguard"}
run_rc_command "$1"