[RFCLAT#8] clatd_test: remove or refactor tests for configure_clat_ipv6_address
1. Delete the test because it has been moved to netd.
- ConfigureIpv6Address
2. Refactor the existing test.
Assign IPv6 address directly because the address is applied by
cli argument now because configure_clat_ipv6_address() is
removed.
- Ipv6AddressChanged
Bug: 212345928
Test: atest clatd_test
Change-Id: I673327a36727e22f4ab23c191ee389fc1914016c
diff --git a/clatd_test.cpp b/clatd_test.cpp
index 7b2fb37..7fa870e 100644
--- a/clatd_test.cpp
+++ b/clatd_test.cpp
@@ -560,21 +560,6 @@
}
}
-static tun_data makeTunData() {
- // Create some fake but realistic-looking sockets so update_clat_ipv6_address doesn't balk.
- return {
- .read_fd6 = socket(AF_PACKET, SOCK_DGRAM, htons(ETH_P_IPV6)),
- .write_fd6 = socket(AF_INET6, SOCK_RAW | SOCK_NONBLOCK, IPPROTO_RAW),
- .fd4 = socket(AF_UNIX, SOCK_DGRAM, 0),
- };
-}
-
-void freeTunData(tun_data *tunnel) {
- close(tunnel->write_fd6);
- close(tunnel->read_fd6);
- close(tunnel->fd4);
-}
-
struct clat_config Global_Clatd_Config;
class ClatdTest : public ::testing::Test {
@@ -860,50 +845,8 @@
expect_ipv6_addr_equal(&expected, &actual);
}
-void expectSocketBound(int ifindex, int sock) {
- // Check that the packet socket is bound to the interface. We can't check the socket filter
- // because there is no way to fetch it from the kernel.
- sockaddr_ll sll;
- socklen_t len = sizeof(sll);
- ASSERT_EQ(0, getsockname(sock, reinterpret_cast<sockaddr *>(&sll), &len));
- EXPECT_EQ(htons(ETH_P_IPV6), sll.sll_protocol);
- EXPECT_EQ(ifindex, sll.sll_ifindex);
-}
-
-TEST_F(ClatdTest, ConfigureIpv6Address) {
- struct tun_data tunnel = makeTunData();
-
- ASSERT_TRUE(IN6_IS_ADDR_UNSPECIFIED(&Global_Clatd_Config.ipv6_local_subnet));
-
- const char *addrStr = "2001:db8::f00";
- in6_addr addr;
- ASSERT_EQ(1, inet_pton(AF_INET6, addrStr, &addr));
- ASSERT_EQ(1, configure_clat_ipv6_address(&tunnel, sTun.name().c_str(), addrStr));
-
- EXPECT_EQ(htonl(0x20010db8), Global_Clatd_Config.ipv6_local_subnet.s6_addr32[0]);
- EXPECT_EQ(htonl(0x00000000), Global_Clatd_Config.ipv6_local_subnet.s6_addr32[1]);
- EXPECT_EQ(htonl(0x00000000), Global_Clatd_Config.ipv6_local_subnet.s6_addr32[2]);
- EXPECT_EQ(htonl(0x00000f00), Global_Clatd_Config.ipv6_local_subnet.s6_addr32[3]);
-
- // Check that the packet socket is bound to the interface. We can't check the socket filter
- // because there is no way to fetch it from the kernel.
- sockaddr_ll sll;
- socklen_t len = sizeof(sll);
- ASSERT_EQ(0, getsockname(tunnel.read_fd6, reinterpret_cast<sockaddr *>(&sll), &len));
- EXPECT_EQ(htons(ETH_P_IPV6), sll.sll_protocol);
- EXPECT_EQ(sll.sll_ifindex, sTun.ifindex());
-
- expectSocketBound(sTun.ifindex(), tunnel.read_fd6);
-
- freeTunData(&tunnel);
-}
-
TEST_F(ClatdTest, Ipv6AddressChanged) {
// Configure the clat IPv6 address.
- struct tun_data tunnel = {
- .read_fd6 = socket(AF_PACKET, SOCK_DGRAM, htons(ETH_P_IPV6)),
- .write_fd6 = socket(AF_INET6, SOCK_RAW | SOCK_NONBLOCK, IPPROTO_RAW),
- };
const char *ifname = sTun.name().c_str();
in6_addr myaddr = sTun.srcAddr();
@@ -911,7 +854,7 @@
char addrstr[INET6_ADDRSTRLEN];
ASSERT_NE(nullptr, inet_ntop(AF_INET6, &myaddr, addrstr, sizeof(addrstr)));
- ASSERT_EQ(1, configure_clat_ipv6_address(&tunnel, ifname, addrstr));
+ Global_Clatd_Config.ipv6_local_subnet = myaddr;
EXPECT_EQ(0, ipv6_address_changed(ifname));
EXPECT_EQ(0, ipv6_address_changed(ifname));