From 2ed1f987eb97d922cd984ae078e4023a70b54c3e Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Fri, 27 Jan 2023 08:24:58 +0100 Subject: [PATCH] net/wireguard: deal with kmod service status; closes #3273 Shift the name from wireguard-go to wireguard in this case. HA between go and kmod is probably not going to work fully as the service name shifts, but eventually go should be gone. Since wireguard rc.d script misuses "status" we don't know what the status is and since the kmod has no "process" either we have nothing to go on so the stop and start actions cannot be cleanly represented and are instead replaced by a single restart. If you want to stop wireguard from the GUI it needs to be disabled in its settings. --- net/wireguard/Makefile | 2 +- .../src/etc/inc/plugins.inc.d/wireguard.inc | 55 ++++++++++++------- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/net/wireguard/Makefile b/net/wireguard/Makefile index bc605c893..fde39474f 100644 --- a/net/wireguard/Makefile +++ b/net/wireguard/Makefile @@ -1,6 +1,6 @@ PLUGIN_NAME= wireguard PLUGIN_VERSION= 1.13 -PLUGIN_REVISION= 3 +PLUGIN_REVISION= 4 PLUGIN_COMMENT= WireGuard VPN service PLUGIN_DEPENDS= wireguard-tools PLUGIN_MAINTAINER= m.muenz@gmail.com diff --git a/net/wireguard/src/etc/inc/plugins.inc.d/wireguard.inc b/net/wireguard/src/etc/inc/plugins.inc.d/wireguard.inc index 365ffc916..cc1e49ee8 100644 --- a/net/wireguard/src/etc/inc/plugins.inc.d/wireguard.inc +++ b/net/wireguard/src/etc/inc/plugins.inc.d/wireguard.inc @@ -34,49 +34,66 @@ function wireguard_enabled() function wireguard_services() { - $services = array(); + $services = []; if (!wireguard_enabled()) { return $services; } - $services[] = array( + $service = [ 'description' => gettext('WireGuard VPN'), - 'configd' => array( - 'restart' => array('wireguard restart'), - 'start' => array('wireguard start'), - 'stop' => array('wireguard stop'), - ), - 'name' => 'wireguard-go' - ); + 'configd' => [ + 'restart' => ['wireguard restart'], + 'start' => ['wireguard start'], + 'stop' => ['wireguard stop'], + ], + 'name' => 'wireguard-go', + ]; + + if (file_exists('/boot/modules/if_wg.ko') || file_exists('/boot/kernel/if_wg.ko')) { + $service['name'] = 'wireguard'; + $service['nocheck'] = true; + } + + $services[] = $service; return $services; } function wireguard_interfaces() { - $interfaces = array(); + $interfaces = []; + if (!wireguard_enabled()) { return $interfaces; } - $oic = array('enable' => true); - $oic['if'] = 'wireguard'; - $oic['descr'] = gettext('WireGuard (Group)'); - $oic['type'] = 'group'; - $oic['virtual'] = true; - $oic['networks'] = array(); - $interfaces['wireguard'] = $oic; + + $interfaces['wireguard'] = [ + 'descr' => gettext('WireGuard (Group)'), + 'if' => 'wireguard', + 'virtual' => true, + 'enable' => true, + 'type' => 'group', + 'networks' => [], + ]; + return $interfaces; } function wireguard_xmlrpc_sync() { - $result = array(); + $result = []; + $result['id'] = 'wireguard'; $result['section'] = 'OPNsense.wireguard'; $result['description'] = gettext('WireGuard'); $result['services'] = ['wireguard-go']; - return array($result); + + if (file_exists('/boot/modules/if_wg.ko') || file_exists('/boot/kernel/if_wg.ko')) { + $result['services'] = ['wireguard']; + } + + return [$result]; } function wireguard_devices()