Skip to content

Commit b4cb5a9

Browse files
committed
Make the VPN MTU explicit
This doesn't solve an immediate issue, but removes the risk that we overflow the VpnRunnable buffer, which assumes a default MTU of 1500.
1 parent 5e3df45 commit b4cb5a9

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

app/src/main/java/tech/httptoolkit/android/ProxyVpnRunnable.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import java.io.FileOutputStream
1313
import java.net.InetSocketAddress
1414
import java.nio.ByteBuffer
1515

16-
// Taken from ToyShark - I suspect this is somewhat arbitrary
17-
private const val MAX_PACKET_LEN = 1500
16+
// Set on our VPN as the MTU, which should guarantee all packets fit this
17+
const val MAX_PACKET_LEN = 1500
1818

1919
class ProxyVpnRunnable(
2020
vpnInterface: ParcelFileDescriptor,

app/src/main/java/tech/httptoolkit/android/ProxyVpnService.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ class ProxyVpnService : VpnService(), IProtectSocket {
148148
vpnInterface = Builder()
149149
.addAddress(VPN_IP_ADDRESS, 32)
150150
.addRoute(ALL_ROUTES, 0)
151-
.setBlocking(true) // We use a blocking loop to read this in ProxyVpnRunnable
151+
152+
.setMtu(MAX_PACKET_LEN) // Limit the packet size to the buffer used by ProxyVpnRunnable
153+
.setBlocking(true) // We use a blocking loop to read in ProxyVpnRunnable
154+
152155
.apply {
153156
// We exclude ourselves from interception, so we can still make network requests
154157
// separately, primarily because otherwise pinging with isReachable is recursive.

0 commit comments

Comments
 (0)