From: Reshma Pattan <reshma.pattan@intel.com>
To: dev@dpdk.org
Cc: Reshma Pattan <reshma.pattan@intel.com>
Subject: [dpdk-dev] [PATCH v10 5/7] pdump: add new library for packet capturing support
Date: Wed, 15 Jun 2016 15:06:22 +0100 [thread overview]
Message-ID: <1465999584-6343-6-git-send-email-reshma.pattan@intel.com> (raw)
In-Reply-To: <1465999584-6343-1-git-send-email-reshma.pattan@intel.com>
The librte_pdump library provides a framework for
packet capturing in dpdk. The library provides set of
APIs to initialize the packet capture framework, to
enable or disable the packet capture, and to uninitialize
it.
The librte_pdump library works on a client/server model.
The server is responsible for enabling or disabling the
packet capture and the clients are responsible
for requesting the enabling or disabling of the packet
capture.
Enabling APIs are supported with port, queue, ring and
mempool parameters. Applications should pass on this information
to get the packets from the dpdk ports.
For enabling requests from applications, library creates the client
request containing the mempool, ring, port and queue information and
sends the request to the server. After receiving the request, server
registers the Rx and Tx callbacks for all the port and queues.
After the callbacks registration, registered callbacks will get the
Rx and Tx packets. Packets then will be copied to the new mbufs that
are allocated from the user passed mempool. These new mbufs then will
be enqueued to the application passed ring. Applications need to dequeue
the mbufs from the rings and direct them to the devices like
pcap vdev for viewing the packets outside of the dpdk
using the packet capture tools.
For disabling requests, library creates the client request containing
the port and queue information and sends the request to the server.
After receiving the request, server removes the Rx and Tx callback
for all the port and queues.
Update the release notes.
Added programmers guide for librte_pdump.
Updated the MAINTAINERS file.
Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
---
MAINTAINERS | 5 +
config/common_base | 5 +
doc/guides/prog_guide/index.rst | 1 +
doc/guides/prog_guide/pdump_library.rst | 123 +++++
doc/guides/rel_notes/release_16_07.rst | 4 +
lib/Makefile | 1 +
lib/librte_pdump/Makefile | 55 ++
lib/librte_pdump/rte_pdump.c | 913 ++++++++++++++++++++++++++++++++
lib/librte_pdump/rte_pdump.h | 216 ++++++++
lib/librte_pdump/rte_pdump_version.map | 13 +
mk/rte.app.mk | 1 +
11 files changed, 1337 insertions(+)
create mode 100644 doc/guides/prog_guide/pdump_library.rst
create mode 100644 lib/librte_pdump/Makefile
create mode 100644 lib/librte_pdump/rte_pdump.c
create mode 100644 lib/librte_pdump/rte_pdump.h
create mode 100644 lib/librte_pdump/rte_pdump_version.map
diff --git a/MAINTAINERS b/MAINTAINERS
index 3e6b70c..afb2d0c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -433,6 +433,11 @@ F: app/test/test_reorder*
F: examples/packet_ordering/
F: doc/guides/sample_app_ug/packet_ordering.rst
+Pdump
+M: Reshma Pattan <reshma.pattan@intel.com>
+F: lib/librte_pdump/
+F: doc/guides/prog_guide/pdump_library.rst
+
Hierarchical scheduler
M: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
F: lib/librte_sched/
diff --git a/config/common_base b/config/common_base
index b9ba405..943730b 100644
--- a/config/common_base
+++ b/config/common_base
@@ -484,6 +484,11 @@ CONFIG_RTE_LIBRTE_DISTRIBUTOR=y
CONFIG_RTE_LIBRTE_REORDER=y
#
+# Compile the pdump library
+#
+CONFIG_RTE_LIBRTE_PDUMP=y
+
+#
# Compile librte_port
#
CONFIG_RTE_LIBRTE_PORT=y
diff --git a/doc/guides/prog_guide/index.rst b/doc/guides/prog_guide/index.rst
index b862d0c..47030c2 100644
--- a/doc/guides/prog_guide/index.rst
+++ b/doc/guides/prog_guide/index.rst
@@ -52,6 +52,7 @@ Programmer's Guide
packet_distrib_lib
reorder_lib
ip_fragment_reassembly_lib
+ pdump_library
multi_proc_support
kernel_nic_interface
thread_safety_dpdk_functions
diff --git a/doc/guides/prog_guide/pdump_library.rst b/doc/guides/prog_guide/pdump_library.rst
new file mode 100644
index 0000000..580ffcb
--- /dev/null
+++ b/doc/guides/prog_guide/pdump_library.rst
@@ -0,0 +1,123 @@
+.. BSD LICENSE
+ Copyright(c) 2016 Intel Corporation. All rights reserved.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+ * Neither the name of Intel Corporation nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+.. _pdump_library:
+
+The librte_pdump Library
+========================
+
+The ``librte_pdump`` library provides a framework for packet capturing in DPDK.
+The library does the complete copy of the Rx and Tx mbufs to a new mempool and
+hence it slows down the performance of the applications, so it is recommended
+to use this library for debugging purposes.
+
+The library provides the following APIs to initialize the packet capture framework, to enable
+or disable the packet capture, and to uninitialize it:
+
+* ``rte_pdump_init()``:
+ This API initializes the packet capture framework.
+
+* ``rte_pdump_enable()``:
+ This API enables the packet capture on a given port and queue.
+ Note: The filter option in the API is a place holder for future enhancements.
+
+* ``rte_pdump_enable_by_deviceid()``:
+ This API enables the packet capture on a given device id (``vdev name or pci address``) and queue.
+ Note: The filter option in the API is a place holder for future enhancements.
+
+* ``rte_pdump_disable()``:
+ This API disables the packet capture on a given port and queue.
+
+* ``rte_pdump_disable_by_deviceid()``:
+ This API disables the packet capture on a given device id (``vdev name or pci address``) and queue.
+
+* ``rte_pdump_uninit()``:
+ This API uninitializes the packet capture framework.
+
+* ``rte_pdump_set_socket_dir()``:
+ This API sets the server and client socket paths.
+ Note: This API is not thread-safe.
+
+
+Operation
+---------
+
+The ``librte_pdump`` library works on a client/server model. The server is responsible for enabling or
+disabling the packet capture and the clients are responsible for requesting the enabling or disabling of
+the packet capture.
+
+The packet capture framework, as part of its initialization, creates the pthread and the server socket in
+the pthread. The application that calls the framework initialization will have the server socket created,
+either under the path that the application has passed or under the default path i.e. either ``/var/run`` for
+root user or ``$HOME`` for non root user.
+
+Applications that request enabling or disabling of the packet capture will have the client socket created either under
+the path that the application has passed or under the default path i.e. either ``/var/run/`` for root user or ``$HOME``
+for not root user to send the requests to the server.
+The server socket will listen for client requests for enabling or disabling the packet capture.
+
+
+Implementation Details
+----------------------
+
+The library API ``rte_pdump_init()``, initializes the packet capture framework by creating the pthread and the server
+socket. The server socket in the pthread context will be listening to the client requests to enable or disable the
+packet capture.
+
+The library APIs ``rte_pdump_enable()`` and ``rte_pdump_enable_by_deviceid()`` enables the packet capture.
+On each call to these APIs, the library creates a separate client socket, creates the "pdump enable" request and sends
+the request to the server. The server that is listening on the socket will take the request and enable the packet capture
+by registering the Ethernet RX and TX callbacks for the given port or device_id and queue combinations.
+Then the server will mirror the packets to the new mempool and enqueue them to the rte_ring that clients have passed
+to these APIs. The server also sends the response back to the client about the status of the request that was processed.
+After the response is received from the server, the client socket is closed.
+
+The library APIs ``rte_pdump_disable()`` and ``rte_pdump_disable_by_deviceid()`` disables the packet capture.
+On each call to these APIs, the library creates a separate client socket, creates the "pdump disable" request and sends
+the request to the server. The server that is listening on the socket will take the request and disable the packet
+capture by removing the Ethernet RX and TX callbacks for the given port or device_id and queue combinations. The server
+also sends the response back to the client about the status of the request that was processed. After the response is
+received from the server, the client socket is closed.
+
+The library API ``rte_pdump_uninit()``, uninitializes the packet capture framework by closing the pthread and the
+server socket.
+
+The library API ``rte_pdump_set_socket_dir()``, sets the given path as either server socket path
+or client socket path based on the ``type`` argument of the API.
+If the given path is ``NULL``, default path will be selected, i.e. either ``/var/run/`` for root user or ``$HOME``
+for non root user. Clients also need to call this API to set their server socket path if the server socket
+path is different from default path.
+
+
+Use Case: Packet Capturing
+--------------------------
+
+The DPDK ``app/pdump`` tool is developed based on this library to capture packets in DPDK.
+Users can use this as an example to develop their own packet capturing tools.
diff --git a/doc/guides/rel_notes/release_16_07.rst b/doc/guides/rel_notes/release_16_07.rst
index c6222f8..2137779 100644
--- a/doc/guides/rel_notes/release_16_07.rst
+++ b/doc/guides/rel_notes/release_16_07.rst
@@ -66,6 +66,10 @@ New Features
* Enable RSS per network interface through the configuration file.
* Streamline the CLI code.
+* **Added packet capture framework.**
+
+ * A new library ``librte_pdump`` is added to provide packet capture APIs.
+
Resolved Issues
---------------
diff --git a/lib/Makefile b/lib/Makefile
index f254dba..ca7c02f 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -57,6 +57,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_PORT) += librte_port
DIRS-$(CONFIG_RTE_LIBRTE_TABLE) += librte_table
DIRS-$(CONFIG_RTE_LIBRTE_PIPELINE) += librte_pipeline
DIRS-$(CONFIG_RTE_LIBRTE_REORDER) += librte_reorder
+DIRS-$(CONFIG_RTE_LIBRTE_PDUMP) += librte_pdump
ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
DIRS-$(CONFIG_RTE_LIBRTE_KNI) += librte_kni
diff --git a/lib/librte_pdump/Makefile b/lib/librte_pdump/Makefile
new file mode 100644
index 0000000..af81a28
--- /dev/null
+++ b/lib/librte_pdump/Makefile
@@ -0,0 +1,55 @@
+# BSD LICENSE
+#
+# Copyright(c) 2016 Intel Corporation. All rights reserved.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Intel Corporation nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+# library name
+LIB = librte_pdump.a
+
+CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3
+CFLAGS += -D_GNU_SOURCE
+
+EXPORT_MAP := rte_pdump_version.map
+
+LIBABIVER := 1
+
+# all source are stored in SRCS-y
+SRCS-$(CONFIG_RTE_LIBRTE_PDUMP) := rte_pdump.c
+
+# install this header file
+SYMLINK-$(CONFIG_RTE_LIBRTE_PDUMP)-include := rte_pdump.h
+
+# this lib depends upon:
+DEPDIRS-$(CONFIG_RTE_LIBRTE_PDUMP) += lib/librte_mbuf
+DEPDIRS-$(CONFIG_RTE_LIBRTE_PDUMP) += lib/librte_eal
+DEPDIRS-$(CONFIG_RTE_LIBRTE_PDUMP) += lib/librte_ether
+
+include $(RTE_SDK)/mk/rte.lib.mk
diff --git a/lib/librte_pdump/rte_pdump.c b/lib/librte_pdump/rte_pdump.c
new file mode 100644
index 0000000..c921f51
--- /dev/null
+++ b/lib/librte_pdump/rte_pdump.c
@@ -0,0 +1,913 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright(c) 2016 Intel Corporation. All rights reserved.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <pthread.h>
+#include <stdbool.h>
+#include <stdio.h>
+
+#include <rte_memcpy.h>
+#include <rte_mbuf.h>
+#include <rte_ethdev.h>
+#include <rte_lcore.h>
+#include <rte_log.h>
+#include <rte_errno.h>
+#include <rte_pci.h>
+
+#include "rte_pdump.h"
+
+#define SOCKET_PATH_VAR_RUN "/var/run/pdump_sockets"
+#define SOCKET_PATH_HOME "HOME/pdump_sockets"
+#define SERVER_SOCKET "%s/pdump_server_socket"
+#define CLIENT_SOCKET "%s/pdump_client_socket_%d_%u"
+#define DEVICE_ID_SIZE 64
+/* Macros for printing using RTE_LOG */
+#define RTE_LOGTYPE_PDUMP RTE_LOGTYPE_USER1
+
+enum pdump_operation {
+ DISABLE = 1,
+ ENABLE = 2
+};
+
+enum pdump_version {
+ V1 = 1
+};
+
+static pthread_t pdump_thread;
+static int pdump_socket_fd;
+static char server_socket_dir[PATH_MAX];
+static char client_socket_dir[PATH_MAX];
+
+struct pdump_request {
+ uint16_t ver;
+ uint16_t op;
+ uint32_t flags;
+ union pdump_data {
+ struct enable_v1 {
+ char device[DEVICE_ID_SIZE];
+ uint16_t queue;
+ struct rte_ring *ring;
+ struct rte_mempool *mp;
+ void *filter;
+ } en_v1;
+ struct disable_v1 {
+ char device[DEVICE_ID_SIZE];
+ uint16_t queue;
+ struct rte_ring *ring;
+ struct rte_mempool *mp;
+ void *filter;
+ } dis_v1;
+ } data;
+};
+
+struct pdump_response {
+ uint16_t ver;
+ uint16_t res_op;
+ int32_t err_value;
+};
+
+static struct pdump_rxtx_cbs {
+ struct rte_ring *ring;
+ struct rte_mempool *mp;
+ struct rte_eth_rxtx_callback *cb;
+ void *filter;
+} rx_cbs[RTE_MAX_ETHPORTS][RTE_MAX_QUEUES_PER_PORT],
+tx_cbs[RTE_MAX_ETHPORTS][RTE_MAX_QUEUES_PER_PORT];
+
+static inline int
+pdump_pktmbuf_copy_data(struct rte_mbuf *seg, const struct rte_mbuf *m)
+{
+ if (rte_pktmbuf_tailroom(seg) < m->data_len) {
+ RTE_LOG(ERR, PDUMP,
+ "User mempool: insufficient data_len of mbuf\n");
+ return -EINVAL;
+ }
+
+ seg->port = m->port;
+ seg->vlan_tci = m->vlan_tci;
+ seg->hash = m->hash;
+ seg->tx_offload = m->tx_offload;
+ seg->ol_flags = m->ol_flags;
+ seg->packet_type = m->packet_type;
+ seg->vlan_tci_outer = m->vlan_tci_outer;
+ seg->data_len = m->data_len;
+ seg->pkt_len = seg->data_len;
+ rte_memcpy(rte_pktmbuf_mtod(seg, void *),
+ rte_pktmbuf_mtod(m, void *),
+ rte_pktmbuf_data_len(seg));
+
+ return 0;
+}
+
+static inline struct rte_mbuf *
+pdump_pktmbuf_copy(struct rte_mbuf *m, struct rte_mempool *mp)
+{
+ struct rte_mbuf *m_dup, *seg, **prev;
+ uint32_t pktlen;
+ uint8_t nseg;
+
+ m_dup = rte_pktmbuf_alloc(mp);
+ if (unlikely(m_dup == NULL))
+ return NULL;
+
+ seg = m_dup;
+ prev = &seg->next;
+ pktlen = m->pkt_len;
+ nseg = 0;
+
+ do {
+ nseg++;
+ if (pdump_pktmbuf_copy_data(seg, m) < 0) {
+ rte_pktmbuf_free(m_dup);
+ return NULL;
+ }
+ *prev = seg;
+ prev = &seg->next;
+ } while ((m = m->next) != NULL &&
+ (seg = rte_pktmbuf_alloc(mp)) != NULL);
+
+ *prev = NULL;
+ m_dup->nb_segs = nseg;
+ m_dup->pkt_len = pktlen;
+
+ /* Allocation of new indirect segment failed */
+ if (unlikely(seg == NULL)) {
+ rte_pktmbuf_free(m_dup);
+ return NULL;
+ }
+
+ __rte_mbuf_sanity_check(m_dup, 1);
+ return m_dup;
+}
+
+static inline void
+pdump_copy(struct rte_mbuf **pkts, uint16_t nb_pkts, void *user_params)
+{
+ unsigned i;
+ int ring_enq;
+ uint16_t d_pkts = 0;
+ struct rte_mbuf *dup_bufs[nb_pkts];
+ struct pdump_rxtx_cbs *cbs;
+ struct rte_ring *ring;
+ struct rte_mempool *mp;
+ struct rte_mbuf *p;
+
+ cbs = user_params;
+ ring = cbs->ring;
+ mp = cbs->mp;
+ for (i = 0; i < nb_pkts; i++) {
+ p = pdump_pktmbuf_copy(pkts[i], mp);
+ if (p)
+ dup_bufs[d_pkts++] = p;
+ }
+
+ ring_enq = rte_ring_enqueue_burst(ring, (void *)dup_bufs, d_pkts);
+ if (unlikely(ring_enq < d_pkts)) {
+ RTE_LOG(DEBUG, PDUMP,
+ "only %d of packets enqueued to ring\n", ring_enq);
+ do {
+ rte_pktmbuf_free(dup_bufs[ring_enq]);
+ } while (++ring_enq < d_pkts);
+ }
+}
+
+static uint16_t
+pdump_rx(uint8_t port __rte_unused, uint16_t qidx __rte_unused,
+ struct rte_mbuf **pkts, uint16_t nb_pkts,
+ uint16_t max_pkts __rte_unused,
+ void *user_params)
+{
+ pdump_copy(pkts, nb_pkts, user_params);
+ return nb_pkts;
+}
+
+static uint16_t
+pdump_tx(uint8_t port __rte_unused, uint16_t qidx __rte_unused,
+ struct rte_mbuf **pkts, uint16_t nb_pkts, void *user_params)
+{
+ pdump_copy(pkts, nb_pkts, user_params);
+ return nb_pkts;
+}
+
+static int
+pdump_get_dombdf(char *device_id, char *domBDF, size_t len)
+{
+ int ret;
+ struct rte_pci_addr dev_addr = {0};
+
+ /* identify if device_id is pci address or name */
+ ret = eal_parse_pci_DomBDF(device_id, &dev_addr);
+ if (ret < 0)
+ return -1;
+
+ if (dev_addr.domain)
+ ret = snprintf(domBDF, len, "%u:%u:%u.%u", dev_addr.domain,
+ dev_addr.bus, dev_addr.devid,
+ dev_addr.function);
+ else
+ ret = snprintf(domBDF, len, "%u:%u.%u", dev_addr.bus,
+ dev_addr.devid,
+ dev_addr.function);
+
+ return ret;
+}
+
+static int
+pdump_regitser_rx_callbacks(uint16_t end_q, uint8_t port, uint16_t queue,
+ struct rte_ring *ring, struct rte_mempool *mp,
+ uint16_t operation)
+{
+ uint16_t qid;
+ struct pdump_rxtx_cbs *cbs = NULL;
+
+ qid = (queue == RTE_PDUMP_ALL_QUEUES) ? 0 : queue;
+ for (; qid < end_q; qid++) {
+ cbs = &rx_cbs[port][qid];
+ if (cbs && operation == ENABLE) {
+ if (cbs->cb) {
+ RTE_LOG(ERR, PDUMP,
+ "failed to add rx callback for port=%d "
+ "and queue=%d, callback already exists\n",
+ port, qid);
+ return -EEXIST;
+ }
+ cbs->ring = ring;
+ cbs->mp = mp;
+ cbs->cb = rte_eth_add_first_rx_callback(port, qid,
+ pdump_rx, cbs);
+ if (cbs->cb == NULL) {
+ RTE_LOG(ERR, PDUMP,
+ "failed to add rx callback, errno=%d\n",
+ rte_errno);
+ return rte_errno;
+ }
+ }
+ if (cbs && operation == DISABLE) {
+ int ret;
+
+ if (cbs->cb == NULL) {
+ RTE_LOG(ERR, PDUMP,
+ "failed to delete non existing rx "
+ "callback for port=%d and queue=%d\n",
+ port, qid);
+ return -EINVAL;
+ }
+ ret = rte_eth_remove_rx_callback(port, qid, cbs->cb);
+ if (ret < 0) {
+ RTE_LOG(ERR, PDUMP,
+ "failed to remove rx callback, errno=%d\n",
+ rte_errno);
+ return ret;
+ }
+ cbs->cb = NULL;
+ }
+ }
+
+ return 0;
+}
+
+static int
+pdump_regitser_tx_callbacks(uint16_t end_q, uint8_t port, uint16_t queue,
+ struct rte_ring *ring, struct rte_mempool *mp,
+ uint16_t operation)
+{
+
+ uint16_t qid;
+ struct pdump_rxtx_cbs *cbs = NULL;
+
+ qid = (queue == RTE_PDUMP_ALL_QUEUES) ? 0 : queue;
+ for (; qid < end_q; qid++) {
+ cbs = &tx_cbs[port][qid];
+ if (cbs && operation == ENABLE) {
+ if (cbs->cb) {
+ RTE_LOG(ERR, PDUMP,
+ "failed to add tx callback for port=%d "
+ "and queue=%d, callback already exists\n",
+ port, qid);
+ return -EEXIST;
+ }
+ cbs->ring = ring;
+ cbs->mp = mp;
+ cbs->cb = rte_eth_add_tx_callback(port, qid, pdump_tx,
+ cbs);
+ if (cbs->cb == NULL) {
+ RTE_LOG(ERR, PDUMP,
+ "failed to add tx callback, errno=%d\n",
+ rte_errno);
+ return rte_errno;
+ }
+ }
+ if (cbs && operation == DISABLE) {
+ int ret;
+
+ if (cbs->cb == NULL) {
+ RTE_LOG(ERR, PDUMP,
+ "failed to delete non existing tx "
+ "callback for port=%d and queue=%d\n",
+ port, qid);
+ return -EINVAL;
+ }
+ ret = rte_eth_remove_tx_callback(port, qid, cbs->cb);
+ if (ret < 0) {
+ RTE_LOG(ERR, PDUMP,
+ "failed to remove tx callback, errno=%d\n",
+ rte_errno);
+ return ret;
+ }
+ cbs->cb = NULL;
+ }
+ }
+
+ return 0;
+}
+
+static int
+set_pdump_rxtx_cbs(struct pdump_request *p)
+{
+ uint16_t nb_rx_q, nb_tx_q = 0, end_q, queue;
+ uint8_t port;
+ int ret = 0;
+ uint32_t flags;
+ uint16_t operation;
+ struct rte_ring *ring;
+ struct rte_mempool *mp;
+
+ flags = p->flags;
+ operation = p->op;
+ if (operation == ENABLE) {
+ ret = rte_eth_dev_get_port_by_name(p->data.en_v1.device,
+ &port);
+ if (ret < 0) {
+ RTE_LOG(ERR, PDUMP,
+ "failed to get potid for device id=%s\n",
+ p->data.en_v1.device);
+ return -EINVAL;
+ }
+ queue = p->data.en_v1.queue;
+ ring = p->data.en_v1.ring;
+ mp = p->data.en_v1.mp;
+ } else {
+ ret = rte_eth_dev_get_port_by_name(p->data.dis_v1.device,
+ &port);
+ if (ret < 0) {
+ RTE_LOG(ERR, PDUMP,
+ "failed to get potid for device id=%s\n",
+ p->data.dis_v1.device);
+ return -EINVAL;
+ }
+ queue = p->data.dis_v1.queue;
+ ring = p->data.dis_v1.ring;
+ mp = p->data.dis_v1.mp;
+ }
+
+ /* validation if packet capture is for all queues */
+ if (queue == RTE_PDUMP_ALL_QUEUES) {
+ struct rte_eth_dev_info dev_info;
+
+ rte_eth_dev_info_get(port, &dev_info);
+ nb_rx_q = dev_info.nb_rx_queues;
+ nb_tx_q = dev_info.nb_tx_queues;
+ if (nb_rx_q == 0 && flags & RTE_PDUMP_FLAG_RX) {
+ RTE_LOG(ERR, PDUMP,
+ "number of rx queues cannot be 0\n");
+ return -EINVAL;
+ }
+ if (nb_tx_q == 0 && flags & RTE_PDUMP_FLAG_TX) {
+ RTE_LOG(ERR, PDUMP,
+ "number of tx queues cannot be 0\n");
+ return -EINVAL;
+ }
+ if ((nb_tx_q == 0 || nb_rx_q == 0) &&
+ flags == RTE_PDUMP_FLAG_RXTX) {
+ RTE_LOG(ERR, PDUMP,
+ "both tx&rx queues must be non zero\n");
+ return -EINVAL;
+ }
+ }
+
+ /* register RX callback */
+ if (flags & RTE_PDUMP_FLAG_RX) {
+ end_q = (queue == RTE_PDUMP_ALL_QUEUES) ? nb_rx_q : queue + 1;
+ ret = pdump_regitser_rx_callbacks(end_q, port, queue, ring, mp,
+ operation);
+ if (ret < 0)
+ return ret;
+ }
+
+ /* register TX callback */
+ if (flags & RTE_PDUMP_FLAG_TX) {
+ end_q = (queue == RTE_PDUMP_ALL_QUEUES) ? nb_tx_q : queue + 1;
+ ret = pdump_regitser_tx_callbacks(end_q, port, queue, ring, mp,
+ operation);
+ if (ret < 0)
+ return ret;
+ }
+
+ return ret;
+}
+
+/* get socket path (/var/run if root, $HOME otherwise) */
+static void
+pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type)
+{
+ const char *dir = NULL;
+
+ if (type == RTE_PDUMP_SOCKET_SERVER && server_socket_dir[0] != 0)
+ dir = server_socket_dir;
+ else if (type == RTE_PDUMP_SOCKET_CLIENT && client_socket_dir[0] != 0)
+ dir = client_socket_dir;
+ else {
+ if (getuid() != 0)
+ dir = getenv(SOCKET_PATH_HOME);
+ else
+ dir = SOCKET_PATH_VAR_RUN;
+ }
+
+ mkdir(dir, 700);
+ if (type == RTE_PDUMP_SOCKET_SERVER)
+ snprintf(buffer, bufsz, SERVER_SOCKET, dir);
+ else
+ snprintf(buffer, bufsz, CLIENT_SOCKET, dir, getpid(),
+ rte_sys_gettid());
+}
+
+static int
+pdump_create_server_socket(void)
+{
+ int ret, socket_fd;
+ struct sockaddr_un addr;
+ socklen_t addr_len;
+
+ pdump_get_socket_path(addr.sun_path, sizeof(addr.sun_path),
+ RTE_PDUMP_SOCKET_SERVER);
+ addr.sun_family = AF_UNIX;
+
+ /* remove if file already exists */
+ unlink(addr.sun_path);
+
+ /* set up a server socket */
+ socket_fd = socket(AF_UNIX, SOCK_DGRAM, 0);
+ if (socket_fd < 0) {
+ RTE_LOG(ERR, PDUMP,
+ "Failed to create server socket: %s, %s:%d\n",
+ strerror(errno), __func__, __LINE__);
+ return -1;
+ }
+
+ addr_len = sizeof(struct sockaddr_un);
+ ret = bind(socket_fd, (struct sockaddr *) &addr, addr_len);
+ if (ret) {
+ RTE_LOG(ERR, PDUMP,
+ "Failed to bind to server socket: %s, %s:%d\n",
+ strerror(errno), __func__, __LINE__);
+ close(socket_fd);
+ return -1;
+ }
+
+ /* save the socket in local configuration */
+ pdump_socket_fd = socket_fd;
+
+ return 0;
+}
+
+static __attribute__((noreturn)) void *
+pdump_thread_main(__rte_unused void *arg)
+{
+ struct sockaddr_un cli_addr;
+ socklen_t cli_len;
+ struct pdump_request cli_req;
+ struct pdump_response resp;
+ int n;
+ int ret = 0;
+
+ /* host thread, never break out */
+ for (;;) {
+ /* recv client requests */
+ cli_len = sizeof(cli_addr);
+ n = recvfrom(pdump_socket_fd, &cli_req,
+ sizeof(struct pdump_request), 0,
+ (struct sockaddr *)&cli_addr, &cli_len);
+ if (n < 0) {
+ RTE_LOG(ERR, PDUMP,
+ "failed to recv from client:%s, %s:%d\n",
+ strerror(errno), __func__, __LINE__);
+ continue;
+ }
+
+ ret = set_pdump_rxtx_cbs(&cli_req);
+
+ resp.ver = cli_req.ver;
+ resp.res_op = cli_req.op;
+ resp.err_value = ret;
+ n = sendto(pdump_socket_fd, &resp,
+ sizeof(struct pdump_response),
+ 0, (struct sockaddr *)&cli_addr, cli_len);
+ if (n < 0) {
+ RTE_LOG(ERR, PDUMP,
+ "failed to send to client:%s, %s:%d\n",
+ strerror(errno), __func__, __LINE__);
+ }
+ }
+}
+
+int
+rte_pdump_init(const char *path)
+{
+ int ret = 0;
+ char thread_name[RTE_MAX_THREAD_NAME_LEN];
+
+ ret = rte_pdump_set_socket_dir(path, RTE_PDUMP_SOCKET_SERVER);
+ if (ret != 0)
+ return -1;
+
+ ret = pdump_create_server_socket();
+ if (ret != 0) {
+ RTE_LOG(ERR, PDUMP,
+ "Failed to create server socket:%s:%d\n",
+ __func__, __LINE__);
+ return -1;
+ }
+
+ /* create the host thread to wait/handle pdump requests */
+ ret = pthread_create(&pdump_thread, NULL, pdump_thread_main, NULL);
+ if (ret != 0) {
+ RTE_LOG(ERR, PDUMP,
+ "Failed to create the pdump thread:%s, %s:%d\n",
+ strerror(errno), __func__, __LINE__);
+ return -1;
+ }
+ /* Set thread_name for aid in debugging. */
+ snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN, "pdump-thread");
+ ret = rte_thread_setname(pdump_thread, thread_name);
+ if (ret != 0) {
+ RTE_LOG(DEBUG, PDUMP,
+ "Failed to set thread name for pdump handling\n");
+ }
+
+ return 0;
+}
+
+int
+rte_pdump_uninit(void)
+{
+ int ret;
+
+ ret = pthread_cancel(pdump_thread);
+ if (ret != 0) {
+ RTE_LOG(ERR, PDUMP,
+ "Failed to cancel the pdump thread:%s, %s:%d\n",
+ strerror(errno), __func__, __LINE__);
+ return -1;
+ }
+
+ ret = close(pdump_socket_fd);
+ if (ret != 0) {
+ RTE_LOG(ERR, PDUMP,
+ "Failed to close server socket: %s, %s:%d\n",
+ strerror(errno), __func__, __LINE__);
+ return -1;
+ }
+
+ struct sockaddr_un addr;
+
+ pdump_get_socket_path(addr.sun_path, sizeof(addr.sun_path),
+ RTE_PDUMP_SOCKET_SERVER);
+ ret = unlink(addr.sun_path);
+ if (ret != 0) {
+ RTE_LOG(ERR, PDUMP,
+ "Failed to remove server socket addr: %s, %s:%d\n",
+ strerror(errno), __func__, __LINE__);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int
+pdump_create_client_socket(struct pdump_request *p)
+{
+ int ret, socket_fd;
+ int pid;
+ int n;
+ struct pdump_response server_resp;
+ struct sockaddr_un addr, serv_addr, from;
+ socklen_t addr_len, serv_len;
+
+ pid = getpid();
+
+ socket_fd = socket(AF_UNIX, SOCK_DGRAM, 0);
+ if (socket_fd < 0) {
+ RTE_LOG(ERR, PDUMP,
+ "client socket(): %s:pid(%d):tid(%u), %s:%d\n",
+ strerror(errno), pid, rte_sys_gettid(),
+ __func__, __LINE__);
+ ret = errno;
+ return ret;
+ }
+
+ pdump_get_socket_path(addr.sun_path, sizeof(addr.sun_path),
+ RTE_PDUMP_SOCKET_CLIENT);
+ addr.sun_family = AF_UNIX;
+ addr_len = sizeof(struct sockaddr_un);
+
+ do {
+ ret = bind(socket_fd, (struct sockaddr *) &addr, addr_len);
+ if (ret) {
+ RTE_LOG(ERR, PDUMP,
+ "client bind(): %s, %s:%d\n",
+ strerror(errno), __func__, __LINE__);
+ ret = errno;
+ break;
+ }
+
+ serv_len = sizeof(struct sockaddr_un);
+ memset(&serv_addr, 0, sizeof(serv_addr));
+ pdump_get_socket_path(serv_addr.sun_path,
+ sizeof(serv_addr.sun_path),
+ RTE_PDUMP_SOCKET_SERVER);
+ serv_addr.sun_family = AF_UNIX;
+
+ n = sendto(socket_fd, p, sizeof(struct pdump_request), 0,
+ (struct sockaddr *)&serv_addr, serv_len);
+ if (n < 0) {
+ RTE_LOG(ERR, PDUMP,
+ "failed to send to server:%s, %s:%d\n",
+ strerror(errno), __func__, __LINE__);
+ ret = errno;
+ break;
+ }
+
+ n = recvfrom(socket_fd, &server_resp,
+ sizeof(struct pdump_response), 0,
+ (struct sockaddr *)&from, &serv_len);
+ if (n < 0) {
+ RTE_LOG(ERR, PDUMP,
+ "failed to recv from server:%s, %s:%d\n",
+ strerror(errno), __func__, __LINE__);
+ ret = errno;
+ break;
+ }
+ ret = server_resp.err_value;
+ } while (0);
+
+ close(socket_fd);
+ unlink(addr.sun_path);
+ return ret;
+}
+
+static int
+pdump_validate_ring_mp(struct rte_ring *ring, struct rte_mempool *mp)
+{
+ if (ring == NULL || mp == NULL) {
+ RTE_LOG(ERR, PDUMP, "NULL ring or mempool are passed %s:%d\n",
+ __func__, __LINE__);
+ rte_errno = EINVAL;
+ return -1;
+ }
+ if (mp->flags & MEMPOOL_F_SP_PUT || mp->flags & MEMPOOL_F_SC_GET) {
+ RTE_LOG(ERR, PDUMP, "mempool with either SP or SC settings"
+ " is not valid for pdump, should have MP and MC settings\n");
+ rte_errno = EINVAL;
+ return -1;
+ }
+ if (ring->prod.sp_enqueue || ring->cons.sc_dequeue) {
+ RTE_LOG(ERR, PDUMP, "ring with either SP or SC settings"
+ " is not valid for pdump, should have MP and MC settings\n");
+ rte_errno = EINVAL;
+ return -1;
+ }
+
+ return 0;
+}
+
+static int
+pdump_validate_flags(uint32_t flags)
+{
+ if (flags != RTE_PDUMP_FLAG_RX && flags != RTE_PDUMP_FLAG_TX &&
+ flags != RTE_PDUMP_FLAG_RXTX) {
+ RTE_LOG(ERR, PDUMP,
+ "invalid flags, should be either rx/tx/rxtx\n");
+ rte_errno = EINVAL;
+ return -1;
+ }
+
+ return 0;
+}
+
+static int
+pdump_validate_port(uint8_t port, char *name)
+{
+ int ret = 0;
+
+ if (port >= RTE_MAX_ETHPORTS) {
+ RTE_LOG(ERR, PDUMP, "Invalid port id %u, %s:%d\n", port,
+ __func__, __LINE__);
+ rte_errno = EINVAL;
+ return -1;
+ }
+
+ ret = rte_eth_dev_get_name_by_port(port, name);
+ if (ret < 0) {
+ RTE_LOG(ERR, PDUMP,
+ "port id to name mapping failed for port id=%u, %s:%d\n",
+ port, __func__, __LINE__);
+ rte_errno = EINVAL;
+ return -1;
+ }
+
+ return 0;
+}
+
+static int
+pdump_prepare_client_request(char *device, uint16_t queue,
+ uint32_t flags,
+ uint16_t operation,
+ struct rte_ring *ring,
+ struct rte_mempool *mp,
+ void *filter)
+{
+ int ret;
+ struct pdump_request req = {.ver = 1,};
+
+ req.flags = flags;
+ req.op = operation;
+ if ((operation & ENABLE) != 0) {
+ strncpy(req.data.en_v1.device, device, strlen(device));
+ req.data.en_v1.queue = queue;
+ req.data.en_v1.ring = ring;
+ req.data.en_v1.mp = mp;
+ req.data.en_v1.filter = filter;
+ } else {
+ strncpy(req.data.dis_v1.device, device, strlen(device));
+ req.data.dis_v1.queue = queue;
+ req.data.dis_v1.ring = NULL;
+ req.data.dis_v1.mp = NULL;
+ req.data.dis_v1.filter = NULL;
+ }
+
+ ret = pdump_create_client_socket(&req);
+ if (ret < 0) {
+ RTE_LOG(ERR, PDUMP,
+ "client request for pdump enable/disable failed\n");
+ rte_errno = ret;
+ return -1;
+ }
+
+ return 0;
+}
+
+int
+rte_pdump_enable(uint8_t port, uint16_t queue, uint32_t flags,
+ struct rte_ring *ring,
+ struct rte_mempool *mp,
+ void *filter)
+{
+
+ int ret = 0;
+ char name[DEVICE_ID_SIZE];
+
+ ret = pdump_validate_port(port, name);
+ if (ret < 0)
+ return ret;
+ ret = pdump_validate_ring_mp(ring, mp);
+ if (ret < 0)
+ return ret;
+ ret = pdump_validate_flags(flags);
+ if (ret < 0)
+ return ret;
+
+ ret = pdump_prepare_client_request(name, queue, flags,
+ ENABLE, ring, mp, filter);
+
+ return ret;
+}
+
+int
+rte_pdump_enable_by_deviceid(char *device_id, uint16_t queue,
+ uint32_t flags,
+ struct rte_ring *ring,
+ struct rte_mempool *mp,
+ void *filter)
+{
+ int ret = 0;
+ char domBDF[DEVICE_ID_SIZE];
+
+ ret = pdump_validate_ring_mp(ring, mp);
+ if (ret < 0)
+ return ret;
+ ret = pdump_validate_flags(flags);
+ if (ret < 0)
+ return ret;
+
+ if (pdump_get_dombdf(device_id, domBDF, sizeof(domBDF)) > 0)
+ ret = pdump_prepare_client_request(domBDF, queue, flags,
+ ENABLE, ring, mp, filter);
+ else
+ ret = pdump_prepare_client_request(device_id, queue, flags,
+ ENABLE, ring, mp, filter);
+
+ return ret;
+}
+
+int
+rte_pdump_disable(uint8_t port, uint16_t queue, uint32_t flags)
+{
+ int ret = 0;
+ char name[DEVICE_ID_SIZE];
+
+ ret = pdump_validate_port(port, name);
+ if (ret < 0)
+ return ret;
+ ret = pdump_validate_flags(flags);
+ if (ret < 0)
+ return ret;
+
+ ret = pdump_prepare_client_request(name, queue, flags,
+ DISABLE, NULL, NULL, NULL);
+
+ return ret;
+}
+
+int
+rte_pdump_disable_by_deviceid(char *device_id, uint16_t queue,
+ uint32_t flags)
+{
+ int ret = 0;
+ char domBDF[DEVICE_ID_SIZE];
+
+ ret = pdump_validate_flags(flags);
+ if (ret < 0)
+ return ret;
+
+ if (pdump_get_dombdf(device_id, domBDF, sizeof(domBDF)) > 0)
+ ret = pdump_prepare_client_request(domBDF, queue, flags,
+ DISABLE, NULL, NULL, NULL);
+ else
+ ret = pdump_prepare_client_request(device_id, queue, flags,
+ DISABLE, NULL, NULL, NULL);
+
+ return ret;
+}
+
+int
+rte_pdump_set_socket_dir(const char *path, enum rte_pdump_socktype type)
+{
+ int ret, count;
+
+ if (path != NULL) {
+ if (type == RTE_PDUMP_SOCKET_SERVER) {
+ count = sizeof(server_socket_dir);
+ ret = snprintf(server_socket_dir, count, "%s", path);
+ } else {
+ count = sizeof(client_socket_dir);
+ ret = snprintf(client_socket_dir, count, "%s", path);
+ }
+
+ if (ret < 0 || ret >= count) {
+ RTE_LOG(ERR, PDUMP,
+ "Invalid socket path:%s:%d\n",
+ __func__, __LINE__);
+ if (type == RTE_PDUMP_SOCKET_SERVER)
+ server_socket_dir[0] = 0;
+ else
+ client_socket_dir[0] = 0;
+ return -EINVAL;
+ }
+ }
+
+ return 0;
+}
diff --git a/lib/librte_pdump/rte_pdump.h b/lib/librte_pdump/rte_pdump.h
new file mode 100644
index 0000000..b5f4e2f
--- /dev/null
+++ b/lib/librte_pdump/rte_pdump.h
@@ -0,0 +1,216 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright(c) 2016 Intel Corporation. All rights reserved.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _RTE_PDUMP_H_
+#define _RTE_PDUMP_H_
+
+/**
+ * @file
+ * RTE pdump
+ *
+ * packet dump library to provide packet capturing support on dpdk.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define RTE_PDUMP_ALL_QUEUES UINT16_MAX
+
+enum {
+ RTE_PDUMP_FLAG_RX = 1, /* receive direction */
+ RTE_PDUMP_FLAG_TX = 2, /* transmit direction */
+ /* both receive and transmit directions */
+ RTE_PDUMP_FLAG_RXTX = (RTE_PDUMP_FLAG_RX|RTE_PDUMP_FLAG_TX)
+};
+
+enum rte_pdump_socktype {
+ RTE_PDUMP_SOCKET_SERVER = 1,
+ RTE_PDUMP_SOCKET_CLIENT = 2
+};
+
+/**
+ * Initialize packet capturing handling
+ *
+ * Creates pthread and server socket for handling clients
+ * requests to enable/disable rxtx callbacks.
+ *
+ * @param path
+ * directory path for server socket.
+ *
+ * @return
+ * 0 on success, -1 on error
+ */
+int
+rte_pdump_init(const char *path);
+
+/**
+ * Un initialize packet capturing handling
+ *
+ * Cancels pthread, close server socket, removes server socket address.
+ *
+ * @return
+ * 0 on success, -1 on error
+ */
+int
+rte_pdump_uninit(void);
+
+/**
+ * Enables packet capturing on given port and queue.
+ *
+ * @param port
+ * port on which packet capturing should be enabled.
+ * @param queue
+ * queue of a given port on which packet capturing should be enabled.
+ * users should pass on value UINT16_MAX to enable packet capturing on all
+ * queues of a given port.
+ * @param flags
+ * flags specifies RTE_PDUMP_FLAG_RX/RTE_PDUMP_FLAG_TX/RTE_PDUMP_FLAG_RXTX
+ * on which packet capturing should be enabled for a given port and queue.
+ * @param ring
+ * ring on which captured packets will be enqueued for user.
+ * @param mp
+ * mempool on to which original packets will be mirrored or duplicated.
+ * @param filter
+ * place holder for packet filtering.
+ *
+ * @return
+ * 0 on success, -1 on error, rte_errno is set accordingly.
+ */
+
+int
+rte_pdump_enable(uint8_t port, uint16_t queue, uint32_t flags,
+ struct rte_ring *ring,
+ struct rte_mempool *mp,
+ void *filter);
+
+/**
+ * Disables packet capturing on given port and queue.
+ *
+ * @param port
+ * port on which packet capturing should be disabled.
+ * @param queue
+ * queue of a given port on which packet capturing should be disabled.
+ * users should pass on value UINT16_MAX to disable packet capturing on all
+ * queues of a given port.
+ * @param flags
+ * flags specifies RTE_PDUMP_FLAG_RX/RTE_PDUMP_FLAG_TX/RTE_PDUMP_FLAG_RXTX
+ * on which packet capturing should be enabled for a given port and queue.
+ *
+ * @return
+ * 0 on success, -1 on error, rte_errno is set accordingly.
+ */
+
+int
+rte_pdump_disable(uint8_t port, uint16_t queue, uint32_t flags);
+
+/**
+ * Enables packet capturing on given device id and queue.
+ * device_id can be name or pci address of device.
+ *
+ * @param device_id
+ * device id on which packet capturing should be enabled.
+ * @param queue
+ * queue of a given device id on which packet capturing should be enabled.
+ * users should pass on value UINT16_MAX to enable packet capturing on all
+ * queues of a given device id.
+ * @param flags
+ * flags specifies RTE_PDUMP_FLAG_RX/RTE_PDUMP_FLAG_TX/RTE_PDUMP_FLAG_RXTX
+ * on which packet capturing should be enabled for a given port and queue.
+ * @param ring
+ * ring on which captured packets will be enqueued for user.
+ * @param mp
+ * mempool on to which original packets will be mirrored or duplicated.
+ * @param filter
+ * place holder for packet filtering.
+ *
+ * @return
+ * 0 on success, -1 on error, rte_errno is set accordingly.
+ */
+
+int
+rte_pdump_enable_by_deviceid(char *device_id, uint16_t queue,
+ uint32_t flags,
+ struct rte_ring *ring,
+ struct rte_mempool *mp,
+ void *filter);
+
+/**
+ * Disables packet capturing on given device_id and queue.
+ * device_id can be name or pci address of device.
+ *
+ * @param device_id
+ * pci address or name of the device on which packet capturing
+ * should be disabled.
+ * @param queue
+ * queue of a given device on which packet capturing should be disabled.
+ * users should pass on value UINT16_MAX to disable packet capturing on all
+ * queues of a given device id.
+ * @param flags
+ * flags specifies RTE_PDUMP_FLAG_RX/RTE_PDUMP_FLAG_TX/RTE_PDUMP_FLAG_RXTX
+ * on which packet capturing should be enabled for a given port and queue.
+ *
+ * @return
+ * 0 on success, -1 on error, rte_errno is set accordingly.
+ */
+int
+rte_pdump_disable_by_deviceid(char *device_id, uint16_t queue,
+ uint32_t flags);
+
+/**
+ * Allows applications to set server and client socket paths.
+ * If specified path is null default path will be selected, i.e.
+ *"/var/run/" for root user and "$HOME" for non root user.
+ * Clients also need to call this API to set their server path if the
+ * server path is different from default path.
+ * This API is not thread-safe.
+ *
+ * @param path
+ * directory path for server or client socket.
+ * @type
+ * specifies RTE_PDUMP_SOCKET_SERVER if socket path is for server.
+ * (or)
+ * specifies RTE_PDUMP_SOCKET_CLIENT if socket path is for client.
+ *
+ * @return
+ * 0 on success, -EINVAL on error
+ *
+ */
+int
+rte_pdump_set_socket_dir(const char *path, enum rte_pdump_socktype type);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_PDUMP_H_ */
diff --git a/lib/librte_pdump/rte_pdump_version.map b/lib/librte_pdump/rte_pdump_version.map
new file mode 100644
index 0000000..edec99a
--- /dev/null
+++ b/lib/librte_pdump/rte_pdump_version.map
@@ -0,0 +1,13 @@
+DPDK_16.07 {
+ global:
+
+ rte_pdump_disable;
+ rte_pdump_disable_by_deviceid;
+ rte_pdump_enable;
+ rte_pdump_enable_by_deviceid;
+ rte_pdump_init;
+ rte_pdump_set_socket_dir;
+ rte_pdump_uninit;
+
+ local: *;
+};
diff --git a/mk/rte.app.mk b/mk/rte.app.mk
index e9969fc..f894669 100644
--- a/mk/rte.app.mk
+++ b/mk/rte.app.mk
@@ -78,6 +78,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_LPM) += -lrte_lpm
_LDLIBS-$(CONFIG_RTE_LIBRTE_ACL) += -lrte_acl
_LDLIBS-$(CONFIG_RTE_LIBRTE_JOBSTATS) += -lrte_jobstats
_LDLIBS-$(CONFIG_RTE_LIBRTE_POWER) += -lrte_power
+_LDLIBS-$(CONFIG_RTE_LIBRTE_PDUMP) += -lrte_pdump
_LDLIBS-y += --whole-archive
--
2.5.0
next prev parent reply other threads:[~2016-06-15 14:06 UTC|newest]
Thread overview: 67+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1465487895-5870-1-git-send-email-reshma.pattan@intel.com>
2016-06-10 16:18 ` [dpdk-dev] [PATCH v8 0/8] add packet capture framework Reshma Pattan
2016-06-10 16:18 ` [dpdk-dev] [PATCH v8 1/8] librte_ether: protect add/remove of rxtx callbacks with spinlocks Reshma Pattan
2016-06-10 16:18 ` [dpdk-dev] [PATCH v8 2/8] librte_ether: add new api rte_eth_add_first_rx_callback Reshma Pattan
2016-06-10 16:18 ` [dpdk-dev] [PATCH v8 3/8] librte_ether: add new fields to rte_eth_dev_info struct Reshma Pattan
2016-06-10 16:18 ` [dpdk-dev] [PATCH v8 4/8] librte_ether: make rte_eth_dev_get_port_by_name rte_eth_dev_get_name_by_port public Reshma Pattan
2016-06-10 16:18 ` [dpdk-dev] [PATCH v8 5/8] lib/librte_pdump: add new library for packet capturing support Reshma Pattan
2016-06-10 18:48 ` Aaron Conole
2016-06-10 22:14 ` Pattan, Reshma
2016-06-13 13:28 ` Aaron Conole
2016-06-10 16:18 ` [dpdk-dev] [PATCH v8 6/8] app/pdump: add pdump tool for packet capturing Reshma Pattan
2016-06-10 16:18 ` [dpdk-dev] [PATCH v8 7/8] app/test-pmd: add pdump initialization uninitialization Reshma Pattan
2016-06-10 16:18 ` [dpdk-dev] [PATCH v8 8/8] doc: update doc for packet capture framework Reshma Pattan
2016-06-10 23:23 ` [dpdk-dev] [PATCH v8 0/8] add " Neil Horman
2016-06-13 8:47 ` Pattan, Reshma
2016-06-14 9:38 ` [dpdk-dev] [PATCH v9 " Reshma Pattan
2016-06-14 9:38 ` [dpdk-dev] [PATCH v9 1/8] ethdev: use locks to protect Rx/Tx callback lists Reshma Pattan
2016-06-14 19:59 ` Thomas Monjalon
2016-06-15 5:30 ` Pattan, Reshma
2016-06-15 8:19 ` Thomas Monjalon
2016-06-15 8:37 ` Ananyev, Konstantin
2016-06-15 8:48 ` Thomas Monjalon
2016-06-15 9:54 ` Ananyev, Konstantin
2016-06-15 11:17 ` Thomas Monjalon
2016-06-15 13:49 ` Thomas Monjalon
2016-06-15 12:15 ` Ivan Boule
2016-06-15 12:40 ` Ananyev, Konstantin
2016-06-15 13:29 ` Bruce Richardson
2016-06-15 14:07 ` Ivan Boule
2016-06-15 14:19 ` Bruce Richardson
2016-06-15 14:20 ` Ananyev, Konstantin
2016-06-15 14:22 ` Bruce Richardson
2016-06-15 14:27 ` Ananyev, Konstantin
2016-06-15 15:33 ` Ivan Boule
2016-06-14 9:38 ` [dpdk-dev] [PATCH v9 2/8] ethdev: add new api to add Rx callback as head of the list Reshma Pattan
2016-06-14 20:01 ` Thomas Monjalon
2016-06-14 21:43 ` Pattan, Reshma
2016-06-14 9:38 ` [dpdk-dev] [PATCH v9 3/8] ethdev: add new fields to ethdev info struct Reshma Pattan
2016-06-14 20:10 ` Thomas Monjalon
2016-06-14 21:57 ` Pattan, Reshma
2016-06-14 9:38 ` [dpdk-dev] [PATCH v9 4/8] ethdev: make get port by name and get name by port public Reshma Pattan
2016-06-14 20:23 ` Thomas Monjalon
2016-06-14 21:55 ` Pattan, Reshma
2016-06-14 9:38 ` [dpdk-dev] [PATCH v9 5/8] pdump: add new library for packet capturing support Reshma Pattan
2016-06-14 20:28 ` Thomas Monjalon
2016-06-14 21:59 ` Pattan, Reshma
2016-06-15 9:05 ` Mcnamara, John
2016-06-15 9:32 ` Thomas Monjalon
2016-06-15 9:43 ` Bruce Richardson
2016-06-15 15:44 ` Mcnamara, John
2016-06-14 9:38 ` [dpdk-dev] [PATCH v9 6/8] app/pdump: add pdump tool for packet capturing Reshma Pattan
2016-06-14 19:56 ` Thomas Monjalon
2016-06-14 9:38 ` [dpdk-dev] [PATCH v9 7/8] app/testpmd: add pdump initialization uninitialization Reshma Pattan
2016-06-14 9:38 ` [dpdk-dev] [PATCH v9 8/8] doc: update doc for packet capture framework Reshma Pattan
2016-06-14 20:41 ` Thomas Monjalon
2016-06-15 5:44 ` Pattan, Reshma
2016-06-15 8:24 ` Thomas Monjalon
2016-06-15 14:06 ` [dpdk-dev] [PATCH v10 0/7] add " Reshma Pattan
2016-06-15 14:06 ` [dpdk-dev] [PATCH v10 1/7] ethdev: use locks to protect Rx/Tx callback lists Reshma Pattan
2016-06-15 14:06 ` [dpdk-dev] [PATCH v10 2/7] ethdev: add new api to add Rx callback as head of the list Reshma Pattan
2016-06-15 14:06 ` [dpdk-dev] [PATCH v10 3/7] ethdev: add new fields to ethdev info struct Reshma Pattan
2016-06-16 19:14 ` Thomas Monjalon
2016-06-15 14:06 ` [dpdk-dev] [PATCH v10 4/7] ethdev: make get port by name and get name by port public Reshma Pattan
2016-06-16 20:27 ` Thomas Monjalon
2016-06-15 14:06 ` Reshma Pattan [this message]
2016-06-15 14:06 ` [dpdk-dev] [PATCH v10 6/7] app/pdump: add pdump tool for packet capturing Reshma Pattan
2016-06-15 14:06 ` [dpdk-dev] [PATCH v10 7/7] app/testpmd: add pdump initialization uninitialization Reshma Pattan
2016-06-16 21:55 ` [dpdk-dev] [PATCH v10 0/7] add packet capture framework Thomas Monjalon
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=1465999584-6343-6-git-send-email-reshma.pattan@intel.com \
--to=reshma.pattan@intel.com \
--cc=dev@dpdk.org \
/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).