From patchwork Fri Apr 1 13:41:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fan Zhang X-Patchwork-Id: 11893 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id E93902C0E; Fri, 1 Apr 2016 15:42:04 +0200 (CEST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 8C8082BA3 for ; Fri, 1 Apr 2016 15:42:02 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP; 01 Apr 2016 06:42:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,427,1455004800"; d="scan'208";a="776192998" Received: from sie-lab-212-033.ir.intel.com (HELO silpixa00383881.ir.intel.com) ([10.237.212.33]) by orsmga003.jf.intel.com with ESMTP; 01 Apr 2016 06:42:00 -0700 From: Fan Zhang To: dev@dpdk.org Date: Fri, 1 Apr 2016 14:41:56 +0100 Message-Id: <1459518117-23944-3-git-send-email-roy.fan.zhang@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1459518117-23944-1-git-send-email-roy.fan.zhang@intel.com> References: <1459518117-23944-1-git-send-email-roy.fan.zhang@intel.com> Subject: [dpdk-dev] [PATCH 2/3] port: fix sink port parameter check X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Fixes: eb5f411 ("port: add pcap file dump") This patch fixes sink port parameter checking logic. Originally, if user set field "file_name" with meaning value but leave PCAP support feature disabled, the program simply ignores this field without notifying the user. Signed-off-by: Fan Zhang Acked-by: Cristian Dumitrescu --- lib/librte_port/rte_port_source_sink.c | 100 ++++++++++++++------------------- 1 file changed, 43 insertions(+), 57 deletions(-) diff --git a/lib/librte_port/rte_port_source_sink.c b/lib/librte_port/rte_port_source_sink.c index 5c24cea..ca40a59 100644 --- a/lib/librte_port/rte_port_source_sink.c +++ b/lib/librte_port/rte_port_source_sink.c @@ -385,47 +385,37 @@ struct rte_port_sink { #ifdef RTE_PORT_PCAP -/** - * Open PCAP file for dumping packets to the file later - * - * @param port - * Handle to sink port - * @param p - * Sink port parameter - * @return - * 0 on SUCCESS - * error code otherwise - */ static int pcap_sink_open(struct rte_port_sink *port, - __rte_unused struct rte_port_sink_params *p) + const char *file_name, + uint32_t max_n_pkts) { pcap_t *tx_pcap; pcap_dumper_t *pcap_dumper; - if (p->file_name == NULL) { - port->dumper = NULL; - port->max_pkts = 0; - port->pkt_index = 0; - port->dump_finish = 0; - return 0; - } - /** Open a dead pcap handler for opening dumper file */ tx_pcap = pcap_open_dead(DLT_EN10MB, 65535); - if (tx_pcap == NULL) - return -ENOENT; + if (tx_pcap == NULL) { + RTE_LOG(ERR, PORT, "Cannot open pcap dead handler\n"); + return -1; + } /* The dumper is created using the previous pcap_t reference */ - pcap_dumper = pcap_dump_open(tx_pcap, p->file_name); - if (pcap_dumper == NULL) - return -ENOENT; + pcap_dumper = pcap_dump_open(tx_pcap, file_name); + if (pcap_dumper == NULL) { + RTE_LOG(ERR, PORT, "Failed to open pcap file " + "\"%s\" for writing\n", file_name); + return -1; + } port->dumper = pcap_dumper; - port->max_pkts = p->max_n_pkts; + port->max_pkts = max_n_pkts; port->pkt_index = 0; port->dump_finish = 0; + RTE_LOG(INFO, PORT, "Ready to dump packets to file \"%s\"\n", + file_name); + return 0; } @@ -520,19 +510,23 @@ pcap_sink_close(void *dumper) pcap_dump_close(pcap_dumper); } -#else +#define PCAP_SINK_OPEN(port, file_name, max_n_pkts) \ + pcap_sink_open(port, file_name, max_n_pkts) -static int -pcap_sink_open(struct rte_port_sink *port, - __rte_unused struct rte_port_sink_params *p) -{ - port->dumper = NULL; - port->max_pkts = 0; - port->pkt_index = 0; - port->dump_finish = 0; +#else - return -ENOTSUP; -} +#define PCAP_SINK_OPEN(port, file_name, max_n_pkts) \ +({ \ + int _ret = 0; \ + \ + if (file_name) { \ + RTE_LOG(ERR, PORT, "Sink port field " \ + "\"file_name\" is not NULL.\n"); \ + _ret = -1; \ + } \ + \ + _ret; \ +}) static void pcap_sink_dump_pkt(__rte_unused struct rte_port_sink *port, @@ -547,11 +541,10 @@ pcap_sink_close(__rte_unused void *dumper) {} #endif static void * -rte_port_sink_create(__rte_unused void *params, int socket_id) +rte_port_sink_create(void *params, int socket_id) { struct rte_port_sink *port; struct rte_port_sink_params *p = params; - int status; /* Memory allocation */ port = rte_zmalloc_socket("PORT", sizeof(*port), @@ -561,24 +554,17 @@ rte_port_sink_create(__rte_unused void *params, int socket_id) return NULL; } - /* Try to open PCAP file for dumping, if possible */ - status = pcap_sink_open(port, p); - if (status == 0) { - if (port->dumper != NULL) - RTE_LOG(INFO, PORT, "Ready to dump packets " - "to file %s\n", p->file_name); - - } else if (status != -ENOTSUP) { - if (status == -ENOENT) - RTE_LOG(ERR, PORT, "%s: Failed to open pcap file " - "%s for writing\n", __func__, - p->file_name); - else - RTE_LOG(ERR, PORT, "%s: Failed to enable pcap " - "support for unknown reason\n", __func__); - - rte_free(port); - port = NULL; + if (!p) + return port; + + if (p->file_name) { + int status = PCAP_SINK_OPEN(port, p->file_name, + p->max_n_pkts); + + if (status < 0) { + rte_free(port); + port = NULL; + } } return port;