switch DscpPolicyTracker from U32 to S32
In practice these are tiny indexes into a small array, see:
packages/modules/Connectivity/bpf_progs/dscpPolicy.h
#define MAX_POLICIES 16
So there is no need to complicate things...
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iac3ddd3fc726b1643b1aad42e40f97ea12cebf29
(cherry picked from commit bdf970240e6a6ae02670cbaaec68bfa43e45ae6d)
Merged-In: Iac3ddd3fc726b1643b1aad42e40f97ea12cebf29
diff --git a/service/src/com/android/server/connectivity/DscpPolicyTracker.java b/service/src/com/android/server/connectivity/DscpPolicyTracker.java
index 2bfad10..8d566b6 100644
--- a/service/src/com/android/server/connectivity/DscpPolicyTracker.java
+++ b/service/src/com/android/server/connectivity/DscpPolicyTracker.java
@@ -66,8 +66,8 @@
private Set<String> mAttachedIfaces;
- private final BpfMap<Struct.U32, DscpPolicyValue> mBpfDscpIpv4Policies;
- private final BpfMap<Struct.U32, DscpPolicyValue> mBpfDscpIpv6Policies;
+ private final BpfMap<Struct.S32, DscpPolicyValue> mBpfDscpIpv4Policies;
+ private final BpfMap<Struct.S32, DscpPolicyValue> mBpfDscpIpv6Policies;
// The actual policy rules used by the BPF code to process packets
// are in mBpfDscpIpv4Policies and mBpfDscpIpv4Policies. Both of
@@ -85,10 +85,10 @@
public DscpPolicyTracker() throws ErrnoException {
mAttachedIfaces = new HashSet<String>();
mIfaceIndexToPolicyIdBpfMapIndex = new HashMap<Integer, SparseIntArray>();
- mBpfDscpIpv4Policies = new BpfMap<Struct.U32, DscpPolicyValue>(IPV4_POLICY_MAP_PATH,
- BpfMap.BPF_F_RDWR, Struct.U32.class, DscpPolicyValue.class);
- mBpfDscpIpv6Policies = new BpfMap<Struct.U32, DscpPolicyValue>(IPV6_POLICY_MAP_PATH,
- BpfMap.BPF_F_RDWR, Struct.U32.class, DscpPolicyValue.class);
+ mBpfDscpIpv4Policies = new BpfMap<Struct.S32, DscpPolicyValue>(IPV4_POLICY_MAP_PATH,
+ BpfMap.BPF_F_RDWR, Struct.S32.class, DscpPolicyValue.class);
+ mBpfDscpIpv6Policies = new BpfMap<Struct.S32, DscpPolicyValue>(IPV6_POLICY_MAP_PATH,
+ BpfMap.BPF_F_RDWR, Struct.S32.class, DscpPolicyValue.class);
}
private boolean isUnusedIndex(int index) {
@@ -181,7 +181,7 @@
// are both null or if they are both instances of Inet4Address.
if (matchesIpv4(policy)) {
mBpfDscpIpv4Policies.insertOrReplaceEntry(
- new Struct.U32(addIndex),
+ new Struct.S32(addIndex),
new DscpPolicyValue(policy.getSourceAddress(),
policy.getDestinationAddress(), ifIndex,
policy.getSourcePort(), policy.getDestinationPortRange(),
@@ -192,7 +192,7 @@
// are both null or if they are both instances of Inet6Address.
if (matchesIpv6(policy)) {
mBpfDscpIpv6Policies.insertOrReplaceEntry(
- new Struct.U32(addIndex),
+ new Struct.S32(addIndex),
new DscpPolicyValue(policy.getSourceAddress(),
policy.getDestinationAddress(), ifIndex,
policy.getSourcePort(), policy.getDestinationPortRange(),
@@ -258,8 +258,8 @@
boolean sendCallback) {
int status = DSCP_POLICY_STATUS_POLICY_NOT_FOUND;
try {
- mBpfDscpIpv4Policies.replaceEntry(new Struct.U32(index), DscpPolicyValue.NONE);
- mBpfDscpIpv6Policies.replaceEntry(new Struct.U32(index), DscpPolicyValue.NONE);
+ mBpfDscpIpv4Policies.replaceEntry(new Struct.S32(index), DscpPolicyValue.NONE);
+ mBpfDscpIpv6Policies.replaceEntry(new Struct.S32(index), DscpPolicyValue.NONE);
status = DSCP_POLICY_STATUS_DELETED;
} catch (ErrnoException e) {
Log.e(TAG, "Failed to delete policy from map: ", e);