From patchwork Tue Feb 13 11:47:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vignesh Purushotham Srinivas X-Patchwork-Id: 136634 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 71A3743B04; Tue, 13 Feb 2024 12:48:43 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E579D4029C; Tue, 13 Feb 2024 12:48:42 +0100 (CET) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2077.outbound.protection.outlook.com [40.107.22.77]) by mails.dpdk.org (Postfix) with ESMTP id CF9FB4027B for ; Tue, 13 Feb 2024 12:48:41 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dfIueByE2JEJ8knC/VTKUk3pxqKuv2ny7sJW+qysLL9SuFqWcsPapUkILqXpq4tArULjehwoRyBHo3Q4N9RWT1UAJhG44ZY2vLvg21t6HO23I4QmOJwT5zAjhZ95tgLRRhJrnCRt7otGVroi0cC0sf0ibCC4BS8E7IAHb2B/Edr5KTPQuUGM8iqp0C8iKnBxRjors6zS7xmhA6e8m5yQ66Xh6jhPFOAs5hP9/H/ogWMV4FsO+drZQSbRjLQW6BYzLhVEyi/YtJ+KCMUxKshrk/u81fv6o6rkIBV0y+OJpkVI/XzMUWgLqvqGYtoFahDuJG/VsNTiKVL6fyAxzlYAXQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=j0H6RQqkcK/vfnpXJNa3WIAARV0kL5i6Nadclu/rQq8=; b=dcCfgKHI/bHwgvjKlt/xWWZMlXr5vCvSQ8GePejq+OqONq/12nTOx6AS9tNzr/FGlfTXOE75R3nyfdZuEUS0iivo5jXug6pfCpDearPP63UEfWE0P5oxyztvd0zQ5isXDAUJbHDRaYoY7Zyd3xT1Ii5ueEAebKBTfjD53udSE9ueTDFwK7xxqzTdpbGgyZIbTZuYgsOn+8LubDrLkhkAXW/iUgJvOSQnReBqxefaKqbkuq1J0M7QqZKLzyN73PHgWSJs8fvEIeB8vx1yfGs+oC3eWj3OX2vMIW2Y2XzY/LhQUR5vXRN+YwRjXdB4CKLMyWVeye6Sd/Em1BfyBmsAgQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 192.176.1.74) smtp.rcpttodomain=dpdk.org smtp.mailfrom=ericsson.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ericsson.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=j0H6RQqkcK/vfnpXJNa3WIAARV0kL5i6Nadclu/rQq8=; b=woBa2vVsSGQFMsKPhDbArzn3KLyUaLPCjDuGVDo3r8cidFVDTB9UwrU1yaAzFRo6RKirQOIc+9D+Dtew/1nJRkfs1Cq8ZTSlpBqVkypHJZhrmlB7QRebpWzPBZrch6DaaTr/jT68L418pJFToglrttYqQfJYVvE6IhUMfWXh8GSK6t+2MZFd+3gp1NCmTRrZJTp7vZP5d16OVqbAmamL2LpXHyJmdXKcz/6Jfnn1Zsmh2kx7r8mDZY9rYRlKd7+aYXYdkW06uD+mJZBQz087lUp+8sEIYRkFBY9nrC6Y2XxIl/k6jhN+NuztWaNeQU0d5v+sFmYjEuiNDoqx3FR9KQ== Received: from AM6P193CA0079.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:88::20) by AS8PR07MB7414.eurprd07.prod.outlook.com (2603:10a6:20b:2ae::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.38; Tue, 13 Feb 2024 11:48:40 +0000 Received: from AMS0EPF0000019F.eurprd05.prod.outlook.com (2603:10a6:209:88:cafe::51) by AM6P193CA0079.outlook.office365.com (2603:10a6:209:88::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.39 via Frontend Transport; Tue, 13 Feb 2024 11:48:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 192.176.1.74) smtp.mailfrom=ericsson.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ericsson.com; Received-SPF: Pass (protection.outlook.com: domain of ericsson.com designates 192.176.1.74 as permitted sender) receiver=protection.outlook.com; client-ip=192.176.1.74; helo=oa.msg.ericsson.com; pr=C Received: from oa.msg.ericsson.com (192.176.1.74) by AMS0EPF0000019F.mail.protection.outlook.com (10.167.16.251) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25 via Frontend Transport; Tue, 13 Feb 2024 11:48:40 +0000 Received: from seroius18815.sero.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.60) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Tue, 13 Feb 2024 12:48:40 +0100 Received: from seroiuts03116.sero.gic.ericsson.se (seroiuts03116.sero.gic.ericsson.se [10.210.134.60]) by seroius18815.sero.gic.ericsson.se (Postfix) with ESMTP id 64B77C0006ED; Tue, 13 Feb 2024 12:48:15 +0100 (CET) Received: by seroiuts03116.sero.gic.ericsson.se (Postfix, from userid 7401342) id 3789E61A72B5; Tue, 13 Feb 2024 12:48:15 +0100 (CET) From: To: CC: , Vignesh PS Subject: [RFC] ip_frag: support IPv6 reassembly with extensions Date: Tue, 13 Feb 2024 12:47:27 +0100 Message-ID: <20240213114727.550209-1-vignesh.purushotham.srinivas@ericsson.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AMS0EPF0000019F:EE_|AS8PR07MB7414:EE_ X-MS-Office365-Filtering-Correlation-Id: 2363f2d9-5c6f-4f19-3cb1-08dc2c89b904 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ijdoHd1WlW0OkX2iZiIrK3JsIS+2MOhDU0WC3CI2BKNWhxq7VEn19o8jWr9XsClltM8ZWtcDYqq/gTpWmr3+ymXY93O8MsgdqYEJNbqYrrlQjQ6Lnel+WbGJiu6wnZW9MrzqG0zzWfNP1jDWpuZVw9OCLf7eh6yRxe8/H21P/sCw+cC/S8NiTAwXpNI3i1wD/RvFpYcOvXk5r2aBioSOaNzivtydGVCbroqgFVS8zdm8ovzFReiIBE6rO6gSrNkjizUTieHPbe+nGHK9A+Q8NYq5ZhjiUkmR+sSu9tL++ZKJ+byRrqx2tNPByGGv7GEKI8uiPx1pEHEVfxjWEDuAi0bU2Vo3Ey2dA2zoxsczqnA4nTxM7RtBTU0unAyBG4LQVFbB0F8hCk+2E9h2E2N2gu0ho9pfYwPDtVGW9kpjAAlaEaBDzCl3ihmFpSxvs4zBJ6YSe+6gQnZL/ayUkCGQSTntnmYBIlfX+iPeLqMBCE809tTeVZIl7T2Mq6DKMBYPdWltFvZ0oXqw6vY6Tc9JE4svUZ9YhmC4VsblgUDjJ9fVRNauky6lqY/D4t4wcupVt5CS3s89BLwcJdSXiwqeRG21LJB8But7oLRlsTYrvtk= X-Forefront-Antispam-Report: CIP:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net; CAT:NONE; SFS:(13230031)(4636009)(376002)(396003)(39860400002)(136003)(346002)(230922051799003)(64100799003)(451199024)(82310400011)(186009)(1800799012)(40470700004)(36840700001)(46966006)(2906002)(2876002)(41300700001)(6266002)(478600001)(26005)(2616005)(1076003)(4326008)(336012)(54906003)(5660300002)(6916009)(42186006)(8676002)(70206006)(8936002)(70586007)(83380400001)(36756003)(103116003)(316002)(107886003)(6666004)(82960400001)(7636003)(356005)(82740400003); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Feb 2024 11:48:40.5347 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2363f2d9-5c6f-4f19-3cb1-08dc2c89b904 X-MS-Exchange-CrossTenant-Id: 92e84ceb-fbfd-47ab-be52-080c6b87953f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=92e84ceb-fbfd-47ab-be52-080c6b87953f; Ip=[192.176.1.74]; Helo=[oa.msg.ericsson.com] X-MS-Exchange-CrossTenant-AuthSource: AMS0EPF0000019F.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR07MB7414 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 From: Vignesh PS Add support to ip_frag library to perform IPv6 reassembly when extension headers are present before the fragment extension in the packet. Signed-off-by: Vignesh PS --- .mailmap | 1 + lib/ip_frag/ip_frag_common.h | 2 + lib/ip_frag/ip_reassembly.h | 2 + lib/ip_frag/rte_ipv6_reassembly.c | 64 ++++++++++++++++++++++++++----- 4 files changed, 60 insertions(+), 9 deletions(-) diff --git a/.mailmap b/.mailmap index de339562f4..6c068d5af3 100644 --- a/.mailmap +++ b/.mailmap @@ -1476,6 +1476,7 @@ Viacheslav Ovsiienko Victor Kaplansky Victor Raj Vidya Sagar Velumuri +Vignesh PS Vignesh Sridhar Vijayakumar Muthuvel Manickam Vijaya Mohan Guvva diff --git a/lib/ip_frag/ip_frag_common.h b/lib/ip_frag/ip_frag_common.h index c766154dbe..e671246898 100644 --- a/lib/ip_frag/ip_frag_common.h +++ b/lib/ip_frag/ip_frag_common.h @@ -169,6 +169,8 @@ ip_frag_reset(struct ip_frag_pkt *fp, uint64_t tms) fp->total_size = UINT32_MAX; fp->frag_size = 0; fp->last_idx = IP_MIN_FRAG_NUM; + fp->exts_len = 0; + fp->next_proto = NULL; fp->frags[IP_LAST_FRAG_IDX] = zero_frag; fp->frags[IP_FIRST_FRAG_IDX] = zero_frag; } diff --git a/lib/ip_frag/ip_reassembly.h b/lib/ip_frag/ip_reassembly.h index a9f97aefca..4605e1291f 100644 --- a/lib/ip_frag/ip_reassembly.h +++ b/lib/ip_frag/ip_reassembly.h @@ -54,6 +54,8 @@ struct ip_frag_pkt { uint32_t total_size; /* expected reassembled size */ uint32_t frag_size; /* size of fragments received */ uint32_t last_idx; /* index of next entry to fill */ + uint32_t exts_len; /* length of extension hdrs for first fragment */ + uint8_t *next_proto; /* pointer of the next_proto field */ struct ip_frag frags[IP_MAX_FRAG_NUM]; /* fragments */ } __rte_cache_aligned; diff --git a/lib/ip_frag/rte_ipv6_reassembly.c b/lib/ip_frag/rte_ipv6_reassembly.c index 88863a98d1..4e862fb55a 100644 --- a/lib/ip_frag/rte_ipv6_reassembly.c +++ b/lib/ip_frag/rte_ipv6_reassembly.c @@ -91,19 +91,19 @@ ipv6_frag_reassemble(struct ip_frag_pkt *fp) /* update ipv6 header for the reassembled datagram */ ip_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv6_hdr *, m->l2_len); + payload_len += fp->exts_len; ip_hdr->payload_len = rte_cpu_to_be_16(payload_len); /* * remove fragmentation header. note that per RFC2460, we need to update * the last non-fragmentable header with the "next header" field to contain - * type of the first fragmentable header, but we currently don't support - * other headers, so we assume there are no other headers and thus update - * the main IPv6 header instead. + * type of the first fragmentable header. */ - move_len = m->l2_len + m->l3_len - sizeof(*frag_hdr); - frag_hdr = (struct rte_ipv6_fragment_ext *) (ip_hdr + 1); - ip_hdr->proto = frag_hdr->next_header; + frag_hdr = (struct rte_ipv6_fragment_ext *) + ((uint8_t *) (ip_hdr + 1) + fp->exts_len); + *fp->next_proto = frag_hdr->next_header; + move_len = m->l2_len + m->l3_len - sizeof(*frag_hdr); ip_frag_memmove(rte_pktmbuf_mtod_offset(m, char *, sizeof(*frag_hdr)), rte_pktmbuf_mtod(m, char*), move_len); @@ -112,6 +112,35 @@ ipv6_frag_reassemble(struct ip_frag_pkt *fp) return m; } +/* + * Function to crawl through the extension header stack. + * This function breaks as soon a the fragment header is + * found and returns the total length the traversed exts + * and the last extension before the fragment header + */ +static inline uint32_t +ip_frag_get_last_exthdr(struct rte_ipv6_hdr *ip_hdr, uint8_t **last_ext) +{ + uint32_t total_len = 0; + size_t ext_len = 0; + *last_ext = (uint8_t *)(ip_hdr + 1); + int next_proto = ip_hdr->proto; + + while (next_proto != IPPROTO_FRAGMENT && + (next_proto = rte_ipv6_get_next_ext( + *last_ext, next_proto, &ext_len)) >= 0) { + + total_len += ext_len; + + if (next_proto == IPPROTO_FRAGMENT) + return total_len; + + *last_ext += ext_len; + } + + return total_len; +} + /* * Process new mbuf with fragment of IPV6 datagram. * Incoming mbuf should have its l2_len/l3_len fields setup correctly. @@ -139,6 +168,8 @@ rte_ipv6_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl, { struct ip_frag_pkt *fp; struct ip_frag_key key; + uint8_t *last_ipv6_ext; + uint32_t exts_len; uint16_t ip_ofs; int32_t ip_len; int32_t trim; @@ -154,10 +185,10 @@ rte_ipv6_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl, /* * as per RFC2460, payload length contains all extension headers * as well. - * since we don't support anything but frag headers, - * this is what we remove from the payload len. + * so we remove the extension len from the payload len. */ - ip_len = rte_be_to_cpu_16(ip_hdr->payload_len) - sizeof(*frag_hdr); + exts_len = ip_frag_get_last_exthdr(ip_hdr, &last_ipv6_ext); + ip_len = rte_be_to_cpu_16(ip_hdr->payload_len) - exts_len - sizeof(*frag_hdr); trim = mb->pkt_len - (ip_len + mb->l3_len + mb->l2_len); IP_FRAG_LOG(DEBUG, "%s:%d:\n" @@ -201,6 +232,21 @@ rte_ipv6_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl, /* process the fragmented packet. */ mb = ip_frag_process(fp, dr, mb, ip_ofs, ip_len, MORE_FRAGS(frag_hdr->frag_data)); + + /* store extension stack info, only for first fragment */ + if (ip_ofs == 0) { + /* + * fp->next_proto points to either the IP's next header + * or th next header of the extension before the fragment + * extension + */ + fp->next_proto = (uint8_t *)&ip_hdr->proto; + if (exts_len > 0) { + fp->exts_len = exts_len; + fp->next_proto = last_ipv6_ext; + } + } + ip_frag_inuse(tbl, fp); IP_FRAG_LOG(DEBUG, "%s:%d:\n"