From 54395808339868877f5d401a46ed8885fbbe74a1 Mon Sep 17 00:00:00 2001 From: He Chunhui Date: Wed, 16 Mar 2016 07:43:38 +0000 Subject: [PATCH 1/3] fix incompatible unit in LWIP_NAT_TMR_INTERVAL_SEC LWIP_NAT_TMR_INTERVAL_SEC defined in ipv4_nat.h is in miliseconds, but ip_nat_check_timeout() thinks it's in seconds. With this bug, all nat entries will expire immediately when ip_nat_check_timeout() is called. Note sys_timeout() is in miliseconds. --- components/net/lwip_nat/ipv4_nat.c | 4 ++-- components/net/lwip_nat/ipv4_nat.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/net/lwip_nat/ipv4_nat.c b/components/net/lwip_nat/ipv4_nat.c index 13c1877f2c..6f218fc1e1 100644 --- a/components/net/lwip_nat/ipv4_nat.c +++ b/components/net/lwip_nat/ipv4_nat.c @@ -229,7 +229,7 @@ nat_timer(void *arg) LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: nat_timer()\n")); ip_nat_tmr(); - sys_timeout(LWIP_NAT_TMR_INTERVAL_SEC, nat_timer, NULL); + sys_timeout(LWIP_NAT_TMR_INTERVAL_SEC * 1000, nat_timer, NULL); } /** Initialize this module */ @@ -255,7 +255,7 @@ ip_nat_init(void) rt_enter_critical(); /* add a lwip timer for NAT */ - sys_timeout(LWIP_NAT_TMR_INTERVAL_SEC, nat_timer, NULL); + sys_timeout(LWIP_NAT_TMR_INTERVAL_SEC * 1000, nat_timer, NULL); /* un-protect */ rt_exit_critical(); diff --git a/components/net/lwip_nat/ipv4_nat.h b/components/net/lwip_nat/ipv4_nat.h index e369c781da..b30ed98428 100644 --- a/components/net/lwip_nat/ipv4_nat.h +++ b/components/net/lwip_nat/ipv4_nat.h @@ -67,7 +67,7 @@ #include "lwip/opt.h" /** Timer interval at which to call ip_nat_tmr() */ -#define LWIP_NAT_TMR_INTERVAL_SEC (30*1000) +#define LWIP_NAT_TMR_INTERVAL_SEC (30) #ifdef __cplusplus extern "C" { From 0fc0ed1bb1880014eb81073d3810c88a5e6acd92 Mon Sep 17 00:00:00 2001 From: He Chunhui Date: Wed, 16 Mar 2016 08:00:33 +0000 Subject: [PATCH 2/3] fix copy-paste bug This bug causes buffer overrun. --- components/net/lwip_nat/ipv4_nat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/net/lwip_nat/ipv4_nat.c b/components/net/lwip_nat/ipv4_nat.c index 6f218fc1e1..a49a246129 100644 --- a/components/net/lwip_nat/ipv4_nat.c +++ b/components/net/lwip_nat/ipv4_nat.c @@ -370,12 +370,12 @@ ip_nat_reset_state(ip_nat_conf_t *cfg) } } for (i = 0; i < LWIP_NAT_DEFAULT_STATE_TABLES_TCP; i++) { - if(ip_nat_icmp_table[i].common.cfg == cfg) { + if(ip_nat_tcp_table[i].common.cfg == cfg) { IPNAT_ENTRY_RESET(&ip_nat_tcp_table[i].common); } } for (i = 0; i < LWIP_NAT_DEFAULT_STATE_TABLES_UDP; i++) { - if(ip_nat_icmp_table[i].common.cfg == cfg) { + if(ip_nat_udp_table[i].common.cfg == cfg) { IPNAT_ENTRY_RESET(&ip_nat_udp_table[i].common); } } From 7290ff5d760060da34efa4820249deb365d33c00 Mon Sep 17 00:00:00 2001 From: He Chunhui Date: Wed, 16 Mar 2016 08:03:33 +0000 Subject: [PATCH 3/3] fix typo --- components/net/lwip_nat/ipv4_nat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/net/lwip_nat/ipv4_nat.c b/components/net/lwip_nat/ipv4_nat.c index a49a246129..bf8c934976 100644 --- a/components/net/lwip_nat/ipv4_nat.c +++ b/components/net/lwip_nat/ipv4_nat.c @@ -622,7 +622,7 @@ ip_nat_tmr(void) } } -/** Vheck if we want to perform NAT with this packet. If so, send it out on +/** Check if we want to perform NAT with this packet. If so, send it out on * the correct interface. * * @param p the packet to test/send