Merge "ClatCoordinator: replace BpfMap with IBpfMap"
This commit is contained in:
@@ -39,6 +39,7 @@ import com.android.internal.annotations.VisibleForTesting;
|
|||||||
import com.android.internal.util.IndentingPrintWriter;
|
import com.android.internal.util.IndentingPrintWriter;
|
||||||
import com.android.modules.utils.build.SdkLevel;
|
import com.android.modules.utils.build.SdkLevel;
|
||||||
import com.android.net.module.util.BpfMap;
|
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.InterfaceParams;
|
||||||
import com.android.net.module.util.TcUtils;
|
import com.android.net.module.util.TcUtils;
|
||||||
import com.android.net.module.util.bpf.ClatEgress4Key;
|
import com.android.net.module.util.bpf.ClatEgress4Key;
|
||||||
@@ -115,12 +116,12 @@ public class ClatCoordinator {
|
|||||||
private final INetd mNetd;
|
private final INetd mNetd;
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Dependencies mDeps;
|
private final Dependencies mDeps;
|
||||||
// BpfMap objects {mIngressMap, mEgressMap} are initialized in #maybeStartBpf and closed in
|
// IBpfMap objects {mIngressMap, mEgressMap} are initialized in #maybeStartBpf and closed in
|
||||||
// #maybeStopBpf.
|
// #maybeStopBpf.
|
||||||
@Nullable
|
@Nullable
|
||||||
private BpfMap<ClatIngress6Key, ClatIngress6Value> mIngressMap = null;
|
private IBpfMap<ClatIngress6Key, ClatIngress6Value> mIngressMap = null;
|
||||||
@Nullable
|
@Nullable
|
||||||
private BpfMap<ClatEgress4Key, ClatEgress4Value> mEgressMap = null;
|
private IBpfMap<ClatEgress4Key, ClatEgress4Value> mEgressMap = null;
|
||||||
@Nullable
|
@Nullable
|
||||||
private ClatdTracker mClatdTracker = null;
|
private ClatdTracker mClatdTracker = null;
|
||||||
|
|
||||||
@@ -248,7 +249,7 @@ public class ClatCoordinator {
|
|||||||
|
|
||||||
/** Get ingress6 BPF map. */
|
/** Get ingress6 BPF map. */
|
||||||
@Nullable
|
@Nullable
|
||||||
public BpfMap<ClatIngress6Key, ClatIngress6Value> getBpfIngress6Map() {
|
public IBpfMap<ClatIngress6Key, ClatIngress6Value> getBpfIngress6Map() {
|
||||||
// Pre-T devices don't use ClatCoordinator to access clat map. Since Nat464Xlat
|
// Pre-T devices don't use ClatCoordinator to access clat map. Since Nat464Xlat
|
||||||
// initializes a ClatCoordinator object to avoid redundant null pointer check
|
// initializes a ClatCoordinator object to avoid redundant null pointer check
|
||||||
// while using, ignore the BPF map initialization on pre-T devices.
|
// while using, ignore the BPF map initialization on pre-T devices.
|
||||||
@@ -265,7 +266,7 @@ public class ClatCoordinator {
|
|||||||
|
|
||||||
/** Get egress4 BPF map. */
|
/** Get egress4 BPF map. */
|
||||||
@Nullable
|
@Nullable
|
||||||
public BpfMap<ClatEgress4Key, ClatEgress4Value> getBpfEgress4Map() {
|
public IBpfMap<ClatEgress4Key, ClatEgress4Value> getBpfEgress4Map() {
|
||||||
// Pre-T devices don't use ClatCoordinator to access clat map. Since Nat464Xlat
|
// Pre-T devices don't use ClatCoordinator to access clat map. Since Nat464Xlat
|
||||||
// initializes a ClatCoordinator object to avoid redundant null pointer check
|
// initializes a ClatCoordinator object to avoid redundant null pointer check
|
||||||
// while using, ignore the BPF map initialization on pre-T devices.
|
// while using, ignore the BPF map initialization on pre-T devices.
|
||||||
@@ -379,7 +380,7 @@ public class ClatCoordinator {
|
|||||||
private void closeEgressMap() {
|
private void closeEgressMap() {
|
||||||
try {
|
try {
|
||||||
mEgressMap.close();
|
mEgressMap.close();
|
||||||
} catch (ErrnoException e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "Cannot close egress4 map: " + e);
|
Log.e(TAG, "Cannot close egress4 map: " + e);
|
||||||
}
|
}
|
||||||
mEgressMap = null;
|
mEgressMap = null;
|
||||||
@@ -388,7 +389,7 @@ public class ClatCoordinator {
|
|||||||
private void closeIngressMap() {
|
private void closeIngressMap() {
|
||||||
try {
|
try {
|
||||||
mIngressMap.close();
|
mIngressMap.close();
|
||||||
} catch (ErrnoException e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "Cannot close ingress6 map: " + e);
|
Log.e(TAG, "Cannot close ingress6 map: " + e);
|
||||||
}
|
}
|
||||||
mIngressMap = null;
|
mIngressMap = null;
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ import android.os.ParcelFileDescriptor;
|
|||||||
|
|
||||||
import androidx.test.filters.SmallTest;
|
import androidx.test.filters.SmallTest;
|
||||||
|
|
||||||
import com.android.net.module.util.BpfMap;
|
import com.android.net.module.util.IBpfMap;
|
||||||
import com.android.net.module.util.bpf.ClatEgress4Key;
|
import com.android.net.module.util.bpf.ClatEgress4Key;
|
||||||
import com.android.net.module.util.bpf.ClatEgress4Value;
|
import com.android.net.module.util.bpf.ClatEgress4Value;
|
||||||
import com.android.net.module.util.bpf.ClatIngress6Key;
|
import com.android.net.module.util.bpf.ClatIngress6Key;
|
||||||
@@ -123,8 +123,8 @@ public class ClatCoordinatorTest {
|
|||||||
|
|
||||||
@Mock private INetd mNetd;
|
@Mock private INetd mNetd;
|
||||||
@Spy private TestDependencies mDeps = new TestDependencies();
|
@Spy private TestDependencies mDeps = new TestDependencies();
|
||||||
@Mock private BpfMap<ClatIngress6Key, ClatIngress6Value> mIngressMap;
|
@Mock private IBpfMap<ClatIngress6Key, ClatIngress6Value> mIngressMap;
|
||||||
@Mock private BpfMap<ClatEgress4Key, ClatEgress4Value> mEgressMap;
|
@Mock private IBpfMap<ClatEgress4Key, ClatEgress4Value> mEgressMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The dependency injection class is used to mock the JNI functions and system functions
|
* 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. */
|
/** Get ingress6 BPF map. */
|
||||||
@Override
|
@Override
|
||||||
public BpfMap<ClatIngress6Key, ClatIngress6Value> getBpfIngress6Map() {
|
public IBpfMap<ClatIngress6Key, ClatIngress6Value> getBpfIngress6Map() {
|
||||||
return mIngressMap;
|
return mIngressMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get egress4 BPF map. */
|
/** Get egress4 BPF map. */
|
||||||
@Override
|
@Override
|
||||||
public BpfMap<ClatEgress4Key, ClatEgress4Value> getBpfEgress4Map() {
|
public IBpfMap<ClatEgress4Key, ClatEgress4Value> getBpfEgress4Map() {
|
||||||
return mEgressMap;
|
return mEgressMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user