limit IFINDEX matching to specific actions.

For each netlink message that belongs to net subsystem, the netd
NetLinkHandler will try to find the IFINDEX param in the netlink event.
Since most of the net related netlink event do not have IFINDEX inside
the message, it causes a lot of FindParam() error when handle those
messages. So we only do a FindParam for message with action kLinkUp,
kLinkDown and kAdd so the false alarm of IFINDEX not exist will not be
triggered.

Bug: 73137611
Test: ./netd_unit_test pass and adb logcat | grep IFINDEX do not show
NetlinkEvent errors;

Change-Id: If8f06b357d7f6added0dc6d9bfe2742ec9601575
(cherry picked from aosp commit 04f3b17f4d8bd5483ff5d530a8be4e831ce46b4f)
diff --git a/server/NetlinkHandler.cpp b/server/NetlinkHandler.cpp
index 77ba239..9b033ff 100644
--- a/server/NetlinkHandler.cpp
+++ b/server/NetlinkHandler.cpp
@@ -65,16 +65,20 @@
     if (!strcmp(subsys, "net")) {
         NetlinkEvent::Action action = evt->getAction();
         const char *iface = evt->findParam("INTERFACE");
-        const char *ifIndex = evt->findParam("IFINDEX");
-        if (ifIndex) {
-            char *endptr;
-            long ifaceIndex = strtol(ifIndex, &endptr, 10);
-            if ((errno == ERANGE && (ifaceIndex == LONG_MAX || ifaceIndex == LONG_MIN))
-                || (errno != 0 && ifaceIndex == 0) || endptr == ifIndex) {
-                ALOGE("invalid interface index: %s(%s)", iface, ifIndex);
-           } else {
-                gCtls->trafficCtrl.addInterface(iface, ifaceIndex);
-           }
+        if ((action == NetlinkEvent::Action::kAdd) ||
+            (action == NetlinkEvent::Action::kLinkUp) ||
+            (action == NetlinkEvent::Action::kLinkDown)) {
+            const char *ifIndex = evt->findParam("IFINDEX");
+            if (ifIndex) {
+                // strtol returns 0 on error, which is fine because 0 is not a valid ifindex.
+                long ifaceIndex = strtol(ifIndex, NULL, 10);
+                if (ifaceIndex == 0 ||
+                    (errno == ERANGE && (ifaceIndex == LONG_MAX || ifaceIndex == LONG_MIN))) {
+                    ALOGE("invalid interface index: %s(%s)", iface, ifIndex);
+                } else {
+                    gCtls->trafficCtrl.addInterface(iface, ifaceIndex);
+                }
+            }
         }
 
         if (action == NetlinkEvent::Action::kAdd) {