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.
Change-Id: If6b2b27d2da6eb72f01c090cbe4f7dc2b9c296ae
diff --git a/NatController.cpp b/NatController.cpp
index bdbc429..b68e4bf 100644
--- a/NatController.cpp
+++ b/NatController.cpp
@@ -87,7 +87,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 5939924..b2c5031 100644
--- a/SecondaryTableController.cpp
+++ b/SecondaryTableController.cpp
@@ -52,7 +52,7 @@
int SecondaryTableController::findTableNumber(const char *iface) {
int i;
for (i = 0; i < INTERFACES_TRACKED; i++) {
- if (strncmp(iface, mInterfaceTable[i], MAX_IFACE_LENGTH) == 0) {
+ if (strncmp(iface, mInterfaceTable[i], IFNAMSIZ) == 0) {
return i;
}
}
@@ -70,7 +70,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 259ab43..58914df 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;
@@ -40,7 +45,7 @@
int modifyRoute(SocketClient *cli, const 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];
void modifyRuleCount(int tableIndex, const char *action);
int verifyTableIndex(int tableIndex);