GoBackend: default MTU is 1280

This sucks, but it works with mobile networks. Later we can do something
sophisticated like we do with wg-quick.c, but not now.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld
2018-04-17 05:59:23 +02:00
parent b5360871e8
commit 140fb395dc
3 changed files with 16 additions and 7 deletions
@@ -72,7 +72,7 @@ public final class GoBackend implements Backend {
private static native void wgTurnOff(int handle);
private static native int wgTurnOn(String ifName, int tunFd, String settings);
private static native int wgTurnOn(String ifName, int tunFd, int mtu, String settings);
@Override
public Config applyConfig(final Tunnel tunnel, final Config config) throws Exception {
@@ -244,12 +244,21 @@ public final class GoBackend implements Backend {
}
}
int mtu = -1;
try {
mtu = Integer.parseInt(config.getInterface().getMtu(), 10);
} catch (Exception e) {
}
if (mtu < 0)
mtu = 1280;
builder.setMtu(mtu);
builder.setBlocking(true);
ParcelFileDescriptor tun = builder.establish();
if (tun == null)
throw new Exception("Unable to create tun device");
currentTunnelHandle = wgTurnOn(tunnel.getName(), tun.detachFd(), fmt.toString());
currentTunnelHandle = wgTurnOn(tunnel.getName(), tun.detachFd(), mtu, fmt.toString());
if (currentTunnelHandle < 0)
throw new Exception("Unable to turn tunnel on (wgTurnOn return " + currentTunnelHandle + ")");