From patchwork Thu Jun 16 10:31:10 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: 70173 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp186216qgy; Thu, 16 Jun 2016 03:32:00 -0700 (PDT) X-Received: by 10.55.108.2 with SMTP id h2mr3738409qkc.97.1466073119977; Thu, 16 Jun 2016 03:31:59 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id u68si25834734qka.142.2016.06.16.03.31.59; Thu, 16 Jun 2016 03:31:59 -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 A30DB6879C; Thu, 16 Jun 2016 10:31:59 +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 C6D4E61691; Thu, 16 Jun 2016 10:31:53 +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 D31A9616D2; Thu, 16 Jun 2016 10:31:51 +0000 (UTC) Received: from emea01-db3-obe.outbound.protection.outlook.com (mail-db3on0141.outbound.protection.outlook.com [157.55.234.141]) by lists.linaro.org (Postfix) with ESMTPS id AAEA561588 for ; Thu, 16 Jun 2016 10:31:50 +0000 (UTC) Received: from VI1PR07CA0080.eurprd07.prod.outlook.com (10.164.94.176) by HE1PR07MB1067.eurprd07.prod.outlook.com (10.163.177.141) with Microsoft SMTP Server (TLS) id 15.1.517.8; Thu, 16 Jun 2016 10:31:48 +0000 Received: from AM1FFO11OLC006.protection.gbl (2a01:111:f400:7e00::145) by VI1PR07CA0080.outlook.office365.com (2a01:111:e400:5967::48) with Microsoft SMTP Server (TLS) id 15.1.517.8 via Frontend Transport; Thu, 16 Jun 2016 10:31:48 +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 AM1FFO11OLC006.mail.protection.outlook.com (10.174.64.134) with Microsoft SMTP Server (TLS) id 15.1.511.7 via Frontend Transport; Thu, 16 Jun 2016 10:31:48 +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 u5GAVAPf008019 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 16 Jun 2016 13:31:10 +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 u5GAVA97008013 (version=TLSv1/SSLv3 cipher=AES128-SHA256 bits=128 verify=NOT) for ; Thu, 16 Jun 2016 13:31:10 +0300 X-HPESVCS-Source-Ip: 10.144.104.92 From: Matias Elo To: Date: Thu, 16 Jun 2016 13:31:10 +0300 Message-ID: <1466073070-20148-2-git-send-email-matias.elo@nokia.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1466073070-20148-1-git-send-email-matias.elo@nokia.com> References: <1466073070-20148-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)(33646002)(356003)(68736007)(77096005)(189998001)(586003)(5003940100001)(87936001)(2950100001)(97736004)(92566002)(47776003)(50466002)(50986999)(81166006)(50226002)(48376002)(8676002)(8936002)(450100001)(2906002)(110136002)(16796002)(107886002)(36756003)(22756006)(2351001)(229853001)(19580405001)(5008740100001)(81156014)(106466001)(11100500001)(6806005)(19580395003)(76176999)(42882005); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1PR07MB1067; 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; AM1FFO11OLC006; 1:oPdj61iDx3P+yLkRwtcWK9970tEUaTO9NbXZA1q68gT7QJQ7POKnhChGGudQIDgiNFCTa4n/r6/zXLDid4hlp0282LjkdVNFkuF/DlUs6tdLI9ao89dE1zdoCe+xeBory6GrxzIDyaHbBV44im+e3VE0/CyYHA8KORDX+5NSnRXZm2186aevzerKD/woMAsADvwAYNcyV+vr34sh7Q8JVXUd2GB11EvbU0PL6sCMHrkNC7EPHQNGoFGtLopZKUISU8da03rOZhJJkiLb7LUNc+vLRtEPnUHz+mAX2/lJN7yWK6bFmMl0r20UwdzpiZwoxmVCT2Y+wjye5x7hzNCVTt3jrPvVymkhsoVxveA9LwvqPiRBAgZfpy6yoiDnBQBkIpXS0cozCW2wqgprYmjX4VubOnbEJ8CNheG4dAGQxSc= MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 30ba9f21-1dc4-4158-f4be-08d395d16c04 X-Microsoft-Exchange-Diagnostics: 1; HE1PR07MB1067; 2:HJiGdvUB0RMG7ZOnPMNZdaKBpqhXTtEHm2+KP9m03ogfyO3L1Mzfd/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psE1ZSjKr6h0UTJNB28HcZOhj/8Auvu/YiCPlyQOOxw4jlhY+X+NOgpF+CY7S2Udg+aXmxXGxcLwCRfy/YqGlx0trdtBbrirlGcpJHMoih3lEaHQVbdPEyp5uJmaqKtIBNoFl/RduinZ+6sVUsTBIhhvJGRYZJQmIgvYtaeGpCvdj+Y1CJBwhFJrmWltwcA4kow6bCX60gkwuiGMwsugEWMxb0NPjR2R0WRWb+Jet5bw== X-Microsoft-Exchange-Diagnostics: 1; HE1PR07MB1067; 20:BRT3+SAh+ls+xcVv5d6PKHQ2OJIyxu1dvJ5t0FuVpT4SklbhaCYUUBncn2WUWN3Cq+L3sX+6fUBJgiHQ4jWs7MlZLi4ADhIvCj4+Up9BqNfE0fs/3n8d11e/6mzYolk2ZuxQfIZWqnelg3t+x3rltcv19iQQZHJ/0tdBBxzp75fqSnLYxbwo8rrQY5w7visSi7Eic+tqNUlLqBgxFPEVw+J1lAOnBjYdiLT+Tnuopy2J3k3f7qgqfDTfYgdniEp1YWOzeODHwosxMghRunFvGWFmS2TJlYg4uKYGk9+qON4fpmfUjlwxXk/Uy3QHNYuA+9SMKqKw1qGW0eURlZ7V4AOX5EXGUx32GepS5fjcEshx5xAADlcN9Ca5PgC0e4qYrXMioxbkMazQAexJUN928pjsAun+oH3iz7977W2axKtlhQ1AGQCOJLatuoFQGEjqHiF5Un0h6lqexqJA178O/o5mqh26QBSHgo6baT7p67tW1j4IGOyGfR72l9Z0o9c2+PZM7CAvOO4gthh/3alTkQir526gGQVMoULHbsV7O5+I69GsC3U3vQk0Oc0dibxHeDALeLzM1alCh7TEGckR/UxVZyy858V9kENP3xC8y5o= 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)(8121501046)(13018025)(13016025)(3002001)(10201501046); SRVR:HE1PR07MB1067; BCL:0; PCL:0; RULEID:; SRVR:HE1PR07MB1067; X-Microsoft-Exchange-Diagnostics: 1; HE1PR07MB1067; 4:lIHlrloCdwCzPOJAxCpPrCltIBEcbMAkWYGA/UwLA3eVqFBheeL2/W5gUJpv5vn88j+4bJC/A9GQ4P82D6GgmAuYgXPhSlgyygFUF0kNCnUCQ7uY6uPpe7cQyQLnefO3wk1Q5wr3IdtlHXd7hI7JrdJgxp90euKZSViwgrB6dOPCk4S2+A2fp+XbITfpMavxDiZPr3b8ts0xBwH/OAhFAJDtW4BmLkzrflqavhRtPLHJJXXiNl6cKVKPanb9gaxGMgXDZfOs2Ry6BcEVKm8uLgs25C1cNwQbf1IsCIicalJSCiof5ON9mLq/gb89RR6VZ8Yl02NYfPw37QLVary6KfTbkul0SyvSYeEUh1/qWbo+T+V5QBuyQFkgydYZ+Xpoo7srJ0/xEscWAs28EE/McM9KAzGzvGW8U++mziIYGIUJ6ujiI5f99GpW1Z7YpLg6RwiAzISf/wH6ySfkECyuXA== X-Forefront-PRVS: 09752BC779 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR07MB1067; 23:pj8vA2oJnGxDx4wQ1mCfHD/TPKXb+VNeMRka8gzjL?= =?us-ascii?Q?ZFh38mVM/k7WzldrafDFU6Q2hiBvt9JT529ycEdWJoUcPU0rXvS7zUWm7sLF?= =?us-ascii?Q?a2P+3iKd1h1pSc9+X4OToqjChzoS3eY5Kavv21mxLTg3BprHCYdMB640owsy?= =?us-ascii?Q?rJX5rQ+EBvKQrW8w8C4RKT67mB9BfWQX/5rM4s9A4R9MiuAGxf6onFvgYfTe?= =?us-ascii?Q?dpNRuccyyuusqNRn5dT+QebOtEei/uq+/W5a6x5CLghegJUtbtsjNJSYfBt8?= =?us-ascii?Q?VUIooCIzU+VAYfrjQhGEVswI4/pU3hSSVadSrYv/e0ekzvMSZCouBPtP6UyA?= =?us-ascii?Q?KdOyI7FWbOnZv2V43dRFZnwqP1qSAfvJC8VY/6/JJ87cNUyUdPkZvqrGvIoz?= =?us-ascii?Q?0oqIeo0EzQYrProiFCY6kIiY8Njo8dQXr3Ot1611T56OfPkKehKexaakjubx?= =?us-ascii?Q?sBOTMRoc0qZHRL3bhnMUOF/kH9u1jbTpm8nzimw0ZtxESKdo67QDMqR2CpAA?= =?us-ascii?Q?n84KDRvuOKC0A9GfpxZUM3gpb+RS41QUumKHs6AAMsR+W/CokT2CnRVLIdZt?= =?us-ascii?Q?CrdJFEicSlIPUZYdla6IcB1VYLE7UMfhooM+F38IOXjthX/dwGCybDVUNxgg?= =?us-ascii?Q?ch/h+dXvboa+B05YcVvz+yvWAA5mfLUFrCopZi0HIxCddCxfm7zWYWkWPokD?= =?us-ascii?Q?UBxCVrnU4CYkbP1YR1YPKP0cz/Olyk7mFAbzUhb3X9kF3/lmJgqMYvK7Kouw?= =?us-ascii?Q?zx34m5apb3iaYKkc4l4Eli2k1kxKVfNr3TpZhHqyGusgwpX8NRWKXoXK5OUX?= =?us-ascii?Q?A2SKsKqxk0B5F8B4aNk2btm/5CHl4FKZiyn7b+XMN/7zQJrrQAm4PlNX6njy?= =?us-ascii?Q?WirktDBapta2Nt8evwetESNxwGuTV17DdE9fwSvrSb/mFF37k/lmTPv/uSCV?= =?us-ascii?Q?R66TZOBEFuaJthgOoZbMznwAayZ3wOMiVfgVSsgkE6PCEYq19yYefOzh0Dbe?= =?us-ascii?Q?UHdrViKCT/tk3/sU2ikcdY7HsGTAexMRpMRWKBgFCi/IQhQfXkArxhX8AFgd?= =?us-ascii?Q?XT6bxwxB7uZSVbNghiwydHzpNEsG0FdUgxyzSHk7D2PYSP+MA=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; HE1PR07MB1067; 6:z4CaYsuw3I6MGDmg1KtXvPSWDgHuMHxSll5uH4eXQ9rERzaAZJna9HA4uoRVrvrPritCXHrwTIGEQWoWOXiVVZi4VP/nJlU3QD8zWNEpbrFS2dBIG/AoRSYi4JmN+lNRzIClxV9kCpqql/LbjIQvo5Qk9FJI5CQAe7/nkWxi4uaEOaZKHu/pdx5/obpYO6iWNXcVys+66+RiWLuwvGTnGwIZrzoe/DkaLJtk4ZRlX3r6r8+N2df9PuxiiBcdazaijSHTlXlHP5PzdTCG/Acqun1w+SMTEXJ4Qd6jiFYqvtg=; 5:UjJeevEx0/ga7DtUFq//7ytTwqXWIN/WmUJXXxTArOlRMTkB3ZrLxGIE504XTStsuVYHY9NX2xNOIYaYEcRPPGLDNapJnAcoe9ekbtUs6MMMXA5smndAhAU+Kgtjg302ORQhfEhc+I67y645ZisjuQ==; 24:rcvKourZyzieS5l85gejcJiGZf8WkPt7aHPwL02roGMX1MmpVIBNDMq16/ZR3biQbBbSRaRQ5Qc8bAEcR4LrLL0XBfqVjeTXPu/erICaKks=; 7:yC9VInFFlUo1suADaXvB6Sshmh0OlwvXph8klP1uw3Xl4WtdnkrCHbl5Mf8ZN5B0dM3ol1v4nMQi4c/FD1sLL1DeY8eTYOv9DFBeDshxZF/B+pQF1vRuCY8azUISIlWB3A2syoXN25NCU1hIDz1Ba7kBy8K1+fBYAZa6o5JOq3Sqri4gxrhMN/9YA4Nn+/X1SLv0Mi30u38nmPS7NQLKmg== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2016 10:31:48.0623 (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: HE1PR07MB1067 X-Topics: patch Subject: [lng-odp] [PATCH 2/2] example: echo: reply to icmp echo request 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" When the application is run in responder mode it will also reply to standard ICMP echo packets sent by for example the ping utility. Signed-off-by: Matias Elo --- example/echo/odp_echo.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/example/echo/odp_echo.c b/example/echo/odp_echo.c index cc966e1..ff56f30 100644 --- a/example/echo/odp_echo.c +++ b/example/echo/odp_echo.c @@ -12,6 +12,7 @@ #include #include #include +#include #define POOL_NUM_PKT 256 #define POOL_SEG_LEN 1856 @@ -178,6 +179,31 @@ static echo_hdr_t *echo_hdr(odp_packet_t pkt) } /** + * ICMPv4 echo header start pointer + * + * @param pkt Packet handle + * + * @return ICMP echo header start pointer + * @retval NULL packet does not contain a valid ICMP echo header + */ +static odph_icmphdr_t *icmp_echo_hdr(odp_packet_t pkt) +{ + odph_icmphdr_t *icmp; + + if (!odp_packet_has_ipv4(pkt)) + return NULL; + + if (!odp_packet_has_icmp(pkt)) + return NULL; + + icmp = odp_packet_l4_ptr(pkt, NULL); + if (icmp->type != ICMP_ECHO) + return NULL; + + return icmp; +} + +/** * Echo packet responder thread */ static int run_responder(void *arg ODP_UNUSED) @@ -197,9 +223,13 @@ static int run_responder(void *arg ODP_UNUSED) if (odp_unlikely(pkts <= 0)) continue; + for (i = 0; i < pkts; i++) { odp_packet_t pkt = pkt_tbl[i]; odph_ethhdr_t *eth; + odph_icmphdr_t *icmp; + echo_hdr_t *echo; + int icmp_len; if (odp_unlikely(!odp_packet_has_eth(pkt))) { odp_packet_free(pkt); @@ -207,11 +237,31 @@ static int run_responder(void *arg ODP_UNUSED) } eth = odp_packet_l2_ptr(pkt, NULL); - if (echo_hdr(pkt) == NULL) { + icmp = icmp_echo_hdr(pkt); + echo = echo_hdr(pkt); + if (echo == NULL && icmp == NULL) { odp_packet_free(pkt); continue; } + /* Format ICMP echo reply */ + if (icmp) { + odph_ipv4hdr_t *ip; + odp_u32be_t tmp_addr; + + ip = odp_packet_l3_ptr(pkt, NULL); + tmp_addr = ip->src_addr; + ip->src_addr = ip->dst_addr; + ip->dst_addr = tmp_addr; + + icmp_len = odp_packet_len(pkt) - + ODPH_ETHHDR_LEN - ODPH_IPV4HDR_LEN; + + icmp->type = ICMP_ECHOREPLY; + icmp->chksum = 0; + icmp->chksum = odph_chksum(icmp, icmp_len); + } + /* Swap MAC addresses */ eth->dst = eth->src; eth->src = global.src;