Address comments for XfrmController::Init
-Use a cleaner string comparison
-Add a check to the unit test
Bug: 74560705
Test: atest netd_integration_test
Merged-In: Ia1fe2b7691a904696baefb186a7233a681412263
Change-Id: Ia1fe2b7691a904696baefb186a7233a681412263
(cherry picked from commit ac62cbd5217ccda2364d5cf942db41f699637fe9)
diff --git a/server/XfrmController.cpp b/server/XfrmController.cpp
index 0317779..9f62453 100644
--- a/server/XfrmController.cpp
+++ b/server/XfrmController.cpp
@@ -390,7 +390,7 @@
for (const std::string& iface : ifaces.value()) {
int status = 0;
// Look for the reserved interface prefix, which must be in the name at position 0
- if (iface.find(TUNNEL_INTERFACE_PREFIX) == 0 &&
+ if (!iface.compare(0, strlen(TUNNEL_INTERFACE_PREFIX), TUNNEL_INTERFACE_PREFIX) &&
(status = removeVirtualTunnelInterface(iface)) < 0) {
ALOGE("Failed to delete ipsec tunnel %s.", iface.c_str());
return netdutils::statusFromErrno(status, "Failed to remove ipsec tunnel.");