Merge "IPACM: Remove meta data equation for Ethernet bridging"
diff --git a/ipacm/src/IPACM_ConntrackListener.cpp b/ipacm/src/IPACM_ConntrackListener.cpp
index 3a2041a..e00f921 100644
--- a/ipacm/src/IPACM_ConntrackListener.cpp
+++ b/ipacm/src/IPACM_ConntrackListener.cpp
@@ -316,86 +316,101 @@
 
 int IPACM_ConntrackListener::CreateConnTrackThreads(void)
 {
-	 int ret;
-	 pthread_t tcp_thread = 0, udp_thread = 0;
+	int ret;
+	pthread_t tcp_thread = 0, udp_thread = 0;
 
-	 if(isCTReg == false)
-	 {
-
-			if(!tcp_thread)
+	if(isCTReg == false)
+	{
+		if(!tcp_thread)
+		{
+			ret = pthread_create(&tcp_thread, NULL, IPACM_ConntrackClient::TCPRegisterWithConnTrack, NULL);
+			if(0 != ret)
 			{
-				 ret = pthread_create(&tcp_thread, NULL, IPACM_ConntrackClient::TCPRegisterWithConnTrack, NULL);
-				 if(0 != ret)
-				 {
-						IPACMERR("unable to create TCP conntrack event listner thread\n");
-						PERROR("unable to create TCP conntrack\n");
-						return -1;
-				 }
-
-				 IPACMDBG("created TCP conntrack event listner thread\n");
+				IPACMERR("unable to create TCP conntrack event listner thread\n");
+				PERROR("unable to create TCP conntrack\n");
+				return -1;
 			}
 
-			if(!udp_thread)
+			IPACMDBG("created TCP conntrack event listner thread\n");
+			if(pthread_setname_np(tcp_thread, "tcp ct listener") != 0)
 			{
-				 ret = pthread_create(&udp_thread, NULL, IPACM_ConntrackClient::UDPRegisterWithConnTrack, NULL);
-				 if(0 != ret)
-				 {
-						IPACMERR("unable to create UDP conntrack event listner thread\n");
-						PERROR("unable to create UDP conntrack\n");
-						goto error;
-				 }
+				IPACMERR("unable to set thread name\n");
+			}
+		}
 
-				 IPACMDBG("created UDP conntrack event listner thread\n");
+		if(!udp_thread)
+		{
+			ret = pthread_create(&udp_thread, NULL, IPACM_ConntrackClient::UDPRegisterWithConnTrack, NULL);
+			if(0 != ret)
+			{
+				IPACMERR("unable to create UDP conntrack event listner thread\n");
+				PERROR("unable to create UDP conntrack\n");
+				goto error;
 			}
 
-			isCTReg = true;
-	 }
+			IPACMDBG("created UDP conntrack event listner thread\n");
+			if(pthread_setname_np(udp_thread, "udp ct listener") != 0)
+			{
+				IPACMERR("unable to set thread name\n");
+			}
+		}
 
-	 return 0;
+		isCTReg = true;
+	}
+
+	return 0;
 
 error:
-	 return -1;
+	return -1;
 }
 int IPACM_ConntrackListener::CreateNatThreads(void)
 {
-	 int ret;
-	 pthread_t udpcto_thread = 0, to_monitor_thread = 0;
+	int ret;
+	pthread_t udpcto_thread = 0, to_monitor_thread = 0;
 
-	 if(isNatThreadStart == false)
-	 {
+	if(isNatThreadStart == false)
+	{
 
-			if(!udpcto_thread)
+		if(!udpcto_thread)
+		{
+			ret = pthread_create(&udpcto_thread, NULL, IPACM_ConntrackClient::UDPConnTimeoutUpdate, NULL);
+			if(0 != ret)
 			{
-				 ret = pthread_create(&udpcto_thread, NULL, IPACM_ConntrackClient::UDPConnTimeoutUpdate, NULL);
-				 if(0 != ret)
-				 {
-						IPACMERR("unable to create udp conn timeout thread\n");
-						PERROR("unable to create udp conn timeout\n");
-						goto error;
-				 }
-
-				 IPACMDBG("created upd conn timeout thread\n");
+				IPACMERR("unable to create udp conn timeout thread\n");
+				PERROR("unable to create udp conn timeout\n");
+				goto error;
 			}
 
-			if(!to_monitor_thread)
+			IPACMDBG("created upd conn timeout thread\n");
+			if(pthread_setname_np(udpcto_thread, "udp conn timeout") != 0)
 			{
-				ret = pthread_create(&to_monitor_thread, NULL, IPACM_ConntrackClient::TCPUDP_Timeout_monitor, NULL);
-				 if(0 != ret)
-				 {
-						IPACMERR("unable to create tcp/udp timeout monitor thread\n");
-						PERROR("unable to create tcp/udp timeout monitor\n");
-						goto error;
-				 }
+				IPACMERR("unable to set thread name\n");
+			}
+		}
 
-				 IPACMDBG("created tcp/udp timeout monitor thread\n");
+		if(!to_monitor_thread)
+		{
+			ret = pthread_create(&to_monitor_thread, NULL, IPACM_ConntrackClient::TCPUDP_Timeout_monitor, NULL);
+			if(0 != ret)
+			{
+				IPACMERR("unable to create tcp/udp timeout monitor thread\n");
+				PERROR("unable to create tcp/udp timeout monitor\n");
+				goto error;
 			}
 
-			isNatThreadStart = true;
-	 }
-	 return 0;
+			IPACMDBG("created tcp/udp timeout monitor thread\n");
+			if(pthread_setname_np(to_monitor_thread, "tcp udp timeout mtr") != 0)
+			{
+				IPACMERR("unable to set thread name\n");
+			}
+		}
+
+		isNatThreadStart = true;
+	}
+	return 0;
 
 error:
-	 return -1;
+	return -1;
 }
 
 void IPACM_ConntrackListener::TriggerWANDown(uint32_t wan_addr)
diff --git a/ipacm/src/IPACM_Main.cpp b/ipacm/src/IPACM_Main.cpp
index 06d9f41..0aef584 100644
--- a/ipacm/src/IPACM_Main.cpp
+++ b/ipacm/src/IPACM_Main.cpp
@@ -713,6 +713,10 @@
 			return ret;
 		}
 		IPACMDBG_H("created command queue thread\n");
+		if(pthread_setname_np(cmd_queue_thread, "cmd queue process") != 0)
+		{
+			IPACMERR("unable to set thread name\n");
+		}
 	}
 
 	if (IPACM_SUCCESS == netlink_thread)
@@ -724,6 +728,10 @@
 			return ret;
 		}
 		IPACMDBG_H("created netlink thread\n");
+		if(pthread_setname_np(netlink_thread, "netlink socket") != 0)
+		{
+			IPACMERR("unable to set thread name\n");
+		}
 	}
 
 
@@ -736,6 +744,10 @@
 			return ret;
 		}
 		IPACMDBG_H("created firewall monitor thread\n");
+		if(pthread_setname_np(monitor_thread, "firewall cfg process") != 0)
+		{
+			IPACMERR("unable to set thread name\n");
+		}
 	}
 
 	if (IPACM_SUCCESS == ipa_driver_thread)
@@ -747,6 +759,10 @@
 			return ret;
 		}
 		IPACMDBG_H("created ipa_driver_wlan thread\n");
+		if(pthread_setname_np(ipa_driver_thread, "ipa driver ntfy") != 0)
+		{
+			IPACMERR("unable to set thread name\n");
+		}
 	}
 
 	pthread_join(cmd_queue_thread, NULL);
diff --git a/ipacm/src/IPACM_Wan.cpp b/ipacm/src/IPACM_Wan.cpp
index 81e365a..86587bd 100644
--- a/ipacm/src/IPACM_Wan.cpp
+++ b/ipacm/src/IPACM_Wan.cpp
@@ -230,7 +230,14 @@
 			rt_rule_entry->rule.hdr_hdl = hdr.hdl;
 		}
 	    rt_rule_entry->at_rear = false;
-	    rt_rule_entry->rule.dst = iface_query->excp_pipe;  //go to A5
+		if(m_is_sta_mode == Q6_WAN)
+		{
+			rt_rule_entry->rule.dst = IPA_CLIENT_APPS_WAN_CONS;
+		}
+		else
+		{
+			rt_rule_entry->rule.dst = IPA_CLIENT_APPS_LAN_CONS;
+		}
 	    rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
 	    	rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = data->ipv6_addr[0];
 	    	rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = data->ipv6_addr[1];
@@ -383,9 +390,13 @@
 				return IPACM_FAILURE;
 			}
 			rt_rule_entry->rule.hdr_hdl = hdr.hdl;
+			rt_rule_entry->rule.dst = IPA_CLIENT_APPS_WAN_CONS;
+		}
+		else
+		{
+			rt_rule_entry->rule.dst = IPA_CLIENT_APPS_LAN_CONS;
 		}
 		rt_rule_entry->at_rear = false;
-		rt_rule_entry->rule.dst = iface_query->excp_pipe;  //go to A5
 		rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
 		/* still need setup v4 default routing rule to A5*/
 		strcpy(rt_rule->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_lan_v4.name);
@@ -958,7 +969,7 @@
 {
 
 	/* add default WAN route */
-	struct ipa_ioc_add_rt_rule *rt_rule;
+	struct ipa_ioc_add_rt_rule *rt_rule = NULL;
 	struct ipa_rt_rule_add *rt_rule_entry;
 	struct ipa_ioc_get_hdr sRetHeader;
 	uint32_t cnt, tx_index = 0;
@@ -1190,7 +1201,14 @@
     strcpy(rt_rule->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_wan_v6.name);
     memset(rt_rule_entry, 0, sizeof(struct ipa_rt_rule_add));
 	rt_rule_entry->at_rear = true;
-    rt_rule_entry->rule.dst = iface_query->excp_pipe;  //go to A5
+	if(m_is_sta_mode == Q6_WAN)
+	{
+		rt_rule_entry->rule.dst = IPA_CLIENT_APPS_WAN_CONS;
+	}
+	else
+	{
+		rt_rule_entry->rule.dst = IPA_CLIENT_APPS_LAN_CONS;
+	}
     rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
 	rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0;
 	rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0;
@@ -1219,6 +1237,7 @@
 	if (wanup_data == NULL)
 	{
 		IPACMERR("Unable to allocate memory\n");
+		free(rt_rule);
 		return IPACM_FAILURE;
 	}
 	memset(wanup_data, 0, sizeof(ipacm_event_iface_up));
@@ -1295,6 +1314,10 @@
 	IPACMDBG_H("depend Got pipe %d rm index : %d \n", tx_prop->tx[0].dst_pipe, IPACM_Iface::ipacmcfg->ipa_client_rm_map_tbl[tx_prop->tx[0].dst_pipe]);
 	IPACM_Iface::ipacmcfg->AddRmDepend(IPACM_Iface::ipacmcfg->ipa_client_rm_map_tbl[tx_prop->tx[0].dst_pipe],false);
 
+	if(rt_rule != NULL)
+	{
+		free(rt_rule);
+	}
 	return IPACM_SUCCESS;
 }
 
@@ -4225,7 +4248,8 @@
 		if(0 != ioctl(m_fd_ipa, IPA_IOC_GENERATE_FLT_EQ, &flt_eq))
 		{
 			IPACMERR("Failed to get eq_attrib\n");
-			return IPACM_FAILURE;
+			res = IPACM_FAILURE;
+			goto fail;
 		}
 		memcpy(&flt_rule_entry.rule.eq_attrib,
 			&flt_eq.eq_attrib,
@@ -4257,8 +4281,8 @@
 		if(ioctl(m_fd_ipa, IPA_IOC_QUERY_RT_TBL_INDEX, &rt_tbl_idx) < 0)
 		{
 			IPACMERR("Failed to get routing table index from name\n");
-			free(pFilteringTable_v4);
-			return IPACM_FAILURE;
+			res = IPACM_FAILURE;
+			goto fail;
 		}
 		IPACMDBG_H("Routing table %s has index %d\n", rt_tbl_idx.name, rt_tbl_idx.idx);
 
@@ -4280,7 +4304,8 @@
 		if(0 != ioctl(m_fd_ipa, IPA_IOC_GENERATE_FLT_EQ, &flt_eq))
 		{
 			IPACMERR("Failed to get eq_attrib\n");
-			return IPACM_FAILURE;
+			res = IPACM_FAILURE;
+			goto fail;
 		}
 		memcpy(&flt_rule_entry.rule.eq_attrib,
 			&flt_eq.eq_attrib,
diff --git a/ipanat/src/ipa_nat_drvi.c b/ipanat/src/ipa_nat_drvi.c
index 74161a7..32114b5 100644
--- a/ipanat/src/ipa_nat_drvi.c
+++ b/ipanat/src/ipa_nat_drvi.c
@@ -665,6 +665,9 @@
 		return -EINVAL;
 	}
 
+	/* Reset the nat table before posting init cmd */
+	ipa_nati_reset_tbl(tbl_indx);
+
 	/* Initialize the ipa hw with nat table dimensions */
 	ret = ipa_nati_post_ipv4_init_cmd(tbl_indx);
 	if (0 != ret) {
@@ -672,8 +675,6 @@
 		return -EINVAL;
 	}
 
-	ipa_nati_reset_tbl(tbl_indx);
-
 	/* Return table handle */
 	ipv4_nat_cache.table_cnt++;
 	*tbl_hdl = ipv4_nat_cache.table_cnt;