From: Yanglong Wu Subject: [PATCH v2] net/i40e: illagel pactket checking Date: Fri, 8 Jun 2018 11:54:12 +0800 Message-ID: <20180608035412.91329-1-yanglong.wu@intel.com> References: <20180607093938.62579-1-yanglong.wu@intel.com> Cc: qi.z.zhang@intel.com, konstantin.ananyev@intel.com, Yanglong Wu To: dev@dpdk.org Return-path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 715BE7CFA for ; Fri, 8 Jun 2018 06:01:56 +0200 (CEST) In-Reply-To: <20180607093938.62579-1-yanglong.wu@intel.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Some illegal packets will lead to TX/RX hang and can't recover automatically. This pacth check those illegal packets and protect TX/RX from hanging. Signed-off-by: Yanglong Wu --- v2: fix coding style issue and error --- drivers/net/i40e/i40e_rxtx.c | 11 +++++++++++ drivers/net/i40e/i40e_rxtx.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/drivers/net/i40e/i40e_rxtx.c b/drivers/net/i40e/i40e_rxtx.c index 6032d5541..05cf3956c 100644 --- a/drivers/net/i40e/i40e_rxtx.c +++ b/drivers/net/i40e/i40e_rxtx.c @@ -1458,6 +1458,17 @@ i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts, return i; } + /*check the size of pkt len*/ + if (m->pkt_len > I40E_FRAME_SIZE_MAX || + m->pkt_len < I40E_TX_MIN_PKT_LEN) { + rte_errno = -EINVAL; + return i; } + + /*check the number of mbuf segments*/ + if (m->nb_segs > I40E_TX_MAX_MTU_SEG) { + rte_errno = -EINVAL; + return i; } + #ifdef RTE_LIBRTE_ETHDEV_DEBUG ret = rte_validate_tx_offload(m); if (ret != 0) { diff --git a/drivers/net/i40e/i40e_rxtx.h b/drivers/net/i40e/i40e_rxtx.h index ea73a8a1b..3fc619af9 100644 --- a/drivers/net/i40e/i40e_rxtx.h +++ b/drivers/net/i40e/i40e_rxtx.h @@ -30,6 +30,8 @@ #define I40E_TX_MAX_SEG UINT8_MAX #define I40E_TX_MAX_MTU_SEG 8 +#define I40E_TX_MIN_PKT_LEN 17 + #undef container_of #define container_of(ptr, type, member) ({ \ typeof(((type *)0)->member)(*__mptr) = (ptr); \ -- 2.11.0