From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8E905A09EE for ; Sat, 12 Dec 2020 11:18:27 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 481C2A54F; Sat, 12 Dec 2020 11:18:26 +0100 (CET) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by dpdk.org (Postfix) with ESMTP id 37169A54F for ; Sat, 12 Dec 2020 11:18:22 +0100 (CET) Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4CtNrR5pTWz15bvZ for ; Sat, 12 Dec 2020 18:17:43 +0800 (CST) Received: from localhost (10.174.243.72) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Sat, 12 Dec 2020 18:18:08 +0800 From: Yicai Lu To: CC: Yicai Lu , Date: Sat, 12 Dec 2020 18:18:06 +0800 Message-ID: <1607768286-15440-1-git-send-email-luyicai@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.243.72] X-CFilter-Loop: Reflected Subject: [dpdk-stable] [PATCH v4] ip_frag: recalculate pkt length of fragment X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" In some situations, we would get several ip fragments, which total data length is less than minimum frame(64) and padding with zeros. Examples: Second Fragment "a0a1 a2a3 a4a5 a6a7 0000 0000 ..." and Third Fragment "a8a9 aaab acad aeaf b0b1 b2b3 ...". Finally, we would reassemble Second and Third Fragment like this "a0a1 a2a3 a4a5 a6a7 0000 0000 ... a8a9 aaab acad aeaf b0b1 ...", which is not correct! So, we need recalculate the length of fragment to remove padding! Fixes: 7f0983ee331c ("ip_frag: check fragment length of incoming packet") Cc: stable@dpdk.org Signed-off-by: Yicai Lu --- v3 -> v4: Update the comments. --- lib/librte_ip_frag/rte_ipv4_reassembly.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/librte_ip_frag/rte_ipv4_reassembly.c b/lib/librte_ip_frag/rte_ipv4_reassembly.c index 1dda8ac..fdf66a4 100644 --- a/lib/librte_ip_frag/rte_ipv4_reassembly.c +++ b/lib/librte_ip_frag/rte_ipv4_reassembly.c @@ -104,6 +104,7 @@ struct rte_mbuf * const unaligned_uint64_t *psd; uint16_t flag_offset, ip_ofs, ip_flag; int32_t ip_len; + int32_t trim; flag_offset = rte_be_to_cpu_16(ip_hdr->fragment_offset); ip_ofs = (uint16_t)(flag_offset & RTE_IPV4_HDR_OFFSET_MASK); @@ -117,14 +118,15 @@ struct rte_mbuf * ip_ofs *= RTE_IPV4_HDR_OFFSET_UNITS; ip_len = rte_be_to_cpu_16(ip_hdr->total_length) - mb->l3_len; + trim = mb->pkt_len - (ip_len + mb->l3_len + mb->l2_len); IP_FRAG_LOG(DEBUG, "%s:%d:\n" - "mbuf: %p, tms: %" PRIu64 - ", key: <%" PRIx64 ", %#x>, ofs: %u, len: %d, flags: %#x\n" + "mbuf: %p, tms: %" PRIu64 ", key: <%" PRIx64 ", %#x>" + "ofs: %u, len: %d, padding: %d, flags: %#x\n" "tbl: %p, max_cycles: %" PRIu64 ", entry_mask: %#x, " "max_entries: %u, use_entries: %u\n\n", __func__, __LINE__, - mb, tms, key.src_dst[0], key.id, ip_ofs, ip_len, ip_flag, + mb, tms, key.src_dst[0], key.id, ip_ofs, ip_len, trim, ip_flag, tbl, tbl->max_cycles, tbl->entry_mask, tbl->max_entries, tbl->use_entries); @@ -134,6 +136,10 @@ struct rte_mbuf * return NULL; } + if (unlikely(trim > 0)) { + rte_pktmbuf_trim(mb, trim); + } + /* try to find/add entry into the fragment's table. */ if ((fp = ip_frag_find(tbl, dr, &key, tms)) == NULL) { IP_FRAG_MBUF2DR(dr, mb); -- 1.9.5.msysgit.1