From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-eopbgr00132.outbound.protection.outlook.com [40.107.0.132]) by dpdk.org (Postfix) with ESMTP id 181834C96 for ; Tue, 19 Jun 2018 16:38:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cgstowernetworks.onmicrosoft.com; s=selector1-cgstowernetworks-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bmFR8JQ3nGWoqsAE15rtkT9ucTFifrZ+qBy5qD9ZmXQ=; b=APW+kKsrQfA6sCdHUb0zOZszifECi6qRZQ6pBqdlNo/h8e8jyiQXY8fMxCjoyu4WOS8riCtaXMt7NgVpb39hOe4JwWSI0qjMo++IO/Uup5on7CTSqh4fgsQOF5Mm246wJef7x3y4CJVrXWBwvq676a7LuIozQx9V1MetoWdUikU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Ido@cgstowernetworks.com; Received: from ubuntu.localdomain (5.144.48.231) by VI1PR0901MB1439.eurprd09.prod.outlook.com (2603:10a6:800:8d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.863.19; Tue, 19 Jun 2018 14:38:13 +0000 From: ido goshen To: Ferruh Yigit Cc: dev@dpdk.org, ido goshen Date: Tue, 19 Jun 2018 17:37:26 +0300 Message-Id: <1529419046-95906-2-git-send-email-ido@cgstowernetworks.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1529419046-95906-1-git-send-email-ido@cgstowernetworks.com> References: <1529419046-95906-1-git-send-email-ido@cgstowernetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [5.144.48.231] X-ClientProxiedBy: LO2P265CA0190.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a::34) To VI1PR0901MB1439.eurprd09.prod.outlook.com (2603:10a6:800:8d::7) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fcacca7c-8f2c-4680-afa1-08d5d5f249ff X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(711020)(2017052603328)(7153060)(7193020); SRVR:VI1PR0901MB1439; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0901MB1439; 3:pTMrqcTuucZ+zHC78O06pvzvsqLoCgrDytT7GjDqxDmGjfpwzb5BtocjaUZ/WvSPKX/nO8UHzg4hDVhanje4woVXA9YFbvM72B/GycL0gnAeou9TJ6iXdien1zo/ixrvMz+2vh5IfiVCKJSfFWOG4qghzFEnjUdEzhw8frTzJ5njbgU70DBhRzYAN/Hr8QlBqGvimMb8cZut2gYFgl4s7Jv5KrtVTSONNCvtwx7zEx1jIkpnFzz8dDOwTTit4vUF; 25:VPeJQatIAPjU7ufKS9lJhZWmatPafD1KJfprnc5q4zmZYhoyTOdu6XhynJhRAPo+Q///VtAokffBmjuwnxnY+L7OMwRiNWo9vSrKF6FgSIoJ17rvitl/aSWcYdo+Wi1oRaqZr2Katfp603DQAAuZi29M2ByWjDNrEi6zt/TIqkYbmUyCOxvaEjtUOs0thrzyrVD7zxF9WeZzg3FhEkOm5otUJrqyxC01KVPZjdaX2eLQ9LT6+buuAHFcmjL29vEVkKowJnYb7aviylPfkS82XfSU/9dVTrVHNq296l/EHurckJsUvSshrsd+MKlDc7sdhQNqZ0UmbhnP4FO1HBY8CQ==; 31:cYrfqXlw+VnfQgKSuwJkVO8WEoTtRx6XwVWZbcPVxIrEpl3mV+I0t13CA5S4RJf0AsRXIeq14HN2h0Co2WAh+k8tznMc0TGUjpq4TFf2zyq2yk+KqU5CcK2Gw4hxn5tT6M4bNtd878CVE5IdZ4zhrfKrHv92EnMOxueGmab1xtTwdnAVt4G/ig3oI9m5h7zhXAv3B32SzM+B9OE7UEwtnQ2cBBiW9lNr/heGhpi9P8M= X-MS-TrafficTypeDiagnostic: VI1PR0901MB1439: X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231254)(944501410)(52105095)(3002001)(10201501046)(149027)(150027)(6041310)(20161123558120)(20161123564045)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011)(7699016); SRVR:VI1PR0901MB1439; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0901MB1439; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0901MB1439; 4:31QgPLtcgo7XLWcd/GhGd8KkS18zAItnYqI7uZKjZdOI7irCZ0d5oLXwkOudwhznPLCGquHKGON6DKR1OKvKGXhiB+Ld3Z1ciSnD6NRJ4DFtDbLmcDtc1tzSGQ3d3QSjmQC3EEcusgensKa/8tWFO9e+Z0BYsLE2dIIAby1mYWxdkt+z/kVWXrH2npf/3Ckyaspz0QFI5h+7H9D61V/rLXVIDkBjdbRhZEC8DTtkOid6ZHm8ttuNnO5JNr4rbgYZpxIEYHLZMvzqeCaWUFFjCg== X-Forefront-PRVS: 07083FF734 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(39840400004)(366004)(39380400002)(396003)(376002)(346002)(199004)(189003)(48376002)(86362001)(76176011)(316002)(305945005)(51416003)(16586007)(53936002)(52116002)(11346002)(486006)(476003)(2616005)(956004)(446003)(50466002)(478600001)(71446004)(72206003)(80792005)(106356001)(107886003)(25786009)(8936002)(97736004)(4326008)(81166006)(105586002)(8676002)(81156014)(386003)(6506007)(26005)(186003)(16526019)(2906002)(59450400001)(7736002)(6916009)(5660300001)(66066001)(6666003)(36756003)(50226002)(6116002)(3846002)(68736007)(47776003)(6512007)(6486002)(86152003)(37156001); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0901MB1439; H:ubuntu.localdomain; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: cgstowernetworks.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0901MB1439; 23:ZsYVHBU5HRPmE15CDUhY0oPX2oRyZo8WcfR9wvo?= =?us-ascii?Q?rFyTk4cQEyMzojnH1WyBwxAN0bFc445luYU8b9NeCBu1pW8S0f4dVG0mkKXZ?= =?us-ascii?Q?IbWjBZsW8xBKFChCdSRFXlVw4gF2svAfZsMPneOCmUG2JOy79Dlo+0SDGGvd?= =?us-ascii?Q?fQ7SLaK8d8n1tprJjLVaxa0Dh2e5zzBmdtaZALj/gCnMiFesbt/iyRsPGwEx?= =?us-ascii?Q?u+T0BVa8D/Q5ZMdbRfn1QenpZNViL1Kxou+9VkP7OcZTPVzyfZduvxShNPGh?= =?us-ascii?Q?yZRgn4JzrAF6MtUW+xL2aMaSgANdNLA294kS0woIlQ1fFDRecanGL0aBBtnx?= =?us-ascii?Q?/7KdQaeox3wX2JNVTslps799a2imas7HlvHxMGgdMDU8/rDTf6qgBlcgAiyq?= =?us-ascii?Q?5bIurw+UA6ySPnnzhYqZiPyO5TkLLJcmQxY+p31DDq2m3Gwv4iaqYpI0QQ7S?= =?us-ascii?Q?IePGpApuWcWLXyjTNlng6Rop0AqSGOYpmO1SzdaR3dIIOWjQMe1BDq01UOkw?= =?us-ascii?Q?yIk8ne0DUKuh57LsEYFpSdXuV+JG/IFkGJKaA5tFH5xGeiTZm9PbxDYxkJnn?= =?us-ascii?Q?ovYVcyrbKqCtrQ/8XfbC/xa/KymONftWW/KXkLIRLR1KEGP9Uz9G2anh/GNi?= =?us-ascii?Q?xYnuB5COIVBXzL6Dsn3JCJohAU6wG8sxvNewbeeMALgcLJwVHn2ccZQihjnE?= =?us-ascii?Q?ruHflEbxpFXJ7GeJU87Jjho0FbYouG6Bym/mLJcAi7mNmydIXCFznoQfKoxt?= =?us-ascii?Q?FAB6N3jwLLikZnuBa7Khl+RpAdDidIrXfDfEyekTR9lXDTUyeWIT/yV18c/F?= =?us-ascii?Q?CigXLpkvEs4JzUFsgfiS9c7/a1mE4WWJqS2TnMAR7R9IXXU6Fco9BByvwGpu?= =?us-ascii?Q?8mON25uD3UvDzZGrgX3IMcnWCG5zCS7/BDuLcawq45/FF++U0KR9W7AsXzUt?= =?us-ascii?Q?6vyCpe1WXe4qEIvs9fwvNMCq9+w0LYhArFJNFQ/eDdsNYX+oNTuwIZj5W4qc?= =?us-ascii?Q?hb47uqGA6dP3Z++mUPyIob3V0jVVJjVMF1pJbEQJJH8fO3T2z0yU82tCuAa+?= =?us-ascii?Q?e7DZUvFmR3srrMjTRd90tonh+vR48BYi6ew4e506V4wN4x1ZW5uxcGEn1zFU?= =?us-ascii?Q?26THniWgbAGKtj+NlEAluyTlL3sqERH7u3/PZLBC3gRM37Q3LrqymErb8VHV?= =?us-ascii?Q?5gXE19j1QKw3QZ3Xk4crHfJMWS+KyOyMNtdI4HikZXy1T/FAPcEl0dWyinUn?= =?us-ascii?Q?DskQlpDOPjCnqqZcG8Nwv3KgfLukget68BO8n2bwpfkD7WTwqmEWX/bR62OR?= =?us-ascii?Q?bmf8z5NZWUujbShYD/9rEpTBRaOjNeKjmH8cmsNLe830q?= X-Microsoft-Antispam-Message-Info: HdhclWyW+9PLsNcAqxSl36NUUG67CENBOESbBWzsSOUwRLMrN5SofyxI2yxTZICgbHloeCjSWot8FDWSQXXe+x0lehsx+zOg8WEWBa+KTtnweu2umWdptzE16Qh5ViGRX2Cfv+V68rQBro0v+N0m3DtcmMhv9OPP2Yw+8p3TwKAv+5oVFBMbywJ/BHnI7R81V0vpjOu/i3YJd0OxPoNs5b/Iyy0mZuq80d7h8F8wSALEt/xJo3vdY8TuXYedTe8mHGI7w/oqxGhzV6lhgBZ+AoBcOykAFP560IblS3cep9s9suhdjuinsa4f0St47OKRX+WtjYJc/YaMpeOPoR9U5Q== X-Microsoft-Exchange-Diagnostics: 1; VI1PR0901MB1439; 6:JhMr5Mq4zj4GlRn7UjjiWZslb9qQzE9XnjSAkR4viIZVvJHZFLywZ5xzW7d047GrhiX6IBYk3wVOfk433MSFR/bobO2In92wPf2p3DH/ZfFroEqycksQJ86yZLzb7M9Ykpin10a6ojMQ83zcnWbge2hBItYPV82/LrxNMtQHGJhMDB27UeHKO9FAw+LUNJEFwhWmbsq879vNlO0GdbcnPdk89Fe8Z2LmPmSkWLWjhktHxsR2z93Twp6Td24fnC5jIbAzGkadjzeLHEkS4vFMDgNUnudMsyp4IVHSJR8pHL45jfIp3cTzGg+uSWs9INBUrCIa/fPiamWEv9uMDMQX8CJGQudDt/65bGHlf2nxkHi8DMh7MLCKuErlINJkCe6DxdUDCQ6ECYrXmBRJwJpJE0w31I9RtxK7Jkxyr9dqZmwpY6b4Wp6FLHbbiPXv8/6Xhg6rcIq/TdBwN50CXpJBeA==; 5:DrbmWnukWOo/FJZC1Dyh+lPprn+r/4QONy2gS5fy6uye6ApFO9nNgVnavJv/3CewwxDd9gIM9zOaJA9wBaUVmXmi4q9iqageE3AFk4KsHdks7nyVkQ3I08NofH0OzUSBmHjvaypqiQpsbVegWq0VSlXc0V/kWhnAxICKuc+2z4o=; 24:mlmaTHgRdiHQTOg5PtMLjb2a9vWXuN/1cWdVn/G1TJQ5uHVJzGKL/BgzNlfn1SZBcATQgmzRLnebUL/YQYnZNfiIkIS7tx18eU8Z3rWftIY= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0901MB1439; 7:wrGPVmoml2knpYbNMplpGOdS02lBJHtAHRnViuGKZAa9EQX94sdQN0aCnd8O2qc5ictprXKC0f2rznEMQOjBDbtey7RjsTDIleGk/nEfbV0ChKo3a2znA3imdi0P6ivRVOm3/P+JyKdb+FxWjkqcqVgJXssQCLZkkrTIMlNf+B4co6681EA4lU6G+nNs7AyuZ2752otcdn143l0vQAMZqVjFGqIVSxZ89fbB4ogxCJtpjMMW7JBpyP+7Lr7TZw8u X-OriginatorOrg: cgstowernetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jun 2018 14:38:13.6994 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fcacca7c-8f2c-4680-afa1-08d5d5f249ff X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fc9e9498-07e8-4b82-b4cf-365bba23cbbf X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0901MB1439 X-Mailman-Approved-At: Wed, 20 Jun 2018 00:55:58 +0200 Subject: [dpdk-dev] [PATCH v2 2/2] net/pcap: duplicate code consolidation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Jun 2018 14:38:15 -0000 Signed-off-by: ido goshen --- drivers/net/pcap/rte_eth_pcap.c | 77 +++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c index b4f81ac..b21930b 100644 --- a/drivers/net/pcap/rte_eth_pcap.c +++ b/drivers/net/pcap/rte_eth_pcap.c @@ -658,6 +658,22 @@ struct pmd_devargs { .stats_reset = eth_stats_reset, }; +static int +add_queue(struct pmd_devargs *pmd, const char *name, const char *type, + pcap_t *pcap, pcap_dumper_t *dumper) +{ + if (pmd->num_of_queue >= RTE_PMD_PCAP_MAX_QUEUES) + return -1; + if (pcap) + pmd->queue[pmd->num_of_queue].pcap = pcap; + if (dumper) + pmd->queue[pmd->num_of_queue].dumper = dumper; + pmd->queue[pmd->num_of_queue].name = name; + pmd->queue[pmd->num_of_queue].type = type; + pmd->num_of_queue++; + return 0; +} + /* * Function handler that opens the pcap file for reading a stores a * reference of it for use it later on. @@ -669,15 +685,13 @@ struct pmd_devargs { struct pmd_devargs *rx = extra_args; pcap_t *pcap = NULL; - if (rx->num_of_queue >= RTE_PMD_PCAP_MAX_QUEUES) - return -1; if (open_single_rx_pcap(pcap_filename, &pcap) < 0) return -1; - rx->queue[rx->num_of_queue].pcap = pcap; - rx->queue[rx->num_of_queue].name = pcap_filename; - rx->queue[rx->num_of_queue].type = key; - rx->num_of_queue++; + if (add_queue(rx, pcap_filename, key, pcap, NULL) < 0) { + pcap_close(pcap); + return -1; + } return 0; } @@ -693,15 +707,13 @@ struct pmd_devargs { struct pmd_devargs *dumpers = extra_args; pcap_dumper_t *dumper; - if (dumpers->num_of_queue >= RTE_PMD_PCAP_MAX_QUEUES) - return -1; if (open_single_tx_pcap(pcap_filename, &dumper) < 0) return -1; - dumpers->queue[dumpers->num_of_queue].dumper = dumper; - dumpers->queue[dumpers->num_of_queue].name = pcap_filename; - dumpers->queue[dumpers->num_of_queue].type = key; - dumpers->num_of_queue++; + if (add_queue(dumpers, pcap_filename, key, NULL, dumper) < 0) { + pcap_dump_close(dumper); + return -1; + } return 0; } @@ -726,48 +738,39 @@ struct pmd_devargs { return 0; } -/* - * Opens a NIC for reading packets from it - */ static inline int -open_rx_iface(const char *key, const char *value, void *extra_args) +open_iface(const char *key, const char *value, void *extra_args) { const char *iface = value; - struct pmd_devargs *rx = extra_args; + struct pmd_devargs *pmd = extra_args; pcap_t *pcap = NULL; - if (rx->num_of_queue >= RTE_PMD_PCAP_MAX_QUEUES) - return -1; if (open_single_iface(iface, &pcap) < 0) return -1; - rx->queue[rx->num_of_queue].pcap = pcap; - rx->queue[rx->num_of_queue].name = iface; - rx->queue[rx->num_of_queue].type = key; - rx->num_of_queue++; + if (add_queue(pmd, iface, key, pcap, NULL) < 0) { + pcap_close(pcap); + return -1; + } return 0; } /* + * Opens a NIC for reading packets from it + */ +static inline int +open_rx_iface(const char *key, const char *value, void *extra_args) +{ + return open_iface(key, value, extra_args); +} + +/* * Opens a NIC for writing packets to it */ static int open_tx_iface(const char *key, const char *value, void *extra_args) { - const char *iface = value; - struct pmd_devargs *tx = extra_args; - pcap_t *pcap; - - if (tx->num_of_queue >= RTE_PMD_PCAP_MAX_QUEUES) - return -1; - if (open_single_iface(iface, &pcap) < 0) - return -1; - tx->queue[tx->num_of_queue].pcap = pcap; - tx->queue[tx->num_of_queue].name = iface; - tx->queue[tx->num_of_queue].type = key; - tx->num_of_queue++; - - return 0; + return open_iface(key, value, extra_args); } static struct rte_vdev_driver pmd_pcap_drv; -- 1.9.1