ClatUtils - implement hardwareAddressType()

Test: builds and atest netd_unit_test
Bug: 65674744
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia032ab061bf7121affc465ec6cd63524979f26b1
diff --git a/server/ClatUtilsTest.cpp b/server/ClatUtilsTest.cpp
index f1eed0c..79d3440 100644
--- a/server/ClatUtilsTest.cpp
+++ b/server/ClatUtilsTest.cpp
@@ -20,6 +20,8 @@
 
 #include "ClatUtils.h"
 
+#include <linux/if_arp.h>
+
 namespace android {
 namespace net {
 
@@ -28,5 +30,35 @@
     void SetUp() {}
 };
 
+TEST_F(ClatUtilsTest, HardwareAddressTypeOfNonExistingIf) {
+    EXPECT_EQ(-ENODEV, hardwareAddressType("not_existing_if"));
+}
+
+TEST_F(ClatUtilsTest, HardwareAddressTypeOfLoopback) {
+    EXPECT_EQ(ARPHRD_LOOPBACK, hardwareAddressType("lo"));
+}
+
+// If wireless 'wlan0' interface exists it should be Ethernet.
+TEST_F(ClatUtilsTest, HardwareAddressTypeOfWireless) {
+    int type = hardwareAddressType("wlan0");
+    if (type == -ENODEV) return;
+
+    EXPECT_EQ(ARPHRD_ETHER, type);
+}
+
+// If cellular 'rmnet_data0' interface exists it should
+// *probably* not be Ethernet and instead be RawIp.
+TEST_F(ClatUtilsTest, HardwareAddressTypeOfCellular) {
+    int type = hardwareAddressType("rmnet_data0");
+    if (type == -ENODEV) return;
+
+    EXPECT_NE(ARPHRD_ETHER, type);
+
+    // ARPHRD_RAWIP is 530 on some pre-4.14 Qualcomm devices.
+    if (type == 530) return;
+
+    EXPECT_EQ(ARPHRD_RAWIP, type);
+}
+
 }  // namespace net
 }  // namespace android