diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2019-04-13 20:37:03 +0200 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2022-03-18 23:35:32 +0100 |
commit | 4536f837dd6fb7371026c32c6186989a5b31d435 (patch) | |
tree | ae883703ba086af2397f23e648684cbd29819670 /tunnel/src/main/java/com | |
parent | a04105032137325ba108f219e194ba64842ff9f2 (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')
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 5aaad826..45cd73e5 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 3d0886cf..21c449b9 100644 --- a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java +++ b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java @@ -80,6 +80,10 @@ 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(); /** @@ -88,6 +92,19 @@ public final class GoBackend implements Backend { * @return A set of string values denoting names of running tunnels. */ @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<>(); @@ -305,6 +322,7 @@ public final class GoBackend implements Backend { throw new BackendException(Reason.TUN_CREATION_ERROR); Log.d(TAG, "Go backend " + 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 3121c996..f07a662c 100644 --- a/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java +++ b/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java @@ -58,6 +58,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. |