Merge "IPACM: Fix the nat iface missing when cfg change"
diff --git a/ipacm/src/IPACM_Lan.cpp b/ipacm/src/IPACM_Lan.cpp
index 1d65a9f..6f5f2ad 100644
--- a/ipacm/src/IPACM_Lan.cpp
+++ b/ipacm/src/IPACM_Lan.cpp
@@ -1660,7 +1660,7 @@
 
 								snprintf(index,sizeof(index), "%d", ipa_if_num);
 								strlcpy(pHeaderDescriptor->hdr[0].name, index, sizeof(pHeaderDescriptor->hdr[0].name));
-
+								pHeaderDescriptor->hdr[0].name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 								if (strlcat(pHeaderDescriptor->hdr[0].name, IPA_ETH_HDR_NAME_v4, sizeof(pHeaderDescriptor->hdr[0].name)) > IPA_RESOURCE_NAME_MAX)
 								{
 									IPACMERR(" header name construction failed exceed length (%d)\n", strlen(pHeaderDescriptor->hdr[0].name));
@@ -1751,7 +1751,7 @@
 
 				snprintf(index,sizeof(index), "%d", ipa_if_num);
 				strlcpy(pHeaderDescriptor->hdr[0].name, index, sizeof(pHeaderDescriptor->hdr[0].name));
-
+				pHeaderDescriptor->hdr[0].name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 				if (strlcat(pHeaderDescriptor->hdr[0].name, IPA_ETH_HDR_NAME_v6, sizeof(pHeaderDescriptor->hdr[0].name)) > IPA_RESOURCE_NAME_MAX)
 				{
 					IPACMERR(" header name construction failed exceed length (%d)\n", strlen(pHeaderDescriptor->hdr[0].name));
@@ -1996,11 +1996,10 @@
                 IPACMDBG_H("client(%d): v4 header handle:(0x%x)\n",
 		  				 eth_index,
 		  				 get_client_memptr(eth_client, eth_index)->hdr_hdl_v4);
-				strncpy(rt_rule->rt_tbl_name,
+				strlcpy(rt_rule->rt_tbl_name,
 								IPACM_Iface::ipacmcfg->rt_tbl_lan_v4.name,
 								sizeof(rt_rule->rt_tbl_name));
-
-
+				rt_rule->rt_tbl_name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 			    rt_rule_entry->rule.dst = tx_prop->tx[tx_index].dst_pipe;
 			    memcpy(&rt_rule_entry->rule.attrib,
 						 &tx_prop->tx[tx_index].attrib,
@@ -2032,10 +2031,10 @@
 		  	    			 get_client_memptr(eth_client, eth_index)->hdr_hdl_v6);
 
 		            /* v6 LAN_RT_TBL */
-			    	strncpy(rt_rule->rt_tbl_name,
+				strlcpy(rt_rule->rt_tbl_name,
 			    					IPACM_Iface::ipacmcfg->rt_tbl_v6.name,
 			    					sizeof(rt_rule->rt_tbl_name));
-
+				rt_rule->rt_tbl_name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 		            /* Support QCMAP LAN traffic feature, send to A5 */
 					rt_rule_entry->rule.dst = IPA_CLIENT_APPS_LAN_CONS;
 			        memset(&rt_rule_entry->rule.attrib, 0, sizeof(rt_rule_entry->rule.attrib));
@@ -2062,8 +2061,8 @@
 		            				 get_client_memptr(eth_client, eth_index)->eth_rt_hdl[tx_index].eth_rt_rule_hdl_v6[v6_num], iptype);
 
 			        /*Copy same rule to v6 WAN RT TBL*/
-				strncpy(rt_rule->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_wan_v6.name, sizeof(rt_rule->rt_tbl_name));
-
+				strlcpy(rt_rule->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_wan_v6.name, sizeof(rt_rule->rt_tbl_name));
+				rt_rule->rt_tbl_name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 				/* Downlink traffic from Wan iface, directly through IPA */
 					rt_rule_entry->rule.dst = tx_prop->tx[tx_index].dst_pipe;
 			        memcpy(&rt_rule_entry->rule.attrib,
@@ -3902,7 +3901,7 @@
 
 				memset(pHeader->hdr[0].name, 0, sizeof(pHeader->hdr[0].name));
 				strlcpy(pHeader->hdr[0].name, IPA_LAN_TO_LAN_USB_HDR_NAME_V4, sizeof(pHeader->hdr[0].name));
-
+				pHeader->hdr[0].name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 				for(j=0; j<MAX_OFFLOAD_PAIR; j++)
 				{
 					if( lan2lan_hdr_hdl_v4[j].valid == false)
@@ -3989,7 +3988,7 @@
 
 				memset(pHeader->hdr[0].name, 0, sizeof(pHeader->hdr[0].name));
 				strlcpy(pHeader->hdr[0].name, IPA_LAN_TO_LAN_USB_HDR_NAME_V6, sizeof(pHeader->hdr[0].name));
-
+				pHeader->hdr[0].name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 				for(j=0; j<MAX_OFFLOAD_PAIR; j++)
 				{
 					if( lan2lan_hdr_hdl_v6[j].valid == false)
@@ -6141,25 +6140,25 @@
 	{
 		if (iptype == IPA_IP_v4)
 		{
-			strncpy(rt_rule_table->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_eth_bridge_lan_lan_v4.name, sizeof(rt_rule_table->rt_tbl_name));
+			strlcpy(rt_rule_table->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_eth_bridge_lan_lan_v4.name, sizeof(rt_rule_table->rt_tbl_name));
 		}
 		else
 		{
-			strncpy(rt_rule_table->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_eth_bridge_lan_lan_v6.name, sizeof(rt_rule_table->rt_tbl_name));
+			strlcpy(rt_rule_table->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_eth_bridge_lan_lan_v6.name, sizeof(rt_rule_table->rt_tbl_name));
 		}
 	}
 	else
 	{
 		if (iptype == IPA_IP_v4)
 		{
-			strncpy(rt_rule_table->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_eth_bridge_lan_wlan_v4.name, sizeof(rt_rule_table->rt_tbl_name));
+			strlcpy(rt_rule_table->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_eth_bridge_lan_wlan_v4.name, sizeof(rt_rule_table->rt_tbl_name));
 		}
 		else
 		{
-			strncpy(rt_rule_table->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_eth_bridge_lan_wlan_v6.name, sizeof(rt_rule_table->rt_tbl_name));
+			strlcpy(rt_rule_table->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_eth_bridge_lan_wlan_v6.name, sizeof(rt_rule_table->rt_tbl_name));
 		}
 	}
-
+	rt_rule_table->rt_tbl_name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 	memset(&rt_rule, 0, sizeof(ipa_rt_rule_add));
 	rt_rule.at_rear = false;
 	rt_rule.status = -1;
diff --git a/ipacm/src/IPACM_Neighbor.cpp b/ipacm/src/IPACM_Neighbor.cpp
index 93bec04..270ed7b 100644
--- a/ipacm/src/IPACM_Neighbor.cpp
+++ b/ipacm/src/IPACM_Neighbor.cpp
@@ -161,7 +161,7 @@
 			{
 				if (data->ipv4_addr != 0) /* not 0.0.0.0 */
 				{
-					IPACMDBG(" Got 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)
 					{
@@ -222,7 +222,7 @@
 												evt_data.event,
 												IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].iface_name);
 								break;
-							};
+							}
 						}
 					}
 					else
@@ -231,36 +231,36 @@
 						if (event == IPA_NEW_NEIGH_EVENT)
 						{
 							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++)
-						{
-							/* find the client */
-							if (memcmp(neighbor_client[i].mac_addr, data->mac_addr, sizeof(neighbor_client[i].mac_addr)) == 0)
+							/* Also save to cache for ipv4 */
+							/*searh if seen this client or not*/
+							for (i = 0; i < num_neighbor_client_temp; i++)
 							{
-								/* update the network interface client associated */
-								neighbor_client[i].iface_index = data->if_index;
-								neighbor_client[i].ipa_if_num = ipa_interface_index;
-								neighbor_client[i].v4_addr = data->ipv4_addr; // cache client's previous ipv4 address
-								IPACMDBG_H("update cache %d-entry, with %s iface, ipv4 address: 0x%x\n",
-												i,
-												IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].iface_name,
-												data->ipv4_addr);
-								break;
+								/* find the client */
+								if (memcmp(neighbor_client[i].mac_addr, data->mac_addr, sizeof(neighbor_client[i].mac_addr)) == 0)
+								{
+									/* update the network interface client associated */
+									neighbor_client[i].iface_index = data->if_index;
+									neighbor_client[i].ipa_if_num = ipa_interface_index;
+									neighbor_client[i].v4_addr = data->ipv4_addr; // cache client's previous ipv4 address
+									IPACMDBG_H("update cache %d-entry, with %s iface, ipv4 address: 0x%x\n",
+													i,
+													IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].iface_name,
+													data->ipv4_addr);
+									break;
+								}
 							}
-						}
-						/* not find client */
-						if (i == num_neighbor_client_temp)
-						{
-							if (num_neighbor_client_temp < IPA_MAX_NUM_NEIGHBOR_CLIENTS)
+							/* not find client */
+							if (i == num_neighbor_client_temp)
 							{
-								memcpy(neighbor_client[num_neighbor_client_temp].mac_addr,
-											data->mac_addr,
-											sizeof(data->mac_addr));
-								neighbor_client[num_neighbor_client_temp].iface_index = data->if_index;
-								/* 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;
+								if (num_neighbor_client_temp < IPA_MAX_NUM_NEIGHBOR_CLIENTS)
+								{
+									memcpy(neighbor_client[num_neighbor_client_temp].mac_addr,
+												data->mac_addr,
+												sizeof(data->mac_addr));
+									neighbor_client[num_neighbor_client_temp].iface_index = data->if_index;
+									/* 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;
 									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],
@@ -270,10 +270,10 @@
 												neighbor_client[num_neighbor_client_temp].mac_addr[4],
 												neighbor_client[num_neighbor_client_temp].mac_addr[5],
 												num_neighbor_client);
-								return;
-							}
-							else
-							{
+								}
+								else
+								{
+
 									IPACMERR("error:  neighbor client oversize! recycle %d-st entry ! \n", circular_index);
 									memcpy(neighbor_client[circular_index].mac_addr,
 												data->mac_addr,
@@ -292,10 +292,9 @@
 													num_neighbor_client,
 													circular_index);
 									circular_index++;
-								return;
+								}
 							}
 						}
-					}
 						else
 						{
 							evt_data.event = IPA_NEIGH_CLIENT_IP_ADDR_DEL_EVENT;
@@ -346,9 +345,8 @@
 						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,
+									IPACM_Iface::ipacmcfg->iface_table[ipa_interface_index].iface_name);
 					}
 				}
 			}
@@ -445,10 +443,9 @@
 
 								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;
+										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));
diff --git a/ipacm/src/IPACM_Wan.cpp b/ipacm/src/IPACM_Wan.cpp
index 0de5b6c..0aec857 100644
--- a/ipacm/src/IPACM_Wan.cpp
+++ b/ipacm/src/IPACM_Wan.cpp
@@ -230,7 +230,8 @@
 	    rt_rule_entry = &rt_rule->rules[0];
 		if(m_is_sta_mode == Q6_WAN)
 		{
-			strncpy(hdr.name, tx_prop->tx[0].hdr_name, sizeof(hdr.name));
+			strlcpy(hdr.name, tx_prop->tx[0].hdr_name, sizeof(hdr.name));
+			hdr.name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 			if(m_header.GetHeaderHandle(&hdr) == false)
 			{
 				IPACMERR("Failed to get QMAP header.\n");
@@ -415,7 +416,8 @@
 		rt_rule_entry = &rt_rule->rules[0];
 		if(m_is_sta_mode == Q6_WAN)
 		{
-			strncpy(hdr.name, tx_prop->tx[0].hdr_name, sizeof(hdr.name));
+			strlcpy(hdr.name, tx_prop->tx[0].hdr_name, sizeof(hdr.name));
+			hdr.name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 			if(m_header.GetHeaderHandle(&hdr) == false)
 			{
 				IPACMERR("Failed to get QMAP header.\n");
@@ -1353,7 +1355,8 @@
 		if(m_is_sta_mode == Q6_WAN)
 		{
 			memset(&hdr, 0, sizeof(hdr));
-			strncpy(hdr.name, tx_prop->tx[0].hdr_name, sizeof(hdr.name));
+			strlcpy(hdr.name, tx_prop->tx[0].hdr_name, sizeof(hdr.name));
+			hdr.name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 			if(m_header.GetHeaderHandle(&hdr) == false)
 			{
 				IPACMERR("Failed to get QMAP header.\n");
@@ -1609,7 +1612,7 @@
 
 	/* default firewall is disable and the rule action is drop */
 	memset(&firewall_config, 0, sizeof(firewall_config));
-	strncpy(firewall_config.firewall_config_file, "/etc/mobileap_firewall.xml", sizeof(firewall_config.firewall_config_file));
+	strlcpy(firewall_config.firewall_config_file, "/etc/mobileap_firewall.xml", sizeof(firewall_config.firewall_config_file));
 
 	if (firewall_config.firewall_config_file)
 	{
@@ -2319,7 +2322,7 @@
 
 	/* default firewall is disable and the rule action is drop */
 	memset(&firewall_config, 0, sizeof(firewall_config));
-	strncpy(firewall_config.firewall_config_file, "/etc/mobileap_firewall.xml", sizeof(firewall_config.firewall_config_file));
+	strlcpy(firewall_config.firewall_config_file, "/etc/mobileap_firewall.xml", sizeof(firewall_config.firewall_config_file));
 
 	if (firewall_config.firewall_config_file)
 	{
@@ -2357,7 +2360,8 @@
 
 		memset(&rt_tbl_idx, 0, sizeof(rt_tbl_idx));
 		rt_tbl_idx.ip = IPA_IP_v6;
-		strncpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_dl.name, IPA_RESOURCE_NAME_MAX);
+		strlcpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_dl.name, IPA_RESOURCE_NAME_MAX);
+		rt_tbl_idx.name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 		if(0 != ioctl(m_fd_ipa, IPA_IOC_QUERY_RT_TBL_INDEX, &rt_tbl_idx))
 		{
 			IPACMERR("Failed to get routing table index from name\n");
@@ -2424,13 +2428,13 @@
 					rt_tbl_idx.ip = iptype;
 					if(flt_rule_entry.rule.action == IPA_PASS_TO_ROUTING)
 					{
-						strncpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_dl.name, IPA_RESOURCE_NAME_MAX);
+						strlcpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_dl.name, IPA_RESOURCE_NAME_MAX);
 					}
 					else /*pass to dst nat*/
 					{
-						strncpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_lan_v4.name, IPA_RESOURCE_NAME_MAX);
+						strlcpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_lan_v4.name, IPA_RESOURCE_NAME_MAX);
 					}
-
+					rt_tbl_idx.name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 					if(0 != ioctl(m_fd_ipa, IPA_IOC_QUERY_RT_TBL_INDEX, &rt_tbl_idx))
 					{
 						IPACMERR("Failed to get routing table index from name\n");
@@ -2560,12 +2564,13 @@
 
 		if(flt_rule_entry.rule.action == IPA_PASS_TO_ROUTING)
 		{
-			strncpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_dl.name, IPA_RESOURCE_NAME_MAX);
+			strlcpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_dl.name, IPA_RESOURCE_NAME_MAX);
 		}
 		else /*pass to dst nat*/
 		{
-			strncpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_lan_v4.name, IPA_RESOURCE_NAME_MAX);
+			strlcpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_lan_v4.name, IPA_RESOURCE_NAME_MAX);
 		}
+		rt_tbl_idx.name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 
 		if(0 != ioctl(m_fd_ipa, IPA_IOC_QUERY_RT_TBL_INDEX, &rt_tbl_idx))
 		{
@@ -2633,12 +2638,14 @@
 					/* matched rules for v6 go PASS_TO_ROUTE */
 					if(firewall_config.rule_action_accept == true)
 					{
-						strncpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_v6.name, IPA_RESOURCE_NAME_MAX);
+						strlcpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_v6.name, IPA_RESOURCE_NAME_MAX);
 					}
 					else
 					{
-						strncpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_dl.name, IPA_RESOURCE_NAME_MAX);
+						strlcpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_dl.name, IPA_RESOURCE_NAME_MAX);
 					}
+					rt_tbl_idx.name[IPA_RESOURCE_NAME_MAX-1] = '\0';
+
 					if(0 != ioctl(m_fd_ipa, IPA_IOC_QUERY_RT_TBL_INDEX, &rt_tbl_idx))
 					{
 						IPACMERR("Failed to get routing table index from name\n");
@@ -2744,17 +2751,18 @@
 			/* default action for v6 is PASS_TO_ROUTE unless user set to exception*/
 			if(firewall_config.rule_action_accept == true)
 			{
-				strncpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_dl.name, IPA_RESOURCE_NAME_MAX);
+				strlcpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_dl.name, IPA_RESOURCE_NAME_MAX);
 			}
 			else
 			{
-				strncpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_v6.name, IPA_RESOURCE_NAME_MAX);
+				strlcpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_v6.name, IPA_RESOURCE_NAME_MAX);
 			}
 		}
 		else
 		{
-			strncpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_v6.name, IPA_RESOURCE_NAME_MAX);
+			strlcpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_v6.name, IPA_RESOURCE_NAME_MAX);
 		}
+		rt_tbl_idx.name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 		if(0 != ioctl(m_fd_ipa, IPA_IOC_QUERY_RT_TBL_INDEX, &rt_tbl_idx))
 		{
 			IPACMERR("Failed to get routing table index from name\n");
@@ -2901,7 +2909,8 @@
 		original_num_rules = IPACM_Wan::num_v4_flt_rule;
 
 		memset(&rt_tbl_idx, 0, sizeof(rt_tbl_idx));
-		strncpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_dl.name, IPA_RESOURCE_NAME_MAX);
+		strlcpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_dl.name, IPA_RESOURCE_NAME_MAX);
+		rt_tbl_idx.name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 		rt_tbl_idx.ip = iptype;
 		if(0 != ioctl(m_fd_ipa, IPA_IOC_QUERY_RT_TBL_INDEX, &rt_tbl_idx))
 		{
@@ -3017,7 +3026,8 @@
 		original_num_rules = IPACM_Wan::num_v6_flt_rule;
 
 		memset(&rt_tbl_idx, 0, sizeof(rt_tbl_idx));
-		strncpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_dl.name, IPA_RESOURCE_NAME_MAX);
+		strlcpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_dl.name, IPA_RESOURCE_NAME_MAX);
+		rt_tbl_idx.name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 		rt_tbl_idx.ip = iptype;
 		if(0 != ioctl(m_fd_ipa, IPA_IOC_QUERY_RT_TBL_INDEX, &rt_tbl_idx))
 		{
@@ -3206,7 +3216,8 @@
 	if (iptype == IPA_IP_v4)
 	{
 		memset(&rt_tbl_idx, 0, sizeof(rt_tbl_idx));
-		strncpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_dl.name, IPA_RESOURCE_NAME_MAX);
+		strlcpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_dl.name, IPA_RESOURCE_NAME_MAX);
+		rt_tbl_idx.name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 		rt_tbl_idx.ip = iptype;
 		if(0 != ioctl(m_fd_ipa, IPA_IOC_QUERY_RT_TBL_INDEX, &rt_tbl_idx))
 		{
@@ -3285,7 +3296,8 @@
 	else	/*insert rules for ipv6*/
 	{
 		memset(&rt_tbl_idx, 0, sizeof(rt_tbl_idx));
-		strncpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_dl.name, IPA_RESOURCE_NAME_MAX);
+		strlcpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_dl.name, IPA_RESOURCE_NAME_MAX);
+		rt_tbl_idx.name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 		rt_tbl_idx.ip = iptype;
 		if(0 != ioctl(m_fd_ipa, IPA_IOC_QUERY_RT_TBL_INDEX, &rt_tbl_idx))
 		{
@@ -3845,7 +3857,8 @@
 
 	/* get eMBMS ODU tbl index*/
 	memset(&rt_tbl_idx, 0, sizeof(rt_tbl_idx));
-	strncpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_odu_v4.name, IPA_RESOURCE_NAME_MAX);
+	strlcpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_odu_v4.name, IPA_RESOURCE_NAME_MAX);
+	rt_tbl_idx.name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 	rt_tbl_idx.ip = IPA_IP_v4;
 	if(0 != ioctl(m_fd_ipa, IPA_IOC_QUERY_RT_TBL_INDEX, &rt_tbl_idx))
 	{
@@ -3890,7 +3903,8 @@
 	memset(&flt_rule_entry, 0, sizeof(struct ipa_flt_rule_add));
 	/* get eMBMS ODU tbl*/
 	memset(&rt_tbl_idx, 0, sizeof(rt_tbl_idx));
-	strncpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_odu_v6.name, IPA_RESOURCE_NAME_MAX);
+	strlcpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_odu_v6.name, IPA_RESOURCE_NAME_MAX);
+	rt_tbl_idx.name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 	rt_tbl_idx.ip = IPA_IP_v6;
 	if(0 != ioctl(m_fd_ipa, IPA_IOC_QUERY_RT_TBL_INDEX, &rt_tbl_idx))
 	{
@@ -4405,7 +4419,8 @@
 		/* Configuring Software-Routing Filtering Rule */
 		memset(&flt_rule_entry, 0, sizeof(struct ipa_flt_rule_add));
 		memset(&rt_tbl_idx, 0, sizeof(rt_tbl_idx));
-		strncpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_dl.name, IPA_RESOURCE_NAME_MAX);
+		strlcpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_dl.name, IPA_RESOURCE_NAME_MAX);
+		rt_tbl_idx.name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 		rt_tbl_idx.ip = IPA_IP_v4;
 		if(ioctl(m_fd_ipa, IPA_IOC_QUERY_RT_TBL_INDEX, &rt_tbl_idx) < 0)
 		{
@@ -4462,7 +4477,8 @@
 		/* Configuring Software-Routing Filtering Rule */
 		memset(&flt_rule_entry, 0, sizeof(struct ipa_flt_rule_add));
 		memset(&rt_tbl_idx, 0, sizeof(rt_tbl_idx));
-		strncpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_dl.name, IPA_RESOURCE_NAME_MAX);
+		strlcpy(rt_tbl_idx.name, IPACM_Iface::ipacmcfg->rt_tbl_wan_dl.name, IPA_RESOURCE_NAME_MAX);
+		rt_tbl_idx.name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 		rt_tbl_idx.ip = IPA_IP_v6;
 		if(ioctl(m_fd_ipa, IPA_IOC_QUERY_RT_TBL_INDEX, &rt_tbl_idx) < 0)
 		{
@@ -4785,7 +4801,7 @@
 
 								snprintf(index,sizeof(index), "%d", ipa_if_num);
 								strlcpy(pHeaderDescriptor->hdr[0].name, index, sizeof(pHeaderDescriptor->hdr[0].name));
-
+								pHeaderDescriptor->hdr[0].name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 								if (strlcat(pHeaderDescriptor->hdr[0].name, IPA_WAN_PARTIAL_HDR_NAME_v4, sizeof(pHeaderDescriptor->hdr[0].name)) > IPA_RESOURCE_NAME_MAX)
 								{
 									IPACMERR(" header name construction failed exceed length (%d)\n", strlen(pHeaderDescriptor->hdr[0].name));
@@ -4882,7 +4898,7 @@
 
 				snprintf(index,sizeof(index), "%d", ipa_if_num);
 				strlcpy(pHeaderDescriptor->hdr[0].name, index, sizeof(pHeaderDescriptor->hdr[0].name));
-
+				pHeaderDescriptor->hdr[0].name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 				if (strlcat(pHeaderDescriptor->hdr[0].name, IPA_WAN_PARTIAL_HDR_NAME_v6, sizeof(pHeaderDescriptor->hdr[0].name)) > IPA_RESOURCE_NAME_MAX)
 				{
 					IPACMERR(" header name construction failed exceed length (%d)\n", strlen(pHeaderDescriptor->hdr[0].name));
@@ -5128,10 +5144,10 @@
 				IPACMDBG_H("client(%d): v4 header handle:(0x%x)\n",
 						wan_index,
 						get_client_memptr(wan_client, wan_index)->hdr_hdl_v4);
-				strncpy(rt_rule->rt_tbl_name,
+				strlcpy(rt_rule->rt_tbl_name,
 						IPACM_Iface::ipacmcfg->rt_tbl_wan_v4.name,
 						sizeof(rt_rule->rt_tbl_name));
-
+				rt_rule->rt_tbl_name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 				if (IPACM_Iface::ipacmcfg->isMCC_Mode == true)
 				{
 					IPACMDBG_H("In MCC mode, use alt dst pipe: %d\n",
@@ -5171,10 +5187,10 @@
 							get_client_memptr(wan_client, wan_index)->hdr_hdl_v6);
 
 					/* v6 LAN_RT_TBL */
-					strncpy(rt_rule->rt_tbl_name,
+					strlcpy(rt_rule->rt_tbl_name,
 							IPACM_Iface::ipacmcfg->rt_tbl_v6.name,
 							sizeof(rt_rule->rt_tbl_name));
-
+					rt_rule->rt_tbl_name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 					/* Support QCMAP LAN traffic feature, send to A5 */
 					rt_rule_entry->rule.dst = iface_query->excp_pipe;
 					memset(&rt_rule_entry->rule.attrib, 0, sizeof(rt_rule_entry->rule.attrib));
@@ -5201,10 +5217,10 @@
 							get_client_memptr(wan_client, wan_index)->wan_rt_hdl[tx_index].wan_rt_rule_hdl_v6[v6_num], iptype);
 
 					/*Copy same rule to v6 WAN RT TBL*/
-					strncpy(rt_rule->rt_tbl_name,
+					strlcpy(rt_rule->rt_tbl_name,
 							IPACM_Iface::ipacmcfg->rt_tbl_wan_v6.name,
 							sizeof(rt_rule->rt_tbl_name));
-
+					rt_rule->rt_tbl_name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 					/* Downlink traffic from Wan iface, directly through IPA */
 					if (IPACM_Iface::ipacmcfg->isMCC_Mode == true)
 					{
diff --git a/ipacm/src/IPACM_Wlan.cpp b/ipacm/src/IPACM_Wlan.cpp
index 7de85a2..f51c0c3 100644
--- a/ipacm/src/IPACM_Wlan.cpp
+++ b/ipacm/src/IPACM_Wlan.cpp
@@ -1670,6 +1670,7 @@
 
 				snprintf(index,sizeof(index), "%d", ipa_if_num);
 				strlcpy(pHeaderDescriptor->hdr[0].name, index, sizeof(pHeaderDescriptor->hdr[0].name));
+				pHeaderDescriptor->hdr[0].name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 
 				if (strlcat(pHeaderDescriptor->hdr[0].name, IPA_WLAN_PARTIAL_HDR_NAME_v4, sizeof(pHeaderDescriptor->hdr[0].name)) > IPA_RESOURCE_NAME_MAX)
 				{
@@ -1775,6 +1776,7 @@
 
 				snprintf(index,sizeof(index), "%d", ipa_if_num);
 				strlcpy(pHeaderDescriptor->hdr[0].name, index, sizeof(pHeaderDescriptor->hdr[0].name));
+				pHeaderDescriptor->hdr[0].name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 				if (strlcat(pHeaderDescriptor->hdr[0].name, IPA_WLAN_PARTIAL_HDR_NAME_v6, sizeof(pHeaderDescriptor->hdr[0].name)) > IPA_RESOURCE_NAME_MAX)
 				{
 					IPACMERR(" header name construction failed exceed length (%d)\n", strlen(pHeaderDescriptor->hdr[0].name));
@@ -2026,10 +2028,10 @@
 				IPACMDBG_H("client(%d): v4 header handle:(0x%x)\n",
 						wlan_index,
 						get_client_memptr(wlan_client, wlan_index)->hdr_hdl_v4);
-				strncpy(rt_rule->rt_tbl_name,
+				strlcpy(rt_rule->rt_tbl_name,
 						IPACM_Iface::ipacmcfg->rt_tbl_lan_v4.name,
 						sizeof(rt_rule->rt_tbl_name));
-
+				rt_rule->rt_tbl_name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 
 				if(IPACM_Iface::ipacmcfg->isMCC_Mode)
 				{
@@ -2072,10 +2074,10 @@
 							get_client_memptr(wlan_client, wlan_index)->hdr_hdl_v6);
 
 					/* v6 LAN_RT_TBL */
-					strncpy(rt_rule->rt_tbl_name,
+					strlcpy(rt_rule->rt_tbl_name,
 							IPACM_Iface::ipacmcfg->rt_tbl_v6.name,
 							sizeof(rt_rule->rt_tbl_name));
-
+					rt_rule->rt_tbl_name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 					/* Support QCMAP LAN traffic feature, send to A5 */
 					rt_rule_entry->rule.dst = iface_query->excp_pipe;
 					memset(&rt_rule_entry->rule.attrib, 0, sizeof(rt_rule_entry->rule.attrib));
@@ -2102,10 +2104,10 @@
 							get_client_memptr(wlan_client, wlan_index)->wifi_rt_hdl[tx_index].wifi_rt_rule_hdl_v6[v6_num], iptype);
 
 					/*Copy same rule to v6 WAN RT TBL*/
-					strncpy(rt_rule->rt_tbl_name,
+					strlcpy(rt_rule->rt_tbl_name,
 							IPACM_Iface::ipacmcfg->rt_tbl_wan_v6.name,
 							sizeof(rt_rule->rt_tbl_name));
-
+					rt_rule->rt_tbl_name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 					/* Downlink traffic from Wan iface, directly through IPA */
 					if(IPACM_Iface::ipacmcfg->isMCC_Mode)
 					{
@@ -2351,10 +2353,9 @@
 	/* Delete v4 filtering rules */
 	if (ip_type != IPA_IP_v6 && rx_prop != NULL)
 	{
-#ifdef FEATURE_ETH_BRIDGE_LE
+		/* delete IPv4 icmp filter rules */
 		if(wlan_ap_index == 0)
 		{
-			/* delete IPv4 icmp filter rules */
 			if(m_filtering.DeleteFilteringHdls(ipv4_icmp_flt_rule_hdl, IPA_IP_v4, NUM_IPV4_ICMP_FLT_RULE) == false)
 			{
 				IPACMERR("Error Deleting ICMPv4 Filtering Rule, aborting...\n");
@@ -2362,6 +2363,10 @@
 				goto fail;
 			}
 			IPACM_Iface::ipacmcfg->decreaseFltRuleCount(rx_prop->rx[0].src_pipe, IPA_IP_v4, NUM_IPV4_ICMP_FLT_RULE);
+		}
+#ifdef FEATURE_ETH_BRIDGE_LE
+		if(wlan_ap_index == 0)
+		{
 			/* delete default filter rules */
 			for(i=0; i<IPV4_DEFAULT_FILTERTING_RULES; i++)
 			{
@@ -2922,7 +2927,7 @@
 
 				memset(pHeader->hdr[0].name, 0, sizeof(pHeader->hdr[0].name));
 				strlcpy(pHeader->hdr[0].name, IPA_LAN_TO_LAN_WLAN_HDR_NAME_V4, sizeof(pHeader->hdr[0].name));
-
+				pHeader->hdr[0].name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 				for(j=0; j<MAX_OFFLOAD_PAIR; j++)
 				{
 					if( lan2lan_hdr_hdl_v4[j].valid == false)
@@ -3039,7 +3044,7 @@
 
 				memset(pHeader->hdr[0].name, 0, sizeof(pHeader->hdr[0].name));
 				strlcpy(pHeader->hdr[0].name, IPA_LAN_TO_LAN_WLAN_HDR_NAME_V6, sizeof(pHeader->hdr[0].name));
-
+				pHeader->hdr[0].name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 
 				for(j=0; j<MAX_OFFLOAD_PAIR; j++)
 				{
@@ -4281,25 +4286,25 @@
 	{
 		if(iptype == IPA_IP_v4)
 		{
-			strncpy(rt_rule_table->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_eth_bridge_wlan_wlan_v4.name, sizeof(rt_rule_table->rt_tbl_name));
+			strlcpy(rt_rule_table->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_eth_bridge_wlan_wlan_v4.name, sizeof(rt_rule_table->rt_tbl_name));
 		}
 		else
 		{
-			strncpy(rt_rule_table->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_eth_bridge_wlan_wlan_v6.name, sizeof(rt_rule_table->rt_tbl_name));
+			strlcpy(rt_rule_table->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_eth_bridge_wlan_wlan_v6.name, sizeof(rt_rule_table->rt_tbl_name));
 		}
 	}
 	else
 	{
 		if(iptype == IPA_IP_v4)
 		{
-			strncpy(rt_rule_table->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_eth_bridge_lan_wlan_v4.name, sizeof(rt_rule_table->rt_tbl_name));
+			strlcpy(rt_rule_table->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_eth_bridge_lan_wlan_v4.name, sizeof(rt_rule_table->rt_tbl_name));
 		}
 		else
 		{
-			strncpy(rt_rule_table->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_eth_bridge_lan_wlan_v6.name, sizeof(rt_rule_table->rt_tbl_name));
+			strlcpy(rt_rule_table->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_eth_bridge_lan_wlan_v6.name, sizeof(rt_rule_table->rt_tbl_name));
 		}
 	}
-
+	rt_rule_table->rt_tbl_name[IPA_RESOURCE_NAME_MAX-1] = '\0';
 	memset(&rt_rule, 0, sizeof(ipa_rt_rule_add));
 	rt_rule.at_rear = false;
 	rt_rule.status = -1;