Merge "Use IBpfMap type instead of BpfMap type"
This commit is contained in:
@@ -28,7 +28,7 @@ import android.util.SparseArray;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.android.net.module.util.BpfMap;
|
import com.android.net.module.util.IBpfMap;
|
||||||
import com.android.net.module.util.IBpfMap.ThrowingBiConsumer;
|
import com.android.net.module.util.IBpfMap.ThrowingBiConsumer;
|
||||||
import com.android.net.module.util.SharedLog;
|
import com.android.net.module.util.SharedLog;
|
||||||
import com.android.net.module.util.bpf.Tether4Key;
|
import com.android.net.module.util.bpf.Tether4Key;
|
||||||
@@ -66,31 +66,31 @@ public class BpfCoordinatorShimImpl
|
|||||||
|
|
||||||
// BPF map for downstream IPv4 forwarding.
|
// BPF map for downstream IPv4 forwarding.
|
||||||
@Nullable
|
@Nullable
|
||||||
private final BpfMap<Tether4Key, Tether4Value> mBpfDownstream4Map;
|
private final IBpfMap<Tether4Key, Tether4Value> mBpfDownstream4Map;
|
||||||
|
|
||||||
// BPF map for upstream IPv4 forwarding.
|
// BPF map for upstream IPv4 forwarding.
|
||||||
@Nullable
|
@Nullable
|
||||||
private final BpfMap<Tether4Key, Tether4Value> mBpfUpstream4Map;
|
private final IBpfMap<Tether4Key, Tether4Value> mBpfUpstream4Map;
|
||||||
|
|
||||||
// BPF map for downstream IPv6 forwarding.
|
// BPF map for downstream IPv6 forwarding.
|
||||||
@Nullable
|
@Nullable
|
||||||
private final BpfMap<TetherDownstream6Key, Tether6Value> mBpfDownstream6Map;
|
private final IBpfMap<TetherDownstream6Key, Tether6Value> mBpfDownstream6Map;
|
||||||
|
|
||||||
// BPF map for upstream IPv6 forwarding.
|
// BPF map for upstream IPv6 forwarding.
|
||||||
@Nullable
|
@Nullable
|
||||||
private final BpfMap<TetherUpstream6Key, Tether6Value> mBpfUpstream6Map;
|
private final IBpfMap<TetherUpstream6Key, Tether6Value> mBpfUpstream6Map;
|
||||||
|
|
||||||
// BPF map of tethering statistics of the upstream interface since tethering startup.
|
// BPF map of tethering statistics of the upstream interface since tethering startup.
|
||||||
@Nullable
|
@Nullable
|
||||||
private final BpfMap<TetherStatsKey, TetherStatsValue> mBpfStatsMap;
|
private final IBpfMap<TetherStatsKey, TetherStatsValue> mBpfStatsMap;
|
||||||
|
|
||||||
// BPF map of per-interface quota for tethering offload.
|
// BPF map of per-interface quota for tethering offload.
|
||||||
@Nullable
|
@Nullable
|
||||||
private final BpfMap<TetherLimitKey, TetherLimitValue> mBpfLimitMap;
|
private final IBpfMap<TetherLimitKey, TetherLimitValue> mBpfLimitMap;
|
||||||
|
|
||||||
// BPF map of interface index mapping for XDP.
|
// BPF map of interface index mapping for XDP.
|
||||||
@Nullable
|
@Nullable
|
||||||
private final BpfMap<TetherDevKey, TetherDevValue> mBpfDevMap;
|
private final IBpfMap<TetherDevKey, TetherDevValue> mBpfDevMap;
|
||||||
|
|
||||||
// Tracking IPv4 rule count while any rule is using the given upstream interfaces. Used for
|
// Tracking IPv4 rule count while any rule is using the given upstream interfaces. Used for
|
||||||
// reducing the BPF map iteration query. The count is increased or decreased when the rule is
|
// reducing the BPF map iteration query. The count is increased or decreased when the rule is
|
||||||
@@ -482,7 +482,7 @@ public class BpfCoordinatorShimImpl
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String mapStatus(BpfMap m, String name) {
|
private String mapStatus(IBpfMap m, String name) {
|
||||||
return name + "{" + (m != null ? "OK" : "ERROR") + "}";
|
return name + "{" + (m != null ? "OK" : "ERROR") + "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ import com.android.modules.utils.build.SdkLevel;
|
|||||||
import com.android.net.module.util.BpfDump;
|
import com.android.net.module.util.BpfDump;
|
||||||
import com.android.net.module.util.BpfMap;
|
import com.android.net.module.util.BpfMap;
|
||||||
import com.android.net.module.util.CollectionUtils;
|
import com.android.net.module.util.CollectionUtils;
|
||||||
|
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.NetworkStackConstants;
|
import com.android.net.module.util.NetworkStackConstants;
|
||||||
import com.android.net.module.util.SharedLog;
|
import com.android.net.module.util.SharedLog;
|
||||||
@@ -320,7 +321,7 @@ public class BpfCoordinator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Get downstream4 BPF map. */
|
/** Get downstream4 BPF map. */
|
||||||
@Nullable public BpfMap<Tether4Key, Tether4Value> getBpfDownstream4Map() {
|
@Nullable public IBpfMap<Tether4Key, Tether4Value> getBpfDownstream4Map() {
|
||||||
if (!isAtLeastS()) return null;
|
if (!isAtLeastS()) return null;
|
||||||
try {
|
try {
|
||||||
return new BpfMap<>(TETHER_DOWNSTREAM4_MAP_PATH,
|
return new BpfMap<>(TETHER_DOWNSTREAM4_MAP_PATH,
|
||||||
@@ -332,7 +333,7 @@ public class BpfCoordinator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Get upstream4 BPF map. */
|
/** Get upstream4 BPF map. */
|
||||||
@Nullable public BpfMap<Tether4Key, Tether4Value> getBpfUpstream4Map() {
|
@Nullable public IBpfMap<Tether4Key, Tether4Value> getBpfUpstream4Map() {
|
||||||
if (!isAtLeastS()) return null;
|
if (!isAtLeastS()) return null;
|
||||||
try {
|
try {
|
||||||
return new BpfMap<>(TETHER_UPSTREAM4_MAP_PATH,
|
return new BpfMap<>(TETHER_UPSTREAM4_MAP_PATH,
|
||||||
@@ -344,7 +345,7 @@ public class BpfCoordinator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Get downstream6 BPF map. */
|
/** Get downstream6 BPF map. */
|
||||||
@Nullable public BpfMap<TetherDownstream6Key, Tether6Value> getBpfDownstream6Map() {
|
@Nullable public IBpfMap<TetherDownstream6Key, Tether6Value> getBpfDownstream6Map() {
|
||||||
if (!isAtLeastS()) return null;
|
if (!isAtLeastS()) return null;
|
||||||
try {
|
try {
|
||||||
return new BpfMap<>(TETHER_DOWNSTREAM6_FS_PATH,
|
return new BpfMap<>(TETHER_DOWNSTREAM6_FS_PATH,
|
||||||
@@ -356,7 +357,7 @@ public class BpfCoordinator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Get upstream6 BPF map. */
|
/** Get upstream6 BPF map. */
|
||||||
@Nullable public BpfMap<TetherUpstream6Key, Tether6Value> getBpfUpstream6Map() {
|
@Nullable public IBpfMap<TetherUpstream6Key, Tether6Value> getBpfUpstream6Map() {
|
||||||
if (!isAtLeastS()) return null;
|
if (!isAtLeastS()) return null;
|
||||||
try {
|
try {
|
||||||
return new BpfMap<>(TETHER_UPSTREAM6_FS_PATH, BpfMap.BPF_F_RDWR,
|
return new BpfMap<>(TETHER_UPSTREAM6_FS_PATH, BpfMap.BPF_F_RDWR,
|
||||||
@@ -368,7 +369,7 @@ public class BpfCoordinator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Get stats BPF map. */
|
/** Get stats BPF map. */
|
||||||
@Nullable public BpfMap<TetherStatsKey, TetherStatsValue> getBpfStatsMap() {
|
@Nullable public IBpfMap<TetherStatsKey, TetherStatsValue> getBpfStatsMap() {
|
||||||
if (!isAtLeastS()) return null;
|
if (!isAtLeastS()) return null;
|
||||||
try {
|
try {
|
||||||
return new BpfMap<>(TETHER_STATS_MAP_PATH,
|
return new BpfMap<>(TETHER_STATS_MAP_PATH,
|
||||||
@@ -380,7 +381,7 @@ public class BpfCoordinator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Get limit BPF map. */
|
/** Get limit BPF map. */
|
||||||
@Nullable public BpfMap<TetherLimitKey, TetherLimitValue> getBpfLimitMap() {
|
@Nullable public IBpfMap<TetherLimitKey, TetherLimitValue> getBpfLimitMap() {
|
||||||
if (!isAtLeastS()) return null;
|
if (!isAtLeastS()) return null;
|
||||||
try {
|
try {
|
||||||
return new BpfMap<>(TETHER_LIMIT_MAP_PATH,
|
return new BpfMap<>(TETHER_LIMIT_MAP_PATH,
|
||||||
@@ -392,7 +393,7 @@ public class BpfCoordinator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Get dev BPF map. */
|
/** Get dev BPF map. */
|
||||||
@Nullable public BpfMap<TetherDevKey, TetherDevValue> getBpfDevMap() {
|
@Nullable public IBpfMap<TetherDevKey, TetherDevValue> getBpfDevMap() {
|
||||||
if (!isAtLeastS()) return null;
|
if (!isAtLeastS()) return null;
|
||||||
try {
|
try {
|
||||||
return new BpfMap<>(TETHER_DEV_MAP_PATH,
|
return new BpfMap<>(TETHER_DEV_MAP_PATH,
|
||||||
@@ -1047,7 +1048,7 @@ public class BpfCoordinator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void dumpBpfStats(@NonNull IndentingPrintWriter pw) {
|
private void dumpBpfStats(@NonNull IndentingPrintWriter pw) {
|
||||||
try (BpfMap<TetherStatsKey, TetherStatsValue> map = mDeps.getBpfStatsMap()) {
|
try (IBpfMap<TetherStatsKey, TetherStatsValue> map = mDeps.getBpfStatsMap()) {
|
||||||
if (map == null) {
|
if (map == null) {
|
||||||
pw.println("No BPF stats map");
|
pw.println("No BPF stats map");
|
||||||
return;
|
return;
|
||||||
@@ -1102,7 +1103,7 @@ public class BpfCoordinator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void dumpIpv6UpstreamRules(IndentingPrintWriter pw) {
|
private void dumpIpv6UpstreamRules(IndentingPrintWriter pw) {
|
||||||
try (BpfMap<TetherUpstream6Key, Tether6Value> map = mDeps.getBpfUpstream6Map()) {
|
try (IBpfMap<TetherUpstream6Key, Tether6Value> map = mDeps.getBpfUpstream6Map()) {
|
||||||
if (map == null) {
|
if (map == null) {
|
||||||
pw.println("No IPv6 upstream");
|
pw.println("No IPv6 upstream");
|
||||||
return;
|
return;
|
||||||
@@ -1130,7 +1131,7 @@ public class BpfCoordinator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void dumpIpv6DownstreamRules(IndentingPrintWriter pw) {
|
private void dumpIpv6DownstreamRules(IndentingPrintWriter pw) {
|
||||||
try (BpfMap<TetherDownstream6Key, Tether6Value> map = mDeps.getBpfDownstream6Map()) {
|
try (IBpfMap<TetherDownstream6Key, Tether6Value> map = mDeps.getBpfDownstream6Map()) {
|
||||||
if (map == null) {
|
if (map == null) {
|
||||||
pw.println("No IPv6 downstream");
|
pw.println("No IPv6 downstream");
|
||||||
return;
|
return;
|
||||||
@@ -1161,7 +1162,7 @@ public class BpfCoordinator {
|
|||||||
pw.decreaseIndent();
|
pw.decreaseIndent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private <K extends Struct, V extends Struct> void dumpRawMap(BpfMap<K, V> map,
|
private <K extends Struct, V extends Struct> void dumpRawMap(IBpfMap<K, V> map,
|
||||||
IndentingPrintWriter pw) throws ErrnoException {
|
IndentingPrintWriter pw) throws ErrnoException {
|
||||||
if (map == null) {
|
if (map == null) {
|
||||||
pw.println("No BPF support");
|
pw.println("No BPF support");
|
||||||
@@ -1192,7 +1193,7 @@ public class BpfCoordinator {
|
|||||||
// expected argument order.
|
// expected argument order.
|
||||||
// TODO: dump downstream4 map.
|
// TODO: dump downstream4 map.
|
||||||
if (CollectionUtils.contains(args, DUMPSYS_RAWMAP_ARG_STATS)) {
|
if (CollectionUtils.contains(args, DUMPSYS_RAWMAP_ARG_STATS)) {
|
||||||
try (BpfMap<TetherStatsKey, TetherStatsValue> statsMap = mDeps.getBpfStatsMap()) {
|
try (IBpfMap<TetherStatsKey, TetherStatsValue> statsMap = mDeps.getBpfStatsMap()) {
|
||||||
dumpRawMap(statsMap, pw);
|
dumpRawMap(statsMap, pw);
|
||||||
} catch (ErrnoException | IOException e) {
|
} catch (ErrnoException | IOException e) {
|
||||||
pw.println("Error dumping stats map: " + e);
|
pw.println("Error dumping stats map: " + e);
|
||||||
@@ -1200,7 +1201,7 @@ public class BpfCoordinator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (CollectionUtils.contains(args, DUMPSYS_RAWMAP_ARG_UPSTREAM4)) {
|
if (CollectionUtils.contains(args, DUMPSYS_RAWMAP_ARG_UPSTREAM4)) {
|
||||||
try (BpfMap<Tether4Key, Tether4Value> upstreamMap = mDeps.getBpfUpstream4Map()) {
|
try (IBpfMap<Tether4Key, Tether4Value> upstreamMap = mDeps.getBpfUpstream4Map()) {
|
||||||
dumpRawMap(upstreamMap, pw);
|
dumpRawMap(upstreamMap, pw);
|
||||||
} catch (ErrnoException | IOException e) {
|
} catch (ErrnoException | IOException e) {
|
||||||
pw.println("Error dumping IPv4 map: " + e);
|
pw.println("Error dumping IPv4 map: " + e);
|
||||||
@@ -1245,7 +1246,7 @@ public class BpfCoordinator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void dumpIpv4ForwardingRuleMap(long now, boolean downstream,
|
private void dumpIpv4ForwardingRuleMap(long now, boolean downstream,
|
||||||
BpfMap<Tether4Key, Tether4Value> map, IndentingPrintWriter pw) throws ErrnoException {
|
IBpfMap<Tether4Key, Tether4Value> map, IndentingPrintWriter pw) throws ErrnoException {
|
||||||
if (map == null) {
|
if (map == null) {
|
||||||
pw.println("No IPv4 support");
|
pw.println("No IPv4 support");
|
||||||
return;
|
return;
|
||||||
@@ -1260,8 +1261,8 @@ public class BpfCoordinator {
|
|||||||
private void dumpBpfForwardingRulesIpv4(IndentingPrintWriter pw) {
|
private void dumpBpfForwardingRulesIpv4(IndentingPrintWriter pw) {
|
||||||
final long now = SystemClock.elapsedRealtimeNanos();
|
final long now = SystemClock.elapsedRealtimeNanos();
|
||||||
|
|
||||||
try (BpfMap<Tether4Key, Tether4Value> upstreamMap = mDeps.getBpfUpstream4Map();
|
try (IBpfMap<Tether4Key, Tether4Value> upstreamMap = mDeps.getBpfUpstream4Map();
|
||||||
BpfMap<Tether4Key, Tether4Value> downstreamMap = mDeps.getBpfDownstream4Map()) {
|
IBpfMap<Tether4Key, Tether4Value> downstreamMap = mDeps.getBpfDownstream4Map()) {
|
||||||
pw.println("IPv4 Upstream: proto [inDstMac] iif(iface) src -> nat -> "
|
pw.println("IPv4 Upstream: proto [inDstMac] iif(iface) src -> nat -> "
|
||||||
+ "dst [outDstMac] age");
|
+ "dst [outDstMac] age");
|
||||||
pw.increaseIndent();
|
pw.increaseIndent();
|
||||||
@@ -1283,7 +1284,7 @@ public class BpfCoordinator {
|
|||||||
pw.println("No counter support");
|
pw.println("No counter support");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try (BpfMap<S32, S32> map = new BpfMap<>(TETHER_ERROR_MAP_PATH, BpfMap.BPF_F_RDONLY,
|
try (IBpfMap<S32, S32> map = new BpfMap<>(TETHER_ERROR_MAP_PATH, BpfMap.BPF_F_RDONLY,
|
||||||
S32.class, S32.class)) {
|
S32.class, S32.class)) {
|
||||||
|
|
||||||
map.forEach((k, v) -> {
|
map.forEach((k, v) -> {
|
||||||
@@ -1304,7 +1305,7 @@ public class BpfCoordinator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void dumpDevmap(@NonNull IndentingPrintWriter pw) {
|
private void dumpDevmap(@NonNull IndentingPrintWriter pw) {
|
||||||
try (BpfMap<TetherDevKey, TetherDevValue> map = mDeps.getBpfDevMap()) {
|
try (IBpfMap<TetherDevKey, TetherDevValue> map = mDeps.getBpfDevMap()) {
|
||||||
if (map == null) {
|
if (map == null) {
|
||||||
pw.println("No devmap support");
|
pw.println("No devmap support");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -94,8 +94,8 @@ import androidx.test.filters.SmallTest;
|
|||||||
import androidx.test.runner.AndroidJUnit4;
|
import androidx.test.runner.AndroidJUnit4;
|
||||||
|
|
||||||
import com.android.dx.mockito.inline.extended.ExtendedMockito;
|
import com.android.dx.mockito.inline.extended.ExtendedMockito;
|
||||||
import com.android.net.module.util.BpfMap;
|
|
||||||
import com.android.net.module.util.CollectionUtils;
|
import com.android.net.module.util.CollectionUtils;
|
||||||
|
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.NetworkStackConstants;
|
import com.android.net.module.util.NetworkStackConstants;
|
||||||
import com.android.net.module.util.SharedLog;
|
import com.android.net.module.util.SharedLog;
|
||||||
@@ -362,9 +362,9 @@ public class BpfCoordinatorTest {
|
|||||||
@Mock private IpServer mIpServer2;
|
@Mock private IpServer mIpServer2;
|
||||||
@Mock private TetheringConfiguration mTetherConfig;
|
@Mock private TetheringConfiguration mTetherConfig;
|
||||||
@Mock private ConntrackMonitor mConntrackMonitor;
|
@Mock private ConntrackMonitor mConntrackMonitor;
|
||||||
@Mock private BpfMap<TetherDownstream6Key, Tether6Value> mBpfDownstream6Map;
|
@Mock private IBpfMap<TetherDownstream6Key, Tether6Value> mBpfDownstream6Map;
|
||||||
@Mock private BpfMap<TetherUpstream6Key, Tether6Value> mBpfUpstream6Map;
|
@Mock private IBpfMap<TetherUpstream6Key, Tether6Value> mBpfUpstream6Map;
|
||||||
@Mock private BpfMap<TetherDevKey, TetherDevValue> mBpfDevMap;
|
@Mock private IBpfMap<TetherDevKey, TetherDevValue> mBpfDevMap;
|
||||||
|
|
||||||
// Late init since methods must be called by the thread that created this object.
|
// Late init since methods must be called by the thread that created this object.
|
||||||
private TestableNetworkStatsProviderCbBinder mTetherStatsProviderCb;
|
private TestableNetworkStatsProviderCbBinder mTetherStatsProviderCb;
|
||||||
@@ -379,13 +379,13 @@ public class BpfCoordinatorTest {
|
|||||||
private final ArgumentCaptor<ArrayList> mStringArrayCaptor =
|
private final ArgumentCaptor<ArrayList> mStringArrayCaptor =
|
||||||
ArgumentCaptor.forClass(ArrayList.class);
|
ArgumentCaptor.forClass(ArrayList.class);
|
||||||
private final TestLooper mTestLooper = new TestLooper();
|
private final TestLooper mTestLooper = new TestLooper();
|
||||||
private final BpfMap<Tether4Key, Tether4Value> mBpfDownstream4Map =
|
private final IBpfMap<Tether4Key, Tether4Value> mBpfDownstream4Map =
|
||||||
spy(new TestBpfMap<>(Tether4Key.class, Tether4Value.class));
|
spy(new TestBpfMap<>(Tether4Key.class, Tether4Value.class));
|
||||||
private final BpfMap<Tether4Key, Tether4Value> mBpfUpstream4Map =
|
private final IBpfMap<Tether4Key, Tether4Value> mBpfUpstream4Map =
|
||||||
spy(new TestBpfMap<>(Tether4Key.class, Tether4Value.class));
|
spy(new TestBpfMap<>(Tether4Key.class, Tether4Value.class));
|
||||||
private final TestBpfMap<TetherStatsKey, TetherStatsValue> mBpfStatsMap =
|
private final IBpfMap<TetherStatsKey, TetherStatsValue> mBpfStatsMap =
|
||||||
spy(new TestBpfMap<>(TetherStatsKey.class, TetherStatsValue.class));
|
spy(new TestBpfMap<>(TetherStatsKey.class, TetherStatsValue.class));
|
||||||
private final TestBpfMap<TetherLimitKey, TetherLimitValue> mBpfLimitMap =
|
private final IBpfMap<TetherLimitKey, TetherLimitValue> mBpfLimitMap =
|
||||||
spy(new TestBpfMap<>(TetherLimitKey.class, TetherLimitValue.class));
|
spy(new TestBpfMap<>(TetherLimitKey.class, TetherLimitValue.class));
|
||||||
private BpfCoordinator.Dependencies mDeps =
|
private BpfCoordinator.Dependencies mDeps =
|
||||||
spy(new BpfCoordinator.Dependencies() {
|
spy(new BpfCoordinator.Dependencies() {
|
||||||
@@ -424,37 +424,37 @@ public class BpfCoordinatorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public BpfMap<Tether4Key, Tether4Value> getBpfDownstream4Map() {
|
public IBpfMap<Tether4Key, Tether4Value> getBpfDownstream4Map() {
|
||||||
return mBpfDownstream4Map;
|
return mBpfDownstream4Map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public BpfMap<Tether4Key, Tether4Value> getBpfUpstream4Map() {
|
public IBpfMap<Tether4Key, Tether4Value> getBpfUpstream4Map() {
|
||||||
return mBpfUpstream4Map;
|
return mBpfUpstream4Map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public BpfMap<TetherDownstream6Key, Tether6Value> getBpfDownstream6Map() {
|
public IBpfMap<TetherDownstream6Key, Tether6Value> getBpfDownstream6Map() {
|
||||||
return mBpfDownstream6Map;
|
return mBpfDownstream6Map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public BpfMap<TetherUpstream6Key, Tether6Value> getBpfUpstream6Map() {
|
public IBpfMap<TetherUpstream6Key, Tether6Value> getBpfUpstream6Map() {
|
||||||
return mBpfUpstream6Map;
|
return mBpfUpstream6Map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public BpfMap<TetherStatsKey, TetherStatsValue> getBpfStatsMap() {
|
public IBpfMap<TetherStatsKey, TetherStatsValue> getBpfStatsMap() {
|
||||||
return mBpfStatsMap;
|
return mBpfStatsMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public BpfMap<TetherLimitKey, TetherLimitValue> getBpfLimitMap() {
|
public IBpfMap<TetherLimitKey, TetherLimitValue> getBpfLimitMap() {
|
||||||
return mBpfLimitMap;
|
return mBpfLimitMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public BpfMap<TetherDevKey, TetherDevValue> getBpfDevMap() {
|
public IBpfMap<TetherDevKey, TetherDevValue> getBpfDevMap() {
|
||||||
return mBpfDevMap;
|
return mBpfDevMap;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ import com.android.internal.annotations.VisibleForTesting;
|
|||||||
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.DeviceConfigUtils;
|
import com.android.net.module.util.DeviceConfigUtils;
|
||||||
|
import com.android.net.module.util.IBpfMap;
|
||||||
import com.android.net.module.util.Struct.U32;
|
import com.android.net.module.util.Struct.U32;
|
||||||
import com.android.net.module.util.Struct.U8;
|
import com.android.net.module.util.Struct.U8;
|
||||||
|
|
||||||
@@ -99,10 +100,10 @@ public class BpfNetMaps {
|
|||||||
private static final long STATS_SELECT_MAP_A = 0;
|
private static final long STATS_SELECT_MAP_A = 0;
|
||||||
private static final long STATS_SELECT_MAP_B = 1;
|
private static final long STATS_SELECT_MAP_B = 1;
|
||||||
|
|
||||||
private static BpfMap<U32, U32> sConfigurationMap = null;
|
private static IBpfMap<U32, U32> sConfigurationMap = null;
|
||||||
// BpfMap for UID_OWNER_MAP_PATH. This map is not accessed by others.
|
// BpfMap for UID_OWNER_MAP_PATH. This map is not accessed by others.
|
||||||
private static BpfMap<U32, UidOwnerValue> sUidOwnerMap = null;
|
private static IBpfMap<U32, UidOwnerValue> sUidOwnerMap = null;
|
||||||
private static BpfMap<U32, U8> sUidPermissionMap = null;
|
private static IBpfMap<U32, U8> sUidPermissionMap = null;
|
||||||
|
|
||||||
// LINT.IfChange(match_type)
|
// LINT.IfChange(match_type)
|
||||||
@VisibleForTesting public static final long NO_MATCH = 0;
|
@VisibleForTesting public static final long NO_MATCH = 0;
|
||||||
@@ -132,7 +133,7 @@ public class BpfNetMaps {
|
|||||||
* Set configurationMap for test.
|
* Set configurationMap for test.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static void setConfigurationMapForTest(BpfMap<U32, U32> configurationMap) {
|
public static void setConfigurationMapForTest(IBpfMap<U32, U32> configurationMap) {
|
||||||
sConfigurationMap = configurationMap;
|
sConfigurationMap = configurationMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +141,7 @@ public class BpfNetMaps {
|
|||||||
* Set uidOwnerMap for test.
|
* Set uidOwnerMap for test.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static void setUidOwnerMapForTest(BpfMap<U32, UidOwnerValue> uidOwnerMap) {
|
public static void setUidOwnerMapForTest(IBpfMap<U32, UidOwnerValue> uidOwnerMap) {
|
||||||
sUidOwnerMap = uidOwnerMap;
|
sUidOwnerMap = uidOwnerMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,11 +149,11 @@ public class BpfNetMaps {
|
|||||||
* Set uidPermissionMap for test.
|
* Set uidPermissionMap for test.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static void setUidPermissionMapForTest(BpfMap<U32, U8> uidPermissionMap) {
|
public static void setUidPermissionMapForTest(IBpfMap<U32, U8> uidPermissionMap) {
|
||||||
sUidPermissionMap = uidPermissionMap;
|
sUidPermissionMap = uidPermissionMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BpfMap<U32, U32> getConfigurationMap() {
|
private static IBpfMap<U32, U32> getConfigurationMap() {
|
||||||
try {
|
try {
|
||||||
return new BpfMap<>(
|
return new BpfMap<>(
|
||||||
CONFIGURATION_MAP_PATH, BpfMap.BPF_F_RDWR, U32.class, U32.class);
|
CONFIGURATION_MAP_PATH, BpfMap.BPF_F_RDWR, U32.class, U32.class);
|
||||||
@@ -161,7 +162,7 @@ public class BpfNetMaps {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BpfMap<U32, UidOwnerValue> getUidOwnerMap() {
|
private static IBpfMap<U32, UidOwnerValue> getUidOwnerMap() {
|
||||||
try {
|
try {
|
||||||
return new BpfMap<>(
|
return new BpfMap<>(
|
||||||
UID_OWNER_MAP_PATH, BpfMap.BPF_F_RDWR, U32.class, UidOwnerValue.class);
|
UID_OWNER_MAP_PATH, BpfMap.BPF_F_RDWR, U32.class, UidOwnerValue.class);
|
||||||
@@ -170,7 +171,7 @@ public class BpfNetMaps {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BpfMap<U32, U8> getUidPermissionMap() {
|
private static IBpfMap<U32, U8> getUidPermissionMap() {
|
||||||
try {
|
try {
|
||||||
return new BpfMap<>(
|
return new BpfMap<>(
|
||||||
UID_PERMISSION_MAP_PATH, BpfMap.BPF_F_RDWR, U32.class, U8.class);
|
UID_PERMISSION_MAP_PATH, BpfMap.BPF_F_RDWR, U32.class, U8.class);
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ import android.os.ServiceSpecificException;
|
|||||||
import androidx.test.filters.SmallTest;
|
import androidx.test.filters.SmallTest;
|
||||||
|
|
||||||
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.IBpfMap;
|
||||||
import com.android.net.module.util.Struct.U32;
|
import com.android.net.module.util.Struct.U32;
|
||||||
import com.android.net.module.util.Struct.U8;
|
import com.android.net.module.util.Struct.U8;
|
||||||
import com.android.testutils.DevSdkIgnoreRule;
|
import com.android.testutils.DevSdkIgnoreRule;
|
||||||
@@ -113,10 +113,10 @@ public final class BpfNetMapsTest {
|
|||||||
@Mock INetd mNetd;
|
@Mock INetd mNetd;
|
||||||
@Mock BpfNetMaps.Dependencies mDeps;
|
@Mock BpfNetMaps.Dependencies mDeps;
|
||||||
@Mock Context mContext;
|
@Mock Context mContext;
|
||||||
private final BpfMap<U32, U32> mConfigurationMap = new TestBpfMap<>(U32.class, U32.class);
|
private final IBpfMap<U32, U32> mConfigurationMap = new TestBpfMap<>(U32.class, U32.class);
|
||||||
private final BpfMap<U32, UidOwnerValue> mUidOwnerMap =
|
private final IBpfMap<U32, UidOwnerValue> mUidOwnerMap =
|
||||||
new TestBpfMap<>(U32.class, UidOwnerValue.class);
|
new TestBpfMap<>(U32.class, UidOwnerValue.class);
|
||||||
private final BpfMap<U32, U8> mUidPermissionMap = new TestBpfMap<>(U32.class, U8.class);
|
private final IBpfMap<U32, U8> mUidPermissionMap = new TestBpfMap<>(U32.class, U8.class);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user