Skip to content

Commit 07545a9

Browse files
committed
wireguard: use syncconf in newwanip event
setconf can fail for DNS resolution reasons. It is being considered a configuration parsing error so nothing gets set on the instance. However, our code remembers that the instance was fully set up although that is not the case. The newwanip event was handling DNS renew but does not understand that the configuration is not complete. Replacing reresolve-dns.py by doing syncconf works, but this is used as a cron-based script and likely does the job it is intended for. Instead rehook the newwanip event into a simple syncconf invoke which takes "more" time (according to the man page) but won't touch existing peers being connected while still fixing any configuration mismatch in the (possibly stale) instance.
1 parent 6f6284f commit 07545a9

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/etc/inc/plugins.inc.d/wireguard.inc

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function wireguard_prepare($device)
144144
function wireguard_configure()
145145
{
146146
return [
147-
'newwanip' => ['wireguard_renew:2'],
147+
'newwanip' => ['wireguard_sync:2'],
148148
'vpn' => ['wireguard_configure_do:2'],
149149
];
150150
}
@@ -162,15 +162,32 @@ function wireguard_configure_do($verbose = false, $unused = '')
162162
service_log("done.\n", $verbose);
163163
}
164164

165-
function wireguard_renew($verbose = false, $unused = '')
165+
function wireguard_sync($verbose = false, $unused = '')
166166
{
167167
if (!wireguard_enabled()) {
168168
return;
169169
}
170170

171-
service_log('Renewing WireGuard VPN...', $verbose);
171+
$instances = [];
172+
foreach ((new OPNsense\Wireguard\Server())->servers->server->iterateItems() as $node) {
173+
if (!empty((string)$node->enabled)) {
174+
$instances[(string)$node->interface] = (string)$node->cnfFilename;
175+
}
176+
}
177+
178+
if (!count($instances)) {
179+
return;
180+
}
181+
182+
service_log('Synchronizing WireGuard VPN...', $verbose);
183+
184+
openlog('wireguard', LOG_ODELAY, LOG_AUTH);
185+
186+
foreach ($instances as $device => $config) {
187+
mwexecf('/usr/bin/wg syncconf %s %s', [$device, $config]);
188+
}
172189

173-
configd_run('wireguard renew');
190+
reopenlog();
174191

175192
service_log("done.\n", $verbose);
176193
}

0 commit comments

Comments
 (0)