net/pcap: fix multiple queues

Change open_rx/tx_pcap/iface functions to open only a single pcap/dumper
and not loop num_of_queue times
The num_of_queue loop is already achieved by the
caller rte_kvargs_process

Fixing:
1. Opens N requested pcaps/dumpers instead of N^2
2. Leak of pcap/dumper's which are being overwritten by
   the sequential calls to open_rx/tx_pcap/iface functions
3. Use the filename/iface args per queue and not just the last one
   that overwrites the previous names

Fixes: 4c173302c307 ("pcap: add new driver")
Cc: stable@dpdk.org

Signed-off-by: Ido Goshen <ido@cgstowernetworks.com>
Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>
This commit is contained in:
Ido Goshen 2018-06-19 17:37:25 +03:00 committed by Ferruh Yigit
parent 279d33199c
commit 8ffda7673f

View File

@ -665,19 +665,19 @@ static const struct eth_dev_ops ops = {
static int static int
open_rx_pcap(const char *key, const char *value, void *extra_args) open_rx_pcap(const char *key, const char *value, void *extra_args)
{ {
unsigned int i;
const char *pcap_filename = value; const char *pcap_filename = value;
struct pmd_devargs *rx = extra_args; struct pmd_devargs *rx = extra_args;
pcap_t *pcap = NULL; pcap_t *pcap = NULL;
for (i = 0; i < rx->num_of_queue; i++) { if (rx->num_of_queue >= RTE_PMD_PCAP_MAX_QUEUES)
if (open_single_rx_pcap(pcap_filename, &pcap) < 0) return -1;
return -1; if (open_single_rx_pcap(pcap_filename, &pcap) < 0)
return -1;
rx->queue[i].pcap = pcap; rx->queue[rx->num_of_queue].pcap = pcap;
rx->queue[i].name = pcap_filename; rx->queue[rx->num_of_queue].name = pcap_filename;
rx->queue[i].type = key; rx->queue[rx->num_of_queue].type = key;
} rx->num_of_queue++;
return 0; return 0;
} }
@ -689,19 +689,19 @@ open_rx_pcap(const char *key, const char *value, void *extra_args)
static int static int
open_tx_pcap(const char *key, const char *value, void *extra_args) open_tx_pcap(const char *key, const char *value, void *extra_args)
{ {
unsigned int i;
const char *pcap_filename = value; const char *pcap_filename = value;
struct pmd_devargs *dumpers = extra_args; struct pmd_devargs *dumpers = extra_args;
pcap_dumper_t *dumper; pcap_dumper_t *dumper;
for (i = 0; i < dumpers->num_of_queue; i++) { if (dumpers->num_of_queue >= RTE_PMD_PCAP_MAX_QUEUES)
if (open_single_tx_pcap(pcap_filename, &dumper) < 0) return -1;
return -1; if (open_single_tx_pcap(pcap_filename, &dumper) < 0)
return -1;
dumpers->queue[i].dumper = dumper; dumpers->queue[dumpers->num_of_queue].dumper = dumper;
dumpers->queue[i].name = pcap_filename; dumpers->queue[dumpers->num_of_queue].name = pcap_filename;
dumpers->queue[i].type = key; dumpers->queue[dumpers->num_of_queue].type = key;
} dumpers->num_of_queue++;
return 0; return 0;
} }
@ -732,18 +732,18 @@ open_rx_tx_iface(const char *key, const char *value, void *extra_args)
static inline int static inline int
open_rx_iface(const char *key, const char *value, void *extra_args) open_rx_iface(const char *key, const char *value, void *extra_args)
{ {
unsigned int i;
const char *iface = value; const char *iface = value;
struct pmd_devargs *rx = extra_args; struct pmd_devargs *rx = extra_args;
pcap_t *pcap = NULL; pcap_t *pcap = NULL;
for (i = 0; i < rx->num_of_queue; i++) { if (rx->num_of_queue >= RTE_PMD_PCAP_MAX_QUEUES)
if (open_single_iface(iface, &pcap) < 0) return -1;
return -1; if (open_single_iface(iface, &pcap) < 0)
rx->queue[i].pcap = pcap; return -1;
rx->queue[i].name = iface; rx->queue[rx->num_of_queue].pcap = pcap;
rx->queue[i].type = key; rx->queue[rx->num_of_queue].name = iface;
} rx->queue[rx->num_of_queue].type = key;
rx->num_of_queue++;
return 0; return 0;
} }
@ -754,18 +754,18 @@ open_rx_iface(const char *key, const char *value, void *extra_args)
static int static int
open_tx_iface(const char *key, const char *value, void *extra_args) open_tx_iface(const char *key, const char *value, void *extra_args)
{ {
unsigned int i;
const char *iface = value; const char *iface = value;
struct pmd_devargs *tx = extra_args; struct pmd_devargs *tx = extra_args;
pcap_t *pcap; pcap_t *pcap;
for (i = 0; i < tx->num_of_queue; i++) { if (tx->num_of_queue >= RTE_PMD_PCAP_MAX_QUEUES)
if (open_single_iface(iface, &pcap) < 0) return -1;
return -1; if (open_single_iface(iface, &pcap) < 0)
tx->queue[i].pcap = pcap; return -1;
tx->queue[i].name = iface; tx->queue[tx->num_of_queue].pcap = pcap;
tx->queue[i].type = key; tx->queue[tx->num_of_queue].name = iface;
} tx->queue[tx->num_of_queue].type = key;
tx->num_of_queue++;
return 0; return 0;
} }
@ -958,15 +958,8 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
* We check whether we want to open a RX stream from a real NIC or a * We check whether we want to open a RX stream from a real NIC or a
* pcap file * pcap file
*/ */
pcaps.num_of_queue = rte_kvargs_count(kvlist, ETH_PCAP_RX_PCAP_ARG); is_rx_pcap = rte_kvargs_count(kvlist, ETH_PCAP_RX_PCAP_ARG) ? 1 : 0;
if (pcaps.num_of_queue) pcaps.num_of_queue = 0;
is_rx_pcap = 1;
else
pcaps.num_of_queue = rte_kvargs_count(kvlist,
ETH_PCAP_RX_IFACE_ARG);
if (pcaps.num_of_queue > RTE_PMD_PCAP_MAX_QUEUES)
pcaps.num_of_queue = RTE_PMD_PCAP_MAX_QUEUES;
if (is_rx_pcap) if (is_rx_pcap)
ret = rte_kvargs_process(kvlist, ETH_PCAP_RX_PCAP_ARG, ret = rte_kvargs_process(kvlist, ETH_PCAP_RX_PCAP_ARG,
@ -982,15 +975,8 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
* We check whether we want to open a TX stream to a real NIC or a * We check whether we want to open a TX stream to a real NIC or a
* pcap file * pcap file
*/ */
dumpers.num_of_queue = rte_kvargs_count(kvlist, ETH_PCAP_TX_PCAP_ARG); is_tx_pcap = rte_kvargs_count(kvlist, ETH_PCAP_TX_PCAP_ARG) ? 1 : 0;
if (dumpers.num_of_queue) dumpers.num_of_queue = 0;
is_tx_pcap = 1;
else
dumpers.num_of_queue = rte_kvargs_count(kvlist,
ETH_PCAP_TX_IFACE_ARG);
if (dumpers.num_of_queue > RTE_PMD_PCAP_MAX_QUEUES)
dumpers.num_of_queue = RTE_PMD_PCAP_MAX_QUEUES;
if (is_tx_pcap) if (is_tx_pcap)
ret = rte_kvargs_process(kvlist, ETH_PCAP_TX_PCAP_ARG, ret = rte_kvargs_process(kvlist, ETH_PCAP_TX_PCAP_ARG,