From 6b6f22fac4c33fcd349aaf6970bbdc191db752a3 Mon Sep 17 00:00:00 2001 From: Gordon Gao Date: Thu, 18 Sep 2014 11:50:09 -0700 Subject: [PATCH] Enable tcp mss clamp for Tethering With this change, IPv4 tethering clients (such as PC) with default MTU size 1500 will be configured again in the phone to use MTU matching the carrier network, then no IP fragemention in the phone and have higher data throughput for tethering. bug:17552732 Change-Id: Ia306b1b8454da1b0e2d9c320e770aeff172d5fc4 --- server/NatController.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/server/NatController.cpp b/server/NatController.cpp index 902756b..d9a779c 100644 --- a/server/NatController.cpp +++ b/server/NatController.cpp @@ -83,12 +83,25 @@ int NatController::setupIptablesHooks() { struct CommandsAndArgs defaultCommands[] = { /* - * Chain for tethering counters. + * First chain is for tethering counters. * This chain is reached via --goto, and then RETURNS. + * + * Second chain is used to limit downstream mss to the upstream pmtu + * so we don't end up fragmenting every large packet tethered devices + * send. Note this feature requires kernel support with flag + * CONFIG_NETFILTER_XT_TARGET_TCPMSS=y, which not all builds will have, + * so the final rule is allowed to fail. + * Bug 17629786 asks to make the failure more obvious, or even fatal + * so that all builds eventually gain the performance improvement. */ {{IPTABLES_PATH, "-F", LOCAL_TETHER_COUNTERS_CHAIN,}, 0}, {{IPTABLES_PATH, "-X", LOCAL_TETHER_COUNTERS_CHAIN,}, 0}, {{IPTABLES_PATH, "-N", LOCAL_TETHER_COUNTERS_CHAIN,}, 1}, + {{IPTABLES_PATH, "-t", "mangle", "-F", LOCAL_FORWARD,}, 0}, + {{IPTABLES_PATH, "-t", "mangle", "-X", LOCAL_FORWARD,}, 0}, + {{IPTABLES_PATH, "-t", "mangle", "-N", LOCAL_FORWARD,}, 1}, + {{IPTABLES_PATH, "-t", "mangle", "-A", LOCAL_FORWARD, "-p", "tcp", "--tcp-flags", + "SYN", "SYN", "-j", "TCPMSS", "--clamp-mss-to-pmtu"}, 0}, }; for (unsigned int cmdNum = 0; cmdNum < ARRAY_SIZE(defaultCommands); cmdNum++) { if (runCmd(ARRAY_SIZE(defaultCommands[cmdNum].cmd), defaultCommands[cmdNum].cmd) && -- 2.11.0