summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorHanhui <hanhui@acoinfo.com>2021-09-02 12:22:08 (GMT)
committer Hanhui <hanhui@acoinfo.com>2021-09-02 12:22:08 (GMT)
commitab5b6a29a3447cc5c2040f0e778c2178e7424fba (patch)
tree4facf467d59599b5e0e6ead3f41914b8602b005d
parent667b7bb90661740f62fd02a1c276bcd37894001b (diff)
downloadlibsylixos-ab5b6a29a3447cc5c2040f0e778c2178e7424fba.zip
libsylixos-ab5b6a29a3447cc5c2040f0e778c2178e7424fba.tar.gz
libsylixos-ab5b6a29a3447cc5c2040f0e778c2178e7424fba.tar.bz2
Fixed AF_PACKET send max length valid check error.
-rw-r--r--SylixOS/net/lwip/packet/af_packet.c4
-rw-r--r--SylixOS/net/lwip/packet/af_packet_eth.c15
2 files changed, 13 insertions, 6 deletions
diff --git a/SylixOS/net/lwip/packet/af_packet.c b/SylixOS/net/lwip/packet/af_packet.c
index e2ae94c..fe221d5 100644
--- a/SylixOS/net/lwip/packet/af_packet.c
+++ b/SylixOS/net/lwip/packet/af_packet.c
@@ -50,9 +50,9 @@ extern void __socketEnotify(void *file, LW_SEL_TYPE type, INT iSoErr);
/*********************************************************************************************************
宏配置
*********************************************************************************************************/
-#define __AF_PACKET_BUF_MAX (LW_CFG_KB_SIZE * 256) /* 默认为 64K 接收缓冲 */
+#define __AF_PACKET_BUF_MAX (LW_CFG_KB_SIZE * 512) /* 最大接收缓冲大小 */
#define __AF_PACKET_BUF_MIN (LW_CFG_KB_SIZE * 16) /* 最小接收缓冲大小 */
-#define __AF_PACKET_BUF_DEF (LW_CFG_KB_SIZE * 64)
+#define __AF_PACKET_BUF_DEF (LW_CFG_KB_SIZE * 64) /* 默认为 64K 接收缓冲 */
#define __AF_PACKET_PKT_NODES LW_CFG_LWIP_NUM_POOLS
/*********************************************************************************************************
全局变量
diff --git a/SylixOS/net/lwip/packet/af_packet_eth.c b/SylixOS/net/lwip/packet/af_packet_eth.c
index b3341fc..1419606 100644
--- a/SylixOS/net/lwip/packet/af_packet_eth.c
+++ b/SylixOS/net/lwip/packet/af_packet_eth.c
@@ -56,7 +56,7 @@ errno_t __packetEthRawSendto (AF_PACKET_T *pafpacket,
struct pbuf *pbuf_dat;
err_t err;
- if ((stBytes < ETH_HLEN) || (stBytes > ETH_FRAME_LEN)) {
+ if (stBytes < ETH_HLEN || stBytes > (UINT16_MAX - ETH_PAD_SIZE)) {
return (EMSGSIZE);
}
@@ -74,6 +74,10 @@ errno_t __packetEthRawSendto (AF_PACKET_T *pafpacket,
UNLOCK_TCPIP_CORE();
return (ENXIO);
}
+ if (pnetif->mtu && (stBytes > pnetif->mtu + ETH_HLEN)) {
+ UNLOCK_TCPIP_CORE();
+ return (EMSGSIZE);
+ }
if (!netif_is_up(pnetif) || !netif_is_link_up(pnetif)) {
UNLOCK_TCPIP_CORE();
return (ENETDOWN);
@@ -142,10 +146,10 @@ errno_t __packetEthDgramSendto (AF_PACKET_T *pafpacket,
struct eth_hdr *pethhdr;
err_t err;
- if (stBytes > ETH_DATA_LEN) {
+ if (stBytes > (UINT16_MAX - ETH_HLEN - ETH_PAD_SIZE)) {
return (EMSGSIZE);
}
-
+
LOCK_TCPIP_CORE();
pnetif = netif_get_by_index(psockaddrll->sll_ifindex);
if (pnetif == LW_NULL) {
@@ -160,7 +164,10 @@ errno_t __packetEthDgramSendto (AF_PACKET_T *pafpacket,
UNLOCK_TCPIP_CORE();
return (ENETDOWN);
}
-
+ if (pnetif->mtu && (stBytes > pnetif->mtu)) {
+ UNLOCK_TCPIP_CORE();
+ return (EMSGSIZE);
+ }
pbuf_hdr = pbuf_alloc(PBUF_RAW, ETH_HLEN + ETH_PAD_SIZE, PBUF_RAM); /* 分配带有 PAD 的报头 */
if (pbuf_hdr == LW_NULL) {
UNLOCK_TCPIP_CORE();