patchpanel: simplify traffic account jump rules

This patch simplifies the creation of traffic accounting jump rules by
adding a single check point for returning early if traffic account rules
for a given interface already exist.

BUG=b:161060333
BUG=b:160112868
TEST=Unit tests. Checked GetTrafficCounters still work with:
  $ dbus-send --system --dest=org.chromium.PatchPanel --print-reply \
    /org/chromium/PatchPanel org.chromium.PatchPanel.GetTrafficCounters
Checked that accounting chains and jump rules for eth0 are created only
once when plugging in and out an eth adapter multiple times.

Change-Id: I60afecf58466177686b815726b7b5f4ff4d7ce93
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2562980
Reviewed-by: Jie Jiang <jiejiang@chromium.org>
Commit-Queue: Hugo Benichi <hugobenichi@google.com>
Tested-by: Hugo Benichi <hugobenichi@google.com>
diff --git a/patchpanel/datapath.h b/patchpanel/datapath.h
index adde6d0..a638747 100644
--- a/patchpanel/datapath.h
+++ b/patchpanel/datapath.h
@@ -247,6 +247,11 @@
                    const std::string& op,
                    const std::string& chain,
                    bool log_failures = true);
+  // Sends an iptables command for table |table|.
+  bool ModifyIptables(IpFamily family,
+                      const std::string& table,
+                      const std::vector<std::string>& argv,
+                      bool log_failures = true);
 
   MinijailedProcessRunner& runner() const;
 
@@ -342,10 +347,6 @@
                                const std::string& iif,
                                Fwmark mark,
                                Fwmark mask);
-  bool ModifyIptables(IpFamily family,
-                      const std::string& table,
-                      const std::vector<std::string>& argv,
-                      bool log_failures = true);
   bool ModifyRtentry(ioctl_req_t op, struct rtentry* route);
   int FindIfIndex(const std::string& ifname);