BandwidthController: cleanup ipv4/v6, set/remove multiple quotas.

Regroup the ipv4/ipv6 choice deeper down to avoid copypasted code.
Shared quota accross ifaces.
Single quota per ifaces.

Nothing preventing an iface from have a single and shared quota.
Might be close to having a working combination.

Added commands:
 - shared quota
  ndc bandwidth setquotas <quotaBytes> <iface> ...
  ndc bandwidth setquota <iface> <quotaBytes>
  ndc bandwidth removequota <iface>
  ndc bandwidth removequotas <iface> ...

 - quota per iface
  ndc bandwidth setiquota <iface> <quotaBytes>
  ndc bandwidth removeiquota <iface>

Change-Id: I370d223da3c8b6e16e8d0a455309ae9e0756a721
diff --git a/BandwidthController.h b/BandwidthController.h
index 405e2ef..4b0f338 100644
--- a/BandwidthController.h
+++ b/BandwidthController.h
@@ -25,24 +25,40 @@
     int enableBandwidthControl(void);
     int disableBandwidthControl(void);
 
-    int setInterfaceSharedQuota(int64_t bytes, const char *iface);
+    int setInterfaceSharedQuota(const char *iface, int64_t bytes);
     int removeInterfaceSharedQuota(const char *iface);
 
+    int setInterfaceQuota(const char *iface, int64_t bytes);
+    int removeInterfaceQuota(const char *iface);
+
     int addNaughtyApps(int numUids, char *appUids[]);
     int removeNaughtyApps(int numUids, char *appUids[]);
 
+
 protected:
-    int runCommands(int numCommands, const char *commands[],
-            bool allowFailure = false, bool isIpv6 = false);
     typedef std::pair<std::string /*ifaceName*/, int64_t /*quota*/> QuotaInfo;
     enum IptOp {IptOpInsert, IptOpReplace, IptOpDelete};
+
     int64_t sharedQuotaBytes;
-    std::list<QuotaInfo> ifaceRules;
+    std::list<std::string> sharedQuotaIfaces;
+
+    std::list<QuotaInfo> quotaIfaces;
+
     std::list<int /*appUid*/> naughtyAppUids;
-    std::string makeIptablesNaughtyCmd(IptOp op, int uid, bool isIp6);
-    std::string makeIptablesQuotaCmd(IptOp op, char *costName, int64_t quota, bool isIp6);
     int maninpulateNaughtyApps(int numUids, char *appStrUids[], bool doAdd);
 
+    int prepCostlyIface(const char *ifn, bool isShared);
+    int cleanupCostlyIface(const char *ifn, bool isShared);
+
+    std::string makeIptablesNaughtyCmd(IptOp op, int uid);
+    std::string makeIptablesQuotaCmd(IptOp op, char *costName, int64_t quota);
+
+    /* Runs for both ipv4 and ipv6 iptables */
+    int runCommands(int numCommands, const char *commands[], bool allowFailure);
+    /* Runs for both ipv4 and ipv6 iptables, appends -j REJECT --reject-with ...  */
+    static int runIpxtablesCmd(const char *cmd, bool appendReject);
+    static int runIptablesCmd(const char *cmd, bool appendReject, bool isIp6);
+
 private:
     static const char *cleanupCommands[];
     static const char *setupCommands[];
@@ -53,7 +69,6 @@
     static const char IPTABLES_PATH[];
     static const char IP6TABLES_PATH[];
 
-    static int runIptablesCmd(const char *cmd, bool isIp6 = false);
 };
 
 #endif