net/wireguard: different approach to bootup handling

This commit is contained in:
Franco Fichtner
2023-10-17 08:21:13 +02:00
parent b276276aeb
commit f3695f92d4
3 changed files with 19 additions and 10 deletions
+1
View File
@@ -1,5 +1,6 @@
PLUGIN_NAME= wireguard
PLUGIN_VERSION= 2.3
PLUGIN_REVISION= 1
PLUGIN_COMMENT= WireGuard VPN service kernel implementation
PLUGIN_DEPENDS= wireguard-kmod
PLUGIN_CONFLICTS= wireguard-go
@@ -122,8 +122,23 @@ function wireguard_devices()
function wireguard_prepare($device)
{
mwexecf('/sbin/ifconfig wg create name %s', $device);
mwexecf('/sbin/ifconfig %s group wireguard', $device);
foreach ((new OPNsense\Wireguard\Server())->servers->server->iterateItems() as $node) {
if ($device != (string)$node->interface) {
continue;
}
/* deleting the stat file marks the interface for eventual reconfiguration */
@unlink((string)$node->statFilename);
if (!does_interface_exist($device)) {
mwexecf('/sbin/ifconfig wg create name %s', $device);
mwexecf('/sbin/ifconfig %s group wireguard', $device);
}
return $device;
}
return null;
}
function wireguard_configure()
@@ -223,14 +223,7 @@ if (isset($opts['h']) || empty($args) || !in_array($args[0], ['start', 'stop', '
wg_start($node, $statHandle, $carp_if_flag);
break;
case 'configure':
if (
@md5_file($node->cnfFilename) != get_stat_hash($statHandle)['file'] ||
!isset($ifdetails[(string)$node->interface]) || (
// Interface has been setup, but without configuration
empty($ifdetails[(string)$node->interface]['ipv4']) &&
empty($ifdetails[(string)$node->interface]['ipv6'])
)
) {
if (@md5_file($node->cnfFilename) != get_stat_hash($statHandle)['file']) {
if (get_stat_hash($statHandle)['interface'] != wg_reconfigure_hash($node)) {
// Fluent reloading not supported for this instance, make sure the user is informed
syslog(