Merge "IPACM: Fix the nat timeout update issue"
diff --git a/ipacm/inc/IPACM_ConntrackClient.h b/ipacm/inc/IPACM_ConntrackClient.h
index 58c6316..a6076cf 100644
--- a/ipacm/inc/IPACM_ConntrackClient.h
+++ b/ipacm/inc/IPACM_ConntrackClient.h
@@ -59,17 +59,6 @@
 #define UDP_TIMEOUT_UPDATE 20
 #define BROADCAST_IPV4_ADDR 0xFFFFFFFF
 
-
-#define IPACM_TCP_UDP_DIR_NAME       "/proc/sys/net/ipv4/netfilter"
-#define IPACM_TCP_FILE_NAME  "ip_conntrack_tcp_timeout_established"
-#define IPACM_UDP_FILE_NAME   "ip_conntrack_udp_timeout_stream"
-
-#define IPACM_TCP_FULL_FILE_NAME  "/proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_timeout_established"
-#define IPACM_UDP_FULL_FILE_NAME   "/proc/sys/net/ipv4/netfilter/ip_conntrack_udp_timeout_stream"
-
-#define INOTIFY_EVT_SIZE  (sizeof(struct inotify_event))
-#define INOTIFY_BUFFER_LEN     (INOTIFY_EVT_SIZE + 2*sizeof(IPACM_TCP_FILE_NAME))
-
 class IPACM_ConntrackClient
 {
 
@@ -95,7 +84,6 @@
    static void* TCPRegisterWithConnTrack(void *);
    static void* UDPRegisterWithConnTrack(void *);
    static void* UDPConnTimeoutUpdate(void *);
-   static void* TCPUDP_Timeout_monitor(void *);
 
    static void UpdateUDPFilters(void *, bool);
    static void UpdateTCPFilters(void *, bool);
diff --git a/ipacm/inc/IPACM_Conntrack_NATApp.h b/ipacm/inc/IPACM_Conntrack_NATApp.h
index 836241a..e6c27af 100644
--- a/ipacm/inc/IPACM_Conntrack_NATApp.h
+++ b/ipacm/inc/IPACM_Conntrack_NATApp.h
@@ -44,6 +44,9 @@
 
 #define MAX_TEMP_ENTRIES 25
 
+#define IPACM_TCP_FULL_FILE_NAME  "/proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_timeout_established"
+#define IPACM_UDP_FULL_FILE_NAME   "/proc/sys/net/ipv4/netfilter/ip_conntrack_udp_timeout_stream"
+
 typedef struct _nat_table_entry
 {
 	uint32_t private_ip;
@@ -117,7 +120,7 @@
 	int DelEntriesOnClntDiscon(uint32_t);
 	int DelEntriesOnSTAClntDiscon(uint32_t);
 
-	void UpdateTcpUdpTo(uint32_t, int proto);
+	void Read_TcpUdp_Timeout(void);
 
 	void AddTempEntry(const nat_table_entry *);
 	void CacheEntry(const nat_table_entry *);
diff --git a/ipacm/src/IPACM_ConntrackClient.cpp b/ipacm/src/IPACM_ConntrackClient.cpp
index 9de5911..2a670c8 100644
--- a/ipacm/src/IPACM_ConntrackClient.cpp
+++ b/ipacm/src/IPACM_ConntrackClient.cpp
@@ -445,7 +445,7 @@
 	}
 
 	/* Register callback with netfilter handler */
-	IPACMDBG("tcp handle:%p, fd:%d\n", pClient->tcp_hdl, nfct_fd(pClient->tcp_hdl));
+	IPACMDBG_H("tcp handle:%p, fd:%d\n", pClient->tcp_hdl, nfct_fd(pClient->tcp_hdl));
 #ifndef CT_OPT
 	nfct_callback_register(pClient->tcp_hdl,
 			(nf_conntrack_msg_type)	(NFCT_T_UPDATE | NFCT_T_DESTROY | NFCT_T_NEW),
@@ -476,7 +476,7 @@
 	nfct_callback_unregister(pClient->tcp_hdl);
 	/* close the handle */
 	nfct_close(pClient->tcp_hdl);
-  pClient->tcp_hdl = NULL;
+	pClient->tcp_hdl = NULL;
 
 	pthread_exit(NULL);
 	return NULL;
@@ -522,7 +522,7 @@
 	}
 
 	/* Register callback with netfilter handler */
-	IPACMDBG("udp handle:%p, fd:%d\n", pClient->udp_hdl, nfct_fd(pClient->udp_hdl));
+	IPACMDBG_H("udp handle:%p, fd:%d\n", pClient->udp_hdl, nfct_fd(pClient->udp_hdl));
 	nfct_callback_register(pClient->udp_hdl,
 												 (nf_conntrack_msg_type)(NFCT_T_NEW | NFCT_T_DESTROY),
 												 IPAConntrackEventCB,
@@ -650,140 +650,3 @@
   return;
 }
 
-void IPACM_ConntrackClient::Read_TcpUdp_Timeout(char *in, int len)
-{
-	int proto;
-	FILE *fd = NULL;
-	char to_str[10];
-	uint32_t value;
-	NatApp *nat_inst = NULL;
-
-	nat_inst = NatApp::GetInstance();
-	if(nat_inst == NULL)
-	{
-		IPACMERR("unable to create nat instance\n");
-		return;
-	}
-
-	if(!strncmp(in, IPACM_TCP_FILE_NAME, len))
-	{
-		proto = IPPROTO_TCP;
-	}
-	else if(!strncmp(in, IPACM_UDP_FILE_NAME, len))
-	{
-		proto = IPPROTO_UDP;
-	}
-	else
-	{
-		return;
-	}
-
-	if(proto == IPPROTO_TCP)
-	{
-		fd = fopen(IPACM_TCP_FULL_FILE_NAME, "r");
-	}
-	else
-	{
-		fd = fopen(IPACM_UDP_FULL_FILE_NAME, "r");
-	}
-	if(fd == NULL)
-	{
-		PERROR("unable to open file");
-		return;
-	}
-
-	fgets(to_str, sizeof(to_str), fd);
-	value = atoi(to_str);
-	IPACMDBG("Protocol %d file \"%s\" value: %d\n", proto, in, value);
-	nat_inst->UpdateTcpUdpTo(value, proto);
-
-	fclose(fd);
-	return;
-}
-
-void *IPACM_ConntrackClient::TCPUDP_Timeout_monitor(void *)
-{
-  int length;
-	int wd;
-	char buffer[INOTIFY_BUFFER_LEN];
-	int inotify_fd;
-	uint32_t mask = IN_MODIFY;
-	FILE *to_fd = NULL;
-	char to_str[10];
-	uint32_t value=0;
-	NatApp *nat_inst = NULL;
-
-	nat_inst = NatApp::GetInstance();
-	if(nat_inst == NULL)
-	{
-		IPACMERR("unable to create nat instance\n");
-		return NULL;
-	}
-
-	to_fd = fopen(IPACM_TCP_FULL_FILE_NAME, "r");
-	if(to_fd == NULL)
-	{
-	  PERROR("unable to open file \"ip_conntrack_tcp_timeout_established\" ");
-		return NULL;
-	}
-	memset(to_str, 0, sizeof(to_str));
-	fgets(to_str, sizeof(to_str), to_fd);
-	value = atoi(to_str);
-	IPACMDBG("ip conntrack tcp timeout initial value:%d\n", value);
-	nat_inst->UpdateTcpUdpTo(value, IPPROTO_TCP);
-	fclose(to_fd);
-
-	to_fd = fopen(IPACM_UDP_FULL_FILE_NAME, "r");
-	if(to_fd == NULL)
-	{
-	  PERROR("unable to open file \"ip_conntrack_udp_timeout_stream\" ");
-		return NULL;
-	}
-	memset(to_str, 0, sizeof(to_str));
-	fgets(to_str, sizeof(to_str), to_fd);
-	value = atoi(to_str);
-	IPACMDBG("ip conntrack udp timeout:%d\n", value);
-	nat_inst->UpdateTcpUdpTo(value, IPPROTO_UDP);
-	fclose(to_fd);
-
-	inotify_fd = inotify_init();
-	if (inotify_fd < 0)
-	{
-		PERROR("inotify_init");
-		return NULL;
-	}
-
-	IPACMDBG("Waiting for nofications in dir %s with mask: 0x%x\n",
-					              IPACM_TCP_UDP_DIR_NAME, mask);
-
-	wd = inotify_add_watch(inotify_fd,
-												 IPACM_TCP_UDP_DIR_NAME,
-												 mask);
-
-	while (1)
-	{
-		length = read(inotify_fd, buffer, INOTIFY_BUFFER_LEN);
-		struct inotify_event *event = (struct inotify_event *)buffer;
-
-		if (length < 0)
-		{
-			IPACMERR("inotify read() error return length: %d and mask: 0x%x 0x%x\n",
-							         length, event->mask, mask);
-			return NULL;
-		}
-
-		if( (event->len > 0) && (event->mask & IN_MODIFY) )
-		{
-			if(!(event->mask & IN_ISDIR))
-			{
-				IPACMDBG("Received inotify event for file %s with mask %x value",
-								       event->name, event->mask);
-				Read_TcpUdp_Timeout(event->name, event->len);
-			}
-		}
-	}
-
-	(void)inotify_rm_watch(inotify_fd, wd);
-	(void)close(inotify_fd);
-	return NULL;
-}
diff --git a/ipacm/src/IPACM_ConntrackListener.cpp b/ipacm/src/IPACM_ConntrackListener.cpp
index 996dbfa..ab25bde 100644
--- a/ipacm/src/IPACM_ConntrackListener.cpp
+++ b/ipacm/src/IPACM_ConntrackListener.cpp
@@ -90,7 +90,7 @@
 #endif
 
 	 case IPA_HANDLE_WAN_UP:
-			IPACMDBG("Received IPA_HANDLE_WAN_UP event\n");
+			IPACMDBG_H("Received IPA_HANDLE_WAN_UP event\n");
 			CreateConnTrackThreads();
 			if(!isWanUp())
 			{
@@ -99,7 +99,7 @@
 			break;
 
 	 case IPA_HANDLE_WAN_DOWN:
-			IPACMDBG("Received IPA_HANDLE_WAN_DOWN event\n");
+			IPACMDBG_H("Received IPA_HANDLE_WAN_DOWN event\n");
 			wan_down = (ipacm_event_iface_up *)data;
 			if(isWanUp())
 			{
@@ -111,7 +111,7 @@
 		 tcp/udp filters to ignore local wlan or lan connections */
 	 case IPA_HANDLE_WLAN_UP:
 	 case IPA_HANDLE_LAN_UP:
-			IPACMDBG("Received event: %d with ifname: %s and address: 0x%x\n",
+			IPACMDBG_H("Received event: %d with ifname: %s and address: 0x%x\n",
 							 evt, ((ipacm_event_iface_up *)data)->ifname,
 							 ((ipacm_event_iface_up *)data)->ipv4_addr);
 			CreateConnTrackThreads();
@@ -136,7 +136,7 @@
 		return;
 	}
 
-  IPACMDBG("\n");
+	IPACMDBG("\n");
 	IPACMDBG("Received interface index %d with ip type: %d", data->if_index, data->iptype);
 	iptodot(" and ipv4 address", data->ipv4_addr);
 
@@ -152,28 +152,25 @@
 
 
 	cnt = pConfig->GetNatIfacesCnt();
-		NatIfaceCnt = cnt;
-		if(pNatIfaces != NULL)
-		{
-			free(pNatIfaces);
-			pNatIfaces = NULL;
-		}
+	NatIfaceCnt = cnt;
+	if (pNatIfaces != NULL) {
+		free(pNatIfaces);
+		pNatIfaces = NULL;
+	}
 
-		len = (sizeof(NatIfaces) * NatIfaceCnt);
-		pNatIfaces = (NatIfaces *)malloc(len);
-		if(pNatIfaces == NULL)
-		{
-			IPACMERR("Unable to allocate memory for non nat ifaces\n");
-			return;
-		}
-		memset(pNatIfaces, 0, len);
+	len = (sizeof(NatIfaces) * NatIfaceCnt);
+	pNatIfaces = (NatIfaces *)malloc(len);
+	if (pNatIfaces == NULL) {
+		IPACMERR("Unable to allocate memory for non nat ifaces\n");
+		return;
+	}
+	memset(pNatIfaces, 0, len);
 
-		if(pConfig->GetNatIfaces(NatIfaceCnt, pNatIfaces) != 0)
-		{
-			IPACMERR("Unable to retrieve non nat ifaces\n");
-			return;
-		}
-  IPACMDBG("Update %d Nat ifaces\n", NatIfaceCnt);
+	if (pConfig->GetNatIfaces(NatIfaceCnt, pNatIfaces) != 0) {
+		IPACMERR("Unable to retrieve non nat ifaces\n");
+		return;
+	}
+	IPACMDBG("Update %d Nat ifaces\n", NatIfaceCnt); 
 
 
 	/* Search/Configure linux interface-index and map it to IPA interface-index */
@@ -227,8 +224,10 @@
 
 
 			isNatIface = true;
-			IPACMDBG("Nating connections of Interface (%s), entry (%d) ", pNatIfaces[i].iface_name, j);
-			iptodot("with ipv4 address", nat_iface_ipv4_addr[j]);
+			IPACMDBG_H("Nating connections of Interface (%s), entry (%d) ", pNatIfaces[i].iface_name, j);
+			IPACMDBG_H(" with ipv4 address(0x%x): %d.%d.%d.%d\n", nat_iface_ipv4_addr[j],
+					    ((nat_iface_ipv4_addr[j]>>24) & 0xFF), ((nat_iface_ipv4_addr[j]>>16) & 0xFF), 
+					    ((nat_iface_ipv4_addr[j]>>8) & 0xFF), (nat_iface_ipv4_addr[j] & 0xFF));
 			break;
 		}
 	}
@@ -281,7 +280,7 @@
 	}
 
 	nat_inst->FlushTempEntries(ipv4_addr, false);
-  nat_inst->DelEntriesOnClntDiscon(ipv4_addr);
+	nat_inst->DelEntriesOnClntDiscon(ipv4_addr);
 	return;
 }
 
@@ -289,8 +288,8 @@
 {
 	 ipacm_event_iface_up *wanup_data = (ipacm_event_iface_up *)in_param;
 
-	 IPACMDBG("Recevied below information during wanup,\n");
-	 IPACMDBG("if_name:%s, ipv4_address:0x%x\n",
+	 IPACMDBG_H("Recevied below information during wanup,\n");
+	 IPACMDBG_H("if_name:%s, ipv4_address:0x%x\n",
 						wanup_data->ifname, wanup_data->ipv4_addr);
 
 	 if(wanup_data->ipv4_addr == 0)
@@ -367,11 +366,10 @@
 int IPACM_ConntrackListener::CreateNatThreads(void)
 {
 	int ret;
-	pthread_t udpcto_thread = 0, to_monitor_thread = 0;
+	pthread_t udpcto_thread = 0;
 
 	if(isNatThreadStart == false)
 	{
-
 		if(!udpcto_thread)
 		{
 			ret = pthread_create(&udpcto_thread, NULL, IPACM_ConntrackClient::UDPConnTimeoutUpdate, NULL);
@@ -389,23 +387,6 @@
 			}
 		}
 
-		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;
-			}
-
-			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;
@@ -416,8 +397,11 @@
 
 void IPACM_ConntrackListener::TriggerWANDown(uint32_t wan_addr)
 {
-	 IPACMDBG("Deleting ipv4 nat table with");
-	 iptodot("public ip address", wan_addr);
+	 IPACMDBG_H("Deleting ipv4 nat table with");
+	 IPACMDBG_H(" public ip address(0x%x): %d.%d.%d.%d\n", wan_addr,
+		    ((wan_addr>>24) & 0xFF), ((wan_addr>>16) & 0xFF), 
+		    ((wan_addr>>8) & 0xFF), (wan_addr & 0xFF));
+	 
 	 WanUp = false;
 
 	 if(nat_inst != NULL)
@@ -624,8 +608,7 @@
 	 out_flags = (NFCT_OF_SHOW_LAYER3 | NFCT_OF_TIME | NFCT_OF_ID);
 	 nfct_snprintf(buf, sizeof(buf), evt_data->ct,
 								 evt_data->type, NFCT_O_PLAIN, out_flags);
-	 IPACMDBG("%s\n", buf);
-	 IPACMDBG("\n");
+	 IPACMDBG_H("%s\n", buf);
 
 	 ParseCTMessage(evt_data->ct);
 #endif
@@ -711,7 +694,7 @@
 		}
 		else
 		{
-			IPACMDBG("Neither orig src ip:0x%x Nor orig Dst IP:0x%x equal to wan ip:0x%x\n",
+			IPACMDBG_H("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
@@ -841,7 +824,7 @@
 				 {
 					 IPACMDBG("matched nat_iface_ipv4_addr entry(%d)\n", cnt);
 					 iptodot("ProcessTCPorUDPMsg(): Nat entry match with ip addr",
-																					nat_iface_ipv4_addr[cnt]);
+									nat_iface_ipv4_addr[cnt]);
 					 break;
 				 }
 			 }
@@ -849,7 +832,7 @@
 
 		if(cnt == MAX_NAT_IFACES)
 		{
-			IPACMDBG("Not mtaching with nat ifaces\n");
+			IPACMDBG_H("Not mtaching with nat ifaces\n");
 			if(pConfig == NULL)
 			{
 				goto IGNORE;
@@ -909,13 +892,13 @@
 		}
 	 }
 
-	IPACMDBG("Not matching with STA Clnt Ip Addrs 0x%x\n",
+	IPACMDBG_H("Not matching with STA Clnt Ip Addrs 0x%x\n",
 		rule.target_ip);
 	isTempEntry = true;
 
 
 ADD:
-	 IPACMDBG("Nat Entry with below information will either be added or deleted\n");
+	 IPACMDBG_H("Nat Entry with below information will either be added or deleted\n");
 	 iptodot("target ip or dst ip", rule.target_ip);
 	 IPACMDBG("target port or dst port: 0x%x Decimal:%d\n", rule.target_port, rule.target_port);
 	 iptodot("private ip or src ip", rule.private_ip);
@@ -1003,7 +986,7 @@
 	 return;
 
 IGNORE:
-	IPACMDBG("ignoring below Nat Entry\n");
+	IPACMDBG_H("ignoring below Nat Entry\n");
 	iptodot("target ip or dst ip", rule.target_ip);
 	IPACMDBG("target port or dst port: 0x%x Decimal:%d\n", rule.target_port, rule.target_port);
 	iptodot("private ip or src ip", rule.private_ip);
@@ -1017,7 +1000,7 @@
 void IPACM_ConntrackListener::HandleSTAClientAddEvt(uint32_t clnt_ip_addr)
 {
 	 int cnt;
-	 IPACMDBG("Received STA client 0x%x\n", clnt_ip_addr);
+	 IPACMDBG_H("Received STA client 0x%x\n", clnt_ip_addr);
 
 	 if(StaClntCnt >= MAX_STA_CLNT_IFACES)
 	 {
@@ -1053,7 +1036,7 @@
 void IPACM_ConntrackListener::HandleSTAClientDelEvt(uint32_t clnt_ip_addr)
 {
 	 int cnt;
-	 IPACMDBG("Received STA client 0x%x\n", clnt_ip_addr);
+	 IPACMDBG_H("Received STA client 0x%x\n", clnt_ip_addr);
 
 	 for(cnt=0; cnt<MAX_STA_CLNT_IFACES; cnt++)
 	 {
diff --git a/ipacm/src/IPACM_Conntrack_NATApp.cpp b/ipacm/src/IPACM_Conntrack_NATApp.cpp
index 348faa9..6efb475 100644
--- a/ipacm/src/IPACM_Conntrack_NATApp.cpp
+++ b/ipacm/src/IPACM_Conntrack_NATApp.cpp
@@ -232,6 +232,7 @@
 {
 	int cnt = 0;
 	IPACMDBG("%s() %d\n", __FUNCTION__, __LINE__);
+
 	for(; cnt < max_entries; cnt++)
 	{
 		if(cache[cnt].private_ip == rule->private_ip &&
@@ -275,11 +276,11 @@
 					IPACMERR("%s() %d deletion failed\n", __FUNCTION__, __LINE__);
 				}
 
-				IPACMDBG("Deleted Nat entry(%d) Successfully\n", cnt);
+				IPACMDBG_H("Deleted Nat entry(%d) Successfully\n", cnt);
 			}
 			else
 			{
-				IPACMDBG("Deleted Nat entry(%d) only from cache\n", cnt);
+				IPACMDBG_H("Deleted Nat entry(%d) only from cache\n", cnt);
 			}
 
 			memset(&cache[cnt], 0, sizeof(cache[cnt]));
@@ -305,7 +306,7 @@
 	if(isAlgPort(rule->protocol, rule->private_port) ||
 		 isAlgPort(rule->protocol, rule->target_port))
 	{
-		IPACMERR("connection using ALG Port. Dont insert into nat table\n");
+		IPACMERR("connection using ALG Port, ignore\n");
 		return -1;
 	}
 
@@ -386,11 +387,11 @@
 
 	if(cache[cnt].enabled == true)
 	{
-		IPACMDBG("Added rule(%d) successfully\n", cnt);
+		IPACMDBG_H("Added rule(%d) successfully\n", cnt);
 	}
   else
   {
-    IPACMDBG("Cached rule(%d) successfully\n", cnt);
+    IPACMDBG_H("Cached rule(%d) successfully\n", cnt);
   }
 
 	return 0;
@@ -484,6 +485,7 @@
 {
 	int cnt;
 	uint32_t ts;
+	bool read_to = false;
 
 	for(cnt = 0; cnt < max_entries; cnt++)
 	{
@@ -504,6 +506,11 @@
 				continue;
 			}
 
+			if (read_to == false) {
+				read_to = true;
+				Read_TcpUdp_Timeout();
+			}
+
 			UpdateCTUdpTs(&cache[cnt], ts);
 		} /* end of outer if */
 
@@ -545,7 +552,7 @@
 int NatApp::UpdatePwrSaveIf(uint32_t client_lan_ip)
 {
 	int cnt;
-	IPACMDBG("Received IP address: 0x%x\n", client_lan_ip);
+	IPACMDBG_H("Received IP address: 0x%x\n", client_lan_ip);
 
 	if(client_lan_ip == INVALID_IP_ADDR)
 	{
@@ -596,7 +603,7 @@
 	int cnt;
 	ipa_nat_ipv4_rule nat_rule;
 
-	IPACMDBG("Received ip address: 0x%x\n", client_lan_ip);
+	IPACMDBG_H("Received ip address: 0x%x\n", client_lan_ip);
 
 	if(client_lan_ip == INVALID_IP_ADDR)
 	{
@@ -650,20 +657,6 @@
 	return -1;
 }
 
-void NatApp::UpdateTcpUdpTo(uint32_t new_value, int proto)
-{
-	if(proto == IPPROTO_TCP)
-	{
-		tcp_timeout = new_value;
-		IPACMDBG("new nat tcp timeout value: %d\n", tcp_timeout);
-	}
-	else if(proto == IPPROTO_UDP)
-	{
-		udp_timeout = new_value;
-		IPACMDBG("new nat udp timeout value: %d\n", udp_timeout);
-	}
-}
-
 uint32_t NatApp::GetTableHdl(uint32_t in_ip_addr)
 {
 	if(in_ip_addr == pub_ip_addr)
@@ -757,8 +750,8 @@
 	int cnt;
 	int ret;
 
-	IPACMDBG("Received below with isAdd:%d\n", isAdd);
-	iptodot("IP Address:", ip_addr);
+	IPACMDBG_H("Received below with isAdd:%d ", isAdd);
+	IPACMDBG_H("IP Address: (ox%x)\n", ip_addr);
 
 	for(cnt=0; cnt<MAX_TEMP_ENTRIES; cnt++)
 	{
@@ -787,7 +780,7 @@
 int NatApp::DelEntriesOnClntDiscon(uint32_t ip_addr)
 {
 	int cnt, tmp = 0;
-	IPACMDBG("Received IP address: 0x%x\n", ip_addr);
+	IPACMDBG_H("Received IP address: 0x%x\n", ip_addr);
 
 	if(ip_addr == INVALID_IP_ADDR)
 	{
@@ -834,7 +827,7 @@
 int NatApp::DelEntriesOnSTAClntDiscon(uint32_t ip_addr)
 {
 	int cnt, tmp = curCnt;
-	IPACMDBG("Received IP address: 0x%x\n", ip_addr);
+	IPACMDBG_H("Received IP address: 0x%x\n", ip_addr);
 
 	if(ip_addr == INVALID_IP_ADDR)
 	{
@@ -923,3 +916,43 @@
 	IPACMDBG("Cached rule(%d) successfully\n", cnt);
 	return;
 }
+
+void NatApp::Read_TcpUdp_Timeout(void) {
+	FILE *udp_fd = NULL, *tcp_fd = NULL;
+
+	/* Read UDP timeout value */
+	udp_fd = fopen(IPACM_UDP_FULL_FILE_NAME, "r");
+	if (udp_fd == NULL) {
+		IPACMERR("unable to open %s\n", IPACM_UDP_FULL_FILE_NAME);
+		goto fail;
+	}
+
+	if (fscanf(udp_fd, "%d", &udp_timeout) != 1) {
+		IPACMERR("Error reading udp timeout\n");
+	}
+	IPACMDBG_H("udp timeout value: %d\n", udp_timeout);
+
+
+	/* Read TCP timeout value */
+	tcp_fd = fopen(IPACM_TCP_FULL_FILE_NAME, "r");
+	if (tcp_fd == NULL) {
+		IPACMERR("unable to open %s\n", IPACM_TCP_FULL_FILE_NAME);
+		goto fail;
+	}
+
+
+	if (fscanf(tcp_fd, "%d", &tcp_timeout) != 1) {
+		IPACMERR("Error reading tcp timeout\n");
+	}
+	IPACMDBG_H("tcp timeout value: %d\n", tcp_timeout);
+
+fail:
+	if (udp_fd) {
+		fclose(udp_fd);
+	}
+	if (tcp_fd) {
+		fclose(tcp_fd);
+	}
+
+	return;
+}