From 9416307fa10ea759202087cc1d1408263a01077f Mon Sep 17 00:00:00 2001 From: Hungming Chen Date: Mon, 9 May 2022 15:45:31 +0800 Subject: [PATCH] Revert "ClatCoordinator: replace BpfMap with IBpfMap" Test: build This reverts commit 12c625bbf85564310f81afb14314adf898307876. Change-Id: I100dc77a8e29ac21ca649d6487563021e8cf0f80 --- .../server/connectivity/ClatCoordinator.java | 15 +++++++-------- .../server/connectivity/ClatCoordinatorTest.java | 10 +++++----- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/service/src/com/android/server/connectivity/ClatCoordinator.java b/service/src/com/android/server/connectivity/ClatCoordinator.java index 3b0b3fd605..33494d44a3 100644 --- a/service/src/com/android/server/connectivity/ClatCoordinator.java +++ b/service/src/com/android/server/connectivity/ClatCoordinator.java @@ -39,7 +39,6 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.IndentingPrintWriter; import com.android.modules.utils.build.SdkLevel; import com.android.net.module.util.BpfMap; -import com.android.net.module.util.IBpfMap; import com.android.net.module.util.InterfaceParams; import com.android.net.module.util.TcUtils; import com.android.net.module.util.bpf.ClatEgress4Key; @@ -116,12 +115,12 @@ public class ClatCoordinator { private final INetd mNetd; @NonNull private final Dependencies mDeps; - // IBpfMap objects {mIngressMap, mEgressMap} are initialized in #maybeStartBpf and closed in + // BpfMap objects {mIngressMap, mEgressMap} are initialized in #maybeStartBpf and closed in // #maybeStopBpf. @Nullable - private IBpfMap mIngressMap = null; + private BpfMap mIngressMap = null; @Nullable - private IBpfMap mEgressMap = null; + private BpfMap mEgressMap = null; @Nullable private ClatdTracker mClatdTracker = null; @@ -249,7 +248,7 @@ public class ClatCoordinator { /** Get ingress6 BPF map. */ @Nullable - public IBpfMap getBpfIngress6Map() { + public BpfMap getBpfIngress6Map() { // Pre-T devices don't use ClatCoordinator to access clat map. Since Nat464Xlat // initializes a ClatCoordinator object to avoid redundant null pointer check // while using, ignore the BPF map initialization on pre-T devices. @@ -266,7 +265,7 @@ public class ClatCoordinator { /** Get egress4 BPF map. */ @Nullable - public IBpfMap getBpfEgress4Map() { + public BpfMap getBpfEgress4Map() { // Pre-T devices don't use ClatCoordinator to access clat map. Since Nat464Xlat // initializes a ClatCoordinator object to avoid redundant null pointer check // while using, ignore the BPF map initialization on pre-T devices. @@ -380,7 +379,7 @@ public class ClatCoordinator { private void closeEgressMap() { try { mEgressMap.close(); - } catch (Exception e) { + } catch (ErrnoException e) { Log.e(TAG, "Cannot close egress4 map: " + e); } mEgressMap = null; @@ -389,7 +388,7 @@ public class ClatCoordinator { private void closeIngressMap() { try { mIngressMap.close(); - } catch (Exception e) { + } catch (ErrnoException e) { Log.e(TAG, "Cannot close ingress6 map: " + e); } mIngressMap = null; diff --git a/tests/unit/java/com/android/server/connectivity/ClatCoordinatorTest.java b/tests/unit/java/com/android/server/connectivity/ClatCoordinatorTest.java index a1eeaf4ed5..de5698fc4b 100644 --- a/tests/unit/java/com/android/server/connectivity/ClatCoordinatorTest.java +++ b/tests/unit/java/com/android/server/connectivity/ClatCoordinatorTest.java @@ -46,7 +46,7 @@ import android.os.ParcelFileDescriptor; import androidx.test.filters.SmallTest; -import com.android.net.module.util.IBpfMap; +import com.android.net.module.util.BpfMap; import com.android.net.module.util.bpf.ClatEgress4Key; import com.android.net.module.util.bpf.ClatEgress4Value; import com.android.net.module.util.bpf.ClatIngress6Key; @@ -123,8 +123,8 @@ public class ClatCoordinatorTest { @Mock private INetd mNetd; @Spy private TestDependencies mDeps = new TestDependencies(); - @Mock private IBpfMap mIngressMap; - @Mock private IBpfMap mEgressMap; + @Mock private BpfMap mIngressMap; + @Mock private BpfMap mEgressMap; /** * The dependency injection class is used to mock the JNI functions and system functions @@ -326,13 +326,13 @@ public class ClatCoordinatorTest { /** Get ingress6 BPF map. */ @Override - public IBpfMap getBpfIngress6Map() { + public BpfMap getBpfIngress6Map() { return mIngressMap; } /** Get egress4 BPF map. */ @Override - public IBpfMap getBpfEgress4Map() { + public BpfMap getBpfEgress4Map() { return mEgressMap; }