Merge "Fix negative uid stats caused by 464xlat adjust when eBPF is on." am: 0d63da86e2 am: a38302f84f
am: fcb523e095
Change-Id: I9d0d8b67ed0159ba2a71059620ebe5698eb79ccb
This commit is contained in:
@@ -811,14 +811,19 @@ public class NetworkStats implements Parcelable {
|
|||||||
* packet needs to be subtracted from the root UID on the base interface both for tx
|
* packet needs to be subtracted from the root UID on the base interface both for tx
|
||||||
* and rx traffic (http://b/12249687, http:/b/33681750).
|
* and rx traffic (http://b/12249687, http:/b/33681750).
|
||||||
*
|
*
|
||||||
|
* As for eBPF, the per uid stats is collected by different hook, the rx packets on base
|
||||||
|
* interface will not be counted. Thus, the adjustment on root uid is only needed in tx
|
||||||
|
* direction.
|
||||||
|
*
|
||||||
* <p>This method will behave fine if {@code stackedIfaces} is an non-synchronized but add-only
|
* <p>This method will behave fine if {@code stackedIfaces} is an non-synchronized but add-only
|
||||||
* {@code ConcurrentHashMap}
|
* {@code ConcurrentHashMap}
|
||||||
* @param baseTraffic Traffic on the base interfaces. Will be mutated.
|
* @param baseTraffic Traffic on the base interfaces. Will be mutated.
|
||||||
* @param stackedTraffic Stats with traffic stacked on top of our ifaces. Will also be mutated.
|
* @param stackedTraffic Stats with traffic stacked on top of our ifaces. Will also be mutated.
|
||||||
* @param stackedIfaces Mapping ipv6if -> ipv4if interface where traffic is counted on both.
|
* @param stackedIfaces Mapping ipv6if -> ipv4if interface where traffic is counted on both.
|
||||||
|
* @param useBpfStats True if eBPF is in use.
|
||||||
*/
|
*/
|
||||||
public static void apply464xlatAdjustments(NetworkStats baseTraffic,
|
public static void apply464xlatAdjustments(NetworkStats baseTraffic,
|
||||||
NetworkStats stackedTraffic, Map<String, String> stackedIfaces) {
|
NetworkStats stackedTraffic, Map<String, String> stackedIfaces, boolean useBpfStats) {
|
||||||
// Total 464xlat traffic to subtract from uid 0 on all base interfaces.
|
// Total 464xlat traffic to subtract from uid 0 on all base interfaces.
|
||||||
// stackedIfaces may grow afterwards, but NetworkStats will just be resized automatically.
|
// stackedIfaces may grow afterwards, but NetworkStats will just be resized automatically.
|
||||||
final NetworkStats adjustments = new NetworkStats(0, stackedIfaces.size());
|
final NetworkStats adjustments = new NetworkStats(0, stackedIfaces.size());
|
||||||
@@ -837,15 +842,20 @@ public class NetworkStats implements Parcelable {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Subtract any 464lat traffic seen for the root UID on the current base interface.
|
// Subtract any 464lat traffic seen for the root UID on the current base interface.
|
||||||
|
// However, for eBPF, the per uid stats is collected by different hook, the rx packets
|
||||||
|
// on base interface will not be counted. Thus, the adjustment on root uid is only
|
||||||
|
// needed in tx direction.
|
||||||
adjust.iface = baseIface;
|
adjust.iface = baseIface;
|
||||||
adjust.rxBytes = -(entry.rxBytes + entry.rxPackets * IPV4V6_HEADER_DELTA);
|
if (!useBpfStats) {
|
||||||
|
adjust.rxBytes = -(entry.rxBytes + entry.rxPackets * IPV4V6_HEADER_DELTA);
|
||||||
|
adjust.rxPackets = -entry.rxPackets;
|
||||||
|
}
|
||||||
adjust.txBytes = -(entry.txBytes + entry.txPackets * IPV4V6_HEADER_DELTA);
|
adjust.txBytes = -(entry.txBytes + entry.txPackets * IPV4V6_HEADER_DELTA);
|
||||||
adjust.rxPackets = -entry.rxPackets;
|
|
||||||
adjust.txPackets = -entry.txPackets;
|
adjust.txPackets = -entry.txPackets;
|
||||||
adjustments.combineValues(adjust);
|
adjustments.combineValues(adjust);
|
||||||
|
|
||||||
// For 464xlat traffic, xt_qtaguid only counts the bytes of the native IPv4 packet sent
|
// For 464xlat traffic, per uid stats only counts the bytes of the native IPv4 packet
|
||||||
// on the stacked interface with prefix "v4-" and drops the IPv6 header size after
|
// sent on the stacked interface with prefix "v4-" and drops the IPv6 header size after
|
||||||
// unwrapping. To account correctly for on-the-wire traffic, add the 20 additional bytes
|
// unwrapping. To account correctly for on-the-wire traffic, add the 20 additional bytes
|
||||||
// difference for all packets (http://b/12249687, http:/b/33681750).
|
// difference for all packets (http://b/12249687, http:/b/33681750).
|
||||||
entry.rxBytes += entry.rxPackets * IPV4V6_HEADER_DELTA;
|
entry.rxBytes += entry.rxPackets * IPV4V6_HEADER_DELTA;
|
||||||
@@ -864,8 +874,8 @@ public class NetworkStats implements Parcelable {
|
|||||||
* base and stacked traffic.
|
* base and stacked traffic.
|
||||||
* @param stackedIfaces Mapping ipv6if -> ipv4if interface where traffic is counted on both.
|
* @param stackedIfaces Mapping ipv6if -> ipv4if interface where traffic is counted on both.
|
||||||
*/
|
*/
|
||||||
public void apply464xlatAdjustments(Map<String, String> stackedIfaces) {
|
public void apply464xlatAdjustments(Map<String, String> stackedIfaces, boolean useBpfStats) {
|
||||||
apply464xlatAdjustments(this, this, stackedIfaces);
|
apply464xlatAdjustments(this, this, stackedIfaces, useBpfStats);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -113,11 +113,12 @@ public class NetworkStatsFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies 464xlat adjustments with ifaces noted with {@link #noteStackedIface(String, String)}.
|
* Applies 464xlat adjustments with ifaces noted with {@link #noteStackedIface(String, String)}.
|
||||||
* @see NetworkStats#apply464xlatAdjustments(NetworkStats, NetworkStats, Map)
|
* @see NetworkStats#apply464xlatAdjustments(NetworkStats, NetworkStats, Map, boolean)
|
||||||
*/
|
*/
|
||||||
public static void apply464xlatAdjustments(NetworkStats baseTraffic,
|
public static void apply464xlatAdjustments(NetworkStats baseTraffic,
|
||||||
NetworkStats stackedTraffic) {
|
NetworkStats stackedTraffic, boolean useBpfStats) {
|
||||||
NetworkStats.apply464xlatAdjustments(baseTraffic, stackedTraffic, sStackedIfaces);
|
NetworkStats.apply464xlatAdjustments(baseTraffic, stackedTraffic, sStackedIfaces,
|
||||||
|
useBpfStats);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -263,7 +264,7 @@ public class NetworkStatsFactory {
|
|||||||
|
|
||||||
// No locking here: apply464xlatAdjustments behaves fine with an add-only ConcurrentHashMap.
|
// No locking here: apply464xlatAdjustments behaves fine with an add-only ConcurrentHashMap.
|
||||||
// TODO: remove this and only apply adjustments in NetworkStatsService.
|
// TODO: remove this and only apply adjustments in NetworkStatsService.
|
||||||
stats.apply464xlatAdjustments(sStackedIfaces);
|
stats.apply464xlatAdjustments(sStackedIfaces, mUseBpfStats);
|
||||||
|
|
||||||
return stats;
|
return stats;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1627,7 +1627,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
// fold tethering stats and operations into uid snapshot
|
// fold tethering stats and operations into uid snapshot
|
||||||
final NetworkStats tetherSnapshot = getNetworkStatsTethering(STATS_PER_UID);
|
final NetworkStats tetherSnapshot = getNetworkStatsTethering(STATS_PER_UID);
|
||||||
tetherSnapshot.filter(UID_ALL, ifaces, TAG_ALL);
|
tetherSnapshot.filter(UID_ALL, ifaces, TAG_ALL);
|
||||||
NetworkStatsFactory.apply464xlatAdjustments(uidSnapshot, tetherSnapshot);
|
NetworkStatsFactory.apply464xlatAdjustments(uidSnapshot, tetherSnapshot,
|
||||||
|
mUseBpfTrafficStats);
|
||||||
uidSnapshot.combineAllValues(tetherSnapshot);
|
uidSnapshot.combineAllValues(tetherSnapshot);
|
||||||
|
|
||||||
final TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(
|
final TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(
|
||||||
@@ -1637,7 +1638,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
final NetworkStats vtStats = telephonyManager.getVtDataUsage(STATS_PER_UID);
|
final NetworkStats vtStats = telephonyManager.getVtDataUsage(STATS_PER_UID);
|
||||||
if (vtStats != null) {
|
if (vtStats != null) {
|
||||||
vtStats.filter(UID_ALL, ifaces, TAG_ALL);
|
vtStats.filter(UID_ALL, ifaces, TAG_ALL);
|
||||||
NetworkStatsFactory.apply464xlatAdjustments(uidSnapshot, vtStats);
|
NetworkStatsFactory.apply464xlatAdjustments(uidSnapshot, vtStats,
|
||||||
|
mUseBpfTrafficStats);
|
||||||
uidSnapshot.combineAllValues(vtStats);
|
uidSnapshot.combineAllValues(vtStats);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user