From e5e15aee20874d93ad457f860b43fdcf93af4baf Mon Sep 17 00:00:00 2001 From: junyulai Date: Fri, 28 Jun 2019 16:47:49 +0800 Subject: [PATCH] Fix mobile data usage didn't get increased for xlat464 traffic Interface stats on stacked interfaces is usually clatd. For xt_qtaguid supported device, the stats is already accounted against its final egress interface by the kernel. Framework side does not need to handle stats on statcked interface at all. However, on devices that support BPF offload, xlat464 packets are seen by the iptables rules as arriving on stack interface only. Thus, add stack interface into accounting is needed. Bug: 136193260 Test: 1. atest FrameworksNetTests 2. atest android.app.usage.cts.NetworkUsageStatsTest 3. manual test on ipv6-only wifi network Change-Id: I8ebbefbe4df00e40f4896a17fa52c8438d41286e --- .../android/server/net/NetworkStatsService.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/net/NetworkStatsService.java b/services/core/java/com/android/server/net/NetworkStatsService.java index 4f4377df09..90dc700e7d 100644 --- a/services/core/java/com/android/server/net/NetworkStatsService.java +++ b/services/core/java/com/android/server/net/NetworkStatsService.java @@ -1180,14 +1180,22 @@ public class NetworkStatsService extends INetworkStatsService.Stub { } } - // Traffic occurring on stacked interfaces is usually clatd, - // which is already accounted against its final egress interface - // by the kernel. Thus, we only need to collect stacked - // interface stats at the UID level. + // Traffic occurring on stacked interfaces is usually clatd. + // UID stats are always counted on the stacked interface and never + // on the base interface, because the packets on the base interface + // do not actually match application sockets until they are translated. + // + // Interface stats are more complicated. Packets subject to BPF offload + // never appear on the base interface and only appear on the stacked + // interface, so to ensure those packets increment interface stats, interface + // stats from stacked interfaces must be collected. final List stackedLinks = state.linkProperties.getStackedLinks(); for (LinkProperties stackedLink : stackedLinks) { final String stackedIface = stackedLink.getInterfaceName(); if (stackedIface != null) { + if (mUseBpfTrafficStats) { + findOrCreateNetworkIdentitySet(mActiveIfaces, stackedIface).add(ident); + } findOrCreateNetworkIdentitySet(mActiveUidIfaces, stackedIface).add(ident); if (isMobile) { mobileIfaces.add(stackedIface);