From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7FF4DA0546; Tue, 6 Apr 2021 15:53:18 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 08BE2140F94; Tue, 6 Apr 2021 15:53:18 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mails.dpdk.org (Postfix) with ESMTP id 33322140F8E for ; Tue, 6 Apr 2021 15:53:16 +0200 (CEST) IronPort-SDR: KBQpx+UFnArgd/wDEc5qDbWjhWICci4yMQ+bhBAq7DpVcmnXKAbxfkCmbCHgf/qyGHBFSaTrtB hph/kYQ6OqlQ== X-IronPort-AV: E=McAfee;i="6000,8403,9946"; a="213430055" X-IronPort-AV: E=Sophos;i="5.81,309,1610438400"; d="scan'208";a="213430055" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Apr 2021 06:53:14 -0700 IronPort-SDR: XHKfave0GwpSu++qSGfd7qvWXUzh47ddu7ojC/28OlsQCvV60OVcc8EdRdMSJfIyuMb1F0+FEZ VlR5aPMYv6cA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,309,1610438400"; d="scan'208";a="519041465" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by fmsmga001.fm.intel.com with ESMTP; 06 Apr 2021 06:53:14 -0700 Received: from fmsmsx609.amr.corp.intel.com (10.18.126.89) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Tue, 6 Apr 2021 06:53:14 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx609.amr.corp.intel.com (10.18.126.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2 via Frontend Transport; Tue, 6 Apr 2021 06:53:14 -0700 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.172) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2106.2; Tue, 6 Apr 2021 06:53:12 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HneBZ0F3V1TQgVrQc3jTDM8ZEu6I4i2rp4VKfL1zuBFScF1x9g0debH3RTAc21/ZLvJlBcWAMixAO8VhySEC2sAEUTd1J/KaX/O0pnB0nAjtGJ7HtNG8kTcy14+Iwatfo4jFWoN4NTe0lzC/SLBAxx5+QDb/W8RJjxcogpPuHTP1HjOdgC7qV1IbTd3uhPar8EOZ+HgGnITnwK7/ZLieTaVInjeUZuVJQRD0NkAiBQZv2PirInpOCbmF5eKEbTf78tY/tWlkgLenl0wNF2w17DwFuVXmV9eEBM35/xCgCd8eXyvLmwwkGfrtHxNWA5v6Zj5oqbFiSAPkjU0D5cP0fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=E8VfU4xGEL2h8/+eYJzdE5NRP8ikvuqiweIShgscuYg=; b=BI2DG1rUujzYjenLfHjzPUPtrJFPg1IEtU14nPynramzMrLPD865dgRD7qR6dxXedGdZQL4dpkmhV+jCf/kL3wJfDSUGniZWffGn/NToTqFR0kkUo5g81ZSwwCLhjzRjTdjVa3IrbYsmMsXCNMs+ZTTeJkeOwJBIxHeymFYsXreTyXvBcoCSXi7paGN31FQHg50MSMhnyLZzZYV74oZWTn9P3VLc7xx3Qmq8i/h85rVG2wtHpCQk8rCUDXongbi6t/kopFxNHecAzQbjOgHeoeMNDG+k+L0ndaOesIpNLe1qQpxCBiaMgKOmcwcqd7/0P4qcPM8QFWg9DJqrVrL58Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=E8VfU4xGEL2h8/+eYJzdE5NRP8ikvuqiweIShgscuYg=; b=gwzLmL6nc+DR1/GF7R0UvFtkXQv5Y7CSofADlw/ZktjnyBwd+Dldjuj3N6iUGsJEpR2XVT85ALbNKm3B+EsGB4plcFbKiJc7OzSiweRx26AUJgwSezH92obSeWHRdqfUOR688Hbq4UieK/4V/yeFjWnxsLX4leYaB5zQiwTysx8= Received: from DM6PR11MB4491.namprd11.prod.outlook.com (2603:10b6:5:204::19) by DM6PR11MB4459.namprd11.prod.outlook.com (2603:10b6:5:1de::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28; Tue, 6 Apr 2021 13:53:10 +0000 Received: from DM6PR11MB4491.namprd11.prod.outlook.com ([fe80::3182:6da2:8c64:f07a]) by DM6PR11MB4491.namprd11.prod.outlook.com ([fe80::3182:6da2:8c64:f07a%3]) with mapi id 15.20.3999.032; Tue, 6 Apr 2021 13:53:10 +0000 From: "Ananyev, Konstantin" To: "583493798@qq.com" <583493798@qq.com>, "dev@dpdk.org" CC: "thomas@monjalon.net" , "Burakov, Anatoly" , Thomas Monjalon Thread-Topic: [PATCH v2] ip_frag: fix fragmenting ipv4 packet with header option Thread-Index: AQHXIWe9IJgRtF/pvkWw/AwfXZOKQaqnlVKA Date: Tue, 6 Apr 2021 13:53:09 +0000 Message-ID: References: <20200501161603.33907-1-583493798@qq.com> In-Reply-To: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.5.1.3 authentication-results: qq.com; dkim=none (message not signed) header.d=none;qq.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [109.255.184.192] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d9cb0de5-9ccf-419b-4e47-08d8f9035059 x-ms-traffictypediagnostic: DM6PR11MB4459: x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:5797; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: M/WsSh1NeZVt2xlCzKP+ApZZ5vrhZYQUDrc9/+v1Mo/QYd5wxJcc5+lkxV38XxWyThQ/CStHghx6bSWcLqZhFrBjaOyAo1ON2i2pK2KIRwzMjfoXfuT0nPSF+afUrZGmiZz08axNSOxAA67iBHXFfgwVKlmFBUFCo9f1j95nF8Jwx6AcYyecKHUfoJUVD91XufyTlMDjGLyHBZbZPyU0SEBQNj5UYNYpUQXSakqkDoNxJ7bt3C1Patn8Lu/AUmZaHrREXY6rZg53IMFCFoGwbM/K6SrMnrE0MKKUqBm4w7XmY59MVFaxyGcwNFJSUmUHU/YkH0VZD9biU7VmaioX1R2IhJ5sWMf/8iCPWRmEeWAQyTTB60QWp9pIL4mTxOagmATuvB/yfzSoJVeEcol3WOIMHNYMHZtj0ZHVYbEfqkakBupsItxTFilF8jA7duV++oMNoapQNPeS4LcH+1k5Jo6g3ClQBjGmz+cKkzDBTZn2unl+KEf0YGnilIJIcLIxyt2WOCzCo8q5p+3Kr9fmBHKfKzt0MQFsg3FzpT2YcFVCj/GQhlFUhEYKJxKKfIlh86hcW/8vpHeIhgTTOkD5Dg55j2vULTF52jbVbru/Ncje8dO+Xk9tmKGWpWCNyWhgZ/2s99+QmNpHO9NIFZ/gY+KmIK2Ah6pRFz+2MQ1j4DU= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR11MB4491.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(376002)(366004)(136003)(396003)(346002)(39860400002)(55016002)(9686003)(7696005)(86362001)(8936002)(8676002)(6506007)(2906002)(5660300002)(110136005)(54906003)(83380400001)(4326008)(64756008)(38100700001)(76116006)(52536014)(33656002)(71200400001)(66556008)(66946007)(66476007)(186003)(316002)(66446008)(478600001)(26005)(55236004); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?iKhy7JQE/I/b1xtIyMCoFMrH2o6+HkVr7iCsxX2kKTEoaJcb/OutQvDkpSRh?= =?us-ascii?Q?jXJXXr7TC6jnmsoKIB6H+fUa919ZjA20rntuM34gYR9+amrgohMHkNF1qn6i?= =?us-ascii?Q?guNXYt2M9WgjvFRVFeibXh0+jxNCqxDZxf1KMNjnGTk4FA15gTs+j9uyQsSl?= =?us-ascii?Q?P/lNKVJfwB2d13sndXjbivb26PJI+OitB2Bn2hITry2sq5ydjsJynkoRkDs3?= =?us-ascii?Q?nnD8KeptQFyUQXXg6FDJDGdyBOmhmJxTqBvB9aCxSGLIOafBrNqkt/zh//Ol?= =?us-ascii?Q?q/Gr5hrPlWab4CZlWTTUZ9hh2dhx+WbCtlivlHHl9BT2s0SVkUgbUa7lGW3y?= =?us-ascii?Q?U3xtaXyjgoVbO6f4S9ujwJU9oVwa6pYibkwJxUwuOEM21wjlRXiBid7Z49xA?= =?us-ascii?Q?qwO8AEf+cfZQSAMYPr//DX/SA81U8lk6IbAd2/ALDSoYTqKtUg71cbxwnVRl?= =?us-ascii?Q?eKztVaIgc9WWiEod4Qi2lWsGCzSC4YyyOGNKRLl/ITJnqvhDOw7eXoKfg4AY?= =?us-ascii?Q?n2447YTAApWwmp1eV5LDQgACxKNjQSk7RGfzUBuafbU6ARvi4DCdlPqVmGEo?= =?us-ascii?Q?uBZVLOt7oeeExyam6Ji6gQ130MmFx2Ki070U2SF9CF0sQyY+qCnevrVjLDnm?= =?us-ascii?Q?yk4//pvT91HngjMBijlCD1YIsQnfgLx61KjN/6/Kql8KFFcX2fzliHkwhtOr?= =?us-ascii?Q?API5mfw9UXqM0+o6hPm25GjFYPihn89KCSz5g8Ids49Q6T95X/E8x9oNsED0?= =?us-ascii?Q?3kFhLs7zEv7P08BpYsOQtp36IPHyv/WEODKCL31tr11/SA7+EV5Y9ktRaK15?= =?us-ascii?Q?6gJvoYxyqWaI2mB2DxOGgnIChV9nVZQT0QfHxAph/lYCidKaxy15M3KLwi9i?= =?us-ascii?Q?q5Yf0zfVC3bpRqAAS/xRk8zm39oGzxTjhx11RoQgiGE3vSrod/OYNRgqhA6M?= =?us-ascii?Q?Gjuiha4zO0BHCt/HlR96AVZjUtEi8PgElrYI89woXhwvJXmd2grZrlI0VggB?= =?us-ascii?Q?DiZLKcL27QnOLWJLCGWfdbnmDuMOy2YEWJd1zXL+uI4AmFmlraLE1O0yKuzL?= =?us-ascii?Q?kXcD9oN3ctHHUL20L8wKRFumCbvL+9JreGsvF4zKpowCH/jd5jNyryLya4oF?= =?us-ascii?Q?hT5C6bn00wkCLHa5EvQYix0YS47phFnjBBHqy5zDW4AoYG68vUR6x2FPl/uh?= =?us-ascii?Q?gCgJ06SCx8/jpbQHghW/3KJQELoJoaduuzAShFP0HQfC9phSoPPTchvE0IV7?= =?us-ascii?Q?c5oUzFQDP0XsWHzbYjMTKRVoTA3HUc0HUxrLqd1xcf3qYAFIH95/RewamSzd?= =?us-ascii?Q?NCvUjTKXwxZBfBJOAQ0DyW/b?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR11MB4491.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d9cb0de5-9ccf-419b-4e47-08d8f9035059 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Apr 2021 13:53:09.9504 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: X4t9ZKUJgxXWzW2hA51e/hYLd4GMnvbQC03Bh7/GbpLeVLXi6vC4V6dZ6APV18nrqijfFgsOwaGnGhW6/e5HaKmmFPYNmSOZL+JVmZcUyG0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB4459 X-OriginatorOrg: intel.com Subject: Re: [dpdk-dev] [PATCH v2] ip_frag: fix fragmenting ipv4 packet with header option X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" >=20 > From: Pu Xu <583493798@qq.com> >=20 > When fragmenting ipv4 packet, the data offset should be calculated throug= h > the ihl field in ip header rather than using sizeof(struct rte_ipv4_hdr). >=20 > Fixes: 4c38e5532a07 ("ip_frag: refactor IPv4 fragmentation into a proper = library") >=20 > Signed-off-by: Pu Xu <583493798@qq.com> > --- > lib/librte_ip_frag/rte_ipv4_fragmentation.c | 34 +++++++++++++-------- > 1 file changed, 21 insertions(+), 13 deletions(-) >=20 > diff --git a/lib/librte_ip_frag/rte_ipv4_fragmentation.c b/lib/librte_ip_= frag/rte_ipv4_fragmentation.c > index e9de335ae..2e7739d02 100644 > --- a/lib/librte_ip_frag/rte_ipv4_fragmentation.c > +++ b/lib/librte_ip_frag/rte_ipv4_fragmentation.c > @@ -23,10 +23,10 @@ > #define IPV4_HDR_FO_ALIGN (1 << RTE_IPV4_HDR_FO_SHIFT) >=20 > static inline void __fill_ipv4hdr_frag(struct rte_ipv4_hdr *dst, > - const struct rte_ipv4_hdr *src, uint16_t len, uint16_t fofs, > - uint16_t dofs, uint32_t mf) > + const struct rte_ipv4_hdr *src, uint16_t header_len, > + uint16_t len, uint16_t fofs, uint16_t dofs, uint32_t mf) > { > - rte_memcpy(dst, src, sizeof(*dst)); > + rte_memcpy(dst, src, header_len); > fofs =3D (uint16_t)(fofs + (dofs >> RTE_IPV4_HDR_FO_SHIFT)); > fofs =3D (uint16_t)(fofs | mf << RTE_IPV4_HDR_MF_SHIFT); > dst->fragment_offset =3D rte_cpu_to_be_16(fofs); > @@ -74,7 +74,7 @@ rte_ipv4_fragment_packet(struct rte_mbuf *pkt_in, > struct rte_ipv4_hdr *in_hdr; > uint32_t out_pkt_pos, in_seg_data_pos; > uint32_t more_in_segs; > - uint16_t fragment_offset, flag_offset, frag_size; > + uint16_t fragment_offset, flag_offset, frag_size, header_len; > uint16_t frag_bytes_remaining; >=20 > /* > @@ -86,14 +86,22 @@ rte_ipv4_fragment_packet(struct rte_mbuf *pkt_in, > unlikely(mtu_size < RTE_ETHER_MIN_MTU)) > return -EINVAL; >=20 > + in_hdr =3D rte_pktmbuf_mtod(pkt_in, struct rte_ipv4_hdr *); > + header_len =3D (in_hdr->version_ihl & RTE_IPV4_HDR_IHL_MASK) * > + RTE_IPV4_IHL_MULTIPLIER; > + > + /* Check IP header length */ > + if (unlikely(pkt_in->data_len < header_len) || > + unlikely(mtu_size < header_len)) > + return -EINVAL; > + > /* > * Ensure the IP payload length of all fragments is aligned to a > * multiple of 8 bytes as per RFC791 section 2.3. > */ > - frag_size =3D RTE_ALIGN_FLOOR((mtu_size - sizeof(struct rte_ipv4_hdr)), > + frag_size =3D RTE_ALIGN_FLOOR((mtu_size - header_len), > IPV4_HDR_FO_ALIGN); >=20 > - in_hdr =3D rte_pktmbuf_mtod(pkt_in, struct rte_ipv4_hdr *); > flag_offset =3D rte_cpu_to_be_16(in_hdr->fragment_offset); >=20 > /* If Don't Fragment flag is set */ > @@ -102,11 +110,11 @@ rte_ipv4_fragment_packet(struct rte_mbuf *pkt_in, >=20 > /* Check that pkts_out is big enough to hold all fragments */ > if (unlikely(frag_size * nb_pkts_out < > - (uint16_t)(pkt_in->pkt_len - sizeof(struct rte_ipv4_hdr)))) > + (uint16_t)(pkt_in->pkt_len - header_len))) > return -EINVAL; >=20 > in_seg =3D pkt_in; > - in_seg_data_pos =3D sizeof(struct rte_ipv4_hdr); > + in_seg_data_pos =3D header_len; > out_pkt_pos =3D 0; > fragment_offset =3D 0; >=20 > @@ -124,8 +132,8 @@ rte_ipv4_fragment_packet(struct rte_mbuf *pkt_in, > } >=20 > /* Reserve space for the IP header that will be built later */ > - out_pkt->data_len =3D sizeof(struct rte_ipv4_hdr); > - out_pkt->pkt_len =3D sizeof(struct rte_ipv4_hdr); > + out_pkt->data_len =3D header_len; > + out_pkt->pkt_len =3D header_len; > frag_bytes_remaining =3D frag_size; >=20 > out_seg_prev =3D out_pkt; > @@ -176,14 +184,14 @@ rte_ipv4_fragment_packet(struct rte_mbuf *pkt_in, >=20 > out_hdr =3D rte_pktmbuf_mtod(out_pkt, struct rte_ipv4_hdr *); >=20 > - __fill_ipv4hdr_frag(out_hdr, in_hdr, > + __fill_ipv4hdr_frag(out_hdr, in_hdr, header_len, > (uint16_t)out_pkt->pkt_len, > flag_offset, fragment_offset, more_in_segs); >=20 > fragment_offset =3D (uint16_t)(fragment_offset + > - out_pkt->pkt_len - sizeof(struct rte_ipv4_hdr)); > + out_pkt->pkt_len - header_len); >=20 > - out_pkt->l3_len =3D sizeof(struct rte_ipv4_hdr); > + out_pkt->l3_len =3D header_len; >=20 > /* Write the fragment to the output list */ > pkts_out[out_pkt_pos] =3D out_pkt; > -- Acked-by: Konstantin Ananyev > 2.17.0