Increase the valid name of the iface to IFNAMSIZ

Define MAX_IFACE_LENGTH as IFNAMSIZ instead of 10, to
prevent netd from treating an interface name 'rmnet_sdio0'
as invalid.
Also fix an off-by-one error.

bug:5675718
Change-Id: I2b6ba823c89941031e5898b24dab388cd9c2dae8
diff --git a/NatController.cpp b/NatController.cpp
index 7f1bc60..4ea5d24 100644
--- a/NatController.cpp
+++ b/NatController.cpp
@@ -89,7 +89,7 @@
 }
 
 bool NatController::checkInterface(const char *iface) {
-    if (strlen(iface) > MAX_IFACE_LENGTH) return false;
+    if (strlen(iface) > IFNAMSIZ) return false;
     return true;
 }
 
diff --git a/SecondaryTableController.cpp b/SecondaryTableController.cpp
index 287bba5..2289259 100644
--- a/SecondaryTableController.cpp
+++ b/SecondaryTableController.cpp
@@ -55,7 +55,8 @@
 int SecondaryTableController::findTableNumber(const char *iface) {
     int i;
     for (i = 0; i < INTERFACES_TRACKED; i++) {
-        if (strncmp(iface, mInterfaceTable[i], MAX_IFACE_LENGTH) == 0) {
+        // compare through the final null, hence +1
+        if (strncmp(iface, mInterfaceTable[i], IFNAMSIZ + 1) == 0) {
             return i;
         }
     }
@@ -73,7 +74,9 @@
             cli->sendMsg(ResponseCode::OperationFailed, "Max number NATed", true);
             return -1;
         }
-        strncpy(mInterfaceTable[tableIndex], iface, MAX_IFACE_LENGTH);
+        strncpy(mInterfaceTable[tableIndex], iface, IFNAMSIZ);
+        // Ensure null termination even if truncation happened
+        mInterfaceTable[tableIndex][IFNAMSIZ] = 0;
     }
 
     return modifyRoute(cli, ADD, iface, dest, prefix, gateway, tableIndex);
diff --git a/SecondaryTableController.h b/SecondaryTableController.h
index 0051f7f..7f30178 100644
--- a/SecondaryTableController.h
+++ b/SecondaryTableController.h
@@ -19,7 +19,12 @@
 
 #include <sysutils/FrameworkListener.h>
 
-static const unsigned int MAX_IFACE_LENGTH = 10;
+#include <linux/if.h>
+
+#ifndef IFNAMSIZ
+#define IFNAMSIZ 16
+#endif
+
 static const int INTERFACES_TRACKED = 10;
 static const int BASE_TABLE_NUMBER = 60;
 static int MAX_TABLE_NUMBER = BASE_TABLE_NUMBER + INTERFACES_TRACKED;
@@ -38,7 +43,7 @@
     int modifyRoute(SocketClient *cli, char *action, char *iface, char *dest, int prefix,
             char *gateway, int tableIndex);
 
-    char mInterfaceTable[INTERFACES_TRACKED][MAX_IFACE_LENGTH];
+    char mInterfaceTable[INTERFACES_TRACKED][IFNAMSIZ + 1];
     int mInterfaceRuleCount[INTERFACES_TRACKED];
 
     int runAndFree(SocketClient *cli, char *cmd);