Merge "ipa : Addition of diag log messages for IPA NAT"
diff --git a/ipacm/inc/IPACM_Conntrack_NATApp.h b/ipacm/inc/IPACM_Conntrack_NATApp.h
index 1fb12bf..836241a 100644
--- a/ipacm/inc/IPACM_Conntrack_NATApp.h
+++ b/ipacm/inc/IPACM_Conntrack_NATApp.h
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2013, The Linux Foundation. All rights reserved.
+Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are
@@ -52,7 +52,7 @@
 	uint32_t target_ip;
 	uint16_t target_port;
 
-	uint16_t public_ip;
+	uint32_t public_ip;
 	uint16_t public_port;
 
 	u_int8_t  protocol;
diff --git a/ipacm/inc/IPACM_Neighbor.h b/ipacm/inc/IPACM_Neighbor.h
index 55ab92e..14e86e5 100644
--- a/ipacm/inc/IPACM_Neighbor.h
+++ b/ipacm/inc/IPACM_Neighbor.h
@@ -48,7 +48,7 @@
 #include "IPACM_Listener.h"
 #include "IPACM_Iface.h"
 
-#define IPA_MAX_NUM_NEIGHBOR_CLIENTS  17
+#define IPA_MAX_NUM_NEIGHBOR_CLIENTS  100
 
 struct ipa_neighbor_client
 {
@@ -72,8 +72,9 @@
 
 	int num_neighbor_client;
 
-	ipa_neighbor_client neighbor_client[IPA_MAX_NUM_NEIGHBOR_CLIENTS];
+	int circular_index;
 
+	ipa_neighbor_client neighbor_client[IPA_MAX_NUM_NEIGHBOR_CLIENTS];
 
 };
 
diff --git a/ipacm/src/Android.mk b/ipacm/src/Android.mk
index d9f3145..64ee3ec 100644
--- a/ipacm/src/Android.mk
+++ b/ipacm/src/Android.mk
@@ -1,3 +1,6 @@
+BOARD_PLATFORM_LIST := msm8916
+BOARD_PLATFORM_LIST += msm8909
+ifneq ($(call is-board-platform-in-list,$(BOARD_PLATFORM_LIST)),true)
 ifneq (,$(filter $(QCOM_BOARD_PLATFORMS),$(TARGET_BOARD_PLATFORM)))
 ifneq (, $(filter aarch64 arm arm64, $(TARGET_ARCH)))
 ifneq ($(TARGET_USES_AOSP),true)
@@ -90,3 +93,4 @@
 endif # not (TARGET_USES_AOSP)
 endif # $(TARGET_ARCH)
 endif
+endif
\ No newline at end of file
diff --git a/ipacm/src/IPACM_ConntrackListener.cpp b/ipacm/src/IPACM_ConntrackListener.cpp
index 9e66a00..4ad0164 100644
--- a/ipacm/src/IPACM_ConntrackListener.cpp
+++ b/ipacm/src/IPACM_ConntrackListener.cpp
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2013, The Linux Foundation. All rights reserved.
+Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are
@@ -699,22 +699,20 @@
 			 return;
 		 }
 
-		 if(orig_src_ip == wan_ipaddr)
-		 {
-			 IPACMDBG("orig src ip:0x%x equal to wan ip\n",orig_src_ip);
-			 status = IPS_SRC_NAT;
-			 rule.public_ip = wan_ipaddr;
-		 }
-		 else if(orig_dst_ip == wan_ipaddr)
-		 {
-			 IPACMDBG("orig Dst IP:0x%x equal to wan ip\n",orig_dst_ip);
-			 status = IPS_DST_NAT;
-	 	 	 rule.public_ip = wan_ipaddr;
-		 }
-		 else
-		 {
-			 IPACMDBG("Neither orig src ip:0x%x Nor orig Dst IP:0x%x equal to wan ip:0x%x\n",
-						orig_src_ip, orig_dst_ip, wan_ipaddr);
+		if(orig_src_ip == wan_ipaddr)
+		{
+			IPACMDBG("orig src ip:0x%x equal to wan ip\n",orig_src_ip);
+			status = IPS_SRC_NAT;
+		}
+		else if(orig_dst_ip == wan_ipaddr)
+		{
+			IPACMDBG("orig Dst IP:0x%x equal to wan ip\n",orig_dst_ip);
+			status = IPS_DST_NAT;
+		}
+		else
+		{
+			IPACMDBG("Neither orig src ip:0x%x Nor orig Dst IP:0x%x equal to wan ip:0x%x\n",
+					orig_src_ip, orig_dst_ip, wan_ipaddr);
 
 #ifdef CT_OPT
 		if(p_lan2lan == NULL)
@@ -849,13 +847,13 @@
 			 }
 		 }
 
-		 if(cnt == MAX_NAT_IFACES)
-		 {
-			 IPACMDBG("Not mtaching with nat ifaces\n")
-			 if(pConfig == NULL)
-			 {
-				 goto IGNORE;
-			 }
+		if(cnt == MAX_NAT_IFACES)
+		{
+			IPACMDBG("Not mtaching with nat ifaces\n");
+			if(pConfig == NULL)
+			{
+				goto IGNORE;
+			}
 
 			 if(pConfig->isPrivateSubnet(rule.private_ip) ||
 						pConfig->isPrivateSubnet(rule.target_ip))
@@ -911,9 +909,9 @@
 		}
 	 }
 
-	 IPACMDBG("Not matching with STA Clnt Ip Addrs 0x%x\n",
-			 rule.target_ip);
-	 goto IGNORE;
+	IPACMDBG("Not matching with STA Clnt Ip Addrs 0x%x\n",
+		rule.target_ip);
+	isTempEntry = true;
 
 
 ADD:
@@ -925,12 +923,13 @@
 	 IPACMDBG("public port or reply dst port: 0x%x, Decimal:%d\n", rule.public_port, rule.public_port);
 	 IPACMDBG("Protocol: %d, destination nat flag: %d\n", rule.protocol, rule.dst_nat);
 
-	 if(IPPROTO_TCP == rule.protocol)
-	 {
-			if(nat_inst == NULL)
-			{
-				return;
-			}
+	rule.public_ip = wan_ipaddr;
+	if(IPPROTO_TCP == rule.protocol)
+	{
+		if(nat_inst == NULL)
+		{
+			return;
+		}
 
 			tcp_state = nfct_get_attr_u8(ct, ATTR_TCP_STATE);
 			if(TCP_CONNTRACK_ESTABLISHED == tcp_state)
@@ -1059,6 +1058,7 @@
 
 	 }
 
+	 nat_inst->FlushTempEntries(clnt_ip_addr, true);
 	 return;
 }
 
@@ -1082,5 +1082,6 @@
 		}
 	 }
 
-  return;
+	 nat_inst->FlushTempEntries(clnt_ip_addr, false);
+   return;
 }
diff --git a/ipacm/src/IPACM_Conntrack_NATApp.cpp b/ipacm/src/IPACM_Conntrack_NATApp.cpp
index e9bfd4e..ff02c2a 100644
--- a/ipacm/src/IPACM_Conntrack_NATApp.cpp
+++ b/ipacm/src/IPACM_Conntrack_NATApp.cpp
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2013, The Linux Foundation. All rights reserved.
+Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are
@@ -562,7 +562,6 @@
 		}
 	}
 
-
 	for(cnt = 0; cnt < IPA_MAX_NUM_WIFI_CLIENTS; cnt++)
 	{
 		if(PwrSaveIfs[cnt] == 0)
@@ -761,7 +760,7 @@
 
 int NatApp::DelEntriesOnClntDiscon(uint32_t ip_addr)
 {
- 	int cnt, tmp = curCnt;
+	int cnt, tmp = 0;
 	IPACMDBG("Received IP address: 0x%x\n", ip_addr);
 
 	if(ip_addr == INVALID_IP_ADDR)
@@ -770,39 +769,40 @@
 		return -1;
 	}
 
-
-  for(cnt = 0; cnt < IPA_MAX_NUM_WIFI_CLIENTS; cnt++)
-  {
-    if(PwrSaveIfs[cnt] == ip_addr)
-    {
-      PwrSaveIfs[cnt] = 0;
-      IPACMDBG("Remove %d power save entry\n", cnt);
-      break;
-    }
-  }
-
-  for(cnt = 0; cnt < max_entries; cnt++)
-  {
-	if(cache[cnt].private_ip == ip_addr)
+	for(cnt = 0; cnt < IPA_MAX_NUM_WIFI_CLIENTS; cnt++)
 	{
-		if(cache[cnt].enabled == true)
-      		{
-			if(ipa_nat_del_ipv4_rule(nat_table_hdl, cache[cnt].rule_hdl) < 0)
-			{
-				IPACMERR("unable to delete the rule\n");
-				continue;
-			}
-			else
-			{
-				IPACMDBG("won't delete the rule\n");
-				cache[cnt].enabled = false;
-		        }
-	        }
-		IPACMDBG("won't delete the rule for entry %d, enabled %d\n",cnt, cache[cnt].enabled);
+		if(PwrSaveIfs[cnt] == ip_addr)
+		{
+			PwrSaveIfs[cnt] = 0;
+			IPACMDBG("Remove %d power save entry\n", cnt);
+			break;
+		}
 	}
-  }
-  IPACMDBG("Deleted %d entries\n", (tmp - curCnt));
-  return 0;
+
+	for(cnt = 0; cnt < max_entries; cnt++)
+	{
+		if(cache[cnt].private_ip == ip_addr)
+		{
+			if(cache[cnt].enabled == true)
+			{
+				if(ipa_nat_del_ipv4_rule(nat_table_hdl, cache[cnt].rule_hdl) < 0)
+				{
+					IPACMERR("unable to delete the rule\n");
+					continue;
+				}
+				else
+				{
+					IPACMDBG("won't delete the rule\n");
+					cache[cnt].enabled = false;
+					tmp++;
+				}
+			}
+			IPACMDBG("won't delete the rule for entry %d, enabled %d\n",cnt, cache[cnt].enabled);
+		}
+	}
+
+	IPACMDBG("Deleted (but cached) %d entries\n", tmp);
+	return 0;
 }
 
 int NatApp::DelEntriesOnSTAClntDiscon(uint32_t ip_addr)
@@ -816,7 +816,6 @@
 		return -1;
 	}
 
-
 	for(cnt = 0; cnt < max_entries; cnt++)
 	{
 		if(cache[cnt].target_ip == ip_addr)
@@ -882,6 +881,7 @@
 			cache[cnt].protocol = rule->protocol;
 			cache[cnt].timestamp = 0;
 			cache[cnt].public_port = rule->public_port;
+			cache[cnt].public_ip = rule->public_ip;
 			cache[cnt].dst_nat = rule->dst_nat;
 			curCnt++;
 		}
diff --git a/ipacm/src/IPACM_Main.cpp b/ipacm/src/IPACM_Main.cpp
index 3d4ad5b..478fad2 100644
--- a/ipacm/src/IPACM_Main.cpp
+++ b/ipacm/src/IPACM_Main.cpp
@@ -275,7 +275,7 @@
 	ipacm_event_data_all* new_neigh_data;
 
 	fd = open(IPA_DRIVER, O_RDWR);
-	if (fd == 0)
+	if (fd < 0)
 	{
 		IPACMERR("Failed opening %s.\n", IPA_DRIVER);
 		return NULL;
diff --git a/ipacm/src/IPACM_Neighbor.cpp b/ipacm/src/IPACM_Neighbor.cpp
index 91facbd..93bec04 100644
--- a/ipacm/src/IPACM_Neighbor.cpp
+++ b/ipacm/src/IPACM_Neighbor.cpp
@@ -48,6 +48,8 @@
 IPACM_Neighbor::IPACM_Neighbor()
 {
 	num_neighbor_client = 0;
+	circular_index = 0;
+	memset(neighbor_client, 0, IPA_MAX_NUM_NEIGHBOR_CLIENTS * sizeof(ipa_neighbor_client));
 	IPACM_EvtDispatcher::registr(IPA_WLAN_CLIENT_ADD_EVENT_EX, this);
 	IPACM_EvtDispatcher::registr(IPA_NEW_NEIGH_EVENT, this);
 	IPACM_EvtDispatcher::registr(IPA_DEL_NEIGH_EVENT, this);
@@ -143,6 +145,15 @@
 
 		default:
 		{
+			if (event == IPA_NEW_NEIGH_EVENT)
+			{
+				IPACMDBG_H("Received IPA_NEW_NEIGH_EVENT\n");
+			}
+			else
+			{
+				IPACMDBG_H("Received IPA_DEL_NEIGH_EVENT\n");
+			}
+
 			ipacm_event_data_all *data = (ipacm_event_data_all *)param;
 			ipa_interface_index = IPACM_Iface::iface_ipa_index_query(data->if_index);
 
@@ -150,7 +161,7 @@
 			{
 				if (data->ipv4_addr != 0) /* not 0.0.0.0 */
 				{
-					IPACMDBG(" Got New_Neighbor event with ipv4 address \n");
+					IPACMDBG(" Got Neighbor event with ipv4 address \n");
 					/* check if iface is bridge interface*/
 					if (strcmp(IPACM_Iface::ipacmcfg->ipa_virtual_iface_name, IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].iface_name) == 0)
 					{
@@ -165,8 +176,36 @@
 								if (event == IPA_NEW_NEIGH_EVENT)
 									evt_data.event = IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT;
 								else
+								{
 									evt_data.event = IPA_NEIGH_CLIENT_IP_ADDR_DEL_EVENT;
+									/* do the clean-up*/
+									IPACMDBG_H("Clean %d-st Cached client-MAC %02x:%02x:%02x:%02x:%02x:%02x\n, total client: %d\n",
+												i,
+												neighbor_client[i].mac_addr[0],
+												neighbor_client[i].mac_addr[1],
+												neighbor_client[i].mac_addr[2],
+												neighbor_client[i].mac_addr[3],
+												neighbor_client[i].mac_addr[4],
+												neighbor_client[i].mac_addr[5],
+												num_neighbor_client);
 
+									memset(neighbor_client[i].mac_addr, 0, sizeof(neighbor_client[i].mac_addr));
+									neighbor_client[i].iface_index = 0;
+									neighbor_client[i].v4_addr = 0;
+									neighbor_client[i].ipa_if_num = 0;
+
+									for (; i < num_neighbor_client_temp - 1; i++)
+									{
+										memcpy(neighbor_client[i].mac_addr,
+													neighbor_client[i+1].mac_addr,
+													sizeof(neighbor_client[i].mac_addr));
+										neighbor_client[i].iface_index = neighbor_client[i+1].iface_index;
+										neighbor_client[i].v4_addr = neighbor_client[i+1].v4_addr;
+										neighbor_client[i].ipa_if_num = neighbor_client[i+1].ipa_if_num;
+									}
+									num_neighbor_client--;
+									IPACMDBG_H(" total number of left cased clients: %d\n", num_neighbor_client);
+								}
 								data_all = (ipacm_event_data_all *)malloc(sizeof(ipacm_event_data_all));
 								if (data_all == NULL)
 								{
@@ -190,22 +229,8 @@
 					{
 						/* construct IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT command and insert to command-queue */
 						if (event == IPA_NEW_NEIGH_EVENT)
-							evt_data.event = IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT;
-						else
-							evt_data.event = IPA_NEIGH_CLIENT_IP_ADDR_DEL_EVENT;
-
-						data_all = (ipacm_event_data_all *)malloc(sizeof(ipacm_event_data_all));
-						if (data_all == NULL)
 						{
-							IPACMERR("Unable to allocate memory\n");
-							return;
-						}
-						memcpy(data_all, data, sizeof(ipacm_event_data_all));
-						evt_data.evt_data = (void *)data_all;
-						IPACM_EvtDispatcher::PostEvt(&evt_data);
-						IPACMDBG_H("Posted event %d with %s for ipv4\n",
-										evt_data.event,
-										IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].iface_name);
+							evt_data.event = IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT;
 						/* Also save to cache for ipv4 */
 						/*searh if seen this client or not*/
 						for (i = 0; i < num_neighbor_client_temp; i++)
@@ -236,7 +261,8 @@
 								/* cache the network interface client associated */
 								neighbor_client[num_neighbor_client_temp].ipa_if_num = ipa_interface_index;
 								neighbor_client[num_neighbor_client_temp].v4_addr = data->ipv4_addr;
-								IPACMDBG_H("Cache wlan-iface client MAC %02x:%02x:%02x:%02x:%02x:%02x\n, total client: %d\n",
+									num_neighbor_client++;
+									IPACMDBG_H("Cache client MAC %02x:%02x:%02x:%02x:%02x:%02x\n, total client: %d\n",
 												neighbor_client[num_neighbor_client_temp].mac_addr[0],
 												neighbor_client[num_neighbor_client_temp].mac_addr[1],
 												neighbor_client[num_neighbor_client_temp].mac_addr[2],
@@ -244,16 +270,86 @@
 												neighbor_client[num_neighbor_client_temp].mac_addr[4],
 												neighbor_client[num_neighbor_client_temp].mac_addr[5],
 												num_neighbor_client);
-								num_neighbor_client++;
 								return;
 							}
 							else
 							{
-								IPACMERR("error:  neighbor client oversize!");
+									IPACMERR("error:  neighbor client oversize! recycle %d-st entry ! \n", circular_index);
+									memcpy(neighbor_client[circular_index].mac_addr,
+												data->mac_addr,
+												sizeof(data->mac_addr));
+									neighbor_client[circular_index].iface_index = data->if_index;
+									/* cache the network interface client associated */
+									neighbor_client[circular_index].ipa_if_num = ipa_interface_index;
+									neighbor_client[circular_index].v4_addr = 0;
+									IPACMDBG_H("Copy wlan-iface client MAC %02x:%02x:%02x:%02x:%02x:%02x\n, total client: %d, circular %d\n",
+													neighbor_client[circular_index].mac_addr[0],
+													neighbor_client[circular_index].mac_addr[1],
+													neighbor_client[circular_index].mac_addr[2],
+													neighbor_client[circular_index].mac_addr[3],
+													neighbor_client[circular_index].mac_addr[4],
+													neighbor_client[circular_index].mac_addr[5],
+													num_neighbor_client,
+													circular_index);
+									circular_index++;
 								return;
 							}
 						}
 					}
+						else
+						{
+							evt_data.event = IPA_NEIGH_CLIENT_IP_ADDR_DEL_EVENT;
+							/*searh if seen this client or not*/
+							for (i = 0; i < num_neighbor_client_temp; i++)
+							{
+								/* find the client */
+								if (memcmp(neighbor_client[i].mac_addr, data->mac_addr, sizeof(neighbor_client[i].mac_addr)) == 0)
+								{
+									IPACMDBG_H("Clean %d-st Cached client-MAC %02x:%02x:%02x:%02x:%02x:%02x\n, total client: %d\n",
+												i,
+												neighbor_client[i].mac_addr[0],
+												neighbor_client[i].mac_addr[1],
+												neighbor_client[i].mac_addr[2],
+												neighbor_client[i].mac_addr[3],
+												neighbor_client[i].mac_addr[4],
+												neighbor_client[i].mac_addr[5],
+												num_neighbor_client);
+
+									memset(neighbor_client[i].mac_addr, 0, sizeof(neighbor_client[i].mac_addr));
+									neighbor_client[i].iface_index = 0;
+									neighbor_client[i].v4_addr = 0;
+									neighbor_client[i].ipa_if_num = 0;
+									for (; i < num_neighbor_client_temp - 1; i++)
+									{
+										memcpy(neighbor_client[i].mac_addr,
+													neighbor_client[i+1].mac_addr,
+													sizeof(neighbor_client[i].mac_addr));
+										neighbor_client[i].iface_index = neighbor_client[i+1].iface_index;
+										neighbor_client[i].v4_addr = neighbor_client[i+1].v4_addr;
+										neighbor_client[i].ipa_if_num = neighbor_client[i+1].ipa_if_num;
+									}
+									num_neighbor_client--;
+									IPACMDBG_H(" total number of left cased clients: %d\n", num_neighbor_client);
+									break;
+								}
+							}
+							/* not find client, no need clean-up */
+						}
+
+						data_all = (ipacm_event_data_all *)malloc(sizeof(ipacm_event_data_all));
+						if (data_all == NULL)
+						{
+							IPACMERR("Unable to allocate memory\n");
+							return;
+						}
+						memcpy(data_all, data, sizeof(ipacm_event_data_all));
+						evt_data.evt_data = (void *)data_all;
+						IPACM_EvtDispatcher::PostEvt(&evt_data);
+						IPACMDBG_H("Posted event %d with %s for ipv4\n",
+										evt_data.event,
+										IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].iface_name);
+
+					}
 				}
 			}
 			else
@@ -315,13 +411,22 @@
 				}
 				else
 				{
-					IPACMDBG(" Got New_Neighbor event with no ipv6/ipv4 address \n");
+					IPACMDBG(" Got Neighbor event with no ipv6/ipv4 address \n");
 					/*no ipv6 in data searh if seen this client or not*/
 					for (i = 0; i < num_neighbor_client_temp; i++)
 					{
 						/* find the client */
 						if (memcmp(neighbor_client[i].mac_addr, data->mac_addr, sizeof(neighbor_client[i].mac_addr)) == 0)
 						{
+							IPACMDBG_H(" find %d-st client, MAC %02x:%02x:%02x:%02x:%02x:%02x\n, total client: %d\n",
+												i,
+												neighbor_client[i].mac_addr[0],
+												neighbor_client[i].mac_addr[1],
+												neighbor_client[i].mac_addr[2],
+												neighbor_client[i].mac_addr[3],
+												neighbor_client[i].mac_addr[4],
+												neighbor_client[i].mac_addr[5],
+												num_neighbor_client);
 							/* check if iface is not bridge interface*/
 							if (strcmp(IPACM_Iface::ipacmcfg->ipa_virtual_iface_name, IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].iface_name) != 0)
 							{
@@ -340,7 +445,12 @@
 
 								if (neighbor_client[i].v4_addr != 0) /* not 0.0.0.0 */
 								{
+//									evt_data.event = IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT;
+									/* construct IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT command and insert to command-queue */
+									if (event == IPA_NEW_NEIGH_EVENT)
 									evt_data.event = IPA_NEIGH_CLIENT_IP_ADDR_ADD_EVENT;
+									else
+										evt_data.event = IPA_NEIGH_CLIENT_IP_ADDR_DEL_EVENT;
 									data_all = (ipacm_event_data_all *)malloc(sizeof(ipacm_event_data_all));
 									if (data_all == NULL)
 									{
@@ -362,11 +472,40 @@
 													IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].iface_name);
 								}
 							}
+							/* delete cache neighbor entry */
+							if (event == IPA_DEL_NEIGH_EVENT)
+							{
+								IPACMDBG_H("Clean %d-st Cached client-MAC %02x:%02x:%02x:%02x:%02x:%02x\n, total client: %d\n",
+										i,
+										neighbor_client[i].mac_addr[0],
+										neighbor_client[i].mac_addr[1],
+										neighbor_client[i].mac_addr[2],
+										neighbor_client[i].mac_addr[3],
+										neighbor_client[i].mac_addr[4],
+										neighbor_client[i].mac_addr[5],
+										num_neighbor_client);
+
+								memset(neighbor_client[i].mac_addr, 0, sizeof(neighbor_client[i].mac_addr));
+								neighbor_client[i].iface_index = 0;
+								neighbor_client[i].v4_addr = 0;
+								neighbor_client[i].ipa_if_num = 0;
+								for (; i < num_neighbor_client_temp - 1; i++)
+								{
+									memcpy(neighbor_client[i].mac_addr,
+												neighbor_client[i+1].mac_addr,
+												sizeof(neighbor_client[i].mac_addr));
+									neighbor_client[i].iface_index = neighbor_client[i+1].iface_index;
+									neighbor_client[i].v4_addr = neighbor_client[i+1].v4_addr;
+									neighbor_client[i].ipa_if_num = neighbor_client[i+1].ipa_if_num;
+								}
+								num_neighbor_client--;
+								IPACMDBG_H(" total number of left cased clients: %d\n", num_neighbor_client);
+							}
 							break;
 						}
 					}
 					/* not find client */
-					if (i == num_neighbor_client_temp)
+					if ((i == num_neighbor_client_temp) && (event == IPA_NEW_NEIGH_EVENT))
 					{
 						/* check if iface is not bridge interface*/
 						if (strcmp(IPACM_Iface::ipacmcfg->ipa_virtual_iface_name, IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].iface_name) != 0)
@@ -380,7 +519,8 @@
 								/* cache the network interface client associated */
 								neighbor_client[num_neighbor_client_temp].ipa_if_num = ipa_interface_index;
 								neighbor_client[num_neighbor_client_temp].v4_addr = 0;
-								IPACMDBG_H("Copy wlan-iface client MAC %02x:%02x:%02x:%02x:%02x:%02x\n, total client: %d\n",
+								num_neighbor_client++;
+								IPACMDBG_H("Copy client MAC %02x:%02x:%02x:%02x:%02x:%02x\n, total client: %d\n",
 												neighbor_client[num_neighbor_client_temp].mac_addr[0],
 												neighbor_client[num_neighbor_client_temp].mac_addr[1],
 												neighbor_client[num_neighbor_client_temp].mac_addr[2],
@@ -388,12 +528,28 @@
 												neighbor_client[num_neighbor_client_temp].mac_addr[4],
 												neighbor_client[num_neighbor_client_temp].mac_addr[5],
 												num_neighbor_client);
-								num_neighbor_client++;
 								return;
 							}
 							else
 							{
-								IPACMERR("error:  neighbor client oversize!");
+								IPACMERR("error:  neighbor client oversize! recycle %d-st entry ! \n", circular_index);
+								memcpy(neighbor_client[circular_index].mac_addr,
+											data->mac_addr,
+											sizeof(data->mac_addr));
+								neighbor_client[circular_index].iface_index = data->if_index;
+								/* cache the network interface client associated */
+								neighbor_client[circular_index].ipa_if_num = ipa_interface_index;
+								neighbor_client[circular_index].v4_addr = 0;
+								IPACMDBG_H("Copy wlan-iface client MAC %02x:%02x:%02x:%02x:%02x:%02x\n, total client: %d, circular %d\n",
+												neighbor_client[circular_index].mac_addr[0],
+												neighbor_client[circular_index].mac_addr[1],
+												neighbor_client[circular_index].mac_addr[2],
+												neighbor_client[circular_index].mac_addr[3],
+												neighbor_client[circular_index].mac_addr[4],
+												neighbor_client[circular_index].mac_addr[5],
+												num_neighbor_client,
+												circular_index);
+								circular_index++;
 								return;
 							}
 						}
diff --git a/ipanat/src/Android.mk b/ipanat/src/Android.mk
index a97b6ce..ea14920 100644
--- a/ipanat/src/Android.mk
+++ b/ipanat/src/Android.mk
@@ -1,3 +1,6 @@
+BOARD_PLATFORM_LIST := msm8916
+BOARD_PLATFORM_LIST += msm8909
+ifneq ($(call is-board-platform-in-list,$(BOARD_PLATFORM_LIST)),true)
 ifneq (,$(filter $(QCOM_BOARD_PLATFORMS),$(TARGET_BOARD_PLATFORM)))
 ifneq (, $(filter aarch64 arm arm64, $(TARGET_ARCH)))
 
@@ -22,3 +25,4 @@
 
 endif # $(TARGET_ARCH)
 endif
+endif
\ No newline at end of file
diff --git a/ipanat/test/Android.mk b/ipanat/test/Android.mk
index c5336e4..4c94b56 100644
--- a/ipanat/test/Android.mk
+++ b/ipanat/test/Android.mk
@@ -1,3 +1,6 @@
+BOARD_PLATFORM_LIST := msm8916
+BOARD_PLATFORM_LIST += msm8909
+ifneq ($(call is-board-platform-in-list,$(BOARD_PLATFORM_LIST)),true)
 ifneq (,$(filter $(QCOM_BOARD_PLATFORMS),$(TARGET_BOARD_PLATFORM)))
 ifneq (, $(filter aarch64 arm arm64, $(TARGET_ARCH)))
 
@@ -47,3 +50,4 @@
 
 endif # $(TARGET_ARCH)
 endif
+endif
\ No newline at end of file