tunnel: add windows-style killswitch semantics for GoBackend
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
3208bac987
commit
8e2d63db75
@ -9,6 +9,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
|
import android.system.OsConstants;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.wireguard.android.backend.BackendException.Reason;
|
import com.wireguard.android.backend.BackendException.Reason;
|
||||||
@ -202,9 +203,19 @@ public final class GoBackend implements Backend {
|
|||||||
for (final InetAddress addr : config.getInterface().getDnsServers())
|
for (final InetAddress addr : config.getInterface().getDnsServers())
|
||||||
builder.addDnsServer(addr.getHostAddress());
|
builder.addDnsServer(addr.getHostAddress());
|
||||||
|
|
||||||
|
boolean sawDefaultRoute = false;
|
||||||
for (final Peer peer : config.getPeers()) {
|
for (final Peer peer : config.getPeers()) {
|
||||||
for (final InetNetwork addr : peer.getAllowedIps())
|
for (final InetNetwork addr : peer.getAllowedIps()) {
|
||||||
|
if (addr.getMask() == 0)
|
||||||
|
sawDefaultRoute = true;
|
||||||
builder.addRoute(addr.getAddress(), addr.getMask());
|
builder.addRoute(addr.getAddress(), addr.getMask());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// "Kill-switch" semantics
|
||||||
|
if (!(sawDefaultRoute && config.getPeers().size() == 1)) {
|
||||||
|
builder.allowFamily(OsConstants.AF_INET);
|
||||||
|
builder.allowFamily(OsConstants.AF_INET6);
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.setMtu(config.getInterface().getMtu().orElse(1280));
|
builder.setMtu(config.getInterface().getMtu().orElse(1280));
|
||||||
|
Loading…
Reference in New Issue
Block a user