Merge "Ignore ipv6 tx traffic on clat uid." am: 191f32fdc7 am: 9c0075aad0

am: 59c7f1a494

Change-Id: I1ac85ac863026ea99117c5b0115bcc0c9144fb7b
This commit is contained in:
Junyu Lai
2019-01-04 08:47:41 -08:00
committed by android-build-merger

View File

@@ -16,6 +16,8 @@
package android.net; package android.net;
import static android.os.Process.CLAT_UID;
import android.annotation.UnsupportedAppUsage; import android.annotation.UnsupportedAppUsage;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
@@ -828,13 +830,15 @@ public class NetworkStats implements Parcelable {
* *
* <p>For 464xlat traffic, xt_qtaguid sees every IPv4 packet twice, once as a native IPv4 * <p>For 464xlat traffic, xt_qtaguid sees every IPv4 packet twice, once as a native IPv4
* packet on the stacked interface, and once as translated to an IPv6 packet on the * packet on the stacked interface, and once as translated to an IPv6 packet on the
* base interface. For correct stats accounting on the base interface, every 464xlat * base interface. For correct stats accounting on the base interface, if using xt_qtaguid,
* packet needs to be subtracted from the root UID on the base interface both for tx * every rx 464xlat packet needs to be subtracted from the root UID on the base interface
* and rx traffic (http://b/12249687, http:/b/33681750). * (http://b/12249687, http:/b/33681750), and every tx 464xlat packet which was counted onto
* clat uid should be ignored.
* *
* As for eBPF, the per uid stats is collected by different hook, the rx packets on base * 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 * interface will not be counted. Thus, the adjustment on root uid is not needed. However, the
* direction. * tx traffic counted in the same way xt_qtaguid does, so the traffic on clat uid still
* needs to be ignored.
* *
* <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}
@@ -862,17 +866,14 @@ public class NetworkStats implements Parcelable {
if (baseIface == null) { if (baseIface == null) {
continue; continue;
} }
// Subtract any 464lat traffic seen for the root UID on the current base interface. // Subtract xt_qtaguid 464lat rx traffic seen for the root UID on the current base
// However, for eBPF, the per uid stats is collected by different hook, the rx packets // interface. As for eBPF, the per uid stats is collected by different hook, the rx
// on base interface will not be counted. Thus, the adjustment on root uid is only // packets on base interface will not be counted.
// needed in tx direction.
adjust.iface = baseIface; adjust.iface = baseIface;
if (!useBpfStats) { if (!useBpfStats) {
adjust.rxBytes = -(entry.rxBytes + entry.rxPackets * IPV4V6_HEADER_DELTA); adjust.rxBytes = -(entry.rxBytes + entry.rxPackets * IPV4V6_HEADER_DELTA);
adjust.rxPackets = -entry.rxPackets; adjust.rxPackets = -entry.rxPackets;
} }
adjust.txBytes = -(entry.txBytes + entry.txPackets * IPV4V6_HEADER_DELTA);
adjust.txPackets = -entry.txPackets;
adjustments.combineValues(adjust); adjustments.combineValues(adjust);
// For 464xlat traffic, per uid stats only counts the bytes of the native IPv4 packet // For 464xlat traffic, per uid stats only counts the bytes of the native IPv4 packet
@@ -884,6 +885,9 @@ public class NetworkStats implements Parcelable {
stackedTraffic.setValues(i, entry); stackedTraffic.setValues(i, entry);
} }
// Traffic on clat uid is v6 tx traffic that is already counted with app uid on the stacked
// v4 interface, so it needs to be removed to avoid double-counting.
baseTraffic.removeUids(new int[] {CLAT_UID});
baseTraffic.combineAllValues(adjustments); baseTraffic.combineAllValues(adjustments);
} }