From patchwork Fri Jun 10 14:54:27 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: 69782 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp336343qgf; Fri, 10 Jun 2016 07:55:17 -0700 (PDT) X-Received: by 10.140.218.79 with SMTP id o76mr2296215qhb.83.1465570517202; Fri, 10 Jun 2016 07:55:17 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id j13si6465857qkh.172.2016.06.10.07.55.16; Fri, 10 Jun 2016 07:55:17 -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 8FF4B68143; Fri, 10 Jun 2016 14:55:16 +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 B462B6813A; Fri, 10 Jun 2016 14:55:04 +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 E65E56813A; Fri, 10 Jun 2016 14:55:00 +0000 (UTC) Received: from emea01-db3-obe.outbound.protection.outlook.com (mail-db3on0122.outbound.protection.outlook.com [157.55.234.122]) by lists.linaro.org (Postfix) with ESMTPS id 9F33768131 for ; Fri, 10 Jun 2016 14:54:58 +0000 (UTC) Received: from AMXPR07CA0023.eurprd07.prod.outlook.com (10.242.64.23) by HE1PR07MB1516.eurprd07.prod.outlook.com (10.169.122.150) with Microsoft SMTP Server (TLS) id 15.1.511.8; Fri, 10 Jun 2016 14:54:56 +0000 Received: from AM1FFO11OLC010.protection.gbl (2a01:111:f400:7e00::146) by AMXPR07CA0023.outlook.office365.com (2a01:111:e400:1000::23) with Microsoft SMTP Server (TLS) id 15.1.517.8 via Frontend Transport; Fri, 10 Jun 2016 14:54:56 +0000 Received-SPF: Pass (protection.outlook.com: domain of nokia.com designates 131.228.2.240 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.2.240; helo=mailrelay.int.nokia.com; Received: from mailrelay.int.nokia.com (131.228.2.240) by AM1FFO11OLC010.mail.protection.outlook.com (10.174.65.124) with Microsoft SMTP Server (TLS) id 15.1.497.8 via Frontend Transport; Fri, 10 Jun 2016 14:54:56 +0000 Received: from fihe3nok0734.emea.nsn-net.net (localhost [127.0.0.1]) by fihe3nok0734.emea.nsn-net.net (8.14.9/8.14.5) with ESMTP id u5AEsS71019594 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 10 Jun 2016 17:54:28 +0300 Received: from 10.144.19.15 ([10.144.104.109]) by fihe3nok0734.emea.nsn-net.net (8.14.9/8.14.5) with ESMTP id u5AEsR71019588 (version=TLSv1/SSLv3 cipher=AES256-SHA256 bits=256 verify=NO) for ; Fri, 10 Jun 2016 17:54:27 +0300 X-HPESVCS-Source-Ip: 10.144.104.109 From: Matias Elo To: Date: Fri, 10 Jun 2016 17:54:27 +0300 Message-ID: <1465570467-13225-2-git-send-email-matias.elo@nokia.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1465570467-13225-1-git-send-email-matias.elo@nokia.com> References: <1465570467-13225-1-git-send-email-matias.elo@nokia.com> X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:131.228.2.240; IPV:NLI; CTRY:FI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(438002)(199003)(189002)(33646002)(450100001)(5003940100001)(47776003)(16796002)(6806005)(229853001)(76176999)(8936002)(81166006)(8676002)(5008740100001)(2351001)(2906002)(50466002)(92566002)(36756003)(48376002)(106466001)(22756006)(50226002)(575784001)(2950100001)(107886002)(97736004)(11100500001)(81156014)(50986999)(586003)(189998001)(87936001)(19580405001)(68736007)(110136002)(77096005)(19580395003)(42882005); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1PR07MB1516; H:mailrelay.int.nokia.com; FPR:; SPF:Pass; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; AM1FFO11OLC010; 1:VBtzoYaFPRnhGtNmhDFqJ7TMEHhIImqcuyhPGySV6O+RlVgr8mwN6nHEyDLV/xCt5InAs72MSedzEFz1IPa5Sqx8XFpvPyzw2v2rCCCAWXzP30F09RPgyBRL1dCihDQdrcxoc7nCCtMJZRmm4BU/+tMvUa7tDmojF7TN42fAv2+VDT4Hyq+UsGfVLyBSjTwV1p8GYCraO6sq5vwoxWO3rJVBFnxJbGiKr8J7a5sANZVjZkbE1B3No5YxnalxLqqQgpXc3qe1TIjagPUidM1tFUrT4jcGdBDXIloAun+fi7meivQjboKKvlNH8mViiKRHOeRxSD8YY+RwbKJ1NaGiV7T3+EESDR424f+P8+sqe/Kpnnz0G6lgH8XYqP8hJgdDk6sWDt6S/6WpUyMe3qGU50NcjtBUNwQqD03pQxCRXZHDAayQwV9bT93npyGAVACryMurxjNjtKNnQ4E1fActuA== MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: b0422535-4b5f-4d4d-dd9b-08d3913f3010 X-Microsoft-Exchange-Diagnostics: 1; HE1PR07MB1516; 2:Rm5o1Sa/pl+8EDd6fYswfTv5t9y51Xl05McPLPpZDz4Q06r+MNjTfQY3Abs5rLXwnSboiOUoujVgG6I89ZKUXjdERNkwT2n4tDQHJDNA2Y1c02/vxgR59ZAFk6yq+fGWKyGB94zdnxp7Z6mYly/WJqmsfLe3BcEkQFGnRu6nmxVnsTZmtouTLmhnQ5C2fHRB; 3:14iGR2JFybflBUWnx1IWslo+ViVdKn59AbgxBxCrHb8p0rTww58M7FxDIDF8/xhm2NBpJp32QH1nEFoZnqDFQEgpzO6L9REbqs0tU4G4JDLiisvrRTmaDmYN4q8gzZlrvEOly97EKlIUDg5EkgRNOW5y1zBKMLmfsnLDbDBg4knmRIhhL+mRni8qFVq12htMKC8ZOl+0lbGPXUtt38JvnRhkTLrIr0mML3hfJJHmK/xn0zUfqdA/Xa1O/ZvvSC3K4vrBTeeXE59jYBx+MaPdgg==; 25:K9GLv3LJY8ESRP6CWnz9Kywn/YKKs7EbZANMYlwIBNSMMrdMJNJTjnX73T1MC82JIN8LtrTOO0zoMHmDOQCJdPBiTzjcvhD4JsmwmkQ0Bp6XmrmPlTgtyINtc+WHyrNEYYoHlaGzHvv8zG6kpIsJZrXXgFyvaBx+Jg7Z0JE99vVzq4yRcxeqNJSpDmKSW4G3jN/XGTfqwPwqF3Amw50RphspZZqtt3UK4kMAJx+zQvLLNJYlY2hdfBsbOSjecyB0GQOqn/KdKUjBQfzci0pll85mo2JZCBHuEN/Puy4hxTl4S1d5wLYVskM6ED+FHsZ0SuxPvtzB0kxVL12emaQg9EeAzJJhhPDVVLu+XAAbubnO5dgQgmpWQDdYP8tjhuIh6N1WkA5k4N9/6dYgv5zkmA07CE+IcOiQ+CQUUC0SUjY= X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(8251501002); SRVR:HE1PR07MB1516; X-Microsoft-Exchange-Diagnostics: 1; HE1PR07MB1516; 20:NG0UCHb6qTXSfKbQhsOis0T67czXF3e6Mdk7vT0KpKJQEyMIbUYko2L35b/ogtlfo13oUl6UfmkL/BHuvludiUHh8VKXS9cZvrPqLeZ8XWzzZhT6llvWXkz7YGrmvsvf1G4blDA7oIkth0u+y8jJvSHWkX53Splcir2URt/fGqXsNP+KFkJLws91cBHLLMz3TSOc/S0zp5ardMOBXrlOWZP5D6lnrl75PRVnSI9IVALuQmci3gPhMj74pn0jrsKh3s/yPDHvZyiHH10JIFtA5POX2lgxNbV/FCPz4sxRUQzasgynsIlUgULNKEoPb0NDwLWxVCIjqC1WRGaTOaBjOhscAULAjv5bvxvMbd3S5mTTBQA4V9Kf0Wq1MIMhbkIbcO3ZoJr1amW9H9BsoZKDWZIlXz8dbYOvxfZJe0F6SjrPY9b4blQSmk5PkaOh5+Vf+3pIMdbSoRkh4l0gdr9qrg35wSvkagQRHTX8GJ0eBAST2ZylBHKge5asquqgMk5rp4ir73AJKuHk8dOQxcdusfVmWQxHc2WrbnOBYDXOjpJI5cjgh8D6amVUavTIJ20DvY7N0RiGSiJ276iMphii0ML/UQUemwMb/OrsGxjFi2M= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(82608151540597); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(13016025)(8121501046)(13018025)(3002001)(10201501046); SRVR:HE1PR07MB1516; BCL:0; PCL:0; RULEID:; SRVR:HE1PR07MB1516; X-Microsoft-Exchange-Diagnostics: 1; HE1PR07MB1516; 4:OoVUWE7MmlyKm6smHOwa4+OkwJENBkiD5KvJ9ABBoGbZKW5FB270QZDqNZ+ii1gJBDhjSCVNQ2/ajoAhSy3Nx77bGmSq0oPhx8SmnifSpjQ0iyo18EGVQflXvAH3mWhOwmcCcdloodBH/0YHI8MCGpamEwjcE/vPnGOWdQotGYSBxMlA3S8TRgoGU7AHFtQdqf+HiV+6361es3Ym6r0MslET5B5SoT0aOV6cIP2yVximBkeez8OAN33I4XqunxvQigAxfp/jhvkxCtM/11sAIaT/9VibPjSujyaV7uZmZSu+AFWxkWPxgZ2FLzoSYKetjU0y1ylGvtkOVoAvUDMKfewGuQDnYvx9NE56qPrMxYfERn2IRy4+0imEpeVdlf7Cvw75LWXRz4bEfv2wltYO0+e2sJ6252y5waASSXUtRCSLLe3Djr2aPCvqYxeyNDFGd3OcmwTDXKu7n/FJg9Yjsw== X-Forefront-PRVS: 096943F07A X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR07MB1516; 23:mA3H6xoAlPSLhC2itHCiaTOqCog6653DXLR4Z7mOF?= =?us-ascii?Q?4EaBiv2bJsXIjMQU/o7AwcOhPDCKh55Jqr0xD7faCq6N8GnoaP4ubRvmHHFS?= =?us-ascii?Q?dUcLgMOwflyy+WIm59g+75JW7DOA7O6mYXLuksG8SdmOrcq+E1cwy5ZRyUDi?= =?us-ascii?Q?ZykPsGe/4wl5fSeKvOTW6YvVois416mA45H3xmysLf1zH1ZpVAc4r5pxQ4R1?= =?us-ascii?Q?+8Z1S/mAMg6D8MwFGJP8FWK8UCuAJVB8mMCRsoUmu5GDWUyUDN+9diXIZfsq?= =?us-ascii?Q?d1Hjb1QNpT562sjFK2KWpua6Kn4M4kEqgPMobtsxkiSs/1oFrGTz9jeAayZ0?= =?us-ascii?Q?uUCaJSvR3AlA1rxb10hpDprjsRdmlKW4Ct0EI4hsqfRh/tRb+oDoSDPBC4hN?= =?us-ascii?Q?zbYgrPfff5vBrEcH2n4h9m131/dE5240UZ/A+qe5pML9q4kUUB6ZI4SWS/6L?= =?us-ascii?Q?0yg1ifmWDfX/O8eELzg9p4hlN4p44dXXdtRuoZIvzAR4Vv0TzieDYsmCVRSY?= =?us-ascii?Q?L0THXDSaUlVbLvinwVBG6RuqkpMRRkUq3hrs7RyFfZyNjwlnuu0Yd0Qini7A?= =?us-ascii?Q?Kr+IjiaDCBRdzfVEHjmBekzbBYoCJZP9Rxu8zfSZtAvDYjkJYhNmukilfgYH?= =?us-ascii?Q?+j21UtbB1rbcU4HIu8i2p3xe8XgbujZwG597mkdDvCWZRJkFX5NOKnje3ffB?= =?us-ascii?Q?M1L8AykI959gX8Kol8XvLOCVbu+FzpTwyEtz57nu12Pqk0rHtATZoBomY/7/?= =?us-ascii?Q?s/qneYeueXFYkU4OeSrnosl8szlufl/lueXjxMVw/UjZMfogcJA3km4o31Mp?= =?us-ascii?Q?y5+hY3R4Ce9m5h8zhXeT5ZFLrReWOMAGP+6tScG8zVEqzCtIVC/288cuQG6X?= =?us-ascii?Q?/eF6ITYyBQb7UBAYCmi/o95JlxLDmhCY+zK0S+Z7djRLk+B/jqxfYTKrKXZ5?= =?us-ascii?Q?pdDNKds7oUHZTQtCWw9o8v1mamnY6LmB9weq0jIfvZwbrbB8W5wEnTE4ap72?= =?us-ascii?Q?LB9prmkw0/UrHw+4zartqko3iXjp2ei3ZeS60OHGHA3vNuxYinNF+XOjpUd/?= =?us-ascii?Q?TCT4d6IhNOie/BNlRZhqmkT7M3a0HKcEZiQUxmIPf34zjmdcQ=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; HE1PR07MB1516; 5:nIVGme7gk0lbJKaey08EsFpwTPdzzu7Jr3K9fdXPOd3epCe7I/3DiiqOqg3rsaCswaJv2N/FhsbVMcCv23qBL/o9kGFWq25vEk8giDilIU637RPBuC6mhQsVVNN7nbWXzk3fePoLSdRx0RMdug/Bdw==; 24:adg6Vq4QlOhPzk9YHxkMZjitRgrfc3NV4ITe8acEpmPyKGbbCwkAjpyBOIUlfQ8VVwLu4vttRvW5hxDlm2YNtpvnMps2VzVVYhOhV2WFju4=; 7:Fb9URmhlG4jPGGw4ugJr/KwbMVsaU3pZWFV5muzwcxAcrBcKoQzp/SL9jUky0/3PfSELnXsddHuGN56d8jT+K36Sh03eMS5ea7z4lswcGryAh1xgHts7RZkcENzuiRm5mVQ0tGiOKNQ6eqmop+8XrAVQle/vz90FpwgvmAX6E22MFjXR54wxCzr+eZ4P5EgsUpMbO8xvDOj59nsaeCqMxs1+hSUwEsKkZiEw3v1T8x4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2016 14:54:56.3346 (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.240]; Helo=[mailrelay.int.nokia.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR07MB1516 X-Topics: patch Subject: [lng-odp] [PATCH 2/2] linux-gen: packet: use packet_parser_t as main argument for 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_parser_common(). packet_parser_common() now takes also segment length as argument. Comprehensive segment overwrite checking not yet implemented. Signed-off-by: Matias Elo --- .../include/odp_classification_internal.h | 5 +- .../linux-generic/include/odp_packet_internal.h | 9 +- platform/linux-generic/odp_classification.c | 12 +- platform/linux-generic/odp_packet.c | 165 +++++++++++---------- 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, 120 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..91d5b2c 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -287,9 +287,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 +303,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 +340,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..d09f124 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,26 @@ 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) { 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 +1063,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 +1073,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 < frame_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 +1098,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 +1119,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 +1141,43 @@ 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) +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 +1186,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 +1198,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 +1211,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 +1221,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 +1229,74 @@ 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); 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 */ } + if (odp_unlikely(offset > seg_len)) + return -1; + /* 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); + 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); + 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 +1304,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;