tunnel: add isAlwaysOn and isLockdownEnabled

Signed-off-by: Brandon T <JustBrandonT@gmail.com>
[Harsh: fix build and Javadoc errors]
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Brandon T
2025-10-20 18:22:36 +02:00
committed by Jason A. Donenfeld
parent 89c0bb6c7a
commit 0d18e478ca
3 changed files with 50 additions and 0 deletions
@@ -52,6 +52,28 @@ public interface Backend {
*/ */
String getVersion() throws Exception; String getVersion() throws Exception;
/**
* Determines whether the service is running in always-on VPN mode.
* In this mode the system ensures that the service is always running by restarting it when necessary,
* e.g. after reboot.
*
* @return A boolean indicating whether the service is running in always-on VPN mode.
* @throws Exception Exception raised while retrieving the always-on status.
*/
boolean isAlwaysOn() throws Exception;
/**
* Determines whether the service is running in always-on VPN lockdown mode.
* In this mode the system ensures that the service is always running and that the apps
* aren't allowed to bypass the VPN.
*
* @return A boolean indicating whether the service is running in always-on VPN lockdown mode.
* @throws Exception Exception raised while retrieving the lockdown status.
*/
boolean isLockdownEnabled() throws Exception;
/** /**
* Set the state of a tunnel, updating it's configuration. If the tunnel is already up, config * Set the state of a tunnel, updating it's configuration. If the tunnel is already up, config
* may update the running configuration; config may be null when setting the tunnel down. * may update the running configuration; config may be null when setting the tunnel down.
@@ -188,6 +188,24 @@ public final class GoBackend implements Backend {
return wgVersion(); return wgVersion();
} }
/**
* Determines if the service is running in always-on VPN mode.
* @return {@link boolean} whether the service is running in always-on VPN mode.
*/
@Override
public boolean isAlwaysOn() throws ExecutionException, InterruptedException, TimeoutException {
return vpnService.get(0, TimeUnit.NANOSECONDS).isAlwaysOn();
}
/**
* Determines if the service is running in always-on VPN lockdown mode.
* @return {@link boolean} whether the service is running in always-on VPN lockdown mode.
*/
@Override
public boolean isLockdownEnabled() throws ExecutionException, InterruptedException, TimeoutException {
return vpnService.get(0, TimeUnit.NANOSECONDS).isLockdownEnabled();
}
/** /**
* Change the state of a given {@link Tunnel}, optionally applying a given {@link Config}. * Change the state of a given {@link Tunnel}, optionally applying a given {@link Config}.
* *
@@ -109,6 +109,16 @@ public final class WgQuickBackend implements Backend {
return output.get(0); return output.get(0);
} }
@Override
public boolean isAlwaysOn() {
return false;
}
@Override
public boolean isLockdownEnabled() {
return false;
}
public void setMultipleTunnels(final boolean on) { public void setMultipleTunnels(final boolean on) {
multipleTunnels = on; multipleTunnels = on;
} }