Skip to contentSkip to conversation

Packet Capture enhancements

RFC In review Stephen Hemminger 4 participants 20 messages Oct 7, 2019 – Oct 9, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Packet Capture enhancements

This is a set of patches to provide enhanced capabilities for packet capture. It adds new features to base pdump library (with API versioning); new PCAPNG output formatter and new application which works like dumpcap from Wireshark.

Stephen Hemminger (8):
pdump: use new pktmbuf copy function
pdump: use dynamic logtype
pdump: tag copied mbuf with port
pdump: stamp packets with current timestamp
pdump: add classic BPF filtering
pdump: add packet header truncation
pcapng: add new library for writing pcapng files app/capture: add packet capture using pcapng

 app/Makefile                             |   1 +
 app/capture/Makefile                     |  19 +
 app/capture/main.c                       | 675 +++++++++++++++++++++++
 app/capture/meson.build                  |  22 +
 app/meson.build                          |   1 +
 app/pdump/main.c                         |  32 +-
 app/test/test_pdump.c                    |  10 +-
 config/common_base                       |  11 +
 lib/Makefile                             |   2 +
 lib/librte_pcapng/Makefile               |  22 +
 lib/librte_pcapng/meson.build            |  10 +
 lib/librte_pcapng/pcapng_proto.h         | 112 ++++
 lib/librte_pcapng/rte_pcapng.c           | 449 +++++++++++++++
 lib/librte_pcapng/rte_pcapng.h           | 132 +++++
 lib/librte_pcapng/rte_pcapng_version.map |  12 +
 lib/librte_pdump/Makefile                |   2 +-
 lib/librte_pdump/pdump_bpf.h             | 168 ++++++
 lib/librte_pdump/rte_pcap_filter.c       | 462 ++++++++++++++++
 lib/librte_pdump/rte_pdump.c             | 326 ++++++-----
 lib/librte_pdump/rte_pdump.h             |  65 ++-
 lib/librte_pdump/rte_pdump_version.map   |   7 +
 lib/meson.build                          |   2 +-
 mk/rte.app.mk                            |   1 +
 23 files changed, 2367 insertions(+), 176 deletions(-)
 create mode 100644 app/capture/Makefile
 create mode 100644 app/capture/main.c
 create mode 100644 app/capture/meson.build
 create mode 100644 lib/librte_pcapng/Makefile
 create mode 100644 lib/librte_pcapng/meson.build
 create mode 100644 lib/librte_pcapng/pcapng_proto.h
 create mode 100644 lib/librte_pcapng/rte_pcapng.c
 create mode 100644 lib/librte_pcapng/rte_pcapng.h
 create mode 100644 lib/librte_pcapng/rte_pcapng_version.map
 create mode 100644 lib/librte_pdump/pdump_bpf.h
 create mode 100644 lib/librte_pdump/rte_pcap_filter.c
Signature · 1 line
2.20.1
#1 lore raw

RFC 1/8 pdump: use new pktmbuf copy function

The rte_pktmbuf_copy handles varying size mbuf pools correctly.

---
 lib/librte_pdump/rte_pdump.c | 69 +-----------------------------------
 1 file changed, 1 insertion(+), 68 deletions(-)
lib/librte_pdump/rte_pdump.c +1 -68
index cd24dd010951..c665cf237f65 100644
@@ -64,73 +64,6 @@ static struct pdump_rxtx_cbs {
 } 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;
-	uint16_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) {
-			if (seg != m_dup)
-				rte_pktmbuf_free_seg(seg);
-			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)
@@ -148,7 +81,7 @@ pdump_copy(struct rte_mbuf **pkts, uint16_t nb_pkts, void *user_params)
 	ring = cbs->ring;
 	mp = cbs->mp;
 	for (i = 0; i < nb_pkts; i++) {
-		p = pdump_pktmbuf_copy(pkts[i], mp);
+		p = rte_pktmbuf_copy(pkts[i], mp, 0, UINT32_MAX);
 		if (p)
 			dup_bufs[d_pkts++] = p;
 	}
Signature · 1 line
2.20.1
#2 lore raw

RFC 2/8 pdump: use dynamic logtype

In reply to Stephen Hemminger

The logtype USER1 should not be overloaded for library function. Instead use a dynamic log type.

---
 lib/librte_pdump/rte_pdump.c | 68 ++++++++++++++++++++----------------
 1 file changed, 38 insertions(+), 30 deletions(-)
lib/librte_pdump/rte_pdump.c +38 -30
index c665cf237f65..cfb8be7ca227 100644
@@ -13,8 +13,12 @@
 #include "rte_pdump.h"
 
 #define DEVICE_ID_SIZE 64
-/* Macros for printing using RTE_LOG */
-#define RTE_LOGTYPE_PDUMP RTE_LOGTYPE_USER1
+
+/* Macro for printing using RTE_LOG */
+static int pdump_logtype;
+#define PDUMP_LOG(level, fmt, args...)				\
+	rte_log(RTE_LOG_ ## level, pdump_logtype, "%s(): " fmt,	\
+		__func__, ## args)
 
 /* Used for the multi-process communication */
 #define PDUMP_MP	"mp_pdump"
@@ -88,7 +92,7 @@ pdump_copy(struct rte_mbuf **pkts, uint16_t nb_pkts, void *user_params)
 
 	ring_enq = rte_ring_enqueue_burst(ring, (void *)dup_bufs, d_pkts, NULL);
 	if (unlikely(ring_enq < d_pkts)) {
-		RTE_LOG(DEBUG, PDUMP,
+		PDUMP_LOG(DEBUG,
 			"only %d of packets enqueued to ring\n", ring_enq);
 		do {
 			rte_pktmbuf_free(dup_bufs[ring_enq]);
@@ -127,7 +131,7 @@ pdump_register_rx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue,
 		cbs = &rx_cbs[port][qid];
 		if (cbs && operation == ENABLE) {
 			if (cbs->cb) {
-				RTE_LOG(ERR, PDUMP,
+				PDUMP_LOG(ERR,
 					"failed to add rx callback for port=%d "
 					"and queue=%d, callback already exists\n",
 					port, qid);
@@ -138,7 +142,7 @@ pdump_register_rx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue,
 			cbs->cb = rte_eth_add_first_rx_callback(port, qid,
 								pdump_rx, cbs);
 			if (cbs->cb == NULL) {
-				RTE_LOG(ERR, PDUMP,
+				PDUMP_LOG(ERR,
 					"failed to add rx callback, errno=%d\n",
 					rte_errno);
 				return rte_errno;
@@ -148,7 +152,7 @@ pdump_register_rx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue,
 			int ret;
 
 			if (cbs->cb == NULL) {
-				RTE_LOG(ERR, PDUMP,
+				PDUMP_LOG(ERR,
 					"failed to delete non existing rx "
 					"callback for port=%d and queue=%d\n",
 					port, qid);
@@ -156,7 +160,7 @@ pdump_register_rx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue,
 			}
 			ret = rte_eth_remove_rx_callback(port, qid, cbs->cb);
 			if (ret < 0) {
-				RTE_LOG(ERR, PDUMP,
+				PDUMP_LOG(ERR,
 					"failed to remove rx callback, errno=%d\n",
 					-ret);
 				return ret;
@@ -182,7 +186,7 @@ pdump_register_tx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue,
 		cbs = &tx_cbs[port][qid];
 		if (cbs && operation == ENABLE) {
 			if (cbs->cb) {
-				RTE_LOG(ERR, PDUMP,
+				PDUMP_LOG(ERR,
 					"failed to add tx callback for port=%d "
 					"and queue=%d, callback already exists\n",
 					port, qid);
@@ -193,7 +197,7 @@ pdump_register_tx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue,
 			cbs->cb = rte_eth_add_tx_callback(port, qid, pdump_tx,
 								cbs);
 			if (cbs->cb == NULL) {
-				RTE_LOG(ERR, PDUMP,
+				PDUMP_LOG(ERR,
 					"failed to add tx callback, errno=%d\n",
 					rte_errno);
 				return rte_errno;
@@ -203,7 +207,7 @@ pdump_register_tx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue,
 			int ret;
 
 			if (cbs->cb == NULL) {
-				RTE_LOG(ERR, PDUMP,
+				PDUMP_LOG(ERR,
 					"failed to delete non existing tx "
 					"callback for port=%d and queue=%d\n",
 					port, qid);
@@ -211,7 +215,7 @@ pdump_register_tx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue,
 			}
 			ret = rte_eth_remove_tx_callback(port, qid, cbs->cb);
 			if (ret < 0) {
-				RTE_LOG(ERR, PDUMP,
+				PDUMP_LOG(ERR,
 					"failed to remove tx callback, errno=%d\n",
 					-ret);
 				return ret;
@@ -240,7 +244,7 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)
 		ret = rte_eth_dev_get_port_by_name(p->data.en_v1.device,
 				&port);
 		if (ret < 0) {
-			RTE_LOG(ERR, PDUMP,
+			PDUMP_LOG(ERR,
 				"failed to get port id for device id=%s\n",
 				p->data.en_v1.device);
 			return -EINVAL;
@@ -252,7 +256,7 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)
 		ret = rte_eth_dev_get_port_by_name(p->data.dis_v1.device,
 				&port);
 		if (ret < 0) {
-			RTE_LOG(ERR, PDUMP,
+			PDUMP_LOG(ERR,
 				"failed to get port id for device id=%s\n",
 				p->data.dis_v1.device);
 			return -EINVAL;
@@ -270,18 +274,18 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)
 		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,
+			PDUMP_LOG(ERR,
 				"number of rx queues cannot be 0\n");
 			return -EINVAL;
 		}
 		if (nb_tx_q == 0 && flags & RTE_PDUMP_FLAG_TX) {
-			RTE_LOG(ERR, PDUMP,
+			PDUMP_LOG(ERR,
 				"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,
+			PDUMP_LOG(ERR,
 				"both tx&rx queues must be non zero\n");
 			return -EINVAL;
 		}
@@ -317,7 +321,7 @@ pdump_server(const struct rte_mp_msg *mp_msg, const void *peer)
 
 	/* recv client requests */
 	if (mp_msg->len_param != sizeof(*cli_req)) {
-		RTE_LOG(ERR, PDUMP, "failed to recv from client\n");
+		PDUMP_LOG(ERR, "failed to recv from client\n");
 		resp->err_value = -EINVAL;
 	} else {
 		cli_req = (const struct pdump_request *)mp_msg->param;
@@ -330,8 +334,8 @@ pdump_server(const struct rte_mp_msg *mp_msg, const void *peer)
 	mp_resp.len_param = sizeof(*resp);
 	mp_resp.num_fds = 0;
 	if (rte_mp_reply(&mp_resp, peer) < 0) {
-		RTE_LOG(ERR, PDUMP, "failed to send to client:%s, %s:%d\n",
-			strerror(rte_errno), __func__, __LINE__);
+		PDUMP_LOG(ERR, "failed to send to client:%s\n",
+			  strerror(rte_errno));
 		return -1;
 	}
 
@@ -359,19 +363,18 @@ 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__);
+		PDUMP_LOG(ERR, "NULL ring or mempool\n");
 		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"
+		PDUMP_LOG(ERR, "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.single || ring->cons.single) {
-		RTE_LOG(ERR, PDUMP, "ring with either SP or SC settings"
+		PDUMP_LOG(ERR, "ring with either SP or SC settings"
 		" is not valid for pdump, should have MP and MC settings\n");
 		rte_errno = EINVAL;
 		return -1;
@@ -385,7 +388,7 @@ 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,
+		PDUMP_LOG(ERR,
 			"invalid flags, should be either rx/tx/rxtx\n");
 		rte_errno = EINVAL;
 		return -1;
@@ -400,17 +403,15 @@ pdump_validate_port(uint16_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__);
+		PDUMP_LOG(ERR, "Invalid port id %u\n", port);
 		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__);
+		PDUMP_LOG(ERR, "port %u to name mapping failed\n",
+			  port);
 		rte_errno = EINVAL;
 		return -1;
 	}
@@ -465,7 +466,7 @@ pdump_prepare_client_request(char *device, uint16_t queue,
 	}
 
 	if (ret < 0)
-		RTE_LOG(ERR, PDUMP,
+		PDUMP_LOG(ERR,
 			"client request for pdump enable/disable failed\n");
 	return ret;
 }
@@ -552,3 +553,10 @@ rte_pdump_disable_by_deviceid(char *device_id, uint16_t queue,
 
 	return ret;
 }
+
+RTE_INIT(pdump_log)
+{
+	pdump_logtype = rte_log_register("lib.pdump");
+	if (pdump_logtype >= 0)
+		rte_log_set_level(pdump_logtype, RTE_LOG_NOTICE);
+}
Signature · 1 line
2.20.1
#3 lore raw

RFC 3/8 pdump: tag copied mbuf with port

In reply to Stephen Hemminger

Set the port when packets go into ring, so same ring can be used for multiple ports.

---
 lib/librte_pdump/rte_pdump.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
lib/librte_pdump/rte_pdump.c +10 -8
index cfb8be7ca227..830decef91e2 100644
@@ -68,9 +68,9 @@ static struct pdump_rxtx_cbs {
 } rx_cbs[RTE_MAX_ETHPORTS][RTE_MAX_QUEUES_PER_PORT],
 tx_cbs[RTE_MAX_ETHPORTS][RTE_MAX_QUEUES_PER_PORT];
 
-
-static inline void
-pdump_copy(struct rte_mbuf **pkts, uint16_t nb_pkts, void *user_params)
+static void
+pdump_copy(uint16_t port, struct rte_mbuf **pkts,
+	   uint16_t nb_pkts, void *user_params)
 {
 	unsigned i;
 	int ring_enq;
@@ -86,8 +86,10 @@ pdump_copy(struct rte_mbuf **pkts, uint16_t nb_pkts, void *user_params)
 	mp = cbs->mp;
 	for (i = 0; i < nb_pkts; i++) {
 		p = rte_pktmbuf_copy(pkts[i], mp, 0, UINT32_MAX);
-		if (p)
+		if (p) {
+			p->port = port;
 			dup_bufs[d_pkts++] = p;
+		}
 	}
 
 	ring_enq = rte_ring_enqueue_burst(ring, (void *)dup_bufs, d_pkts, NULL);
@@ -101,20 +103,20 @@ pdump_copy(struct rte_mbuf **pkts, uint16_t nb_pkts, void *user_params)
 }
 
 static uint16_t
-pdump_rx(uint16_t port __rte_unused, uint16_t qidx __rte_unused,
+pdump_rx(uint16_t port, 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);
+	pdump_copy(port, pkts, nb_pkts, user_params);
 	return nb_pkts;
 }
 
 static uint16_t
-pdump_tx(uint16_t port __rte_unused, uint16_t qidx __rte_unused,
+pdump_tx(uint16_t port, uint16_t qidx __rte_unused,
 		struct rte_mbuf **pkts, uint16_t nb_pkts, void *user_params)
 {
-	pdump_copy(pkts, nb_pkts, user_params);
+	pdump_copy(port, pkts, nb_pkts, user_params);
 	return nb_pkts;
 }
 
Signature · 1 line
2.20.1
#4 lore raw

RFC 4/8 pdump: stamp packets with current timestamp

In reply to Stephen Hemminger

Put the current cycle count in as timestamp when
they are placed in the ring for packet capture.

---
 lib/librte_pdump/rte_pdump.c | 2 ++
 1 file changed, 2 insertions(+)
lib/librte_pdump/rte_pdump.c +2 -0
index 830decef91e2..41f2ec17a26b 100644
@@ -75,6 +75,7 @@ pdump_copy(uint16_t port, struct rte_mbuf **pkts,
 	unsigned i;
 	int ring_enq;
 	uint16_t d_pkts = 0;
+	uint64_t now = rte_get_tsc_cycles();
 	struct rte_mbuf *dup_bufs[nb_pkts];
 	struct pdump_rxtx_cbs *cbs;
 	struct rte_ring *ring;
@@ -88,6 +89,7 @@ pdump_copy(uint16_t port, struct rte_mbuf **pkts,
 		p = rte_pktmbuf_copy(pkts[i], mp, 0, UINT32_MAX);
 		if (p) {
 			p->port = port;
+			p->timestamp = now;
 			dup_bufs[d_pkts++] = p;
 		}
 	}
Signature · 1 line
2.20.1
#5 lore raw

RFC 5/8 pdump: add classic BPF filtering

In reply to Stephen Hemminger

Simple classic BPF interpreter based off of libpcap.

This is a copy of the BPF interpreter from libpcap which is modified to handle mbuf meta data. The existing pcap_offline_filter does not expose a way to match VLAN tags. Copying the BPF interpreter also means that rte_pdump still does not have a hard dependency on libpcap.

The API for pdump is versioned because the filter needs to know both byte code and length of program to validate it.

This patch does cause a small checkpatch warning because it keeps the original variable names from the pcap code.

---
 app/pdump/main.c                       |  16 +-
 app/test/test_pdump.c                  |   4 +-
 lib/librte_pdump/Makefile              |   2 +-
 lib/librte_pdump/pdump_bpf.h           | 168 +++++++++
 lib/librte_pdump/rte_pcap_filter.c     | 462 +++++++++++++++++++++++++
 lib/librte_pdump/rte_pdump.c           | 145 ++++++--
 lib/librte_pdump/rte_pdump.h           |  54 ++-
 lib/librte_pdump/rte_pdump_version.map |   7 +
 8 files changed, 806 insertions(+), 52 deletions(-)
 create mode 100644 lib/librte_pdump/pdump_bpf.h
 create mode 100644 lib/librte_pdump/rte_pcap_filter.c
app/pdump/main.c +8 -8
index c1b901279f4b..c3eb554ef28b 100644
@@ -828,20 +828,20 @@ enable_pdump(void)
 						pt->queue,
 						RTE_PDUMP_FLAG_RX,
 						pt->rx_ring,
-						pt->mp, NULL);
+						pt->mp, NULL, 0);
 				ret1 = rte_pdump_enable_by_deviceid(
 						pt->device_id,
 						pt->queue,
 						RTE_PDUMP_FLAG_TX,
 						pt->tx_ring,
-						pt->mp, NULL);
+						pt->mp, NULL, 0);
 			} else if (pt->dump_by_type == PORT_ID) {
 				ret = rte_pdump_enable(pt->port, pt->queue,
 						RTE_PDUMP_FLAG_RX,
-						pt->rx_ring, pt->mp, NULL);
+						pt->rx_ring, pt->mp, NULL, 0);
 				ret1 = rte_pdump_enable(pt->port, pt->queue,
 						RTE_PDUMP_FLAG_TX,
-						pt->tx_ring, pt->mp, NULL);
+						pt->tx_ring, pt->mp, NULL, 0);
 			}
 		} else if (pt->dir == RTE_PDUMP_FLAG_RX) {
 			if (pt->dump_by_type == DEVICE_ID)
@@ -849,22 +849,22 @@ enable_pdump(void)
 						pt->device_id,
 						pt->queue,
 						pt->dir, pt->rx_ring,
-						pt->mp, NULL);
+						pt->mp, NULL, 0);
 			else if (pt->dump_by_type == PORT_ID)
 				ret = rte_pdump_enable(pt->port, pt->queue,
 						pt->dir,
-						pt->rx_ring, pt->mp, NULL);
+						pt->rx_ring, pt->mp, NULL, 0);
 		} else if (pt->dir == RTE_PDUMP_FLAG_TX) {
 			if (pt->dump_by_type == DEVICE_ID)
 				ret = rte_pdump_enable_by_deviceid(
 						pt->device_id,
 						pt->queue,
 						pt->dir,
-						pt->tx_ring, pt->mp, NULL);
+						pt->tx_ring, pt->mp, NULL, 0);
 			else if (pt->dump_by_type == PORT_ID)
 				ret = rte_pdump_enable(pt->port, pt->queue,
 						pt->dir,
-						pt->tx_ring, pt->mp, NULL);
+						pt->tx_ring, pt->mp, NULL, 0);
 		}
 		if (ret < 0 || ret1 < 0) {
 			cleanup_pdump_resources();
app/test/test_pdump.c +2 -2
index af206968b38d..f0187a4cd279 100644
@@ -79,7 +79,7 @@ run_pdump_client_tests(void)
 
 	for (itr = 0; itr < NUM_ITR; itr++) {
 		ret = rte_pdump_enable(portid, QUEUE_ID, flags, ring_client,
-				       mp, NULL);
+				       mp, NULL, 0);
 		if (ret < 0) {
 			printf("rte_pdump_enable failed\n");
 			return -1;
@@ -94,7 +94,7 @@ run_pdump_client_tests(void)
 		printf("pdump_disable success\n");
 
 		ret = rte_pdump_enable_by_deviceid(deviceid, QUEUE_ID, flags,
-						   ring_client, mp, NULL);
+						   ring_client, mp, NULL, 0);
 		if (ret < 0) {
 			printf("rte_pdump_enable_by_deviceid failed\n");
 			return -1;
lib/librte_pdump/Makefile +1 -1
index 89593689a7d5..4a631c06a0ec 100644
@@ -15,7 +15,7 @@ EXPORT_MAP := rte_pdump_version.map
 LIBABIVER := 3
 
 # all source are stored in SRCS-y
-SRCS-$(CONFIG_RTE_LIBRTE_PDUMP) := rte_pdump.c
+SRCS-$(CONFIG_RTE_LIBRTE_PDUMP) := rte_pdump.c rte_pcap_filter.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_PDUMP)-include := rte_pdump.h
lib/librte_pdump/pdump_bpf.h new file +168 -0

168 lines not on this page · raw message

lib/librte_pdump/rte_pcap_filter.c new file +462 -0

462 lines not on this page · raw message

lib/librte_pdump/rte_pdump.c +117 -28

277 lines not on this page · raw message

lib/librte_pdump/rte_pdump.h +41 -13

83 lines not on this page · raw message

lib/librte_pdump/rte_pdump_version.map +7 -0
index 3e744f30123c..e78ba5a8350a 100644
@@ -10,3 +10,10 @@ DPDK_16.07 {
 
 	local: *;
 };
+
+DPDK_19.11 {
+	global:
+
+	rte_pdump_enable;
+	rte_pdump_enable_by_deviceid;
+} DPDK_16.07;
Signature · 1 line
2.20.1
#6 lore raw

Re: [dpdk-dev] [RFC 5/8] pdump: add classic BPF filtering

Quoted 8 lines · Stephen Hemminger,

Simple classic BPF interpreter based off of libpcap.

This is a copy of the BPF interpreter from libpcap which is modified to handle mbuf meta data. The existing pcap_offline_filter does not expose a way to match VLAN tags. Copying the BPF interpreter also means that rte_pdump still does not have a hard dependency on libpcap.

Why not use DPDK's librte_bpf library? Rather implementing cBPF interpreter. Currently it supports eBPF which is super set of cBPF.if is this features very specific to cBPF, we clould simply implement cBPF using eBPF or implement a new cBPF program type. That scheme could leverage existing JIT infrastructure also. Using JIT will improve filtering performance.

Quoted 2 lines
#7 lore raw

Re: [dpdk-dev] [RFC 5/8] pdump: add classic BPF filtering

Quoted 12 lines · On Mon, 7 Oct 2019 22:37:43 +0530 Jerin Jacob <[email protected]> wrote:
Quoted 8 lines · Stephen Hemminger,

Simple classic BPF interpreter based off of libpcap.

This is a copy of the BPF interpreter from libpcap which is modified to handle mbuf meta data. The existing pcap_offline_filter does not expose a way to match VLAN tags. Copying the BPF interpreter also means that rte_pdump still does not have a hard dependency on libpcap.

Quoted 9 lines

Why not use DPDK's librte_bpf library? Rather implementing cBPF interpreter. Currently it supports eBPF which is super set of cBPF.if is this features very specific to cBPF, we clould simply implement cBPF using eBPF or implement a new cBPF program type. That scheme could leverage existing JIT infrastructure also. Using JIT will improve filtering performance.

Quoted 2 lines

Because pcap library generates cBPF in its string to BPF compiler. Translating cBPF to eBPF is non trivial.

#8 lore raw

Re: [dpdk-dev] [RFC 5/8] pdump: add classic BPF filtering

Quoted 27 lines · Stephen Hemminger,
Quoted 1 line · On Mon, 7 Oct 2019 22:37:43 +0530 Jerin Jacob <[email protected]> wrote:

On Mon, 7 Oct, 2019, 10:23 PM Stephen Hemminger, <

[email protected]>

Quoted 11 lines
Quoted 8 lines · wrote:

Simple classic BPF interpreter based off of libpcap.

This is a copy of the BPF interpreter from libpcap which is modified to handle mbuf meta data. The existing pcap_offline_filter does not expose a way to match VLAN tags. Copying the BPF interpreter also means that rte_pdump still does not have a hard dependency on libpcap.

Quoted 3 lines

Why not use DPDK's librte_bpf library? Rather implementing cBPF interpreter. Currently it supports eBPF which is super set of cBPF.if is this features very specific to cBPF, we clould simply implement cBPF

using

Quoted 6 lines

eBPF or implement a new cBPF program type. That scheme could leverage existing JIT infrastructure also. Using JIT will improve filtering performance.

Quoted 2 lines
Quoted 3 lines

Because pcap library generates cBPF in its string to BPF compiler. Translating cBPF to eBPF is non trivial.

Then at least cBPF interpreter should move to librte_bpf. We can hook to JIT if required in future.

#9 lore raw

Re: [dpdk-dev] [RFC 5/8] pdump: add classic BPF filtering

Quoted 30 lines · On Tue, 8 Oct 2019 01:03:17 +0530 Jerin Jacob <[email protected]> wrote:
Quoted 27 lines · Stephen Hemminger,
Quoted 1 line · On Mon, 7 Oct 2019 22:37:43 +0530 Jerin Jacob <[email protected]> wrote:

On Mon, 7 Oct, 2019, 10:23 PM Stephen Hemminger, <

[email protected]>

Quoted 11 lines
Quoted 8 lines · wrote:

Simple classic BPF interpreter based off of libpcap.

This is a copy of the BPF interpreter from libpcap which is modified to handle mbuf meta data. The existing pcap_offline_filter does not expose a way to match VLAN tags. Copying the BPF interpreter also means that rte_pdump still does not have a hard dependency on libpcap.

Quoted 3 lines

Why not use DPDK's librte_bpf library? Rather implementing cBPF interpreter. Currently it supports eBPF which is super set of cBPF.if is this features very specific to cBPF, we clould simply implement cBPF

using

Quoted 6 lines

eBPF or implement a new cBPF program type. That scheme could leverage existing JIT infrastructure also. Using JIT will improve filtering performance.

Quoted 2 lines
Quoted 6 lines
Quoted 3 lines

Because pcap library generates cBPF in its string to BPF compiler. Translating cBPF to eBPF is non trivial.

Then at least cBPF interpreter should move to librte_bpf. We can hook to JIT if required in future.

The opcodes for cBPF and eBPF are not compatiable.

#10 lore raw

Re: [dpdk-dev] [RFC 5/8] pdump: add classic BPF filtering

Quoted 37 lines · Stephen Hemminger,
Quoted 1 line · On Tue, 8 Oct 2019 01:03:17 +0530 Jerin Jacob <[email protected]> wrote:

On Mon, 7 Oct, 2019, 11:03 PM Stephen Hemminger, <

[email protected]>

Quoted 6 lines
Quoted 4 lines · wrote:
Quoted 1 line · On Mon, 7 Oct 2019 22:37:43 +0530 Jerin Jacob <[email protected]> wrote:

On Mon, 7 Oct, 2019, 10:23 PM Stephen Hemminger, <

Quoted 8 lines
Quoted 8 lines

[email protected]>

Quoted 7 lines
Quoted 5 lines · wrote:

Simple classic BPF interpreter based off of libpcap.

This is a copy of the BPF interpreter from libpcap which is modified to handle mbuf meta data. The existing pcap_offline_filter does not expose a way to match VLAN tags. Copying the BPF

interpreter

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

also means that rte_pdump still does not have a hard dependency on libpcap.

Why not use DPDK's librte_bpf library? Rather implementing cBPF interpreter. Currently it supports eBPF which is super set of

cBPF.if is

Quoted 1 line
Quoted 1 line
Quoted 1 line

this features very specific to cBPF, we clould simply implement

cBPF

Quoted 8 lines
Quoted 8 lines

using

Quoted 6 lines

eBPF or implement a new cBPF program type. That scheme could leverage existing JIT infrastructure also. Using JIT will improve filtering performance.

Quoted 2 lines
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

Because pcap library generates cBPF in its string to BPF compiler. Translating cBPF to eBPF is non trivial.

Then at least cBPF interpreter should move to librte_bpf. We can hook to JIT if required in future.

The opcodes for cBPF and eBPF are not compatiable.

Yeah. I am saying to add new program type in bpf library of cBPF. Obviously pdump is not the correct place for cBPF interpreter. Moving to rte_libbpf library would help to enable other applications or libraries to use cBPF bpf program class.

#11 lore raw

Re: [dpdk-dev] [RFC 5/8] pdump: add classic BPF filtering

Quoted 47 lines · On Tue, 8 Oct 2019 09:17:08 +0530 Jerin Jacob <[email protected]> wrote:
Quoted 44 lines · Stephen Hemminger,
Quoted 1 line · On Tue, 8 Oct 2019 01:03:17 +0530 Jerin Jacob <[email protected]> wrote:

On Mon, 7 Oct, 2019, 11:03 PM Stephen Hemminger, <

[email protected]>

Quoted 6 lines
Quoted 4 lines · wrote:
Quoted 1 line · On Mon, 7 Oct 2019 22:37:43 +0530 Jerin Jacob <[email protected]> wrote:

On Mon, 7 Oct, 2019, 10:23 PM Stephen Hemminger, <

Quoted 8 lines
Quoted 8 lines

[email protected]>

Quoted 7 lines
Quoted 5 lines · wrote:

Simple classic BPF interpreter based off of libpcap.

This is a copy of the BPF interpreter from libpcap which is modified to handle mbuf meta data. The existing pcap_offline_filter does not expose a way to match VLAN tags. Copying the BPF

interpreter

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

also means that rte_pdump still does not have a hard dependency on libpcap.

Why not use DPDK's librte_bpf library? Rather implementing cBPF interpreter. Currently it supports eBPF which is super set of

cBPF.if is

Quoted 1 line
Quoted 1 line
Quoted 1 line

this features very specific to cBPF, we clould simply implement

cBPF

Quoted 14 lines
Quoted 11 lines

using

Quoted 6 lines

eBPF or implement a new cBPF program type. That scheme could leverage existing JIT infrastructure also. Using JIT will improve filtering performance.

Quoted 2 lines

Because pcap library generates cBPF in its string to BPF compiler. Translating cBPF to eBPF is non trivial.

Then at least cBPF interpreter should move to librte_bpf. We can hook to JIT if required in future.

Quoted 7 lines
Quoted 2 lines

The opcodes for cBPF and eBPF are not compatiable.

Yeah. I am saying to add new program type in bpf library of cBPF. Obviously pdump is not the correct place for cBPF interpreter. Moving to rte_libbpf library would help to enable other applications or libraries to use cBPF bpf program class.

The problem is you need a version of string to BPF program which is what the libpcap pcap_compile() function does for you. eBPF as used now is all about having a full language (CLANG or GCC) and that is not what is needed here at all. The problem is not the interpreter, the problem is on the userspace BPF side. Until/unless that is fixed, cBPF is a better solution.

#12 lore raw

Re: [dpdk-dev] [RFC 5/8] pdump: add classic BPF filtering

Quoted 64 lines · Stephen Hemminger,
Quoted 1 line · On Tue, 8 Oct 2019 09:17:08 +0530 Jerin Jacob <[email protected]> wrote:

On Tue, 8 Oct, 2019, 3:15 AM Stephen Hemminger, <

[email protected]>

Quoted 12 lines
Quoted 10 lines · wrote:
Quoted 1 line · On Tue, 8 Oct 2019 01:03:17 +0530 Jerin Jacob <[email protected]> wrote:

On Mon, 7 Oct, 2019, 11:03 PM Stephen Hemminger, <

[email protected]>

Quoted 5 lines
Quoted 3 lines · wrote:

On Mon, 7 Oct 2019 22:37:43 +0530
Jerin Jacob <[email protected]> wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line

On Mon, 7 Oct, 2019, 10:23 PM Stephen Hemminger, <

[email protected]>

Quoted 6 lines
Quoted 4 lines · wrote:

Simple classic BPF interpreter based off of libpcap.

This is a copy of the BPF interpreter from libpcap which is modified to handle mbuf meta data. The existing

pcap_offline_filter

Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

does not expose a way to match VLAN tags. Copying the BPF

interpreter

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

also means that rte_pdump still does not have a hard dependency on libpcap.

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Why not use DPDK's librte_bpf library? Rather implementing cBPF interpreter. Currently it supports eBPF which is super set of

cBPF.if is

Quoted 1 line
Quoted 1 line
Quoted 1 line

this features very specific to cBPF, we clould simply implement

cBPF

Quoted 2 lines
Quoted 2 lines

using

Quoted 1 line

eBPF or implement a new cBPF program type. That scheme could

leverage

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

existing JIT infrastructure also. Using JIT will improve

filtering

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Quoted 4 lines

performance.

Quoted 2 lines

Because pcap library generates cBPF in its string to BPF compiler. Translating cBPF to eBPF is non trivial.

Then at least cBPF interpreter should move to librte_bpf. We can

hook to

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

JIT if required in future.

The opcodes for cBPF and eBPF are not compatiable.

Yeah. I am saying to add new program type in bpf library of cBPF.

Obviously

Quoted 3 lines

pdump is not the correct place for cBPF interpreter. Moving to rte_libbpf library would help to enable other applications or libraries to use cBPF bpf program class.

Quoted 6 lines

The problem is you need a version of string to BPF program which is what the libpcap pcap_compile() function does for you. eBPF as used now is all about having a full language (CLANG or GCC) and that is not what is needed here at all. The problem is not the interpreter, the problem is on the userspace BPF side. Until/unless that is fixed, cBPF is a better solution.

I am not saying to use eBPF with libpcap. All I am saying to move the cBPF interpreter code(this patch) to rte_libbpf as it is the correct place of that code in DPDK PoV. So that it can be used by another applications or library.

Quoted 1 line
#13 lore raw

Re: [dpdk-dev] [RFC 5/8] pdump: add classic BPF filtering

Quoted 75 lines · On Tue, 8 Oct 2019 09:45:45 +0530 Jerin Jacob <[email protected]> wrote:
Quoted 64 lines · Stephen Hemminger,
Quoted 1 line · On Tue, 8 Oct 2019 09:17:08 +0530 Jerin Jacob <[email protected]> wrote:

On Tue, 8 Oct, 2019, 3:15 AM Stephen Hemminger, <

[email protected]>

Quoted 12 lines
Quoted 10 lines · wrote:
Quoted 1 line · On Tue, 8 Oct 2019 01:03:17 +0530 Jerin Jacob <[email protected]> wrote:

On Mon, 7 Oct, 2019, 11:03 PM Stephen Hemminger, <

[email protected]>

Quoted 5 lines
Quoted 3 lines · wrote:

On Mon, 7 Oct 2019 22:37:43 +0530
Jerin Jacob <[email protected]> wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line

On Mon, 7 Oct, 2019, 10:23 PM Stephen Hemminger, <

[email protected]>

Quoted 6 lines
Quoted 4 lines · wrote:

Simple classic BPF interpreter based off of libpcap.

This is a copy of the BPF interpreter from libpcap which is modified to handle mbuf meta data. The existing

pcap_offline_filter

Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

does not expose a way to match VLAN tags. Copying the BPF

interpreter

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

also means that rte_pdump still does not have a hard dependency on libpcap.

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Why not use DPDK's librte_bpf library? Rather implementing cBPF interpreter. Currently it supports eBPF which is super set of

cBPF.if is

Quoted 1 line
Quoted 1 line
Quoted 1 line

this features very specific to cBPF, we clould simply implement

cBPF

Quoted 2 lines
Quoted 2 lines

using

Quoted 1 line

eBPF or implement a new cBPF program type. That scheme could

leverage

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

existing JIT infrastructure also. Using JIT will improve

filtering

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Quoted 4 lines

performance.

Quoted 2 lines

Because pcap library generates cBPF in its string to BPF compiler. Translating cBPF to eBPF is non trivial.

Then at least cBPF interpreter should move to librte_bpf. We can

hook to

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

JIT if required in future.

The opcodes for cBPF and eBPF are not compatiable.

Yeah. I am saying to add new program type in bpf library of cBPF.

Obviously

Quoted 3 lines

pdump is not the correct place for cBPF interpreter. Moving to rte_libbpf library would help to enable other applications or libraries to use cBPF bpf program class.

Quoted 6 lines

The problem is you need a version of string to BPF program which is what the libpcap pcap_compile() function does for you. eBPF as used now is all about having a full language (CLANG or GCC) and that is not what is needed here at all. The problem is not the interpreter, the problem is on the userspace BPF side. Until/unless that is fixed, cBPF is a better solution.

Quoted 6 lines

I am not saying to use eBPF with libpcap. All I am saying to move the cBPF interpreter code(this patch) to rte_libbpf as it is the correct place of that code in DPDK PoV. So that it can be used by another applications or library.

Quoted 1 line

Sure that make sense?

#14 lore raw

Re: [dpdk-dev] [RFC 5/8] pdump: add classic BPF filtering

Quoted 94 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Stephen Hemminger
Sent: Tuesday, October 8, 2019 6:23 AM

Quoted 1 line · On Tue, 8 Oct 2019 09:45:45 +0530 Jerin Jacob <[email protected]> wrote:

On Tue, 8 Oct, 2019, 9:31 AM Stephen Hemminger,

<[email protected]>

Quoted 23 lines
Quoted 21 lines · wrote:
Quoted 1 line · On Tue, 8 Oct 2019 09:17:08 +0530 Jerin Jacob <[email protected]> wrote:

On Tue, 8 Oct, 2019, 3:15 AM Stephen Hemminger, <

[email protected]>

Quoted 16 lines
Quoted 14 lines · wrote:
Quoted 1 line · On Tue, 8 Oct 2019 01:03:17 +0530 Jerin Jacob <[email protected]> wrote:

On Mon, 7 Oct, 2019, 11:03 PM Stephen Hemminger, <

[email protected]>

Quoted 9 lines
Quoted 7 lines · wrote:
Quoted 1 line · On Mon, 7 Oct 2019 22:37:43 +0530 Jerin Jacob <[email protected]> wrote:

On Mon, 7 Oct, 2019, 10:23 PM Stephen Hemminger, <

[email protected]>

Quoted 2 lines

wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Simple classic BPF interpreter based off of libpcap.

This is a copy of the BPF interpreter from libpcap which is modified to handle mbuf meta data. The existing

pcap_offline_filter

Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

does not expose a way to match VLAN tags. Copying the BPF

interpreter

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

also means that rte_pdump still does not have a hard

dependency

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

on libpcap.

Why not use DPDK's librte_bpf library? Rather implementing

cBPF

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

interpreter. Currently it supports eBPF which is super set of

cBPF.if is

Quoted 1 line
Quoted 1 line
Quoted 1 line

this features very specific to cBPF, we clould simply

implement

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines

cBPF

Quoted 2 lines
Quoted 2 lines

using

Quoted 1 line

eBPF or implement a new cBPF program type. That scheme could

leverage

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

existing JIT infrastructure also. Using JIT will improve

filtering

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

performance.

Quoted 2 lines

Because pcap library generates cBPF in its string to BPF

compiler.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

Translating cBPF to eBPF is non trivial.

Then at least cBPF interpreter should move to librte_bpf. We can

hook to

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

JIT if required in future.

The opcodes for cBPF and eBPF are not compatiable.

Yeah. I am saying to add new program type in bpf library of cBPF.

Obviously

Quoted 1 line

pdump is not the correct place for cBPF interpreter. Moving to

rte_libbpf

Quoted 1 line
Quoted 1 line
Quoted 1 line

library would help to enable other applications or libraries to use

cBPF

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

bpf program class.

The problem is you need a version of string to BPF program which is

what

Quoted 1 line
Quoted 1 line

the libpcap pcap_compile() function does for you. eBPF as used now is

all

Quoted 1 line
Quoted 1 line

about having a full language (CLANG or GCC) and that is not what is

needed

Quoted 2 lines
Quoted 2 lines

here at all. The problem is not the interpreter, the problem is on the userspace BPF side. Until/unless that is fixed, cBPF is a better

solution.

Quoted 4 lines
Quoted 1 line

I am not saying to use eBPF with libpcap. All I am saying to move the

Quoted 8 lines

cBPF

Quoted 5 lines

interpreter code(this patch) to rte_libbpf as it is the correct place of that code in DPDK PoV. So that it can be used by another applications or library.

Quoted 1 line

Sure that make sense?

Initially, I would have said yes, because we already implemented our own cBPF interpreter that way. However, we are using it for packet capture only, and I cannot see any other use for it - except perhaps filtered port mirroring, but that is just another form of packet capturing. So it might as well stay with the packet capture library.

And here goes my rant against eBPF:

In my opinion, eBPF and cBPF are two completely different things... If only rte_libbpf was named rte_libebpf. Then we could have the cBPF interpreter as rte_libbpf or rte_libcbpf.

I would like to elaborate Stephen's comment about the main thing being the integration with userspace:
cBPF has a range of easily accessible tools readily available for use by network operators, such as tcpdump. I consider eBPF for programmers only.

A real life example: Our network appliance provides a GUI. The packet capture feature has a filter field where you can provide a cBPF program in the form of a hex string, which a network operator basically can create by using tcpdump with the right parameters on his laptop. I cannot imagine any network operator sitting down to write an eBPF program for capturing e.g. packets with UDP source port 53 and IP source address 1.1.1.1.

Med venlig hilsen / kind regards
- Morten Brørup

#15 lore raw

Re: [dpdk-dev] [RFC 5/8] pdump: add classic BPF filtering

Hi everyone,

Quoted 62 lines
Quoted 62 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Simple classic BPF interpreter based off of libpcap.

This is a copy of the BPF interpreter from libpcap which is modified to handle mbuf meta data. The existing

pcap_offline_filter

Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

does not expose a way to match VLAN tags. Copying the BPF

interpreter

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

also means that rte_pdump still does not have a hard

dependency

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

on libpcap.

Why not use DPDK's librte_bpf library? Rather implementing

cBPF

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

interpreter. Currently it supports eBPF which is super set of

cBPF.if is

Quoted 1 line
Quoted 1 line
Quoted 1 line

this features very specific to cBPF, we clould simply

implement

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines

cBPF

Quoted 2 lines
Quoted 2 lines

using

Quoted 1 line

eBPF or implement a new cBPF program type. That scheme could

leverage

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

existing JIT infrastructure also. Using JIT will improve

filtering

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

performance.

Quoted 2 lines

Because pcap library generates cBPF in its string to BPF

compiler.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

Translating cBPF to eBPF is non trivial.

Then at least cBPF interpreter should move to librte_bpf. We can

hook to

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

JIT if required in future.

The opcodes for cBPF and eBPF are not compatiable.

Yeah. I am saying to add new program type in bpf library of cBPF.

Obviously

Quoted 1 line

pdump is not the correct place for cBPF interpreter. Moving to

rte_libbpf

Quoted 1 line
Quoted 1 line
Quoted 1 line

library would help to enable other applications or libraries to use

cBPF

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

bpf program class.

The problem is you need a version of string to BPF program which is

what

Quoted 1 line
Quoted 1 line

the libpcap pcap_compile() function does for you. eBPF as used now is

all

Quoted 1 line
Quoted 1 line

about having a full language (CLANG or GCC) and that is not what is

needed

Quoted 2 lines
Quoted 2 lines

here at all. The problem is not the interpreter, the problem is on the userspace BPF side. Until/unless that is fixed, cBPF is a better

solution.

Quoted 4 lines
Quoted 1 line

I am not saying to use eBPF with libpcap. All I am saying to move the

Quoted 8 lines
Quoted 8 lines

cBPF

Quoted 5 lines

interpreter code(this patch) to rte_libbpf as it is the correct place of that code in DPDK PoV. So that it can be used by another applications or library.

Quoted 1 line

Sure that make sense?

For me yes, what Jerin suggests does make sense.
We probably can extend rte_bpf_load to accept both ebpf and cbpf bytecode. Or create a new function: cbpf_load() and make bpf_exec() to be able to execute both ISA. Then pdump library can support both flavors (eBPF and cBPF).
Stephen, not sure I understand - what is your concern with such approach?

Quoted 10 lines

Initially, I would have said yes, because we already implemented our own cBPF interpreter that way. However, we are using it for packet capture only, and I cannot see any other use for it - except perhaps filtered port mirroring, but that is just another form of packet capturing. So it might as well stay with the packet capture library.

And here goes my rant against eBPF:

In my opinion, eBPF and cBPF are two completely different things... If only rte_libbpf was named rte_libebpf. Then we could have the cBPF interpreter as rte_libbpf or rte_libcbpf.

I think we still can have it, see above.

Quoted 8 lines

I would like to elaborate Stephen's comment about the main thing being the integration with userspace:
cBPF has a range of easily accessible tools readily available for use by network operators, such as tcpdump. I consider eBPF for programmers only.
A real life example: Our network appliance provides a GUI. The packet capture feature has a filter field where you can provide a cBPF program in the form of a hex string, which a network operator basically can create by using tcpdump with the right parameters on his laptop. I cannot imagine any network operator sitting down to write an eBPF program for capturing e.g. packets with UDP source port 53 and IP source address 1.1.1.1.

As I can read your main complaint is not about eBPF itself, but about luck of eBPF code generation tools... AFAIK for kernel guys it is not a problem, as in kernel cBPF bytecode always converted to eBPF one before execute/JIT. Probably we just need the same ability in user-space.

Quoted 3 lines

Med venlig hilsen / kind regards
- Morten Brørup

#16 lore raw

Re: [dpdk-dev] [RFC 5/8] pdump: add classic BPF filtering

Quoted 101 lines · Konstantin

Hi everyone,

Quoted 62 lines
Quoted 62 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Simple classic BPF interpreter based off of libpcap.

This is a copy of the BPF interpreter from libpcap which is modified to handle mbuf meta data. The existing

pcap_offline_filter

Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

does not expose a way to match VLAN tags. Copying the BPF

interpreter

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

also means that rte_pdump still does not have a hard

dependency

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

on libpcap.

Why not use DPDK's librte_bpf library? Rather implementing

cBPF

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

interpreter. Currently it supports eBPF which is super set of

cBPF.if is

Quoted 1 line
Quoted 1 line
Quoted 1 line

this features very specific to cBPF, we clould simply

implement

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines

cBPF

Quoted 2 lines
Quoted 2 lines

using

Quoted 1 line

eBPF or implement a new cBPF program type. That scheme could

leverage

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

existing JIT infrastructure also. Using JIT will improve

filtering

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

performance.

Quoted 2 lines

Because pcap library generates cBPF in its string to BPF

compiler.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

Translating cBPF to eBPF is non trivial.

Then at least cBPF interpreter should move to librte_bpf. We can

hook to

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

JIT if required in future.

The opcodes for cBPF and eBPF are not compatiable.

Yeah. I am saying to add new program type in bpf library of cBPF.

Obviously

Quoted 1 line

pdump is not the correct place for cBPF interpreter. Moving to

rte_libbpf

Quoted 1 line
Quoted 1 line
Quoted 1 line

library would help to enable other applications or libraries to use

cBPF

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

bpf program class.

The problem is you need a version of string to BPF program which is

what

Quoted 1 line
Quoted 1 line

the libpcap pcap_compile() function does for you. eBPF as used now is

all

Quoted 1 line
Quoted 1 line

about having a full language (CLANG or GCC) and that is not what is

needed

Quoted 2 lines
Quoted 2 lines

here at all. The problem is not the interpreter, the problem is on the userspace BPF side. Until/unless that is fixed, cBPF is a better

solution.

Quoted 4 lines
Quoted 1 line

I am not saying to use eBPF with libpcap. All I am saying to move the

Quoted 8 lines
Quoted 8 lines

cBPF

Quoted 5 lines

interpreter code(this patch) to rte_libbpf as it is the correct place of that code in DPDK PoV. So that it can be used by another applications or library.

Quoted 1 line

Sure that make sense?

For me yes, what Jerin suggests does make sense.
We probably can extend rte_bpf_load to accept both ebpf and cbpf bytecode. Or create a new function: cbpf_load() and make bpf_exec() to be able to execute both ISA. Then pdump library can support both flavors (eBPF and cBPF).
Stephen, not sure I understand - what is your concern with such approach?

Quoted 10 lines

Initially, I would have said yes, because we already implemented our own cBPF interpreter that way. However, we are using it for packet capture only, and I cannot see any other use for it - except perhaps filtered port mirroring, but that is just another form of packet capturing. So it might as well stay with the packet capture library.

And here goes my rant against eBPF:

In my opinion, eBPF and cBPF are two completely different things... If only rte_libbpf was named rte_libebpf. Then we could have the cBPF interpreter as rte_libbpf or rte_libcbpf.

I think we still can have it, see above.

Quoted 8 lines

I would like to elaborate Stephen's comment about the main thing being the integration with userspace:
cBPF has a range of easily accessible tools readily available for use by network operators, such as tcpdump. I consider eBPF for programmers only.
A real life example: Our network appliance provides a GUI. The packet capture feature has a filter field where you can provide a cBPF program in the form of a hex string, which a network operator basically can create by using tcpdump with the right parameters on his laptop. I cannot imagine any network operator sitting down to write an eBPF program for capturing e.g. packets with UDP source port 53 and IP source address 1.1.1.1.

Quoted 3 lines

As I can read your main complaint is not about eBPF itself, but about luck of eBPF code generation tools... AFAIK for kernel guys it is not a problem, as in kernel cBPF bytecode always converted to eBPF one before execute/JIT. Probably we just need the same ability in user-space.

Since the DPDK API needs to copy (to rte_malloc memory) and validate the capture filter, Lets investigate something net/core/filter.c:bpf_convert_filter in Linux.

#17 lore raw

RFC 6/8 pdump: add packet header truncation

In reply to Stephen Hemminger

Add support for pcap style header truncation (called snap length). This optimizes packet capture by not copying the whole packet.

Since API is already versioned (in previous patch), it is ok to add one new argument for the length.

---
 app/pdump/main.c             | 16 ++++++-------
 app/test/test_pdump.c        |  6 +++--
 lib/librte_pdump/rte_pdump.c | 46 +++++++++++++++++++++++-------------
 lib/librte_pdump/rte_pdump.h | 29 ++++++++++++++---------
 4 files changed, 60 insertions(+), 37 deletions(-)
app/pdump/main.c +8 -8
index c3eb554ef28b..e55a94c0f10e 100644
@@ -825,45 +825,45 @@ enable_pdump(void)
 			if (pt->dump_by_type == DEVICE_ID) {
 				ret = rte_pdump_enable_by_deviceid(
 						pt->device_id,
-						pt->queue,
+						pt->queue, UINT16_MAX,
 						RTE_PDUMP_FLAG_RX,
 						pt->rx_ring,
 						pt->mp, NULL, 0);
 				ret1 = rte_pdump_enable_by_deviceid(
 						pt->device_id,
-						pt->queue,
+						pt->queue, UINT16_MAX,
 						RTE_PDUMP_FLAG_TX,
 						pt->tx_ring,
 						pt->mp, NULL, 0);
 			} else if (pt->dump_by_type == PORT_ID) {
 				ret = rte_pdump_enable(pt->port, pt->queue,
-						RTE_PDUMP_FLAG_RX,
+						UINT16_MAX, RTE_PDUMP_FLAG_RX,
 						pt->rx_ring, pt->mp, NULL, 0);
 				ret1 = rte_pdump_enable(pt->port, pt->queue,
-						RTE_PDUMP_FLAG_TX,
+						UINT16_MAX, RTE_PDUMP_FLAG_TX,
 						pt->tx_ring, pt->mp, NULL, 0);
 			}
 		} else if (pt->dir == RTE_PDUMP_FLAG_RX) {
 			if (pt->dump_by_type == DEVICE_ID)
 				ret = rte_pdump_enable_by_deviceid(
 						pt->device_id,
-						pt->queue,
+						pt->queue, UINT16_MAX,
 						pt->dir, pt->rx_ring,
 						pt->mp, NULL, 0);
 			else if (pt->dump_by_type == PORT_ID)
 				ret = rte_pdump_enable(pt->port, pt->queue,
-						pt->dir,
+						UINT16_MAX, pt->dir,
 						pt->rx_ring, pt->mp, NULL, 0);
 		} else if (pt->dir == RTE_PDUMP_FLAG_TX) {
 			if (pt->dump_by_type == DEVICE_ID)
 				ret = rte_pdump_enable_by_deviceid(
 						pt->device_id,
-						pt->queue,
+						pt->queue, UINT16_MAX,
 						pt->dir,
 						pt->tx_ring, pt->mp, NULL, 0);
 			else if (pt->dump_by_type == PORT_ID)
 				ret = rte_pdump_enable(pt->port, pt->queue,
-						pt->dir,
+						UINT16_MAX, pt->dir,
 						pt->tx_ring, pt->mp, NULL, 0);
 		}
 		if (ret < 0 || ret1 < 0) {
app/test/test_pdump.c +4 -2
index f0187a4cd279..c2468b968247 100644
@@ -78,7 +78,8 @@ run_pdump_client_tests(void)
 	printf("\n***** flags = RTE_PDUMP_FLAG_TX *****\n");
 
 	for (itr = 0; itr < NUM_ITR; itr++) {
-		ret = rte_pdump_enable(portid, QUEUE_ID, flags, ring_client,
+		ret = rte_pdump_enable(portid, QUEUE_ID, flags,
+				       UINT16_MAX, ring_client,
 				       mp, NULL, 0);
 		if (ret < 0) {
 			printf("rte_pdump_enable failed\n");
@@ -93,7 +94,8 @@ run_pdump_client_tests(void)
 		}
 		printf("pdump_disable success\n");
 
-		ret = rte_pdump_enable_by_deviceid(deviceid, QUEUE_ID, flags,
+		ret = rte_pdump_enable_by_deviceid(deviceid, QUEUE_ID,
+						   flags, UINT16_MAX,
 						   ring_client, mp, NULL, 0);
 		if (ret < 0) {
 			printf("rte_pdump_enable_by_deviceid failed\n");
lib/librte_pdump/rte_pdump.c +30 -16

195 lines not on this page · raw message

lib/librte_pdump/rte_pdump.h +18 -11
index 12cb46f8b0e9..e04ef4c1933b 100644
@@ -63,13 +63,15 @@ rte_pdump_uninit(void);
  * @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 snap_len
+ *  only the first snap_len bytes of packet will be captured.
  * @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.
+ *  mempool on to which original packets will be duplicated.
  * @param filter
  *  filter to apply to incoming packet (classic BPF)
- * @param len
+ * @param filter_len
  *  length of filter (in BPF instructions)
  *
  * @return
@@ -77,15 +79,17 @@ rte_pdump_uninit(void);
  */
 int
 rte_pdump_enable(uint16_t port, uint16_t queue, uint32_t flags,
-		 struct rte_ring *ring, struct rte_mempool *mp,
-		 const void *filter, uint32_t len);
+		 uint16_t snap_len, struct rte_ring *ring,
+		 struct rte_mempool *mp,
+		 const void *filter, uint32_t filter_len);
 int
 rte_pdump_enable_v1607(uint16_t port, uint16_t queue, uint32_t flags,
 		       struct rte_ring *ring, struct rte_mempool *mp,
 		       void *filter);
 int
 rte_pdump_enable_v1911(uint16_t port, uint16_t queue, uint32_t flags,
-		       struct rte_ring *ring, struct rte_mempool *mp,
+		       uint16_t snap_len, struct rte_ring *ring,
+		       struct rte_mempool *mp,
 		       const void *filter, uint32_t len);
 
 /**
@@ -121,13 +125,15 @@ rte_pdump_disable(uint16_t port, uint16_t queue, uint32_t flags);
  * @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 snap_len
+ *  only the first snap_len bytes of packet will be captured.
  * @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.
+ *  mempool on to which original packets will be duplicated.
  * @param filter
  *  filter to apply to incoming packet (classic BPF)
- * @param len
+ * @param filter_len
  *  length of filter (in BPF instructions)
  *
  * @return
@@ -135,10 +141,10 @@ rte_pdump_disable(uint16_t port, uint16_t queue, uint32_t flags);
  */
 int
 rte_pdump_enable_by_deviceid(const char *device_id, uint16_t queue,
-			     uint32_t flags,
+			     uint32_t flags, uint16_t snap_len,
 			     struct rte_ring *ring,
 			     struct rte_mempool *mp,
-			     const void *filter, uint32_t len);
+			     const void *filter, uint32_t filter_len);
 int
 rte_pdump_enable_by_deviceid_v1607(char *device_id, uint16_t queue,
 				   uint32_t flags, struct rte_ring *ring,
@@ -146,9 +152,10 @@ rte_pdump_enable_by_deviceid_v1607(char *device_id, uint16_t queue,
 				   void *filter);
 int
 rte_pdump_enable_by_deviceid_v1911(const char *device_id, uint16_t queue,
-				   uint32_t flags, struct rte_ring *ring,
+				   uint32_t flags, uint16_t snap_len,
+				   struct rte_ring *ring,
 				   struct rte_mempool *mp,
-				   const void *filter, uint32_t len);
+				   const void *filter, uint32_t filter_len);
 
 /**
  * Disables packet capturing on given device_id and queue.
Signature · 1 line
2.20.1
#18 lore raw

RFC 7/8 pcapng: add new library for writing pcapng files

In reply to Stephen Hemminger

Simple library for formatting pcapng files used by wireshark and other programs.

See PCAP next generation file format specification
https://github.com/pcapng/pcapng

---
 config/common_base                       |   6 +
 lib/Makefile                             |   2 +
 lib/librte_pcapng/Makefile               |  22 ++
 lib/librte_pcapng/meson.build            |  10 +
 lib/librte_pcapng/pcapng_proto.h         | 112 ++++++
 lib/librte_pcapng/rte_pcapng.c           | 449 +++++++++++++++++++++++
 lib/librte_pcapng/rte_pcapng.h           | 132 +++++++
 lib/librte_pcapng/rte_pcapng_version.map |  12 +
 lib/meson.build                          |   2 +-
 mk/rte.app.mk                            |   1 +
 10 files changed, 747 insertions(+), 1 deletion(-)
 create mode 100644 lib/librte_pcapng/Makefile
 create mode 100644 lib/librte_pcapng/meson.build
 create mode 100644 lib/librte_pcapng/pcapng_proto.h
 create mode 100644 lib/librte_pcapng/rte_pcapng.c
 create mode 100644 lib/librte_pcapng/rte_pcapng.h
 create mode 100644 lib/librte_pcapng/rte_pcapng_version.map
config/common_base +6 -0
index 8ef75c2039a2..0ccfcfae377d 100644
@@ -998,6 +998,12 @@ CONFIG_RTE_KNI_PREEMPT_DEFAULT=y
 #
 CONFIG_RTE_LIBRTE_PDUMP=y
 
+#
+# Compile the pcapng library
+#
+CONFIG_RTE_LIBRTE_PCAPNG=y
+
+#
 #
 # Compile vhost user library
 #
lib/Makefile +2 -0
index 41c463d92139..47786030fade 100644
@@ -102,6 +102,8 @@ DIRS-$(CONFIG_RTE_LIBRTE_REORDER) += librte_reorder
 DEPDIRS-librte_reorder := librte_eal librte_mempool librte_mbuf
 DIRS-$(CONFIG_RTE_LIBRTE_PDUMP) += librte_pdump
 DEPDIRS-librte_pdump := librte_eal librte_mempool librte_mbuf librte_ethdev
+DIRS-$(CONFIG_RTE_LIBRTE_PCAPNG) += librte_pcapng
+DEPDIRS-librte_pcapng := librte_eal librte_mbuf librte_ethdev librte_net
 DIRS-$(CONFIG_RTE_LIBRTE_GSO) += librte_gso
 DEPDIRS-librte_gso := librte_eal librte_mbuf librte_ethdev librte_net
 DEPDIRS-librte_gso += librte_mempool
lib/librte_pcapng/Makefile new file +22 -0
new file mode 100644
index 000000000000..eaf3e85e3ad2
@@ -0,0 +1,22 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Microsoft Corporation
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+# library name
+LIB = librte_pcapng.a
+
+CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3
+CFLAGS += -DALLOW_EXPERIMENTAL_API
+
+EXPORT_MAP := rte_pcapng_version.map
+
+LIBABIVER := 1
+
+# all source are stored in SRCS-y
+SRCS-$(CONFIG_RTE_LIBRTE_PCAPNG) := rte_pcapng.c
+
+# install includes
+SYMLINK-$(CONFIG_RTE_LIBRTE_MBUF)-include := rte_pcapng.h
+
+include $(RTE_SDK)/mk/rte.lib.mk
lib/librte_pcapng/meson.build new file +10 -0
new file mode 100644
index 000000000000..7904b4759b00
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Microsoft Corporation
+
+version = 1
+sources = files('rte_pcapng.c')
+headers = files('rte_pcapng.h')
+
+allow_experimental_apis = true
+
+deps += ['ethdev']
lib/librte_pcapng/pcapng_proto.h new file +112 -0

112 lines not on this page · raw message

lib/librte_pcapng/rte_pcapng.c new file +449 -0

449 lines not on this page · raw message

lib/librte_pcapng/rte_pcapng.h new file +132 -0

132 lines not on this page · raw message

lib/librte_pcapng/rte_pcapng_version.map new file +12 -0
new file mode 100644
index 000000000000..eb8ae2b50984
@@ -0,0 +1,12 @@
+EXPERIMENTAL {
+	global:
+
+	rte_pcapng_fdopen;
+	rte_pcapng_add_interface;
+	rte_pcapng_dump_packet;
+	rte_pcapng_dump_tx;
+	rte_pcapng_dump_rx;
+	rte_pcapng_close;
+
+	local: *;
+};
lib/meson.build +1 -1
index e5ff83893489..cb07e38d8b58 100644
@@ -21,7 +21,7 @@ libraries = [
 	'distributor', 'efd', 'eventdev',
 	'gro', 'gso', 'ip_frag', 'jobstats',
 	'kni', 'latencystats', 'lpm', 'member',
-	'power', 'pdump', 'rawdev',
+	'power', 'pdump', 'rawdev', 'pcapng',
 	'rcu', 'reorder', 'sched', 'security', 'stack', 'vhost',
 	# ipsec lib depends on net, crypto and security
 	'ipsec',
mk/rte.app.mk +1 -0
index ba5c39e01957..b50b74ed6c99 100644
@@ -42,6 +42,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_PORT)           += -lrte_port
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PORT)           += --no-whole-archive
 
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PDUMP)          += -lrte_pdump
+_LDLIBS-$(CONFIG_RTE_LIBRTE_PCAPNG)         += -lrte_pcapng
 _LDLIBS-$(CONFIG_RTE_LIBRTE_DISTRIBUTOR)    += -lrte_distributor
 _LDLIBS-$(CONFIG_RTE_LIBRTE_IP_FRAG)        += -lrte_ip_frag
 _LDLIBS-$(CONFIG_RTE_LIBRTE_METER)          += -lrte_meter
Signature · 1 line
2.20.1
#19 lore raw

RFC 8/8 app/capture: add packet capture using pcapng

In reply to Stephen Hemminger

New application (dpdk-capture) with syntax analogous to tshark's dumpcap command. It runs as a secondary process and produces capture output in pcapng format.

It does not use DPDK style EAL arguments; instead the flags are meant to be the same as dumpcap.

The program depends on libpcap since it uses the pcap_compile() function to compile a string into a BPF program.

---
 app/Makefile            |   1 +
 app/capture/Makefile    |  19 ++
 app/capture/main.c      | 675 ++++++++++++++++++++++++++++++++++++++++
 app/capture/meson.build |  22 ++
 app/meson.build         |   1 +
 config/common_base      |   5 +
 6 files changed, 723 insertions(+)
 create mode 100644 app/capture/Makefile
 create mode 100644 app/capture/main.c
 create mode 100644 app/capture/meson.build
app/Makefile +1 -0
index 28acbceca904..509cd7f4de13 100644
@@ -7,6 +7,7 @@ DIRS-$(CONFIG_RTE_APP_TEST) += test
 DIRS-$(CONFIG_RTE_TEST_PMD) += test-pmd
 DIRS-$(CONFIG_RTE_PROC_INFO) += proc-info
 DIRS-$(CONFIG_RTE_LIBRTE_PDUMP) += pdump
+DIRS-$(CONFIG_RTE_APP_CAPTURE) += capture
 DIRS-$(CONFIG_RTE_LIBRTE_ACL) += test-acl
 DIRS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test-cmdline
 DIRS-$(CONFIG_RTE_LIBRTE_PIPELINE) += test-pipeline
app/capture/Makefile new file +19 -0
new file mode 100644
index 000000000000..78ff7d2e97bf
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Microsoft Corporation
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+ifeq ($(CONFIG_RTE_LIBRTE_PCAPNG),y)
+
+APP = dpdk-capture
+
+CFLAGS += -DALLOW_EXPERIMENTAL_API
+CFLAGS += -O3
+CFLAGS += $(WERROR_FLAGS)
+LDLIBS += -lpcap
+
+SRCS-y := main.c
+
+include $(RTE_SDK)/mk/rte.app.mk
+
+endif
app/capture/main.c new file +675 -0

675 lines not on this page · raw message

app/capture/meson.build new file +22 -0
new file mode 100644
index 000000000000..9558f10562bd
@@ -0,0 +1,22 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2019 Microsoft Corporation
+pcap_dep = dependency('pcap', required: false)
+if pcap_dep.found()
+	build = true
+else
+	# pcap got a pkg-config file only in 1.9.0 and before that meson uses
+	# an internal pcap-config finder, which is not compatible with
+	# cross-compilation, so try to fallback to find_library
+	pcap_dep = cc.find_library('pcap', required: false)
+	if pcap_dep.found() and cc.has_header('pcap.h', dependencies: pcap_dep)
+		build = true
+		pkgconfig_extra_libs += '-lpcap'
+	else
+		build = false
+		reason = 'missing dependency, "libpcap"'
+	endif
+endif
+
+sources = files('main.c')
+ext_deps += pcap_dep
+deps += ['ethdev', 'pdump', 'pcapng']
app/meson.build +1 -0
index b0e6afbbe9d9..a33198182133 100644
@@ -6,6 +6,7 @@ if is_windows
 endif
 
 apps = [
+	'capture',
 	'pdump',
 	'proc-info',
 	'test-acl',
config/common_base +5 -0
index 0ccfcfae377d..e1bab8e77988 100644
@@ -1073,3 +1073,8 @@ CONFIG_RTE_APP_CRYPTO_PERF=y
 # Compile the eventdev application
 #
 CONFIG_RTE_APP_EVENTDEV=y
+
+#
+# Compile the capture application
+#
+CONFIG_RTE_APP_CAPTURE=n
Signature · 1 line
2.20.1