summaryrefslogtreecommitdiffhomepage
path: root/tunnel/src/main/java/com/wireguard
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2019-04-13 20:37:03 +0200
committerMikael Magnusson <mikma@users.sourceforge.net>2020-03-17 22:27:45 +0100
commitab4e2b29e61e913ce63a4494a3b3cfe069a3bb12 (patch)
treef05fa201e151b272de6dd2356e0ff5da47c746ed /tunnel/src/main/java/com/wireguard
parent553ec49d11eb7ad727b0409982a2285e86f4917d (diff)
Implement get and set tunnel config actions
Add three tunnel actions: com.wireguard.android.action.GET_TUNNEL_CONFIG com.wireguard.android.action.SET_TUNNEL_CONFIG com.wireguard.android.action.SET_TUNNEL_USERSPACE_CONFIG
Diffstat (limited to 'tunnel/src/main/java/com/wireguard')
-rw-r--r--tunnel/src/main/java/com/wireguard/android/backend/Backend.java11
-rw-r--r--tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java18
-rw-r--r--tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java5
3 files changed, 34 insertions, 0 deletions
diff --git a/tunnel/src/main/java/com/wireguard/android/backend/Backend.java b/tunnel/src/main/java/com/wireguard/android/backend/Backend.java
index 4c18d98b..9afda719 100644
--- a/tunnel/src/main/java/com/wireguard/android/backend/Backend.java
+++ b/tunnel/src/main/java/com/wireguard/android/backend/Backend.java
@@ -19,6 +19,17 @@ import androidx.annotation.Nullable;
@NonNullForAll
public interface Backend {
/**
+ * Update the volatile configuration of a running tunnel and return the resulting configuration.
+ * If the tunnel is not up, return the configuration that would result (if known), or else
+ * simply return the given configuration.
+ *
+ * @param tunnel The tunnel to apply the configuration to.
+ * @param config The new configuration for this tunnel.
+ * @return The updated configuration of the tunnel.
+ */
+ Config applyUserspaceConfig(ObservableTunnel tunnel, Config config) throws Exception;
+
+ /**
* Enumerate names of currently-running tunnels.
*
* @return The set of running tunnel names.
diff --git a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java
index 978b39aa..952a30f0 100644
--- a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java
+++ b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java
@@ -61,9 +61,26 @@ public final class GoBackend implements Backend {
private static native int wgTurnOn(String ifName, int tunFd, String settings);
+ private static native String wgGetOperation(int handle);
+
+ private static native int wgSetOperation(int handle, String settings);
+
private static native String wgVersion();
@Override
+ public Config applyUserspaceConfig(final ObservableTunnel tunnel, final Config config) throws Exception {
+ if (currentTunnelHandle != -1) {
+ // Build config
+ final String goConfig = config.toWgUserspaceString();
+
+ Log.d(TAG, "Go backend v" + wgVersion());
+ wgSetOperation(currentTunnelHandle, goConfig);
+ Log.d(TAG, "Settings " + wgGetOperation(currentTunnelHandle));
+ }
+ return config;
+ }
+
+ @Override
public Set<String> getRunningTunnelNames() {
if (currentTunnel != null) {
final Set<String> runningTunnels = new ArraySet<>();
@@ -216,6 +233,7 @@ public final class GoBackend implements Backend {
throw new BackendException(Reason.TUN_CREATION_ERROR);
Log.d(TAG, "Go backend v" + wgVersion());
currentTunnelHandle = wgTurnOn(tunnel.getName(), tun.detachFd(), goConfig);
+ Log.d(TAG, "Settings " + wgGetOperation(currentTunnelHandle));
}
if (currentTunnelHandle < 0)
throw new BackendException(Reason.GO_ACTIVATION_ERROR_CODE, currentTunnelHandle);
diff --git a/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java b/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java
index 78d7d5b6..c6a63691 100644
--- a/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java
+++ b/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java
@@ -55,6 +55,11 @@ public final class WgQuickBackend implements Backend {
}
@Override
+ public Config applyUserspaceConfig(final ObservableTunnel tunnel, final Config config) throws Exception {
+ throw new RuntimeException("Not implemented");
+ }
+
+ @Override
public Set<String> getRunningTunnelNames() {
final List<String> output = new ArrayList<>();
// Don't throw an exception here or nothing will show up in the UI.