ClatCoordinator: use Java class BpfMap to add clat rule
This a preparation to replace duplicated native functions with the
existing Java class.
Bug: 221213090
Test: atest FrameworksNetTests
Test: check map content {iface index, v4addr, v6addr, pfx96} manually.
The map fileds are the same as "ip addr" and clatd logging.
$ adb shell dumpsys netd
ClatdController
BPF ingress map: iif(iface) nat64Prefix v6Addr -> v4Addr oif(iface)
47(wlan0) 64:ff9b::/96 2a00:79e1:abc:6f02:f9e1:8c2d:604e:bc06 -> 192.0.0.4 53(v4-wlan0)
BPF egress map: iif(iface) v4Addr -> v6Addr nat64Prefix oif(iface)
53(v4-wlan0) 192.0.0.4 -> 2a00:79e1:abc:6f02:f9e1:8c2d:604e:bc06 64:ff9b::/96 47(wlan0) ether
$ adb shell ip addr
47: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ..
53: v4-wlan0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1472 ..
03-14 18:35:04.822 30852 30852 I clatd : Starting clat version 1.5 on wlan0 plat=64:ff9b:: v4=192.0.0.4 v6=2a00:79e1:abc:6f02:f9e1:8c2d:604e:bc06
Change-Id: I91d0cb6e76c4ef7bacf91b996786308ff4918f35
This commit is contained in:
@@ -41,6 +41,11 @@ import android.os.ParcelFileDescriptor;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.net.module.util.IBpfMap;
|
||||
import com.android.net.module.util.bpf.ClatEgress4Key;
|
||||
import com.android.net.module.util.bpf.ClatEgress4Value;
|
||||
import com.android.net.module.util.bpf.ClatIngress6Key;
|
||||
import com.android.net.module.util.bpf.ClatIngress6Value;
|
||||
import com.android.testutils.DevSdkIgnoreRule;
|
||||
import com.android.testutils.DevSdkIgnoreRunner;
|
||||
|
||||
@@ -98,8 +103,19 @@ public class ClatCoordinatorTest {
|
||||
private static final ParcelFileDescriptor PACKET_SOCK_PFD = new ParcelFileDescriptor(
|
||||
new FileDescriptor());
|
||||
|
||||
private static final ClatEgress4Key EGRESS_KEY = new ClatEgress4Key(STACKED_IFINDEX,
|
||||
INET4_LOCAL4);
|
||||
private static final ClatEgress4Value EGRESS_VALUE = new ClatEgress4Value(BASE_IFINDEX,
|
||||
INET6_LOCAL6, INET6_PFX96, (short) 1 /* oifIsEthernet, 1 = true */);
|
||||
private static final ClatIngress6Key INGRESS_KEY = new ClatIngress6Key(BASE_IFINDEX,
|
||||
INET6_PFX96, INET6_LOCAL6);
|
||||
private static final ClatIngress6Value INGRESS_VALUE = new ClatIngress6Value(STACKED_IFINDEX,
|
||||
INET4_LOCAL4);
|
||||
|
||||
@Mock private INetd mNetd;
|
||||
@Spy private TestDependencies mDeps = new TestDependencies();
|
||||
@Mock private IBpfMap<ClatIngress6Key, ClatIngress6Value> mIngressMap;
|
||||
@Mock private IBpfMap<ClatEgress4Key, ClatEgress4Value> mEgressMap;
|
||||
|
||||
/**
|
||||
* The dependency injection class is used to mock the JNI functions and system functions
|
||||
@@ -298,6 +314,26 @@ public class ClatCoordinatorTest {
|
||||
fail("unsupported arg: " + cookie);
|
||||
}
|
||||
}
|
||||
|
||||
/** Get ingress6 BPF map. */
|
||||
@Override
|
||||
public IBpfMap<ClatIngress6Key, ClatIngress6Value> getBpfIngress6Map() {
|
||||
return mIngressMap;
|
||||
}
|
||||
|
||||
/** Get egress4 BPF map. */
|
||||
@Override
|
||||
public IBpfMap<ClatEgress4Key, ClatEgress4Value> getBpfEgress4Map() {
|
||||
return mEgressMap;
|
||||
}
|
||||
|
||||
/** Checks if the network interface uses an ethernet L2 header. */
|
||||
public boolean isEthernet(String iface) throws IOException {
|
||||
if (BASE_IFACE.equals(iface)) return true;
|
||||
|
||||
fail("unsupported arg: " + iface);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@NonNull
|
||||
@@ -322,8 +358,8 @@ public class ClatCoordinatorTest {
|
||||
@Test
|
||||
public void testStartStopClatd() throws Exception {
|
||||
final ClatCoordinator coordinator = makeClatCoordinator();
|
||||
final InOrder inOrder = inOrder(mNetd, mDeps);
|
||||
clearInvocations(mNetd, mDeps);
|
||||
final InOrder inOrder = inOrder(mNetd, mDeps, mIngressMap, mEgressMap);
|
||||
clearInvocations(mNetd, mDeps, mIngressMap, mEgressMap);
|
||||
|
||||
// [1] Start clatd.
|
||||
final String addr6For464xlat = coordinator.clatStart(BASE_IFACE, NETID, NAT64_IP_PREFIX);
|
||||
@@ -379,6 +415,8 @@ public class ClatCoordinatorTest {
|
||||
argThat(fd -> Objects.equals(RAW_SOCK_PFD.getFileDescriptor(), fd)),
|
||||
eq(BASE_IFACE), eq(NAT64_PREFIX_STRING),
|
||||
eq(XLAT_LOCAL_IPV4ADDR_STRING), eq(XLAT_LOCAL_IPV6ADDR_STRING));
|
||||
inOrder.verify(mEgressMap).insertEntry(eq(EGRESS_KEY), eq(EGRESS_VALUE));
|
||||
inOrder.verify(mIngressMap).insertEntry(eq(INGRESS_KEY), eq(INGRESS_VALUE));
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
|
||||
// [2] Start clatd again failed.
|
||||
|
||||
Reference in New Issue
Block a user