patchpanel: add traffic accounting rules for sources
This patch adds to the traffic accounting chains the traffic counter
rules matching individual sources based on the fwmark source tag of the
traffic.
BUG=b:160112868
TEST=unit tests, flashed rammus, checked with iptables that counter
rules are incremented. Checked GetTrafficCounters still work with:
$ dbus-send --system --dest=org.chromium.PatchPanel --print-reply \
/org/chromium/PatchPanel org.chromium.PatchPanel.GetTrafficCounters
Change-Id: I24b29911923ecf227837c17447959201fa980431
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2562981
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/routing_service.h b/patchpanel/routing_service.h
index 57db00e..b09d981 100644
--- a/patchpanel/routing_service.h
+++ b/patchpanel/routing_service.h
@@ -204,6 +204,11 @@
constexpr std::array<TrafficSource, 5> kForwardedSources{
{ARC, CROSVM, PLUGINVM, TETHER_DOWNSTREAM, ARC_VPN}};
+// All sources
+constexpr std::array<TrafficSource, 10> kAllSources{
+ {CHROME, USER, UPDATE_ENGINE, SYSTEM, HOST_VPN, ARC, CROSVM, PLUGINVM,
+ TETHER_DOWNSTREAM, ARC_VPN}};
+
// Constant fwmark value for tagging traffic with the "route-on-vpn" intent.
constexpr const Fwmark kFwmarkRouteOnVpn = {.policy = 0x80};
// Constant fwmark value for tagging traffic with the "bypass-vpn" intent.