summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorHanhui <sylixos@gmail.com>2019-04-09 07:45:05 (GMT)
committer Hanhui <sylixos@gmail.com>2019-03-07 12:37:36 (GMT)
commit3f9526fdb7d455d1d1fd7f3c00b97b2a071333a9 (patch)
treeab684361b9aadf9e0cc340f8523c6a8092835232
parent750c0e8eac386a8fa9198a791a1ac204a1fe383f (diff)
downloadAIC-OS-3f9526fdb7d455d1d1fd7f3c00b97b2a071333a9.zip
Add net device descriptor helper static buffer support custom offset.
-rw-r--r--SylixOS/net/lwip/netdev/netdesc.c33
-rw-r--r--SylixOS/net/lwip/netdev/netdev.h1
-rw-r--r--SylixOS/net/lwip/tools/nat/lwip_natlib.c57
3 files changed, 58 insertions, 33 deletions
diff --git a/SylixOS/net/lwip/netdev/netdesc.c b/SylixOS/net/lwip/netdev/netdesc.c
index 650bf5b..6b6014a 100644
--- a/SylixOS/net/lwip/netdev/netdesc.c
+++ b/SylixOS/net/lwip/netdev/netdesc.c
@@ -542,6 +542,39 @@ struct pbuf *netdev_desc_rx_input (struct netdev_desc_helper *helper, int idx, i
return (p);
}
+/* netdev_desc_rx_input_offset (you must ensure 'idx' is valid) */
+struct pbuf *netdev_desc_rx_input_offset (struct netdev_desc_helper *helper, int idx, int len, int offset)
+{
+ struct pbuf *p;
+ struct netdev_desc_buf *rx_buf;
+
+ rx_buf = NETDEV_RX_DESC_BUF(helper, idx);
+ if (rx_buf->p) {
+ p = rx_buf->p;
+ p->tot_len = p->len = (u16_t)len;
+ rx_buf->p = NULL;
+#if LW_CFG_CACHE_EN > 0
+ if (helper->cache_zc_invalid) {
+ cacheInvalidate(DATA_CACHE, p->payload, p->tot_len);
+ }
+#endif /* LW_CFG_CACHE_EN */
+
+ } else {
+ p = netdev_pbuf_alloc((u16_t)len);
+ if (!p) {
+ return (NULL);
+ }
+#if LW_CFG_CACHE_EN > 0
+ if (helper->cache_rs_invalid) {
+ cacheInvalidate(DATA_CACHE, (char *)rx_buf->buffer + offset, len);
+ }
+#endif /* LW_CFG_CACHE_EN */
+ pbuf_take(p, (char *)rx_buf->buffer + offset, (u16_t)len);
+ }
+
+ return (p);
+}
+
/* netdev_desc_rx_refill (you must ensure 'idx' is valid) */
netdev_desc_btype netdev_desc_rx_refill (struct netdev_desc_helper *helper, int idx)
{
diff --git a/SylixOS/net/lwip/netdev/netdev.h b/SylixOS/net/lwip/netdev/netdev.h
index 0af5fd3..e7b372e 100644
--- a/SylixOS/net/lwip/netdev/netdev.h
+++ b/SylixOS/net/lwip/netdev/netdev.h
@@ -494,6 +494,7 @@ netdev_desc_btype netdev_desc_tx_prepare(struct netdev_desc_helper *helper, int
void netdev_desc_tx_clean(struct netdev_desc_helper *helper, int idx);
/* get Rx descriptor buffer (you must ensure 'idx' is valid) */
struct pbuf *netdev_desc_rx_input(struct netdev_desc_helper *helper, int idx, int len);
+struct pbuf *netdev_desc_rx_input_offset(struct netdev_desc_helper *helper, int idx, int len, int offset);
/* refill Rx descriptor buffer (you must ensure 'idx' is valid) */
netdev_desc_btype netdev_desc_rx_refill(struct netdev_desc_helper *helper, int idx);
netdev_desc_btype netdev_desc_rx_refill_res(struct netdev_desc_helper *helper, int idx, UINT16 res);
diff --git a/SylixOS/net/lwip/tools/nat/lwip_natlib.c b/SylixOS/net/lwip/tools/nat/lwip_natlib.c
index 76eee1d..6f2f1a6 100644
--- a/SylixOS/net/lwip/tools/nat/lwip_natlib.c
+++ b/SylixOS/net/lwip/tools/nat/lwip_natlib.c
@@ -38,6 +38,7 @@
2018.01.16 使用 iphook 实现更加灵活的 NAT 管理.
2018.04.06 NAT 支持提前分片重组.
2019.02.15 本地 TCP SYN, CLOSING 仅保持 1 分钟.
+2019.04.09 NAT AP 端口支持主机安全隔离.
*********************************************************************************************************/
#define __SYLIXOS_STDIO
#define __SYLIXOS_KERNEL
@@ -755,41 +756,35 @@ static INT __natApInput (struct pbuf *p, struct netif *netifIn)
ip4_addr_p_t ipaddr; /* 内网映射服务器 IP */
u16_t usSrcHash = iphdr->src.addr % pnatmap->NATM_usLocalCnt;
/* 外网 hash */
- if (ip4_addr_cmp(&pnatmap->NATM_ipaddrLocalIp,
- netif_ip4_addr(netifIn))) { /* 本机映射 */
- ipaddr.addr = pnatmap->NATM_ipaddrLocalIp.addr;
-
- } else { /* 内网其他主机映射 */
- for (plineTemp = plineHeader;
- plineTemp != LW_NULL;
- plineTemp = _list_line_get_next(plineTemp)) {
+ for (plineTemp = plineHeader; /* 内网主机映射 */
+ plineTemp != LW_NULL;
+ plineTemp = _list_line_get_next(plineTemp)) {
- pnatcb = _LIST_ENTRY(plineTemp, __NAT_CB, NAT_lineManage);
- if ((usSrcHash == pnatcb->NAT_usSrcHash) &&
- (usDestPort == pnatcb->NAT_usAssPort) &&
- (ucProto == pnatcb->NAT_ucProto)) {
- break; /* 找到了 NAT 控制块 */
- }
+ pnatcb = _LIST_ENTRY(plineTemp, __NAT_CB, NAT_lineManage);
+ if ((usSrcHash == pnatcb->NAT_usSrcHash) &&
+ (usDestPort == pnatcb->NAT_usAssPort) &&
+ (ucProto == pnatcb->NAT_ucProto)) {
+ break; /* 找到了 NAT 控制块 */
}
- if (plineTemp == LW_NULL) {
- u32_t uiHost;
+ }
+ if (plineTemp == LW_NULL) {
+ u32_t uiHost;
- uiHost = (u32_t)PP_NTOHL(pnatmap->NATM_ipaddrLocalIp.addr);
- uiHost += usSrcHash; /* 根据源地址散列做均衡 */
- ipaddr.addr = (u32_t)PP_HTONL(uiHost);
+ uiHost = (u32_t)PP_NTOHL(pnatmap->NATM_ipaddrLocalIp.addr);
+ uiHost += usSrcHash; /* 根据源地址散列做均衡 */
+ ipaddr.addr = (u32_t)PP_HTONL(uiHost);
- pnatcb = __natNew(&ipaddr, /* 新建控制块 */
- pnatmap->NATM_usLocalPort, ucProto);
+ pnatcb = __natNew(&ipaddr, /* 新建控制块 */
+ pnatmap->NATM_usLocalPort, ucProto);
- pnatcb->NAT_usSrcHash = usSrcHash;
- pnatcb->NAT_usAssPortSave = pnatcb->NAT_usAssPort; /* 保存端口资源 */
- pnatcb->NAT_usAssPort = pnatmap->NATM_usAssPort;
-
- } else {
- ipaddr.addr = pnatcb->NAT_ipaddrLocalIp.addr;
+ pnatcb->NAT_usSrcHash = usSrcHash;
+ pnatcb->NAT_usAssPortSave = pnatcb->NAT_usAssPort; /* 保存端口资源 */
+ pnatcb->NAT_usAssPort = pnatmap->NATM_usAssPort;
- pnatcb->NAT_ulIdleTimer = 0; /* 刷新空闲时间 */
- }
+ } else {
+ ipaddr.addr = pnatcb->NAT_ipaddrLocalIp.addr;
+
+ pnatcb->NAT_ulIdleTimer = 0; /* 刷新空闲时间 */
}
/*
@@ -997,10 +992,6 @@ static INT __natApOutput (struct pbuf *p, struct netif *pnetifIn, struct netif
}
}
if (plineTemp == LW_NULL) {
- pnatcb = LW_NULL; /* 没有找到 */
- }
-
- if (pnatcb == LW_NULL) {
pnatcb = __natNew(&iphdr->src, usSrcPort, ucProto); /* 新建控制块 */
}