refactor: continued am: a0e2c0445d

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1553320

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I35f19f1b378271907788b41631e864886bdf4e8a
This commit is contained in:
Maciej Żenczykowski
2021-01-20 15:42:54 +00:00
committed by Automerger Merge Worker
5 changed files with 27 additions and 23 deletions

View File

@@ -69,7 +69,7 @@ public class BpfCoordinatorShimImpl
public BpfCoordinatorShimImpl(@NonNull final Dependencies deps) {
mLog = deps.getSharedLog().forSubComponent(TAG);
mBpfDownstream6Map = deps.getBpfIngressMap();
mBpfDownstream6Map = deps.getBpfDownstream6Map();
mBpfStatsMap = deps.getBpfStatsMap();
mBpfLimitMap = deps.getBpfLimitMap();
}

View File

@@ -73,7 +73,7 @@ import java.util.Objects;
public class BpfCoordinator {
private static final String TAG = BpfCoordinator.class.getSimpleName();
private static final int DUMP_TIMEOUT_MS = 10_000;
private static final String TETHER_INGRESS_FS_PATH =
private static final String TETHER_DOWNSTREAM6_FS_PATH =
"/sys/fs/bpf/map_offload_tether_downstream6_map";
private static final String TETHER_STATS_MAP_PATH =
"/sys/fs/bpf/map_offload_tether_stats_map";
@@ -190,13 +190,14 @@ public class BpfCoordinator {
return SdkLevel.isAtLeastS();
}
/** Get ingress BPF map. */
@Nullable public BpfMap<TetherDownstream6Key, TetherDownstream6Value> getBpfIngressMap() {
/** Get downstream6 BPF map. */
@Nullable public BpfMap<TetherDownstream6Key, TetherDownstream6Value>
getBpfDownstream6Map() {
try {
return new BpfMap<>(TETHER_INGRESS_FS_PATH,
return new BpfMap<>(TETHER_DOWNSTREAM6_FS_PATH,
BpfMap.BPF_F_RDWR, TetherDownstream6Key.class, TetherDownstream6Value.class);
} catch (ErrnoException e) {
Log.e(TAG, "Cannot create ingress map: " + e);
Log.e(TAG, "Cannot create downstream6 map: " + e);
return null;
}
}

View File

@@ -51,7 +51,7 @@ import java.util.concurrent.atomic.AtomicInteger;
public final class BpfMapTest {
// Sync from packages/modules/Connectivity/Tethering/bpf_progs/offload.c.
private static final int TEST_MAP_SIZE = 16;
private static final String TETHER_INGRESS_FS_PATH =
private static final String TETHER_DOWNSTREAM6_FS_PATH =
"/sys/fs/bpf/tethering/map_test_tether_downstream6_map";
private ArrayMap<TetherDownstream6Key, TetherDownstream6Value> mTestData;
@@ -88,7 +88,7 @@ public final class BpfMapTest {
private BpfMap<TetherDownstream6Key, TetherDownstream6Value> getTestMap() throws Exception {
return new BpfMap<>(
TETHER_INGRESS_FS_PATH, BpfMap.BPF_F_RDWR,
TETHER_DOWNSTREAM6_FS_PATH, BpfMap.BPF_F_RDWR,
TetherDownstream6Key.class, TetherDownstream6Value.class);
}
@@ -122,7 +122,7 @@ public final class BpfMapTest {
@Test
public void testGetFd() throws Exception {
try (BpfMap readOnlyMap = new BpfMap<>(TETHER_INGRESS_FS_PATH, BpfMap.BPF_F_RDONLY,
try (BpfMap readOnlyMap = new BpfMap<>(TETHER_DOWNSTREAM6_FS_PATH, BpfMap.BPF_F_RDONLY,
TetherDownstream6Key.class, TetherDownstream6Value.class)) {
assertNotNull(readOnlyMap);
try {
@@ -132,7 +132,7 @@ public final class BpfMapTest {
assertEquals(OsConstants.EPERM, expected.errno);
}
}
try (BpfMap writeOnlyMap = new BpfMap<>(TETHER_INGRESS_FS_PATH, BpfMap.BPF_F_WRONLY,
try (BpfMap writeOnlyMap = new BpfMap<>(TETHER_DOWNSTREAM6_FS_PATH, BpfMap.BPF_F_WRONLY,
TetherDownstream6Key.class, TetherDownstream6Value.class)) {
assertNotNull(writeOnlyMap);
try {
@@ -142,7 +142,7 @@ public final class BpfMapTest {
assertEquals(OsConstants.EPERM, expected.errno);
}
}
try (BpfMap readWriteMap = new BpfMap<>(TETHER_INGRESS_FS_PATH, BpfMap.BPF_F_RDWR,
try (BpfMap readWriteMap = new BpfMap<>(TETHER_DOWNSTREAM6_FS_PATH, BpfMap.BPF_F_RDWR,
TetherDownstream6Key.class, TetherDownstream6Value.class)) {
assertNotNull(readWriteMap);
}

View File

@@ -296,7 +296,8 @@ public class IpServerTest {
}
@Nullable
public BpfMap<TetherDownstream6Key, TetherDownstream6Value> getBpfIngressMap() {
public BpfMap<TetherDownstream6Key, TetherDownstream6Value>
getBpfDownstream6Map() {
return mBpfDownstream6Map;
}
@@ -770,13 +771,13 @@ public class IpServerTest {
}
@NonNull
private static TetherDownstream6Key makeIngressKey(int upstreamIfindex,
private static TetherDownstream6Key makeDownstream6Key(int upstreamIfindex,
@NonNull final InetAddress dst) {
return new TetherDownstream6Key(upstreamIfindex, dst.getAddress());
}
@NonNull
private static TetherDownstream6Value makeIngressValue(@NonNull final MacAddress dstMac) {
private static TetherDownstream6Value makeDownstream6Value(@NonNull final MacAddress dstMac) {
return new TetherDownstream6Value(TEST_IFACE_PARAMS.index, dstMac,
TEST_IFACE_PARAMS.macAddr, ETH_P_IPV6, NetworkStackConstants.ETHER_MTU);
}
@@ -793,7 +794,7 @@ public class IpServerTest {
@NonNull final InetAddress dst, @NonNull final MacAddress dstMac) throws Exception {
if (mBpfDeps.isAtLeastS()) {
verifyWithOrder(inOrder, mBpfDownstream6Map).updateEntry(
makeIngressKey(upstreamIfindex, dst), makeIngressValue(dstMac));
makeDownstream6Key(upstreamIfindex, dst), makeDownstream6Value(dstMac));
} else {
verifyWithOrder(inOrder, mNetd).tetherOffloadRuleAdd(matches(upstreamIfindex, dst,
dstMac));
@@ -803,8 +804,9 @@ public class IpServerTest {
private void verifyNeverTetherOffloadRuleAdd(int upstreamIfindex,
@NonNull final InetAddress dst, @NonNull final MacAddress dstMac) throws Exception {
if (mBpfDeps.isAtLeastS()) {
verify(mBpfDownstream6Map, never()).updateEntry(makeIngressKey(upstreamIfindex, dst),
makeIngressValue(dstMac));
verify(mBpfDownstream6Map, never()).updateEntry(
makeDownstream6Key(upstreamIfindex, dst),
makeDownstream6Value(dstMac));
} else {
verify(mNetd, never()).tetherOffloadRuleAdd(matches(upstreamIfindex, dst, dstMac));
}
@@ -821,8 +823,8 @@ public class IpServerTest {
private void verifyTetherOffloadRuleRemove(@Nullable InOrder inOrder, int upstreamIfindex,
@NonNull final InetAddress dst, @NonNull final MacAddress dstMac) throws Exception {
if (mBpfDeps.isAtLeastS()) {
verifyWithOrder(inOrder, mBpfDownstream6Map).deleteEntry(makeIngressKey(upstreamIfindex,
dst));
verifyWithOrder(inOrder, mBpfDownstream6Map).deleteEntry(makeDownstream6Key(
upstreamIfindex, dst));
} else {
// |dstMac| is not required for deleting rules. Used bacause tetherOffloadRuleRemove
// uses a whole rule to be a argument.

View File

@@ -194,7 +194,8 @@ public class BpfCoordinatorTest {
}
@Nullable
public BpfMap<TetherDownstream6Key, TetherDownstream6Value> getBpfIngressMap() {
public BpfMap<TetherDownstream6Key, TetherDownstream6Value>
getBpfDownstream6Map() {
return mBpfDownstream6Map;
}
@@ -846,7 +847,7 @@ public class BpfCoordinatorTest {
private void checkBpfDisabled() throws Exception {
// The caller may mock the global dependencies |mDeps| which is used in
// #makeBpfCoordinator for testing.
// See #testBpfDisabledbyNoBpfIngressMap.
// See #testBpfDisabledbyNoBpfDownstream6Map.
final BpfCoordinator coordinator = makeBpfCoordinator();
coordinator.startPolling();
@@ -909,9 +910,9 @@ public class BpfCoordinatorTest {
@Test
@IgnoreUpTo(Build.VERSION_CODES.R)
public void testBpfDisabledbyNoBpfIngressMap() throws Exception {
public void testBpfDisabledbyNoBpfDownstream6Map() throws Exception {
setupFunctioningNetdInterface();
doReturn(null).when(mDeps).getBpfIngressMap();
doReturn(null).when(mDeps).getBpfDownstream6Map();
checkBpfDisabled();
}