summaryrefslogtreecommitdiffhomepage
path: root/tunnel/src/main/java/com/wireguard/android
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2023-03-27 00:02:42 +0200
committerMikael Magnusson <mikma@users.sourceforge.net>2023-05-10 21:08:27 +0200
commit395794efe1555e878656ff8865aa81bcab2ce397 (patch)
treee3601709d6d4df25cf05f9cf4eca4815ee81f0aa /tunnel/src/main/java/com/wireguard/android
parenta53fca34c09bf52633b6cbd1cb245158de92bd54 (diff)
tunnel: support dynamic updates of allowed-ips in Go backend
Diffstat (limited to 'tunnel/src/main/java/com/wireguard/android')
-rw-r--r--tunnel/src/main/java/com/wireguard/android/backend/Backend.java5
-rw-r--r--tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java23
-rw-r--r--tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java6
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 edf98b9e..5ffdf8e2 100644
--- a/tunnel/src/main/java/com/wireguard/android/backend/Backend.java
+++ b/tunnel/src/main/java/com/wireguard/android/backend/Backend.java
@@ -6,8 +6,11 @@
package com.wireguard.android.backend;
import com.wireguard.config.Config;
+import com.wireguard.config.InetNetwork;
+import com.wireguard.crypto.Key;
import com.wireguard.util.NonNullForAll;
+import java.util.List;
import java.util.Set;
import androidx.annotation.Nullable;
@@ -64,4 +67,6 @@ public interface Backend {
* @throws Exception Exception raised while changing state.
*/
Tunnel.State setState(Tunnel tunnel, Tunnel.State state, @Nullable Config config) throws Exception;
+
+ void addAllowedIps(Tunnel tunnel, Key publicKey, List<InetNetwork> addNetworks);
}
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 17d6e8b1..24f1adc8 100644
--- a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java
+++ b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java
@@ -303,6 +303,29 @@ public final class GoBackend implements Backend {
return getState(tunnel);
}
+ @Override
+ public void addAllowedIps(Tunnel tunnel, Key publicKey, List<InetNetwork> addNetworks) {
+ if (tunnel != currentTunnel) {
+ // TODO logerror and/or return error/throw.
+ return;
+ }
+
+ StringBuffer sb = new StringBuffer();
+ sb.append("public_key=").append(publicKey.toHex()).append('\n');
+ for (final InetNetwork allowedIp: addNetworks) {
+ sb.append("allowed_ip=").append(allowedIp).append('\n');
+ }
+
+ String goConfig = sb.toString();
+ // TODO removed removeNetworks
+ Log.w(TAG, "Wg user string: " + goConfig);
+
+ LibwgGrpc.LibwgBlockingStub stub = LibwgGrpc.newBlockingStub(channel);
+ TunnelHandle handle = TunnelHandle.newBuilder().setHandle(currentTunnelHandle).build();
+ IpcSetRequest request = IpcSetRequest.newBuilder().setTunnel(handle).setConfig(goConfig).build();
+ IpcSetResponse resp = stub.ipcSet(request);
+ }
+
private static String downloadPacFile(Network network, Uri pacFileUrl) {
HttpURLConnection urlConnection = null;
StringBuffer buf = new StringBuffer();
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 023743a8..2a3ee588 100644
--- a/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java
+++ b/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java
@@ -14,6 +14,7 @@ import com.wireguard.android.backend.Tunnel.State;
import com.wireguard.android.util.RootShell;
import com.wireguard.android.util.ToolsInstaller;
import com.wireguard.config.Config;
+import com.wireguard.config.InetNetwork;
import com.wireguard.crypto.Key;
import com.wireguard.util.NonNullForAll;
@@ -167,6 +168,11 @@ public final class WgQuickBackend implements Backend {
return state;
}
+ @Override
+ public void addAllowedIps(Tunnel tunnel, Key publicKey, List<InetNetwork> addNetworks) {
+ throw new RuntimeException("Not implemented");
+ }
+
private void setStateInternal(final Tunnel tunnel, @Nullable final Config config, final State state) throws Exception {
Log.i(TAG, "Bringing tunnel " + tunnel.getName() + ' ' + state);