Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Mozi
rt-thread
提交
3e31d349
R
rt-thread
项目概览
Mozi
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3e31d349
编写于
1月 31, 2015
作者:
B
bernard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[lwIP] fix the pbuf q=NULL issue in ip_nat_input.
上级
72298bac
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
21 addition
and
13 deletion
+21
-13
components/net/lwip-1.4.1/src/lwipopts.h
components/net/lwip-1.4.1/src/lwipopts.h
+2
-2
components/net/lwip_nat/ipv4_nat.c
components/net/lwip_nat/ipv4_nat.c
+19
-11
未找到文件。
components/net/lwip-1.4.1/src/lwipopts.h
浏览文件 @
3e31d349
...
@@ -162,9 +162,9 @@
...
@@ -162,9 +162,9 @@
#define SYS_LIGHTWEIGHT_PROT (NO_SYS==0)
#define SYS_LIGHTWEIGHT_PROT (NO_SYS==0)
#ifdef LWIP_USING_NAT
#ifdef LWIP_USING_NAT
#define
LWIP_NAT
1
#define
IP_NAT
1
#else
#else
#define
LWIP_NAT
0
#define
IP_NAT
0
#endif
#endif
/* ---------- TCP options ---------- */
/* ---------- TCP options ---------- */
...
...
components/net/lwip_nat/ipv4_nat.c
浏览文件 @
3e31d349
...
@@ -117,9 +117,10 @@
...
@@ -117,9 +117,10 @@
#define LWIP_NAT_TTL_INFINITE (INT_MAX)
#define LWIP_NAT_TTL_INFINITE (INT_MAX)
#define LWIP_NAT_DEFAULT_TTL_SECONDS (128)
#define LWIP_NAT_DEFAULT_TTL_SECONDS (128)
#define LWIP_NAT_FORWARD_HEADER_SIZE_MIN (sizeof(struct eth_hdr))
#define LWIP_NAT_FORWARD_HEADER_SIZE_MIN (sizeof(struct eth_hdr))
#define LWIP_NAT_DEFAULT_STATE_TABLES_ICMP (2)
#define LWIP_NAT_DEFAULT_STATE_TABLES_TCP (16)
#define LWIP_NAT_DEFAULT_STATE_TABLES_ICMP (4)
#define LWIP_NAT_DEFAULT_STATE_TABLES_UDP (16)
#define LWIP_NAT_DEFAULT_STATE_TABLES_TCP (32)
#define LWIP_NAT_DEFAULT_STATE_TABLES_UDP (32)
#define LWIP_NAT_DEFAULT_TCP_SOURCE_PORT (40000)
#define LWIP_NAT_DEFAULT_TCP_SOURCE_PORT (40000)
#define LWIP_NAT_DEFAULT_UDP_SOURCE_PORT (40000)
#define LWIP_NAT_DEFAULT_UDP_SOURCE_PORT (40000)
...
@@ -250,12 +251,12 @@ ip_nat_init(void)
...
@@ -250,12 +251,12 @@ ip_nat_init(void)
IPNAT_ENTRY_RESET
(
&
ip_nat_udp_table
[
i
].
common
);
IPNAT_ENTRY_RESET
(
&
ip_nat_udp_table
[
i
].
common
);
}
}
/* we must lock scheduler to protect following code */
/* we must lock scheduler to protect following code */
rt_enter_critical
();
rt_enter_critical
();
/* add a lwip timer for NAT */
/* add a lwip timer for NAT */
sys_timeout
(
LWIP_NAT_TMR_INTERVAL_SEC
,
nat_timer
,
NULL
);
sys_timeout
(
LWIP_NAT_TMR_INTERVAL_SEC
,
nat_timer
,
NULL
);
/* un-protect */
/* un-protect */
rt_exit_critical
();
rt_exit_critical
();
}
}
...
@@ -361,7 +362,7 @@ ip_nat_reset_state(ip_nat_conf_t *cfg)
...
@@ -361,7 +362,7 @@ ip_nat_reset_state(ip_nat_conf_t *cfg)
{
{
int
i
;
int
i
;
/* @todo: optimize this!!!
/* @todo: optimize this!!!
why do we search for it anyway, if we have the pointer??? */
why do we search for it anyway, if we have the pointer??? */
for
(
i
=
0
;
i
<
LWIP_NAT_DEFAULT_STATE_TABLES_ICMP
;
i
++
)
{
for
(
i
=
0
;
i
<
LWIP_NAT_DEFAULT_STATE_TABLES_ICMP
;
i
++
)
{
if
(
ip_nat_icmp_table
[
i
].
common
.
cfg
==
cfg
)
{
if
(
ip_nat_icmp_table
[
i
].
common
.
cfg
==
cfg
)
{
...
@@ -392,7 +393,7 @@ ip_nat_shallnat(const struct ip_hdr *iphdr)
...
@@ -392,7 +393,7 @@ ip_nat_shallnat(const struct ip_hdr *iphdr)
ip_nat_conf_t
*
nat_config
=
ip_nat_cfg
;
ip_nat_conf_t
*
nat_config
=
ip_nat_cfg
;
for
(
nat_config
=
ip_nat_cfg
;
nat_config
!=
NULL
;
nat_config
=
nat_config
->
next
)
{
for
(
nat_config
=
ip_nat_cfg
;
nat_config
!=
NULL
;
nat_config
=
nat_config
->
next
)
{
if
(
ip_addr_netcmp
(
&
(
iphdr
->
dest
),
&
(
nat_config
->
entry
.
dest_net
),
if
(
ip_addr_netcmp
(
&
(
iphdr
->
dest
),
&
(
nat_config
->
entry
.
dest_net
),
&
(
nat_config
->
entry
.
dest_netmask
))
||
&
(
nat_config
->
entry
.
dest_netmask
))
||
ip_addr_netcmp
(
&
(
iphdr
->
src
),
&
(
nat_config
->
entry
.
source_net
),
ip_addr_netcmp
(
&
(
iphdr
->
src
),
&
(
nat_config
->
entry
.
source_net
),
&
(
nat_config
->
entry
.
source_netmask
)))
{
&
(
nat_config
->
entry
.
source_netmask
)))
{
...
@@ -435,7 +436,7 @@ ip_nat_check_header(struct pbuf *p, u16_t min_size)
...
@@ -435,7 +436,7 @@ ip_nat_check_header(struct pbuf *p, u16_t min_size)
* @return 1 if the packet has been consumed (it was a NAT packet),
* @return 1 if the packet has been consumed (it was a NAT packet),
* 0 if the packet has not been consumed (no NAT packet)
* 0 if the packet has not been consumed (no NAT packet)
*/
*/
u8_t
u8_t
ip_nat_input
(
struct
pbuf
*
p
)
ip_nat_input
(
struct
pbuf
*
p
)
{
{
struct
ip_hdr
*
iphdr
=
(
struct
ip_hdr
*
)
p
->
payload
;
struct
ip_hdr
*
iphdr
=
(
struct
ip_hdr
*
)
p
->
payload
;
...
@@ -538,6 +539,7 @@ ip_nat_input(struct pbuf *p)
...
@@ -538,6 +539,7 @@ ip_nat_input(struct pbuf *p)
q
=
pbuf_alloc
(
PBUF_LINK
,
0
,
PBUF_RAM
);
q
=
pbuf_alloc
(
PBUF_LINK
,
0
,
PBUF_RAM
);
if
(
q
==
NULL
)
{
if
(
q
==
NULL
)
{
LWIP_DEBUGF
(
LWIP_NAT_DEBUG
,
(
"ip_nat_input: no pbuf for outgoing header
\n
"
));
LWIP_DEBUGF
(
LWIP_NAT_DEBUG
,
(
"ip_nat_input: no pbuf for outgoing header
\n
"
));
// rt_kprintf("ip_nat_input: no pbuf for outgoing header\n");
/* @todo: stats? */
/* @todo: stats? */
pbuf_free
(
p
);
pbuf_free
(
p
);
p
=
NULL
;
p
=
NULL
;
...
@@ -549,11 +551,13 @@ ip_nat_input(struct pbuf *p)
...
@@ -549,11 +551,13 @@ ip_nat_input(struct pbuf *p)
/* restore p->payload to IP header */
/* restore p->payload to IP header */
if
(
pbuf_header
(
p
,
-
PBUF_LINK_HLEN
))
{
if
(
pbuf_header
(
p
,
-
PBUF_LINK_HLEN
))
{
LWIP_DEBUGF
(
LWIP_NAT_DEBUG
,
(
"ip_nat_input: restoring header failed
\n
"
));
LWIP_DEBUGF
(
LWIP_NAT_DEBUG
,
(
"ip_nat_input: restoring header failed
\n
"
));
// rt_kprintf("ip_nat_input: restoring header failed\n");
/* @todo: stats? */
/* @todo: stats? */
pbuf_free
(
p
);
pbuf_free
(
p
);
p
=
NULL
;
p
=
NULL
;
return
1
;
return
1
;
}
}
else
q
=
p
;
}
}
/* if we come here, q is the pbuf to send (either points to p or to a chain) */
/* if we come here, q is the pbuf to send (either points to p or to a chain) */
in_if
=
nat_entry
.
cmn
->
cfg
->
entry
.
in_if
;
in_if
=
nat_entry
.
cmn
->
cfg
->
entry
.
in_if
;
...
@@ -572,6 +576,7 @@ ip_nat_input(struct pbuf *p)
...
@@ -572,6 +576,7 @@ ip_nat_input(struct pbuf *p)
LWIP_DEBUGF
(
LWIP_NAT_DEBUG
,
LWIP_DEBUGF
(
LWIP_NAT_DEBUG
,
(
"ip_nat_input: failed to send rewritten packet. link layer returned %d
\n
"
,
(
"ip_nat_input: failed to send rewritten packet. link layer returned %d
\n
"
,
err
));
err
));
// rt_kprintf("ip_nat_input: failed to send rewritten packet. link layer returned %d\n", err);
}
}
/* now that q (and/or p) is sent (or not), give up the reference to it
/* now that q (and/or p) is sent (or not), give up the reference to it
this frees the input pbuf (p) as we have consumed it. */
this frees the input pbuf (p) as we have consumed it. */
...
@@ -736,6 +741,7 @@ ip_nat_out(struct pbuf *p)
...
@@ -736,6 +741,7 @@ ip_nat_out(struct pbuf *p)
if
(
err
!=
ERR_OK
)
{
if
(
err
!=
ERR_OK
)
{
LWIP_DEBUGF
(
LWIP_NAT_DEBUG
,
LWIP_DEBUGF
(
LWIP_NAT_DEBUG
,
(
"ip_nat_out: failed to send rewritten packet. link layer returned %d
\n
"
,
err
));
(
"ip_nat_out: failed to send rewritten packet. link layer returned %d
\n
"
,
err
));
// rt_kprintf("ip_nat_out: failed to send rewritten packet. link layer returned %d\n", err);
}
else
{
}
else
{
sent
=
1
;
sent
=
1
;
}
}
...
@@ -842,6 +848,7 @@ ip_nat_udp_lookup_outgoing(ip_nat_conf_t *nat_config, const struct ip_hdr *iphdr
...
@@ -842,6 +848,7 @@ ip_nat_udp_lookup_outgoing(ip_nat_conf_t *nat_config, const struct ip_hdr *iphdr
nat_entry
.
udp
);
nat_entry
.
udp
);
}
else
{
}
else
{
LWIP_DEBUGF
(
LWIP_NAT_DEBUG
,
(
"ip_nat_udp_lookup_outgoing: no more NAT entries available
\n
"
));
LWIP_DEBUGF
(
LWIP_NAT_DEBUG
,
(
"ip_nat_udp_lookup_outgoing: no more NAT entries available
\n
"
));
// rt_kprintf("ip_nat_udp_lookup_outgoing: no more NAT entries available\n");
}
}
}
}
}
}
...
@@ -926,6 +933,7 @@ ip_nat_tcp_lookup_outgoing(ip_nat_conf_t *nat_config, const struct ip_hdr *iphdr
...
@@ -926,6 +933,7 @@ ip_nat_tcp_lookup_outgoing(ip_nat_conf_t *nat_config, const struct ip_hdr *iphdr
nat_entry
.
tcp
);
nat_entry
.
tcp
);
}
else
{
}
else
{
LWIP_DEBUGF
(
LWIP_NAT_DEBUG
,
(
"ip_nat_udp_lookup_outgoing: no more NAT entries available
\n
"
));
LWIP_DEBUGF
(
LWIP_NAT_DEBUG
,
(
"ip_nat_udp_lookup_outgoing: no more NAT entries available
\n
"
));
// rt_kprintf("ip_nat_udp_lookup_outgoing: no more NAT entries available\n");
}
}
}
}
}
}
...
@@ -1005,9 +1013,9 @@ ip_nat_dbg_dump(const char *msg, const struct ip_hdr *iphdr)
...
@@ -1005,9 +1013,9 @@ ip_nat_dbg_dump(const char *msg, const struct ip_hdr *iphdr)
LWIP_ASSERT
(
"NULL != msg"
,
NULL
!=
msg
);
LWIP_ASSERT
(
"NULL != msg"
,
NULL
!=
msg
);
LWIP_ASSERT
(
"NULL != iphdr"
,
NULL
!=
iphdr
);
LWIP_ASSERT
(
"NULL != iphdr"
,
NULL
!=
iphdr
);
LWIP_DEBUGF
(
LWIP_NAT_DEBUG
,
(
"%s: IP: ("
,
msg
));
LWIP_DEBUGF
(
LWIP_NAT_DEBUG
,
(
"%s: IP: ("
,
msg
));
ip_nat_dbg_dump_ip
(
&
iphdr
->
src
);
ip_nat_dbg_dump_ip
(
(
ip_addr_t
*
)
&
(
iphdr
->
src
)
);
LWIP_DEBUGF
(
LWIP_NAT_DEBUG
,
(
" --> "
));
LWIP_DEBUGF
(
LWIP_NAT_DEBUG
,
(
" --> "
));
ip_nat_dbg_dump_ip
(
&
iphdr
->
dest
);
ip_nat_dbg_dump_ip
(
(
ip_addr_t
*
)
&
(
iphdr
->
dest
)
);
LWIP_DEBUGF
(
LWIP_NAT_DEBUG
,
(
" id=%"
U16_F
", chksum=%"
U16_F
")
\n
"
,
LWIP_DEBUGF
(
LWIP_NAT_DEBUG
,
(
" id=%"
U16_F
", chksum=%"
U16_F
")
\n
"
,
ntohs
(
IPH_ID
(
iphdr
)),
ntohs
(
IPH_CHKSUM
(
iphdr
))));
ntohs
(
IPH_ID
(
iphdr
)),
ntohs
(
IPH_CHKSUM
(
iphdr
))));
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录