diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2023-02-27 23:29:04 +0100 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2023-03-23 22:55:18 +0100 |
commit | 9c39e6dccced35856719935743bb75c14f8ead56 (patch) | |
tree | 3db6e6181e2569bd9f0ac62343cc71c8863a0273 /tunnel/src/main | |
parent | d6153ccbff8c1fa8d3648daa16ac26e7c37e4d9d (diff) |
WIP: use first ULA address as DHCPv6 source address
Diffstat (limited to 'tunnel/src/main')
-rw-r--r-- | tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java | 14 | ||||
-rw-r--r-- | tunnel/src/main/java/com/wireguard/util/Resolver.java | 2 | ||||
-rw-r--r-- | tunnel/src/main/proto/libwg.proto | 2 |
3 files changed, 16 insertions, 2 deletions
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 1a5e54dd..00f12bd6 100644 --- a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java +++ b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java @@ -384,8 +384,20 @@ public final class GoBackend implements Backend { private void Dhcp(VpnService service) throws Exception{ obtainDhcpLease = false; + // Heuristics: Use first ULA address as client address + com.wireguard.android.backend.gen.InetAddress source = null; + + for (final InetNetwork net : currentConfig.getInterface().getAddresses()) { + InetAddress addr = net.getAddress(); + if (addr instanceof Inet6Address) { + if (Resolver.isULA((Inet6Address)addr)) { + source = com.wireguard.android.backend.gen.InetAddress.newBuilder().setAddress(ByteString.copyFrom(addr.getAddress())).build(); + } + } + } + LibwgGrpc.LibwgBlockingStub stub = LibwgGrpc.newBlockingStub(channel); - DhcpRequest request = DhcpRequest.newBuilder().build(); + DhcpRequest request = DhcpRequest.newBuilder().setSource(source).build(); DhcpResponse resp = stub.dhcp(request); Log.i(TAG, "Dhcp: " + resp.getError().getMessage()); diff --git a/tunnel/src/main/java/com/wireguard/util/Resolver.java b/tunnel/src/main/java/com/wireguard/util/Resolver.java index f401b584..301e03e0 100644 --- a/tunnel/src/main/java/com/wireguard/util/Resolver.java +++ b/tunnel/src/main/java/com/wireguard/util/Resolver.java @@ -36,7 +36,7 @@ public class Resolver { } } - static boolean isULA(Inet6Address addr) { + public static boolean isULA(Inet6Address addr) { byte[] raw = addr.getAddress(); return ((raw[0] & 0xfe) == 0xfc); } diff --git a/tunnel/src/main/proto/libwg.proto b/tunnel/src/main/proto/libwg.proto index 349166ca..4fa4468b 100644 --- a/tunnel/src/main/proto/libwg.proto +++ b/tunnel/src/main/proto/libwg.proto @@ -115,6 +115,8 @@ message Lease { } message DhcpRequest { + InetAddress relay = 1; + InetAddress source = 2; } message DhcpResponse { |