From bdf970240e6a6ae02670cbaaec68bfa43e45ae6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Thu, 22 Dec 2022 00:15:26 +0000 Subject: [PATCH] switch DscpPolicyTracker from U32 to S32 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Change-Id: Iac3ddd3fc726b1643b1aad42e40f97ea12cebf29 --- .../connectivity/DscpPolicyTracker.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/service/src/com/android/server/connectivity/DscpPolicyTracker.java b/service/src/com/android/server/connectivity/DscpPolicyTracker.java index 2bfad10b1e..8d566b6f07 100644 --- a/service/src/com/android/server/connectivity/DscpPolicyTracker.java +++ b/service/src/com/android/server/connectivity/DscpPolicyTracker.java @@ -66,8 +66,8 @@ public class DscpPolicyTracker { private Set mAttachedIfaces; - private final BpfMap mBpfDscpIpv4Policies; - private final BpfMap mBpfDscpIpv6Policies; + private final BpfMap mBpfDscpIpv4Policies; + private final BpfMap 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 class DscpPolicyTracker { public DscpPolicyTracker() throws ErrnoException { mAttachedIfaces = new HashSet(); mIfaceIndexToPolicyIdBpfMapIndex = new HashMap(); - mBpfDscpIpv4Policies = new BpfMap(IPV4_POLICY_MAP_PATH, - BpfMap.BPF_F_RDWR, Struct.U32.class, DscpPolicyValue.class); - mBpfDscpIpv6Policies = new BpfMap(IPV6_POLICY_MAP_PATH, - BpfMap.BPF_F_RDWR, Struct.U32.class, DscpPolicyValue.class); + mBpfDscpIpv4Policies = new BpfMap(IPV4_POLICY_MAP_PATH, + BpfMap.BPF_F_RDWR, Struct.S32.class, DscpPolicyValue.class); + mBpfDscpIpv6Policies = new BpfMap(IPV6_POLICY_MAP_PATH, + BpfMap.BPF_F_RDWR, Struct.S32.class, DscpPolicyValue.class); } private boolean isUnusedIndex(int index) { @@ -181,7 +181,7 @@ public class DscpPolicyTracker { // 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 @@ public class DscpPolicyTracker { // 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 @@ public class DscpPolicyTracker { 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);