From patchwork Mon Jun 13 10:48:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Elo, Matias \(Nokia - FI/Espoo\)" X-Patchwork-Id: 69868 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp1476790qgf; Mon, 13 Jun 2016 03:50:18 -0700 (PDT) X-Received: by 10.55.104.68 with SMTP id d65mr14276343qkc.190.1465815018204; Mon, 13 Jun 2016 03:50:18 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id m26si14800629qkh.116.2016.06.13.03.50.17; Mon, 13 Jun 2016 03:50:18 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE dis=NONE) header.from=nokia.com Received: by lists.linaro.org (Postfix, from userid 109) id C6BF1684CB; Mon, 13 Jun 2016 10:50:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 3E962684B3; Mon, 13 Jun 2016 10:50:00 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 582C9684C0; Mon, 13 Jun 2016 10:49:56 +0000 (UTC) Received: from emea01-db3-obe.outbound.protection.outlook.com (mail-db3on0117.outbound.protection.outlook.com [157.55.234.117]) by lists.linaro.org (Postfix) with ESMTPS id 5B1EF684B2 for ; Mon, 13 Jun 2016 10:49:38 +0000 (UTC) Received: from VI1PR07CA0126.eurprd07.prod.outlook.com (10.165.229.180) by VI1PR07MB0912.eurprd07.prod.outlook.com (10.161.109.12) with Microsoft SMTP Server (TLS) id 15.1.517.8; Mon, 13 Jun 2016 10:49:35 +0000 Received: from DB3FFO11FD005.protection.gbl (2a01:111:f400:7e04::159) by VI1PR07CA0126.outlook.office365.com (2a01:111:e400:7a52::52) with Microsoft SMTP Server (TLS) id 15.1.517.8 via Frontend Transport; Mon, 13 Jun 2016 10:49:35 +0000 Received-SPF: Pass (protection.outlook.com: domain of nokia.com designates 131.228.2.241 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.2.241; helo=mailrelay.int.nokia.com; Received: from mailrelay.int.nokia.com (131.228.2.241) by DB3FFO11FD005.mail.protection.outlook.com (10.47.216.94) with Microsoft SMTP Server (TLS) id 15.1.497.8 via Frontend Transport; Mon, 13 Jun 2016 10:49:35 +0000 Received: from fihe3nok0735.emea.nsn-net.net (localhost [127.0.0.1]) by fihe3nok0735.emea.nsn-net.net (8.14.9/8.14.5) with ESMTP id u5DAmjZL023996 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 13 Jun 2016 13:48:45 +0300 Received: from 10.144.19.15 ([10.144.104.92]) by fihe3nok0735.emea.nsn-net.net (8.14.9/8.14.5) with ESMTP id u5DAmjjr023989 (version=TLSv1/SSLv3 cipher=AES256-SHA256 bits=256 verify=NO) for ; Mon, 13 Jun 2016 13:48:45 +0300 X-HPESVCS-Source-Ip: 10.144.104.92 From: Matias Elo To: Date: Mon, 13 Jun 2016 13:48:44 +0300 Message-ID: <1465814925-27259-2-git-send-email-matias.elo@nokia.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1465814925-27259-1-git-send-email-matias.elo@nokia.com> References: <1465814925-27259-1-git-send-email-matias.elo@nokia.com> X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:131.228.2.241; IPV:NLI; CTRY:FI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(7916002)(2980300002)(438002)(189002)(199003)(92566002)(76176999)(50226002)(107886002)(110136002)(189998001)(2906002)(50986999)(36756003)(8676002)(81156014)(81166006)(2950100001)(575784001)(356003)(5003940100001)(97736004)(50466002)(48376002)(19580395003)(47776003)(106466001)(68736007)(229853001)(450100001)(16796002)(2351001)(8936002)(19580405001)(33646002)(87936001)(586003)(6806005)(22756006)(11100500001)(5008740100001)(77096005)(42882005); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR07MB0912; H:mailrelay.int.nokia.com; FPR:; SPF:Pass; PTR:InfoDomainNonexistent; MX:1; A:1; CAT:NONE; LANG:en; CAT:NONE; X-Microsoft-Exchange-Diagnostics: 1; DB3FFO11FD005; 1:ObB5SAexUivxg8F4VKxZaHORfFYuIISg/NG7OWm8fYxxpTmXHiqiqcxseQcdfyStsvbbQL7baK3j5HSfQqzm3U3bqgD2CxFS1SiIUyaA/SIRRYgcWpkeov7UUyZcAfF4IA1FcBqSqHN9DAi6qBbFn5oy7WCBg766u62cZ+Wwm8a+B2iXo1vOCUa6Q0pUlqyiHdpgsZwXbxJIbnxu5Tjcg/2Fhf3MnkhXVKMgNaSETXzdNfPNhnthZFmnOL/HEHfloQNUZOMwB2UkJT5+WBe7Z2VRhiux5ZHzz6d0yPpbh/1zGE6HobUI1+NFspgnu8H6s+wS4L96actLKkogxS9Sz8e7HoFI/Ym2CHdqxJFI+xS2o29m6k49uoxr5bhghWK45l355wvr9Cf9HR6x9+cULcODetyFBD/oEFtZfmQ0cpsyGhYD+inC0TYCSGE1Z0u0 MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 074ff5a8-3fd3-4929-714a-08d3937868f3 X-Microsoft-Exchange-Diagnostics: 1; VI1PR07MB0912; 2:LmS4fd2EcRVr6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VMAPzxmDxcxg02AxNdoEgxCemWzhaWRr+joLe7sqnyabFqZerQFDD2KCYXv1udZWUTCRuXstHpOL1afFyF9uM/29EC4SnOQExLF7n0KG5WobUnz9GYCFwOwUXbjrp9KOZAJNZNNfOZBc60falhxosKdWkrkDk8qbH4+qxHTR0qzuBCrwuzuzCiILDKGqF1t+0XJHJEtkvsWQEeKIA650EAKolowdfICFlwNJSrHzXKX6cW88bopbc04mquFQFSLxjo6YGCMyy1OQSZrcZ/hTqvH3N4BRRsIekBMfSt0btaX8S5dJblf4bH2EkcO3mT9yA1weSSNGmtEx1fJ9TXCdDfrsjOylfszyDbhAtbP0ZJcjBAyU9IW/txWbU387OX/WHZ8HQPXBsIoWZgOH0a7qHidrQ6cK3zW+TLZpveZAtBTr+35mXXmqI44BnTfjkOUw4IIhAKBOzYMv4O8AGLhGwaiWliLocb/AOVOOlAkPuZtQOfRLDA9p+PH6TB2VNoCg2cYAMaiEDypMjuvsmPVIHXGEVrUs= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(82608151540597); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13016025)(13018025)(8121501046)(5005006)(10201501046)(3002001); SRVR:VI1PR07MB0912; BCL:0; PCL:0; RULEID:; SRVR:VI1PR07MB0912; X-Microsoft-Exchange-Diagnostics: 1; VI1PR07MB0912; 4:/ZT9L8Nhd7Pzbh2hNLIoqEeDmmej3MkB5Gl3n9epO7sEvZxg4tvXj5JszXa2vrcACCDkE4HpuWGWY49pJeUvOBjibG/2y+0b318OtKS6tNZm0xS9hQV+HbtuWbwcCE1kWxLv4WCi7OvYiapy9y47nsz1oyVZeMnbU7SN8uAga5Pxomd2nYQcPG3vTJMsgUgme2wAzYop2y0f9xdEhQQsxlIVK/yXh80EE6N6YGrnv3/IpA4AUosMh407QOeC9hx4Ujyr/g9K2CkvhQj/vWB2DIfHzTKt+ZsrfFajrXXHc3POwsftMLDYUJoZa0CMZS6A/ZSc16hsj/yeLEbNU48Jt6TYcdR0iyMjhYsSqvtVl9X74H1I41z+3IFr57oqftYq2JxmFNk6cnuIAbt8hRdyuQgrCO9mpHUXbQvbGAnw574rKl3ufwUACgFPzmPVQgaE X-Forefront-PRVS: 0972DEC1D9 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR07MB0912; 23:FtcEnR5P5T7qHwxVbLJBfM7WUurc4RTVZ2xdUNjK9?= =?us-ascii?Q?9yUU/Qapen/5596akoG9KLCHn3CPEsNMoezVtpAv0dMHTg9DjPUhFNi/A4W1?= =?us-ascii?Q?DvlGYiYYzk7Bk0Lfs5/yeATBAKygS2oFmFsFWttCghS+jRB4JbPSS0Gqk0bm?= =?us-ascii?Q?HQZIOQvgW8g+9igZYLnrxuVQI4fxhDCRSC+CPOQMEcA8ZGWNAbyRZ5cNrPG8?= =?us-ascii?Q?5l3P+iEtgb6+IdGejECTly84l3kJADLuLgm1qFFo70xD+ygnfweXY5/8KeWX?= =?us-ascii?Q?TwefTaKndO8/+gLYk/tIfLCUwdl8EfTIauLHNSafg210yyDHoXgETYaKkrhm?= =?us-ascii?Q?fwt9HS/5oek6wHiqv/diceMKD2inoTK1cze/ED6UFfRNWdDMyPSAfgiKjZf6?= =?us-ascii?Q?xH/6ieZOBWL06SPB6FGVr4lVbCC75NCGYhXMLZkJFLVIK4bPlxe0DD+IqjRy?= =?us-ascii?Q?Ma1DbojsyW7qa3Tq0d1T4DqOOP9dVQqQhy/Dw2bHZH7fb3Rx4D5TgCVIPKlK?= =?us-ascii?Q?7Qg5xJexszvYOdjTUvnl9tbN6R9lrBgF3XM2k5fhd3iw0jv+lUHau051/c9/?= =?us-ascii?Q?DDgYekMgXbIotBCn6BAUbnWjWvJ1tkPWIexnvH/eAgOO9qZKFcmCzQj3VkCv?= =?us-ascii?Q?bd0P0Z9m/Ip+QcQBq5p7nHdGafBgvBgGElV1U9S71jW5SWqIkH0d8NSksBx9?= =?us-ascii?Q?zGge/IS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tPLELkWAPEZcaJRrK+3jV/LvH/OcRHmtiW04zXeC3uHwvOcN5g=; 7:v8kDU9yTi+bkwEKZFpPG+bNZ+acvEF6kY6poPQkZYgWuqt+9vz0JCGpT4c0fGQz2/lThet9t15pgvQ9AaQIPp53IRwZjVt5c/RLjBq5TTZyVf9O21NLmabXJGoVUAwjUocjJqjr51LSkNfESaP12Mqycl5E6pOX2AY/txWDw+kxIpiuTIpjK19E4nGi+Opt9ltOOUhhLV5NEmbF8fYJY8XgCKOO1jITBjZMDbTW+v6k= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2016 10:49:35.3487 (UTC) X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5d471751-9675-428d-917b-70f44f9630b0; Ip=[131.228.2.241]; Helo=[mailrelay.int.nokia.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR07MB0912 X-Topics: patch Subject: [lng-odp] [PATCH v2 2/3] linux-gen: packet: use packet_parser_t type argument with parser functions X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Modify packet parser functions to utilize new packet_parser_t structure. Renamed the main parser function _odp_parse_common() to packet_parse_common(). packet_parse_common() now takes also segment length as argument. Signed-off-by: Matias Elo --- .../include/odp_classification_internal.h | 5 +- .../linux-generic/include/odp_packet_internal.h | 12 +- platform/linux-generic/odp_classification.c | 12 +- platform/linux-generic/odp_packet.c | 174 +++++++++++---------- platform/linux-generic/pktio/dpdk.c | 5 +- platform/linux-generic/pktio/loop.c | 11 +- platform/linux-generic/pktio/netmap.c | 4 +- platform/linux-generic/pktio/pcap.c | 2 +- platform/linux-generic/pktio/socket.c | 4 +- platform/linux-generic/pktio/socket_mmap.c | 4 +- platform/linux-generic/pktio/tap.c | 2 +- 11 files changed, 132 insertions(+), 103 deletions(-) diff --git a/platform/linux-generic/include/odp_classification_internal.h b/platform/linux-generic/include/odp_classification_internal.h index d6d6904..78eaac9 100644 --- a/platform/linux-generic/include/odp_classification_internal.h +++ b/platform/linux-generic/include/odp_classification_internal.h @@ -47,8 +47,9 @@ Start function for Packet Classifier This function calls Classifier module internal functions for a given packet and selects destination queue and packet pool based on selected PMR and CoS. **/ -int cls_classify_packet(pktio_entry_t *entry, const uint8_t *base, uint16_t len, - odp_pool_t *pool, odp_packet_hdr_t *pkt_hdr); +int cls_classify_packet(pktio_entry_t *entry, const uint8_t *base, + uint16_t pkt_len, uint32_t seg_len, odp_pool_t *pool, + odp_packet_hdr_t *pkt_hdr); /** Packet IO classifier init diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index 99de9f9..6ba2a2d 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -29,6 +29,9 @@ extern "C" { #define PACKET_JUMBO_LEN (9 * 1024) +/** Minimum segment length expected by packet_parse_common() */ +#define PACKET_PARSE_SEG_LEN 96 + /** * Packet input & protocol flags */ @@ -287,9 +290,9 @@ static inline void packet_set_len(odp_packet_t pkt, uint32_t len) odp_packet_hdr(pkt)->frame_len = len; } -static inline int packet_parse_l2_not_done(odp_packet_hdr_t *pkt_hdr) +static inline int packet_parse_l2_not_done(packet_parser_t *prs) { - return !pkt_hdr->p.input_flags.parsed_l2; + return !prs->input_flags.parsed_l2; } static inline int packet_parse_not_complete(odp_packet_hdr_t *pkt_hdr) @@ -303,7 +306,7 @@ void _odp_packet_copy_md_to_packet(odp_packet_t srcpkt, odp_packet_t dstpkt); odp_packet_t packet_alloc(odp_pool_t pool_hdl, uint32_t len, int parse); /* Fill in parser metadata for L2 */ -void packet_parse_l2(odp_packet_hdr_t *pkt_hdr); +void packet_parse_l2(packet_parser_t *prs, uint32_t frame_len); /* Perform full packet parse */ int packet_parse_full(odp_packet_hdr_t *pkt_hdr); @@ -340,7 +343,8 @@ static inline void packet_set_ts(odp_packet_hdr_t *pkt_hdr, odp_time_t *ts) } } -int _odp_parse_common(odp_packet_hdr_t *pkt_hdr, const uint8_t *parseptr); +int packet_parse_common(packet_parser_t *pkt_hdr, const uint8_t *ptr, + uint32_t pkt_len, uint32_t seg_len); int _odp_cls_parse(odp_packet_hdr_t *pkt_hdr, const uint8_t *parseptr); diff --git a/platform/linux-generic/odp_classification.c b/platform/linux-generic/odp_classification.c index 15fe9a8..61a4836 100644 --- a/platform/linux-generic/odp_classification.c +++ b/platform/linux-generic/odp_classification.c @@ -799,7 +799,8 @@ static inline cos_t *cls_select_cos(pktio_entry_t *entry, * * @param pktio_entry Ingress pktio * @param base Packet data - * @param len Packet length + * @param pkt_len Packet length + * @param seg_leg Segment length * @param pool[out] Packet pool * @param pkt_hdr[out] Packet header * @@ -809,15 +810,16 @@ static inline cos_t *cls_select_cos(pktio_entry_t *entry, * * @note *base is not released */ -int cls_classify_packet(pktio_entry_t *entry, const uint8_t *base, uint16_t len, - odp_pool_t *pool, odp_packet_hdr_t *pkt_hdr) +int cls_classify_packet(pktio_entry_t *entry, const uint8_t *base, + uint16_t pkt_len, uint32_t seg_len, odp_pool_t *pool, + odp_packet_hdr_t *pkt_hdr) { cos_t *cos; packet_parse_reset(pkt_hdr); - pkt_hdr->frame_len = len; + pkt_hdr->frame_len = pkt_len; - _odp_parse_common(pkt_hdr, base); + packet_parse_common(&pkt_hdr->p, base, pkt_len, seg_len); cos = cls_select_cos(entry, base, pkt_hdr); if (cos == NULL) diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 991a648..c319833 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -992,8 +992,8 @@ void _odp_packet_copy_md_to_packet(odp_packet_t srcpkt, odp_packet_t dstpkt) /** * Parser helper function for IPv4 */ -static inline uint8_t parse_ipv4(odp_packet_hdr_t *pkt_hdr, - const uint8_t **parseptr, uint32_t *offset) +static inline uint8_t parse_ipv4(packet_parser_t *prs, const uint8_t **parseptr, + uint32_t *offset, uint32_t frame_len) { const odph_ipv4hdr_t *ipv4 = (const odph_ipv4hdr_t *)*parseptr; uint8_t ver = ODPH_IPV4HDR_VER(ipv4->ver_ihl); @@ -1001,12 +1001,12 @@ static inline uint8_t parse_ipv4(odp_packet_hdr_t *pkt_hdr, uint16_t frag_offset; uint32_t dstaddr = odp_be_to_cpu_32(ipv4->dst_addr); - pkt_hdr->p.l3_len = odp_be_to_cpu_16(ipv4->tot_len); + prs->l3_len = odp_be_to_cpu_16(ipv4->tot_len); if (odp_unlikely(ihl < ODPH_IPV4HDR_IHL_MIN) || odp_unlikely(ver != 4) || - (pkt_hdr->p.l3_len > pkt_hdr->frame_len - *offset)) { - pkt_hdr->p.error_flags.ip_err = 1; + (prs->l3_len > frame_len - *offset)) { + prs->error_flags.ip_err = 1; return 0; } @@ -1014,7 +1014,7 @@ static inline uint8_t parse_ipv4(odp_packet_hdr_t *pkt_hdr, *parseptr += ihl * 4; if (odp_unlikely(ihl > ODPH_IPV4HDR_IHL_MIN)) - pkt_hdr->p.input_flags.ipopt = 1; + prs->input_flags.ipopt = 1; /* A packet is a fragment if: * "more fragments" flag is set (all fragments except the last) @@ -1023,11 +1023,11 @@ static inline uint8_t parse_ipv4(odp_packet_hdr_t *pkt_hdr, */ frag_offset = odp_be_to_cpu_16(ipv4->frag_offset); if (odp_unlikely(ODPH_IPV4HDR_IS_FRAGMENT(frag_offset))) - pkt_hdr->p.input_flags.ipfrag = 1; + prs->input_flags.ipfrag = 1; /* Handle IPv4 broadcast / multicast */ - pkt_hdr->p.input_flags.ip_bcast = (dstaddr == 0xffffffff); - pkt_hdr->p.input_flags.ip_mcast = (dstaddr >> 28) == 0xd; + prs->input_flags.ip_bcast = (dstaddr == 0xffffffff); + prs->input_flags.ip_mcast = (dstaddr >> 28) == 0xd; return ipv4->proto; } @@ -1035,26 +1035,27 @@ static inline uint8_t parse_ipv4(odp_packet_hdr_t *pkt_hdr, /** * Parser helper function for IPv6 */ -static inline uint8_t parse_ipv6(odp_packet_hdr_t *pkt_hdr, - const uint8_t **parseptr, uint32_t *offset) +static inline uint8_t parse_ipv6(packet_parser_t *prs, const uint8_t **parseptr, + uint32_t *offset, uint32_t frame_len, + uint32_t seg_len) { const odph_ipv6hdr_t *ipv6 = (const odph_ipv6hdr_t *)*parseptr; const odph_ipv6hdr_ext_t *ipv6ext; uint32_t dstaddr0 = odp_be_to_cpu_32(ipv6->dst_addr[0]); - pkt_hdr->p.l3_len = odp_be_to_cpu_16(ipv6->payload_len) + + prs->l3_len = odp_be_to_cpu_16(ipv6->payload_len) + ODPH_IPV6HDR_LEN; /* Basic sanity checks on IPv6 header */ if ((odp_be_to_cpu_32(ipv6->ver_tc_flow) >> 28) != 6 || - pkt_hdr->p.l3_len > pkt_hdr->frame_len - *offset) { - pkt_hdr->p.error_flags.ip_err = 1; + prs->l3_len > frame_len - *offset) { + prs->error_flags.ip_err = 1; return 0; } /* IPv6 broadcast / multicast flags */ - pkt_hdr->p.input_flags.ip_mcast = (dstaddr0 & 0xff000000) == 0xff000000; - pkt_hdr->p.input_flags.ip_bcast = 0; + prs->input_flags.ip_mcast = (dstaddr0 & 0xff000000) == 0xff000000; + prs->input_flags.ip_bcast = 0; /* Skip past IPv6 header */ *offset += sizeof(odph_ipv6hdr_t); @@ -1063,7 +1064,7 @@ static inline uint8_t parse_ipv6(odp_packet_hdr_t *pkt_hdr, /* Skip past any IPv6 extension headers */ if (ipv6->next_hdr == ODPH_IPPROTO_HOPOPTS || ipv6->next_hdr == ODPH_IPPROTO_ROUTE) { - pkt_hdr->p.input_flags.ipopt = 1; + prs->input_flags.ipopt = 1; do { ipv6ext = (const odph_ipv6hdr_ext_t *)*parseptr; @@ -1073,23 +1074,23 @@ static inline uint8_t parse_ipv6(odp_packet_hdr_t *pkt_hdr, *parseptr += extlen; } while ((ipv6ext->next_hdr == ODPH_IPPROTO_HOPOPTS || ipv6ext->next_hdr == ODPH_IPPROTO_ROUTE) && - *offset < pkt_hdr->frame_len); + *offset < seg_len); - if (*offset >= pkt_hdr->p.l3_offset + + if (*offset >= prs->l3_offset + odp_be_to_cpu_16(ipv6->payload_len)) { - pkt_hdr->p.error_flags.ip_err = 1; + prs->error_flags.ip_err = 1; return 0; } if (ipv6ext->next_hdr == ODPH_IPPROTO_FRAG) - pkt_hdr->p.input_flags.ipfrag = 1; + prs->input_flags.ipfrag = 1; return ipv6ext->next_hdr; } if (odp_unlikely(ipv6->next_hdr == ODPH_IPPROTO_FRAG)) { - pkt_hdr->p.input_flags.ipopt = 1; - pkt_hdr->p.input_flags.ipfrag = 1; + prs->input_flags.ipopt = 1; + prs->input_flags.ipfrag = 1; } return ipv6->next_hdr; @@ -1098,18 +1099,18 @@ static inline uint8_t parse_ipv6(odp_packet_hdr_t *pkt_hdr, /** * Parser helper function for TCP */ -static inline void parse_tcp(odp_packet_hdr_t *pkt_hdr, +static inline void parse_tcp(packet_parser_t *prs, const uint8_t **parseptr, uint32_t *offset) { const odph_tcphdr_t *tcp = (const odph_tcphdr_t *)*parseptr; if (tcp->hl < sizeof(odph_tcphdr_t) / sizeof(uint32_t)) - pkt_hdr->p.error_flags.tcp_err = 1; + prs->error_flags.tcp_err = 1; else if ((uint32_t)tcp->hl * 4 > sizeof(odph_tcphdr_t)) - pkt_hdr->p.input_flags.tcpopt = 1; + prs->input_flags.tcpopt = 1; - pkt_hdr->p.l4_len = pkt_hdr->p.l3_len + - pkt_hdr->p.l3_offset - pkt_hdr->p.l4_offset; + prs->l4_len = prs->l3_len + + prs->l3_offset - prs->l4_offset; if (offset) *offset += (uint32_t)tcp->hl * 4; @@ -1119,19 +1120,19 @@ static inline void parse_tcp(odp_packet_hdr_t *pkt_hdr, /** * Parser helper function for UDP */ -static inline void parse_udp(odp_packet_hdr_t *pkt_hdr, +static inline void parse_udp(packet_parser_t *prs, const uint8_t **parseptr, uint32_t *offset) { const odph_udphdr_t *udp = (const odph_udphdr_t *)*parseptr; uint32_t udplen = odp_be_to_cpu_16(udp->length); if (udplen < sizeof(odph_udphdr_t) || - udplen > (pkt_hdr->p.l3_len + - pkt_hdr->p.l4_offset - pkt_hdr->p.l3_offset)) { - pkt_hdr->p.error_flags.udp_err = 1; + udplen > (prs->l3_len + + prs->l4_offset - prs->l3_offset)) { + prs->error_flags.udp_err = 1; } - pkt_hdr->p.l4_len = udplen; + prs->l4_len = udplen; if (offset) *offset += sizeof(odph_udphdr_t); @@ -1141,43 +1142,49 @@ static inline void parse_udp(odp_packet_hdr_t *pkt_hdr, /** * Initialize L2 related parser flags and metadata */ -void packet_parse_l2(odp_packet_hdr_t *pkt_hdr) +void packet_parse_l2(packet_parser_t *prs, uint32_t frame_len) { /* Packet alloc or reset have already init other offsets and flags */ /* We only support Ethernet for now */ - pkt_hdr->p.input_flags.eth = 1; + prs->input_flags.eth = 1; /* Detect jumbo frames */ - if (pkt_hdr->frame_len > ODPH_ETH_LEN_MAX) - pkt_hdr->p.input_flags.jumbo = 1; + if (frame_len > ODPH_ETH_LEN_MAX) + prs->input_flags.jumbo = 1; /* Assume valid L2 header, no CRC/FCS check in SW */ - pkt_hdr->p.input_flags.l2 = 1; + prs->input_flags.l2 = 1; - pkt_hdr->p.input_flags.parsed_l2 = 1; + prs->input_flags.parsed_l2 = 1; } -int _odp_parse_common(odp_packet_hdr_t *pkt_hdr, const uint8_t *ptr) +/** + * Parse common packet headers + * + * The function expects at least PACKET_PARSE_SEG_LEN bytes of data to be + * available from the ptr. + */ +int packet_parse_common(packet_parser_t *prs, const uint8_t *ptr, + uint32_t frame_len, uint32_t seg_len) { const odph_ethhdr_t *eth; const odph_vlanhdr_t *vlan; uint16_t ethtype; - uint32_t offset, seglen; + uint32_t offset; uint8_t ip_proto = 0; const uint8_t *parseptr; uint16_t macaddr0, macaddr2, macaddr4; offset = sizeof(odph_ethhdr_t); - if (packet_parse_l2_not_done(pkt_hdr)) - packet_parse_l2(pkt_hdr); + if (packet_parse_l2_not_done(prs)) + packet_parse_l2(prs, frame_len); - eth = ptr ? (const odph_ethhdr_t *)ptr : - (odph_ethhdr_t *)packet_map(pkt_hdr, 0, &seglen); + eth = (const odph_ethhdr_t *)ptr; /* Handle Ethernet broadcast/multicast addresses */ macaddr0 = odp_be_to_cpu_16(*((const uint16_t *)(const void *)eth)); - pkt_hdr->p.input_flags.eth_mcast = (macaddr0 & 0x0100) == 0x0100; + prs->input_flags.eth_mcast = (macaddr0 & 0x0100) == 0x0100; if (macaddr0 == 0xffff) { macaddr2 = @@ -1186,10 +1193,10 @@ int _odp_parse_common(odp_packet_hdr_t *pkt_hdr, const uint8_t *ptr) macaddr4 = odp_be_to_cpu_16(*((const uint16_t *) (const void *)eth + 2)); - pkt_hdr->p.input_flags.eth_bcast = + prs->input_flags.eth_bcast = (macaddr2 == 0xffff) && (macaddr4 == 0xffff); } else { - pkt_hdr->p.input_flags.eth_bcast = 0; + prs->input_flags.eth_bcast = 0; } /* Get Ethertype */ @@ -1198,9 +1205,9 @@ int _odp_parse_common(odp_packet_hdr_t *pkt_hdr, const uint8_t *ptr) /* Check for SNAP vs. DIX */ if (ethtype < ODPH_ETH_LEN_MAX) { - pkt_hdr->p.input_flags.snap = 1; - if (ethtype > pkt_hdr->frame_len - offset) { - pkt_hdr->p.error_flags.snap_len = 1; + prs->input_flags.snap = 1; + if (ethtype > frame_len - offset) { + prs->error_flags.snap_len = 1; goto parse_exit; } ethtype = odp_be_to_cpu_16(*((const uint16_t *) @@ -1211,8 +1218,8 @@ int _odp_parse_common(odp_packet_hdr_t *pkt_hdr, const uint8_t *ptr) /* Parse the VLAN header(s), if present */ if (ethtype == ODPH_ETHTYPE_VLAN_OUTER) { - pkt_hdr->p.input_flags.vlan_qinq = 1; - pkt_hdr->p.input_flags.vlan = 1; + prs->input_flags.vlan_qinq = 1; + prs->input_flags.vlan = 1; vlan = (const odph_vlanhdr_t *)parseptr; ethtype = odp_be_to_cpu_16(vlan->type); @@ -1221,7 +1228,7 @@ int _odp_parse_common(odp_packet_hdr_t *pkt_hdr, const uint8_t *ptr) } if (ethtype == ODPH_ETHTYPE_VLAN) { - pkt_hdr->p.input_flags.vlan = 1; + prs->input_flags.vlan = 1; vlan = (const odph_vlanhdr_t *)parseptr; ethtype = odp_be_to_cpu_16(vlan->type); offset += sizeof(odph_vlanhdr_t); @@ -1229,71 +1236,76 @@ int _odp_parse_common(odp_packet_hdr_t *pkt_hdr, const uint8_t *ptr) } /* Set l3_offset+flag only for known ethtypes */ - pkt_hdr->p.input_flags.l3 = 1; - pkt_hdr->p.l3_offset = offset; + prs->input_flags.l3 = 1; + prs->l3_offset = offset; /* Parse Layer 3 headers */ switch (ethtype) { case ODPH_ETHTYPE_IPV4: - pkt_hdr->p.input_flags.ipv4 = 1; - ip_proto = parse_ipv4(pkt_hdr, &parseptr, &offset); + prs->input_flags.ipv4 = 1; + ip_proto = parse_ipv4(prs, &parseptr, &offset, frame_len); break; case ODPH_ETHTYPE_IPV6: - pkt_hdr->p.input_flags.ipv6 = 1; - ip_proto = parse_ipv6(pkt_hdr, &parseptr, &offset); + prs->input_flags.ipv6 = 1; + ip_proto = parse_ipv6(prs, &parseptr, &offset, frame_len, + seg_len); break; case ODPH_ETHTYPE_ARP: - pkt_hdr->p.input_flags.arp = 1; + prs->input_flags.arp = 1; ip_proto = 255; /* Reserved invalid by IANA */ break; default: - pkt_hdr->p.input_flags.l3 = 0; - pkt_hdr->p.l3_offset = ODP_PACKET_OFFSET_INVALID; + prs->input_flags.l3 = 0; + prs->l3_offset = ODP_PACKET_OFFSET_INVALID; ip_proto = 255; /* Reserved invalid by IANA */ } /* Set l4_offset+flag only for known ip_proto */ - pkt_hdr->p.input_flags.l4 = 1; - pkt_hdr->p.l4_offset = offset; + prs->input_flags.l4 = 1; + prs->l4_offset = offset; /* Parse Layer 4 headers */ switch (ip_proto) { case ODPH_IPPROTO_ICMP: - pkt_hdr->p.input_flags.icmp = 1; + prs->input_flags.icmp = 1; break; case ODPH_IPPROTO_TCP: - pkt_hdr->p.input_flags.tcp = 1; - parse_tcp(pkt_hdr, &parseptr, NULL); + if (odp_unlikely(offset + ODPH_TCPHDR_LEN > seg_len)) + return -1; + prs->input_flags.tcp = 1; + parse_tcp(prs, &parseptr, NULL); break; case ODPH_IPPROTO_UDP: - pkt_hdr->p.input_flags.udp = 1; - parse_udp(pkt_hdr, &parseptr, NULL); + if (odp_unlikely(offset + ODPH_UDPHDR_LEN > seg_len)) + return -1; + prs->input_flags.udp = 1; + parse_udp(prs, &parseptr, NULL); break; case ODPH_IPPROTO_AH: - pkt_hdr->p.input_flags.ipsec = 1; - pkt_hdr->p.input_flags.ipsec_ah = 1; + prs->input_flags.ipsec = 1; + prs->input_flags.ipsec_ah = 1; break; case ODPH_IPPROTO_ESP: - pkt_hdr->p.input_flags.ipsec = 1; - pkt_hdr->p.input_flags.ipsec_esp = 1; + prs->input_flags.ipsec = 1; + prs->input_flags.ipsec_esp = 1; break; default: - pkt_hdr->p.input_flags.l4 = 0; - pkt_hdr->p.l4_offset = ODP_PACKET_OFFSET_INVALID; + prs->input_flags.l4 = 0; + prs->l4_offset = ODP_PACKET_OFFSET_INVALID; break; } parse_exit: - pkt_hdr->p.input_flags.parsed_all = 1; - return pkt_hdr->p.error_flags.all != 0; + prs->input_flags.parsed_all = 1; + return prs->error_flags.all != 0; } /** @@ -1301,5 +1313,9 @@ parse_exit: */ int packet_parse_full(odp_packet_hdr_t *pkt_hdr) { - return _odp_parse_common(pkt_hdr, NULL); + uint32_t seg_len; + void *base = packet_map(pkt_hdr, 0, &seg_len); + + return packet_parse_common(&pkt_hdr->p, base, pkt_hdr->frame_len, + seg_len); } diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c index e2b3aec..09ea6fc 100644 --- a/platform/linux-generic/pktio/dpdk.c +++ b/platform/linux-generic/pktio/dpdk.c @@ -724,7 +724,8 @@ static inline int mbuf_to_pkt(pktio_entry_t *pktio_entry, if (pktio_cls_enabled(pktio_entry)) { if (cls_classify_packet(pktio_entry, (const uint8_t *)buf, - pkt_len, &pool, &parsed_hdr)) + pkt_len, pkt_len, &pool, + &parsed_hdr)) goto fail; } pkt = packet_alloc(pool, pkt_len, 1); @@ -744,7 +745,7 @@ static inline int mbuf_to_pkt(pktio_entry_t *pktio_entry, if (pktio_cls_enabled(pktio_entry)) copy_packet_cls_metadata(&parsed_hdr, pkt_hdr); else - packet_parse_l2(pkt_hdr); + packet_parse_l2(&pkt_hdr->p, pkt_len); if (mbuf->ol_flags & PKT_RX_RSS_HASH) odp_packet_flow_hash_set(pkt, mbuf->hash.rss); diff --git a/platform/linux-generic/pktio/loop.c b/platform/linux-generic/pktio/loop.c index 2fb88e2..e0b2ed4 100644 --- a/platform/linux-generic/pktio/loop.c +++ b/platform/linux-generic/pktio/loop.c @@ -77,7 +77,11 @@ static int loopback_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED, } for (i = 0; i < nbr; i++) { + uint32_t pkt_len; + pkt = _odp_packet_from_buffer(odp_hdr_to_buf(hdr_tbl[i])); + pkt_len = odp_packet_len(pkt); + if (pktio_cls_enabled(pktio_entry)) { odp_packet_t new_pkt; @@ -87,7 +91,8 @@ static int loopback_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED, pkt_addr = odp_packet_data(pkt); ret = cls_classify_packet(pktio_entry, pkt_addr, - odp_packet_len(pkt), + pkt_len, + odp_packet_seg_len(pkt), &new_pool, &parsed_hdr); if (ret) { failed++; @@ -113,11 +118,11 @@ static int loopback_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED, if (pktio_cls_enabled(pktio_entry)) copy_packet_cls_metadata(&parsed_hdr, pkt_hdr); else - packet_parse_l2(pkt_hdr); + packet_parse_l2(&pkt_hdr->p, pkt_len); packet_set_ts(pkt_hdr, ts); - pktio_entry->s.stats.in_octets += odp_packet_len(pkt); + pktio_entry->s.stats.in_octets += pkt_len; pkts[num_rx++] = pkt; } diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c index d189aae..6d2cc78 100644 --- a/platform/linux-generic/pktio/netmap.c +++ b/platform/linux-generic/pktio/netmap.c @@ -610,7 +610,7 @@ static inline int netmap_pkt_to_odp(pktio_entry_t *pktio_entry, if (pktio_cls_enabled(pktio_entry)) { if (cls_classify_packet(pktio_entry, (const uint8_t *)buf, len, - &pool, &parsed_hdr)) + len, &pool, &parsed_hdr)) return -1; } pkt = packet_alloc(pool, len, 1); @@ -630,7 +630,7 @@ static inline int netmap_pkt_to_odp(pktio_entry_t *pktio_entry, if (pktio_cls_enabled(pktio_entry)) copy_packet_cls_metadata(&parsed_hdr, pkt_hdr); else - packet_parse_l2(pkt_hdr); + packet_parse_l2(&pkt_hdr->p, len); packet_set_ts(pkt_hdr, ts); diff --git a/platform/linux-generic/pktio/pcap.c b/platform/linux-generic/pktio/pcap.c index b719849..08d5f80 100644 --- a/platform/linux-generic/pktio/pcap.c +++ b/platform/linux-generic/pktio/pcap.c @@ -262,7 +262,7 @@ static int pcapif_recv_pkt(pktio_entry_t *pktio_entry, int index ODP_UNUSED, break; } - packet_parse_l2(pkt_hdr); + packet_parse_l2(&pkt_hdr->p, pkt_len); pktio_entry->s.stats.in_octets += pkt_hdr->frame_len; packet_set_ts(pkt_hdr, ts); diff --git a/platform/linux-generic/pktio/socket.c b/platform/linux-generic/pktio/socket.c index b116145..8f86dda 100644 --- a/platform/linux-generic/pktio/socket.c +++ b/platform/linux-generic/pktio/socket.c @@ -664,7 +664,7 @@ static int sock_mmsg_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED, continue; if (cls_classify_packet(pktio_entry, base, pkt_len, - &pool, &parsed_hdr)) + pkt_len, &pool, &parsed_hdr)) continue; pkt = packet_alloc(pool, pkt_len, 1); if (pkt == ODP_PACKET_INVALID) @@ -724,7 +724,7 @@ static int sock_mmsg_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED, odp_packet_pull_tail(pkt_table[i], odp_packet_len(pkt_table[i]) - msgvec[i].msg_len); - packet_parse_l2(pkt_hdr); + packet_parse_l2(&pkt_hdr->p, pkt_hdr->frame_len); packet_set_ts(pkt_hdr, ts); pkt_hdr->input = pktio_entry->s.handle; diff --git a/platform/linux-generic/pktio/socket_mmap.c b/platform/linux-generic/pktio/socket_mmap.c index 30c44e9..420cd26 100644 --- a/platform/linux-generic/pktio/socket_mmap.c +++ b/platform/linux-generic/pktio/socket_mmap.c @@ -199,7 +199,7 @@ static inline unsigned pkt_mmap_v2_rx(pktio_entry_t *pktio_entry, if (pktio_cls_enabled(pktio_entry)) { if (cls_classify_packet(pktio_entry, pkt_buf, pkt_len, - &pool, &parsed_hdr)) { + pkt_len, &pool, &parsed_hdr)) { mmap_rx_user_ready(ppd.raw); /* drop */ frame_num = next_frame_num; continue; @@ -226,7 +226,7 @@ static inline unsigned pkt_mmap_v2_rx(pktio_entry_t *pktio_entry, if (pktio_cls_enabled(pktio_entry)) copy_packet_cls_metadata(&parsed_hdr, hdr); else - packet_parse_l2(hdr); + packet_parse_l2(&hdr->p, pkt_len); packet_set_ts(hdr, ts); diff --git a/platform/linux-generic/pktio/tap.c b/platform/linux-generic/pktio/tap.c index 975ad25..8ba7bed 100644 --- a/platform/linux-generic/pktio/tap.c +++ b/platform/linux-generic/pktio/tap.c @@ -197,7 +197,7 @@ static odp_packet_t pack_odp_pkt(pktio_entry_t *pktio_entry, const void *data, } pkt_hdr = odp_packet_hdr(pkt); - packet_parse_l2(pkt_hdr); + packet_parse_l2(&pkt_hdr->p, len); packet_set_ts(pkt_hdr, ts); pkt_hdr->input = pktio_entry->s.handle;