OSDN Git Service

Always add costly interfaces to the bw_FORWARD chain
authorErik Kline <ek@google.com>
Fri, 2 Oct 2015 08:52:37 +0000 (17:52 +0900)
committerErik Kline <ek@google.com>
Wed, 14 Oct 2015 00:07:58 +0000 (09:07 +0900)
This adds a jump to bw_costly_<ifname> for traffic forwarded out
interface <ifname> to the bw_FORWARD chain, regardless of tethering
state (as having it safely in place is harmless).

Bug: 24497044
Change-Id: I165724c319051ddf29a2833912eb286368b0570d

server/BandwidthController.cpp

index d71ce3b..a9bd5e2 100644 (file)
@@ -555,6 +555,12 @@ int BandwidthController::prepCostlyIface(const char *ifn, QuotaType quotaType) {
 
     snprintf(cmd, sizeof(cmd), "-I bw_OUTPUT %d -o %s --jump %s", ruleInsertPos, ifn, costCString);
     res |= runIpxtablesCmd(cmd, IptJumpNoAdd);
+
+    snprintf(cmd, sizeof(cmd), "-D bw_FORWARD -o %s --jump %s", ifn, costCString);
+    runIpxtablesCmd(cmd, IptJumpNoAdd, IptFailHide);
+    snprintf(cmd, sizeof(cmd), "-A bw_FORWARD -o %s --jump %s", ifn, costCString);
+    res |= runIpxtablesCmd(cmd, IptJumpNoAdd);
+
     return res;
 }
 
@@ -580,8 +586,10 @@ int BandwidthController::cleanupCostlyIface(const char *ifn, QuotaType quotaType
 
     snprintf(cmd, sizeof(cmd), "-D bw_INPUT -i %s --jump %s", ifn, costCString);
     res |= runIpxtablesCmd(cmd, IptJumpNoAdd);
-    snprintf(cmd, sizeof(cmd), "-D bw_OUTPUT -o %s --jump %s", ifn, costCString);
-    res |= runIpxtablesCmd(cmd, IptJumpNoAdd);
+    for (const auto tableName : {LOCAL_OUTPUT, LOCAL_FORWARD}) {
+        snprintf(cmd, sizeof(cmd), "-D %s -o %s --jump %s", tableName, ifn, costCString);
+        res |= runIpxtablesCmd(cmd, IptJumpNoAdd);
+    }
 
     /* The "-N bw_costly_shared" is created upfront, no need to handle it here. */
     if (quotaType == QuotaUnique) {