xref: /dpdk/lib/pdump/rte_pdump.h (revision bdc89d75a19d20dff9d313440cb7a753b0b45559)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2016 Intel Corporation
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #ifndef _RTE_PDUMP_H_
699a2dd95SBruce Richardson #define _RTE_PDUMP_H_
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson /**
999a2dd95SBruce Richardson  * @file
1099a2dd95SBruce Richardson  * RTE pdump
1199a2dd95SBruce Richardson  *
1299a2dd95SBruce Richardson  * packet dump library to provide packet capturing support on dpdk.
1399a2dd95SBruce Richardson  */
1499a2dd95SBruce Richardson 
1599a2dd95SBruce Richardson #include <stdint.h>
16*bdc89d75SStephen Hemminger 
1710f726efSStephen Hemminger #include <rte_bpf.h>
1899a2dd95SBruce Richardson 
1999a2dd95SBruce Richardson #ifdef __cplusplus
2099a2dd95SBruce Richardson extern "C" {
2199a2dd95SBruce Richardson #endif
2299a2dd95SBruce Richardson 
2399a2dd95SBruce Richardson #define RTE_PDUMP_ALL_QUEUES UINT16_MAX
2499a2dd95SBruce Richardson 
2599a2dd95SBruce Richardson enum {
2699a2dd95SBruce Richardson 	RTE_PDUMP_FLAG_RX = 1,  /* receive direction */
2799a2dd95SBruce Richardson 	RTE_PDUMP_FLAG_TX = 2,  /* transmit direction */
2899a2dd95SBruce Richardson 	/* both receive and transmit directions */
2910f726efSStephen Hemminger 	RTE_PDUMP_FLAG_RXTX = (RTE_PDUMP_FLAG_RX|RTE_PDUMP_FLAG_TX),
3010f726efSStephen Hemminger 
3110f726efSStephen Hemminger 	RTE_PDUMP_FLAG_PCAPNG = 4, /* format for pcapng */
3299a2dd95SBruce Richardson };
3399a2dd95SBruce Richardson 
3499a2dd95SBruce Richardson /**
3599a2dd95SBruce Richardson  * Initialize packet capturing handling
3699a2dd95SBruce Richardson  *
3799a2dd95SBruce Richardson  * Register the IPC action for communication with target (primary) process.
3899a2dd95SBruce Richardson  *
3999a2dd95SBruce Richardson  * @return
4099a2dd95SBruce Richardson  *    0 on success, -1 on error
4199a2dd95SBruce Richardson  */
4299a2dd95SBruce Richardson int
4399a2dd95SBruce Richardson rte_pdump_init(void);
4499a2dd95SBruce Richardson 
4599a2dd95SBruce Richardson /**
4699a2dd95SBruce Richardson  * Un initialize packet capturing handling
4799a2dd95SBruce Richardson  *
4899a2dd95SBruce Richardson  * Unregister the IPC action for communication with target (primary) process.
4999a2dd95SBruce Richardson  *
5099a2dd95SBruce Richardson  * @return
5199a2dd95SBruce Richardson  *    0 on success, -1 on error
5299a2dd95SBruce Richardson  */
5399a2dd95SBruce Richardson int
5499a2dd95SBruce Richardson rte_pdump_uninit(void);
5599a2dd95SBruce Richardson 
5699a2dd95SBruce Richardson /**
5799a2dd95SBruce Richardson  * Enables packet capturing on given port and queue.
5899a2dd95SBruce Richardson  *
5999a2dd95SBruce Richardson  * @param port
6099a2dd95SBruce Richardson  *  port on which packet capturing should be enabled.
6199a2dd95SBruce Richardson  * @param queue
6299a2dd95SBruce Richardson  *  queue of a given port on which packet capturing should be enabled.
6399a2dd95SBruce Richardson  *  users should pass on value UINT16_MAX to enable packet capturing on all
6499a2dd95SBruce Richardson  *  queues of a given port.
6599a2dd95SBruce Richardson  * @param flags
6699a2dd95SBruce Richardson  *  flags specifies RTE_PDUMP_FLAG_RX/RTE_PDUMP_FLAG_TX/RTE_PDUMP_FLAG_RXTX
6799a2dd95SBruce Richardson  *  on which packet capturing should be enabled for a given port and queue.
6899a2dd95SBruce Richardson  * @param ring
6999a2dd95SBruce Richardson  *  ring on which captured packets will be enqueued for user.
7099a2dd95SBruce Richardson  * @param mp
7199a2dd95SBruce Richardson  *  mempool on to which original packets will be mirrored or duplicated.
7299a2dd95SBruce Richardson  * @param filter
7310f726efSStephen Hemminger  *  Unused should be NULL.
7499a2dd95SBruce Richardson  *
7599a2dd95SBruce Richardson  * @return
7699a2dd95SBruce Richardson  *    0 on success, -1 on error, rte_errno is set accordingly.
7799a2dd95SBruce Richardson  */
7899a2dd95SBruce Richardson 
7999a2dd95SBruce Richardson int
8099a2dd95SBruce Richardson rte_pdump_enable(uint16_t port, uint16_t queue, uint32_t flags,
8199a2dd95SBruce Richardson 		struct rte_ring *ring,
8299a2dd95SBruce Richardson 		struct rte_mempool *mp,
8399a2dd95SBruce Richardson 		void *filter);
8499a2dd95SBruce Richardson 
8599a2dd95SBruce Richardson /**
8610f726efSStephen Hemminger  * Enables packet capturing on given port and queue with filtering.
8710f726efSStephen Hemminger  *
8810f726efSStephen Hemminger  * @param port_id
8910f726efSStephen Hemminger  *  The Ethernet port on which packet capturing should be enabled.
9010f726efSStephen Hemminger  * @param queue
9110f726efSStephen Hemminger  *  The queue on the Ethernet port which packet capturing
9210f726efSStephen Hemminger  *  should be enabled. Pass UINT16_MAX to enable packet capturing on all
9310f726efSStephen Hemminger  *  queues of a given port.
9410f726efSStephen Hemminger  * @param flags
9510f726efSStephen Hemminger  *  Pdump library flags that specify direction and packet format.
9610f726efSStephen Hemminger  * @param snaplen
9710f726efSStephen Hemminger  *  The upper limit on bytes to copy.
9810f726efSStephen Hemminger  *  Passing UINT32_MAX means capture all the possible data.
9910f726efSStephen Hemminger  * @param ring
10010f726efSStephen Hemminger  *  The ring on which captured packets will be enqueued for user.
10110f726efSStephen Hemminger  * @param mp
10210f726efSStephen Hemminger  *  The mempool on to which original packets will be mirrored or duplicated.
10310f726efSStephen Hemminger  * @param prm
10410f726efSStephen Hemminger  *  Use BPF program to run to filter packes (can be NULL)
10510f726efSStephen Hemminger  *
10610f726efSStephen Hemminger  * @return
10710f726efSStephen Hemminger  *    0 on success, -1 on error, rte_errno is set accordingly.
10810f726efSStephen Hemminger  */
10910f726efSStephen Hemminger int
11010f726efSStephen Hemminger rte_pdump_enable_bpf(uint16_t port_id, uint16_t queue,
11110f726efSStephen Hemminger 		     uint32_t flags, uint32_t snaplen,
11210f726efSStephen Hemminger 		     struct rte_ring *ring,
11310f726efSStephen Hemminger 		     struct rte_mempool *mp,
11410f726efSStephen Hemminger 		     const struct rte_bpf_prm *prm);
11510f726efSStephen Hemminger 
11610f726efSStephen Hemminger /**
11799a2dd95SBruce Richardson  * Disables packet capturing on given port and queue.
11899a2dd95SBruce Richardson  *
11999a2dd95SBruce Richardson  * @param port
12099a2dd95SBruce Richardson  *  port on which packet capturing should be disabled.
12199a2dd95SBruce Richardson  * @param queue
12299a2dd95SBruce Richardson  *  queue of a given port on which packet capturing should be disabled.
12399a2dd95SBruce Richardson  *  users should pass on value UINT16_MAX to disable packet capturing on all
12499a2dd95SBruce Richardson  *  queues of a given port.
12599a2dd95SBruce Richardson  * @param flags
12699a2dd95SBruce Richardson  *  flags specifies RTE_PDUMP_FLAG_RX/RTE_PDUMP_FLAG_TX/RTE_PDUMP_FLAG_RXTX
12799a2dd95SBruce Richardson  *  on which packet capturing should be enabled for a given port and queue.
12899a2dd95SBruce Richardson  *
12999a2dd95SBruce Richardson  * @return
13099a2dd95SBruce Richardson  *    0 on success, -1 on error, rte_errno is set accordingly.
13199a2dd95SBruce Richardson  */
13299a2dd95SBruce Richardson 
13399a2dd95SBruce Richardson int
13499a2dd95SBruce Richardson rte_pdump_disable(uint16_t port, uint16_t queue, uint32_t flags);
13599a2dd95SBruce Richardson 
13699a2dd95SBruce Richardson /**
13799a2dd95SBruce Richardson  * Enables packet capturing on given device id and queue.
13899a2dd95SBruce Richardson  * device_id can be name or pci address of device.
13999a2dd95SBruce Richardson  *
14099a2dd95SBruce Richardson  * @param device_id
14199a2dd95SBruce Richardson  *  device id on which packet capturing should be enabled.
14299a2dd95SBruce Richardson  * @param queue
14399a2dd95SBruce Richardson  *  queue of a given device id on which packet capturing should be enabled.
14499a2dd95SBruce Richardson  *  users should pass on value UINT16_MAX to enable packet capturing on all
14599a2dd95SBruce Richardson  *  queues of a given device id.
14699a2dd95SBruce Richardson  * @param flags
14799a2dd95SBruce Richardson  *  flags specifies RTE_PDUMP_FLAG_RX/RTE_PDUMP_FLAG_TX/RTE_PDUMP_FLAG_RXTX
14899a2dd95SBruce Richardson  *  on which packet capturing should be enabled for a given port and queue.
14999a2dd95SBruce Richardson  * @param ring
15099a2dd95SBruce Richardson  *  ring on which captured packets will be enqueued for user.
15199a2dd95SBruce Richardson  * @param mp
15299a2dd95SBruce Richardson  *  mempool on to which original packets will be mirrored or duplicated.
15399a2dd95SBruce Richardson  * @param filter
15410f726efSStephen Hemminger  *  unused should be NULL
15599a2dd95SBruce Richardson  *
15699a2dd95SBruce Richardson  * @return
15799a2dd95SBruce Richardson  *    0 on success, -1 on error, rte_errno is set accordingly.
15899a2dd95SBruce Richardson  */
15999a2dd95SBruce Richardson 
16099a2dd95SBruce Richardson int
16199a2dd95SBruce Richardson rte_pdump_enable_by_deviceid(char *device_id, uint16_t queue,
16299a2dd95SBruce Richardson 				uint32_t flags,
16399a2dd95SBruce Richardson 				struct rte_ring *ring,
16499a2dd95SBruce Richardson 				struct rte_mempool *mp,
16599a2dd95SBruce Richardson 				void *filter);
16699a2dd95SBruce Richardson 
16799a2dd95SBruce Richardson /**
16810f726efSStephen Hemminger  * Enables packet capturing on given device id and queue with filtering.
16910f726efSStephen Hemminger  * device_id can be name or pci address of device.
17010f726efSStephen Hemminger  *
17110f726efSStephen Hemminger  * @param device_id
17210f726efSStephen Hemminger  *  device id on which packet capturing should be enabled.
17310f726efSStephen Hemminger  * @param queue
17410f726efSStephen Hemminger  *  The queue on the Ethernet port which packet capturing
17510f726efSStephen Hemminger  *  should be enabled. Pass UINT16_MAX to enable packet capturing on all
17610f726efSStephen Hemminger  *  queues of a given port.
17710f726efSStephen Hemminger  * @param flags
17810f726efSStephen Hemminger  *  Pdump library flags that specify direction and packet format.
17910f726efSStephen Hemminger  * @param snaplen
18010f726efSStephen Hemminger  *  The upper limit on bytes to copy.
18110f726efSStephen Hemminger  *  Passing UINT32_MAX means capture all the possible data.
18210f726efSStephen Hemminger  * @param ring
18310f726efSStephen Hemminger  *  The ring on which captured packets will be enqueued for user.
18410f726efSStephen Hemminger  * @param mp
18510f726efSStephen Hemminger  *  The mempool on to which original packets will be mirrored or duplicated.
18610f726efSStephen Hemminger  * @param filter
18710f726efSStephen Hemminger  *  Use BPF program to run to filter packes (can be NULL)
18810f726efSStephen Hemminger  *
18910f726efSStephen Hemminger  * @return
19010f726efSStephen Hemminger  *    0 on success, -1 on error, rte_errno is set accordingly.
19110f726efSStephen Hemminger  */
19210f726efSStephen Hemminger int
19310f726efSStephen Hemminger rte_pdump_enable_bpf_by_deviceid(const char *device_id, uint16_t queue,
19410f726efSStephen Hemminger 				 uint32_t flags, uint32_t snaplen,
19510f726efSStephen Hemminger 				 struct rte_ring *ring,
19610f726efSStephen Hemminger 				 struct rte_mempool *mp,
19710f726efSStephen Hemminger 				 const struct rte_bpf_prm *filter);
19810f726efSStephen Hemminger 
19910f726efSStephen Hemminger 
20010f726efSStephen Hemminger /**
20199a2dd95SBruce Richardson  * Disables packet capturing on given device_id and queue.
20299a2dd95SBruce Richardson  * device_id can be name or pci address of device.
20399a2dd95SBruce Richardson  *
20499a2dd95SBruce Richardson  * @param device_id
20599a2dd95SBruce Richardson  *  pci address or name of the device on which packet capturing
20699a2dd95SBruce Richardson  *  should be disabled.
20799a2dd95SBruce Richardson  * @param queue
20899a2dd95SBruce Richardson  *  queue of a given device on which packet capturing should be disabled.
20999a2dd95SBruce Richardson  *  users should pass on value UINT16_MAX to disable packet capturing on all
21099a2dd95SBruce Richardson  *  queues of a given device id.
21199a2dd95SBruce Richardson  * @param flags
21299a2dd95SBruce Richardson  *  flags specifies RTE_PDUMP_FLAG_RX/RTE_PDUMP_FLAG_TX/RTE_PDUMP_FLAG_RXTX
21399a2dd95SBruce Richardson  *  on which packet capturing should be enabled for a given port and queue.
21499a2dd95SBruce Richardson  *
21599a2dd95SBruce Richardson  * @return
21699a2dd95SBruce Richardson  *    0 on success, -1 on error, rte_errno is set accordingly.
21799a2dd95SBruce Richardson  */
21899a2dd95SBruce Richardson int
21999a2dd95SBruce Richardson rte_pdump_disable_by_deviceid(char *device_id, uint16_t queue,
22099a2dd95SBruce Richardson 				uint32_t flags);
22199a2dd95SBruce Richardson 
22210f726efSStephen Hemminger 
22310f726efSStephen Hemminger /**
22410f726efSStephen Hemminger  * A structure used to retrieve statistics from packet capture.
22510f726efSStephen Hemminger  * The statistics are sum of both receive and transmit queues.
22610f726efSStephen Hemminger  */
22710f726efSStephen Hemminger struct rte_pdump_stats {
228938c55cbSTyler Retzlaff 	RTE_ATOMIC(uint64_t) accepted; /**< Number of packets accepted by filter. */
229938c55cbSTyler Retzlaff 	RTE_ATOMIC(uint64_t) filtered; /**< Number of packets rejected by filter. */
230938c55cbSTyler Retzlaff 	RTE_ATOMIC(uint64_t) nombuf;   /**< Number of mbuf allocation failures. */
231938c55cbSTyler Retzlaff 	RTE_ATOMIC(uint64_t) ringfull; /**< Number of missed packets due to ring full. */
23210f726efSStephen Hemminger 
23310f726efSStephen Hemminger 	uint64_t reserved[4]; /**< Reserved and pad to cache line */
23410f726efSStephen Hemminger };
23510f726efSStephen Hemminger 
23610f726efSStephen Hemminger /**
23710f726efSStephen Hemminger  * Retrieve the packet capture statistics for a queue.
23810f726efSStephen Hemminger  *
23910f726efSStephen Hemminger  * @param port_id
24010f726efSStephen Hemminger  *   The port identifier of the Ethernet device.
24110f726efSStephen Hemminger  * @param stats
24210f726efSStephen Hemminger  *   A pointer to structure of type *rte_pdump_stats* to be filled in.
24310f726efSStephen Hemminger  * @return
24410f726efSStephen Hemminger  *   Zero if successful. -1 on error and rte_errno is set.
24510f726efSStephen Hemminger  */
24610f726efSStephen Hemminger int
24710f726efSStephen Hemminger rte_pdump_stats(uint16_t port_id, struct rte_pdump_stats *stats);
24810f726efSStephen Hemminger 
24910f726efSStephen Hemminger 
25099a2dd95SBruce Richardson #ifdef __cplusplus
25199a2dd95SBruce Richardson }
25299a2dd95SBruce Richardson #endif
25399a2dd95SBruce Richardson 
25499a2dd95SBruce Richardson #endif /* _RTE_PDUMP_H_ */
255