[RFCLAT#9] refactor getinterface_ip() to stop using libnl
The interface address query doesn't use libnl anymore.
Needed for reducing the library dependency. Once the last libnl user
del_anycast_address() is removed, clatd can remove libnl. Less
dependency helps moving clatd to mainline.
parse_ifaddrmsg() is used to replaced with getaddr_cb() which updates
struct target variable until walking through all messages.
parse_ifaddrmsg() keeps the same behavior as getaddr_cb().
Bug: 212345928
Test: atest clatd_test and manual test
1. Connect to ipv6-only wifi.
2. Try IPv4 traffic.
$ ping 8.8.8.8
Change-Id: I56591ec851d3202e18cce9fce3995d658d9f07e2
diff --git a/clatd_test.cpp b/clatd_test.cpp
index 7fa870e..8eef738 100644
--- a/clatd_test.cpp
+++ b/clatd_test.cpp
@@ -837,7 +837,20 @@
"UDP/IPv4 -> UDP/IPv6 checksum neutral");
}
-TEST_F(ClatdTest, GetInterfaceIp) {
+TEST_F(ClatdTest, GetInterfaceIpV4) {
+ TunInterface v4Iface;
+ ASSERT_EQ(0, v4Iface.init());
+ EXPECT_EQ(0, v4Iface.addAddress("192.0.2.1", 32));
+
+ union anyip *ip = getinterface_ip(v4Iface.name().c_str(), AF_INET);
+ ASSERT_NE(nullptr, ip);
+ EXPECT_EQ(inet_addr("192.0.2.1"), ip->ip4.s_addr);
+ free(ip);
+
+ v4Iface.destroy();
+}
+
+TEST_F(ClatdTest, GetInterfaceIpV6) {
union anyip *ip = getinterface_ip(sTun.name().c_str(), AF_INET6);
ASSERT_NE(nullptr, ip);
in6_addr expected = sTun.srcAddr();