DPDK patches and discussions
 help / color / mirror / Atom feed
From: ido goshen <ido@cgstowernetworks.com>
To: Ferruh Yigit <ferruh.yigit@intel.com>
Cc: dev@dpdk.org, ido goshen <ido@cgstowernetworks.com>
Subject: [dpdk-dev] [PATCH 2/2] net/pcap: duplicate code consolidation
Date: Sat, 16 Jun 2018 18:36:37 +0300	[thread overview]
Message-ID: <1529163397-88330-2-git-send-email-ido@cgstowernetworks.com> (raw)
In-Reply-To: <1529163397-88330-1-git-send-email-ido@cgstowernetworks.com>

Signed-off-by: ido goshen <ido@cgstowernetworks.com>
---
 drivers/net/pcap/rte_eth_pcap.c | 58 ++++++++++++++++++++---------------------
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
index 444abbb..e63998b 100644
--- a/drivers/net/pcap/rte_eth_pcap.c
+++ b/drivers/net/pcap/rte_eth_pcap.c
@@ -658,6 +658,20 @@ 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 (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.
@@ -672,10 +686,7 @@ struct pmd_devargs {
 	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++;
+	add_queue(rx, pcap_filename, key, pcap, NULL);
 
 	return 0;
 }
@@ -694,10 +705,7 @@ struct pmd_devargs {
 	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++;
+	add_queue(dumpers, pcap_filename, key, NULL, dumper);
 
 	return 0;
 }
@@ -722,44 +730,36 @@ 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 (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++;
+	add_queue(pmd, iface, key, pcap, NULL);
 
 	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 (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

  reply	other threads:[~2018-06-16 15:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-16 15:36 [dpdk-dev] [PATCH 1/2] net/pcap: multiple queues fix ido goshen
2018-06-16 15:36 ` ido goshen [this message]
2018-06-18  8:25 ` Ferruh Yigit
2018-06-19  9:45   ` Ido Goshen
2018-06-19 10:00     ` Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1529163397-88330-2-git-send-email-ido@cgstowernetworks.com \
    --to=ido@cgstowernetworks.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).