pcap: fix storage of name and type in queues
[dpdk.git] / lib / librte_pmd_pcap / rte_eth_pcap.c
index 5e94930..ff9b534 100644 (file)
@@ -56,6 +56,8 @@
 #define ETH_PCAP_TX_IFACE_ARG "tx_iface"
 #define ETH_PCAP_IFACE_ARG    "iface"
 
+#define ETH_PCAP_ARG_MAXLEN    64
+
 static char errbuf[PCAP_ERRBUF_SIZE];
 static struct timeval start_time;
 static uint64_t start_cycles;
@@ -67,8 +69,8 @@ struct pcap_rx_queue {
        struct rte_mempool *mb_pool;
        volatile unsigned long rx_pkts;
        volatile unsigned long err_pkts;
-       const char *name;
-       const char *type;
+       char name[PATH_MAX];
+       char type[ETH_PCAP_ARG_MAXLEN];
 };
 
 struct pcap_tx_queue {
@@ -76,8 +78,8 @@ struct pcap_tx_queue {
        pcap_t *pcap;
        volatile unsigned long tx_pkts;
        volatile unsigned long err_pkts;
-       const char *name;
-       const char *type;
+       char name[PATH_MAX];
+       char type[ETH_PCAP_ARG_MAXLEN];
 };
 
 struct rx_pcaps {
@@ -136,7 +138,6 @@ eth_pcap_rx(void *queue,
        const u_char *packet;
        struct rte_mbuf *mbuf;
        struct pcap_rx_queue *pcap_q = queue;
-       struct rte_pktmbuf_pool_private *mbp_priv;
        uint16_t num_rx = 0;
        uint16_t buf_size;
 
@@ -157,8 +158,7 @@ eth_pcap_rx(void *queue,
                        break;
 
                /* Now get the space available for data in the mbuf */
-               mbp_priv =  rte_mempool_get_priv(pcap_q->mb_pool);
-               buf_size = (uint16_t) (mbp_priv->mbuf_data_room_size -
+               buf_size = (uint16_t)(rte_pktmbuf_data_room_size(pcap_q->mb_pool) -
                                RTE_PKTMBUF_HEADROOM);
 
                if (header.len <= buf_size) {
@@ -483,19 +483,19 @@ eth_tx_queue_setup(struct rte_eth_dev *dev,
        return 0;
 }
 
-static struct eth_dev_ops ops = {
-               .dev_start = eth_dev_start,
-               .dev_stop =     eth_dev_stop,
-               .dev_close = eth_dev_close,
-               .dev_configure = eth_dev_configure,
-               .dev_infos_get = eth_dev_info,
-               .rx_queue_setup = eth_rx_queue_setup,
-               .tx_queue_setup = eth_tx_queue_setup,
-               .rx_queue_release = eth_queue_release,
-               .tx_queue_release = eth_queue_release,
-               .link_update = eth_link_update,
-               .stats_get = eth_stats_get,
-               .stats_reset = eth_stats_reset,
+static const struct eth_dev_ops ops = {
+       .dev_start = eth_dev_start,
+       .dev_stop =     eth_dev_stop,
+       .dev_close = eth_dev_close,
+       .dev_configure = eth_dev_configure,
+       .dev_infos_get = eth_dev_info,
+       .rx_queue_setup = eth_rx_queue_setup,
+       .tx_queue_setup = eth_tx_queue_setup,
+       .rx_queue_release = eth_queue_release,
+       .tx_queue_release = eth_queue_release,
+       .link_update = eth_link_update,
+       .stats_get = eth_stats_get,
+       .stats_reset = eth_stats_reset,
 };
 
 static struct eth_driver rte_pcap_pmd = {
@@ -760,12 +760,11 @@ rte_pmd_init_internals(const char *name, const unsigned nb_rx_queues,
 
        return 0;
 
-       error: if (data)
-               rte_free(data);
-       if (pci_dev)
-               rte_free(pci_dev);
-       if (*internals)
-               rte_free(*internals);
+error: 
+       rte_free(data);
+       rte_free(pci_dev);
+       rte_free(*internals);
+
        return -1;
 }
 
@@ -793,14 +792,22 @@ rte_eth_from_pcaps_n_dumpers(const char *name,
                return -1;
 
        for (i = 0; i < nb_rx_queues; i++) {
-               internals->rx_queue->pcap = rx_queues->pcaps[i];
-               internals->rx_queue->name = rx_queues->names[i];
-               internals->rx_queue->type = rx_queues->types[i];
+               internals->rx_queue[i].pcap = rx_queues->pcaps[i];
+               snprintf(internals->rx_queue[i].name,
+                       sizeof(internals->rx_queue[i].name), "%s",
+                       rx_queues->names[i]);
+               snprintf(internals->rx_queue[i].type,
+                       sizeof(internals->rx_queue[i].type), "%s",
+                       rx_queues->types[i]);
        }
        for (i = 0; i < nb_tx_queues; i++) {
-               internals->tx_queue->dumper = tx_queues->dumpers[i];
-               internals->tx_queue->name = tx_queues->names[i];
-               internals->tx_queue->type = tx_queues->types[i];
+               internals->tx_queue[i].dumper = tx_queues->dumpers[i];
+               snprintf(internals->tx_queue[i].name,
+                       sizeof(internals->tx_queue[i].name), "%s",
+                       tx_queues->names[i]);
+               snprintf(internals->tx_queue[i].type,
+                       sizeof(internals->tx_queue[i].type), "%s",
+                       tx_queues->types[i]);
        }
 
        /* using multiple pcaps/interfaces */
@@ -812,7 +819,6 @@ rte_eth_from_pcaps_n_dumpers(const char *name,
        return 0;
 }
 
-       struct rx_pcaps pcaps;
 static int
 rte_eth_from_pcaps(const char *name,
                struct rx_pcaps *rx_queues,
@@ -838,14 +844,22 @@ rte_eth_from_pcaps(const char *name,
                return -1;
 
        for (i = 0; i < nb_rx_queues; i++) {
-               internals->rx_queue->pcap = rx_queues->pcaps[i];
-               internals->rx_queue->name = rx_queues->names[i];
-               internals->rx_queue->type = rx_queues->types[i];
+               internals->rx_queue[i].pcap = rx_queues->pcaps[i];
+               snprintf(internals->rx_queue[i].name,
+                       sizeof(internals->rx_queue[i].name), "%s",
+                       rx_queues->names[i]);
+               snprintf(internals->rx_queue[i].type,
+                       sizeof(internals->rx_queue[i].type), "%s",
+                       rx_queues->types[i]);
        }
        for (i = 0; i < nb_tx_queues; i++) {
-               internals->tx_queue->pcap = tx_queues->pcaps[i];
-               internals->tx_queue->name = tx_queues->names[i];
-               internals->tx_queue->type = tx_queues->types[i];
+               internals->tx_queue[i].dumper = tx_queues->dumpers[i];
+               snprintf(internals->tx_queue[i].name,
+                       sizeof(internals->tx_queue[i].name), "%s",
+                       tx_queues->names[i]);
+               snprintf(internals->tx_queue[i].type,
+                       sizeof(internals->tx_queue[i].type), "%s",
+                       tx_queues->types[i]);
        }
 
        /* store wether we are using a single interface for rx/tx or not */
@@ -888,12 +902,13 @@ rte_pmd_pcap_devinit(const char *name, const char *params)
                ret = rte_kvargs_process(kvlist, ETH_PCAP_IFACE_ARG,
                                &open_rx_tx_iface, &pcaps);
                if (ret < 0)
-                       return -1;
+                       goto free_kvlist;
                dumpers.pcaps[0] = pcaps.pcaps[0];
                dumpers.names[0] = pcaps.names[0];
                dumpers.types[0] = pcaps.types[0];
-               return rte_eth_from_pcaps(name, &pcaps, 1, &dumpers, 1,
+               ret = rte_eth_from_pcaps(name, &pcaps, 1, &dumpers, 1,
                                numa_node, kvlist, 1);
+               goto free_kvlist;
        }
 
        /*
@@ -911,7 +926,7 @@ rte_pmd_pcap_devinit(const char *name, const char *params)
        }
 
        if (ret < 0)
-               return -1;
+               goto free_kvlist;
 
        /*
         * We check whether we want to open a TX stream to a real NIC or a
@@ -930,15 +945,18 @@ rte_pmd_pcap_devinit(const char *name, const char *params)
        }
 
        if (ret < 0)
-               return -1;
+               goto free_kvlist;
 
        if (using_dumpers)
-               return rte_eth_from_pcaps_n_dumpers(name, &pcaps, pcaps.num_of_rx,
+               ret = rte_eth_from_pcaps_n_dumpers(name, &pcaps, pcaps.num_of_rx,
                                &dumpers, dumpers.num_of_tx, numa_node, kvlist);
-
-       return rte_eth_from_pcaps(name, &pcaps, pcaps.num_of_rx, &dumpers,
+       else
+               ret = rte_eth_from_pcaps(name, &pcaps, pcaps.num_of_rx, &dumpers,
                        dumpers.num_of_tx, numa_node, kvlist, 0);
 
+free_kvlist:
+       rte_kvargs_free(kvlist);
+       return ret;
 }
 
 static int