Packet capture using port mirroring
Subsystems (3)
cover Packet capture using port mirroring
This is a rework of how packet capture is done in DPDK. The existing mechanism using callbacks has a number of problems; the main one is that any packets sent/received in a secondary process are not visible. The root cause is that callbacks can not function across process boundaries, they are specific to the role.
The new mechanism builds on the concept of port mirroring used in Linux/FreeBSD and also router vendors (SPAN ports). The infrastructure is built around a new ethdev call to mirror a port.
The internals of dumpcap are redone but the program command syntax is unchanged (no doc change needed). Usingthe new mirror mechanism, the dumpcap program creates a port using ring PMD and
then directs mirror to that. Then the packets are extracted from the ring. If capturing on multiple devices, they all get mirrored to
the same ring PMD.
Doing this uncovered a bunch of additional missing features and bugs. The first is that test-pmd auto attach introduced in 24.11 breaks this (and it broke old pdump as well) so it is removed.
The dumpcap program needs to be able to start the ring PMD it created but the existing ethdev API is broken when used from secondary process. So fix that.
The mirror API has a restriction that the port being mirrored to must allow lock free transmit. This is because both rx and tx as well as multiple queues need to go over the same transmit queue. Although it might be possible to have some complex mapping between multiple ports/queues being mirrored to multiple transmit queues, that gets to be a lot of overhead in API's and implementation. Fixing the ring and null PMD to allow lockeless transmit is good enough.
Added tests for the new features.
The performance has not been measured but the overhead of checking for mirror port is no more that the overhead of looking at the callback list.
TODO items:
- need release notes for new features
- more through testing on real hardware
- mark old pdump API and application for deprecation in 25.07 and removal in 25.11
- more cleanup of patch wording and docs needed.
Stephen Hemminger (13):
app/testpmd: revert auto attach/detach
ethdev: allow start/stop from secondary process
test: add test for hotplug and secondary process operations net/ring: allow lockfree transmit if ring supports it net/ring: add argument to attach existing ring net/ring: add timestamp devargs
net/null: all lockfree transmit
mbuf: add fields for mirroring
ethdev: add port mirror capability
pcapng: split packet copy from header insertion
test: add tests for ethdev mirror
app/testpmd: support for port mirroring app/dumpcap: use port mirror instead of pdump
app/dumpcap/main.c | 361 +++++++++++++++----- app/dumpcap/meson.build | 2 +- app/test-pmd/cmdline.c | 1 + app/test-pmd/cmdline_mirror.c | 120 +++++++ app/test-pmd/cmdline_mirror.h | 12 + app/test-pmd/meson.build | 1 + app/test-pmd/testpmd.c | 77 ++--- app/test/meson.build | 1 + app/test/test_ethdev_mirror.c | 286 ++++++++++++++++ app/test/test_mp_secondary.c | 51 ++- config/rte_config.h | 2 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 15 + drivers/net/null/rte_eth_null.c | 1 + drivers/net/ring/rte_eth_ring.c | 91 ++++- lib/ethdev/ethdev_driver.c | 11 +- lib/ethdev/ethdev_driver.h | 3 + lib/ethdev/ethdev_private.c | 80 +++++ lib/ethdev/ethdev_private.h | 23 ++ lib/ethdev/ethdev_trace.h | 14 + lib/ethdev/ethdev_trace_points.c | 6 + lib/ethdev/rte_ethdev.c | 275 +++++++++++++-- lib/ethdev/rte_ethdev.h | 81 +++++ lib/ethdev/rte_ethdev_core.h | 6 +- lib/mbuf/rte_mbuf_core.h | 8 + lib/pcapng/rte_pcapng.c | 178 +++++----- lib/pcapng/rte_pcapng.h | 27 +- 26 files changed, 1468 insertions(+), 265 deletions(-) create mode 100644 app/test-pmd/cmdline_mirror.c create mode 100644 app/test-pmd/cmdline_mirror.h create mode 100644 app/test/test_ethdev_mirror.c
Signature · 1 line
2.47.2
RFC 1/13 app/testpmd: revert auto attach/detach
Revert "app/testpmd: add port attach/detach for multiple process" This reverts commit 994635edb2c038e64617bcf2790a8cd326c3e8e0.
This commit breaks using pdump and other secondary processes that create there own devices. The patch makes testpmd grab any new hotplug device and configure it.
It may also break failsafe and netvsc PMD handling of VF devices. But I don't have access to test that part.
The patch is flawed in concept, and needs to go.
Bugzilla ID: 1695
--- app/test-pmd/testpmd.c | 77 +++++++++++------------------------------- 1 file changed, 20 insertions(+), 57 deletions(-)
app/test-pmd/testpmd.c +20 -57
@@ -705,7 +705,7 @@ eth_dev_set_mtu_mp(uint16_t port_id, uint16_t mtu) }/* Forward function declarations */ -static void setup_attached_port (void *arg); +static void setup_attached_port (portid_t pi);static void check_all_ports_link_status (uint32_t port_mask); static int eth_event_callback(portid_t port_id, enum rte_eth_event_type type,
@@ -2906,7 +2906,6 @@ start_port(portid_t pid) at_least_one_port_exist = true; port = &ports[pi]; -if (port->port_status ==RTE_PORT_STOPPED ) { port->port_status =RTE_PORT_HANDLING ; all_ports_already_started = false;
@@ -3254,7 +3253,6 @@ remove_invalid_ports(void)remove_invalid_ports_in (ports_ids, &nb_ports);remove_invalid_ports_in (fwd_ports_ids, &nb_fwd_ports); nb_cfg_ports = nb_fwd_ports; -printf ("Now total ports is %d\n" , nb_ports); } static void
@@ -3427,11 +3425,14 @@ attach_port(char *identifier)return ; } -/* First attach mode: event -* New port flag is updated on RTE_ETH_EVENT_NEW event -*/ +/* first attach mode: event */ if (setup_on_probe_event) { - goto out; +/* new ports are detected on RTE_ETH_EVENT_NEW event */ +for (pi =0 ; pi <RTE_MAX_ETHPORTS ; pi++) +if (ports[pi].port_status ==RTE_PORT_HANDLING && + ports[pi].need_setup !=0 ) +setup_attached_port (pi); +return ; }/* second attach mode: iterator */
@@ -3439,17 +3440,13 @@ attach_port(char *identifier)/* setup ports matching the devargs used for probing */ if (port_is_forwarding (pi))continue ;/* port was already attached before */ -setup_attached_port ((void *)(intptr_t )pi); +setup_attached_port (pi); } -out: -printf ("Port %s is attached.\n" , identifier); -printf ("Done\n" ); }static void -setup_attached_port (void *arg) +setup_attached_port (portid_t pi) { -portid_t pi = (intptr_t )arg;unsigned int socket_id;int ret;
@@ -3464,8 +3461,14 @@ setup_attached_port(void *arg)"Error during enabling promiscuous mode for port %u: %s - ignore\n" , pi, rte_strerror(-ret)); + ports_ids[nb_ports++] = pi; + fwd_ports_ids[nb_fwd_ports++] = pi; + nb_cfg_ports = nb_fwd_ports; ports[pi].need_setup =0 ; ports[pi].port_status =RTE_PORT_STOPPED ; + +printf ("Port %d is attached. Now total ports is %d\n" , pi, nb_ports); +printf ("Done\n" ); } static void
@@ -3495,8 +3498,10 @@ detach_device(struct rte_device *dev)TESTPMD_LOG (ERR ,"Failed to detach device %s\n" ,rte_dev_name (dev));return ; } +remove_invalid_ports ();printf ("Device is detached\n" ); +printf ("Now total ports is %d\n" , nb_ports);printf ("Done\n" );return ; }
@@ -3728,25 +3733,7 @@ rmv_port_callback(void *arg)struct rte_device *device = dev_info.device;close_port (port_id);detach_device (device);/* might be already removed or have more ports */ -remove_invalid_ports (); - } -if (need_to_start) -start_packet_forwarding (0 ); -} - -static void -remove_invalid_ports_callback (void *arg) -{ -portid_t port_id = (intptr_t )arg; -int need_to_start =0 ; - -if (!test_done &&port_is_forwarding (port_id)) { - need_to_start =1 ; -stop_packet_forwarding (); } - -remove_invalid_ports (); -if (need_to_start)start_packet_forwarding (0 ); }
@@ -3772,23 +3759,8 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,switch (type) {case RTE_ETH_EVENT_NEW : -/* The port in ports_id and fwd_ports_ids is always valid -* from index 0 ~ (nb_ports - 1) due to updating their -* position when one port is detached or removed. -*/ - ports_ids[nb_ports++] = port_id; - fwd_ports_ids[nb_fwd_ports++] = port_id; - nb_cfg_ports = nb_fwd_ports; -printf ("Port %d is probed. Now total ports is %d\n" , port_id, nb_ports); - -if (setup_on_probe_event) { - ports[port_id].need_setup =1 ; - ports[port_id].port_status =RTE_PORT_HANDLING ; - } -/* Can't initialize port directly in new event. */ -if (rte_eal_alarm_set (100000 , setup_attached_port, - (void *)(intptr_t )port_id)) -fprintf (stderr,"Could not set up deferred task to setup this attached port.\n" ); + ports[port_id].need_setup =1 ; + ports[port_id].port_status =RTE_PORT_HANDLING ;break ;case RTE_ETH_EVENT_INTR_RMV :if (port_id_is_invalid (port_id,DISABLED_WARN ))
@@ -3801,15 +3773,6 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,case RTE_ETH_EVENT_DESTROY : ports[port_id].port_status =RTE_PORT_CLOSED ;printf ("Port %u is closed\n" , port_id); -/* -* Defer to remove port id due to the reason that the ethdev -* state is changed from 'ATTACHED' to 'UNUSED' only after the -* event callback finished. Otherwise this port id can not be -* removed. -*/ -if (rte_eal_alarm_set (100000 , remove_invalid_ports_callback, - (void *)(intptr_t )port_id)) -fprintf (stderr,"Could not set up deferred task to remove this port id.\n" );break ;case RTE_ETH_EVENT_RX_AVAIL_THRESH : {uint16_t rxq_id;
Signature · 1 line
2.47.2
Re: [RFC 01/13] app/testpmd: revert auto attach/detach
Hi Stephen,
The main cause of cpfl driver attach failure is the added alarm in new event callback to setup port automatically. It's a question of when to set up the new port. Please see the discussion[1]. I have a stupid method, but I'm not very willing to do that. For the Bugzilla id1695, I'll take a look at it.
[1] https://bugs.dpdk.org/show_bug.cgi?id=1671
/Huisong
Quoted 184 lines · Stephen Hemminger
Revert "app/testpmd: add port attach/detach for multiple process" This reverts commit
994635edb2c038e64617bcf2790a8cd326c3e8e0.This commit breaks using pdump and other secondary processes that create there own devices. The patch makes testpmd grab any new hotplug device and configure it.
It may also break failsafe and netvsc PMD handling of VF devices. But I don't have access to test that part.
The patch is flawed in concept, and needs to go.
Bugzilla ID: 1695
Fixes 994635edb2c0 ("app/testpmd: add port attach/detach for multiple process")Signed-off-by Stephen Hemminger <[email protected]>--- app/test-pmd/testpmd.c | 77 +++++++++++------------------------------- 1 file changed, 20 insertions(+), 57 deletions(-)app/test-pmd/testpmd.c +20
-57@@ -705,7 +705,7 @@ eth_dev_set_mtu_mp(uint16_t port_id, uint16_t mtu) }/* Forward function declarations */ -static void setup_attached_port (void *arg); +static void setup_attached_port (portid_t pi);static void check_all_ports_link_status (uint32_t port_mask); static int eth_event_callback(portid_t port_id, enum rte_eth_event_type type,@@ -2906,7 +2906,6 @@ start_port(portid_t pid) at_least_one_port_exist = true; port = &ports[pi]; -if (port->port_status ==RTE_PORT_STOPPED ) { port->port_status =RTE_PORT_HANDLING ; all_ports_already_started = false;@@ -3254,7 +3253,6 @@ remove_invalid_ports(void)remove_invalid_ports_in (ports_ids, &nb_ports);remove_invalid_ports_in (fwd_ports_ids, &nb_fwd_ports); nb_cfg_ports = nb_fwd_ports; -printf ("Now total ports is %d\n" , nb_ports); } static void@@ -3427,11 +3425,14 @@ attach_port(char *identifier)return ; } -/* First attach mode: event -* New port flag is updated on RTE_ETH_EVENT_NEW event -*/ +/* first attach mode: event */ if (setup_on_probe_event) { - goto out; +/* new ports are detected on RTE_ETH_EVENT_NEW event */ +for (pi =0 ; pi <RTE_MAX_ETHPORTS ; pi++) +if (ports[pi].port_status ==RTE_PORT_HANDLING && + ports[pi].need_setup !=0 ) +setup_attached_port (pi); +return ; }/* second attach mode: iterator */ @@ -3439,17 +3440,13 @@ attach_port(char *identifier)/* setup ports matching the devargs used for probing */ if (port_is_forwarding (pi))continue ;/* port was already attached before */ -setup_attached_port ((void *)(intptr_t )pi); +setup_attached_port (pi); } -out: -printf ("Port %s is attached.\n" , identifier); -printf ("Done\n" ); }static void -setup_attached_port (void *arg) +setup_attached_port (portid_t pi) { -portid_t pi = (intptr_t )arg;unsigned int socket_id;int ret;@@ -3464,8 +3461,14 @@ setup_attached_port(void *arg)"Error during enabling promiscuous mode for port %u: %s - ignore\n" , pi, rte_strerror(-ret)); + ports_ids[nb_ports++] = pi; + fwd_ports_ids[nb_fwd_ports++] = pi; + nb_cfg_ports = nb_fwd_ports; ports[pi].need_setup =0 ; ports[pi].port_status =RTE_PORT_STOPPED ; + +printf ("Port %d is attached. Now total ports is %d\n" , pi, nb_ports); +printf ("Done\n" ); } static void@@ -3495,8 +3498,10 @@ detach_device(struct rte_device *dev)TESTPMD_LOG (ERR ,"Failed to detach device %s\n" ,rte_dev_name (dev));return ; } +remove_invalid_ports ();printf ("Device is detached\n" ); +printf ("Now total ports is %d\n" , nb_ports);printf ("Done\n" );return ; }@@ -3728,25 +3733,7 @@ rmv_port_callback(void *arg)struct rte_device *device = dev_info.device;close_port (port_id);detach_device (device);/* might be already removed or have more ports */ -remove_invalid_ports (); - } -if (need_to_start) -start_packet_forwarding (0 ); -} - -static void -remove_invalid_ports_callback (void *arg) -{ -portid_t port_id = (intptr_t )arg; -int need_to_start =0 ; - -if (!test_done &&port_is_forwarding (port_id)) { - need_to_start =1 ; -stop_packet_forwarding (); } - -remove_invalid_ports (); -if (need_to_start)start_packet_forwarding (0 ); }@@ -3772,23 +3759,8 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,switch (type) {case RTE_ETH_EVENT_NEW : -/* The port in ports_id and fwd_ports_ids is always valid -* from index 0 ~ (nb_ports - 1) due to updating their -* position when one port is detached or removed. -*/ - ports_ids[nb_ports++] = port_id; - fwd_ports_ids[nb_fwd_ports++] = port_id; - nb_cfg_ports = nb_fwd_ports; -printf ("Port %d is probed. Now total ports is %d\n" , port_id, nb_ports); - -if (setup_on_probe_event) { - ports[port_id].need_setup =1 ; - ports[port_id].port_status =RTE_PORT_HANDLING ; - } -/* Can't initialize port directly in new event. */ -if (rte_eal_alarm_set (100000 , setup_attached_port, - (void *)(intptr_t )port_id)) -fprintf (stderr,"Could not set up deferred task to setup this attached port.\n" ); + ports[port_id].need_setup =1 ; + ports[port_id].port_status =RTE_PORT_HANDLING ;break ;case RTE_ETH_EVENT_INTR_RMV :if (port_id_is_invalid (port_id,DISABLED_WARN ))@@ -3801,15 +3773,6 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,case RTE_ETH_EVENT_DESTROY : ports[port_id].port_status =RTE_PORT_CLOSED ;printf ("Port %u is closed\n" , port_id); -/* -* Defer to remove port id due to the reason that the ethdev -* state is changed from 'ATTACHED' to 'UNUSED' only after the -* event callback finished. Otherwise this port id can not be -* removed. -*/ -if (rte_eal_alarm_set (100000 , remove_invalid_ports_callback, - (void *)(intptr_t )port_id)) -fprintf (stderr,"Could not set up deferred task to remove this port id.\n" );break ;case RTE_ETH_EVENT_RX_AVAIL_THRESH : {uint16_t rxq_id;
Re: [RFC 01/13] app/testpmd: revert auto attach/detach
Quoted 10 lines · On Tue, 15 Apr 2025 21:28:07 +0800 "lihuisong (C)" <[email protected]> wrote:
Hi Stephen,
The main cause of cpfl driver attach failure is the added alarm in new event callback to setup port automatically.
It's a question of when to set up the new port. Please see the discussion[1]. I have a stupid method, but I'm not very willing to do that. For the Bugzilla id1695, I'll take a look at it.
For now I am going to revert the testpmd change.
Come back when you have something that works without breaking pdump application.
Re: [RFC 01/13] app/testpmd: revert auto attach/detach
Quoted 11 lines · Stephen Hemminger
Quoted 8 lines · On Tue, 15 Apr 2025 21:28:07 +0800 "lihuisong (C)" <[email protected]> wrote:
Hi Stephen,
The main cause of cpfl driver attach failure is the added alarm in new event callback to setup port automatically.
It's a question of when to set up the new port. Please see the discussion[1]. I have a stupid method, but I'm not very willing to do that. For the Bugzilla id1695, I'll take a look at it.
Quoted 4 lines
Quoted 2 lines
For now I am going to revert the testpmd change.
Come back when you have something that works without breaking pdump application.
ok
RFC 2/13 ethdev: allow start/stop from secondary process
In reply to Stephen HemmingerBefore this patch if secondary process called start/stop it would only impact the secondary process, the ethdev on the primary process will still not be started.
With this patch, when start/stop is called from secondary, it calls the primary and does the operation there. The design is generic, and we can later add queue and other operations as needed.
Bugzilla ID: 73
--- lib/ethdev/ethdev_driver.c | 11 ++++- lib/ethdev/ethdev_private.c | 77 ++++++++++++++++++++++++++++++++++ lib/ethdev/ethdev_private.h | 23 ++++++++++ lib/ethdev/rte_ethdev.c | 84 +++++++++++++++++++++---------------- 4 files changed, 158 insertions(+), 37 deletions(-)
lib/ethdev/ethdev_driver.c +10 -1
@@ -114,6 +114,14 @@ rte_eth_dev_allocate(const char *name) goto unlock; } +if (eth_dev_shared_data->allocated_ports ==0 && +rte_mp_action_register (ETHDEV_MP , ethdev_server) && + rte_errno !=ENOTSUP ) { +RTE_ETHDEV_LOG_LINE (ERR , +"Could not start %s service" ,ETHDEV_MP ); + goto unlock; + } + eth_dev =eth_dev_get (port_id); eth_dev->flow_fp_ops = &rte_flow_fp_default_ops;strlcpy (eth_dev->data->name, name,sizeof (eth_dev->data->name));
@@ -282,7 +290,8 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)memset (eth_dev->data,0 ,sizeof (struct rte_eth_dev_data )); eth_dev->data =NULL ; - eth_dev_shared_data->allocated_ports--; +if (--eth_dev_shared_data->allocated_ports ==0 ) +rte_mp_action_unregister (ETHDEV_MP );eth_dev_shared_data_release (); }
lib/ethdev/ethdev_private.c +77 -0
80 lines not on this page · raw message
lib/ethdev/ethdev_private.h +23 -0
@@ -79,4 +79,27 @@ void eth_dev_txq_release(struct rte_eth_dev *dev, uint16_t qid);int eth_dev_rx_queue_config (struct rte_eth_dev *dev,uint16_t nb_queues);int eth_dev_tx_queue_config (struct rte_eth_dev *dev,uint16_t nb_queues); +/* Used to allow start/stop from secondary */ +#define ETHDEV_MP "mp_ethdev" + +enum ethdev_mp_operation { +ETH_REQ_START , +ETH_REQ_STOP , +}; + +struct ethdev_mp_request { +uint16_t operation; +uint16_t port_id; +uint32_t reserved; +}; + +struct ethdev_mp_response { +uint16_t res_op; +uint16_t port_id; +int32_t err_value; +}; + +int ethdev_server (const struct rte_mp_msg *mp_msg,const void *peer); +int ethdev_request (enum ethdev_mp_operation op,uint16_t port,uint16_t queue); +#endif /* _ETH_PRIVATE_H_ */
lib/ethdev/rte_ethdev.c +48 -36
111 lines not on this page · raw message
Signature · 1 line
2.47.2
Re: [RFC 02/13] ethdev: allow start/stop from secondary process
Quoted 9 lines · On Fri, 11 Apr 2025 16:44:39 -0700 Stephen Hemminger…
Before this patch if secondary process called start/stop it would only impact the secondary process, the ethdev on the primary process will still not be started.
With this patch, when start/stop is called from secondary, it calls the primary and does the operation there. The design is generic, and we can later add queue and other operations as needed.
Quoted 4 lines
Bugzilla ID: 73
Signed-off-by Stephen Hemminger <[email protected]>---
Wanted to expand this to other functions like rte_eth_dev_configure() but the structure rte_eth_conf has grown quite large According to pahole
/* size: 2280, cachelines: 36, members: 8 */ /* sum members: 2268, holes: 2, sum holes: 8 */ /* padding: 4 */ /* member types with holes: 3, total: 4, bit holes: 1, total: 1, bit paddings: 1, total: 29 bits */
The biggest offender
there is DCB and VMDQ both of which are features I doubt anyone ever uses, but unlikely to get that fixed.
Because it is so large, it is impossible to pass rte_eth_conf over the mp primary/secondary API.
RFC 3/13 test: add test for hotplug and secondary process operations
In reply to Stephen HemmingerUse null device to exercise ethdev start/stop in secondary process.
--- app/test/test_mp_secondary.c | 51 +++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-)
app/test/test_mp_secondary.c +48 -3
@@ -15,6 +15,9 @@#include <string.h> #include <unistd.h> +#include <rte_ethdev.h> +#include <rte_bus_vdev.h> +#ifdef RTE_EXEC_ENV_WINDOWS int test_mp_secondary (void )
@@ -204,6 +207,44 @@ run_object_creation_tests(void)return 0 ; } +static int +run_ethdev_tests (void ) +{ +char vdev_name[] ="net_null" ; +struct rte_eth_conf dev_conf = {0 }; +uint16_t port; +int ret; + +printf ("### Testing hotplug and ethdev start/stop\n" ); + +/* use hotplug to make a null vdev */ + ret =rte_eal_hotplug_add ("vdev" , vdev_name,"" ); +TEST_ASSERT (ret ==0 ,"Hotplug add of '%s' failed" , vdev_name); + +printf ("# Checked hotlug_add OK\n" ); + + ret =rte_eth_dev_get_port_by_name (vdev_name, &port); +TEST_ASSERT (ret ==0 ,"Lookup vdev '%s' failed" , vdev_name); + + ret =rte_eth_dev_configure (port,1 ,1 , &dev_conf); +TEST_ASSERT (ret ==0 ,"Configure port %u failed" , port); + + ret =rte_eth_dev_start (port); +TEST_ASSERT (ret ==0 ,"Start port %u failed" , port); + +printf ("# Checked rte_eth_dev_start\n" ); + + ret =rte_eth_dev_stop (port); +TEST_ASSERT (ret ==0 ,"Stop port %u failed" , port); + +printf ("# Checked rte_eth_dev_stop\n" ); + +rte_eal_hotplug_remove ("vdev" , vdev_name); + +printf ("# Checked hotlug_remove OK\n" ); +return 0 ; +} +/* if called in a primary process, just spawns off a secondary process to * run validation tests - which brings us right back here again... * if called in a secondary process, this runs a series of API tests to check
@@ -212,15 +253,19 @@ run_object_creation_tests(void)int test_mp_secondary (void ) { -if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) { +int ret; + +if (rte_eal_process_type () ==RTE_PROC_PRIMARY )return run_secondary_instances (); - }printf ("IN SECONDARY PROCESS\n" ); + ret =run_ethdev_tests (); +if (ret !=0 ) +return ret;return run_object_creation_tests (); }#endif /* !RTE_EXEC_ENV_WINDOWS */ -REGISTER_FAST_TEST (multiprocess_autotest, false, false, test_mp_secondary); +REGISTER_FAST_TEST (multiprocess_autotest, true, true, test_mp_secondary);
Signature · 1 line
2.47.2
RFC 4/13 net/ring: allow lockfree transmit if ring supports it
In reply to Stephen HemmingerNeed to be able have multiple threads all using same transmit queue when using SPAN.
--- drivers/net/ring/rte_eth_ring.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/net/ring/rte_eth_ring.c +17 -0
@@ -177,6 +177,19 @@ eth_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,return 0 ; } +static bool +eth_tx_queue_lockfree (const struct pmd_internals *internals) +{ +unsigned int i; + +for (i =0 ; i < internals->max_tx_queues; i++) { +const struct ring_queue *r = &internals->tx_ring_queues[i]; + +if (r->rng->flags &RING_F_SP_ENQ ) +return false; + } +return true; +} static int eth_dev_info(struct rte_eth_dev *dev,
@@ -189,6 +202,10 @@ eth_dev_info(struct rte_eth_dev *dev, dev_info->max_rx_queues = (uint16_t )internals->max_rx_queues; dev_info->rx_offload_capa =RTE_ETH_RX_OFFLOAD_SCATTER ; dev_info->tx_offload_capa =RTE_ETH_TX_OFFLOAD_MULTI_SEGS ; + +if (eth_tx_queue_lockfree (internals)) + dev_info->tx_offload_capa |=RTE_ETH_TX_OFFLOAD_MT_LOCKFREE ; + dev_info->max_tx_queues = (uint16_t )internals->max_tx_queues; dev_info->min_rx_bufsize =0 ;
Signature · 1 line
2.47.2
RFC 5/13 net/ring: add argument to attach existing ring
In reply to Stephen HemmingerNeed ability to allow process like dumpcap to make a ring ethdev with a pre-existing ring. Do this via devargs so it can work with hotplug.
The API rte_eth_from_ring() doesn't do this.
--- drivers/net/ring/rte_eth_ring.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
drivers/net/ring/rte_eth_ring.c +30 -0
@@ -23,9 +23,12 @@#define ETH_RING_INTERNAL_ARG "internal"#define ETH_RING_INTERNAL_ARG_MAX_LEN 19/* "0x..16chars..\0" */ +#define ETH_RING_RING_ARG "ring" +static const char *valid_arguments[] = {ETH_RING_NUMA_NODE_ACTION_ARG ,ETH_RING_INTERNAL_ARG , +ETH_RING_RING_ARG ,NULL };
@@ -693,6 +696,20 @@ parse_internal_args(const char *key __rte_unused, const char *value,return 0 ; } +static int +parse_ring_arg(const char *key __rte_unused, const char *value, void *data) +{ +struct rte_ring **rp = data; + + *rp =rte_ring_lookup (value); +if (*rp ==NULL ) { +PMD_LOG (ERR ,"ring '%s' not found" , value); +return -1 ; + } + +return 0 ; +} +static int rte_pmd_ring_probe (struct rte_vdev_device *dev) {
@@ -770,6 +787,18 @@ rte_pmd_ring_probe(struct rte_vdev_device *dev) ð_dev);if (ret >=0 ) ret =0 ; + }else if (rte_kvargs_count (kvlist,ETH_RING_RING_ARG ) ==1 ) { +struct rte_ring *rxtx[1 ] = { }; + + ret =rte_kvargs_process (kvlist,ETH_RING_RING_ARG , parse_ring_arg, rxtx); +if (ret <0 ) + goto out_free; + +/* Note: rte_eth_from_ring() does not do what is expected here! */ + ret =do_eth_dev_ring_create (name, dev, rxtx,1 , rxtx,1 , +rte_socket_id (),DEV_ATTACH , ð_dev); +if (ret <0 ) + goto out_free; }else { ret =rte_kvargs_count (kvlist,ETH_RING_NUMA_NODE_ACTION_ARG ); info = rte_zmalloc("struct node_action_list",
@@ -843,4 +872,5 @@ static struct rte_vdev_driver pmd_ring_drv = {RTE_PMD_REGISTER_VDEV (net_ring, pmd_ring_drv);RTE_PMD_REGISTER_ALIAS (net_ring, eth_ring);RTE_PMD_REGISTER_PARAM_STRING (net_ring, +ETH_RING_RING_ARG "=<string> " ETH_RING_NUMA_NODE_ACTION_ARG "=name:node:action(ATTACH|CREATE)" );
Signature · 1 line
2.47.2
RFC 6/13 net/ring: add timestamp devargs
In reply to Stephen HemmingerAdd argument to ring PMD creation to force packets going into ring to be timestamped.
--- drivers/net/ring/rte_eth_ring.c | 44 +++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-)
drivers/net/ring/rte_eth_ring.c +42 -2
@@ -20,15 +20,18 @@#define ETH_RING_ACTION_CREATE "CREATE"#define ETH_RING_ACTION_ATTACH "ATTACH"#define ETH_RING_ACTION_MAX_LEN 8/* CREATE | ACTION */ +#define ETH_RING_INTERNAL_ARG "internal"#define ETH_RING_INTERNAL_ARG_MAX_LEN 19/* "0x..16chars..\0" */ #define ETH_RING_RING_ARG "ring" +#define ETH_RING_TIMESTAMP_ARG "timestamp"static const char *valid_arguments[] = {ETH_RING_NUMA_NODE_ACTION_ARG ,ETH_RING_INTERNAL_ARG ,ETH_RING_RING_ARG , +ETH_RING_TIMESTAMP_ARG ,NULL };
@@ -41,6 +44,9 @@ struct ring_internal_args {void *addr;/* self addr for sanity check */ }; +static uint64_t timestamp_dynflag; +static int timestamp_dynfield_offset =-1 ; +enum dev_action {DEV_CREATE ,DEV_ATTACH
@@ -49,6 +55,8 @@ enum dev_action {struct ring_queue {struct rte_ring *rng;uint16_t in_port; +uint8_t timestamp; +RTE_ATOMIC (uint64_t ) rx_pkts;RTE_ATOMIC (uint64_t ) tx_pkts; };
@@ -56,6 +64,7 @@ struct ring_queue {struct pmd_internals {unsigned int max_rx_queues;unsigned int max_tx_queues; +uint8_t timestamp;struct ring_queue rx_ring_queues[RTE_PMD_RING_MAX_RX_RINGS ];struct ring_queue tx_ring_queues[RTE_PMD_RING_MAX_TX_RINGS ];
@@ -64,6 +73,7 @@ struct pmd_internals {enum dev_action action; }; +static struct rte_eth_link pmd_link = { .link_speed =RTE_ETH_SPEED_NUM_10G , .link_duplex =RTE_ETH_LINK_FULL_DUPLEX ,
@@ -99,8 +109,23 @@ eth_ring_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) {void **ptrs = (void *)&bufs[0 ];struct ring_queue *r = q; -const uint16_t nb_tx = (uint16_t )rte_ring_enqueue_burst (r->rng, - ptrs, nb_bufs,NULL ); +uint16_t nb_tx; + +if (r->timestamp) { +unsigned int i; +uint64_t cycles =rte_get_tsc_cycles (); + +for (i =0 ; i < nb_bufs; i++) { +struct rte_mbuf *m = bufs[i]; + *RTE_MBUF_DYNFIELD (m, timestamp_dynfield_offset, + rte_mbuf_timestamp_t *) = cycles; + m->ol_flags |= timestamp_dynflag; + } + } + + + nb_tx = (uint16_t )rte_ring_enqueue_burst (r->rng, ptrs, nb_bufs,NULL ); +if (r->rng->flags &RING_F_SP_ENQ ) r->tx_pkts += nb_tx;else
@@ -176,6 +201,7 @@ eth_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id, {struct pmd_internals *internals = dev->data->dev_private; + internals->tx_ring_queues[tx_queue_id].timestamp = internals->timestamp; dev->data->tx_queues[tx_queue_id] = &internals->tx_ring_queues[tx_queue_id];return 0 ; }
@@ -835,6 +861,20 @@ rte_pmd_ring_probe(struct rte_vdev_device *dev) } } } + +if (rte_kvargs_count (kvlist,ETH_RING_TIMESTAMP_ARG ) ==1 ) { +struct pmd_internals *internals = eth_dev->data->dev_private; + +if (timestamp_dynfield_offset ==-1 ) { + ret =rte_mbuf_dyn_rx_timestamp_register (×tamp_dynfield_offset, + ×tamp_dynflag); +if (ret <0 ) +return ret; + } + + internals->timestamp =1 ; + } + } out_free:
Signature · 1 line
2.47.2
RFC 7/13 net/null: all lockfree transmit
In reply to Stephen HemmingerFor testing mirror, useful if this device allows lockfree Tx.
--- drivers/net/null/rte_eth_null.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/null/rte_eth_null.c +1 -0
@@ -314,6 +314,7 @@ eth_dev_info(struct rte_eth_dev *dev, dev_info->max_rx_queues =RTE_DIM (internals->rx_null_queues); dev_info->max_tx_queues =RTE_DIM (internals->tx_null_queues); dev_info->min_rx_bufsize =0 ; + dev_info->tx_offload_capa =RTE_ETH_TX_OFFLOAD_MULTI_SEGS |RTE_ETH_TX_OFFLOAD_MT_LOCKFREE ; dev_info->reta_size = internals->reta_size; dev_info->flow_type_rss_offloads = internals->flow_type_rss_offloads; dev_info->hash_key_size =sizeof (internals->rss_key);
Signature · 1 line
2.47.2
RFC 8/13 mbuf: add fields for mirroring
In reply to Stephen HemmingerAdd field to union used for sched/event etc, for use when an mbuf is mirrored.
--- lib/mbuf/rte_mbuf_core.h | 8 ++++++++ 1 file changed, 8 insertions(+)
lib/mbuf/rte_mbuf_core.h +8 -0
@@ -589,6 +589,14 @@ struct __rte_cache_aligned rte_mbuf {* @see rte_event_eth_tx_adapter_txq_set() */ } txadapter;/**< Eventdev ethdev Tx adapter */ +struct rte_mbuf_mirror { +uint32_t orig_len; +uint16_t queue_id; +uint16_t direction; +/**< Port mirroring uses this to store origin +* @see rte_eth_mirror() +*/ + } mirror;uint32_t usr;/**< User defined tags. See rte_distributor_process() */ } hash;/**< hash information */
Signature · 1 line
2.47.2
RE: [RFC 08/13] mbuf: add fields for mirroring
Quoted 32 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Saturday, 12 April 2025 01.45Add field to union used for sched/event etc, for use when an mbuf is mirrored.
Signed-off-by Stephen Hemminger <[email protected]>--- lib/mbuf/rte_mbuf_core.h | 8 ++++++++ 1 file changed, 8 insertions(+)lib/mbuf/rte_mbuf_core.h +0
-0@@ -589,6 +589,14 @@ struct __rte_cache_aligned rte_mbuf {* @see rte_event_eth_tx_adapter_txq_set() */ } txadapter;/**< Eventdev ethdev Tx adapter */
lib/mbuf/rte_mbuf_core.h +5
-0+struct rte_mbuf_mirror { +uint32_t orig_len; +uint16_t queue_id; +uint16_t direction; +/**< Port mirroring uses this to store origin
lib/mbuf/rte_mbuf_core.h +3
-0+* @see rte_eth_mirror() +*/ + } mirror;uint32_t usr;/**< User defined tags. See
Quoted 2 lines
rte_distributor_process()*/
} hash; /**< hash information
Stop overloading the "hash" field!
We now have dynfields. The mbuf structure's dedicated fields should be limited to absolute core features.
Long term, the "hash" field should be cleaned up.
E.g. if we get rid of the Flow Director and make the 8 byte "sched" (Hierarchical Scheduler) a dynfield, the "hash" field can be reduced from 8 byte to 4 byte (RSS hash).
I acknowledge that some mbuf fields can be overloaded and thus used for multiple purposes - i.e. a value only used for ingress/forwarding (e.g. RSS hash) can share an mbuf field with a value only used for egress (e.g. Scheduler).
The overloading of the "hash" field is too much already. E.g. can the Hierarchical Scheduler be used together with the Eventdev ethdev Tx adapter, or are they mutually exclusive due to sharing the same mbuf field?
Going to the extreme, we would completely replace the "hash" field by dynfields.
In short: Overloading the "hash" field with port mirror information is a step in the wrong direction.
Quoted 3 lines
*/
--
2.47.2
Re: [RFC 08/13] mbuf: add fields for mirroring
Quoted 42 lines · On Sat, 12 Apr 2025 11:59:10 +0200 Morten Brørup <[email protected]>…
Quoted 32 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Saturday, 12 April 2025 01.45Add field to union used for sched/event etc, for use when an mbuf is mirrored.
Signed-off-by Stephen Hemminger <[email protected]>--- lib/mbuf/rte_mbuf_core.h | 8 ++++++++ 1 file changed, 8 insertions(+)lib/mbuf/rte_mbuf_core.h +0
-0@@ -589,6 +589,14 @@ struct __rte_cache_aligned rte_mbuf {* @see rte_event_eth_tx_adapter_txq_set() */ } txadapter;/**< Eventdev ethdev Tx adapter */
lib/mbuf/rte_mbuf_core.h +5
-0+struct rte_mbuf_mirror { +uint32_t orig_len; +uint16_t queue_id; +uint16_t direction; +/**< Port mirroring uses this to store origin
lib/mbuf/rte_mbuf_core.h +3
-0+* @see rte_eth_mirror() +*/ + } mirror;uint32_t usr;/**< User defined tags. See Quoted 2 lines
rte_distributor_process()*/
} hash; /**< hash informationStop overloading the "hash" field!
We now have dynfields. The mbuf structure's dedicated fields should be limited to absolute core features.
Long term, the "hash" field should be cleaned up.
E.g. if we get rid of the Flow Director and make the 8 byte "sched" (Hierarchical Scheduler) a dynfield, the "hash" field can be reduced from 8 byte to 4 byte (RSS hash).
Quoted 7 lines
I acknowledge that some mbuf fields can be overloaded and thus used for multiple purposes - i.e. a value only used for ingress/forwarding (e.g. RSS hash) can share an mbuf field with a value only used for egress (e.g. Scheduler).
The overloading of the "hash" field is too much already. E.g. can the Hierarchical Scheduler be used together with the Eventdev ethdev Tx adapter, or are they mutually exclusive due to sharing the same mbuf field?
Going to the extreme, we would completely replace the "hash" field by dynfields.
In short: Overloading the "hash" field with port mirror information is a step in the wrong direction.
Short answer: Dynamic Fields are hard to work with primary/secondary process model. The goal was to allow dumpcap to run and just work without modifications to the primary application. If secondary creates dynamic field, the primary doesn't see it.
The hash field is not going away, flow director is stuck, it has been scheduled for removal for 3 years and Intel still needs it. Other uses such as storing received hash value are still needed.
Long answer:
It maybe possible. The patchset went through many revisions during development. Ended up having to have MP server for start/stop, and if that code was extended to allow secondary to proxy setting up mirror, then the code in handling mirror() on primary could also setup the dynamic fields. But accessing dynamic fields is slower, not that it matters that much if we have to copy mbuf anyway. Other option would be to pre-pend a pseudo header that capture could then use.
RE: [RFC 08/13] mbuf: add fields for mirroring
Quoted 64 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Saturday, 12 April 2025 18.57Quoted 37 lines · On Sat, 12 Apr 2025 11:59:10 +0200 Morten Brørup <[email protected]>…
Quoted 32 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Saturday, 12 April 2025 01.45Add field to union used for sched/event etc, for use when an mbuf is mirrored.
Signed-off-by Stephen Hemminger <[email protected]>--- lib/mbuf/rte_mbuf_core.h | 8 ++++++++ 1 file changed, 8 insertions(+)lib/mbuf/rte_mbuf_core.h +0
-0@@ -589,6 +589,14 @@ struct __rte_cache_aligned rte_mbuf {* @see rte_event_eth_tx_adapter_txq_set() */ } txadapter;/**< Eventdev ethdev Tx adapter */
lib/mbuf/rte_mbuf_core.h +5
-0+struct rte_mbuf_mirror { +uint32_t orig_len; +uint16_t queue_id; +uint16_t direction; +/**< Port mirroring uses this to store origin
lib/mbuf/rte_mbuf_core.h +3
-0+* @see rte_eth_mirror() +*/ + } mirror;uint32_t usr;/**< User defined tags. See Quoted 2 lines
rte_distributor_process()*/
} hash; /**< hash informationStop overloading the "hash" field!
Quoted 1 line
We now have dynfields. The mbuf structure's dedicated fields should
be limited to absolute core features.
Quoted 3 lines
Long term, the "hash" field should be cleaned up.
E.g. if we get rid of the Flow Director and make the 8 byte "sched"(Hierarchical Scheduler) a dynfield, the "hash" field can be reduced from 8 byte to 4 byte (RSS hash).
Quoted 2 lines
I acknowledge that some mbuf fields can be overloaded and thus used
for multiple purposes - i.e. a value only used for ingress/forwarding (e.g. RSS hash) can share an mbuf field with a value only used for egress (e.g. Scheduler).
Quoted 2 lines
The overloading of the "hash" field is too much already. E.g. can the
Hierarchical Scheduler be used together with the Eventdev ethdev Tx adapter, or are they mutually exclusive due to sharing the same mbuf field?
Quoted 2 lines
Going to the extreme, we would completely replace the "hash" field by
dynfields.
Quoted 1 line
Quoted 8 lines
Quoted 1 line
In short: Overloading the "hash" field with port mirror information
is a step in the wrong direction.
Short answer: Dynamic Fields are hard to work with primary/secondary process model.
The goal was to allow dumpcap to run and just work without modifications to the primary application.
If secondary creates dynamic field, the primary doesn't see it.
I skimmed the mbuf dynfield source code, and it looks like it is designed for primary/secondary process model.
If the primary process doesn't see a dynfield created in a secondary process, it is a bug in the mbuf dynfield library. I couldn't find such a bug in Bugzilla. I would be much better to fix the bug than overloading the "hash" field.
Quoted 19 lines
The hash field is not going away, flow director is stuck, it has been scheduled for removal
for 3 years and Intel still needs it. Other uses such as storing received hash value are
still needed.Long answer:
It maybe possible. The patchset went through many revisions during development.
Ended up having to have MP server for start/stop, and if that code was extended
to allow secondary to proxy setting up mirror, then the code in handlingmirror()on
primary could also setup the dynamic fields. But accessing dynamic fields is slower,
not that it matters that much if we have to copy mbuf anyway. Other option
would be to pre-pend a pseudo header that capture could then use.
Re: [RFC 08/13] mbuf: add fields for mirroring
Quoted 73 lines · On Sun, 13 Apr 2025 09:00:19 +0200 Morten Brørup <[email protected]>…
Quoted 64 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Saturday, 12 April 2025 18.57Quoted 37 lines · On Sat, 12 Apr 2025 11:59:10 +0200 Morten Brørup <[email protected]>…
Quoted 32 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Saturday, 12 April 2025 01.45Add field to union used for sched/event etc, for use when an mbuf is mirrored.
Signed-off-by Stephen Hemminger <[email protected]>--- lib/mbuf/rte_mbuf_core.h | 8 ++++++++ 1 file changed, 8 insertions(+)lib/mbuf/rte_mbuf_core.h +0
-0@@ -589,6 +589,14 @@ struct __rte_cache_aligned rte_mbuf {* @see rte_event_eth_tx_adapter_txq_set() */ } txadapter;/**< Eventdev ethdev Tx adapter */
lib/mbuf/rte_mbuf_core.h +5
-0+struct rte_mbuf_mirror { +uint32_t orig_len; +uint16_t queue_id; +uint16_t direction; +/**< Port mirroring uses this to store origin
lib/mbuf/rte_mbuf_core.h +3
-0+* @see rte_eth_mirror() +*/ + } mirror;uint32_t usr;/**< User defined tags. See Quoted 2 lines
rte_distributor_process()*/
} hash; /**< hash informationStop overloading the "hash" field!
Quoted 1 line
We now have dynfields. The mbuf structure's dedicated fields should
be limited to absolute core features.
Quoted 3 lines
Long term, the "hash" field should be cleaned up.
E.g. if we get rid of the Flow Director and make the 8 byte "sched"(Hierarchical Scheduler) a dynfield, the "hash" field can be reduced from 8 byte to 4 byte (RSS hash).
Quoted 2 lines
I acknowledge that some mbuf fields can be overloaded and thus used
for multiple purposes - i.e. a value only used for ingress/forwarding (e.g. RSS hash) can share an mbuf field with a value only used for egress (e.g. Scheduler).
Quoted 2 lines
The overloading of the "hash" field is too much already. E.g. can the
Hierarchical Scheduler be used together with the Eventdev ethdev Tx adapter, or are they mutually exclusive due to sharing the same mbuf field?
Quoted 2 lines
Going to the extreme, we would completely replace the "hash" field by
dynfields.
Quoted 1 line
Quoted 8 lines
Quoted 1 line
In short: Overloading the "hash" field with port mirror information
is a step in the wrong direction.
Short answer: Dynamic Fields are hard to work with primary/secondary process model.
The goal was to allow dumpcap to run and just work without modifications to the primary application.
If secondary creates dynamic field, the primary doesn't see it.
Quoted 3 lines
I skimmed the mbuf dynfield source code, and it looks like it is designed for primary/secondary process model.
If the primary process doesn't see a dynfield created in a secondary process, it is a bug in the mbuf dynfield library. I couldn't find such a bug in Bugzilla. I would be much better to fix the bug than overloading the "hash" field.
The problem is that if secondary makes a new field, the primary still has to lookup the offset. And don't want to do that in the packet path. Need to invoke a control path argument in the primary. If primary always makes the dynamic field, there really is not much point in it being dynamic.
RE: [RFC 08/13] mbuf: add fields for mirroring
Quoted 99 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Sunday, 13 April 2025 16.32Quoted 12 lines · On Sun, 13 Apr 2025 09:00:19 +0200 Morten Brørup <[email protected]>…
Quoted 12 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Saturday, 12 April 2025 18.57Quoted 6 lines · On Sat, 12 Apr 2025 11:59:10 +0200 Morten Brørup <[email protected]>…
Quoted 6 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Saturday, 12 April 2025 01.45Add field to union used for sched/event etc, for use when an mbuf is mirrored.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Review
Quoted 6 lines
Signed-off-by Stephen Hemminger <[email protected]>--- lib/mbuf/rte_mbuf_core.h | 8 ++++++++ 1 file changed, 8 insertions(+)(quoted diff) +0
-0
b/lib/mbuf/rte_mbuf_core.hQuoted 8 lines
Quoted 8 lines
Quoted 8 lines
lib/mbuf/rte_mbuf_core.h struct __rte_cache_aligned rte_mbuf { · line 592
Quoted 8 lines
index
a0df265b5d..1806dddd67100644lib/mbuf/rte_mbuf_core.h +0
-0@@ -589,6 +589,14 @@ struct __rte_cache_aligned rte_mbuf {* @see rte_event_eth_tx_adapter_txq_set() */ } txadapter;/**< Eventdev ethdev Tx
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
lib/mbuf/rte_mbuf_core.h struct __rte_cache_aligned rte_mbuf {
Quoted 6 lines
adapter */
lib/mbuf/rte_mbuf_core.h +5
-0+struct rte_mbuf_mirror { +uint32_t orig_len; +uint16_t queue_id; +uint16_t direction; +/**< Port mirroring uses this to
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
store origin
lib/mbuf/rte_mbuf_core.h +3
-0+* @see rte_eth_mirror() +*/ + } mirror;uint32_t usr;/**< User defined tags. See
rte_distributor_process()*/
} hash; /**< hashinformation
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Stop overloading the "hash" field!
We now have dynfields. The mbuf structure's dedicated fields
should
Quoted 4 lines
Quoted 4 lines
be limited to absolute core features.
Quoted 3 lines
Long term, the "hash" field should be cleaned up. E.g. if we get rid of the Flow Director and make the 8 byte
"sched"
Quoted 1 line
Quoted 1 line
(Hierarchical Scheduler) a dynfield, the "hash" field can be
reduced
Quoted 3 lines
Quoted 3 lines
from 8 byte to 4 byte (RSS hash).
Quoted 2 lines
I acknowledge that some mbuf fields can be overloaded and thus
used
Quoted 1 line
Quoted 1 line
for multiple purposes - i.e. a value only used for
ingress/forwarding
Quoted 4 lines
Quoted 4 lines
(e.g. RSS hash) can share an mbuf field with a value only used for egress (e.g. Scheduler).
Quoted 2 lines
The overloading of the "hash" field is too much already. E.g. can
the
Quoted 2 lines
Quoted 2 lines
Hierarchical Scheduler be used together with the Eventdev ethdev Tx adapter, or are they mutually exclusive due to sharing the same
mbuf
Quoted 3 lines
Quoted 3 lines
field?
Quoted 2 lines
Going to the extreme, we would completely replace the "hash"
field by
Quoted 3 lines
Quoted 3 lines
dynfields.
Quoted 2 lines
In short: Overloading the "hash" field with port mirror
information
Quoted 3 lines
Quoted 3 lines
is a step in the wrong direction.
Short answer: Dynamic Fields are hard to work with
primary/secondary
Quoted 6 lines
Quoted 4 lines
process model.
The goal was to allow dumpcap to run and just work without modifications to the primary application.
If secondary creates dynamic field, the primary doesn't see it.I skimmed the mbuf dynfield source code, and it looks like it is
designed for primary/secondary process model.
Quoted 1 line
If the primary process doesn't see a dynfield created in a secondary
process, it is a bug in the mbuf dynfield library. I couldn't find such a bug in Bugzilla.
Quoted 1 line
I would be much better to fix the bug than overloading the "hash"
Quoted 8 lines
field.
The problem is that if secondary makes a new field, the primary still has to lookup the offset.
And don't want to do that in the packet path. Need to invoke a control path argument in the primary.
If primary always makes the dynamic field, there really is not much point in it being dynamic.
The secondary could provide the dynfield offset to the primary in the control plane when adding the mirror, either as part of the struct rte_eth_mirror, or by some other means before setting dev->data->rx/tx_mirror.
RFC 9/13 ethdev: add port mirror capability
In reply to Stephen HemmingerThis adds new feature for port mirroring.
--- config/rte_config.h | 2 + lib/ethdev/ethdev_driver.h | 3 + lib/ethdev/ethdev_private.c | 3 + lib/ethdev/ethdev_trace.h | 14 +++ lib/ethdev/ethdev_trace_points.c | 6 + lib/ethdev/rte_ethdev.c | 191 +++++++++++++++++++++++++++++++ lib/ethdev/rte_ethdev.h | 81 +++++++++++++ lib/ethdev/rte_ethdev_core.h | 6 +- 8 files changed, 304 insertions(+), 2 deletions(-)
config/rte_config.h +2 -0
@@ -70,6 +70,8 @@#define RTE_ETHDEV_QUEUE_STAT_CNTRS 16/* max 256 */ #define RTE_ETHDEV_RXTX_CALLBACKS 1#define RTE_MAX_MULTI_HOST_CTRLS 4 +#define RTE_ETHDEV_MIRROR 1 +#define RTE_MIRROR_BURST_SIZE 256/* cryptodev defines */ #define RTE_CRYPTO_MAX_DEVS 64
lib/ethdev/ethdev_driver.h +3 -0
@@ -172,6 +172,9 @@ struct __rte_cache_aligned rte_eth_dev_data {uint32_t dev_flags;/**< Capabilities */ int numa_node;/**< NUMA node connection */ +struct rte_eth_mirror *rx_mirror;/**< Port mirroring */ +struct rte_eth_mirror *tx_mirror;/**< Port mirroring */ +/** VLAN filter configuration */ struct rte_vlan_filter_conf vlan_filter_conf;
lib/ethdev/ethdev_private.c +3 -0
@@ -284,6 +284,9 @@ eth_dev_fp_ops_setup(struct rte_eth_fp_ops *fpo, fpo->txq.data = dev->data->tx_queues; fpo->txq.clbk = (void * __rte_atomic *)(uintptr_t)dev->pre_tx_burst_cbs; + + fpo->rx_mirror = &dev->data->rx_mirror; + fpo->tx_mirror = &dev->data->tx_mirror; }RTE_EXPORT_SYMBOL (rte_eth_call_rx_callbacks)
lib/ethdev/ethdev_trace.h +14 -0
@@ -1035,6 +1035,20 @@ RTE_TRACE_POINT(rte_trace_point_emit_int (ret); ) +RTE_TRACE_POINT ( + rte_eth_trace_mirror_bind, + RTE_TRACE_POINT_ARGS(uint16_t port_id, + const struct rte_eth_mirror_conf *conf), + rte_trace_point_emit_u16(port_id); +rte_trace_point_emit_ptr (conf); +) + +RTE_TRACE_POINT ( + rte_eth_trace_mirror_unbind, + RTE_TRACE_POINT_ARGS(uint16_t port_id), + rte_trace_point_emit_u16(port_id); +) + RTE_TRACE_POINT( rte_eth_trace_rx_queue_info_get, RTE_TRACE_POINT_ARGS(uint16_t port_id, uint16_t queue_id,
lib/ethdev/ethdev_trace_points.c +6 -0
@@ -389,6 +389,12 @@ RTE_TRACE_POINT_REGISTER(rte_eth_trace_remove_rx_callback,RTE_TRACE_POINT_REGISTER (rte_eth_trace_remove_tx_callback, lib.ethdev.remove_tx_callback) +RTE_TRACE_POINT_REGISTER (rte_eth_trace_mirror_bind, + lib.ethdev.mirror_bind) + +RTE_TRACE_POINT_REGISTER (rte_eth_trace_mirror_unbind, + lib.ethdev.mirror_unbind) +RTE_TRACE_POINT_REGISTER (rte_eth_trace_rx_queue_info_get, lib.ethdev.rx_queue_info_get)
lib/ethdev/rte_ethdev.c +191 -0
209 lines not on this page · raw message
lib/ethdev/rte_ethdev.h +81 -0
99 lines not on this page · raw message
lib/ethdev/rte_ethdev_core.h +4 -2
@@ -101,7 +101,8 @@ struct __rte_cache_aligned rte_eth_fp_ops {eth_rx_descriptor_status_t rx_descriptor_status;/** Refill Rx descriptors with the recycling mbufs. */ eth_recycle_rx_descriptors_refill_t recycle_rx_descriptors_refill; -uintptr_t reserved1[2 ]; +uintptr_t reserved1; +RTE_ATOMIC (struct rte_eth_mirror *) *rx_mirror;/**@}*/ /**@{*/
@@ -121,7 +122,8 @@ struct __rte_cache_aligned rte_eth_fp_ops {eth_recycle_tx_mbufs_reuse_t recycle_tx_mbufs_reuse;/** Get the number of used Tx descriptors. */ eth_tx_queue_count_t tx_queue_count; -uintptr_t reserved2[1 ]; +RTE_ATOMIC (struct rte_eth_mirror *) *tx_mirror; +uintptr_t reserved2;/**@}*/ };
Signature · 1 line
2.47.2
RFC 10/13 pcapng: split packet copy from header insertion
In reply to Stephen HemmingerIn new model, the packet was already copied, only need to wrap it in pcapng format.
--- lib/pcapng/rte_pcapng.c | 178 +++++++++++++++++++++------------------- lib/pcapng/rte_pcapng.h | 27 +++++- 2 files changed, 120 insertions(+), 85 deletions(-)
lib/pcapng/rte_pcapng.c +95 -83
@@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2019 Microsoft Corporation */
@@ -432,8 +433,24 @@ pcapng_vlan_insert(struct rte_mbuf *m, uint16_t ether_type, uint16_t tci)return 0 ; } +/* pad the packet to 32 bit boundary */ +static inline int +pcapng_mbuf_pad32 (struct rte_mbuf *m) +{ +uint32_t pkt_len =rte_pktmbuf_pkt_len (m); +uint32_t padding =RTE_ALIGN (pkt_len,sizeof (uint32_t )) - pkt_len; + +if (padding >0 ) { +void *tail =rte_pktmbuf_append (m, padding); +if (tail ==NULL ) +return -1 ; +memset (tail,0 , padding); + } +return 0 ; +} +/* -* The mbufs created use the Pcapng standard enhanced packet block. +* The mbufs created use the Pcapng standard enhanced packet block. * * 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
@@ -468,71 +485,28 @@ pcapng_vlan_insert(struct rte_mbuf *m, uint16_t ether_type, uint16_t tci)* | Block Total Length | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ - -/* Make a copy of original mbuf with pcapng header and options */ -RTE_EXPORT_SYMBOL (rte_pcapng_copy) -struct rte_mbuf * -rte_pcapng_copy (uint16_t port_id,uint32_t queue, -const struct rte_mbuf *md, -struct rte_mempool *mp, -uint32_t length, -enum rte_pcapng_direction direction, -const char *comment) +RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pcapng_insert, 25.07) +int +rte_pcapng_insert (struct rte_mbuf *m,uint32_t queue, +enum rte_pcapng_direction direction,uint32_t orig_len, +uint64_t timestamp,const char *comment) {struct pcapng_enhance_packet_block *epb; -uint32_t orig_len, pkt_len, padding, flags; -struct pcapng_option *opt; -uint64_t timestamp; -uint16_t optlen; -struct rte_mbuf *mc; -bool rss_hash; - -#ifdef RTE_LIBRTE_ETHDEV_DEBUG -RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id,NULL ); -#endif - orig_len =rte_pktmbuf_pkt_len (md); +uint32_t pkt_len =rte_pktmbuf_pkt_len (m); +uint32_t flags; -/* Take snapshot of the data */ - mc =rte_pktmbuf_copy (md, mp,0 , length); -if (unlikely (mc ==NULL )) -return NULL ; - -/* Expand any offloaded VLAN information */ -if ((direction ==RTE_PCAPNG_DIRECTION_IN && - (md->ol_flags &RTE_MBUF_F_RX_VLAN_STRIPPED )) || - (direction ==RTE_PCAPNG_DIRECTION_OUT && - (md->ol_flags &RTE_MBUF_F_TX_VLAN ))) { -if (pcapng_vlan_insert (mc,RTE_ETHER_TYPE_VLAN , - md->vlan_tci) !=0 ) - goto fail; - } +if (unlikely (pcapng_mbuf_pad32 (m) <0 )) +return -1 ; -if ((direction ==RTE_PCAPNG_DIRECTION_IN && - (md->ol_flags &RTE_MBUF_F_RX_QINQ_STRIPPED )) || - (direction ==RTE_PCAPNG_DIRECTION_OUT && - (md->ol_flags &RTE_MBUF_F_TX_QINQ ))) { -if (pcapng_vlan_insert (mc,RTE_ETHER_TYPE_QINQ , - md->vlan_tci_outer) !=0 ) - goto fail; - } +uint16_t optlen =pcapng_optlen (sizeof (flags)); -/* record HASH on incoming packets */ - rss_hash = (direction ==RTE_PCAPNG_DIRECTION_IN && - (md->ol_flags &RTE_MBUF_F_RX_RSS_HASH )); +/* make queue optional? */ + optlen +=pcapng_optlen (sizeof (queue)); -/* pad the packet to 32 bit boundary */ - pkt_len =rte_pktmbuf_pkt_len (mc); - padding =RTE_ALIGN (pkt_len,sizeof (uint32_t )) - pkt_len; -if (padding >0 ) { -void *tail =rte_pktmbuf_append (mc, padding); +/* does packet have valid RSS hash to include */ +bool rss_hash = (direction ==RTE_PCAPNG_DIRECTION_IN && + (m->ol_flags &RTE_MBUF_F_RX_RSS_HASH )); -if (tail ==NULL ) - goto fail; -memset (tail,0 , padding); - } - - optlen =pcapng_optlen (sizeof (flags)); - optlen +=pcapng_optlen (sizeof (queue));if (rss_hash) optlen +=pcapng_optlen (sizeof (uint8_t ) +sizeof (uint32_t ));
@@ -540,10 +514,10 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue, optlen +=pcapng_optlen (strlen (comment));/* reserve trailing options and block length */ - opt = (struct pcapng_option *) -rte_pktmbuf_append (mc, optlen +sizeof (uint32_t )); +struct pcapng_option *opt = (struct pcapng_option *) +rte_pktmbuf_append (m, optlen +sizeof (uint32_t ));if (unlikely (opt ==NULL )) - goto fail; +return -1 ;switch (direction) {case RTE_PCAPNG_DIRECTION_IN :
@@ -556,24 +530,20 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue, flags =0 ; } - opt =pcapng_add_option (opt,PCAPNG_EPB_FLAGS , - &flags,sizeof (flags)); - - opt =pcapng_add_option (opt,PCAPNG_EPB_QUEUE , - &queue,sizeof (queue)); + opt =pcapng_add_option (opt,PCAPNG_EPB_FLAGS , &flags,sizeof (flags)); + opt =pcapng_add_option (opt,PCAPNG_EPB_QUEUE , &queue,sizeof (queue));if (rss_hash) {uint8_t hash_opt[5 ]; -/* The algorithm could be something else if -* using rte_flow_action_rss; but the current API does not -* have a way for ethdev to report this on a per-packet basis. +/* The algorithm could be something else but the current API does not +* have a way for to record this on a per-packet basis +* and the PCAPNG hash types don't match the DPDK types. */ hash_opt[0 ] =PCAPNG_HASH_TOEPLITZ ; -memcpy (&hash_opt[1 ], &md->hash.rss,sizeof (uint32_t )); - opt =pcapng_add_option (opt,PCAPNG_EPB_HASH , - &hash_opt,sizeof (hash_opt)); +memcpy (&hash_opt[1 ], &m->hash.rss,sizeof (uint32_t )); + opt =pcapng_add_option (opt,PCAPNG_EPB_HASH , &hash_opt,sizeof (hash_opt)); }if (comment)
@@ -583,19 +553,14 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,/* Note: END_OPT necessary here. Wireshark doesn't do it. */ /* Add PCAPNG packet header */ - epb = (struct pcapng_enhance_packet_block *) -rte_pktmbuf_prepend (mc,sizeof (*epb)); + epb = (struct pcapng_enhance_packet_block *)rte_pktmbuf_prepend (m,sizeof (*epb));if (unlikely (epb ==NULL )) - goto fail; +return -1 ; epb->block_type =PCAPNG_ENHANCED_PACKET_BLOCK ; - epb->block_length =rte_pktmbuf_pkt_len (mc); - -/* Interface index is filled in later during write */ - mc->port = port_id; + epb->block_length =rte_pktmbuf_pkt_len (m); -/* Put timestamp in cycles here - adjust in packet write */ - timestamp =rte_get_tsc_cycles (); +/* Put timestamp in cycles here - adjusted in packet write */ epb->timestamp_hi = timestamp >>32 ; epb->timestamp_lo = (uint32_t )timestamp; epb->capture_length = pkt_len;
@@ -603,9 +568,56 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,/* set trailer of block length */ *(uint32_t *)opt = epb->block_length; +return 0 ; +} + +/* Make a copy of original mbuf with pcapng header and options */ +RTE_EXPORT_SYMBOL (rte_pcapng_copy) +struct rte_mbuf * +rte_pcapng_copy (uint16_t port_id,uint32_t queue, +const struct rte_mbuf *md, +struct rte_mempool *mp, +uint32_t length, +enum rte_pcapng_direction direction, +const char *comment) +{ +uint32_t orig_len =rte_pktmbuf_pkt_len (md); +struct rte_mbuf *mc; -return mc; +#ifdef RTE_LIBRTE_ETHDEV_DEBUG +RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id,NULL ); +#endif + +/* Take snapshot of the data */ + mc =rte_pktmbuf_copy (md, mp,0 , length); +if (unlikely (mc ==NULL )) +return NULL ; + +/* Expand any offloaded VLAN information */ +if ((direction ==RTE_PCAPNG_DIRECTION_IN && + (md->ol_flags &RTE_MBUF_F_RX_VLAN_STRIPPED )) || + (direction ==RTE_PCAPNG_DIRECTION_OUT && + (md->ol_flags &RTE_MBUF_F_TX_VLAN ))) { +if (pcapng_vlan_insert (mc,RTE_ETHER_TYPE_VLAN , + md->vlan_tci) !=0 ) + goto fail; + } + +if ((direction ==RTE_PCAPNG_DIRECTION_IN && + (md->ol_flags &RTE_MBUF_F_RX_QINQ_STRIPPED )) || + (direction ==RTE_PCAPNG_DIRECTION_OUT && + (md->ol_flags &RTE_MBUF_F_TX_QINQ ))) { +if (pcapng_vlan_insert (mc,RTE_ETHER_TYPE_QINQ , + md->vlan_tci_outer) !=0 ) + goto fail; + } + +/* Interface index is filled in later during write */ + mc->port = port_id; +if (likely (rte_pcapng_insert (mc, queue, direction, orig_len, +rte_get_tsc_cycles (), comment) ==0 )) +return mc; fail:rte_pktmbuf_free (mc);return NULL ;
lib/pcapng/rte_pcapng.h +25 -2
@@ -99,7 +99,7 @@ enum rte_pcapng_direction { };/** -* Format an mbuf for writing to file. +* Make a copy of mbuf for writing to file. * * @param port_id * The Ethernet port on which packet was received
@@ -117,7 +117,7 @@ enum rte_pcapng_direction {* @param direction * The direction of the packer: receive, transmit or unknown. * @param comment -* Packet comment. +* Packet comment (optional). * * @return * - The pointer to the new mbuf formatted for pcapng_write
@@ -129,6 +129,29 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,uint32_t length, enum rte_pcapng_direction direction, const char *comment); +/** +* Format an mbuf for writing to file. +* +* @param m +* The mbuf to modify. +* @param queue +* The queue on the Ethernet port where packet was received +* or is going to be transmitted. +* @param direction +* The direction of the packer: receive, transmit or unknown. +* @param orig_len +* The length of the original packet which maybe less than actual +* packet if only a snapshot was captured. +* @param timestamp +* The timestamp for packet in TSC cycles. +* @param comment +* Packet comment (optional). +*/ +__rte_experimental +int +rte_pcapng_insert (struct rte_mbuf *m,uint32_t queue, +enum rte_pcapng_direction direction,uint32_t orig_len, +uint64_t timestamp,const char *comment);/** * Determine optimum mbuf data size.
Signature · 1 line
2.47.2
RFC 11/13 test: add tests for ethdev mirror
In reply to Stephen HemmingerSimple API and packet mirroring standalone tests.
--- app/test/meson.build | 1 + app/test/test_ethdev_mirror.c | 286 ++++++++++++++++++++++++++++++++++ 2 files changed, 287 insertions(+) create mode 100644 app/test/test_ethdev_mirror.c
app/test/meson.build +1 -0
@@ -73,6 +73,7 @@ source_file_deps = { 'test_errno.c': [], 'test_ethdev_api.c': ['ethdev'], 'test_ethdev_link.c': ['ethdev'], + 'test_ethdev_mirror.c': ['net_ring', 'ethdev', 'bus_vdev'], 'test_event_crypto_adapter.c': ['cryptodev', 'eventdev', 'bus_vdev'], 'test_event_dma_adapter.c': ['dmadev', 'eventdev', 'bus_vdev'], 'test_event_eth_rx_adapter.c': ['ethdev', 'eventdev', 'bus_vdev'],
app/test/test_ethdev_mirror.c new file +286 -0
286 lines not on this page · raw message
Signature · 1 line
2.47.2
RFC 12/13 app/testpmd: support for port mirroring
In reply to Stephen HemmingerAdd new commands to enable testing of port mirror functionality.
--- app/test-pmd/cmdline.c | 1 + app/test-pmd/cmdline_mirror.c | 120 ++++++++++++++++++++ app/test-pmd/cmdline_mirror.h | 12 ++ app/test-pmd/meson.build | 1 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 15 +++ 5 files changed, 149 insertions(+) create mode 100644 app/test-pmd/cmdline_mirror.c create mode 100644 app/test-pmd/cmdline_mirror.h
app/test-pmd/cmdline.c +1 -0
@@ -66,6 +66,7 @@#include "testpmd.h" #include "cmdline_cman.h" #include "cmdline_mtr.h" +#include "cmdline_mirror.h" #include "cmdline_tm.h" #include "bpf_cmd.h"
app/test-pmd/cmdline_mirror.c new file +120 -0
120 lines not on this page · raw message
app/test-pmd/cmdline_mirror.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Stephen Hemminger <[email protected]> +*/ + +#ifndef _CMDLINE_MIRROR_H_ +#define _CMDLINE_MIRROR_H_ + +/* Port MIRROR commands */ +extern cmdline_parse_inst_t cmd_create_port_mirror; +extern cmdline_parse_inst_t cmd_disable_port_mirror; + +#endif /* _CMDLINE_MIRROR_H_ */
app/test-pmd/meson.build +1 -0
@@ -9,6 +9,7 @@ sources = files( 'cmdline_cman.c', 'cmdline_flow.c', 'cmdline_mtr.c', + 'cmdline_mirror.c', 'cmdline_tm.c', 'cmd_flex_item.c', 'config.c',
doc/guides/testpmd_app_ug/testpmd_funcs.rst +15 -0
@@ -2568,6 +2568,21 @@ where: * ``clear``: Flag that indicates whether the statistics counters should be cleared (i.e. set to zero) immediately after they have been read or not. +create mirror +----------- + +Create a new MIRROR port for an ethernet device:: + + testpmd> create port mirror (port_id) destination (port_id) + +delete mirror +----------- + +Disable MIRROR port for an ethernet device:: + + testpmd> disable port mirror (port_id) + + Traffic Management ------------------
Signature · 1 line
2.47.2
RFC 13/13 app/dumpcap: use port mirror instead of pdump
In reply to Stephen HemmingerUse the new port mirror API instead of pdump.
--- app/dumpcap/main.c | 361 +++++++++++++++++++++++++++++++--------- app/dumpcap/meson.build | 2 +- 2 files changed, 284 insertions(+), 79 deletions(-)
app/dumpcap/main.c +283 -78
@@ -36,8 +36,6 @@#include <rte_mbuf.h> #include <rte_mempool.h> #include <rte_pcapng.h> -#include <rte_pdump.h> -#include <rte_ring.h> #include <rte_string_fns.h> #include <rte_thread.h> #include <rte_time.h>
@@ -92,16 +90,22 @@ struct capture_options {struct interface {TAILQ_ENTRY (interface) next;uint16_t port; +struct rte_bpf *filter; +uint64_t filteraccept;struct capture_options opts; -struct rte_bpf_prm *bpf_prm;char name[RTE_ETH_NAME_MAX_LEN ]; +struct rte_eth_stats start_stats;const char *ifname;const char *ifdescr; }; +static int timestamp_dynfield =-1 ; +static uint64_t timestamp_dynflag; +TAILQ_HEAD (interface_list, interface);static struct interface_list interfaces =TAILQ_HEAD_INITIALIZER (interfaces); +static struct interface *port2intf[RTE_MAX_ETHPORTS ];/* Can do either pcap or pcapng format output */ typedef union {
@@ -239,14 +243,16 @@ static void find_interfaces(void) TAILQ_FOREACH(intf, &interfaces, next) {/* if name is valid then just record port */ -if (rte_eth_dev_get_port_by_name (intf->name, &intf->port) ==0 ) -continue ; +if (rte_eth_dev_get_port_by_name (intf->name, &intf->port) !=0 ) { +/* maybe got passed port number string as name */ + intf->port =get_uint (intf->name,"port_number" ,UINT16_MAX ); +if (rte_eth_dev_get_name_by_port (intf->port, intf->name) <0 ) +rte_exit (EXIT_FAILURE ,"Invalid port number %u\n" , + intf->port); + } -/* maybe got passed port number string as name */ - intf->port =get_uint (intf->name,"port_number" ,UINT16_MAX ); -if (rte_eth_dev_get_name_by_port (intf->port, intf->name) <0 ) -rte_exit (EXIT_FAILURE ,"Invalid port number %u\n" , - intf->port); +if (rte_eth_stats_get (intf->port, &intf->start_stats) <0 ) +rte_exit (EXIT_FAILURE ,"Could not read stats for port %u\n" , intf->port); } }
@@ -266,6 +272,9 @@ static void set_default_interface(void) intf =add_interface (name); intf->port = p; + +if (rte_eth_stats_get (intf->port, &intf->start_stats) <0 ) +rte_exit (EXIT_FAILURE ,"Could not read stats for default port %u\n" , intf->port);return ; }rte_exit (EXIT_FAILURE ,"No usable interfaces found\n" );
@@ -295,6 +304,9 @@ static void compile_filters(void)struct bpf_program bf;pcap_t *pcap; +/* cache for filter packets */ + port2intf[intf->port] = intf; + pcap =pcap_open_dead (DLT_EN10MB , intf->opts.snap_len);if (!pcap)rte_exit (EXIT_FAILURE ,"can not open pcap\n" );
@@ -324,7 +336,12 @@ static void compile_filters(void)exit (0 ); } - intf->bpf_prm = bpf_prm; + + intf->filter =rte_bpf_load (bpf_prm); +if (intf->filter ==NULL ) +rte_exit (EXIT_FAILURE , +"BPF load failed '%s'\n%s(%d)\n" , + intf->name,rte_strerror (rte_errno), rte_errno);/* Don't care about original program any more */ pcap_freecode (&bf);
@@ -518,13 +535,12 @@ static void statistics_loop(void) }static void -cleanup_pdump_resources (void ) +disable_mirror_ports (void ) {struct interface *intf; TAILQ_FOREACH(intf, &interfaces, next) { -rte_pdump_disable (intf->port, -RTE_PDUMP_ALL_QUEUES ,RTE_PDUMP_FLAG_RXTX ); +rte_eth_remove_mirror (intf->port);if (intf->opts.promisc_mode)rte_eth_promiscuous_disable (intf->port); }
@@ -552,7 +568,6 @@ enable_primary_monitor(void) {int ret; -/* Once primary exits, so will pdump. */ ret =rte_eal_alarm_set (MONITOR_INTERVAL , monitor_primary,NULL );if (ret <0 )fprintf (stderr,"Fail to enable monitor:%d\n" , ret);
@@ -571,23 +586,24 @@ disable_primary_monitor(void)static void report_packet_stats (dumpcap_out_t out) { -struct rte_pdump_stats pdump_stats;struct interface *intf; -uint64_t ifrecv, ifdrop; -double percent;fputc ('\n' , stderr); + TAILQ_FOREACH(intf, &interfaces, next) { -if (rte_pdump_stats (intf->port, &pdump_stats) <0 ) +uint64_t ifrecv, ifdrop; +struct rte_eth_stats stats; +double percent; + +if (rte_eth_stats_get (intf->port, &stats) <0 )continue ; -/* do what Wiretap does */ - ifrecv = pdump_stats.accepted + pdump_stats.filtered; - ifdrop = pdump_stats.nombuf + pdump_stats.ringfull; + ifrecv = stats.ipackets - intf->start_stats.ipackets; + ifdrop = (stats.rx_nombuf - intf->start_stats.rx_nombuf) + + (stats.imissed - intf->start_stats.imissed);if (use_pcapng) -rte_pcapng_write_stats (out.pcapng, intf->port, - ifrecv, ifdrop,NULL ); +rte_pcapng_write_stats (out.pcapng, intf->port, ifrecv, ifdrop,NULL );if (ifrecv ==0 ) percent =0 ;
@@ -668,12 +684,21 @@ static void dpdk_init(void)rte_exit (EXIT_FAILURE ,"Can not restore original CPU affinity\n" ); } -/* Create packet ring shared between callbacks and process */ -static struct rte_ring *create_ring (void ) +/* Create ring port to redirect packet to. +* This could be much simpler if the ring PMD API (rte_eth_from_rings) +* worked from a secondary process, but it doesn't. +*/ +static struct rte_ring * +create_ring_dev (char *vdev_name,uint16_t *mirror_port) { -struct rte_ring *ring; +struct rte_eth_dev_owner owner = {0 }; +struct rte_eth_conf dev_conf = {0 }; +struct rte_ring *ring =NULL ;char ring_name[RTE_RING_NAMESIZE ]; +char vdev_args[128 ];size_t size, log2; +uint16_t port; +int ret;/* Find next power of 2 >= size. */ size = ring_size;
@@ -686,17 +711,60 @@ static struct rte_ring *create_ring(void) ring_size = size; } -/* Want one ring per invocation of program */ -snprintf (ring_name,sizeof (ring_name), -"dumpcap-%d" ,getpid ()); + ret =rte_eth_dev_owner_new (&owner.id); +if (ret <0 ) +rte_exit (EXIT_FAILURE ,"rte_eth_dev_owner_new failed: %s\n" , +strerror (-ret)); - ring =rte_ring_create (ring_name, ring_size, -rte_socket_id (),0 ); +/* Give the vdev a unique name */ +snprintf (ring_name,sizeof (ring_name),"dumpcap%" PRIu64, owner.id); + ring =rte_ring_create (ring_name, ring_size,rte_socket_id (), +RING_F_MP_RTS_ENQ |RING_F_SC_DEQ );if (ring ==NULL )rte_exit (EXIT_FAILURE ,"Could not create ring :%s\n" ,rte_strerror (rte_errno)); +strlcpy (owner.name, ring_name,sizeof (owner.name)); + +snprintf (vdev_name,RTE_DEV_NAME_MAX_LEN , +"net_ring-dumpcap%" PRIu64, owner.id); +snprintf (vdev_args,sizeof (vdev_args), +"ring=%s,timestamp" , ring_name); + +if (rte_eal_hotplug_add ("vdev" , vdev_name, vdev_args) <0 ) +rte_exit (EXIT_FAILURE , +"rte_eal_hotplug_add of %s failed:%s\n" , + vdev_name,rte_strerror (rte_errno)); + + ret =rte_eth_dev_get_port_by_name (vdev_name, &port); +if (ret !=0 ) { +fprintf (stderr,"Could not port for %s: %s\n" , + vdev_name,strerror (-ret)); + goto unplug; + } + + ret =rte_eth_dev_owner_set (port, &owner); +if (ret !=0 ) { +fprintf (stderr,"Could not set owner for port for %u: %s\n" , + port,strerror (-ret)); + goto unplug; + } + + ret =rte_eth_dev_configure (port,1 ,1 , &dev_conf); +if (ret <0 ) { +fprintf (stderr,"Could not configure port %u: %s\n" , + port,strerror (-ret)); + goto unplug; + } + + *mirror_port = port;return ring; + +unplug: +rte_eal_hotplug_remove ("vdev" , vdev_name); +rte_ring_free (ring); +rte_eal_cleanup (); +exit (EXIT_FAILURE ); }static struct rte_mempool *create_mempool (void )
@@ -796,7 +864,7 @@ static dumpcap_out_t create_output(void) version(), capture_comment);if (ret.pcapng ==NULL )rte_exit (EXIT_FAILURE ,"pcapng_fdopen failed: %s\n" , -strerror (rte_errno)); +rte_strerror (rte_errno));free (os); TAILQ_FOREACH(intf, &interfaces, next) {
@@ -823,37 +891,30 @@ static dumpcap_out_t create_output(void)return ret; } -static void enable_pdump (struct rte_ring *r,struct rte_mempool *mp) +static int enable_mirror (uint16_t mirror_port,struct rte_mempool *mpool) {struct interface *intf;unsigned int count =0 ; -uint32_t flags;int ret; - flags =RTE_PDUMP_FLAG_RXTX ; -if (use_pcapng) - flags |=RTE_PDUMP_FLAG_PCAPNG ; + ret =rte_eth_dev_start (mirror_port); +if (ret <0 ) +rte_exit (EXIT_FAILURE ,"Could not start mirror port %u: %s\n" , + mirror_port,strerror (-ret)); TAILQ_FOREACH(intf, &interfaces, next) { - ret =rte_pdump_enable_bpf (intf->port,RTE_PDUMP_ALL_QUEUES , - flags, intf->opts.snap_len, - r, mp, intf->bpf_prm); +struct rte_eth_mirror_conf conf = { + .mp = mpool, + .snaplen = intf->opts.snap_len, + .direction =RTE_MIRROR_DIRECTION_INGRESS | +RTE_MIRROR_DIRECTION_EGRESS , + }; + + ret =rte_eth_add_mirror (intf->port, mirror_port, &conf);if (ret <0 ) { -const struct interface *intf2; - -/* unwind any previous enables */ - TAILQ_FOREACH(intf2, &interfaces, next) { -if (intf == intf2) -break ; -rte_pdump_disable (intf2->port, -RTE_PDUMP_ALL_QUEUES ,RTE_PDUMP_FLAG_RXTX ); -if (intf2->opts.promisc_mode) -rte_eth_promiscuous_disable (intf2->port); - } -rte_exit (EXIT_FAILURE , -"Packet dump enable on %u:%s failed %s\n" , - intf->port, intf->name, -rte_strerror (rte_errno)); +fprintf (stderr,"Port mirror on %u:%s failed %s\n" , + intf->port, intf->name,strerror (-ret)); +return -1 ; }if (intf->opts.promisc_mode) {
@@ -868,6 +929,31 @@ static void enable_pdump(struct rte_ring *r, struct rte_mempool *mp) } ++count; } +return count; +} + +static void setup_mbuf (void ) +{ +int offset; + + offset =rte_mbuf_dynfield_lookup (RTE_MBUF_DYNFIELD_TIMESTAMP_NAME ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find timestamp dynamic field\n" ); +return ; + } + timestamp_dynfield = offset; + + offset =rte_mbuf_dynflag_lookup (RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find timestamp flag\n" ); +return ; + } + timestamp_dynflag =RTE_BIT64 (offset); +} + +static void show_capturing (unsigned int count) +{ +struct interface *intf;fputs ("Capturing on " , stdout); TAILQ_FOREACH(intf, &interfaces, next) {
@@ -898,6 +984,42 @@ static void show_count(uint64_t count) bt =fprintf (stderr,"%" PRIu64" " , count); } +static ssize_t +pcapng_write_packets (rte_pcapng_t *pcapng, +struct rte_mbuf *pkts[],uint16_t n) +{ +struct rte_mbuf *towrite[BURST_SIZE ]; +unsigned int count =0 ; +unsigned int i; + +for (i =0 ; i < n; i++) { +struct rte_mbuf *m = pkts[i]; +const struct rte_mbuf_mirror *orig = &m->hash.mirror; +enum rte_pcapng_direction direction; +uint64_t ts; + +if (orig->direction ==RTE_MIRROR_DIRECTION_INGRESS ) + direction =RTE_PCAPNG_DIRECTION_IN ; +else if (orig->direction ==RTE_MIRROR_DIRECTION_EGRESS ) + direction =RTE_PCAPNG_DIRECTION_OUT ; +else + direction =RTE_PCAPNG_DIRECTION_UNKNOWN ; + +if (likely (m->ol_flags & timestamp_dynflag)) + ts = *RTE_MBUF_DYNFIELD(m, timestamp_dynfield, rte_mbuf_timestamp_t *); +else + ts =rte_get_tsc_cycles (); + +if (unlikely (rte_pcapng_insert (m, orig->queue_id, direction, + orig->orig_len, ts,NULL ) <0 )) +continue ;/* skip no headroom? */ + + towrite[count++] = m; + } + +return rte_pcapng_write_packets (pcapng, towrite, count); +} +/* Write multiple packets in older pcap format */ static ssize_t pcap_write_packets(pcap_dumper_t *dumper,
@@ -930,16 +1052,82 @@ pcap_write_packets(pcap_dumper_t *dumper,return total; } +static unsigned int +filter_burst (struct interface *intf,struct rte_mbuf *pkts[],unsigned int n) +{ +uint64_t results[BURST_SIZE ]; +struct rte_mbuf *towrite[BURST_SIZE ]; +unsigned int i, count; +uint32_t matches; + + matches =rte_bpf_exec_burst (intf->filter, (void **)pkts, results, n); +if (matches == n) +return n; + intf->filteraccept += matches; + +for (i =0 , count =0 ; i < n; i++) { +if (results[i]) + towrite[count++] = pkts[i]; +else +rte_pktmbuf_free (pkts[i]); + } +memcpy (pkts, towrite, count *sizeof (struct rte_mbuf *)); +return count; +} + +static ssize_t +process_burst (uint16_t in_port,dumpcap_out_t out, +struct rte_mbuf *pkts[],unsigned int n) +{ +struct interface *intf; +ssize_t written; + +if (in_port >=RTE_MAX_ETHPORTS ) + goto invalid_port; + + intf = port2intf[in_port]; +if (intf ==NULL ) + goto invalid_port; + +if (intf->filter) { + n =filter_burst (intf, pkts, n); +if (n ==0 ) +return 0 ; + } + + packets_received += n; +if (use_pcapng) + written =pcapng_write_packets (out.pcapng, pkts, n); +else + written =pcap_write_packets (out.dumper, pkts, n); + +if (written >0 ) + file_size += written; + +rte_pktmbuf_free_bulk (pkts, n); +return written; + +invalid_port: +static bool warn_once = true; +if (warn_once) { + warn_once = false; +fprintf (stderr,"Packet in ring from port %u\n" , in_port); + } + +rte_pktmbuf_free_bulk (pkts, n); +return 0 ; +} +/* Process all packets in ring and dump to capture file */ -static int process_ring (dumpcap_out_t out,struct rte_ring *r) +static int process_ring (dumpcap_out_t out,struct rte_ring *ring) {struct rte_mbuf *pkts[BURST_SIZE ]; -unsigned int avail, n; +uint16_t in_port; +unsigned int i, n, start, avail;static unsigned int empty_count; -ssize_t written; +int ret; - n =rte_ring_sc_dequeue_burst (r, (void **) pkts,BURST_SIZE , - &avail); + n =rte_ring_sc_dequeue_burst (ring, (void **)pkts,BURST_SIZE , &avail);if (n ==0 ) {/* don't consume endless amounts of cpu if idle */ if (empty_count <SLEEP_THRESHOLD )
@@ -951,18 +1139,24 @@ static int process_ring(dumpcap_out_t out, struct rte_ring *r) empty_count = (avail ==0 ); -if (use_pcapng) - written =rte_pcapng_write_packets (out.pcapng, pkts, n); -else - written =pcap_write_packets (out.dumper, pkts, n); +/* process all packets mirrored from same port */ + start =0 ; + in_port = pkts[start]->port; +for (i =1 ; i < n; i++) { +if (likely (pkts[i]->port == in_port)) +continue ; + ret =process_burst (in_port, out, pkts + start, i - start); +if (ret <0 ) +return ret;/* stop on file write error */ -rte_pktmbuf_free_bulk (pkts, n); + start = i; + in_port = pkts[i]->port; + } -if (written <0 ) -return -1 ; + ret =process_burst (in_port, out, pkts + start, n - start); +if (ret <0 ) +return ret; - file_size += written; - packets_received += n;if (!quiet)show_count (packets_received);
@@ -971,15 +1165,18 @@ static int process_ring(dumpcap_out_t out, struct rte_ring *r)int main (int argc,char **argv) { -struct rte_ring *r;struct rte_mempool *mp;struct sigaction action = { .sa_flags =SA_RESTART , .sa_handler = signal_handler, };struct sigaction origaction; +struct rte_ring *ring =NULL ; +char vdev_name[RTE_DEV_NAME_MAX_LEN ]; +uint16_t mirror_port =UINT16_MAX ;dumpcap_out_t out;char *p; +int ret; p =strrchr (argv[0 ],'/' );if (p ==NULL )
@@ -1018,12 +1215,19 @@ int main(int argc, char **argv)exit (0 ); } - r =create_ring (); mp =create_mempool (); + ring =create_ring_dev (vdev_name, &mirror_port); out =create_output (); + ret =enable_mirror (mirror_port, mp); +if (ret <0 ) + goto cleanup; + +setup_mbuf (); + +show_capturing (ret); + start_time =time (NULL ); -enable_pdump (r, mp);if (!quiet) {fprintf (stderr,"Packets captured: " );
@@ -1031,7 +1235,7 @@ int main(int argc, char **argv) }while (!rte_atomic_load_explicit (&quit_signal, rte_memory_order_relaxed)) { -if (process_ring (out, r) <0 ) { +if (process_ring (out, ring) <0 ) {fprintf (stderr,"pcapng file write failed; %s\n" ,strerror (errno));break ;
@@ -1048,19 +1252,20 @@ int main(int argc, char **argv)break ; } -disable_primary_monitor (); -if (rte_eal_primary_proc_alive (NULL ))report_packet_stats (out); +cleanup:if (use_pcapng)rte_pcapng_close (out.pcapng);else pcap_dump_close (out.dumper); -cleanup_pdump_resources (); +disable_primary_monitor (); +disable_mirror_ports (); -rte_ring_free (r); +rte_eal_hotplug_remove ("vdev" , vdev_name); +rte_ring_free (ring);rte_mempool_free (mp);return rte_eal_cleanup () ?EXIT_FAILURE :0 ;
app/dumpcap/meson.build +1 -1
@@ -14,4 +14,4 @@ endif ext_deps += pcap_dep sources = files('main.c') -deps += ['ethdev', 'pdump', 'pcapng', 'bpf'] +deps += ['net_ring', 'ethdev', 'pcapng', 'bpf']
Signature · 1 line
2.47.2
Quoted 14 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Saturday, 12 April 2025 01.45This is a rework of how packet capture is done in DPDK. The existing mechanism using callbacks has a number of problems; the main one is that any packets sent/received in a secondary process are not visible. The root cause is that callbacks can not function across process boundaries, they are specific to the role.
The new mechanism builds on the concept of port mirroring used in Linux/FreeBSD and also router vendors (SPAN ports). The infrastructure
is built around a new ethdev call to mirror a port.
Quoted 8 lines
The internals of dumpcap are redone but the program command syntax is unchanged (no doc change needed). Usingthe new mirror mechanism,
the dumpcap program creates a port using ring PMD and then directs mirror to that. Then the packets are extracted from the ring.
If capturing on multiple devices, they all get mirrored to the same ring PMD.
Here's some general feedback...
I very much like the concept of using a shared ring for carrying the mirrored packets.
It allows other types of future consumers to process the mirrored packets, e.g. encapsulating and forwarding them into an L2 or L3 tunnel, or Wireshark remote capture.
Using a Ring PMD instead of setting up a dedicated ring also has some advantages, such as the ability to set up multiple separate mirror target instances. For performance reasons, we should ensure that a lightweight Ring PMD is available for mirroring, in case the Ring PMD is extended with new features affecting its performance. Or maybe create a new type of mirror/capture virtual PMD. This would allow applications to enqueue packets from non-ethdev interfaces into it.
I'm not convinced you should undo the VLAN offloads when enqueueing a mirror packet... If you do, you should also undo QinQ offloads. Undoing offloads is never going to end. And if you create a dedicated PMD type for carrying mirrored packets, you can ensure that the offload fields remain intact on dequeue.
You should consider sampling and VLAN filtering as typical mirroring features. It would improve the performance if such filtering is done before copying the packets.
PS: I agree with your choice of copying (rather than cloning by refcount) when mirroring the packets.
Quoted 31 lines
Doing this uncovered a bunch of additional missing features and bugs. The first is that test-pmd auto attach introduced in 24.11 breaks this (and it broke old pdump as well) so it is removed.
The dumpcap program needs to be able to start the ring PMD it created but the existing ethdev API is broken when used from secondary process. So fix that.
The mirror API has a restriction that the port being mirrored to must allow
lock free transmit. This is because both rx and tx as well as multiple queues need to go over the same transmit queue. Although it might be possible
to have some complex mapping between multiple ports/queues being mirrored
to multiple transmit queues, that gets to be a lot of overhead in API's and implementation. Fixing the ring and null PMD to allow lockeless transmit is good enough.Added tests for the new features.
The performance has not been measured but the overhead of checking for mirror port is no more that the overhead of looking at the callback list.TODO items:
- need release notes for new features
- more through testing on real hardware
- mark old pdump API and application for deprecation in 25.07 and
removal in 25.11
- more cleanup of patch wording and docs needed.
Quoted 23 lines · On Sat, 12 Apr 2025 13:06:55 +0200 Morten Brørup <[email protected]>…
Quoted 14 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Saturday, 12 April 2025 01.45This is a rework of how packet capture is done in DPDK. The existing mechanism using callbacks has a number of problems; the main one is that any packets sent/received in a secondary process are not visible. The root cause is that callbacks can not function across process boundaries, they are specific to the role.
The new mechanism builds on the concept of port mirroring used in Linux/FreeBSD and also router vendors (SPAN ports). The infrastructure
is built around a new ethdev call to mirror a port.Quoted 8 lines
The internals of dumpcap are redone but the program command syntax is unchanged (no doc change needed). Usingthe new mirror mechanism,
the dumpcap program creates a port using ring PMD and then directs mirror to that. Then the packets are extracted from the ring.
If capturing on multiple devices, they all get mirrored to the same ring PMD.
Quoted 8 lines
Here's some general feedback...
I very much like the concept of using a shared ring for carrying the mirrored packets.
It allows other types of future consumers to process the mirrored packets, e.g. encapsulating and forwarding them into an L2 or L3 tunnel, or Wireshark remote capture.Using a Ring PMD instead of setting up a dedicated ring also has some advantages, such as the ability to set up multiple separate mirror target instances. For performance reasons, we should ensure that a lightweight Ring PMD is available for mirroring, in case the Ring PMD is extended with new features affecting its performance. Or maybe create a new type of mirror/capture virtual PMD. This would allow applications to enqueue packets from non-ethdev interfaces into it.
The new modifications are simple, and do not impact performance of ring PMD. We don't need another PMD for this.
It did uncover some broken API's in ring PMD, but those can be marked deprecated and disappear in some future version.
Quoted 3 lines
I'm not convinced you should undo the VLAN offloads when enqueueing a mirror packet... If you do, you should also undo QinQ offloads. Undoing offloads is never going to end. And if you create a dedicated PMD type for carrying mirrored packets, you can ensure that the offload fields remain intact on dequeue.
VLAN needs to be unoffloaded before filtering and writing to file. Can move that logic to the other end of the ring (i.e in dumpcap).
The issue with filtering is that current DPDK BPF has no way to reference offload meta data. There is a way to do that with Linux kernel BPF (via negative offsets). Looked into doing this in the DPDK BPF, but there are several blockers: not all the offloads are the same, and more importantly the pcap library to build filters (pcap_compile) has some internal issues. The pcap library "knows" when it is build a direct Linux socket filter, versus just class BPF. For example, if you call pcap_compile() with "vlan 13", it will generate different code based on whether it is a Linux filter or not.
Quoted 2 lines
You should consider sampling and VLAN filtering as typical mirroring features. It would improve the performance if such filtering is done before copying the packets.
The problem is that filtering before going into the ring leads to creating BPF dependency inside ethdev which is a build nightmare. Tried it and was not successful.
Quoted 2 lines
PS: I agree with your choice of copying (rather than cloning by refcount) when mirroring the packets.
Quoted 45 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Saturday, 12 April 2025 19.05Quoted 6 lines · On Sat, 12 Apr 2025 13:06:55 +0200 Morten Brørup <[email protected]>…
Quoted 6 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Saturday, 12 April 2025 01.45This is a rework of how packet capture is done in DPDK. The existing mechanism using callbacks has a number of problems; the main one is that any packets sent/received in a secondary
process
Quoted 8 lines
Quoted 8 lines
are not visible. The root cause is that callbacks can not function across process boundaries, they are specific to the role.
The new mechanism builds on the concept of port mirroring used in Linux/FreeBSD and also router vendors (SPAN ports). The infrastructure
is built around a new ethdev call to mirror a port.Quoted 5 lines
Quoted 5 lines
The internals of dumpcap are redone but the program command syntax is unchanged (no doc change needed). Usingthe new mirror mechanism,
the dumpcap program creates a port using ring PMD and then directs mirror to that. Then the packets are extracted fromthe
Quoted 7 lines
Quoted 3 lines
ring.
If capturing on multiple devices, they all get mirrored to the same ring PMD.Here's some general feedback...
I very much like the concept of using a shared ring for carrying the
mirrored packets.
Quoted 1 line
It allows other types of future consumers to process the mirrored
packets, e.g. encapsulating and forwarding them into an L2 or L3 tunnel, or Wireshark remote capture.
Quoted 2 lines
Using a Ring PMD instead of setting up a dedicated ring also has some
advantages, such as the ability to set up multiple separate mirror target instances.
Quoted 1 line
For performance reasons, we should ensure that a lightweight Ring PMD
is available for mirroring, in case the Ring PMD is extended with new features affecting its performance.
Quoted 7 lines
Quoted 1 line
Or maybe create a new type of mirror/capture virtual PMD. This would
allow applications to enqueue packets from non-ethdev interfaces into it.
The new modifications are simple, and do not impact performance of ring PMD.
We don't need another PMD for this.
Agree; so long as the Ring PMD remains lightweight.
The Ring PMD sets the mbuf "port" field on RX, thereby overwriting the port of the mirrored packet.
Instead of adding a new mbuf field for the mirrored packet to hold the original port, you could add a "transparent" configuration option to the Ring PMD, so it doesn’t touch the transported mbuf. Furthermore, not setting the mbuf "port" field would significantly improve performance of the Ring PMD; this is the only mbuf field written by the Ring PMD, so a memory write operation per packet is eliminated.
Metadata added to the mirrored packet, e.g. the egress port (for packets mirrored at egress) and maybe the queue_id and a timestamp (of the time of mirroring), could be stored in a dedicated dynfield or in a prepended header (as you already mentioned). Prepending a header also works if there are no more dynfields available. Especially if we add a lot of metadata. I think a prepended header is more future proof.
Hmm... if the "port" field is also stored in the metadata, my suggested Ring PMD "transparent" option becomes a performance optimization only.
Quoted 3 lines
It did uncover some broken API's in ring PMD, but those can be marked deprecated
and disappear in some future version.
+1
Quoted 10 lines
Quoted 3 lines
I'm not convinced you should undo the VLAN offloads when enqueueing a
mirror packet... If you do, you should also undo QinQ offloads. Undoing offloads is never going to end.
Quoted 1 line
And if you create a dedicated PMD type for carrying mirrored packets,
you can ensure that the offload fields remain intact on dequeue.
VLAN needs to be unoffloaded before filtering and writing to file. Can move that logic to the other end of the ring (i.e in dumpcap).
If the application at the dequeueing end of the ring is not dumpcap, but some other application, this other application might prefer getting the mbufs as raw as possible. I think moving the unoffloading logic to the dequeueing end of the ring would be better.
BTW, unoffloading should probably be a public DPDK library function, to avoid copy-pasting it from dumpcap to other applications.
Quoted 17 lines
The issue with filtering is that current DPDK BPF has no way to reference offload
meta data. There is a way to do that with Linux kernel BPF (via negative offsets).
Looked into doing this in the DPDK BPF, but there are several blockers:
not all
the offloads are the same, and more importantly the pcap library to build filters
(pcap_compile) has some internal issues. The pcap library "knows" when it is
build a direct Linux socket filter, versus just class BPF. For example, if you callpcap_compile()with "vlan 13", it will generate different code
based on whether it is a Linux filter or not.Quoted 1 line
You should consider sampling and VLAN filtering as typical mirroring
Quoted 8 lines
features.
Quoted 1 line
It would improve the performance if such filtering is done before
copying the packets.
The problem is that filtering before going into the ring leads to creating BPF
dependency inside ethdev which is a build nightmare. Tried it and was not successful.
Filtering before going into the ring is only a performance optimization.
Full BPF would be nice, but apparently not doable.
VLAN filtering (mirroring one interesting VLAN only) and sampling (to reduce the traffic volume) is common for port mirroring. Perhaps just offer this limited pre-filtering as a performance optimization. Full BPF remains in dumpcap. Anyway, limited pre-filtering can be added later; just keep it in mind for API design purposes.
If VLAN pre-filtering is added to the enqueueing end of the ring, it obviously needs to parse the mbuf/packet to obtain the VLAN; but I still think it should not modify the packet, i.e. unoffloading the VLAN tag still belongs in the dequeueing end of the ring.
Another thought (more feature creep)...
It would be "nice to have" the ability to attach multiple mirrors to a port.
E.g. if an application uses the mirror feature for its own purposes, dumpcap can still attach its own mirror to ports already being mirrored by the application.
Quoted 4 lines
Quoted 3 lines
PS: I agree with your choice of copying (rather than cloning by
refcount) when mirroring the packets.
v4 cover Packet capture using port mirroring
In reply to Stephen HemmingerThis is a rework of how packet capture is done in DPDK.
The existing mechanism using callbacks has a number of problems:
it won't work when packets are sent and received in secondary process because callbacks only function in the primary process; pdump requires that the main program "opt-in" to having packet capture which requires changes to existing network appliances.
The new mechanism builds on the concept of port mirroring used in Linux/FreeBSD and also router vendors (SPAN ports).
See: https://en.wikipedia.org/wiki/Port_mirroring for a general description.
The implementation uses two new ethdev API's one to add a port mirror, and one to remove it.
The internals of dumpcap are redone but the program command syntax is unchanged (no doc change needed). Using the new mirror mechanism, the dumpcap program creates a port using ring PMD and
then directs a port mirror to that new ring PMD instance.
Then the packets are extracted from the ring.
If capturing on multiple devices, they all get mirrored to
the same ring PMD.
The dumpcap program needs to be able to start the ring PMD it created but the existing ethdev API is broken when used from secondary process. One of the patches fixes that, it was also reported previously in Bugzilla.
The mirror API has a restriction that the port being mirrored to must allow lock free transmit. This is because both Rx and Tx as well as multiple queues need to go over the same transmit queue. Although it might be possible to have some complex mapping between multiple ports/queues being mirrored to multiple transmit queues, that gets to be a lot of overhead in API's and implementation. Fixing the ring and null PMD to allow lockless transmit is good enough.
Added tests for the new features.
The performance has not been measured but the overhead of checking for mirror port is no more that the overhead of looking at the callback list.
TODO items:
- some names are too verbose
- need release notes for new features
- more through testing on real hardware
v4 - add headers need in some build enviroments
- don't need ring pmd to timestamp
Stephen Hemminger (13):
ethdev: allow start/stop from secondary process
ethdev: make sure all necessary headers included
test: add test for hotplug and secondary process operations net/ring: allow lockfree transmit if ring supports it net/ring: add new devarg to create vdev from existing ring
mbuf: add dynamic flag for use by port mirroring
ethdev: add port mirroring feature
pcapng: split packet copy from header insertion
pcapng: make queue optional
test: add tests for ethdev mirror
app/testpmd: support for port mirroring app/dumpcap: use port mirror instead of pdump
pdump: mark API and application as deprecated
app/dumpcap/main.c | 443 ++++++++++++++++---- app/dumpcap/meson.build | 2 +- app/pdump/main.c | 3 + app/pdump/meson.build | 1 + app/test-pmd/cmdline.c | 1 + app/test-pmd/cmdline_mirror.c | 129 ++++++ app/test-pmd/cmdline_mirror.h | 12 + app/test-pmd/meson.build | 2 + app/test/meson.build | 7 +- app/test/test_ethdev_mirror.c | 285 +++++++++++++ app/test/test_mp_secondary.c | 51 ++- config/rte_config.h | 1 + doc/guides/rel_notes/deprecation.rst | 3 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 15 + drivers/net/ring/rte_eth_ring.c | 47 +++ lib/ethdev/ethdev_driver.c | 11 +- lib/ethdev/ethdev_driver.h | 6 + lib/ethdev/ethdev_private.c | 142 +++++++ lib/ethdev/ethdev_private.h | 29 ++ lib/ethdev/ethdev_trace.h | 17 + lib/ethdev/ethdev_trace_points.c | 6 + lib/ethdev/meson.build | 1 + lib/ethdev/rte_ethdev.c | 101 +++-- lib/ethdev/rte_ethdev.h | 23 +- lib/ethdev/rte_ethdev_core.h | 6 +- lib/ethdev/rte_mirror.c | 348 +++++++++++++++ lib/ethdev/rte_mirror.h | 113 +++++ lib/mbuf/rte_mbuf_dyn.h | 9 + lib/pcapng/rte_pcapng.c | 179 ++++---- lib/pcapng/rte_pcapng.h | 27 +- lib/pdump/rte_pdump.h | 12 +- 31 files changed, 1822 insertions(+), 210 deletions(-) create mode 100644 app/test-pmd/cmdline_mirror.c create mode 100644 app/test-pmd/cmdline_mirror.h create mode 100644 app/test/test_ethdev_mirror.c create mode 100644 lib/ethdev/rte_mirror.c create mode 100644 lib/ethdev/rte_mirror.h
Signature · 1 line
2.47.2
PATCH v4 1/13 ethdev: allow start/stop from secondary process
Before this patch if secondary process called start/stop it would only impact the secondary process, the ethdev on the primary process was not started.
With this patch, when start/stop is called from secondary, it calls the primary and does the operation there. The design is generic, and we can later add queue and other operations as needed.
Bugzilla ID: 73
--- lib/ethdev/ethdev_driver.c | 11 ++++- lib/ethdev/ethdev_private.c | 93 +++++++++++++++++++++++++++++++++++++ lib/ethdev/ethdev_private.h | 26 +++++++++++ lib/ethdev/rte_ethdev.c | 84 +++++++++++++++++++-------------- 4 files changed, 177 insertions(+), 37 deletions(-)
lib/ethdev/ethdev_driver.c +10 -1
@@ -114,6 +114,14 @@ rte_eth_dev_allocate(const char *name) goto unlock; } +if (eth_dev_shared_data->allocated_ports ==0 && +rte_mp_action_register (ETHDEV_MP , ethdev_server) && + rte_errno !=ENOTSUP ) { +RTE_ETHDEV_LOG_LINE (ERR , +"Could not start %s service" ,ETHDEV_MP ); + goto unlock; + } + eth_dev =eth_dev_get (port_id); eth_dev->flow_fp_ops = &rte_flow_fp_default_ops;strlcpy (eth_dev->data->name, name,sizeof (eth_dev->data->name));
@@ -282,7 +290,8 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)memset (eth_dev->data,0 ,sizeof (struct rte_eth_dev_data )); eth_dev->data =NULL ; - eth_dev_shared_data->allocated_ports--; +if (--eth_dev_shared_data->allocated_ports ==0 ) +rte_mp_action_unregister (ETHDEV_MP );eth_dev_shared_data_release (); }
lib/ethdev/ethdev_private.c +93 -0
102 lines not on this page · raw message
lib/ethdev/ethdev_private.h +26 -0
@@ -79,4 +79,30 @@ void eth_dev_txq_release(struct rte_eth_dev *dev, uint16_t qid);int eth_dev_rx_queue_config (struct rte_eth_dev *dev,uint16_t nb_queues);int eth_dev_tx_queue_config (struct rte_eth_dev *dev,uint16_t nb_queues); +/* Used to allow start/stop from secondary */ +#define ETHDEV_MP "mp_ethdev" + +enum ethdev_mp_operation { +ETH_REQ_START , +ETH_REQ_STOP , +}; + +struct ethdev_mp_request { +uint16_t operation; +uint16_t port_id; +uint32_t reserved; + +uint8_t config[];/* operation specific */ +}; + +struct ethdev_mp_response { +uint16_t res_op; +uint16_t port_id; +int32_t err_value; +}; + +int ethdev_server (const struct rte_mp_msg *mp_msg,const void *peer); +int ethdev_request (uint16_t port_id,enum ethdev_mp_operation op, +const void *buf,size_t buf_len); +#endif /* _ETH_PRIVATE_H_ */
lib/ethdev/rte_ethdev.c +48 -36
111 lines not on this page · raw message
Signature · 1 line
2.47.2
PATCH v4 2/13 ethdev: make sure all necessary headers included
In reply to Stephen HemmingerBest not to depend on other EAL headers to include stuff. Some of the later changes had build failures on some platforms.
--- lib/ethdev/ethdev_private.c | 9 +++++++++ 1 file changed, 9 insertions(+)
lib/ethdev/ethdev_private.c +9 -0
@@ -3,9 +3,18 @@*/ #include <assert.h> +#include <errno.h> +#include <inttypes.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <time.h> #include <eal_export.h> #include <rte_debug.h> +#include <rte_eal.h> +#include <rte_lcore.h> +#include <rte_stdatomic.h> #include "rte_ethdev.h" #include "rte_ethdev_trace_fp.h"
Signature · 1 line
2.47.2
PATCH v4 3/13 test: add test for hotplug and secondary process operations
In reply to Stephen HemmingerUse null device to exercise ethdev start/stop in secondary process.
--- app/test/test_mp_secondary.c | 51 +++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-)
app/test/test_mp_secondary.c +48 -3
@@ -15,6 +15,9 @@#include <string.h> #include <unistd.h> +#include <rte_ethdev.h> +#include <rte_bus_vdev.h> +#ifdef RTE_EXEC_ENV_WINDOWS int test_mp_secondary (void )
@@ -204,6 +207,44 @@ run_object_creation_tests(void)return 0 ; } +static int +run_ethdev_tests (void ) +{ +char vdev_name[] ="net_null" ; +struct rte_eth_conf dev_conf = {0 }; +uint16_t port; +int ret; + +printf ("### Testing hotplug and ethdev start/stop\n" ); + +/* use hotplug to make a null vdev */ + ret =rte_eal_hotplug_add ("vdev" , vdev_name,"" ); +TEST_ASSERT (ret ==0 ,"Hotplug add of '%s' failed" , vdev_name); + +printf ("# Checked hotlug_add OK\n" ); + + ret =rte_eth_dev_get_port_by_name (vdev_name, &port); +TEST_ASSERT (ret ==0 ,"Lookup vdev '%s' failed" , vdev_name); + + ret =rte_eth_dev_configure (port,1 ,1 , &dev_conf); +TEST_ASSERT (ret ==0 ,"Configure port %u failed" , port); + + ret =rte_eth_dev_start (port); +TEST_ASSERT (ret ==0 ,"Start port %u failed" , port); + +printf ("# Checked rte_eth_dev_start\n" ); + + ret =rte_eth_dev_stop (port); +TEST_ASSERT (ret ==0 ,"Stop port %u failed" , port); + +printf ("# Checked rte_eth_dev_stop\n" ); + +rte_eal_hotplug_remove ("vdev" , vdev_name); + +printf ("# Checked hotlug_remove OK\n" ); +return 0 ; +} +/* if called in a primary process, just spawns off a secondary process to * run validation tests - which brings us right back here again... * if called in a secondary process, this runs a series of API tests to check
@@ -212,15 +253,19 @@ run_object_creation_tests(void)int test_mp_secondary (void ) { -if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) { +int ret; + +if (rte_eal_process_type () ==RTE_PROC_PRIMARY )return run_secondary_instances (); - }printf ("IN SECONDARY PROCESS\n" ); + ret =run_ethdev_tests (); +if (ret !=0 ) +return ret;return run_object_creation_tests (); }#endif /* !RTE_EXEC_ENV_WINDOWS */ -REGISTER_FAST_TEST (multiprocess_autotest, false, false, test_mp_secondary); +REGISTER_FAST_TEST (multiprocess_autotest, true, true, test_mp_secondary);
Signature · 1 line
2.47.2
PATCH v4 4/13 net/ring: allow lockfree transmit if ring supports it
In reply to Stephen HemmingerNeed to be able have multiple threads all using same transmit queue when using SPAN.
--- drivers/net/ring/rte_eth_ring.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/net/ring/rte_eth_ring.c +17 -0
@@ -177,6 +177,19 @@ eth_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,return 0 ; } +static bool +eth_tx_queue_lockfree (const struct pmd_internals *internals) +{ +unsigned int i; + +for (i =0 ; i < internals->max_tx_queues; i++) { +const struct ring_queue *r = &internals->tx_ring_queues[i]; + +if (r->rng->flags &RING_F_SP_ENQ ) +return false; + } +return true; +} static int eth_dev_info(struct rte_eth_dev *dev,
@@ -189,6 +202,10 @@ eth_dev_info(struct rte_eth_dev *dev, dev_info->max_rx_queues = (uint16_t )internals->max_rx_queues; dev_info->rx_offload_capa =RTE_ETH_RX_OFFLOAD_SCATTER ; dev_info->tx_offload_capa =RTE_ETH_TX_OFFLOAD_MULTI_SEGS ; + +if (eth_tx_queue_lockfree (internals)) + dev_info->tx_offload_capa |=RTE_ETH_TX_OFFLOAD_MT_LOCKFREE ; + dev_info->max_tx_queues = (uint16_t )internals->max_tx_queues; dev_info->min_rx_bufsize =0 ;
Signature · 1 line
2.47.2
PATCH v4 5/13 net/ring: add new devarg to create vdev from existing ring
In reply to Stephen HemmingerNeed ability to allow process like dumpcap to make a ring ethdev with a pre-existing ring. Do this via devargs so it can work with hotplug.
It looked like the API rte_eth_from_ring() would work for this, but it doesn't do the right thing. That API makes new vdev but names the ring based on the parameter.
--- drivers/net/ring/rte_eth_ring.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
drivers/net/ring/rte_eth_ring.c +30 -0
@@ -23,9 +23,12 @@#define ETH_RING_INTERNAL_ARG "internal"#define ETH_RING_INTERNAL_ARG_MAX_LEN 19/* "0x..16chars..\0" */ +#define ETH_RING_RING_ARG "ring" +static const char *valid_arguments[] = {ETH_RING_NUMA_NODE_ACTION_ARG ,ETH_RING_INTERNAL_ARG , +ETH_RING_RING_ARG ,NULL };
@@ -693,6 +696,20 @@ parse_internal_args(const char *key __rte_unused, const char *value,return 0 ; } +static int +parse_ring_arg(const char *key __rte_unused, const char *value, void *data) +{ +struct rte_ring **rp = data; + + *rp =rte_ring_lookup (value); +if (*rp ==NULL ) { +PMD_LOG (ERR ,"ring '%s' not found" , value); +return -1 ; + } + +return 0 ; +} +static int rte_pmd_ring_probe (struct rte_vdev_device *dev) {
@@ -770,6 +787,18 @@ rte_pmd_ring_probe(struct rte_vdev_device *dev) ð_dev);if (ret >=0 ) ret =0 ; + }else if (rte_kvargs_count (kvlist,ETH_RING_RING_ARG ) ==1 ) { +struct rte_ring *rxtx[1 ] = { }; + + ret =rte_kvargs_process (kvlist,ETH_RING_RING_ARG , parse_ring_arg, rxtx); +if (ret <0 ) + goto out_free; + +/* Note: rte_eth_from_ring() does not do what is expected here! */ + ret =do_eth_dev_ring_create (name, dev, rxtx,1 , rxtx,1 , +rte_socket_id (),DEV_ATTACH , ð_dev); +if (ret <0 ) + goto out_free; }else { ret =rte_kvargs_count (kvlist,ETH_RING_NUMA_NODE_ACTION_ARG ); info = rte_zmalloc("struct node_action_list",
@@ -843,4 +872,5 @@ static struct rte_vdev_driver pmd_ring_drv = {RTE_PMD_REGISTER_VDEV (net_ring, pmd_ring_drv);RTE_PMD_REGISTER_ALIAS (net_ring, eth_ring);RTE_PMD_REGISTER_PARAM_STRING (net_ring, +ETH_RING_RING_ARG "=<string> " ETH_RING_NUMA_NODE_ACTION_ARG "=name:node:action(ATTACH|CREATE)" );
Signature · 1 line
2.47.2
PATCH v4 6/13 mbuf: add dynamic flag for use by port mirroring
In reply to Stephen HemmingerAdd names for new port mirror fields.
--- lib/mbuf/rte_mbuf_dyn.h | 9 +++++++++ 1 file changed, 9 insertions(+)
lib/mbuf/rte_mbuf_dyn.h +9 -0
@@ -327,6 +327,15 @@ int rte_mbuf_dyn_tx_timestamp_register(int *field_offset, uint64_t *tx_flag);#define RTE_MBUF_DYNFIELD_IP_REASSEMBLY_NAME "rte_dynfield_ip_reassembly"#define RTE_MBUF_DYNFLAG_IP_REASSEMBLY_INCOMPLETE_NAME "rte_dynflag_ip_reassembly_incomplete" +/** +* The ethdev port mirror needs some extra packet information that +* includes information about the packet before it was copied to the mirror. +*/ +#define RTE_MBUF_DYNFIELD_MIRROR_ORIGIN "rte_dynfield_mirror_origin" +#define RTE_MBUF_DYNFLAG_MIRROR_ORIGIN "rte_dynflag_mirror_origin" +#define RTE_MBUF_DYNFLAG_MIRROR_INGRESS "rte_dynflag_mirror_ingress" +#define RTE_MBUF_DYNFLAG_MIRROR_EGRESS "rte_dynflag_mirror_egress" + #ifdef __cplusplus }#endif
Signature · 1 line
2.47.2
PATCH v4 7/13 ethdev: add port mirroring feature
In reply to Stephen HemmingerThis adds new feature port mirroring to the ethdev layer.
--- config/rte_config.h | 1 + lib/ethdev/ethdev_driver.h | 6 + lib/ethdev/ethdev_private.c | 58 +++++- lib/ethdev/ethdev_private.h | 3 + lib/ethdev/ethdev_trace.h | 17 ++ lib/ethdev/ethdev_trace_points.c | 6 + lib/ethdev/meson.build | 1 + lib/ethdev/rte_ethdev.c | 17 +- lib/ethdev/rte_ethdev.h | 23 +- lib/ethdev/rte_ethdev_core.h | 6 +- lib/ethdev/rte_mirror.c | 348 +++++++++++++++++++++++++++++++ lib/ethdev/rte_mirror.h | 113 ++++++++++ 12 files changed, 581 insertions(+), 18 deletions(-) create mode 100644 lib/ethdev/rte_mirror.c create mode 100644 lib/ethdev/rte_mirror.h
config/rte_config.h +1 -0
@@ -69,6 +69,7 @@#define RTE_MAX_QUEUES_PER_PORT 1024#define RTE_ETHDEV_QUEUE_STAT_CNTRS 16/* max 256 */ #define RTE_ETHDEV_RXTX_CALLBACKS 1 +#define RTE_ETHDEV_MIRROR 1#define RTE_MAX_MULTI_HOST_CTRLS 4/* cryptodev defines */
lib/ethdev/ethdev_driver.h +6 -0
@@ -85,12 +85,18 @@ struct __rte_cache_aligned rte_eth_dev {* received packets before passing them to the user */ RTE_ATOMIC (struct rte_eth_rxtx_callback *) post_rx_burst_cbs[RTE_MAX_QUEUES_PER_PORT ]; + +/** Receive mirrors */ +RTE_ATOMIC (struct rte_eth_mirror *) rx_mirror;/** * User-supplied functions called from tx_burst to pre-process * received packets before passing them to the driver for transmission */ RTE_ATOMIC (struct rte_eth_rxtx_callback *) pre_tx_burst_cbs[RTE_MAX_QUEUES_PER_PORT ]; +/** Transmit mirrors */ +RTE_ATOMIC (struct rte_eth_mirror *) tx_mirror; +enum rte_eth_dev_state state;/**< Flag indicating the port state */ void *security_ctx;/**< Context for security ops */ };
lib/ethdev/ethdev_private.c +49 -9
95 lines not on this page · raw message
lib/ethdev/ethdev_private.h +3 -0
@@ -85,6 +85,9 @@ int eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues);enum ethdev_mp_operation {ETH_REQ_START ,ETH_REQ_STOP , +ETH_REQ_RESET , +ETH_REQ_ADD_MIRROR , +ETH_REQ_REMOVE_MIRROR , };struct ethdev_mp_request {
lib/ethdev/ethdev_trace.h +17 -0
@@ -1035,6 +1035,23 @@ RTE_TRACE_POINT(rte_trace_point_emit_int (ret); ) +RTE_TRACE_POINT ( + rte_eth_trace_add_mirror, + RTE_TRACE_POINT_ARGS(uint16_t port_id, + const struct rte_eth_mirror_conf *conf, int ret), + rte_trace_point_emit_u16(port_id); +rte_trace_point_emit_u16 (conf->target); +rte_trace_point_emit_int (ret); +) + +RTE_TRACE_POINT ( + rte_eth_trace_remove_mirror, + RTE_TRACE_POINT_ARGS(uint16_t port_id, uint16_t target_id, int ret), + rte_trace_point_emit_u16(port_id); +rte_trace_point_emit_u16 (target_id); +rte_trace_point_emit_int (ret); +) + RTE_TRACE_POINT( rte_eth_trace_rx_queue_info_get, RTE_TRACE_POINT_ARGS(uint16_t port_id, uint16_t queue_id,
lib/ethdev/ethdev_trace_points.c +6 -0
@@ -389,6 +389,12 @@ RTE_TRACE_POINT_REGISTER(rte_eth_trace_remove_rx_callback,RTE_TRACE_POINT_REGISTER (rte_eth_trace_remove_tx_callback, lib.ethdev.remove_tx_callback) +RTE_TRACE_POINT_REGISTER (rte_eth_trace_add_mirror, + lib.ethdev.add_mirror) + +RTE_TRACE_POINT_REGISTER (rte_eth_trace_remove_mirror, + lib.ethdev.remove_mirror) +RTE_TRACE_POINT_REGISTER (rte_eth_trace_rx_queue_info_get, lib.ethdev.rx_queue_info_get)
lib/ethdev/meson.build +1 -0
@@ -11,6 +11,7 @@ sources = files( 'rte_ethdev_cman.c', 'rte_ethdev_telemetry.c', 'rte_flow.c', + 'rte_mirror.c', 'rte_mtr.c', 'rte_tm.c', 'sff_telemetry.c',
lib/ethdev/rte_ethdev.c +11 -6
@@ -14,6 +14,8 @@#include <bus_driver.h> #include <eal_export.h> #include <rte_log.h> +#include <rte_cycles.h> +#include <rte_alarm.h> #include <rte_interrupts.h> #include <rte_kvargs.h> #include <rte_memcpy.h>
@@ -2041,13 +2043,16 @@ rte_eth_dev_reset(uint16_t port_id)if (dev->dev_ops->dev_reset ==NULL )return -ENOTSUP ; - ret =rte_eth_dev_stop (port_id); -if (ret !=0 ) { -RTE_ETHDEV_LOG_LINE (ERR , -"Failed to stop device (port %u) before reset: %s - ignore" , - port_id,rte_strerror (-ret)); +if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) { + ret =rte_eth_dev_stop (port_id); +if (ret !=0 ) +RTE_ETHDEV_LOG_LINE (ERR , +"Failed to stop device (port %u) before reset: %s - ignore" , + port_id,rte_strerror (-ret)); + ret =eth_err (port_id, dev->dev_ops->dev_reset (dev)); + }else { + ret =ethdev_request (port_id,ETH_REQ_STOP ,NULL ,0 ); } - ret =eth_err (port_id, dev->dev_ops->dev_reset (dev));rte_ethdev_trace_reset (port_id, ret);
lib/ethdev/rte_ethdev.h +22 -1
@@ -170,6 +170,7 @@#include "rte_ethdev_trace_fp.h" #include "rte_dev_info.h" +#include "rte_mirror.h" #ifdef __cplusplusextern "C" {
@@ -1466,7 +1467,6 @@ enum rte_eth_tunnel_type { RTE_ETH_TUNNEL_TYPE_ECPRI, RTE_ETH_TUNNEL_TYPE_MAX, }; -#ifdef __cplusplus }#endif
@@ -6334,6 +6334,17 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t queue_id, nb_rx = p->rx_pkt_burst (qd, rx_pkts, nb_pkts); +#ifdef RTE_ETHDEV_MIRROR + { +const struct rte_eth_mirror *mirror + =rte_atomic_load_explicit (p->rx_mirror, rte_memory_order_relaxed); + +if (unlikely (mirror !=NULL )) +rte_eth_mirror_burst (port_id, queue_id,RTE_ETH_MIRROR_DIRECTION_INGRESS , + rx_pkts, nb_rx, mirror); + } +#endif +#ifdef RTE_ETHDEV_RXTX_CALLBACKS {void *cb;
@@ -6692,6 +6703,16 @@ rte_eth_tx_burst(uint16_t port_id, uint16_t queue_id, }#endif +#ifdef RTE_ETHDEV_MIRROR + { +const struct rte_eth_mirror *mirror; + + mirror =rte_atomic_load_explicit (p->tx_mirror, rte_memory_order_relaxed); +if (unlikely (mirror !=NULL )) +rte_eth_mirror_burst (port_id, queue_id,RTE_ETH_MIRROR_DIRECTION_EGRESS , + tx_pkts, nb_pkts, mirror); + } +#endif nb_pkts = p->tx_pkt_burst (qd, tx_pkts, nb_pkts);rte_ethdev_trace_tx_burst (port_id, queue_id, (void **)tx_pkts, nb_pkts);
lib/ethdev/rte_ethdev_core.h +4 -2
@@ -101,7 +101,8 @@ struct __rte_cache_aligned rte_eth_fp_ops {eth_rx_descriptor_status_t rx_descriptor_status;/** Refill Rx descriptors with the recycling mbufs. */ eth_recycle_rx_descriptors_refill_t recycle_rx_descriptors_refill; -uintptr_t reserved1[2 ]; +uintptr_t reserved1; +RTE_ATOMIC (struct rte_eth_mirror *) *rx_mirror;/**@}*/ /**@{*/
@@ -121,7 +122,8 @@ struct __rte_cache_aligned rte_eth_fp_ops {eth_recycle_tx_mbufs_reuse_t recycle_tx_mbufs_reuse;/** Get the number of used Tx descriptors. */ eth_tx_queue_count_t tx_queue_count; -uintptr_t reserved2[1 ]; +RTE_ATOMIC (struct rte_eth_mirror *) *tx_mirror; +uintptr_t reserved2;/**@}*/ };
lib/ethdev/rte_mirror.c new file +348 -0
348 lines not on this page · raw message
lib/ethdev/rte_mirror.h new file +113 -0
113 lines not on this page · raw message
Signature · 1 line
2.47.2
PATCH v4 8/13 pcapng: split packet copy from header insertion
In reply to Stephen HemmingerIn new model, the packet was already copied, only need to wrap it in pcapng format.
--- lib/pcapng/rte_pcapng.c | 178 +++++++++++++++++++++------------------- lib/pcapng/rte_pcapng.h | 27 +++++- 2 files changed, 120 insertions(+), 85 deletions(-)
lib/pcapng/rte_pcapng.c +95 -83
@@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2019 Microsoft Corporation */
@@ -432,8 +433,24 @@ pcapng_vlan_insert(struct rte_mbuf *m, uint16_t ether_type, uint16_t tci)return 0 ; } +/* pad the packet to 32 bit boundary */ +static inline int +pcapng_mbuf_pad32 (struct rte_mbuf *m) +{ +uint32_t pkt_len =rte_pktmbuf_pkt_len (m); +uint32_t padding =RTE_ALIGN (pkt_len,sizeof (uint32_t )) - pkt_len; + +if (padding >0 ) { +void *tail =rte_pktmbuf_append (m, padding); +if (tail ==NULL ) +return -1 ; +memset (tail,0 , padding); + } +return 0 ; +} +/* -* The mbufs created use the Pcapng standard enhanced packet block. +* The mbufs created use the Pcapng standard enhanced packet block. * * 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
@@ -468,71 +485,28 @@ pcapng_vlan_insert(struct rte_mbuf *m, uint16_t ether_type, uint16_t tci)* | Block Total Length | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ - -/* Make a copy of original mbuf with pcapng header and options */ -RTE_EXPORT_SYMBOL (rte_pcapng_copy) -struct rte_mbuf * -rte_pcapng_copy (uint16_t port_id,uint32_t queue, -const struct rte_mbuf *md, -struct rte_mempool *mp, -uint32_t length, -enum rte_pcapng_direction direction, -const char *comment) +RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pcapng_insert, 25.07) +int +rte_pcapng_insert (struct rte_mbuf *m,uint32_t queue, +enum rte_pcapng_direction direction,uint32_t orig_len, +uint64_t timestamp,const char *comment) {struct pcapng_enhance_packet_block *epb; -uint32_t orig_len, pkt_len, padding, flags; -struct pcapng_option *opt; -uint64_t timestamp; -uint16_t optlen; -struct rte_mbuf *mc; -bool rss_hash; - -#ifdef RTE_LIBRTE_ETHDEV_DEBUG -RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id,NULL ); -#endif - orig_len =rte_pktmbuf_pkt_len (md); +uint32_t pkt_len =rte_pktmbuf_pkt_len (m); +uint32_t flags; -/* Take snapshot of the data */ - mc =rte_pktmbuf_copy (md, mp,0 , length); -if (unlikely (mc ==NULL )) -return NULL ; - -/* Expand any offloaded VLAN information */ -if ((direction ==RTE_PCAPNG_DIRECTION_IN && - (md->ol_flags &RTE_MBUF_F_RX_VLAN_STRIPPED )) || - (direction ==RTE_PCAPNG_DIRECTION_OUT && - (md->ol_flags &RTE_MBUF_F_TX_VLAN ))) { -if (pcapng_vlan_insert (mc,RTE_ETHER_TYPE_VLAN , - md->vlan_tci) !=0 ) - goto fail; - } +if (unlikely (pcapng_mbuf_pad32 (m) <0 )) +return -1 ; -if ((direction ==RTE_PCAPNG_DIRECTION_IN && - (md->ol_flags &RTE_MBUF_F_RX_QINQ_STRIPPED )) || - (direction ==RTE_PCAPNG_DIRECTION_OUT && - (md->ol_flags &RTE_MBUF_F_TX_QINQ ))) { -if (pcapng_vlan_insert (mc,RTE_ETHER_TYPE_QINQ , - md->vlan_tci_outer) !=0 ) - goto fail; - } +uint16_t optlen =pcapng_optlen (sizeof (flags)); -/* record HASH on incoming packets */ - rss_hash = (direction ==RTE_PCAPNG_DIRECTION_IN && - (md->ol_flags &RTE_MBUF_F_RX_RSS_HASH )); +/* make queue optional? */ + optlen +=pcapng_optlen (sizeof (queue)); -/* pad the packet to 32 bit boundary */ - pkt_len =rte_pktmbuf_pkt_len (mc); - padding =RTE_ALIGN (pkt_len,sizeof (uint32_t )) - pkt_len; -if (padding >0 ) { -void *tail =rte_pktmbuf_append (mc, padding); +/* does packet have valid RSS hash to include */ +bool rss_hash = (direction ==RTE_PCAPNG_DIRECTION_IN && + (m->ol_flags &RTE_MBUF_F_RX_RSS_HASH )); -if (tail ==NULL ) - goto fail; -memset (tail,0 , padding); - } - - optlen =pcapng_optlen (sizeof (flags)); - optlen +=pcapng_optlen (sizeof (queue));if (rss_hash) optlen +=pcapng_optlen (sizeof (uint8_t ) +sizeof (uint32_t ));
@@ -540,10 +514,10 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue, optlen +=pcapng_optlen (strlen (comment));/* reserve trailing options and block length */ - opt = (struct pcapng_option *) -rte_pktmbuf_append (mc, optlen +sizeof (uint32_t )); +struct pcapng_option *opt = (struct pcapng_option *) +rte_pktmbuf_append (m, optlen +sizeof (uint32_t ));if (unlikely (opt ==NULL )) - goto fail; +return -1 ;switch (direction) {case RTE_PCAPNG_DIRECTION_IN :
@@ -556,24 +530,20 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue, flags =0 ; } - opt =pcapng_add_option (opt,PCAPNG_EPB_FLAGS , - &flags,sizeof (flags)); - - opt =pcapng_add_option (opt,PCAPNG_EPB_QUEUE , - &queue,sizeof (queue)); + opt =pcapng_add_option (opt,PCAPNG_EPB_FLAGS , &flags,sizeof (flags)); + opt =pcapng_add_option (opt,PCAPNG_EPB_QUEUE , &queue,sizeof (queue));if (rss_hash) {uint8_t hash_opt[5 ]; -/* The algorithm could be something else if -* using rte_flow_action_rss; but the current API does not -* have a way for ethdev to report this on a per-packet basis. +/* The algorithm could be something else but the current API does not +* have a way for to record this on a per-packet basis +* and the PCAPNG hash types don't match the DPDK types. */ hash_opt[0 ] =PCAPNG_HASH_TOEPLITZ ; -memcpy (&hash_opt[1 ], &md->hash.rss,sizeof (uint32_t )); - opt =pcapng_add_option (opt,PCAPNG_EPB_HASH , - &hash_opt,sizeof (hash_opt)); +memcpy (&hash_opt[1 ], &m->hash.rss,sizeof (uint32_t )); + opt =pcapng_add_option (opt,PCAPNG_EPB_HASH , &hash_opt,sizeof (hash_opt)); }if (comment)
@@ -583,19 +553,14 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,/* Note: END_OPT necessary here. Wireshark doesn't do it. */ /* Add PCAPNG packet header */ - epb = (struct pcapng_enhance_packet_block *) -rte_pktmbuf_prepend (mc,sizeof (*epb)); + epb = (struct pcapng_enhance_packet_block *)rte_pktmbuf_prepend (m,sizeof (*epb));if (unlikely (epb ==NULL )) - goto fail; +return -1 ; epb->block_type =PCAPNG_ENHANCED_PACKET_BLOCK ; - epb->block_length =rte_pktmbuf_pkt_len (mc); - -/* Interface index is filled in later during write */ - mc->port = port_id; + epb->block_length =rte_pktmbuf_pkt_len (m); -/* Put timestamp in cycles here - adjust in packet write */ - timestamp =rte_get_tsc_cycles (); +/* Put timestamp in cycles here - adjusted in packet write */ epb->timestamp_hi = timestamp >>32 ; epb->timestamp_lo = (uint32_t )timestamp; epb->capture_length = pkt_len;
@@ -603,9 +568,56 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,/* set trailer of block length */ *(uint32_t *)opt = epb->block_length; +return 0 ; +} + +/* Make a copy of original mbuf with pcapng header and options */ +RTE_EXPORT_SYMBOL (rte_pcapng_copy) +struct rte_mbuf * +rte_pcapng_copy (uint16_t port_id,uint32_t queue, +const struct rte_mbuf *md, +struct rte_mempool *mp, +uint32_t length, +enum rte_pcapng_direction direction, +const char *comment) +{ +uint32_t orig_len =rte_pktmbuf_pkt_len (md); +struct rte_mbuf *mc; -return mc; +#ifdef RTE_LIBRTE_ETHDEV_DEBUG +RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id,NULL ); +#endif + +/* Take snapshot of the data */ + mc =rte_pktmbuf_copy (md, mp,0 , length); +if (unlikely (mc ==NULL )) +return NULL ; + +/* Expand any offloaded VLAN information */ +if ((direction ==RTE_PCAPNG_DIRECTION_IN && + (md->ol_flags &RTE_MBUF_F_RX_VLAN_STRIPPED )) || + (direction ==RTE_PCAPNG_DIRECTION_OUT && + (md->ol_flags &RTE_MBUF_F_TX_VLAN ))) { +if (pcapng_vlan_insert (mc,RTE_ETHER_TYPE_VLAN , + md->vlan_tci) !=0 ) + goto fail; + } + +if ((direction ==RTE_PCAPNG_DIRECTION_IN && + (md->ol_flags &RTE_MBUF_F_RX_QINQ_STRIPPED )) || + (direction ==RTE_PCAPNG_DIRECTION_OUT && + (md->ol_flags &RTE_MBUF_F_TX_QINQ ))) { +if (pcapng_vlan_insert (mc,RTE_ETHER_TYPE_QINQ , + md->vlan_tci_outer) !=0 ) + goto fail; + } + +/* Interface index is filled in later during write */ + mc->port = port_id; +if (likely (rte_pcapng_insert (mc, queue, direction, orig_len, +rte_get_tsc_cycles (), comment) ==0 )) +return mc; fail:rte_pktmbuf_free (mc);return NULL ;
lib/pcapng/rte_pcapng.h +25 -2
@@ -99,7 +99,7 @@ enum rte_pcapng_direction { };/** -* Format an mbuf for writing to file. +* Make a copy of mbuf for writing to file. * * @param port_id * The Ethernet port on which packet was received
@@ -117,7 +117,7 @@ enum rte_pcapng_direction {* @param direction * The direction of the packer: receive, transmit or unknown. * @param comment -* Packet comment. +* Packet comment (optional). * * @return * - The pointer to the new mbuf formatted for pcapng_write
@@ -129,6 +129,29 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,uint32_t length, enum rte_pcapng_direction direction, const char *comment); +/** +* Format an mbuf for writing to file. +* +* @param m +* The mbuf to modify. +* @param queue +* The queue on the Ethernet port where packet was received +* or is going to be transmitted. +* @param direction +* The direction of the packer: receive, transmit or unknown. +* @param orig_len +* The length of the original packet which maybe less than actual +* packet if only a snapshot was captured. +* @param timestamp +* The timestamp for packet in TSC cycles. +* @param comment +* Packet comment (optional). +*/ +__rte_experimental +int +rte_pcapng_insert (struct rte_mbuf *m,uint32_t queue, +enum rte_pcapng_direction direction,uint32_t orig_len, +uint64_t timestamp,const char *comment);/** * Determine optimum mbuf data size.
Signature · 1 line
2.47.2
PATCH v4 9/13 pcapng: make queue optional
In reply to Stephen HemmingerThe queue field is optional in pcapng received packet. Use UINT16_MAX as flag value.
--- lib/pcapng/rte_pcapng.c | 7 ++++--- lib/pcapng/rte_pcapng.h | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-)
lib/pcapng/rte_pcapng.c +4 -3
@@ -500,8 +500,8 @@ rte_pcapng_insert(struct rte_mbuf *m, uint32_t queue,uint16_t optlen =pcapng_optlen (sizeof (flags)); -/* make queue optional? */ - optlen +=pcapng_optlen (sizeof (queue)); +if (queue !=UINT16_MAX ) + optlen +=pcapng_optlen (sizeof (queue));/* does packet have valid RSS hash to include */ bool rss_hash = (direction == RTE_PCAPNG_DIRECTION_IN &&
@@ -531,7 +531,8 @@ rte_pcapng_insert(struct rte_mbuf *m, uint32_t queue, } opt =pcapng_add_option (opt,PCAPNG_EPB_FLAGS , &flags,sizeof (flags)); - opt =pcapng_add_option (opt,PCAPNG_EPB_QUEUE , &queue,sizeof (queue)); +if (queue !=UINT16_MAX ) + opt =pcapng_add_option (opt,PCAPNG_EPB_QUEUE , &queue,sizeof (queue));if (rss_hash) {uint8_t hash_opt[5 ];
lib/pcapng/rte_pcapng.h +2 -2
@@ -135,8 +135,8 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,* @param m * The mbuf to modify. * @param queue -* The queue on the Ethernet port where packet was received -* or is going to be transmitted. +* The queue on the Ethernet port where packet was received or is going to be transmitted. +* Optional: use UINT16_MAX if not specified. * @param direction * The direction of the packer: receive, transmit or unknown. * @param orig_len
Signature · 1 line
2.47.2
PATCH v4 10/13 test: add tests for ethdev mirror
In reply to Stephen HemmingerSimple API and packet mirroring standalone tests.
--- app/test/meson.build | 1 + app/test/test_ethdev_mirror.c | 285 ++++++++++++++++++++++++++++++++++ 2 files changed, 286 insertions(+) create mode 100644 app/test/test_ethdev_mirror.c
app/test/meson.build +1 -0
@@ -73,6 +73,7 @@ source_file_deps = { 'test_errno.c': [], 'test_ethdev_api.c': ['ethdev'], 'test_ethdev_link.c': ['ethdev'], + 'test_ethdev_mirror.c': ['net_ring', 'ethdev', 'bus_vdev'], 'test_event_crypto_adapter.c': ['cryptodev', 'eventdev', 'bus_vdev'], 'test_event_dma_adapter.c': ['dmadev', 'eventdev', 'bus_vdev'], 'test_event_eth_rx_adapter.c': ['ethdev', 'eventdev', 'bus_vdev'],
app/test/test_ethdev_mirror.c new file +285 -0
285 lines not on this page · raw message
Signature · 1 line
2.47.2
PATCH v4 11/13 app/testpmd: support for port mirroring
In reply to Stephen HemmingerAdd new commands to enable testing of port mirror functionality.
--- app/test-pmd/cmdline.c | 1 + app/test-pmd/cmdline_mirror.c | 129 ++++++++++++++++++++ app/test-pmd/cmdline_mirror.h | 12 ++ app/test-pmd/meson.build | 1 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 15 +++ 5 files changed, 158 insertions(+) create mode 100644 app/test-pmd/cmdline_mirror.c create mode 100644 app/test-pmd/cmdline_mirror.h
app/test-pmd/cmdline.c +1 -0
@@ -66,6 +66,7 @@#include "testpmd.h" #include "cmdline_cman.h" #include "cmdline_mtr.h" +#include "cmdline_mirror.h" #include "cmdline_tm.h" #include "bpf_cmd.h"
app/test-pmd/cmdline_mirror.c new file +129 -0
129 lines not on this page · raw message
app/test-pmd/cmdline_mirror.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Stephen Hemminger <[email protected]> +*/ + +#ifndef _CMDLINE_MIRROR_H_ +#define _CMDLINE_MIRROR_H_ + +/* Port MIRROR commands */ +extern cmdline_parse_inst_t cmd_create_port_mirror; +extern cmdline_parse_inst_t cmd_disable_port_mirror; + +#endif /* _CMDLINE_MIRROR_H_ */
app/test-pmd/meson.build +1 -0
@@ -8,6 +8,7 @@ sources = files( 'cmdline.c', 'cmdline_cman.c', 'cmdline_flow.c', + 'cmdline_mirror.c', 'cmdline_mtr.c', 'cmdline_tm.c', 'cmd_flex_item.c',
doc/guides/testpmd_app_ug/testpmd_funcs.rst +15 -0
@@ -2570,6 +2570,21 @@ where: * ``clear``: Flag that indicates whether the statistics counters should be cleared (i.e. set to zero) immediately after they have been read or not. +create mirror +------------- + +Create a new MIRROR port for an ethernet device:: + + testpmd> create port mirror (port_id) destination (port_id) + +delete mirror +------------- + +Delete an existing MIRROR port on ethernet device:: + + testpmd> delete port mirror (port_id) + + Traffic Management ------------------
Signature · 1 line
2.47.2
PATCH v4 12/13 app/dumpcap: use port mirror instead of pdump
In reply to Stephen HemmingerUse the new port mirror API instead of pdump.
--- app/dumpcap/main.c | 443 +++++++++++++++++++++++++++++++++------- app/dumpcap/meson.build | 2 +- 2 files changed, 373 insertions(+), 72 deletions(-)
app/dumpcap/main.c +372 -71
@@ -36,8 +36,6 @@#include <rte_mbuf.h> #include <rte_mempool.h> #include <rte_pcapng.h> -#include <rte_pdump.h> -#include <rte_ring.h> #include <rte_string_fns.h> #include <rte_thread.h> #include <rte_time.h>
@@ -92,16 +90,28 @@ struct capture_options {struct interface {TAILQ_ENTRY (interface) next;uint16_t port; +struct rte_bpf *filter; +uint64_t filteraccept;struct capture_options opts; -struct rte_bpf_prm *bpf_prm;char name[RTE_ETH_NAME_MAX_LEN ]; +struct rte_eth_stats start_stats;const char *ifname;const char *ifdescr; }; +static int timestamp_dynfield =-1 ; +static uint64_t timestamp_dynflag; +static int mirror_origin_dynfield =-1 ; +static uint64_t mirror_origin_dynflag; +static uint64_t mirror_ingress_dynflag; +static uint64_t mirror_egress_dynflag; + +static bool filtering; +TAILQ_HEAD (interface_list, interface);static struct interface_list interfaces =TAILQ_HEAD_INITIALIZER (interfaces); +static struct interface *port2intf[RTE_MAX_ETHPORTS ];/* Can do either pcap or pcapng format output */ typedef union {
@@ -239,14 +249,16 @@ static void find_interfaces(void) TAILQ_FOREACH(intf, &interfaces, next) {/* if name is valid then just record port */ -if (rte_eth_dev_get_port_by_name (intf->name, &intf->port) ==0 ) -continue ; +if (rte_eth_dev_get_port_by_name (intf->name, &intf->port) !=0 ) { +/* maybe got passed port number string as name */ + intf->port =get_uint (intf->name,"port_number" ,UINT16_MAX ); +if (rte_eth_dev_get_name_by_port (intf->port, intf->name) <0 ) +rte_exit (EXIT_FAILURE ,"Invalid port number %u\n" , + intf->port); + } -/* maybe got passed port number string as name */ - intf->port =get_uint (intf->name,"port_number" ,UINT16_MAX ); -if (rte_eth_dev_get_name_by_port (intf->port, intf->name) <0 ) -rte_exit (EXIT_FAILURE ,"Invalid port number %u\n" , - intf->port); +if (rte_eth_stats_get (intf->port, &intf->start_stats) <0 ) +rte_exit (EXIT_FAILURE ,"Could not read stats for port %u\n" , intf->port); } }
@@ -266,6 +278,10 @@ static void set_default_interface(void) intf =add_interface (name); intf->port = p; + +if (rte_eth_stats_get (intf->port, &intf->start_stats) <0 ) +rte_exit (EXIT_FAILURE , +"Could not read stats for port %u\n" , intf->port);return ; }rte_exit (EXIT_FAILURE ,"No usable interfaces found\n" );
@@ -295,10 +311,17 @@ static void compile_filters(void)struct bpf_program bf;pcap_t *pcap; +/* cache for filter packets */ + port2intf[intf->port] = intf; + +if (intf->opts.filter ==NULL ) +continue ; + pcap =pcap_open_dead (DLT_EN10MB , intf->opts.snap_len);if (!pcap)rte_exit (EXIT_FAILURE ,"can not open pcap\n" ); +if (pcap_compile (pcap, &bf, intf->opts.filter,1 ,PCAP_NETMASK_UNKNOWN ) !=0 ) { fprintf(stderr,
@@ -316,7 +339,7 @@ static void compile_filters(void) rte_strerror(rte_errno), rte_errno);if (dump_bpf) { -printf ("cBPF program (%u insns)\n" , bf.bf_len); +printf ("cops program (%u insns)\n" , bf.bf_len);bpf_dump (&bf,1 );printf ("\neBPF program (%u insns)\n" , bpf_prm->nb_ins);
@@ -324,11 +347,18 @@ static void compile_filters(void)exit (0 ); } - intf->bpf_prm = bpf_prm; + + intf->filter =rte_bpf_load (bpf_prm); +if (intf->filter ==NULL ) +rte_exit (EXIT_FAILURE , +"BPF load failed '%s'\n%s(%d)\n" , + intf->name,rte_strerror (rte_errno), rte_errno);/* Don't care about original program any more */ pcap_freecode (&bf);pcap_close (pcap); + + filtering = true; } }
@@ -518,13 +548,12 @@ static void statistics_loop(void) }static void -cleanup_pdump_resources (void ) +disable_mirror_ports (uint16_t mirror_port) {struct interface *intf; TAILQ_FOREACH(intf, &interfaces, next) { -rte_pdump_disable (intf->port, -RTE_PDUMP_ALL_QUEUES ,RTE_PDUMP_FLAG_RXTX ); +rte_eth_remove_mirror (intf->port, mirror_port);if (intf->opts.promisc_mode)rte_eth_promiscuous_disable (intf->port); }
@@ -552,7 +581,6 @@ enable_primary_monitor(void) {int ret; -/* Once primary exits, so will pdump. */ ret =rte_eal_alarm_set (MONITOR_INTERVAL , monitor_primary,NULL );if (ret <0 )fprintf (stderr,"Fail to enable monitor:%d\n" , ret);
@@ -571,23 +599,24 @@ disable_primary_monitor(void)static void report_packet_stats (dumpcap_out_t out) { -struct rte_pdump_stats pdump_stats;struct interface *intf; -uint64_t ifrecv, ifdrop; -double percent;fputc ('\n' , stderr); + TAILQ_FOREACH(intf, &interfaces, next) { -if (rte_pdump_stats (intf->port, &pdump_stats) <0 ) +uint64_t ifrecv, ifdrop; +struct rte_eth_stats stats; +double percent; + +if (rte_eth_stats_get (intf->port, &stats) <0 )continue ; -/* do what Wiretap does */ - ifrecv = pdump_stats.accepted + pdump_stats.filtered; - ifdrop = pdump_stats.nombuf + pdump_stats.ringfull; + ifrecv = stats.ipackets - intf->start_stats.ipackets; + ifdrop = (stats.rx_nombuf - intf->start_stats.rx_nombuf) + + (stats.imissed - intf->start_stats.imissed);if (use_pcapng) -rte_pcapng_write_stats (out.pcapng, intf->port, - ifrecv, ifdrop,NULL ); +rte_pcapng_write_stats (out.pcapng, intf->port, ifrecv, ifdrop,NULL );if (ifrecv ==0 ) percent =0 ;
@@ -668,12 +697,21 @@ static void dpdk_init(void)rte_exit (EXIT_FAILURE ,"Can not restore original CPU affinity\n" ); } -/* Create packet ring shared between callbacks and process */ -static struct rte_ring *create_ring (void ) +/* Create ring port to redirect packet to. +* This could be much simpler if the ring PMD API (rte_eth_from_rings) +* worked from a secondary process, but it doesn't. +*/ +static struct rte_ring * +create_ring_dev (char *vdev_name,uint16_t *mirror_port) { -struct rte_ring *ring; +struct rte_eth_dev_owner owner = {0 }; +struct rte_eth_conf dev_conf = {0 }; +struct rte_ring *ring =NULL ;char ring_name[RTE_RING_NAMESIZE ]; +char vdev_args[128 ];size_t size, log2; +uint16_t port; +int ret;/* Find next power of 2 >= size. */ size = ring_size;
@@ -686,17 +724,59 @@ static struct rte_ring *create_ring(void) ring_size = size; } -/* Want one ring per invocation of program */ -snprintf (ring_name,sizeof (ring_name), -"dumpcap-%d" ,getpid ()); +/* Use owner as unique Id for ring and to isolate */ + ret =rte_eth_dev_owner_new (&owner.id); +if (ret <0 ) +rte_exit (EXIT_FAILURE ,"rte_eth_dev_owner_new failed: %s\n" , +strerror (-ret)); - ring =rte_ring_create (ring_name, ring_size, -rte_socket_id (),0 ); +/* Give the vdev a unique name */ +snprintf (ring_name,sizeof (ring_name),"dumpcap%" PRIu64, owner.id); + ring =rte_ring_create (ring_name, ring_size,rte_socket_id (), +RING_F_MP_RTS_ENQ |RING_F_SC_DEQ );if (ring ==NULL )rte_exit (EXIT_FAILURE ,"Could not create ring :%s\n" ,rte_strerror (rte_errno)); +strlcpy (owner.name, ring_name,sizeof (owner.name)); + +snprintf (vdev_name,RTE_DEV_NAME_MAX_LEN ,"net_ring-dumpcap%" PRIu64, owner.id); +snprintf (vdev_args,sizeof (vdev_args),"ring=%s" , ring_name); + +if (rte_eal_hotplug_add ("vdev" , vdev_name, vdev_args) <0 ) +rte_exit (EXIT_FAILURE , +"rte_eal_hotplug_add of %s failed:%s\n" , + vdev_name,rte_strerror (rte_errno)); + + ret =rte_eth_dev_get_port_by_name (vdev_name, &port); +if (ret !=0 ) { +fprintf (stderr,"Could not port for %s: %s\n" , + vdev_name,strerror (-ret)); + goto unplug; + } + + ret =rte_eth_dev_owner_set (port, &owner); +if (ret !=0 ) { +fprintf (stderr,"Could not set owner for port for %u: %s\n" , + port,strerror (-ret)); + goto unplug; + } + + ret =rte_eth_dev_configure (port,1 ,1 , &dev_conf); +if (ret <0 ) { +fprintf (stderr,"Could not configure port %u: %s\n" , + port,strerror (-ret)); + goto unplug; + } + + *mirror_port = port;return ring; + +unplug: +rte_eal_hotplug_remove ("vdev" , vdev_name); +rte_ring_free (ring); +rte_eal_cleanup (); +exit (EXIT_FAILURE ); }static struct rte_mempool *create_mempool (void )
@@ -796,7 +876,7 @@ static dumpcap_out_t create_output(void) version(), capture_comment);if (ret.pcapng ==NULL )rte_exit (EXIT_FAILURE ,"pcapng_fdopen failed: %s\n" , -strerror (rte_errno)); +rte_strerror (rte_errno));free (os); TAILQ_FOREACH(intf, &interfaces, next) {
@@ -823,37 +903,32 @@ static dumpcap_out_t create_output(void)return ret; } -static void enable_pdump (struct rte_ring *r,struct rte_mempool *mp) +static int enable_mirror (uint16_t mirror_port,struct rte_mempool *mpool) {struct interface *intf;unsigned int count =0 ; -uint32_t flags;int ret; - flags =RTE_PDUMP_FLAG_RXTX ; -if (use_pcapng) - flags |=RTE_PDUMP_FLAG_PCAPNG ; + ret =rte_eth_dev_start (mirror_port); +if (ret <0 ) +rte_exit (EXIT_FAILURE ,"Could not start mirror port %u: %s\n" , + mirror_port,strerror (-ret)); TAILQ_FOREACH(intf, &interfaces, next) { - ret =rte_pdump_enable_bpf (intf->port,RTE_PDUMP_ALL_QUEUES , - flags, intf->opts.snap_len, - r, mp, intf->bpf_prm); +struct rte_eth_mirror_conf conf = { + .mp = mpool, + .target = mirror_port, + .snaplen = intf->opts.snap_len, + .flags =RTE_ETH_MIRROR_ORIGIN_FLAG |RTE_ETH_MIRROR_TIMESTAMP_FLAG , + .direction =RTE_ETH_MIRROR_DIRECTION_INGRESS | +RTE_ETH_MIRROR_DIRECTION_EGRESS , + }; + + ret =rte_eth_add_mirror (intf->port, &conf);if (ret <0 ) { -const struct interface *intf2; - -/* unwind any previous enables */ - TAILQ_FOREACH(intf2, &interfaces, next) { -if (intf == intf2) -break ; -rte_pdump_disable (intf2->port, -RTE_PDUMP_ALL_QUEUES ,RTE_PDUMP_FLAG_RXTX ); -if (intf2->opts.promisc_mode) -rte_eth_promiscuous_disable (intf2->port); - } -rte_exit (EXIT_FAILURE , -"Packet dump enable on %u:%s failed %s\n" , - intf->port, intf->name, -rte_strerror (rte_errno)); +fprintf (stderr,"Port mirror on %u:%s failed %s\n" , + intf->port, intf->name,strerror (-ret)); +return -1 ; }if (intf->opts.promisc_mode) {
@@ -868,6 +943,60 @@ static void enable_pdump(struct rte_ring *r, struct rte_mempool *mp) } ++count; } +return count; +} + +static int setup_mbuf (void ) +{ +int offset; + + offset =rte_mbuf_dynfield_lookup (RTE_MBUF_DYNFIELD_TIMESTAMP_NAME ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find timestamp dynamic field\n" ); +return -1 ; + } + timestamp_dynfield = offset; + + offset =rte_mbuf_dynflag_lookup (RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find timestamp flag\n" ); +return -1 ; + } + timestamp_dynflag =RTE_BIT64 (offset); + + offset =rte_mbuf_dynfield_lookup (RTE_MBUF_DYNFIELD_MIRROR_ORIGIN ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find mirror origin dynamic field\n" ); +return -1 ; + } + mirror_origin_dynfield = offset; + + offset =rte_mbuf_dynflag_lookup (RTE_MBUF_DYNFLAG_MIRROR_ORIGIN ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find mirror origin dynamic flag\n" ); +return -1 ; + } + mirror_origin_dynflag =RTE_BIT64 (offset); + + offset =rte_mbuf_dynflag_lookup (RTE_MBUF_DYNFLAG_MIRROR_INGRESS ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find mirror ingress flag\n" ); +return -1 ; + } + mirror_ingress_dynflag =RTE_BIT64 (offset); + + offset =rte_mbuf_dynflag_lookup (RTE_MBUF_DYNFLAG_MIRROR_EGRESS ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find mirror egress flag\n" ); +return -1 ; + } + mirror_egress_dynflag =RTE_BIT64 (offset); +return 0 ; +} + +static void show_capturing (unsigned int count) +{ +struct interface *intf;fputs ("Capturing on " , stdout); TAILQ_FOREACH(intf, &interfaces, next) {
@@ -898,6 +1027,47 @@ static void show_count(uint64_t count) bt =fprintf (stderr,"%" PRIu64" " , count); } +static ssize_t +pcapng_write_packets (rte_pcapng_t *pcapng,struct rte_mbuf *pkts[],uint16_t n) +{ +struct rte_mbuf *towrite[BURST_SIZE ]; +unsigned int count =0 ; + +for (unsigned int i =0 ; i < n; i++) { +struct rte_mbuf *m = pkts[i]; +enum rte_pcapng_direction direction =RTE_PCAPNG_DIRECTION_UNKNOWN ; + +/* If no origin flag then why did we get this? */ +if (unlikely (!(m->ol_flags & mirror_origin_dynflag))) { +fprintf (stderr,"Missing origin info in packet\n" ); +return -1 ; + } + +const struct rte_mbuf_origin *origin + = RTE_MBUF_DYNFIELD(m, mirror_origin_dynfield, rte_mbuf_origin_t *); + +if (m->ol_flags & mirror_ingress_dynflag) + direction =RTE_PCAPNG_DIRECTION_IN ; +else if (m->ol_flags & mirror_egress_dynflag) + direction =RTE_PCAPNG_DIRECTION_OUT ; + +uint64_t timestamp; +if (m->ol_flags & timestamp_dynflag) + timestamp = *RTE_MBUF_DYNFIELD (m, timestamp_dynfield, + rte_mbuf_timestamp_t *); +else + timestamp =rte_get_tsc_cycles (); + +if (rte_pcapng_insert (m, origin->queue_id, direction, origin->original_len, + timestamp,NULL ) <0 ) +continue ;/* skip no headroom? */ + + towrite[count++] = m; + } + +return rte_pcapng_write_packets (pcapng, towrite, count); +} +/* Write multiple packets in older pcap format */ static ssize_t pcap_write_packets(pcap_dumper_t *dumper,
@@ -930,16 +1100,127 @@ pcap_write_packets(pcap_dumper_t *dumper,return total; } +/* Do packet filter on incoming packets. +* Some issues to note here: +* - would be better to do before putting into ring +* but that causes ethdev to have dependency on BPF. +* - the filter is per-interface and there maybe more than one interface +* combined into the ring. That means filter is executed once +* per packet (not as burst). +*/ +static unsigned int +filter_packets (struct rte_mbuf *pkts[],unsigned int n) +{ +uint64_t results[BURST_SIZE ]; +uint32_t matches =0 ; + +for (unsigned int i =0 ; i < n; i++) { +struct rte_mbuf *m = pkts[i]; + +/* all packets should have origin info, if not just skip */ +if (unlikely (!(m->ol_flags & mirror_origin_dynflag))) +continue ; + +const struct rte_mbuf_origin *origin + = RTE_MBUF_DYNFIELD(m, mirror_origin_dynfield, rte_mbuf_origin_t *); +uint16_t port_id = origin->port_id; + +if (unlikely (port_id >=RTE_MAX_ETHPORTS )) +continue ; + +const struct interface *intf = port2intf[port_id]; +if (intf ==NULL || intf->filter ==NULL ) +continue ; + +if (rte_bpf_exec_burst (intf->filter, (void **)&m, &results[i],1 ) ==1 ) + ++matches; + } + +if (matches == n) +return n;/* no packets skipped */ + +/* need to shuffle out the skipped packets */ +unsigned int count =0 ; +struct rte_mbuf *towrite[BURST_SIZE ]; +for (unsigned int i =0 ; i < n; i++) { +if (results[i]) + towrite[count++] = pkts[i]; +else +rte_pktmbuf_free (pkts[i]); + } +memcpy (pkts, towrite, count *sizeof (struct rte_mbuf *)); +return count; +} + +/* Make sure configuration of mbuf pool has enough headroom for both vlans */ +static_assert (RTE_PKTMBUF_HEADROOM >2 *sizeof (struct rte_vlan_hdr ), +"not enough mbuf headroom for vlan insertion" ); + +/* +* More general version of rte_vlan_insert() +* Note: mbufs are allocated by rte_eth_mirror_burst() from the +* pool that was passed when setting up mirror. +*/ +static void +vlan_insert (struct rte_mbuf *m,uint16_t ether_type,uint16_t tci) +{ +struct rte_ether_hdr *nh, tmph; +const struct rte_ether_hdr *oh; +struct rte_vlan_hdr *vh; + +RTE_ASSERT (!RTE_MBUF_DIRECT (m)); +RTE_ASSERT (rte_mbuf_refcnt_read (m) ==1 ); + + oh =rte_pktmbuf_read (m,0 ,sizeof (*oh), &tmph); +RTE_ASSERT (oh !=NULL ); + +/* overlay new header */ + nh = (struct rte_ether_hdr *) +rte_pktmbuf_prepend (m,sizeof (struct rte_vlan_hdr )); + +RTE_ASSERT (nh !=NULL ); + +memmove (nh, oh,2 *RTE_ETHER_ADDR_LEN ); + nh->ether_type =rte_cpu_to_be_16 (ether_type); + + vh = (struct rte_vlan_hdr *) (nh +1 ); + vh->vlan_tci =rte_cpu_to_be_16 (tci); +} + +/* Filtering and pcap file format require that VLAN not be offloaded */ +static void +remove_vlan_offload (struct rte_mbuf *pkts[],unsigned int n) +{ +unsigned int i; + +for (i =0 ; i < n; i++) { +struct rte_mbuf *m = pkts[i]; + +if (m->ol_flags & mirror_ingress_dynflag) { +if (m->ol_flags &RTE_MBUF_F_RX_VLAN_STRIPPED ) +vlan_insert (m,RTE_ETHER_TYPE_VLAN , m->vlan_tci); +if (m->ol_flags &RTE_MBUF_F_RX_QINQ_STRIPPED ) +vlan_insert (m,RTE_ETHER_TYPE_QINQ , m->vlan_tci_outer); + } +if (m->ol_flags & mirror_egress_dynflag) { +if (m->ol_flags &RTE_MBUF_F_TX_VLAN ) +vlan_insert (m,RTE_ETHER_TYPE_VLAN , m->vlan_tci); +if (m->ol_flags &RTE_MBUF_F_TX_QINQ ) +vlan_insert (m,RTE_ETHER_TYPE_QINQ , m->vlan_tci_outer); + + } + } +} +/* Process all packets in ring and dump to capture file */ -static int process_ring (dumpcap_out_t out,struct rte_ring *r) +static int process_ring (dumpcap_out_t out,struct rte_ring *ring) {struct rte_mbuf *pkts[BURST_SIZE ]; -unsigned int avail, n; +unsigned int n, avail;static unsigned int empty_count;ssize_t written; - n =rte_ring_sc_dequeue_burst (r, (void **) pkts,BURST_SIZE , - &avail); + n =rte_ring_sc_dequeue_burst (ring, (void **)pkts,BURST_SIZE , &avail);if (n ==0 ) {/* don't consume endless amounts of cpu if idle */ if (empty_count <SLEEP_THRESHOLD )
@@ -948,11 +1229,18 @@ static int process_ring(dumpcap_out_t out, struct rte_ring *r)usleep (10 );return 0 ; } - empty_count = (avail ==0 ); +remove_vlan_offload (pkts, n); + +if (filtering) { + n =filter_packets (pkts, n); +if (n ==0 ) +return 0 ; + } +if (use_pcapng) - written =rte_pcapng_write_packets (out.pcapng, pkts, n); + written =pcapng_write_packets (out.pcapng, pkts, n);else written =pcap_write_packets (out.dumper, pkts, n);
@@ -971,15 +1259,18 @@ static int process_ring(dumpcap_out_t out, struct rte_ring *r)int main (int argc,char **argv) { -struct rte_ring *r;struct rte_mempool *mp;struct sigaction action = { .sa_flags =SA_RESTART , .sa_handler = signal_handler, };struct sigaction origaction; +struct rte_ring *ring =NULL ; +char vdev_name[RTE_DEV_NAME_MAX_LEN ]; +uint16_t mirror_port =UINT16_MAX ;dumpcap_out_t out;char *p; +int ret; p =strrchr (argv[0 ],'/' );if (p ==NULL )
@@ -1018,12 +1309,21 @@ int main(int argc, char **argv)exit (0 ); } - r =create_ring (); mp =create_mempool (); + ring =create_ring_dev (vdev_name, &mirror_port); out =create_output (); + ret =enable_mirror (mirror_port, mp); +if (ret <0 ) + goto cleanup; + + ret =setup_mbuf (); +if (ret <0 ) + goto cleanup; + +show_capturing (ret); + start_time =time (NULL ); -enable_pdump (r, mp);if (!quiet) {fprintf (stderr,"Packets captured: " );
@@ -1031,7 +1331,7 @@ int main(int argc, char **argv) }while (!rte_atomic_load_explicit (&quit_signal, rte_memory_order_relaxed)) { -if (process_ring (out, r) <0 ) { +if (process_ring (out, ring) <0 ) {fprintf (stderr,"pcapng file write failed; %s\n" ,strerror (errno));break ;
@@ -1048,19 +1348,20 @@ int main(int argc, char **argv)break ; } -disable_primary_monitor (); -if (rte_eal_primary_proc_alive (NULL ))report_packet_stats (out); +cleanup:if (use_pcapng)rte_pcapng_close (out.pcapng);else pcap_dump_close (out.dumper); -cleanup_pdump_resources (); +disable_primary_monitor (); +disable_mirror_ports (mirror_port); -rte_ring_free (r); +rte_eal_hotplug_remove ("vdev" , vdev_name); +rte_ring_free (ring);rte_mempool_free (mp);return rte_eal_cleanup () ?EXIT_FAILURE :0 ;
app/dumpcap/meson.build +1 -1
@@ -14,4 +14,4 @@ endif ext_deps += pcap_dep sources = files('main.c') -deps += ['ethdev', 'pdump', 'pcapng', 'bpf'] +deps += ['net_ring', 'ethdev', 'pcapng', 'bpf']
Signature · 1 line
2.47.2
PATCH v4 13/13 pdump: mark API and application as deprecated
In reply to Stephen HemmingerWhen the pdump application is run print a warning. Add release note about deprecation and mark the API's as deprecated.
pdump build deprecated
--- app/pdump/main.c | 3 +++ app/pdump/meson.build | 1 + app/test-pmd/meson.build | 1 + app/test/meson.build | 6 +++++- doc/guides/rel_notes/deprecation.rst | 3 +++ lib/pdump/rte_pdump.h | 12 +++++++++--- 6 files changed, 22 insertions(+), 4 deletions(-)
app/pdump/main.c +3 -0
@@ -986,6 +986,9 @@ main(int argc, char **argv)char mp_flag[] ="--proc-type=secondary" ;char *argp[argc +2 ]; + +fprintf (stderr,"%s: is deprecated use dpdk-dumpcap instead\n" , argv[0 ]); +/* catch ctrl-c so we can cleanup on exit */ sigemptyset (&action.sa_mask);sigaction (SIGTERM , &action,NULL );
app/pdump/meson.build +1 -0
@@ -11,3 +11,4 @@ sources = files('main.c') deps += ['ethdev', 'kvargs', 'pdump'] cflags += no_wvla_cflag +cflags += '-Wno-deprecated-declarations'
app/test-pmd/meson.build +1 -0
@@ -60,6 +60,7 @@ if dpdk_conf.has('RTE_LIB_METRICS') endif if dpdk_conf.has('RTE_LIB_PDUMP') deps += 'pdump' + cflags += '-Wno-deprecated-declarations' endif if dpdk_conf.has('RTE_NET_BNXT') deps += 'net_bnxt'
app/test/meson.build +5 -1
@@ -138,7 +138,6 @@ source_file_deps = { 'test_net_ip6.c': ['net'], 'test_pcapng.c': ['ethdev', 'net', 'pcapng', 'bus_vdev'], 'test_pdcp.c': ['eventdev', 'pdcp', 'net', 'timer', 'security'], - 'test_pdump.c': ['pdump'] + sample_packet_forward_deps, 'test_per_lcore.c': [], 'test_pflock.c': [], 'test_pie.c': ['sched'],
@@ -217,6 +216,11 @@ source_file_ext_deps = { 'test_pcapng.c': ['pcap'], } +if dpdk_conf.has('RTE_LIB_PDUMP') + source_file_deps += { 'test_pdump.c': ['pdump'] + sample_packet_forward_deps, } + cflags += '-Wno-deprecated-declarations' +endif + def_lib = get_option('default_library') foreach f, f_deps : source_file_deps has_deps = true
doc/guides/rel_notes/deprecation.rst +3 -0
@@ -152,3 +152,6 @@ Deprecation Notices * bus/vmbus: Starting DPDK 25.11, all the vmbus API defined in ``drivers/bus/vmbus/rte_bus_vmbus.h`` will become internal to DPDK. Those API functions are used internally by DPDK core and netvsc PMD. + +* pdump: The pdump API and application have been deprecated and will + be removed in a later release.
lib/pdump/rte_pdump.h +9 -3
@@ -39,6 +39,7 @@ enum {* @return * 0 on success, -1 on error */ +__rte_deprecated intrte_pdump_init (void );
@@ -50,6 +51,7 @@ rte_pdump_init(void);* @return * 0 on success, -1 on error */ +__rte_deprecated intrte_pdump_uninit (void );
@@ -75,7 +77,7 @@ rte_pdump_uninit(void);* @return * 0 on success, -1 on error, rte_errno is set accordingly. */ - +__rte_deprecated int rte_pdump_enable(uint16_t port, uint16_t queue, uint32_t flags, struct rte_ring *ring,
@@ -106,6 +108,7 @@ rte_pdump_enable(uint16_t port, uint16_t queue, uint32_t flags,* @return * 0 on success, -1 on error, rte_errno is set accordingly. */ +__rte_deprecated int rte_pdump_enable_bpf(uint16_t port_id, uint16_t queue, uint32_t flags, uint32_t snaplen,
@@ -129,7 +132,7 @@ rte_pdump_enable_bpf(uint16_t port_id, uint16_t queue,* @return * 0 on success, -1 on error, rte_errno is set accordingly. */ - +__rte_deprecated intrte_pdump_disable (uint16_t port,uint16_t queue,uint32_t flags);
@@ -156,7 +159,7 @@ rte_pdump_disable(uint16_t port, uint16_t queue, uint32_t flags);* @return * 0 on success, -1 on error, rte_errno is set accordingly. */ - +__rte_deprecated int rte_pdump_enable_by_deviceid(char *device_id, uint16_t queue, uint32_t flags,
@@ -189,6 +192,7 @@ rte_pdump_enable_by_deviceid(char *device_id, uint16_t queue,* @return * 0 on success, -1 on error, rte_errno is set accordingly. */ +__rte_deprecated int rte_pdump_enable_bpf_by_deviceid(const char *device_id, uint16_t queue, uint32_t flags, uint32_t snaplen,
@@ -215,6 +219,7 @@ rte_pdump_enable_bpf_by_deviceid(const char *device_id, uint16_t queue,* @return * 0 on success, -1 on error, rte_errno is set accordingly. */ +__rte_deprecated intrte_pdump_disable_by_deviceid (char *device_id,uint16_t queue,uint32_t flags);
@@ -243,6 +248,7 @@ struct rte_pdump_stats {* @return * Zero if successful. -1 on error and rte_errno is set. */ +__rte_deprecated intrte_pdump_stats (uint16_t port_id,struct rte_pdump_stats *stats);
Signature · 1 line
2.47.2
v5 cover Packet capture using port mirroring
In reply to Stephen HemmingerThis is a rework of how packet capture is done in DPDK.
The existing mechanism using callbacks has a number of problems:
- can't work when packets are sent and received in secondary process because callbacks only function in the primary process
- requires "opt-in" from application
The new mechanism builds on the concept of port mirroring used in Linux/FreeBSD and also router vendors (SPAN ports).
See: https://en.wikipedia.org/wiki/Port_mirroring for a general description.
The implementation uses two new ethdev API's:
one to add a port mirror, and one to remove it.
The internals of dumpcap are redone but the program command syntax is unchanged (no doc change needed). Using the new mirror mechanism, the dumpcap program creates a port using ring PMD and then directs a port mirror to that new ring PMD instance. Then the packets are extracted from the ring. If capturing on multiple devices, they all get mirrored to the same ring PMD.
The dumpcap program needs to be able to start the ring PMD it created but the existing ethdev API is broken when used from secondary process. One of the patches fixes that, it was also reported previously in Bugzilla.
The mirror API has a restriction that the port being mirrored to must allow lock free transmit. This is because both Rx and Tx as well as multiple queues need to go over the same transmit queue. Although it might be possible to have some complex mapping between multiple ports/queues being mirrored to multiple transmit queues, that gets to be a lot of overhead in API's and implementation. Fixing the ring and null PMD to allow lockless transmit is good enough.
Added tests for the mirror features.
The performance has not been measured but the overhead of checking for mirror port is no more that the overhead of looking at the callback list.
TODO items:
- need release notes for new features (will wait till 25.11)
- more through testing on real hardware
v5 - fix build warnings when experimental not enabled.
Stephen Hemminger (13):
ethdev: allow start/stop from secondary process
ethdev: make sure all necessary headers included
test: add test for hotplug and secondary process operations net/ring: allow lockfree transmit if ring supports it net/ring: add new devarg to create vdev from existing ring
mbuf: add dynamic flag for use by port mirroring
ethdev: add port mirroring feature
pcapng: split packet copy from header insertion
pcapng: make queue optional
test: add tests for ethdev mirror
app/testpmd: support for port mirroring app/dumpcap: use port mirror instead of pdump
pdump: mark API and application as deprecated
app/dumpcap/main.c | 443 +++++++++++++++--- app/dumpcap/meson.build | 2 +- app/pdump/main.c | 3 + app/pdump/meson.build | 1 + app/test-pmd/cmdline.c | 1 + app/test-pmd/cmdline_mirror.c | 129 +++++ app/test-pmd/cmdline_mirror.h | 12 + app/test-pmd/meson.build | 2 + app/test/meson.build | 7 +- app/test/test_ethdev_mirror.c | 286 +++++++++++ app/test/test_mp_secondary.c | 51 +- config/rte_config.h | 1 + doc/guides/howto/packet_capture_framework.rst | 15 +- doc/guides/nics/bnxt.rst | 2 +- doc/guides/prog_guide/ethdev/index.rst | 1 + doc/guides/prog_guide/pdump_lib.rst | 4 + doc/guides/rel_notes/deprecation.rst | 3 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 15 + doc/guides/tools/pdump.rst | 2 + drivers/net/ring/rte_eth_ring.c | 47 ++ lib/ethdev/ethdev_driver.c | 11 +- lib/ethdev/ethdev_driver.h | 6 + lib/ethdev/ethdev_private.c | 142 ++++++ lib/ethdev/ethdev_private.h | 29 ++ lib/ethdev/ethdev_trace.h | 17 + lib/ethdev/ethdev_trace_points.c | 6 + lib/ethdev/meson.build | 1 + lib/ethdev/rte_ethdev.c | 101 ++-- lib/ethdev/rte_ethdev.h | 23 +- lib/ethdev/rte_ethdev_core.h | 12 +- lib/ethdev/rte_mirror.c | 359 ++++++++++++++ lib/ethdev/rte_mirror.h | 99 ++++ lib/mbuf/rte_mbuf_dyn.h | 9 + lib/pcapng/rte_pcapng.c | 179 +++---- lib/pcapng/rte_pcapng.h | 27 +- lib/pdump/rte_pdump.h | 12 +- 36 files changed, 1843 insertions(+), 217 deletions(-) create mode 100644 app/test-pmd/cmdline_mirror.c create mode 100644 app/test-pmd/cmdline_mirror.h create mode 100644 app/test/test_ethdev_mirror.c create mode 100644 lib/ethdev/rte_mirror.c create mode 100644 lib/ethdev/rte_mirror.h
Signature · 1 line
2.47.2
PATCH v5 1/13 ethdev: allow start/stop from secondary process
Before this patch if secondary process called start/stop it would only impact the secondary process, the ethdev on the primary process was not started.
With this patch, when start/stop is called from secondary, it calls the primary and does the operation there. The design is generic, and we can later add queue and other operations as needed.
Bugzilla ID: 73
--- lib/ethdev/ethdev_driver.c | 11 ++++- lib/ethdev/ethdev_private.c | 93 +++++++++++++++++++++++++++++++++++++ lib/ethdev/ethdev_private.h | 26 +++++++++++ lib/ethdev/rte_ethdev.c | 84 +++++++++++++++++++-------------- 4 files changed, 177 insertions(+), 37 deletions(-)
lib/ethdev/ethdev_driver.c +10 -1
@@ -114,6 +114,14 @@ rte_eth_dev_allocate(const char *name) goto unlock; } +if (eth_dev_shared_data->allocated_ports ==0 && +rte_mp_action_register (ETHDEV_MP , ethdev_server) && + rte_errno !=ENOTSUP ) { +RTE_ETHDEV_LOG_LINE (ERR , +"Could not start %s service" ,ETHDEV_MP ); + goto unlock; + } + eth_dev =eth_dev_get (port_id); eth_dev->flow_fp_ops = &rte_flow_fp_default_ops;strlcpy (eth_dev->data->name, name,sizeof (eth_dev->data->name));
@@ -282,7 +290,8 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)memset (eth_dev->data,0 ,sizeof (struct rte_eth_dev_data )); eth_dev->data =NULL ; - eth_dev_shared_data->allocated_ports--; +if (--eth_dev_shared_data->allocated_ports ==0 ) +rte_mp_action_unregister (ETHDEV_MP );eth_dev_shared_data_release (); }
lib/ethdev/ethdev_private.c +93 -0
102 lines not on this page · raw message
lib/ethdev/ethdev_private.h +26 -0
@@ -79,4 +79,30 @@ void eth_dev_txq_release(struct rte_eth_dev *dev, uint16_t qid);int eth_dev_rx_queue_config (struct rte_eth_dev *dev,uint16_t nb_queues);int eth_dev_tx_queue_config (struct rte_eth_dev *dev,uint16_t nb_queues); +/* Used to allow start/stop from secondary */ +#define ETHDEV_MP "mp_ethdev" + +enum ethdev_mp_operation { +ETH_REQ_START , +ETH_REQ_STOP , +}; + +struct ethdev_mp_request { +uint16_t operation; +uint16_t port_id; +uint32_t reserved; + +uint8_t config[];/* operation specific */ +}; + +struct ethdev_mp_response { +uint16_t res_op; +uint16_t port_id; +int32_t err_value; +}; + +int ethdev_server (const struct rte_mp_msg *mp_msg,const void *peer); +int ethdev_request (uint16_t port_id,enum ethdev_mp_operation op, +const void *buf,size_t buf_len); +#endif /* _ETH_PRIVATE_H_ */
lib/ethdev/rte_ethdev.c +48 -36
111 lines not on this page · raw message
Signature · 1 line
2.47.2
PATCH v5 2/13 ethdev: make sure all necessary headers included
In reply to Stephen HemmingerBest not to depend on other EAL headers to include stuff. Some of the later changes had build failures on some platforms.
--- lib/ethdev/ethdev_private.c | 9 +++++++++ 1 file changed, 9 insertions(+)
lib/ethdev/ethdev_private.c +9 -0
@@ -3,9 +3,18 @@*/ #include <assert.h> +#include <errno.h> +#include <inttypes.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <time.h> #include <eal_export.h> #include <rte_debug.h> +#include <rte_eal.h> +#include <rte_lcore.h> +#include <rte_stdatomic.h> #include "rte_ethdev.h" #include "rte_ethdev_trace_fp.h"
Signature · 1 line
2.47.2
PATCH v5 3/13 test: add test for hotplug and secondary process operations
In reply to Stephen HemmingerUse null device to exercise ethdev start/stop in secondary process.
--- app/test/test_mp_secondary.c | 51 +++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-)
app/test/test_mp_secondary.c +48 -3
@@ -15,6 +15,9 @@#include <string.h> #include <unistd.h> +#include <rte_ethdev.h> +#include <rte_bus_vdev.h> +#ifdef RTE_EXEC_ENV_WINDOWS int test_mp_secondary (void )
@@ -204,6 +207,44 @@ run_object_creation_tests(void)return 0 ; } +static int +run_ethdev_tests (void ) +{ +char vdev_name[] ="net_null" ; +struct rte_eth_conf dev_conf = {0 }; +uint16_t port; +int ret; + +printf ("### Testing hotplug and ethdev start/stop\n" ); + +/* use hotplug to make a null vdev */ + ret =rte_eal_hotplug_add ("vdev" , vdev_name,"" ); +TEST_ASSERT (ret ==0 ,"Hotplug add of '%s' failed" , vdev_name); + +printf ("# Checked hotlug_add OK\n" ); + + ret =rte_eth_dev_get_port_by_name (vdev_name, &port); +TEST_ASSERT (ret ==0 ,"Lookup vdev '%s' failed" , vdev_name); + + ret =rte_eth_dev_configure (port,1 ,1 , &dev_conf); +TEST_ASSERT (ret ==0 ,"Configure port %u failed" , port); + + ret =rte_eth_dev_start (port); +TEST_ASSERT (ret ==0 ,"Start port %u failed" , port); + +printf ("# Checked rte_eth_dev_start\n" ); + + ret =rte_eth_dev_stop (port); +TEST_ASSERT (ret ==0 ,"Stop port %u failed" , port); + +printf ("# Checked rte_eth_dev_stop\n" ); + +rte_eal_hotplug_remove ("vdev" , vdev_name); + +printf ("# Checked hotlug_remove OK\n" ); +return 0 ; +} +/* if called in a primary process, just spawns off a secondary process to * run validation tests - which brings us right back here again... * if called in a secondary process, this runs a series of API tests to check
@@ -212,15 +253,19 @@ run_object_creation_tests(void)int test_mp_secondary (void ) { -if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) { +int ret; + +if (rte_eal_process_type () ==RTE_PROC_PRIMARY )return run_secondary_instances (); - }printf ("IN SECONDARY PROCESS\n" ); + ret =run_ethdev_tests (); +if (ret !=0 ) +return ret;return run_object_creation_tests (); }#endif /* !RTE_EXEC_ENV_WINDOWS */ -REGISTER_FAST_TEST (multiprocess_autotest, false, false, test_mp_secondary); +REGISTER_FAST_TEST (multiprocess_autotest, true, true, test_mp_secondary);
Signature · 1 line
2.47.2
PATCH v5 4/13 net/ring: allow lockfree transmit if ring supports it
In reply to Stephen HemmingerNeed to be able have multiple threads all using same transmit queue when using SPAN.
--- drivers/net/ring/rte_eth_ring.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/net/ring/rte_eth_ring.c +17 -0
@@ -177,6 +177,19 @@ eth_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,return 0 ; } +static bool +eth_tx_queue_lockfree (const struct pmd_internals *internals) +{ +unsigned int i; + +for (i =0 ; i < internals->max_tx_queues; i++) { +const struct ring_queue *r = &internals->tx_ring_queues[i]; + +if (r->rng->flags &RING_F_SP_ENQ ) +return false; + } +return true; +} static int eth_dev_info(struct rte_eth_dev *dev,
@@ -189,6 +202,10 @@ eth_dev_info(struct rte_eth_dev *dev, dev_info->max_rx_queues = (uint16_t )internals->max_rx_queues; dev_info->rx_offload_capa =RTE_ETH_RX_OFFLOAD_SCATTER ; dev_info->tx_offload_capa =RTE_ETH_TX_OFFLOAD_MULTI_SEGS ; + +if (eth_tx_queue_lockfree (internals)) + dev_info->tx_offload_capa |=RTE_ETH_TX_OFFLOAD_MT_LOCKFREE ; + dev_info->max_tx_queues = (uint16_t )internals->max_tx_queues; dev_info->min_rx_bufsize =0 ;
Signature · 1 line
2.47.2
PATCH v5 5/13 net/ring: add new devarg to create vdev from existing ring
In reply to Stephen HemmingerNeed ability to allow process like dumpcap to make a ring ethdev with a pre-existing ring. Do this via devargs so it can work with hotplug.
It looked like the API rte_eth_from_ring() would work for this, but it doesn't do the right thing. That API makes new vdev but names the ring based on the parameter.
--- drivers/net/ring/rte_eth_ring.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
drivers/net/ring/rte_eth_ring.c +30 -0
@@ -23,9 +23,12 @@#define ETH_RING_INTERNAL_ARG "internal"#define ETH_RING_INTERNAL_ARG_MAX_LEN 19/* "0x..16chars..\0" */ +#define ETH_RING_RING_ARG "ring" +static const char *valid_arguments[] = {ETH_RING_NUMA_NODE_ACTION_ARG ,ETH_RING_INTERNAL_ARG , +ETH_RING_RING_ARG ,NULL };
@@ -693,6 +696,20 @@ parse_internal_args(const char *key __rte_unused, const char *value,return 0 ; } +static int +parse_ring_arg(const char *key __rte_unused, const char *value, void *data) +{ +struct rte_ring **rp = data; + + *rp =rte_ring_lookup (value); +if (*rp ==NULL ) { +PMD_LOG (ERR ,"ring '%s' not found" , value); +return -1 ; + } + +return 0 ; +} +static int rte_pmd_ring_probe (struct rte_vdev_device *dev) {
@@ -770,6 +787,18 @@ rte_pmd_ring_probe(struct rte_vdev_device *dev) ð_dev);if (ret >=0 ) ret =0 ; + }else if (rte_kvargs_count (kvlist,ETH_RING_RING_ARG ) ==1 ) { +struct rte_ring *rxtx[1 ] = { }; + + ret =rte_kvargs_process (kvlist,ETH_RING_RING_ARG , parse_ring_arg, rxtx); +if (ret <0 ) + goto out_free; + +/* Note: rte_eth_from_ring() does not do what is expected here! */ + ret =do_eth_dev_ring_create (name, dev, rxtx,1 , rxtx,1 , +rte_socket_id (),DEV_ATTACH , ð_dev); +if (ret <0 ) + goto out_free; }else { ret =rte_kvargs_count (kvlist,ETH_RING_NUMA_NODE_ACTION_ARG ); info = rte_zmalloc("struct node_action_list",
@@ -843,4 +872,5 @@ static struct rte_vdev_driver pmd_ring_drv = {RTE_PMD_REGISTER_VDEV (net_ring, pmd_ring_drv);RTE_PMD_REGISTER_ALIAS (net_ring, eth_ring);RTE_PMD_REGISTER_PARAM_STRING (net_ring, +ETH_RING_RING_ARG "=<string> " ETH_RING_NUMA_NODE_ACTION_ARG "=name:node:action(ATTACH|CREATE)" );
Signature · 1 line
2.47.2
PATCH v5 6/13 mbuf: add dynamic flag for use by port mirroring
In reply to Stephen HemmingerAdd names for new port mirror fields.
--- lib/mbuf/rte_mbuf_dyn.h | 9 +++++++++ 1 file changed, 9 insertions(+)
lib/mbuf/rte_mbuf_dyn.h +9 -0
@@ -327,6 +327,15 @@ int rte_mbuf_dyn_tx_timestamp_register(int *field_offset, uint64_t *tx_flag);#define RTE_MBUF_DYNFIELD_IP_REASSEMBLY_NAME "rte_dynfield_ip_reassembly"#define RTE_MBUF_DYNFLAG_IP_REASSEMBLY_INCOMPLETE_NAME "rte_dynflag_ip_reassembly_incomplete" +/** +* The ethdev port mirror needs some extra packet information that +* includes information about the packet before it was copied to the mirror. +*/ +#define RTE_MBUF_DYNFIELD_MIRROR_ORIGIN "rte_dynfield_mirror_origin" +#define RTE_MBUF_DYNFLAG_MIRROR_ORIGIN "rte_dynflag_mirror_origin" +#define RTE_MBUF_DYNFLAG_MIRROR_INGRESS "rte_dynflag_mirror_ingress" +#define RTE_MBUF_DYNFLAG_MIRROR_EGRESS "rte_dynflag_mirror_egress" + #ifdef __cplusplus }#endif
Signature · 1 line
2.47.2
PATCH v5 7/13 ethdev: add port mirroring feature
In reply to Stephen HemmingerThis adds new feature port mirroring to the ethdev layer.
--- config/rte_config.h | 1 + lib/ethdev/ethdev_driver.h | 6 + lib/ethdev/ethdev_private.c | 58 ++++- lib/ethdev/ethdev_private.h | 3 + lib/ethdev/ethdev_trace.h | 17 ++ lib/ethdev/ethdev_trace_points.c | 6 + lib/ethdev/meson.build | 1 + lib/ethdev/rte_ethdev.c | 17 +- lib/ethdev/rte_ethdev.h | 23 +- lib/ethdev/rte_ethdev_core.h | 12 +- lib/ethdev/rte_mirror.c | 359 +++++++++++++++++++++++++++++++ lib/ethdev/rte_mirror.h | 99 +++++++++ 12 files changed, 584 insertions(+), 18 deletions(-) create mode 100644 lib/ethdev/rte_mirror.c create mode 100644 lib/ethdev/rte_mirror.h
config/rte_config.h +1 -0
@@ -69,6 +69,7 @@#define RTE_MAX_QUEUES_PER_PORT 1024#define RTE_ETHDEV_QUEUE_STAT_CNTRS 16/* max 256 */ #define RTE_ETHDEV_RXTX_CALLBACKS 1 +#define RTE_ETHDEV_MIRROR 1#define RTE_MAX_MULTI_HOST_CTRLS 4/* cryptodev defines */
lib/ethdev/ethdev_driver.h +6 -0
@@ -91,6 +91,12 @@ struct __rte_cache_aligned rte_eth_dev {*/ RTE_ATOMIC (struct rte_eth_rxtx_callback *) pre_tx_burst_cbs[RTE_MAX_QUEUES_PER_PORT ]; +/** Receive mirrors */ +RTE_ATOMIC (struct rte_eth_mirror *) rx_mirror; + +/** Transmit mirrors */ +RTE_ATOMIC (struct rte_eth_mirror *) tx_mirror; +enum rte_eth_dev_state state;/**< Flag indicating the port state */ void *security_ctx;/**< Context for security ops */ };
lib/ethdev/ethdev_private.c +49 -9
95 lines not on this page · raw message
lib/ethdev/ethdev_private.h +3 -0
@@ -85,6 +85,9 @@ int eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues);enum ethdev_mp_operation {ETH_REQ_START ,ETH_REQ_STOP , +ETH_REQ_RESET , +ETH_REQ_ADD_MIRROR , +ETH_REQ_REMOVE_MIRROR , };struct ethdev_mp_request {
lib/ethdev/ethdev_trace.h +17 -0
@@ -1035,6 +1035,23 @@ RTE_TRACE_POINT(rte_trace_point_emit_int (ret); ) +RTE_TRACE_POINT ( + rte_eth_trace_add_mirror, + RTE_TRACE_POINT_ARGS(uint16_t port_id, + const struct rte_eth_mirror_conf *conf, int ret), + rte_trace_point_emit_u16(port_id); +rte_trace_point_emit_u16 (conf->target); +rte_trace_point_emit_int (ret); +) + +RTE_TRACE_POINT ( + rte_eth_trace_remove_mirror, + RTE_TRACE_POINT_ARGS(uint16_t port_id, uint16_t target_id, int ret), + rte_trace_point_emit_u16(port_id); +rte_trace_point_emit_u16 (target_id); +rte_trace_point_emit_int (ret); +) + RTE_TRACE_POINT( rte_eth_trace_rx_queue_info_get, RTE_TRACE_POINT_ARGS(uint16_t port_id, uint16_t queue_id,
lib/ethdev/ethdev_trace_points.c +6 -0
@@ -389,6 +389,12 @@ RTE_TRACE_POINT_REGISTER(rte_eth_trace_remove_rx_callback,RTE_TRACE_POINT_REGISTER (rte_eth_trace_remove_tx_callback, lib.ethdev.remove_tx_callback) +RTE_TRACE_POINT_REGISTER (rte_eth_trace_add_mirror, + lib.ethdev.add_mirror) + +RTE_TRACE_POINT_REGISTER (rte_eth_trace_remove_mirror, + lib.ethdev.remove_mirror) +RTE_TRACE_POINT_REGISTER (rte_eth_trace_rx_queue_info_get, lib.ethdev.rx_queue_info_get)
lib/ethdev/meson.build +1 -0
@@ -11,6 +11,7 @@ sources = files( 'rte_ethdev_cman.c', 'rte_ethdev_telemetry.c', 'rte_flow.c', + 'rte_mirror.c', 'rte_mtr.c', 'rte_tm.c', 'sff_telemetry.c',
lib/ethdev/rte_ethdev.c +11 -6
@@ -14,6 +14,8 @@#include <bus_driver.h> #include <eal_export.h> #include <rte_log.h> +#include <rte_cycles.h> +#include <rte_alarm.h> #include <rte_interrupts.h> #include <rte_kvargs.h> #include <rte_memcpy.h>
@@ -2041,13 +2043,16 @@ rte_eth_dev_reset(uint16_t port_id)if (dev->dev_ops->dev_reset ==NULL )return -ENOTSUP ; - ret =rte_eth_dev_stop (port_id); -if (ret !=0 ) { -RTE_ETHDEV_LOG_LINE (ERR , -"Failed to stop device (port %u) before reset: %s - ignore" , - port_id,rte_strerror (-ret)); +if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) { + ret =rte_eth_dev_stop (port_id); +if (ret !=0 ) +RTE_ETHDEV_LOG_LINE (ERR , +"Failed to stop device (port %u) before reset: %s - ignore" , + port_id,rte_strerror (-ret)); + ret =eth_err (port_id, dev->dev_ops->dev_reset (dev)); + }else { + ret =ethdev_request (port_id,ETH_REQ_STOP ,NULL ,0 ); } - ret =eth_err (port_id, dev->dev_ops->dev_reset (dev));rte_ethdev_trace_reset (port_id, ret);
lib/ethdev/rte_ethdev.h +22 -1
@@ -170,6 +170,7 @@#include "rte_ethdev_trace_fp.h" #include "rte_dev_info.h" +#include "rte_mirror.h" #ifdef __cplusplusextern "C" {
@@ -1466,7 +1467,6 @@ enum rte_eth_tunnel_type { RTE_ETH_TUNNEL_TYPE_ECPRI, RTE_ETH_TUNNEL_TYPE_MAX, }; -#ifdef __cplusplus }#endif
@@ -6334,6 +6334,17 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t queue_id, nb_rx = p->rx_pkt_burst (qd, rx_pkts, nb_pkts); +#ifdef RTE_ETHDEV_MIRROR + { +const struct rte_eth_mirror *mirror + =rte_atomic_load_explicit (p->rx_mirror, rte_memory_order_relaxed); + +if (unlikely (mirror !=NULL )) +rte_eth_mirror_burst (port_id, queue_id,RTE_ETH_MIRROR_DIRECTION_INGRESS , + rx_pkts, nb_rx, mirror); + } +#endif +#ifdef RTE_ETHDEV_RXTX_CALLBACKS {void *cb;
@@ -6692,6 +6703,16 @@ rte_eth_tx_burst(uint16_t port_id, uint16_t queue_id, }#endif +#ifdef RTE_ETHDEV_MIRROR + { +const struct rte_eth_mirror *mirror; + + mirror =rte_atomic_load_explicit (p->tx_mirror, rte_memory_order_relaxed); +if (unlikely (mirror !=NULL )) +rte_eth_mirror_burst (port_id, queue_id,RTE_ETH_MIRROR_DIRECTION_EGRESS , + tx_pkts, nb_pkts, mirror); + } +#endif nb_pkts = p->tx_pkt_burst (qd, tx_pkts, nb_pkts);rte_ethdev_trace_tx_burst (port_id, queue_id, (void **)tx_pkts, nb_pkts);
lib/ethdev/rte_ethdev_core.h +10 -2
@@ -22,6 +22,12 @@ RTE_TAILQ_HEAD(rte_eth_dev_cb_list, rte_eth_dev_callback);struct rte_eth_dev ; +struct rte_eth_mirror ; + +void rte_eth_mirror_burst (uint16_t port_id,uint16_t quque_id,uint8_t dir, +struct rte_mbuf **pkts,uint16_t nb_pkts, +const struct rte_eth_mirror *mirror); +/** * @internal Retrieve input packets from a receive queue of an Ethernet device. */
@@ -101,7 +107,8 @@ struct __rte_cache_aligned rte_eth_fp_ops {eth_rx_descriptor_status_t rx_descriptor_status;/** Refill Rx descriptors with the recycling mbufs. */ eth_recycle_rx_descriptors_refill_t recycle_rx_descriptors_refill; -uintptr_t reserved1[2 ]; +uintptr_t reserved1; +RTE_ATOMIC (struct rte_eth_mirror *) *rx_mirror;/**@}*/ /**@{*/
@@ -121,7 +128,8 @@ struct __rte_cache_aligned rte_eth_fp_ops {eth_recycle_tx_mbufs_reuse_t recycle_tx_mbufs_reuse;/** Get the number of used Tx descriptors. */ eth_tx_queue_count_t tx_queue_count; -uintptr_t reserved2[1 ]; +RTE_ATOMIC (struct rte_eth_mirror *) *tx_mirror; +uintptr_t reserved2;/**@}*/ };
lib/ethdev/rte_mirror.c new file +359 -0
359 lines not on this page · raw message
lib/ethdev/rte_mirror.h new file +99 -0
99 lines not on this page · raw message
Signature · 1 line
2.47.2
PATCH v5 8/13 pcapng: split packet copy from header insertion
In reply to Stephen HemmingerIn new model, the packet was already copied, only need to wrap it in pcapng format.
--- lib/pcapng/rte_pcapng.c | 178 +++++++++++++++++++++------------------- lib/pcapng/rte_pcapng.h | 27 +++++- 2 files changed, 120 insertions(+), 85 deletions(-)
lib/pcapng/rte_pcapng.c +95 -83
@@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2019 Microsoft Corporation */
@@ -432,8 +433,24 @@ pcapng_vlan_insert(struct rte_mbuf *m, uint16_t ether_type, uint16_t tci)return 0 ; } +/* pad the packet to 32 bit boundary */ +static inline int +pcapng_mbuf_pad32 (struct rte_mbuf *m) +{ +uint32_t pkt_len =rte_pktmbuf_pkt_len (m); +uint32_t padding =RTE_ALIGN (pkt_len,sizeof (uint32_t )) - pkt_len; + +if (padding >0 ) { +void *tail =rte_pktmbuf_append (m, padding); +if (tail ==NULL ) +return -1 ; +memset (tail,0 , padding); + } +return 0 ; +} +/* -* The mbufs created use the Pcapng standard enhanced packet block. +* The mbufs created use the Pcapng standard enhanced packet block. * * 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
@@ -468,71 +485,28 @@ pcapng_vlan_insert(struct rte_mbuf *m, uint16_t ether_type, uint16_t tci)* | Block Total Length | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ - -/* Make a copy of original mbuf with pcapng header and options */ -RTE_EXPORT_SYMBOL (rte_pcapng_copy) -struct rte_mbuf * -rte_pcapng_copy (uint16_t port_id,uint32_t queue, -const struct rte_mbuf *md, -struct rte_mempool *mp, -uint32_t length, -enum rte_pcapng_direction direction, -const char *comment) +RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pcapng_insert, 25.07) +int +rte_pcapng_insert (struct rte_mbuf *m,uint32_t queue, +enum rte_pcapng_direction direction,uint32_t orig_len, +uint64_t timestamp,const char *comment) {struct pcapng_enhance_packet_block *epb; -uint32_t orig_len, pkt_len, padding, flags; -struct pcapng_option *opt; -uint64_t timestamp; -uint16_t optlen; -struct rte_mbuf *mc; -bool rss_hash; - -#ifdef RTE_LIBRTE_ETHDEV_DEBUG -RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id,NULL ); -#endif - orig_len =rte_pktmbuf_pkt_len (md); +uint32_t pkt_len =rte_pktmbuf_pkt_len (m); +uint32_t flags; -/* Take snapshot of the data */ - mc =rte_pktmbuf_copy (md, mp,0 , length); -if (unlikely (mc ==NULL )) -return NULL ; - -/* Expand any offloaded VLAN information */ -if ((direction ==RTE_PCAPNG_DIRECTION_IN && - (md->ol_flags &RTE_MBUF_F_RX_VLAN_STRIPPED )) || - (direction ==RTE_PCAPNG_DIRECTION_OUT && - (md->ol_flags &RTE_MBUF_F_TX_VLAN ))) { -if (pcapng_vlan_insert (mc,RTE_ETHER_TYPE_VLAN , - md->vlan_tci) !=0 ) - goto fail; - } +if (unlikely (pcapng_mbuf_pad32 (m) <0 )) +return -1 ; -if ((direction ==RTE_PCAPNG_DIRECTION_IN && - (md->ol_flags &RTE_MBUF_F_RX_QINQ_STRIPPED )) || - (direction ==RTE_PCAPNG_DIRECTION_OUT && - (md->ol_flags &RTE_MBUF_F_TX_QINQ ))) { -if (pcapng_vlan_insert (mc,RTE_ETHER_TYPE_QINQ , - md->vlan_tci_outer) !=0 ) - goto fail; - } +uint16_t optlen =pcapng_optlen (sizeof (flags)); -/* record HASH on incoming packets */ - rss_hash = (direction ==RTE_PCAPNG_DIRECTION_IN && - (md->ol_flags &RTE_MBUF_F_RX_RSS_HASH )); +/* make queue optional? */ + optlen +=pcapng_optlen (sizeof (queue)); -/* pad the packet to 32 bit boundary */ - pkt_len =rte_pktmbuf_pkt_len (mc); - padding =RTE_ALIGN (pkt_len,sizeof (uint32_t )) - pkt_len; -if (padding >0 ) { -void *tail =rte_pktmbuf_append (mc, padding); +/* does packet have valid RSS hash to include */ +bool rss_hash = (direction ==RTE_PCAPNG_DIRECTION_IN && + (m->ol_flags &RTE_MBUF_F_RX_RSS_HASH )); -if (tail ==NULL ) - goto fail; -memset (tail,0 , padding); - } - - optlen =pcapng_optlen (sizeof (flags)); - optlen +=pcapng_optlen (sizeof (queue));if (rss_hash) optlen +=pcapng_optlen (sizeof (uint8_t ) +sizeof (uint32_t ));
@@ -540,10 +514,10 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue, optlen +=pcapng_optlen (strlen (comment));/* reserve trailing options and block length */ - opt = (struct pcapng_option *) -rte_pktmbuf_append (mc, optlen +sizeof (uint32_t )); +struct pcapng_option *opt = (struct pcapng_option *) +rte_pktmbuf_append (m, optlen +sizeof (uint32_t ));if (unlikely (opt ==NULL )) - goto fail; +return -1 ;switch (direction) {case RTE_PCAPNG_DIRECTION_IN :
@@ -556,24 +530,20 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue, flags =0 ; } - opt =pcapng_add_option (opt,PCAPNG_EPB_FLAGS , - &flags,sizeof (flags)); - - opt =pcapng_add_option (opt,PCAPNG_EPB_QUEUE , - &queue,sizeof (queue)); + opt =pcapng_add_option (opt,PCAPNG_EPB_FLAGS , &flags,sizeof (flags)); + opt =pcapng_add_option (opt,PCAPNG_EPB_QUEUE , &queue,sizeof (queue));if (rss_hash) {uint8_t hash_opt[5 ]; -/* The algorithm could be something else if -* using rte_flow_action_rss; but the current API does not -* have a way for ethdev to report this on a per-packet basis. +/* The algorithm could be something else but the current API does not +* have a way for to record this on a per-packet basis +* and the PCAPNG hash types don't match the DPDK types. */ hash_opt[0 ] =PCAPNG_HASH_TOEPLITZ ; -memcpy (&hash_opt[1 ], &md->hash.rss,sizeof (uint32_t )); - opt =pcapng_add_option (opt,PCAPNG_EPB_HASH , - &hash_opt,sizeof (hash_opt)); +memcpy (&hash_opt[1 ], &m->hash.rss,sizeof (uint32_t )); + opt =pcapng_add_option (opt,PCAPNG_EPB_HASH , &hash_opt,sizeof (hash_opt)); }if (comment)
@@ -583,19 +553,14 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,/* Note: END_OPT necessary here. Wireshark doesn't do it. */ /* Add PCAPNG packet header */ - epb = (struct pcapng_enhance_packet_block *) -rte_pktmbuf_prepend (mc,sizeof (*epb)); + epb = (struct pcapng_enhance_packet_block *)rte_pktmbuf_prepend (m,sizeof (*epb));if (unlikely (epb ==NULL )) - goto fail; +return -1 ; epb->block_type =PCAPNG_ENHANCED_PACKET_BLOCK ; - epb->block_length =rte_pktmbuf_pkt_len (mc); - -/* Interface index is filled in later during write */ - mc->port = port_id; + epb->block_length =rte_pktmbuf_pkt_len (m); -/* Put timestamp in cycles here - adjust in packet write */ - timestamp =rte_get_tsc_cycles (); +/* Put timestamp in cycles here - adjusted in packet write */ epb->timestamp_hi = timestamp >>32 ; epb->timestamp_lo = (uint32_t )timestamp; epb->capture_length = pkt_len;
@@ -603,9 +568,56 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,/* set trailer of block length */ *(uint32_t *)opt = epb->block_length; +return 0 ; +} + +/* Make a copy of original mbuf with pcapng header and options */ +RTE_EXPORT_SYMBOL (rte_pcapng_copy) +struct rte_mbuf * +rte_pcapng_copy (uint16_t port_id,uint32_t queue, +const struct rte_mbuf *md, +struct rte_mempool *mp, +uint32_t length, +enum rte_pcapng_direction direction, +const char *comment) +{ +uint32_t orig_len =rte_pktmbuf_pkt_len (md); +struct rte_mbuf *mc; -return mc; +#ifdef RTE_LIBRTE_ETHDEV_DEBUG +RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id,NULL ); +#endif + +/* Take snapshot of the data */ + mc =rte_pktmbuf_copy (md, mp,0 , length); +if (unlikely (mc ==NULL )) +return NULL ; + +/* Expand any offloaded VLAN information */ +if ((direction ==RTE_PCAPNG_DIRECTION_IN && + (md->ol_flags &RTE_MBUF_F_RX_VLAN_STRIPPED )) || + (direction ==RTE_PCAPNG_DIRECTION_OUT && + (md->ol_flags &RTE_MBUF_F_TX_VLAN ))) { +if (pcapng_vlan_insert (mc,RTE_ETHER_TYPE_VLAN , + md->vlan_tci) !=0 ) + goto fail; + } + +if ((direction ==RTE_PCAPNG_DIRECTION_IN && + (md->ol_flags &RTE_MBUF_F_RX_QINQ_STRIPPED )) || + (direction ==RTE_PCAPNG_DIRECTION_OUT && + (md->ol_flags &RTE_MBUF_F_TX_QINQ ))) { +if (pcapng_vlan_insert (mc,RTE_ETHER_TYPE_QINQ , + md->vlan_tci_outer) !=0 ) + goto fail; + } + +/* Interface index is filled in later during write */ + mc->port = port_id; +if (likely (rte_pcapng_insert (mc, queue, direction, orig_len, +rte_get_tsc_cycles (), comment) ==0 )) +return mc; fail:rte_pktmbuf_free (mc);return NULL ;
lib/pcapng/rte_pcapng.h +25 -2
@@ -99,7 +99,7 @@ enum rte_pcapng_direction { };/** -* Format an mbuf for writing to file. +* Make a copy of mbuf for writing to file. * * @param port_id * The Ethernet port on which packet was received
@@ -117,7 +117,7 @@ enum rte_pcapng_direction {* @param direction * The direction of the packer: receive, transmit or unknown. * @param comment -* Packet comment. +* Packet comment (optional). * * @return * - The pointer to the new mbuf formatted for pcapng_write
@@ -129,6 +129,29 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,uint32_t length, enum rte_pcapng_direction direction, const char *comment); +/** +* Format an mbuf for writing to file. +* +* @param m +* The mbuf to modify. +* @param queue +* The queue on the Ethernet port where packet was received +* or is going to be transmitted. +* @param direction +* The direction of the packer: receive, transmit or unknown. +* @param orig_len +* The length of the original packet which maybe less than actual +* packet if only a snapshot was captured. +* @param timestamp +* The timestamp for packet in TSC cycles. +* @param comment +* Packet comment (optional). +*/ +__rte_experimental +int +rte_pcapng_insert (struct rte_mbuf *m,uint32_t queue, +enum rte_pcapng_direction direction,uint32_t orig_len, +uint64_t timestamp,const char *comment);/** * Determine optimum mbuf data size.
Signature · 1 line
2.47.2
PATCH v5 9/13 pcapng: make queue optional
In reply to Stephen HemmingerThe queue field is optional in pcapng received packet. Use UINT16_MAX as flag value.
--- lib/pcapng/rte_pcapng.c | 7 ++++--- lib/pcapng/rte_pcapng.h | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-)
lib/pcapng/rte_pcapng.c +4 -3
@@ -500,8 +500,8 @@ rte_pcapng_insert(struct rte_mbuf *m, uint32_t queue,uint16_t optlen =pcapng_optlen (sizeof (flags)); -/* make queue optional? */ - optlen +=pcapng_optlen (sizeof (queue)); +if (queue !=UINT16_MAX ) + optlen +=pcapng_optlen (sizeof (queue));/* does packet have valid RSS hash to include */ bool rss_hash = (direction == RTE_PCAPNG_DIRECTION_IN &&
@@ -531,7 +531,8 @@ rte_pcapng_insert(struct rte_mbuf *m, uint32_t queue, } opt =pcapng_add_option (opt,PCAPNG_EPB_FLAGS , &flags,sizeof (flags)); - opt =pcapng_add_option (opt,PCAPNG_EPB_QUEUE , &queue,sizeof (queue)); +if (queue !=UINT16_MAX ) + opt =pcapng_add_option (opt,PCAPNG_EPB_QUEUE , &queue,sizeof (queue));if (rss_hash) {uint8_t hash_opt[5 ];
lib/pcapng/rte_pcapng.h +2 -2
@@ -135,8 +135,8 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,* @param m * The mbuf to modify. * @param queue -* The queue on the Ethernet port where packet was received -* or is going to be transmitted. +* The queue on the Ethernet port where packet was received or is going to be transmitted. +* Optional: use UINT16_MAX if not specified. * @param direction * The direction of the packer: receive, transmit or unknown. * @param orig_len
Signature · 1 line
2.47.2
PATCH v5 10/13 test: add tests for ethdev mirror
In reply to Stephen HemmingerSimple API and packet mirroring standalone tests.
--- app/test/meson.build | 1 + app/test/test_ethdev_mirror.c | 286 ++++++++++++++++++++++++++++++++++ 2 files changed, 287 insertions(+) create mode 100644 app/test/test_ethdev_mirror.c
app/test/meson.build +1 -0
@@ -73,6 +73,7 @@ source_file_deps = { 'test_errno.c': [], 'test_ethdev_api.c': ['ethdev'], 'test_ethdev_link.c': ['ethdev'], + 'test_ethdev_mirror.c': ['net_ring', 'ethdev', 'bus_vdev'], 'test_event_crypto_adapter.c': ['cryptodev', 'eventdev', 'bus_vdev'], 'test_event_dma_adapter.c': ['dmadev', 'eventdev', 'bus_vdev'], 'test_event_eth_rx_adapter.c': ['ethdev', 'eventdev', 'bus_vdev'],
app/test/test_ethdev_mirror.c new file +286 -0
286 lines not on this page · raw message
Signature · 1 line
2.47.2
PATCH v5 11/13 app/testpmd: support for port mirroring
In reply to Stephen HemmingerAdd new commands to enable testing of port mirror functionality.
--- app/test-pmd/cmdline.c | 1 + app/test-pmd/cmdline_mirror.c | 129 ++++++++++++++++++++ app/test-pmd/cmdline_mirror.h | 12 ++ app/test-pmd/meson.build | 1 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 15 +++ 5 files changed, 158 insertions(+) create mode 100644 app/test-pmd/cmdline_mirror.c create mode 100644 app/test-pmd/cmdline_mirror.h
app/test-pmd/cmdline.c +1 -0
@@ -66,6 +66,7 @@#include "testpmd.h" #include "cmdline_cman.h" #include "cmdline_mtr.h" +#include "cmdline_mirror.h" #include "cmdline_tm.h" #include "bpf_cmd.h"
app/test-pmd/cmdline_mirror.c new file +129 -0
129 lines not on this page · raw message
app/test-pmd/cmdline_mirror.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Stephen Hemminger <[email protected]> +*/ + +#ifndef _CMDLINE_MIRROR_H_ +#define _CMDLINE_MIRROR_H_ + +/* Port MIRROR commands */ +extern cmdline_parse_inst_t cmd_create_port_mirror; +extern cmdline_parse_inst_t cmd_disable_port_mirror; + +#endif /* _CMDLINE_MIRROR_H_ */
app/test-pmd/meson.build +1 -0
@@ -8,6 +8,7 @@ sources = files( 'cmdline.c', 'cmdline_cman.c', 'cmdline_flow.c', + 'cmdline_mirror.c', 'cmdline_mtr.c', 'cmdline_tm.c', 'cmd_flex_item.c',
doc/guides/testpmd_app_ug/testpmd_funcs.rst +15 -0
@@ -2570,6 +2570,21 @@ where: * ``clear``: Flag that indicates whether the statistics counters should be cleared (i.e. set to zero) immediately after they have been read or not. +create mirror +------------- + +Create a new MIRROR port for an ethernet device:: + + testpmd> create port mirror (port_id) destination (port_id) + +delete mirror +------------- + +Delete an existing MIRROR port on ethernet device:: + + testpmd> delete port mirror (port_id) + + Traffic Management ------------------
Signature · 1 line
2.47.2
PATCH v5 12/13 app/dumpcap: use port mirror instead of pdump
In reply to Stephen HemmingerUse the new port mirror API instead of pdump.
--- app/dumpcap/main.c | 443 +++++++++++++++++++++++++++++++++------- app/dumpcap/meson.build | 2 +- 2 files changed, 373 insertions(+), 72 deletions(-)
app/dumpcap/main.c +372 -71
@@ -36,8 +36,6 @@#include <rte_mbuf.h> #include <rte_mempool.h> #include <rte_pcapng.h> -#include <rte_pdump.h> -#include <rte_ring.h> #include <rte_string_fns.h> #include <rte_thread.h> #include <rte_time.h>
@@ -92,16 +90,28 @@ struct capture_options {struct interface {TAILQ_ENTRY (interface) next;uint16_t port; +struct rte_bpf *filter; +uint64_t filteraccept;struct capture_options opts; -struct rte_bpf_prm *bpf_prm;char name[RTE_ETH_NAME_MAX_LEN ]; +struct rte_eth_stats start_stats;const char *ifname;const char *ifdescr; }; +static int timestamp_dynfield =-1 ; +static uint64_t timestamp_dynflag; +static int mirror_origin_dynfield =-1 ; +static uint64_t mirror_origin_dynflag; +static uint64_t mirror_ingress_dynflag; +static uint64_t mirror_egress_dynflag; + +static bool filtering; +TAILQ_HEAD (interface_list, interface);static struct interface_list interfaces =TAILQ_HEAD_INITIALIZER (interfaces); +static struct interface *port2intf[RTE_MAX_ETHPORTS ];/* Can do either pcap or pcapng format output */ typedef union {
@@ -239,14 +249,16 @@ static void find_interfaces(void) TAILQ_FOREACH(intf, &interfaces, next) {/* if name is valid then just record port */ -if (rte_eth_dev_get_port_by_name (intf->name, &intf->port) ==0 ) -continue ; +if (rte_eth_dev_get_port_by_name (intf->name, &intf->port) !=0 ) { +/* maybe got passed port number string as name */ + intf->port =get_uint (intf->name,"port_number" ,UINT16_MAX ); +if (rte_eth_dev_get_name_by_port (intf->port, intf->name) <0 ) +rte_exit (EXIT_FAILURE ,"Invalid port number %u\n" , + intf->port); + } -/* maybe got passed port number string as name */ - intf->port =get_uint (intf->name,"port_number" ,UINT16_MAX ); -if (rte_eth_dev_get_name_by_port (intf->port, intf->name) <0 ) -rte_exit (EXIT_FAILURE ,"Invalid port number %u\n" , - intf->port); +if (rte_eth_stats_get (intf->port, &intf->start_stats) <0 ) +rte_exit (EXIT_FAILURE ,"Could not read stats for port %u\n" , intf->port); } }
@@ -266,6 +278,10 @@ static void set_default_interface(void) intf =add_interface (name); intf->port = p; + +if (rte_eth_stats_get (intf->port, &intf->start_stats) <0 ) +rte_exit (EXIT_FAILURE , +"Could not read stats for port %u\n" , intf->port);return ; }rte_exit (EXIT_FAILURE ,"No usable interfaces found\n" );
@@ -295,10 +311,17 @@ static void compile_filters(void)struct bpf_program bf;pcap_t *pcap; +/* cache for filter packets */ + port2intf[intf->port] = intf; + +if (intf->opts.filter ==NULL ) +continue ; + pcap =pcap_open_dead (DLT_EN10MB , intf->opts.snap_len);if (!pcap)rte_exit (EXIT_FAILURE ,"can not open pcap\n" ); +if (pcap_compile (pcap, &bf, intf->opts.filter,1 ,PCAP_NETMASK_UNKNOWN ) !=0 ) { fprintf(stderr,
@@ -316,7 +339,7 @@ static void compile_filters(void) rte_strerror(rte_errno), rte_errno);if (dump_bpf) { -printf ("cBPF program (%u insns)\n" , bf.bf_len); +printf ("cops program (%u insns)\n" , bf.bf_len);bpf_dump (&bf,1 );printf ("\neBPF program (%u insns)\n" , bpf_prm->nb_ins);
@@ -324,11 +347,18 @@ static void compile_filters(void)exit (0 ); } - intf->bpf_prm = bpf_prm; + + intf->filter =rte_bpf_load (bpf_prm); +if (intf->filter ==NULL ) +rte_exit (EXIT_FAILURE , +"BPF load failed '%s'\n%s(%d)\n" , + intf->name,rte_strerror (rte_errno), rte_errno);/* Don't care about original program any more */ pcap_freecode (&bf);pcap_close (pcap); + + filtering = true; } }
@@ -518,13 +548,12 @@ static void statistics_loop(void) }static void -cleanup_pdump_resources (void ) +disable_mirror_ports (uint16_t mirror_port) {struct interface *intf; TAILQ_FOREACH(intf, &interfaces, next) { -rte_pdump_disable (intf->port, -RTE_PDUMP_ALL_QUEUES ,RTE_PDUMP_FLAG_RXTX ); +rte_eth_remove_mirror (intf->port, mirror_port);if (intf->opts.promisc_mode)rte_eth_promiscuous_disable (intf->port); }
@@ -552,7 +581,6 @@ enable_primary_monitor(void) {int ret; -/* Once primary exits, so will pdump. */ ret =rte_eal_alarm_set (MONITOR_INTERVAL , monitor_primary,NULL );if (ret <0 )fprintf (stderr,"Fail to enable monitor:%d\n" , ret);
@@ -571,23 +599,24 @@ disable_primary_monitor(void)static void report_packet_stats (dumpcap_out_t out) { -struct rte_pdump_stats pdump_stats;struct interface *intf; -uint64_t ifrecv, ifdrop; -double percent;fputc ('\n' , stderr); + TAILQ_FOREACH(intf, &interfaces, next) { -if (rte_pdump_stats (intf->port, &pdump_stats) <0 ) +uint64_t ifrecv, ifdrop; +struct rte_eth_stats stats; +double percent; + +if (rte_eth_stats_get (intf->port, &stats) <0 )continue ; -/* do what Wiretap does */ - ifrecv = pdump_stats.accepted + pdump_stats.filtered; - ifdrop = pdump_stats.nombuf + pdump_stats.ringfull; + ifrecv = stats.ipackets - intf->start_stats.ipackets; + ifdrop = (stats.rx_nombuf - intf->start_stats.rx_nombuf) + + (stats.imissed - intf->start_stats.imissed);if (use_pcapng) -rte_pcapng_write_stats (out.pcapng, intf->port, - ifrecv, ifdrop,NULL ); +rte_pcapng_write_stats (out.pcapng, intf->port, ifrecv, ifdrop,NULL );if (ifrecv ==0 ) percent =0 ;
@@ -668,12 +697,21 @@ static void dpdk_init(void)rte_exit (EXIT_FAILURE ,"Can not restore original CPU affinity\n" ); } -/* Create packet ring shared between callbacks and process */ -static struct rte_ring *create_ring (void ) +/* Create ring port to redirect packet to. +* This could be much simpler if the ring PMD API (rte_eth_from_rings) +* worked from a secondary process, but it doesn't. +*/ +static struct rte_ring * +create_ring_dev (char *vdev_name,uint16_t *mirror_port) { -struct rte_ring *ring; +struct rte_eth_dev_owner owner = {0 }; +struct rte_eth_conf dev_conf = {0 }; +struct rte_ring *ring =NULL ;char ring_name[RTE_RING_NAMESIZE ]; +char vdev_args[128 ];size_t size, log2; +uint16_t port; +int ret;/* Find next power of 2 >= size. */ size = ring_size;
@@ -686,17 +724,59 @@ static struct rte_ring *create_ring(void) ring_size = size; } -/* Want one ring per invocation of program */ -snprintf (ring_name,sizeof (ring_name), -"dumpcap-%d" ,getpid ()); +/* Use owner as unique Id for ring and to isolate */ + ret =rte_eth_dev_owner_new (&owner.id); +if (ret <0 ) +rte_exit (EXIT_FAILURE ,"rte_eth_dev_owner_new failed: %s\n" , +strerror (-ret)); - ring =rte_ring_create (ring_name, ring_size, -rte_socket_id (),0 ); +/* Give the vdev a unique name */ +snprintf (ring_name,sizeof (ring_name),"dumpcap%" PRIu64, owner.id); + ring =rte_ring_create (ring_name, ring_size,rte_socket_id (), +RING_F_MP_RTS_ENQ |RING_F_SC_DEQ );if (ring ==NULL )rte_exit (EXIT_FAILURE ,"Could not create ring :%s\n" ,rte_strerror (rte_errno)); +strlcpy (owner.name, ring_name,sizeof (owner.name)); + +snprintf (vdev_name,RTE_DEV_NAME_MAX_LEN ,"net_ring-dumpcap%" PRIu64, owner.id); +snprintf (vdev_args,sizeof (vdev_args),"ring=%s" , ring_name); + +if (rte_eal_hotplug_add ("vdev" , vdev_name, vdev_args) <0 ) +rte_exit (EXIT_FAILURE , +"rte_eal_hotplug_add of %s failed:%s\n" , + vdev_name,rte_strerror (rte_errno)); + + ret =rte_eth_dev_get_port_by_name (vdev_name, &port); +if (ret !=0 ) { +fprintf (stderr,"Could not port for %s: %s\n" , + vdev_name,strerror (-ret)); + goto unplug; + } + + ret =rte_eth_dev_owner_set (port, &owner); +if (ret !=0 ) { +fprintf (stderr,"Could not set owner for port for %u: %s\n" , + port,strerror (-ret)); + goto unplug; + } + + ret =rte_eth_dev_configure (port,1 ,1 , &dev_conf); +if (ret <0 ) { +fprintf (stderr,"Could not configure port %u: %s\n" , + port,strerror (-ret)); + goto unplug; + } + + *mirror_port = port;return ring; + +unplug: +rte_eal_hotplug_remove ("vdev" , vdev_name); +rte_ring_free (ring); +rte_eal_cleanup (); +exit (EXIT_FAILURE ); }static struct rte_mempool *create_mempool (void )
@@ -796,7 +876,7 @@ static dumpcap_out_t create_output(void) version(), capture_comment);if (ret.pcapng ==NULL )rte_exit (EXIT_FAILURE ,"pcapng_fdopen failed: %s\n" , -strerror (rte_errno)); +rte_strerror (rte_errno));free (os); TAILQ_FOREACH(intf, &interfaces, next) {
@@ -823,37 +903,32 @@ static dumpcap_out_t create_output(void)return ret; } -static void enable_pdump (struct rte_ring *r,struct rte_mempool *mp) +static int enable_mirror (uint16_t mirror_port,struct rte_mempool *mpool) {struct interface *intf;unsigned int count =0 ; -uint32_t flags;int ret; - flags =RTE_PDUMP_FLAG_RXTX ; -if (use_pcapng) - flags |=RTE_PDUMP_FLAG_PCAPNG ; + ret =rte_eth_dev_start (mirror_port); +if (ret <0 ) +rte_exit (EXIT_FAILURE ,"Could not start mirror port %u: %s\n" , + mirror_port,strerror (-ret)); TAILQ_FOREACH(intf, &interfaces, next) { - ret =rte_pdump_enable_bpf (intf->port,RTE_PDUMP_ALL_QUEUES , - flags, intf->opts.snap_len, - r, mp, intf->bpf_prm); +struct rte_eth_mirror_conf conf = { + .mp = mpool, + .target = mirror_port, + .snaplen = intf->opts.snap_len, + .flags =RTE_ETH_MIRROR_ORIGIN_FLAG |RTE_ETH_MIRROR_TIMESTAMP_FLAG , + .direction =RTE_ETH_MIRROR_DIRECTION_INGRESS | +RTE_ETH_MIRROR_DIRECTION_EGRESS , + }; + + ret =rte_eth_add_mirror (intf->port, &conf);if (ret <0 ) { -const struct interface *intf2; - -/* unwind any previous enables */ - TAILQ_FOREACH(intf2, &interfaces, next) { -if (intf == intf2) -break ; -rte_pdump_disable (intf2->port, -RTE_PDUMP_ALL_QUEUES ,RTE_PDUMP_FLAG_RXTX ); -if (intf2->opts.promisc_mode) -rte_eth_promiscuous_disable (intf2->port); - } -rte_exit (EXIT_FAILURE , -"Packet dump enable on %u:%s failed %s\n" , - intf->port, intf->name, -rte_strerror (rte_errno)); +fprintf (stderr,"Port mirror on %u:%s failed %s\n" , + intf->port, intf->name,strerror (-ret)); +return -1 ; }if (intf->opts.promisc_mode) {
@@ -868,6 +943,60 @@ static void enable_pdump(struct rte_ring *r, struct rte_mempool *mp) } ++count; } +return count; +} + +static int setup_mbuf (void ) +{ +int offset; + + offset =rte_mbuf_dynfield_lookup (RTE_MBUF_DYNFIELD_TIMESTAMP_NAME ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find timestamp dynamic field\n" ); +return -1 ; + } + timestamp_dynfield = offset; + + offset =rte_mbuf_dynflag_lookup (RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find timestamp flag\n" ); +return -1 ; + } + timestamp_dynflag =RTE_BIT64 (offset); + + offset =rte_mbuf_dynfield_lookup (RTE_MBUF_DYNFIELD_MIRROR_ORIGIN ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find mirror origin dynamic field\n" ); +return -1 ; + } + mirror_origin_dynfield = offset; + + offset =rte_mbuf_dynflag_lookup (RTE_MBUF_DYNFLAG_MIRROR_ORIGIN ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find mirror origin dynamic flag\n" ); +return -1 ; + } + mirror_origin_dynflag =RTE_BIT64 (offset); + + offset =rte_mbuf_dynflag_lookup (RTE_MBUF_DYNFLAG_MIRROR_INGRESS ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find mirror ingress flag\n" ); +return -1 ; + } + mirror_ingress_dynflag =RTE_BIT64 (offset); + + offset =rte_mbuf_dynflag_lookup (RTE_MBUF_DYNFLAG_MIRROR_EGRESS ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find mirror egress flag\n" ); +return -1 ; + } + mirror_egress_dynflag =RTE_BIT64 (offset); +return 0 ; +} + +static void show_capturing (unsigned int count) +{ +struct interface *intf;fputs ("Capturing on " , stdout); TAILQ_FOREACH(intf, &interfaces, next) {
@@ -898,6 +1027,47 @@ static void show_count(uint64_t count) bt =fprintf (stderr,"%" PRIu64" " , count); } +static ssize_t +pcapng_write_packets (rte_pcapng_t *pcapng,struct rte_mbuf *pkts[],uint16_t n) +{ +struct rte_mbuf *towrite[BURST_SIZE ]; +unsigned int count =0 ; + +for (unsigned int i =0 ; i < n; i++) { +struct rte_mbuf *m = pkts[i]; +enum rte_pcapng_direction direction =RTE_PCAPNG_DIRECTION_UNKNOWN ; + +/* If no origin flag then why did we get this? */ +if (unlikely (!(m->ol_flags & mirror_origin_dynflag))) { +fprintf (stderr,"Missing origin info in packet\n" ); +return -1 ; + } + +const struct rte_mbuf_origin *origin + = RTE_MBUF_DYNFIELD(m, mirror_origin_dynfield, rte_mbuf_origin_t *); + +if (m->ol_flags & mirror_ingress_dynflag) + direction =RTE_PCAPNG_DIRECTION_IN ; +else if (m->ol_flags & mirror_egress_dynflag) + direction =RTE_PCAPNG_DIRECTION_OUT ; + +uint64_t timestamp; +if (m->ol_flags & timestamp_dynflag) + timestamp = *RTE_MBUF_DYNFIELD (m, timestamp_dynfield, + rte_mbuf_timestamp_t *); +else + timestamp =rte_get_tsc_cycles (); + +if (rte_pcapng_insert (m, origin->queue_id, direction, origin->original_len, + timestamp,NULL ) <0 ) +continue ;/* skip no headroom? */ + + towrite[count++] = m; + } + +return rte_pcapng_write_packets (pcapng, towrite, count); +} +/* Write multiple packets in older pcap format */ static ssize_t pcap_write_packets(pcap_dumper_t *dumper,
@@ -930,16 +1100,127 @@ pcap_write_packets(pcap_dumper_t *dumper,return total; } +/* Do packet filter on incoming packets. +* Some issues to note here: +* - would be better to do before putting into ring +* but that causes ethdev to have dependency on BPF. +* - the filter is per-interface and there maybe more than one interface +* combined into the ring. That means filter is executed once +* per packet (not as burst). +*/ +static unsigned int +filter_packets (struct rte_mbuf *pkts[],unsigned int n) +{ +uint64_t results[BURST_SIZE ]; +uint32_t matches =0 ; + +for (unsigned int i =0 ; i < n; i++) { +struct rte_mbuf *m = pkts[i]; + +/* all packets should have origin info, if not just skip */ +if (unlikely (!(m->ol_flags & mirror_origin_dynflag))) +continue ; + +const struct rte_mbuf_origin *origin + = RTE_MBUF_DYNFIELD(m, mirror_origin_dynfield, rte_mbuf_origin_t *); +uint16_t port_id = origin->port_id; + +if (unlikely (port_id >=RTE_MAX_ETHPORTS )) +continue ; + +const struct interface *intf = port2intf[port_id]; +if (intf ==NULL || intf->filter ==NULL ) +continue ; + +if (rte_bpf_exec_burst (intf->filter, (void **)&m, &results[i],1 ) ==1 ) + ++matches; + } + +if (matches == n) +return n;/* no packets skipped */ + +/* need to shuffle out the skipped packets */ +unsigned int count =0 ; +struct rte_mbuf *towrite[BURST_SIZE ]; +for (unsigned int i =0 ; i < n; i++) { +if (results[i]) + towrite[count++] = pkts[i]; +else +rte_pktmbuf_free (pkts[i]); + } +memcpy (pkts, towrite, count *sizeof (struct rte_mbuf *)); +return count; +} + +/* Make sure configuration of mbuf pool has enough headroom for both vlans */ +static_assert (RTE_PKTMBUF_HEADROOM >2 *sizeof (struct rte_vlan_hdr ), +"not enough mbuf headroom for vlan insertion" ); + +/* +* More general version of rte_vlan_insert() +* Note: mbufs are allocated by rte_eth_mirror_burst() from the +* pool that was passed when setting up mirror. +*/ +static void +vlan_insert (struct rte_mbuf *m,uint16_t ether_type,uint16_t tci) +{ +struct rte_ether_hdr *nh, tmph; +const struct rte_ether_hdr *oh; +struct rte_vlan_hdr *vh; + +RTE_ASSERT (!RTE_MBUF_DIRECT (m)); +RTE_ASSERT (rte_mbuf_refcnt_read (m) ==1 ); + + oh =rte_pktmbuf_read (m,0 ,sizeof (*oh), &tmph); +RTE_ASSERT (oh !=NULL ); + +/* overlay new header */ + nh = (struct rte_ether_hdr *) +rte_pktmbuf_prepend (m,sizeof (struct rte_vlan_hdr )); + +RTE_ASSERT (nh !=NULL ); + +memmove (nh, oh,2 *RTE_ETHER_ADDR_LEN ); + nh->ether_type =rte_cpu_to_be_16 (ether_type); + + vh = (struct rte_vlan_hdr *) (nh +1 ); + vh->vlan_tci =rte_cpu_to_be_16 (tci); +} + +/* Filtering and pcap file format require that VLAN not be offloaded */ +static void +remove_vlan_offload (struct rte_mbuf *pkts[],unsigned int n) +{ +unsigned int i; + +for (i =0 ; i < n; i++) { +struct rte_mbuf *m = pkts[i]; + +if (m->ol_flags & mirror_ingress_dynflag) { +if (m->ol_flags &RTE_MBUF_F_RX_VLAN_STRIPPED ) +vlan_insert (m,RTE_ETHER_TYPE_VLAN , m->vlan_tci); +if (m->ol_flags &RTE_MBUF_F_RX_QINQ_STRIPPED ) +vlan_insert (m,RTE_ETHER_TYPE_QINQ , m->vlan_tci_outer); + } +if (m->ol_flags & mirror_egress_dynflag) { +if (m->ol_flags &RTE_MBUF_F_TX_VLAN ) +vlan_insert (m,RTE_ETHER_TYPE_VLAN , m->vlan_tci); +if (m->ol_flags &RTE_MBUF_F_TX_QINQ ) +vlan_insert (m,RTE_ETHER_TYPE_QINQ , m->vlan_tci_outer); + + } + } +} +/* Process all packets in ring and dump to capture file */ -static int process_ring (dumpcap_out_t out,struct rte_ring *r) +static int process_ring (dumpcap_out_t out,struct rte_ring *ring) {struct rte_mbuf *pkts[BURST_SIZE ]; -unsigned int avail, n; +unsigned int n, avail;static unsigned int empty_count;ssize_t written; - n =rte_ring_sc_dequeue_burst (r, (void **) pkts,BURST_SIZE , - &avail); + n =rte_ring_sc_dequeue_burst (ring, (void **)pkts,BURST_SIZE , &avail);if (n ==0 ) {/* don't consume endless amounts of cpu if idle */ if (empty_count <SLEEP_THRESHOLD )
@@ -948,11 +1229,18 @@ static int process_ring(dumpcap_out_t out, struct rte_ring *r)usleep (10 );return 0 ; } - empty_count = (avail ==0 ); +remove_vlan_offload (pkts, n); + +if (filtering) { + n =filter_packets (pkts, n); +if (n ==0 ) +return 0 ; + } +if (use_pcapng) - written =rte_pcapng_write_packets (out.pcapng, pkts, n); + written =pcapng_write_packets (out.pcapng, pkts, n);else written =pcap_write_packets (out.dumper, pkts, n);
@@ -971,15 +1259,18 @@ static int process_ring(dumpcap_out_t out, struct rte_ring *r)int main (int argc,char **argv) { -struct rte_ring *r;struct rte_mempool *mp;struct sigaction action = { .sa_flags =SA_RESTART , .sa_handler = signal_handler, };struct sigaction origaction; +struct rte_ring *ring =NULL ; +char vdev_name[RTE_DEV_NAME_MAX_LEN ]; +uint16_t mirror_port =UINT16_MAX ;dumpcap_out_t out;char *p; +int ret; p =strrchr (argv[0 ],'/' );if (p ==NULL )
@@ -1018,12 +1309,21 @@ int main(int argc, char **argv)exit (0 ); } - r =create_ring (); mp =create_mempool (); + ring =create_ring_dev (vdev_name, &mirror_port); out =create_output (); + ret =enable_mirror (mirror_port, mp); +if (ret <0 ) + goto cleanup; + + ret =setup_mbuf (); +if (ret <0 ) + goto cleanup; + +show_capturing (ret); + start_time =time (NULL ); -enable_pdump (r, mp);if (!quiet) {fprintf (stderr,"Packets captured: " );
@@ -1031,7 +1331,7 @@ int main(int argc, char **argv) }while (!rte_atomic_load_explicit (&quit_signal, rte_memory_order_relaxed)) { -if (process_ring (out, r) <0 ) { +if (process_ring (out, ring) <0 ) {fprintf (stderr,"pcapng file write failed; %s\n" ,strerror (errno));break ;
@@ -1048,19 +1348,20 @@ int main(int argc, char **argv)break ; } -disable_primary_monitor (); -if (rte_eal_primary_proc_alive (NULL ))report_packet_stats (out); +cleanup:if (use_pcapng)rte_pcapng_close (out.pcapng);else pcap_dump_close (out.dumper); -cleanup_pdump_resources (); +disable_primary_monitor (); +disable_mirror_ports (mirror_port); -rte_ring_free (r); +rte_eal_hotplug_remove ("vdev" , vdev_name); +rte_ring_free (ring);rte_mempool_free (mp);return rte_eal_cleanup () ?EXIT_FAILURE :0 ;
app/dumpcap/meson.build +1 -1
@@ -14,4 +14,4 @@ endif ext_deps += pcap_dep sources = files('main.c') -deps += ['ethdev', 'pdump', 'pcapng', 'bpf'] +deps += ['net_ring', 'ethdev', 'pcapng', 'bpf']
Signature · 1 line
2.47.2
PATCH v5 13/13 pdump: mark API and application as deprecated
In reply to Stephen HemmingerWhen the pdump application is run print a warning. Add release note about deprecation and mark the API's as deprecated.
--- app/pdump/main.c | 3 +++ app/pdump/meson.build | 1 + app/test-pmd/meson.build | 1 + app/test/meson.build | 6 +++++- doc/guides/howto/packet_capture_framework.rst | 15 +++++++++------ doc/guides/nics/bnxt.rst | 2 +- doc/guides/prog_guide/ethdev/index.rst | 1 + doc/guides/prog_guide/pdump_lib.rst | 4 ++++ doc/guides/rel_notes/deprecation.rst | 3 +++ doc/guides/tools/pdump.rst | 2 ++ lib/pdump/rte_pdump.h | 12 +++++++++--- 11 files changed, 39 insertions(+), 11 deletions(-)
app/pdump/main.c +3 -0
@@ -986,6 +986,9 @@ main(int argc, char **argv)char mp_flag[] ="--proc-type=secondary" ;char *argp[argc +2 ]; + +fprintf (stderr,"%s: is deprecated use dpdk-dumpcap instead\n" , argv[0 ]); +/* catch ctrl-c so we can cleanup on exit */ sigemptyset (&action.sa_mask);sigaction (SIGTERM , &action,NULL );
app/pdump/meson.build +1 -0
@@ -11,3 +11,4 @@ sources = files('main.c') deps += ['ethdev', 'kvargs', 'pdump'] cflags += no_wvla_cflag +cflags += '-Wno-deprecated-declarations'
app/test-pmd/meson.build +1 -0
@@ -60,6 +60,7 @@ if dpdk_conf.has('RTE_LIB_METRICS') endif if dpdk_conf.has('RTE_LIB_PDUMP') deps += 'pdump' + cflags += '-Wno-deprecated-declarations' endif if dpdk_conf.has('RTE_NET_BNXT') deps += 'net_bnxt'
app/test/meson.build +5 -1
@@ -138,7 +138,6 @@ source_file_deps = { 'test_net_ip6.c': ['net'], 'test_pcapng.c': ['ethdev', 'net', 'pcapng', 'bus_vdev'], 'test_pdcp.c': ['eventdev', 'pdcp', 'net', 'timer', 'security'], - 'test_pdump.c': ['pdump'] + sample_packet_forward_deps, 'test_per_lcore.c': [], 'test_pflock.c': [], 'test_pie.c': ['sched'],
@@ -217,6 +216,11 @@ source_file_ext_deps = { 'test_pcapng.c': ['pcap'], } +if dpdk_conf.has('RTE_LIB_PDUMP') + source_file_deps += { 'test_pdump.c': ['pdump'] + sample_packet_forward_deps, } + cflags += '-Wno-deprecated-declarations' +endif + def_lib = get_option('default_library') foreach f, f_deps : source_file_deps has_deps = true
doc/guides/howto/packet_capture_framework.rst +9 -6
@@ -10,11 +10,11 @@ for users of DPDK who want to know more about the Packet Capture feature and for those who want to monitor traffic on DPDK-controlled devices. The DPDK packet capture framework was introduced in DPDK v16.07 -and enhanced in 21.11. +and enhanced in 21.11, and deprecated in 25.11. It is superseded +by the new port mirroring facility of ethdev. + The DPDK packet capture framework consists of the libraries -for collecting packets ``librte_pdump`` -and writing packets to a file ``librte_pcapng``. -There are two sample applications: ``dpdk-dumpcap`` and older ``dpdk-pdump``. +for collecting packets ``librte_pdump`` and an application ``dpdk-pdump``. Introduction ------------
@@ -49,10 +49,13 @@ and then to the Pcapng file. Some things to note: -* All tools using ``librte_pdump`` can only be used in conjunction with a primary +* The ``dpdk-dumpcap`` tool used the ethdev port mirror functionality + to transparently mirror packets to an internal ring device. + +* Older tools using ``librte_pdump`` can only be used in conjunction with a primary application which has the packet capture framework initialized already. In dpdk, only ``testpmd`` is modified to initialize packet capture framework, - other applications remain untouched. So, if the ``dpdk-dumpcap`` tool has to + other applications remain untouched. So, if the ``dpdk-pdump`` tool has to be used with any application other than the testpmd, the user needs to explicitly modify that application to call the packet capture framework initialization code. Refer to the ``app/test-pmd/testpmd.c`` code and look
doc/guides/nics/bnxt.rst +1 -1
@@ -723,7 +723,7 @@ Note that the applications cannot update the firmware using BNXT PMD. Multiple Processes ~~~~~~~~~~~~~~~~~~ -When two or more DPDK applications (e.g., testpmd and dpdk-pdump) share a single +When two or more DPDK applications (e.g., testpmd and dpdk-dumpcap) share a single instance of DPDK, the BNXT PMD supports a single primary application and one or more secondary applications. Note that the DPDK-layer (not the PMD) ensures there is only one primary application.
doc/guides/prog_guide/ethdev/index.rst +1 -0
@@ -10,6 +10,7 @@ Ethernet Device Library ethdev switch_representation flow_offload + port_mirroring traffic_metering_and_policing traffic_management qos_framework
doc/guides/prog_guide/pdump_lib.rst +4 -0
@@ -9,6 +9,10 @@ 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. +This library is now deprecated becuase it depends on rx and tx callbacks +which will not work if rx or tx is done by secondary process. Use the +Port Mirroring functionality of ethdev instead. + The library uses a generic multi process channel to facilitate communication between primary and secondary process for enabling/disabling packet capture on ports.
doc/guides/rel_notes/deprecation.rst +3 -0
@@ -152,3 +152,6 @@ Deprecation Notices * bus/vmbus: Starting DPDK 25.11, all the vmbus API defined in ``drivers/bus/vmbus/rte_bus_vmbus.h`` will become internal to DPDK. Those API functions are used internally by DPDK core and netvsc PMD. + +* pdump: The pdump API and application have been deprecated and will + be removed in a later release.
doc/guides/tools/pdump.rst +2 -0
@@ -10,6 +10,8 @@ The ``dpdk-pdump`` tool is a Data Plane Development Kit (DPDK) tool that runs as a DPDK secondary process and is capable of enabling packet capture on dpdk ports. .. Note:: + * The ``dpdk-pdump`` is deprecated, use ``dpdk-dumpcap`` instead. + * The ``dpdk-pdump`` tool can only be used in conjunction with a primary application which has the packet capture framework initialized already. In dpdk, only the ``testpmd`` is modified to initialize packet capture
lib/pdump/rte_pdump.h +9 -3
@@ -39,6 +39,7 @@ enum {* @return * 0 on success, -1 on error */ +__rte_deprecated intrte_pdump_init (void );
@@ -50,6 +51,7 @@ rte_pdump_init(void);* @return * 0 on success, -1 on error */ +__rte_deprecated intrte_pdump_uninit (void );
@@ -75,7 +77,7 @@ rte_pdump_uninit(void);* @return * 0 on success, -1 on error, rte_errno is set accordingly. */ - +__rte_deprecated int rte_pdump_enable(uint16_t port, uint16_t queue, uint32_t flags, struct rte_ring *ring,
@@ -106,6 +108,7 @@ rte_pdump_enable(uint16_t port, uint16_t queue, uint32_t flags,* @return * 0 on success, -1 on error, rte_errno is set accordingly. */ +__rte_deprecated int rte_pdump_enable_bpf(uint16_t port_id, uint16_t queue, uint32_t flags, uint32_t snaplen,
@@ -129,7 +132,7 @@ rte_pdump_enable_bpf(uint16_t port_id, uint16_t queue,* @return * 0 on success, -1 on error, rte_errno is set accordingly. */ - +__rte_deprecated intrte_pdump_disable (uint16_t port,uint16_t queue,uint32_t flags);
@@ -156,7 +159,7 @@ rte_pdump_disable(uint16_t port, uint16_t queue, uint32_t flags);* @return * 0 on success, -1 on error, rte_errno is set accordingly. */ - +__rte_deprecated int rte_pdump_enable_by_deviceid(char *device_id, uint16_t queue, uint32_t flags,
@@ -189,6 +192,7 @@ rte_pdump_enable_by_deviceid(char *device_id, uint16_t queue,* @return * 0 on success, -1 on error, rte_errno is set accordingly. */ +__rte_deprecated int rte_pdump_enable_bpf_by_deviceid(const char *device_id, uint16_t queue, uint32_t flags, uint32_t snaplen,
@@ -215,6 +219,7 @@ rte_pdump_enable_bpf_by_deviceid(const char *device_id, uint16_t queue,* @return * 0 on success, -1 on error, rte_errno is set accordingly. */ +__rte_deprecated intrte_pdump_disable_by_deviceid (char *device_id,uint16_t queue,uint32_t flags);
@@ -243,6 +248,7 @@ struct rte_pdump_stats {* @return * Zero if successful. -1 on error and rte_errno is set. */ +__rte_deprecated intrte_pdump_stats (uint16_t port_id,struct rte_pdump_stats *stats);
Signature · 1 line
2.47.2
v6 cover Packet capture using port mirroring
In reply to Stephen HemmingerThis is a rework of how packet capture is done in DPDK.
The existing mechanism using callbacks has a number of problems:
- can't work when packets are sent and received in secondary process because callbacks only function in the primary process
- requires "opt-in" from application
The new mechanism builds on the concept of port mirroring used in Linux/FreeBSD and also router vendors (SPAN ports).
See: https://en.wikipedia.org/wiki/Port_mirroring for a general description.
The implementation uses two new ethdev API's:
one to add a port mirror, and one to remove it.
The internals of dumpcap are redone but the program command syntax is unchanged (no doc change needed). Using the new mirror mechanism, the dumpcap program creates a port using ring PMD and then directs a port mirror to that new ring PMD instance. Then the packets are extracted from the ring. If capturing on multiple devices, they all get mirrored to the same ring PMD.
The dumpcap program needs to be able to start the ring PMD it created but the existing ethdev API is broken when used from secondary process. One of the patches fixes that, it was also reported previously in Bugzilla.
The mirror API has a restriction that the port being mirrored to must allow lock free transmit. This is because both Rx and Tx as well as multiple queues need to go over the same transmit queue. Although it might be possible to have some complex mapping between multiple ports/queues being mirrored to multiple transmit queues, that gets to be a lot of overhead in API's and implementation. Fixing the ring and null PMD to allow lockless transmit is good enough.
Added tests for the mirror features.
The performance has not been measured but the overhead of checking for mirror port is no more that the overhead of looking at the callback list.
TODO items:
- need release notes for new features (will wait till 25.11)
- more through testing on real hardware
v6 - fix build errors on Windows
- use libpcap BPF not DPDK bpf to allow Windows support.
Stephen Hemminger (13):
ethdev: allow start/stop from secondary process
ethdev: make sure all necessary headers included
test: add test for hotplug and secondary process operations net/ring: allow lockfree transmit if ring supports it net/ring: add new devarg to create vdev from existing ring
mbuf: add dynamic flag for use by port mirroring
ethdev: add port mirroring feature
pcapng: split packet copy from header insertion
pcapng: make queue optional
test: add tests for ethdev mirror
app/testpmd: support for port mirroring app/dumpcap: use port mirror instead of pdump
pdump: mark API and application as deprecated
app/dumpcap/main.c | 468 ++++++++++++++---- app/dumpcap/meson.build | 8 +- app/pdump/main.c | 3 + app/pdump/meson.build | 1 + app/test-pmd/cmdline.c | 1 + app/test-pmd/cmdline_mirror.c | 129 +++++ app/test-pmd/cmdline_mirror.h | 12 + app/test-pmd/meson.build | 2 + app/test/meson.build | 7 +- app/test/test_ethdev_mirror.c | 286 +++++++++++ app/test/test_mp_secondary.c | 51 +- config/rte_config.h | 1 + doc/guides/howto/packet_capture_framework.rst | 15 +- doc/guides/nics/bnxt.rst | 2 +- doc/guides/prog_guide/ethdev/index.rst | 1 + doc/guides/prog_guide/pdump_lib.rst | 4 + doc/guides/rel_notes/deprecation.rst | 3 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 15 + doc/guides/tools/pdump.rst | 2 + drivers/net/ring/rte_eth_ring.c | 49 ++ lib/ethdev/ethdev_driver.c | 11 +- lib/ethdev/ethdev_driver.h | 6 + lib/ethdev/ethdev_private.c | 142 ++++++ lib/ethdev/ethdev_private.h | 29 ++ lib/ethdev/ethdev_trace.h | 17 + lib/ethdev/ethdev_trace_points.c | 6 + lib/ethdev/meson.build | 1 + lib/ethdev/rte_ethdev.c | 101 ++-- lib/ethdev/rte_ethdev.h | 23 +- lib/ethdev/rte_ethdev_core.h | 12 +- lib/ethdev/rte_mirror.c | 375 ++++++++++++++ lib/ethdev/rte_mirror.h | 99 ++++ lib/mbuf/rte_mbuf_dyn.h | 9 + lib/pcapng/rte_pcapng.c | 179 +++---- lib/pcapng/rte_pcapng.h | 27 +- lib/pdump/rte_pdump.h | 12 +- 36 files changed, 1866 insertions(+), 243 deletions(-) create mode 100644 app/test-pmd/cmdline_mirror.c create mode 100644 app/test-pmd/cmdline_mirror.h create mode 100644 app/test/test_ethdev_mirror.c create mode 100644 lib/ethdev/rte_mirror.c create mode 100644 lib/ethdev/rte_mirror.h
Signature · 1 line
2.47.2
PATCH v6 1/13 ethdev: allow start/stop from secondary process
Before this patch if secondary process called start/stop it would only impact the secondary process, the ethdev on the primary process was not started.
With this patch, when start/stop is called from secondary, it calls the primary and does the operation there. The design is generic, and we can later add queue and other operations as needed.
Bugzilla ID: 73
--- lib/ethdev/ethdev_driver.c | 11 ++++- lib/ethdev/ethdev_private.c | 93 +++++++++++++++++++++++++++++++++++++ lib/ethdev/ethdev_private.h | 26 +++++++++++ lib/ethdev/rte_ethdev.c | 84 +++++++++++++++++++-------------- 4 files changed, 177 insertions(+), 37 deletions(-)
lib/ethdev/ethdev_driver.c +10 -1
@@ -114,6 +114,14 @@ rte_eth_dev_allocate(const char *name) goto unlock; } +if (eth_dev_shared_data->allocated_ports ==0 && +rte_mp_action_register (ETHDEV_MP , ethdev_server) && + rte_errno !=ENOTSUP ) { +RTE_ETHDEV_LOG_LINE (ERR , +"Could not start %s service" ,ETHDEV_MP ); + goto unlock; + } + eth_dev =eth_dev_get (port_id); eth_dev->flow_fp_ops = &rte_flow_fp_default_ops;strlcpy (eth_dev->data->name, name,sizeof (eth_dev->data->name));
@@ -282,7 +290,8 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)memset (eth_dev->data,0 ,sizeof (struct rte_eth_dev_data )); eth_dev->data =NULL ; - eth_dev_shared_data->allocated_ports--; +if (--eth_dev_shared_data->allocated_ports ==0 ) +rte_mp_action_unregister (ETHDEV_MP );eth_dev_shared_data_release (); }
lib/ethdev/ethdev_private.c +93 -0
102 lines not on this page · raw message
lib/ethdev/ethdev_private.h +26 -0
@@ -79,4 +79,30 @@ void eth_dev_txq_release(struct rte_eth_dev *dev, uint16_t qid);int eth_dev_rx_queue_config (struct rte_eth_dev *dev,uint16_t nb_queues);int eth_dev_tx_queue_config (struct rte_eth_dev *dev,uint16_t nb_queues); +/* Used to allow start/stop from secondary */ +#define ETHDEV_MP "mp_ethdev" + +enum ethdev_mp_operation { +ETH_REQ_START , +ETH_REQ_STOP , +}; + +struct ethdev_mp_request { +uint16_t operation; +uint16_t port_id; +uint32_t reserved; + +uint8_t config[];/* operation specific */ +}; + +struct ethdev_mp_response { +uint16_t res_op; +uint16_t port_id; +int32_t err_value; +}; + +int ethdev_server (const struct rte_mp_msg *mp_msg,const void *peer); +int ethdev_request (uint16_t port_id,enum ethdev_mp_operation op, +const void *buf,size_t buf_len); +#endif /* _ETH_PRIVATE_H_ */
lib/ethdev/rte_ethdev.c +48 -36
111 lines not on this page · raw message
Signature · 1 line
2.47.2
Re: [PATCH v6 01/13] ethdev: allow start/stop from secondary process
Hi Stephen,
(please see below)
Quoted 116 lines · Stephen Hemminger
Before this patch if secondary process called start/stop it would only impact the secondary process, the ethdev on the primary process was not started.
With this patch, when start/stop is called from secondary, it calls the primary and does the operation there. The design is generic, and we can later add queue and other operations as needed.
Bugzilla ID: 73
Signed-off-by Stephen Hemminger <[email protected]>---
lib/ethdev/ethdev_driver.c | 11 ++++- lib/ethdev/ethdev_private.c | 93 +++++++++++++++++++++++++++++++++++++ lib/ethdev/ethdev_private.h | 26 +++++++++++ lib/ethdev/rte_ethdev.c | 84 +++++++++++++++++++-------------- 4 files changed, 177 insertions(+), 37 deletions(-)lib/ethdev/ethdev_driver.c +10
-1@@ -114,6 +114,14 @@ rte_eth_dev_allocate(const char *name) goto unlock; } +if (eth_dev_shared_data->allocated_ports ==0 && +rte_mp_action_register (ETHDEV_MP , ethdev_server) && + rte_errno !=ENOTSUP ) { +RTE_ETHDEV_LOG_LINE (ERR , +"Could not start %s service" ,ETHDEV_MP ); + goto unlock; + } + eth_dev =eth_dev_get (port_id); eth_dev->flow_fp_ops = &rte_flow_fp_default_ops;strlcpy (eth_dev->data->name, name,sizeof (eth_dev->data->name));@@ -282,7 +290,8 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)memset (eth_dev->data,0 ,sizeof (struct rte_eth_dev_data )); eth_dev->data =NULL ; - eth_dev_shared_data->allocated_ports--; +if (--eth_dev_shared_data->allocated_ports ==0 ) +rte_mp_action_unregister (ETHDEV_MP );eth_dev_shared_data_release (); }lib/ethdev/ethdev_private.c +53
-0@@ -2,6 +2,8 @@* Copyright(c) 2018 Gaëtan Rivet */ +#include <assert.h> +#include <eal_export.h> #include <rte_debug.h> @@ -477,3 +479,94 @@ eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues) dev->data->nb_tx_queues = nb_queues;return 0 ; } + +static int +ethdev_handle_request (const struct ethdev_mp_request *req) +{ +switch (req->operation) { +case ETH_REQ_START : +return rte_eth_dev_start (req->port_id); + +case ETH_REQ_STOP : +return rte_eth_dev_stop (req->port_id); + +default : +return -EINVAL ; + } +} + +static_assert (sizeof (struct ethdev_mp_request ) <=RTE_MP_MAX_PARAM_LEN , +"ethdev MP request bigger than available param space" ); + +static_assert (sizeof (struct ethdev_mp_response ) <=RTE_MP_MAX_PARAM_LEN , +"ethdev MP response bigger than available param space" ); + +int +ethdev_server (const struct rte_mp_msg *mp_msg,const void *peer) +{ +const struct ethdev_mp_request *req + = (const struct ethdev_mp_request *)mp_msg->param; + +struct rte_mp_msg mp_resp = { + .name =ETHDEV_MP , + }; +struct ethdev_mp_response *resp; + + resp = (struct ethdev_mp_response *)mp_resp.param; + mp_resp.len_param =sizeof (*resp); + resp->res_op = req->operation; + +/* recv client requests */ +if (mp_msg->len_param !=sizeof (*req)) + resp->err_value = -EINVAL ; +else + resp->err_value =ethdev_handle_request (req); + +return rte_mp_reply (&mp_resp, peer); +} + +int +ethdev_request (uint16_t port_id,enum ethdev_mp_operation operation, +const void *buf,size_t buf_len) +{ +struct rte_mp_msg mp_req = { };
lib/ethdev/ethdev_private.c eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues) · line 542
Quoted 10 lines
lib/ethdev/ethdev_private.c +10
-0+struct rte_mp_reply mp_reply; +struct ethdev_mp_request *req; +struct timespec ts = {.tv_sec =5 , .tv_nsec =0 }; +int ret; + +if (sizeof (*req) + buf_len >RTE_MP_MAX_PARAM_LEN ) { +RTE_ETHDEV_LOG_LINE (ERR , +"request %u port %u invalid len %zu" , + operation, port_id, buf_len); +return -EINVAL ;
A couple of lines below 'resp->err_value' is used to set 'rte_errno'. Why not also set it here then? May be I'm wrong. Or may be set it in (ret < 0) check?
Quoted 12 lines
lib/ethdev/ethdev_private.c +12
-0+ } + +strlcpy (mp_req.name,ETHDEV_MP ,RTE_MP_MAX_NAME_LEN ); + mp_req.len_param =sizeof (*req) + buf_len; + + req = (struct ethdev_mp_request *)mp_req.param; + req->operation = operation; + req->port_id = port_id; + +if (buf_len >0 ) +memcpy (req->config, buf, buf_len); +
lib/ethdev/ethdev_private.c eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues) · line 564
Quoted 10 lines
lib/ethdev/ethdev_private.c +10
-0+ ret =rte_mp_request_sync (&mp_req, &mp_reply, &ts); +if (ret ==0 ) { +const struct rte_mp_msg *mp_rep = &mp_reply.msgs[0 ]; +const struct ethdev_mp_response *resp + = (const struct ethdev_mp_response *)mp_rep->param; + +if (resp->err_value ==0 ) + ret =0 ; +else + rte_errno = -resp->err_value;
By the looks of it, this check sets 'ret = 0' when it is already 0 and, at the same time, when 'resp->err_value' is non-zero, does not override 'ret' with it. I apologise in case I've got this wrong.
Quoted 48 lines
lib/ethdev/ethdev_private.c +8
-0+free (mp_reply.msgs); + } + +if (ret <0 ) +RTE_ETHDEV_LOG_LINE (ERR , +"port %up ethdev op %u failed" , port_id, operation); +return ret; +}lib/ethdev/ethdev_private.h +26
-0@@ -79,4 +79,30 @@ void eth_dev_txq_release(struct rte_eth_dev *dev, uint16_t qid);int eth_dev_rx_queue_config (struct rte_eth_dev *dev,uint16_t nb_queues);int eth_dev_tx_queue_config (struct rte_eth_dev *dev,uint16_t nb_queues); +/* Used to allow start/stop from secondary */ +#define ETHDEV_MP "mp_ethdev" + +enum ethdev_mp_operation { +ETH_REQ_START , +ETH_REQ_STOP , +}; + +struct ethdev_mp_request { +uint16_t operation; +uint16_t port_id; +uint32_t reserved; + +uint8_t config[];/* operation specific */ +}; + +struct ethdev_mp_response { +uint16_t res_op; +uint16_t port_id; +int32_t err_value; +}; + +int ethdev_server (const struct rte_mp_msg *mp_msg,const void *peer); +int ethdev_request (uint16_t port_id,enum ethdev_mp_operation op, +const void *buf,size_t buf_len); +#endif /* _ETH_PRIVATE_H_ */ lib/ethdev/rte_ethdev.c +0
-0
lib/ethdev/rte_ethdev.c rte_eth_dev_start(uint16_t port_id) · line 1804
Quoted 7 lines
lib/ethdev/rte_ethdev.c +2
-2@@ -1800,54 +1800,61 @@ rte_eth_dev_start(uint16_t port_id)if (dev->data->dev_configured ==0 ) {RTE_ETHDEV_LOG_LINE (INFO , -"Device with port_id=%" PRIu16" is not configured." , - port_id); +"Device with port_id=%" PRIu16" is not configured." , + port_id);
On the one hand, it's great that an improvement is being offered. On the other hand, one may argue this is unrelated to the stated purpose of the patch. And, finally, may be placing it 'RTE_ETHDEV_LOG_LINE(INFO, "Device with...' would also work and not trigger a checkpatch warning, but I may be wrong.
lib/ethdev/rte_ethdev.c rte_eth_dev_start(uint16_t port_id) · line 1811
Quoted 9 lines
lib/ethdev/rte_ethdev.c +2
-2return -EINVAL ; }if (dev->data->dev_started !=0 ) {RTE_ETHDEV_LOG_LINE (INFO , -"Device with port_id=%" PRIu16" already started" , - port_id); +"Device with port_id=%" PRIu16" already started" , + port_id);
Same here. But it's all up to you.
lib/ethdev/rte_ethdev.c rte_eth_dev_start(uint16_t port_id) · line 1815
Quoted 7 lines
lib/ethdev/rte_ethdev.c +1
-3return 0 ; } - ret =rte_eth_dev_info_get (port_id, &dev_info); -if (ret !=0 ) -return ret; +if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) {
May be move the 'struct rte_eth_dev_info dev_info;' from above to over here.
Thank you.
Quoted 93 lines
lib/ethdev/rte_ethdev.c +43
-29+ ret =rte_eth_dev_info_get (port_id, &dev_info); +if (ret !=0 ) +return ret; - restore_flags =rte_eth_get_restore_flags (dev,RTE_ETH_START ); + restore_flags =rte_eth_get_restore_flags (dev,RTE_ETH_START ); -/* Lets restore MAC now if device does not support live change */ -if ((*dev_info.dev_flags &RTE_ETH_DEV_NOLIVE_MAC_ADDR ) && - (restore_flags &RTE_ETH_RESTORE_MAC_ADDR )) -eth_dev_mac_restore (dev, &dev_info); +/* Restore MAC now if device does not support live change */ +if ((*dev_info.dev_flags &RTE_ETH_DEV_NOLIVE_MAC_ADDR ) && + (restore_flags &RTE_ETH_RESTORE_MAC_ADDR )) +eth_dev_mac_restore (dev, &dev_info); - diag = dev->dev_ops->dev_start (dev); -if (diag ==0 ) - dev->data->dev_started =1 ; -else -return eth_err (port_id, diag); + diag = dev->dev_ops->dev_start (dev); +if (diag ==0 ) + dev->data->dev_started =1 ; +else +return eth_err (port_id, diag); - ret =eth_dev_config_restore (dev, &dev_info, restore_flags, port_id); -if (ret !=0 ) { -RTE_ETHDEV_LOG_LINE (ERR , -"Error during restoring configuration for device (port %u): %s" , - port_id,rte_strerror (-ret)); - ret_stop =rte_eth_dev_stop (port_id); -if (ret_stop !=0 ) { + ret =eth_dev_config_restore (dev, &dev_info, restore_flags, port_id); +if (ret !=0 ) {RTE_ETHDEV_LOG_LINE (ERR , -"Failed to stop device (port %u): %s" , - port_id,rte_strerror (-ret_stop)); - } +"Error during restoring configuration for device (port %u): %s" , + port_id,rte_strerror (-ret)); + ret_stop =rte_eth_dev_stop (port_id); +if (ret_stop !=0 ) { +RTE_ETHDEV_LOG_LINE (ERR , +"Failed to stop device (port %u): %s" , + port_id,rte_strerror (-ret_stop)); + } -return ret; - } +return ret; + } -if (dev->data->dev_conf.intr_conf.lsc ==0 ) { -if (dev->dev_ops->link_update ==NULL ) -return -ENOTSUP ; - dev->dev_ops->link_update (dev,0 ); +if (dev->data->dev_conf.intr_conf.lsc ==0 ) { +if (dev->dev_ops->link_update ==NULL ) +return -ENOTSUP ; + dev->dev_ops->link_update (dev,0 ); + } + }else { +/* in secondary, proxy to primary */ + ret =ethdev_request (port_id,ETH_REQ_START ,NULL ,0 ); +if (ret !=0 ) +return ret; }/* expose selection of PMD fast-path functions */ @@ -1880,9 +1887,14 @@ rte_eth_dev_stop(uint16_t port_id)/* point fast-path functions to dummy ones */ eth_dev_fp_ops_reset (rte_eth_fp_ops + port_id); - ret = dev->dev_ops->dev_stop (dev); -if (ret ==0 ) - dev->data->dev_started =0 ; +if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) { + ret = dev->dev_ops->dev_stop (dev); +if (ret ==0 ) + dev->data->dev_started =0 ; + }else { + ret =ethdev_request (port_id,ETH_REQ_STOP ,NULL ,0 ); + } +rte_ethdev_trace_stop (port_id, ret);return ret;Signature · 1 line
2.47.2
Re: [PATCH v6 01/13] ethdev: allow start/stop from secondary process
Quoted 47 lines · On Wed, 23 Jul 2025 05:08:04 +0400 (+04) Ivan Malov…
+
Quoted 5 lines
lib/ethdev/ethdev_private.c +5
-0+int +ethdev_request (uint16_t port_id,enum ethdev_mp_operation operation, +const void *buf,size_t buf_len) +{ +struct rte_mp_msg mp_req = { };lib/ethdev/ethdev_private.c eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues) · line 542
Quoted 10 lines
lib/ethdev/ethdev_private.c +10
-0+struct rte_mp_reply mp_reply; +struct ethdev_mp_request *req; +struct timespec ts = {.tv_sec =5 , .tv_nsec =0 }; +int ret; + +if (sizeof (*req) + buf_len >RTE_MP_MAX_PARAM_LEN ) { +RTE_ETHDEV_LOG_LINE (ERR , +"request %u port %u invalid len %zu" , + operation, port_id, buf_len); +return -EINVAL ;A couple of lines below '
resp->err_value' is used to set 'rte_errno'. Why not also set it here then? May be I'm wrong. Or may be set it in (ret < 0) check?Quoted 12 lines
lib/ethdev/ethdev_private.c +12
-0+ } + +strlcpy (mp_req.name,ETHDEV_MP ,RTE_MP_MAX_NAME_LEN ); + mp_req.len_param =sizeof (*req) + buf_len; + + req = (struct ethdev_mp_request *)mp_req.param; + req->operation = operation; + req->port_id = port_id; + +if (buf_len >0 ) +memcpy (req->config, buf, buf_len); +lib/ethdev/ethdev_private.c eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues) · line 564
Quoted 10 lines
lib/ethdev/ethdev_private.c +10
-0+ ret =rte_mp_request_sync (&mp_req, &mp_reply, &ts); +if (ret ==0 ) { +const struct rte_mp_msg *mp_rep = &mp_reply.msgs[0 ]; +const struct ethdev_mp_response *resp + = (const struct ethdev_mp_response *)mp_rep->param; + +if (resp->err_value ==0 ) + ret =0 ; +else + rte_errno = -resp->err_value;By the looks of it, this check sets 'ret = 0' when it is already 0 and, at the same time, when '
resp->err_value' is non-zero, does not override 'ret' with it. I apologise in case I've got this wrong.
Quoted 8 lines
lib/ethdev/ethdev_private.c eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues) · line 572
Quoted 8 lines
lib/ethdev/ethdev_private.c +8
-0+free (mp_reply.msgs); + } + +if (ret <0 ) +RTE_ETHDEV_LOG_LINE (ERR , +"port %up ethdev op %u failed" , port_id, operation); +return ret; +}
Thanks, this code was copy/past from pdump so thats why it was not perfect in error checking.
Quoted 4 lines
Quoted 4 lines
lib/ethdev/rte_ethdev.c +0
-0@@ -1800,54 +1800,61 @@ rte_eth_dev_start(uint16_t port_id)
Quoted 12 lines
lib/ethdev/rte_ethdev.c rte_eth_dev_start(uint16_t port_id) · line 1804
Quoted 6 lines
lib/ethdev/rte_ethdev.c +2
-2if (dev->data->dev_configured ==0 ) {RTE_ETHDEV_LOG_LINE (INFO , -"Device with port_id=%" PRIu16" is not configured." , - port_id); +"Device with port_id=%" PRIu16" is not configured." , + port_id);On the one hand, it's great that an improvement is being offered. On the other hand, one may argue this is unrelated to the stated purpose of the patch. And, finally, may be placing it 'RTE_ETHDEV_LOG_LINE(INFO, "Device with...' would also work and not trigger a checkpatch warning, but I may be wrong.
Thanks this was from editor doing indent, not needed will remove.
PATCH v6 2/13 ethdev: make sure all necessary headers included
In reply to Stephen HemmingerBest not to depend on other EAL headers to include stuff. Some of the later changes had build failures on some platforms.
--- lib/ethdev/ethdev_private.c | 9 +++++++++ 1 file changed, 9 insertions(+)
lib/ethdev/ethdev_private.c +9 -0
@@ -3,9 +3,18 @@*/ #include <assert.h> +#include <errno.h> +#include <inttypes.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <time.h> #include <eal_export.h> #include <rte_debug.h> +#include <rte_eal.h> +#include <rte_lcore.h> +#include <rte_stdatomic.h> #include "rte_ethdev.h" #include "rte_ethdev_trace_fp.h"
Signature · 1 line
2.47.2
PATCH v6 3/13 test: add test for hotplug and secondary process operations
In reply to Stephen HemmingerUse null device to exercise ethdev start/stop in secondary process.
--- app/test/test_mp_secondary.c | 51 +++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-)
app/test/test_mp_secondary.c +48 -3
@@ -15,6 +15,9 @@#include <string.h> #include <unistd.h> +#include <rte_ethdev.h> +#include <rte_bus_vdev.h> +#ifdef RTE_EXEC_ENV_WINDOWS int test_mp_secondary (void )
@@ -204,6 +207,44 @@ run_object_creation_tests(void)return 0 ; } +static int +run_ethdev_tests (void ) +{ +char vdev_name[] ="net_null" ; +struct rte_eth_conf dev_conf = {0 }; +uint16_t port; +int ret; + +printf ("### Testing hotplug and ethdev start/stop\n" ); + +/* use hotplug to make a null vdev */ + ret =rte_eal_hotplug_add ("vdev" , vdev_name,"" ); +TEST_ASSERT (ret ==0 ,"Hotplug add of '%s' failed" , vdev_name); + +printf ("# Checked hotlug_add OK\n" ); + + ret =rte_eth_dev_get_port_by_name (vdev_name, &port); +TEST_ASSERT (ret ==0 ,"Lookup vdev '%s' failed" , vdev_name); + + ret =rte_eth_dev_configure (port,1 ,1 , &dev_conf); +TEST_ASSERT (ret ==0 ,"Configure port %u failed" , port); + + ret =rte_eth_dev_start (port); +TEST_ASSERT (ret ==0 ,"Start port %u failed" , port); + +printf ("# Checked rte_eth_dev_start\n" ); + + ret =rte_eth_dev_stop (port); +TEST_ASSERT (ret ==0 ,"Stop port %u failed" , port); + +printf ("# Checked rte_eth_dev_stop\n" ); + +rte_eal_hotplug_remove ("vdev" , vdev_name); + +printf ("# Checked hotlug_remove OK\n" ); +return 0 ; +} +/* if called in a primary process, just spawns off a secondary process to * run validation tests - which brings us right back here again... * if called in a secondary process, this runs a series of API tests to check
@@ -212,15 +253,19 @@ run_object_creation_tests(void)int test_mp_secondary (void ) { -if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) { +int ret; + +if (rte_eal_process_type () ==RTE_PROC_PRIMARY )return run_secondary_instances (); - }printf ("IN SECONDARY PROCESS\n" ); + ret =run_ethdev_tests (); +if (ret !=0 ) +return ret;return run_object_creation_tests (); }#endif /* !RTE_EXEC_ENV_WINDOWS */ -REGISTER_FAST_TEST (multiprocess_autotest, false, false, test_mp_secondary); +REGISTER_FAST_TEST (multiprocess_autotest, true, true, test_mp_secondary);
Signature · 1 line
2.47.2
Re: [PATCH v6 03/13] test: add test for hotplug and secondary process operations
Hi Stephen,
(please see below)
Quoted 22 lines · Stephen Hemminger
Use null device to exercise ethdev start/stop in secondary process.
Signed-off-by Stephen Hemminger <[email protected]>---
app/test/test_mp_secondary.c| 51 +++++++++++++++++++++++++++++++++---1 file changed, 48 insertions(+), 3 deletions(-)app/test/test_mp_secondary.c +3
-0@@ -15,6 +15,9 @@#include <string.h> #include <unistd.h> +#include <rte_ethdev.h> +#include <rte_bus_vdev.h> +#ifdef RTE_EXEC_ENV_WINDOWS int
test_mp_secondary(void)
app/test/test_mp_secondary.c run_object_creation_tests(void) · line 213
Quoted 7 lines
app/test/test_mp_secondary.c +4
-0@@ -204,6 +207,44 @@ run_object_creation_tests(void)return 0 ; } +static int +run_ethdev_tests (void ) +{ +char vdev_name[] ="net_null" ;
Perhaps 'const'? I don't insist.
app/test/test_mp_secondary.c run_object_creation_tests(void) · line 224
Quoted 11 lines
app/test/test_mp_secondary.c +11
-0+struct rte_eth_conf dev_conf = {0 }; +uint16_t port; +int ret; + +printf ("### Testing hotplug and ethdev start/stop\n" ); + +/* use hotplug to make a null vdev */ + ret =rte_eal_hotplug_add ("vdev" , vdev_name,"" ); +TEST_ASSERT (ret ==0 ,"Hotplug add of '%s' failed" , vdev_name); + +printf ("# Checked hotlug_add OK\n" );
Could be a typo: hot'p'lug_add.
app/test/test_mp_secondary.c run_object_creation_tests(void) · line 230
Quoted 6 lines
app/test/test_mp_secondary.c +6
-0+ + ret =rte_eth_dev_get_port_by_name (vdev_name, &port); +TEST_ASSERT (ret ==0 ,"Lookup vdev '%s' failed" , vdev_name); + + ret =rte_eth_dev_configure (port,1 ,1 , &dev_conf); +TEST_ASSERT (ret ==0 ,"Configure port %u failed" , port);
I may be very wrong here, but if this code is supposed to be run in the secondary process, then is 'rte_eth_dev_configure' allowed in such?
Quoted 4 lines
app/test/test_mp_secondary.c +4
-0+ + ret =rte_eth_dev_start (port); +TEST_ASSERT (ret ==0 ,"Start port %u failed" , port); +
app/test/test_mp_secondary.c run_object_creation_tests(void) · line 244
Quoted 10 lines
app/test/test_mp_secondary.c +10
-0+printf ("# Checked rte_eth_dev_start\n" ); + + ret =rte_eth_dev_stop (port); +TEST_ASSERT (ret ==0 ,"Stop port %u failed" , port); + +printf ("# Checked rte_eth_dev_stop\n" ); + +rte_eal_hotplug_remove ("vdev" , vdev_name); + +printf ("# Checked hotlug_remove OK\n" );
Could be a typo: hot'p'lug_remove.
Thank you.
Quoted 33 lines
app/test/test_mp_secondary.c +3
-0+return 0 ; +} +/* if called in a primary process, just spawns off a secondary process to * run validation tests - which brings us right back here again... * if called in a secondary process, this runs a series of API tests to check @@ -212,15 +253,19 @@ run_object_creation_tests(void)int
test_mp_secondary(void)
{app/test/test_mp_secondary.c +3
-1-if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) { +int ret; + +if (rte_eal_process_type () ==RTE_PROC_PRIMARY )return run_secondary_instances();app/test/test_mp_secondary.c +0
-1- }printf("IN SECONDARY PROCESS\n");app/test/test_mp_secondary.c +3
-0+ ret =run_ethdev_tests (); +if (ret !=0 ) +return ret;return run_object_creation_tests(); }#endif /* !RTE_EXEC_ENV_WINDOWS */
app/test/test_mp_secondary.c +1
-1-REGISTER_FAST_TEST (multiprocess_autotest, false, false, test_mp_secondary); +REGISTER_FAST_TEST (multiprocess_autotest, true, true, test_mp_secondary);Signature · 1 line
2.47.2
Re: [PATCH v6 03/13] test: add test for hotplug and secondary process operations
Quoted 9 lines · On Wed, 23 Jul 2025 05:31:03 +0400 (+04) Ivan Malov…
app/test/test_mp_secondary.c run_object_creation_tests(void) · line 230
Quoted 6 lines
app/test/test_mp_secondary.c +6
-0+ + ret =rte_eth_dev_get_port_by_name (vdev_name, &port); +TEST_ASSERT (ret ==0 ,"Lookup vdev '%s' failed" , vdev_name); + + ret =rte_eth_dev_configure (port,1 ,1 , &dev_conf); +TEST_ASSERT (ret ==0 ,"Configure port %u failed" , port);I may be very wrong here, but if this code is supposed to be run in the secondary process, then is '
rte_eth_dev_configure' allowed in such?
It works because the state in port structure for is in shared huge pages. The issue with start/stop is that it causes state changes that are not shared.
PATCH v6 4/13 net/ring: allow lockfree transmit if ring supports it
In reply to Stephen HemmingerNeed to be able have multiple threads all using same transmit queue when using SPAN.
--- drivers/net/ring/rte_eth_ring.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/net/ring/rte_eth_ring.c +17 -0
@@ -177,6 +177,19 @@ eth_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,return 0 ; } +static bool +eth_tx_queue_lockfree (const struct pmd_internals *internals) +{ +unsigned int i; + +for (i =0 ; i < internals->max_tx_queues; i++) { +const struct ring_queue *r = &internals->tx_ring_queues[i]; + +if (r->rng->flags &RING_F_SP_ENQ ) +return false; + } +return true; +} static int eth_dev_info(struct rte_eth_dev *dev,
@@ -189,6 +202,10 @@ eth_dev_info(struct rte_eth_dev *dev, dev_info->max_rx_queues = (uint16_t )internals->max_rx_queues; dev_info->rx_offload_capa =RTE_ETH_RX_OFFLOAD_SCATTER ; dev_info->tx_offload_capa =RTE_ETH_TX_OFFLOAD_MULTI_SEGS ; + +if (eth_tx_queue_lockfree (internals)) + dev_info->tx_offload_capa |=RTE_ETH_TX_OFFLOAD_MT_LOCKFREE ; + dev_info->max_tx_queues = (uint16_t )internals->max_tx_queues; dev_info->min_rx_bufsize =0 ;
Signature · 1 line
2.47.2
PATCH v6 5/13 net/ring: add new devarg to create vdev from existing ring
In reply to Stephen HemmingerNeed ability to allow process like dumpcap to make a ring ethdev with a pre-existing ring. Do this via devargs so it can work with hotplug.
It looked like the API rte_eth_from_ring() would work for this, but it doesn't do the right thing. That API makes new vdev but names the ring based on the parameter.
--- drivers/net/ring/rte_eth_ring.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
drivers/net/ring/rte_eth_ring.c +32 -0
@@ -23,9 +23,12 @@#define ETH_RING_INTERNAL_ARG "internal"#define ETH_RING_INTERNAL_ARG_MAX_LEN 19/* "0x..16chars..\0" */ +#define ETH_RING_RING_ARG "ring" +static const char *valid_arguments[] = {ETH_RING_NUMA_NODE_ACTION_ARG ,ETH_RING_INTERNAL_ARG , +ETH_RING_RING_ARG ,NULL };
@@ -693,6 +696,20 @@ parse_internal_args(const char *key __rte_unused, const char *value,return 0 ; } +static int +parse_ring_arg(const char *key __rte_unused, const char *value, void *data) +{ +struct rte_ring **rp = data; + + *rp =rte_ring_lookup (value); +if (*rp ==NULL ) { +PMD_LOG (ERR ,"ring '%s' not found" , value); +return -1 ; + } + +return 0 ; +} +static int rte_pmd_ring_probe (struct rte_vdev_device *dev) {
@@ -770,6 +787,20 @@ rte_pmd_ring_probe(struct rte_vdev_device *dev) ð_dev);if (ret >=0 ) ret =0 ; + }else if (rte_kvargs_count (kvlist,ETH_RING_RING_ARG ) ==1 ) { +struct rte_ring *rxtx[1 ] = { }; + + ret =rte_kvargs_process (kvlist,ETH_RING_RING_ARG , parse_ring_arg, rxtx); +if (ret <0 ) + goto out_free; + +/* Note: rte_eth_from_ring() does not do what is expected here! */ + ret =do_eth_dev_ring_create (name, dev, rxtx,1 , rxtx,1 , +rte_socket_id (),DEV_ATTACH , ð_dev); +if (ret <0 ) + goto out_free; + + ret =0 ; }else { ret =rte_kvargs_count (kvlist,ETH_RING_NUMA_NODE_ACTION_ARG ); info = rte_zmalloc("struct node_action_list",
@@ -843,4 +874,5 @@ static struct rte_vdev_driver pmd_ring_drv = {RTE_PMD_REGISTER_VDEV (net_ring, pmd_ring_drv);RTE_PMD_REGISTER_ALIAS (net_ring, eth_ring);RTE_PMD_REGISTER_PARAM_STRING (net_ring, +ETH_RING_RING_ARG "=<string> " ETH_RING_NUMA_NODE_ACTION_ARG "=name:node:action(ATTACH|CREATE)" );
Signature · 1 line
2.47.2
PATCH v6 6/13 mbuf: add dynamic flag for use by port mirroring
In reply to Stephen HemmingerAdd names for new port mirror fields.
--- lib/mbuf/rte_mbuf_dyn.h | 9 +++++++++ 1 file changed, 9 insertions(+)
lib/mbuf/rte_mbuf_dyn.h +9 -0
@@ -327,6 +327,15 @@ int rte_mbuf_dyn_tx_timestamp_register(int *field_offset, uint64_t *tx_flag);#define RTE_MBUF_DYNFIELD_IP_REASSEMBLY_NAME "rte_dynfield_ip_reassembly"#define RTE_MBUF_DYNFLAG_IP_REASSEMBLY_INCOMPLETE_NAME "rte_dynflag_ip_reassembly_incomplete" +/** +* The ethdev port mirror needs some extra packet information that +* includes information about the packet before it was copied to the mirror. +*/ +#define RTE_MBUF_DYNFIELD_MIRROR_ORIGIN "rte_dynfield_mirror_origin" +#define RTE_MBUF_DYNFLAG_MIRROR_ORIGIN "rte_dynflag_mirror_origin" +#define RTE_MBUF_DYNFLAG_MIRROR_INGRESS "rte_dynflag_mirror_ingress" +#define RTE_MBUF_DYNFLAG_MIRROR_EGRESS "rte_dynflag_mirror_egress" + #ifdef __cplusplus }#endif
Signature · 1 line
2.47.2
PATCH v6 7/13 ethdev: add port mirroring feature
In reply to Stephen HemmingerThis adds new feature port mirroring to the ethdev layer.
--- config/rte_config.h | 1 + lib/ethdev/ethdev_driver.h | 6 + lib/ethdev/ethdev_private.c | 58 ++++- lib/ethdev/ethdev_private.h | 3 + lib/ethdev/ethdev_trace.h | 17 ++ lib/ethdev/ethdev_trace_points.c | 6 + lib/ethdev/meson.build | 1 + lib/ethdev/rte_ethdev.c | 17 +- lib/ethdev/rte_ethdev.h | 23 +- lib/ethdev/rte_ethdev_core.h | 12 +- lib/ethdev/rte_mirror.c | 375 +++++++++++++++++++++++++++++++ lib/ethdev/rte_mirror.h | 99 ++++++++ 12 files changed, 600 insertions(+), 18 deletions(-) create mode 100644 lib/ethdev/rte_mirror.c create mode 100644 lib/ethdev/rte_mirror.h
config/rte_config.h +1 -0
@@ -69,6 +69,7 @@#define RTE_MAX_QUEUES_PER_PORT 1024#define RTE_ETHDEV_QUEUE_STAT_CNTRS 16/* max 256 */ #define RTE_ETHDEV_RXTX_CALLBACKS 1 +#define RTE_ETHDEV_MIRROR 1#define RTE_MAX_MULTI_HOST_CTRLS 4/* cryptodev defines */
lib/ethdev/ethdev_driver.h +6 -0
@@ -91,6 +91,12 @@ struct __rte_cache_aligned rte_eth_dev {*/ RTE_ATOMIC (struct rte_eth_rxtx_callback *) pre_tx_burst_cbs[RTE_MAX_QUEUES_PER_PORT ]; +/** Receive mirrors */ +RTE_ATOMIC (struct rte_eth_mirror *) rx_mirror; + +/** Transmit mirrors */ +RTE_ATOMIC (struct rte_eth_mirror *) tx_mirror; +enum rte_eth_dev_state state;/**< Flag indicating the port state */ void *security_ctx;/**< Context for security ops */ };
lib/ethdev/ethdev_private.c +49 -9
95 lines not on this page · raw message
lib/ethdev/ethdev_private.h +3 -0
@@ -85,6 +85,9 @@ int eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues);enum ethdev_mp_operation {ETH_REQ_START ,ETH_REQ_STOP , +ETH_REQ_RESET , +ETH_REQ_ADD_MIRROR , +ETH_REQ_REMOVE_MIRROR , };struct ethdev_mp_request {
lib/ethdev/ethdev_trace.h +17 -0
@@ -1035,6 +1035,23 @@ RTE_TRACE_POINT(rte_trace_point_emit_int (ret); ) +RTE_TRACE_POINT ( + rte_eth_trace_add_mirror, + RTE_TRACE_POINT_ARGS(uint16_t port_id, + const struct rte_eth_mirror_conf *conf, int ret), + rte_trace_point_emit_u16(port_id); +rte_trace_point_emit_u16 (conf->target); +rte_trace_point_emit_int (ret); +) + +RTE_TRACE_POINT ( + rte_eth_trace_remove_mirror, + RTE_TRACE_POINT_ARGS(uint16_t port_id, uint16_t target_id, int ret), + rte_trace_point_emit_u16(port_id); +rte_trace_point_emit_u16 (target_id); +rte_trace_point_emit_int (ret); +) + RTE_TRACE_POINT( rte_eth_trace_rx_queue_info_get, RTE_TRACE_POINT_ARGS(uint16_t port_id, uint16_t queue_id,
lib/ethdev/ethdev_trace_points.c +6 -0
@@ -389,6 +389,12 @@ RTE_TRACE_POINT_REGISTER(rte_eth_trace_remove_rx_callback,RTE_TRACE_POINT_REGISTER (rte_eth_trace_remove_tx_callback, lib.ethdev.remove_tx_callback) +RTE_TRACE_POINT_REGISTER (rte_eth_trace_add_mirror, + lib.ethdev.add_mirror) + +RTE_TRACE_POINT_REGISTER (rte_eth_trace_remove_mirror, + lib.ethdev.remove_mirror) +RTE_TRACE_POINT_REGISTER (rte_eth_trace_rx_queue_info_get, lib.ethdev.rx_queue_info_get)
lib/ethdev/meson.build +1 -0
@@ -11,6 +11,7 @@ sources = files( 'rte_ethdev_cman.c', 'rte_ethdev_telemetry.c', 'rte_flow.c', + 'rte_mirror.c', 'rte_mtr.c', 'rte_tm.c', 'sff_telemetry.c',
lib/ethdev/rte_ethdev.c +11 -6
@@ -14,6 +14,8 @@#include <bus_driver.h> #include <eal_export.h> #include <rte_log.h> +#include <rte_cycles.h> +#include <rte_alarm.h> #include <rte_interrupts.h> #include <rte_kvargs.h> #include <rte_memcpy.h>
@@ -2041,13 +2043,16 @@ rte_eth_dev_reset(uint16_t port_id)if (dev->dev_ops->dev_reset ==NULL )return -ENOTSUP ; - ret =rte_eth_dev_stop (port_id); -if (ret !=0 ) { -RTE_ETHDEV_LOG_LINE (ERR , -"Failed to stop device (port %u) before reset: %s - ignore" , - port_id,rte_strerror (-ret)); +if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) { + ret =rte_eth_dev_stop (port_id); +if (ret !=0 ) +RTE_ETHDEV_LOG_LINE (ERR , +"Failed to stop device (port %u) before reset: %s - ignore" , + port_id,rte_strerror (-ret)); + ret =eth_err (port_id, dev->dev_ops->dev_reset (dev)); + }else { + ret =ethdev_request (port_id,ETH_REQ_STOP ,NULL ,0 ); } - ret =eth_err (port_id, dev->dev_ops->dev_reset (dev));rte_ethdev_trace_reset (port_id, ret);
lib/ethdev/rte_ethdev.h +22 -1
@@ -170,6 +170,7 @@#include "rte_ethdev_trace_fp.h" #include "rte_dev_info.h" +#include "rte_mirror.h" #ifdef __cplusplusextern "C" {
@@ -1466,7 +1467,6 @@ enum rte_eth_tunnel_type { RTE_ETH_TUNNEL_TYPE_ECPRI, RTE_ETH_TUNNEL_TYPE_MAX, }; -#ifdef __cplusplus }#endif
@@ -6334,6 +6334,17 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t queue_id, nb_rx = p->rx_pkt_burst (qd, rx_pkts, nb_pkts); +#ifdef RTE_ETHDEV_MIRROR + { +const struct rte_eth_mirror *mirror + =rte_atomic_load_explicit (p->rx_mirror, rte_memory_order_relaxed); + +if (unlikely (mirror !=NULL )) +rte_eth_mirror_burst (port_id, queue_id,RTE_ETH_MIRROR_DIRECTION_INGRESS , + rx_pkts, nb_rx, mirror); + } +#endif +#ifdef RTE_ETHDEV_RXTX_CALLBACKS {void *cb;
@@ -6692,6 +6703,16 @@ rte_eth_tx_burst(uint16_t port_id, uint16_t queue_id, }#endif +#ifdef RTE_ETHDEV_MIRROR + { +const struct rte_eth_mirror *mirror; + + mirror =rte_atomic_load_explicit (p->tx_mirror, rte_memory_order_relaxed); +if (unlikely (mirror !=NULL )) +rte_eth_mirror_burst (port_id, queue_id,RTE_ETH_MIRROR_DIRECTION_EGRESS , + tx_pkts, nb_pkts, mirror); + } +#endif nb_pkts = p->tx_pkt_burst (qd, tx_pkts, nb_pkts);rte_ethdev_trace_tx_burst (port_id, queue_id, (void **)tx_pkts, nb_pkts);
lib/ethdev/rte_ethdev_core.h +10 -2
@@ -22,6 +22,12 @@ RTE_TAILQ_HEAD(rte_eth_dev_cb_list, rte_eth_dev_callback);struct rte_eth_dev ; +struct rte_eth_mirror ; + +void rte_eth_mirror_burst (uint16_t port_id,uint16_t quque_id,uint8_t dir, +struct rte_mbuf **pkts,uint16_t nb_pkts, +const struct rte_eth_mirror *mirror); +/** * @internal Retrieve input packets from a receive queue of an Ethernet device. */
@@ -101,7 +107,8 @@ struct __rte_cache_aligned rte_eth_fp_ops {eth_rx_descriptor_status_t rx_descriptor_status;/** Refill Rx descriptors with the recycling mbufs. */ eth_recycle_rx_descriptors_refill_t recycle_rx_descriptors_refill; -uintptr_t reserved1[2 ]; +uintptr_t reserved1; +RTE_ATOMIC (struct rte_eth_mirror *) *rx_mirror;/**@}*/ /**@{*/
@@ -121,7 +128,8 @@ struct __rte_cache_aligned rte_eth_fp_ops {eth_recycle_tx_mbufs_reuse_t recycle_tx_mbufs_reuse;/** Get the number of used Tx descriptors. */ eth_tx_queue_count_t tx_queue_count; -uintptr_t reserved2[1 ]; +RTE_ATOMIC (struct rte_eth_mirror *) *tx_mirror; +uintptr_t reserved2;/**@}*/ };
lib/ethdev/rte_mirror.c new file +375 -0
375 lines not on this page · raw message
lib/ethdev/rte_mirror.h new file +99 -0
99 lines not on this page · raw message
Signature · 1 line
2.47.2
Re: [PATCH v6 07/13] ethdev: add port mirroring feature
Hi Stephen,
(please see below)
Quoted 530 lines · Stephen Hemminger
This adds new feature port mirroring to the ethdev layer.
Signed-off-by Stephen Hemminger <[email protected]>---
config/rte_config.h | 1 + lib/ethdev/ethdev_driver.h | 6 + lib/ethdev/ethdev_private.c | 58 ++++- lib/ethdev/ethdev_private.h | 3 + lib/ethdev/ethdev_trace.h | 17 ++ lib/ethdev/ethdev_trace_points.c | 6 + lib/ethdev/meson.build | 1 + lib/ethdev/rte_ethdev.c | 17 +- lib/ethdev/rte_ethdev.h | 23 +- lib/ethdev/rte_ethdev_core.h | 12 +- lib/ethdev/rte_mirror.c | 375 +++++++++++++++++++++++++++++++ lib/ethdev/rte_mirror.h | 99 ++++++++ 12 files changed, 600 insertions(+), 18 deletions(-)create mode 100644
lib/ethdev/rte_mirror.c
create mode 100644lib/ethdev/rte_mirror.hconfig/rte_config.h +1
-0@@ -69,6 +69,7 @@#define RTE_MAX_QUEUES_PER_PORT 1024#define RTE_ETHDEV_QUEUE_STAT_CNTRS 16/* max 256 */ #define RTE_ETHDEV_RXTX_CALLBACKS 1 +#define RTE_ETHDEV_MIRROR 1#define RTE_MAX_MULTI_HOST_CTRLS 4/* cryptodev defines */ lib/ethdev/ethdev_driver.h +6
-0@@ -91,6 +91,12 @@ struct __rte_cache_aligned rte_eth_dev {*/ RTE_ATOMIC (struct rte_eth_rxtx_callback *) pre_tx_burst_cbs[RTE_MAX_QUEUES_PER_PORT ]; +/** Receive mirrors */ +RTE_ATOMIC (struct rte_eth_mirror *) rx_mirror; + +/** Transmit mirrors */ +RTE_ATOMIC (struct rte_eth_mirror *) tx_mirror; +enum rte_eth_dev_state state;/**< Flag indicating the port state */ void *security_ctx;/**< Context for security ops */ };lib/ethdev/ethdev_private.c +2
-0@@ -289,6 +289,8 @@ eth_dev_fp_ops_setup(struct rte_eth_fp_ops *fpo, fpo->tx_descriptor_status = dev->tx_descriptor_status; fpo->recycle_tx_mbufs_reuse = dev->recycle_tx_mbufs_reuse; fpo->recycle_rx_descriptors_refill = dev->recycle_rx_descriptors_refill; + fpo->rx_mirror = (struct rte_eth_mirror * __rte_atomic *)(uintptr_t)&dev->rx_mirror; + fpo->tx_mirror = (struct rte_eth_mirror * __rte_atomic *)(uintptr_t)&dev->tx_mirror; fpo->rxq.data = dev->data->rx_queues; fpo->rxq.clbk = (void * __rte_atomic *)(uintptr_t)dev->post_rx_burst_cbs;@@ -490,17 +492,53 @@ eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues) }static int
lib/ethdev/ethdev_private.c +1
-1-ethdev_handle_request(const struct ethdev_mp_request *req) +ethdev_handle_request(const struct ethdev_mp_request *req, size_t len){
lib/ethdev/ethdev_private.c +2
-0+ len -=sizeof (*req); +switch (req->operation) { case ETH_REQ_START:lib/ethdev/ethdev_private.c +3
-0+if (len !=0 ) +return -EINVAL ; +return rte_eth_dev_start(req->port_id); case ETH_REQ_STOP:lib/ethdev/ethdev_private.c +2
-0+if (len !=0 ) +return -EINVAL ;return rte_eth_dev_stop(req->port_id);lib/ethdev/ethdev_private.c +27
-0+case ETH_REQ_RESET : +if (len !=0 ) +return -EINVAL ; +return rte_eth_dev_reset (req->port_id); + +case ETH_REQ_ADD_MIRROR : +if (len !=sizeof (struct rte_eth_mirror_conf )) { +RTE_ETHDEV_LOG_LINE (ERR , +"add mirror conf wrong size %zu" , len); +return -EINVAL ; + } + +const struct rte_eth_mirror_conf *conf + = (const struct rte_eth_mirror_conf *) req->config; + +return rte_eth_add_mirror (req->port_id, conf); + +case ETH_REQ_REMOVE_MIRROR : +if (len !=sizeof (uint16_t )) { +RTE_ETHDEV_LOG_LINE (ERR , +"mirror remove wrong size %zu" , len); +return -EINVAL ; + } + +uint16_t target = *(const uint16_t *) req->config; +return rte_eth_remove_mirror (req->port_id, target); +default:
lib/ethdev/ethdev_private.c +3
-1-return -EINVAL ; +RTE_ETHDEV_LOG_LINE (ERR , +"Unknown mp request operation %u" , req->operation); +return -ENOTSUP ;} }lib/ethdev/ethdev_private.c +0
-0@@ -513,23 +551,25 @@ static_assert(sizeof(struct ethdev_mp_response) <= RTE_MP_MAX_PARAM_LEN,int
ethdev_server(const struct rte_mp_msg *mp_msg, const void *peer){lib/ethdev/ethdev_private.c +0
-3-const struct ethdev_mp_request *req - = (const struct ethdev_mp_request *)mp_msg->param; -struct rte_mp_msg mp_resp = { .name = ETHDEV_MP, }; struct ethdev_mp_response *resp;lib/ethdev/ethdev_private.c +1
-0+const struct ethdev_mp_request *req;resp = (struct ethdev_mp_response *)mp_resp.param; mp_resp.len_param = sizeof(*resp);lib/ethdev/ethdev_private.c +0
-1- resp->res_op = req->operation;/* recv client requests */lib/ethdev/ethdev_private.c +2
-1-if (mp_msg->len_param !=sizeof (*req)) +if (mp_msg->len_param < (int )sizeof (*req)) { +RTE_ETHDEV_LOG_LINE (ERR ,"invalid request from secondary" );resp->err_value = -EINVAL;lib/ethdev/ethdev_private.c +6
-2-else - resp->err_value =ethdev_handle_request (req); + }else { + req = (const struct ethdev_mp_request *)mp_msg->param; + resp->res_op = req->operation; + resp->err_value =ethdev_handle_request (req, mp_msg->len_param); + + }return rte_mp_reply(&mp_resp, peer); }lib/ethdev/ethdev_private.h +3
-0@@ -85,6 +85,9 @@ int eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues);enum ethdev_mp_operation {ETH_REQ_START ,ETH_REQ_STOP , +ETH_REQ_RESET , +ETH_REQ_ADD_MIRROR , +ETH_REQ_REMOVE_MIRROR , };struct ethdev_mp_request {lib/ethdev/ethdev_trace.h +17
-0@@ -1035,6 +1035,23 @@ RTE_TRACE_POINT(rte_trace_point_emit_int (ret); ) +RTE_TRACE_POINT ( + rte_eth_trace_add_mirror, + RTE_TRACE_POINT_ARGS(uint16_t port_id, + const struct rte_eth_mirror_conf *conf, int ret), + rte_trace_point_emit_u16(port_id); +rte_trace_point_emit_u16 (conf->target); +rte_trace_point_emit_int (ret); +) + +RTE_TRACE_POINT ( + rte_eth_trace_remove_mirror, + RTE_TRACE_POINT_ARGS(uint16_t port_id, uint16_t target_id, int ret), + rte_trace_point_emit_u16(port_id); +rte_trace_point_emit_u16 (target_id); +rte_trace_point_emit_int (ret); +) +RTE_TRACE_POINT(
rte_eth_trace_rx_queue_info_get, RTE_TRACE_POINT_ARGS(uint16_tport_id,uint16_tqueue_id,lib/ethdev/ethdev_trace_points.c +6
-0@@ -389,6 +389,12 @@ RTE_TRACE_POINT_REGISTER(rte_eth_trace_remove_rx_callback,RTE_TRACE_POINT_REGISTER (rte_eth_trace_remove_tx_callback, lib.ethdev.remove_tx_callback) +RTE_TRACE_POINT_REGISTER (rte_eth_trace_add_mirror, + lib.ethdev.add_mirror) + +RTE_TRACE_POINT_REGISTER (rte_eth_trace_remove_mirror, + lib.ethdev.remove_mirror) +RTE_TRACE_POINT_REGISTER (rte_eth_trace_rx_queue_info_get, lib.ethdev.rx_queue_info_get)lib/ethdev/meson.build +1
-0@@ -11,6 +11,7 @@ sources = files( 'rte_ethdev_cman.c', 'rte_ethdev_telemetry.c', 'rte_flow.c', + 'rte_mirror.c', 'rte_mtr.c', 'rte_tm.c', 'sff_telemetry.c',lib/ethdev/rte_ethdev.c +11
-6@@ -14,6 +14,8 @@#include <bus_driver.h> #include <eal_export.h> #include <rte_log.h> +#include <rte_cycles.h> +#include <rte_alarm.h> #include <rte_interrupts.h> #include <rte_kvargs.h> #include <rte_memcpy.h> @@ -2041,13 +2043,16 @@ rte_eth_dev_reset(uint16_t port_id)if (dev->dev_ops->dev_reset ==NULL )return -ENOTSUP ; - ret =rte_eth_dev_stop (port_id); -if (ret !=0 ) { -RTE_ETHDEV_LOG_LINE (ERR , -"Failed to stop device (port %u) before reset: %s - ignore" , - port_id,rte_strerror (-ret)); +if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) { + ret =rte_eth_dev_stop (port_id); +if (ret !=0 ) +RTE_ETHDEV_LOG_LINE (ERR , +"Failed to stop device (port %u) before reset: %s - ignore" , + port_id,rte_strerror (-ret)); + ret =eth_err (port_id, dev->dev_ops->dev_reset (dev)); + }else { + ret =ethdev_request (port_id,ETH_REQ_STOP ,NULL ,0 ); } - ret =eth_err (port_id, dev->dev_ops->dev_reset (dev));rte_ethdev_trace_reset (port_id, ret);lib/ethdev/rte_ethdev.h +22
-1@@ -170,6 +170,7 @@#include "rte_ethdev_trace_fp.h" #include "rte_dev_info.h" +#include "rte_mirror.h" #ifdef __cplusplusextern "C" {@@ -1466,7 +1467,6 @@ enum rte_eth_tunnel_type { RTE_ETH_TUNNEL_TYPE_ECPRI, RTE_ETH_TUNNEL_TYPE_MAX, }; -#ifdef __cplusplus }#endif @@ -6334,6 +6334,17 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t queue_id, nb_rx = p->rx_pkt_burst (qd, rx_pkts, nb_pkts); +#ifdef RTE_ETHDEV_MIRROR + { +const struct rte_eth_mirror *mirror + =rte_atomic_load_explicit (p->rx_mirror, rte_memory_order_relaxed); + +if (unlikely (mirror !=NULL )) +rte_eth_mirror_burst (port_id, queue_id,RTE_ETH_MIRROR_DIRECTION_INGRESS , + rx_pkts, nb_rx, mirror); + } +#endif +#ifdef RTE_ETHDEV_RXTX_CALLBACKS {void *cb;@@ -6692,6 +6703,16 @@ rte_eth_tx_burst(uint16_t port_id, uint16_t queue_id, }#endif +#ifdef RTE_ETHDEV_MIRROR + { +const struct rte_eth_mirror *mirror; + + mirror =rte_atomic_load_explicit (p->tx_mirror, rte_memory_order_relaxed); +if (unlikely (mirror !=NULL )) +rte_eth_mirror_burst (port_id, queue_id,RTE_ETH_MIRROR_DIRECTION_EGRESS , + tx_pkts, nb_pkts, mirror); + } +#endif nb_pkts = p->tx_pkt_burst (qd, tx_pkts, nb_pkts);rte_ethdev_trace_tx_burst (port_id, queue_id, (void **)tx_pkts, nb_pkts);lib/ethdev/rte_ethdev_core.h +10
-2@@ -22,6 +22,12 @@ RTE_TAILQ_HEAD(rte_eth_dev_cb_list, rte_eth_dev_callback);struct rte_eth_dev ; +struct rte_eth_mirror ; + +void rte_eth_mirror_burst (uint16_t port_id,uint16_t quque_id,uint8_t dir, +struct rte_mbuf **pkts,uint16_t nb_pkts, +const struct rte_eth_mirror *mirror); +/** * @internal Retrieve input packets from a receive queue of an Ethernet device. */ @@ -101,7 +107,8 @@ struct __rte_cache_aligned rte_eth_fp_ops {eth_rx_descriptor_status_t rx_descriptor_status;/** Refill Rx descriptors with the recycling mbufs. */ eth_recycle_rx_descriptors_refill_t recycle_rx_descriptors_refill; -uintptr_t reserved1[2 ]; +uintptr_t reserved1; +RTE_ATOMIC (struct rte_eth_mirror *) *rx_mirror;/**@}*/ /**@{*/ @@ -121,7 +128,8 @@ struct __rte_cache_aligned rte_eth_fp_ops {eth_recycle_tx_mbufs_reuse_t recycle_tx_mbufs_reuse;/** Get the number of used Tx descriptors. */ eth_tx_queue_count_t tx_queue_count; -uintptr_t reserved2[1 ]; +RTE_ATOMIC (struct rte_eth_mirror *) *tx_mirror; +uintptr_t reserved2;/**@}*/ };lib/ethdev/rte_mirror.c new file +174
-0@@ -0,0 +1,375 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Stephen Hemminger <[email protected]> +*/ + +#include <errno.h> +#include <inttypes.h> +#include <stdbool.h> +#include <stdint.h> +#include <stdio.h> +#include <string.h> + +#include <rte_config.h> +#include <rte_bitops.h> +#include <rte_eal.h> +#include <rte_log.h> +#include <rte_common.h> +#include <rte_cycles.h> +#include <rte_alarm.h> +#include <rte_ether.h> +#include <rte_malloc.h> +#include <rte_mbuf.h> +#include <rte_spinlock.h> +#include <rte_stdatomic.h> +#include <eal_export.h> + +#include "rte_ethdev.h" +#include "rte_mirror.h" +#include "ethdev_driver.h" +#include "ethdev_private.h" +#include "ethdev_trace.h" + +/* Upper bound of packet bursts redirected */ +#define RTE_MIRROR_BURST_SIZE 64 + +/* spinlock for setting up mirror ports */ +static rte_spinlock_t mirror_port_lock =RTE_SPINLOCK_INITIALIZER ; + +/* dynamically assigned offload flag to indicate ingress vs egress */ +static uint64_t mirror_origin_flag; +static int mirror_origin_offset =-1 ; +static uint64_t mirror_ingress_flag; +static uint64_t mirror_egress_flag; + +static uint64_t mbuf_timestamp_dynflag; +static int mbuf_timestamp_offset =-1 ; + +#ifdef RTE_ETHDEV_MIRROR + +/* register dynamic mbuf fields, done on first mirror creation */ +static int +ethdev_dyn_mirror_register (void ) +{ +const struct rte_mbuf_dynfield field_desc = { + .name =RTE_MBUF_DYNFIELD_MIRROR_ORIGIN , + .size =sizeof (rte_mbuf_origin_t), + .align =sizeof (rte_mbuf_origin_t), + }; +struct rte_mbuf_dynflag flag_desc = { + .name =RTE_MBUF_DYNFLAG_MIRROR_ORIGIN , + }; +int offset; + +if (rte_mbuf_dyn_tx_timestamp_register (&mbuf_timestamp_offset, + &mbuf_timestamp_dynflag) <0 ) { +RTE_ETHDEV_LOG_LINE (ERR ,"Failed to register timestamp flag" ); +return -1 ; + } + + offset =rte_mbuf_dynfield_register (&field_desc); +if (offset <0 ) { +RTE_ETHDEV_LOG_LINE (ERR ,"Failed to register mbuf origin field" ); +return -1 ; + } + mirror_origin_offset = offset; + + offset =rte_mbuf_dynflag_register (&flag_desc); +if (offset <0 ) { +RTE_ETHDEV_LOG_LINE (ERR ,"Failed to register mbuf origin flag" ); +return -1 ; + } + mirror_origin_flag =RTE_BIT64 (offset); + +strlcpy (flag_desc.name,RTE_MBUF_DYNFLAG_MIRROR_INGRESS ,sizeof (flag_desc.name)); + offset =rte_mbuf_dynflag_register (&flag_desc); +if (offset <0 ) { +RTE_ETHDEV_LOG_LINE (ERR ,"Failed to register mbuf ingress flag" ); +return -1 ; + } + mirror_ingress_flag =RTE_BIT64 (offset); + +strlcpy (flag_desc.name,RTE_MBUF_DYNFLAG_MIRROR_EGRESS , +sizeof (flag_desc.name)); + offset =rte_mbuf_dynflag_register (&flag_desc); +if (offset <0 ) { +RTE_ETHDEV_LOG_LINE (ERR ,"Failed to register mbuf egress flag" ); +return -1 ; + } + mirror_egress_flag =RTE_BIT64 (offset); + +return 0 ; +} + +/** +* Structure used to hold information mirror port mirrors for a +* queue on Rx and Tx. +*/ +struct rte_eth_mirror { +RTE_ATOMIC (struct rte_eth_mirror *) next; +struct rte_eth_mirror_conf conf; +}; + +/* Add a new mirror entry to the list. */ +static int +ethdev_insert_mirror (RTE_ATOMIC (struct rte_eth_mirror *) *top, +const struct rte_eth_mirror_conf *conf) +{ +struct rte_eth_mirror *mirror; + +/* Don't allow multiple mirrors from same source to target */ +while ((mirror = *top) !=NULL ) { +if (mirror->conf.target == conf->target) { +RTE_ETHDEV_LOG_LINE (ERR , +"Mirror to port %u already exists" , conf->target); +return -EEXIST ; + } + } + + mirror =rte_zmalloc (NULL ,sizeof (*mirror),0 ); +if (mirror ==NULL ) +return -ENOMEM ; + + mirror->conf = *conf; +/* specifying 0 implies the full packet */ +if (conf->snaplen ==0 ) + mirror->conf.snaplen =UINT32_MAX ; + + mirror->next = *top; + +rte_atomic_store_explicit (top, mirror, rte_memory_order_relaxed); +return 0 ; +} + +RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_add_mirror, 25.11) +int +rte_eth_add_mirror (uint16_t port_id,const struct rte_eth_mirror_conf *conf) +{ +RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV ); + +struct rte_eth_dev *dev = &rte_eth_devices[port_id]; +struct rte_eth_dev_info dev_info; + +if (conf ==NULL ) { +RTE_ETHDEV_LOG_LINE (ERR ,"Missing configuration information" ); +return -EINVAL ; + } + +if (conf->direction ==0 || conf->direction > + (RTE_ETH_MIRROR_DIRECTION_INGRESS |RTE_ETH_MIRROR_DIRECTION_EGRESS )) { +RTE_ETHDEV_LOG_LINE (ERR ,"Invalid direction %#x" , conf->direction); +return -EINVAL ; + } + +if (conf->mp ==NULL ) { +RTE_ETHDEV_LOG_LINE (ERR ,"not a valid mempool" ); +return -EINVAL ; + } + +if (conf->flags & ~RTE_ETH_MIRROR_FLAG_MASK ) { +RTE_ETHDEV_LOG_LINE (ERR ,"unsupported flags" ); +return -EINVAL ; + } + +/* Checks that target exists */ +int ret =rte_eth_dev_info_get (conf->target, &dev_info);
lib/ethdev/rte_mirror.c line 184
Quoted 10 lines
lib/ethdev/rte_mirror.c new file +10
-0+if (ret !=0 ) +return ret; + +/* Loopback mirror could create packet storm */ +if (conf->target == port_id) { +RTE_ETHDEV_LOG_LINE (ERR ,"Cannot mirror port to self" ); +return -EINVAL ; + } + +/* Because multiple directions and multiple queues will all going to the mirror port
Perhaps use
/*
* comment
*/
style (up to you).
Also, 'will all BE going'?
Quoted 41 lines
lib/ethdev/rte_mirror.c new file +41
-0+* need the transmit path to be lockfree. +*/ +if (!(dev_info.tx_offload_capa &RTE_ETH_TX_OFFLOAD_MT_LOCKFREE )) { +RTE_ETHDEV_LOG_LINE (ERR ,"Mirror needs lockfree transmit" ); +return -ENOTSUP ; + } + +if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) { +/* Register dynamic fields once */ +if (mirror_origin_offset <0 ) { + ret =ethdev_dyn_mirror_register (); +if (ret <0 ) +return ret; + } + +rte_spinlock_lock (&mirror_port_lock); + ret =0 ; +if (conf->direction &RTE_ETH_MIRROR_DIRECTION_INGRESS ) + ret =ethdev_insert_mirror (&dev->rx_mirror, conf); +if (ret ==0 && (conf->direction &RTE_ETH_MIRROR_DIRECTION_EGRESS )) + ret =ethdev_insert_mirror (&dev->tx_mirror, conf); +rte_spinlock_unlock (&mirror_port_lock); + }else { +/* in secondary, proxy to primary */ + ret =ethdev_request (port_id,ETH_REQ_ADD_MIRROR , conf,sizeof (*conf)); +if (ret !=0 ) +return ret; + } + +rte_eth_trace_add_mirror (port_id, conf, ret); +return ret; +} + +static bool +ethdev_delete_mirror (RTE_ATOMIC (struct rte_eth_mirror *) *top,uint16_t target_id) +{ +struct rte_eth_mirror *mirror; + +while ((mirror = *top) !=NULL ) { +if (mirror->conf.target == target_id) + goto found;
lib/ethdev/rte_mirror.c line 235
Quoted 10 lines
lib/ethdev/rte_mirror.c new file +10
-0+ top = &mirror->next; + } +/* not found in list */ +return false; + +found: +/* unlink from list */ +rte_atomic_store_explicit (top, mirror->next, rte_memory_order_relaxed); + +/* Defer freeing the mirror until after one second
Perhaps use
/*
* comment
*/
style (up to you).
Quoted 42 lines
lib/ethdev/rte_mirror.c new file +42
-0+* to allow for active threads that are using it. +* Assumes no PMD takes more than one second to transmit a burst. +* Alternative would be RCU, but RCU in DPDK is optional. +*/ +rte_eal_alarm_set (US_PER_S , rte_free, mirror); +return true; +} + +RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_remove_mirror, 25.11) +int +rte_eth_remove_mirror (uint16_t port_id,uint16_t target_id) +{ +int ret =0 ; + +RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV ); +struct rte_eth_dev *dev = &rte_eth_devices[port_id]; + +RTE_ETH_VALID_PORTID_OR_ERR_RET (target_id, -ENODEV ); + +if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) { +bool found; + +rte_spinlock_lock (&mirror_port_lock); + found =ethdev_delete_mirror (&dev->rx_mirror, target_id); + found |=ethdev_delete_mirror (&dev->tx_mirror, target_id); +rte_spinlock_unlock (&mirror_port_lock); +if (!found) + ret = -ENOENT ;/* no mirror present */ + }else { + ret =ethdev_request (port_id,ETH_REQ_REMOVE_MIRROR , + &target_id,sizeof (target_id)); + } + +rte_eth_trace_remove_mirror (port_id, target_id, ret); +return ret; +} + +static inline void +eth_dev_mirror (uint16_t port_id,uint16_t queue_id,uint8_t direction, +struct rte_mbuf **pkts,uint16_t nb_pkts, +const struct rte_eth_mirror_conf *conf) +{
lib/ethdev/rte_mirror.c line 287
Quoted 10 lines
lib/ethdev/rte_mirror.c new file +10
-0+struct rte_mbuf *tosend[RTE_MIRROR_BURST_SIZE ]; +unsigned int count =0 ; +unsigned int i; + +for (i =0 ; i < nb_pkts; i++) { +struct rte_mbuf *m = pkts[i]; +struct rte_mbuf *mc; + +if (conf->flags &RTE_ETH_MIRROR_INDIRECT_FLAG ) { + mc =rte_pktmbuf_alloc (conf->mp);
Can 'rte_pktmbuf_alloc_bulk' be used prior to the 'for' loop? I do not insist.
Quoted 45 lines
lib/ethdev/rte_mirror.c new file +45
-0+if (unlikely (mc ==NULL )) +continue ; + +/* Make both mbuf's point to the same data */ +rte_pktmbuf_attach (mc, m); + }else { + mc =rte_pktmbuf_copy (m, conf->mp,0 , conf->snaplen); +/* TODO: dropped stats? */ +if (unlikely (mc ==NULL )) +continue ; + } + +/* Put info about origin of the packet */ +if (conf->flags &RTE_ETH_MIRROR_ORIGIN_FLAG ) { +struct rte_mbuf_origin *origin + = RTE_MBUF_DYNFIELD(mc, mirror_origin_offset, rte_mbuf_origin_t *); + origin->original_len = m->pkt_len; + origin->port_id = port_id; + origin->queue_id = queue_id; + mc->ol_flags |= mirror_origin_flag; + } + +/* Insert timestamp into packet */ +if (conf->flags &RTE_ETH_MIRROR_TIMESTAMP_FLAG ) { + *RTE_MBUF_DYNFIELD(m, mbuf_timestamp_offset, rte_mbuf_timestamp_t *) + =rte_get_tsc_cycles (); + mc->ol_flags |= mbuf_timestamp_dynflag; + } + + mc->ol_flags &= ~(mirror_ingress_flag | mirror_egress_flag); +if (direction &RTE_ETH_MIRROR_DIRECTION_INGRESS ) + mc->ol_flags |= mirror_ingress_flag; +else if (direction &RTE_ETH_MIRROR_DIRECTION_EGRESS ) + mc->ol_flags |= mirror_egress_flag; + + tosend[count++] = mc; + } + +uint16_t nsent =rte_eth_tx_burst (conf->target,0 , tosend, count); +if (unlikely (nsent < count)) { +uint16_t drop = count - nsent; + +/* TODO: need some stats here? */ +rte_pktmbuf_free_bulk (pkts + nsent, drop); + }
lib/ethdev/rte_mirror.c line 342
Quoted 10 lines
lib/ethdev/rte_mirror.c new file +10
-0+} + +/* This function is really internal but used from inline */ +RTE_EXPORT_SYMBOL (rte_eth_mirror_burst) +void +rte_eth_mirror_burst (uint16_t port_id,uint16_t queue_id,uint8_t direction, +struct rte_mbuf **pkts,uint16_t nb_pkts, +const struct rte_eth_mirror *mirror) +{ +unsigned int i;
Perhaps move this to the inside of 'while' below.
Quoted 99 lines
lib/ethdev/rte_mirror.c new file +33
-0+ +while (mirror !=NULL ) { +for (i =0 ; i < nb_pkts; i +=RTE_MIRROR_BURST_SIZE ) { +uint16_t left = nb_pkts - i; +uint16_t burst =RTE_MIN (left,RTE_MIRROR_BURST_SIZE ); + +eth_dev_mirror (port_id, queue_id, direction, + pkts + i, burst, &mirror->conf); + } + + mirror =rte_atomic_load_explicit (&mirror->next, rte_memory_order_relaxed); + } +} + +#else + +RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_add_mirror, 25.11) +int +rte_eth_add_mirror(uint16_t port_id __rte_unused, + const struct rte_eth_mirror_conf *conf __rte_unused) +{ +return -ENOTSUP ; +} + + +RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_remove_mirror, 25.11) +int +rte_eth_remove_mirror(uint16_t port_id __rte_unused, uint16_t target_id __rte_unused) +{ +return -ENOTSUP ; + +} +#endif /* RTE_ETHDEV_MIRROR */ lib/ethdev/rte_mirror.h new file +60
-0@@ -0,0 +1,99 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Stephen Hemminger <[email protected]> +*/ + +#ifndef RTE_MIRROR_H_ +#define RTE_MIRROR_H_ + +#include <stdint.h> + +#include <rte_compat.h> +#include <rte_mbuf.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file + * Ethdev port mirroring + * + * This interface provides the ability to duplicate packets to another port. + */ + +/* Definitions for ethdev analyzer direction */ +#define RTE_ETH_MIRROR_DIRECTION_INGRESS 1 +#define RTE_ETH_MIRROR_DIRECTION_EGRESS 2 + +/** + * @warning + * @b EXPERIMENTAL: this structure may change without prior notice. + * + * This dynamic field is added to mbuf's when they are copied to + * the port mirror. + */ +typedef struct rte_mbuf_origin { + uint32_t original_len; /**< Packet length before copy */ + uint16_t port_id; /**< Port where packet originated */ + uint16_t queue_id; /**< Queue used for Tx or Rx */ +} rte_mbuf_origin_t; + +/** + * @warning + * @b EXPERIMENTAL: this structure may change without prior notice. + * + * Structure used to configure ethdev Switched Port Analyzer (MIRROR) + */ +struct rte_eth_mirror_conf { + struct rte_mempool *mp; /**< Memory pool for copies, If NULL then cloned. */ + uint32_t snaplen; /**< Upper limit on number of bytes to copy */ + uint32_t flags; /**< bitmask of RTE_ETH_MIRROR_XXX_FLAG's */ + uint16_t target; /**< Destination port */ + uint8_t direction; /**< bitmask of RTE_ETH_MIRROR_DIRECTION_XXX */ +}; + +#define RTE_ETH_MIRROR_TIMESTAMP_FLAG 1 /**< insert timestamp into mirrored packet */ +#define RTE_ETH_MIRROR_ORIGIN_FLAG 2 /**< insert rte_mbuf_origin into mirrored packet */ +#define RTE_ETH_MIRROR_INDIRECT_FLAG 4 /**< use rte_mbuf_attach rather than copy */ + +#define RTE_ETH_MIRROR_FLAG_MASK 7 +
lib/ethdev/rte_mirror.h line 70
Quoted 10 lines
lib/ethdev/rte_mirror.h new file +10
-0+/** +* @warning +* @b EXPERIMENTAL: this API may change, or be removed, without prior notice +* +* Create a Switched Port Analyzer (MIRROR) instance. +* +* @param port_id +* The port identifier of the source Ethernet device. +* @param conf +* Settings for this MIRROR instance..
Redundant 'period' sign at the end.
lib/ethdev/rte_mirror.h line 82
Quoted 12 lines
lib/ethdev/rte_mirror.h new file +12
-0+* @return +* Negative errno value on error, 0 on success. +*/ +__rte_experimental +int +rte_eth_add_mirror (uint16_t port_id,const struct rte_eth_mirror_conf *conf); + +/** +* @warning +* @b EXPERIMENTAL: this API may change, or be removed, without prior notice +* +* Break port mirrorning.
Could be a typo: mirror'n'ing.
lib/ethdev/rte_mirror.h line 83
Quoted 1 line
lib/ethdev/rte_mirror.h new file +1
-0+* After this call no more packets will be sent the target port.
Perhaps 'to the target port'? It's up to you.
Thank you.
Quoted 20 lines
lib/ethdev/rte_mirror.h new file +16
-0+* +* @param port_id +* The port identifier of the source Ethernet device. +* @param target_id +* The identifier of the destination port. +* @return +* Negative errno value on error, 0 on success. +*/ +__rte_experimental +int rte_eth_remove_mirror(uint16_t port_id, uint16_t target_id); + +#ifdef __cplusplus +} +#endif + +#endif /* RTE_MIRROR_H_ */ Signature · 1 line
2.47.2
Re: [PATCH v6 07/13] ethdev: add port mirroring feature
Quoted 18 lines · On Wed, 23 Jul 2025 06:13:27 +0400 (+04) Ivan Malov…
+static inline void
Quoted 4 lines
lib/ethdev/rte_mirror.c new file +4
-0+eth_dev_mirror(uint16_t port_id, uint16_t queue_id, uint8_t direction, + struct rte_mbuf **pkts, uint16_t nb_pkts, + const struct rte_eth_mirror_conf *conf) +{lib/ethdev/rte_mirror.c line 287
Quoted 10 lines
lib/ethdev/rte_mirror.c new file +10
-0+struct rte_mbuf *tosend[RTE_MIRROR_BURST_SIZE ]; +unsigned int count =0 ; +unsigned int i; + +for (i =0 ; i < nb_pkts; i++) { +struct rte_mbuf *m = pkts[i]; +struct rte_mbuf *mc; + +if (conf->flags &RTE_ETH_MIRROR_INDIRECT_FLAG ) { + mc =rte_pktmbuf_alloc (conf->mp);Can '
rte_pktmbuf_alloc_bulk' be used prior to the 'for' loop? I do not insist.
Quoted 12 lines
lib/ethdev/rte_mirror.c line 298
Quoted 12 lines
lib/ethdev/rte_mirror.c new file +11
-0+if (unlikely (mc ==NULL )) +continue ; + +/* Make both mbuf's point to the same data */ +rte_pktmbuf_attach (mc, m); + }else { + mc =rte_pktmbuf_copy (m, conf->mp,0 , conf->snaplen); +/* TODO: dropped stats? */ +if (unlikely (mc ==NULL )) +continue ; + }
Both sides could use a bulk allocated array, but would need new variant of rte_pktmbuf_copy for that.
Re: [PATCH v6 07/13] ethdev: add port mirroring feature
Quoted 21 lines · Stephen Hemminger
Quoted 18 lines · On Wed, 23 Jul 2025 06:13:27 +0400 (+04) Ivan Malov…
+static inline void
Quoted 4 lines
lib/ethdev/rte_mirror.c new file +4
-0+eth_dev_mirror(uint16_t port_id, uint16_t queue_id, uint8_t direction, + struct rte_mbuf **pkts, uint16_t nb_pkts, + const struct rte_eth_mirror_conf *conf) +{lib/ethdev/rte_mirror.c line 287
Quoted 10 lines
lib/ethdev/rte_mirror.c new file +10
-0+struct rte_mbuf *tosend[RTE_MIRROR_BURST_SIZE ]; +unsigned int count =0 ; +unsigned int i; + +for (i =0 ; i < nb_pkts; i++) { +struct rte_mbuf *m = pkts[i]; +struct rte_mbuf *mc; + +if (conf->flags &RTE_ETH_MIRROR_INDIRECT_FLAG ) { + mc =rte_pktmbuf_alloc (conf->mp);Can '
rte_pktmbuf_alloc_bulk' be used prior to the 'for' loop? I do not insist.
Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
lib/ethdev/rte_mirror.c new file +4
-0+if (unlikely (mc ==NULL )) +continue ; + +/* Make both mbuf's point to the same data */ Quoted 8 lines
lib/ethdev/rte_mirror.c line 298
Quoted 8 lines
lib/ethdev/rte_mirror.c new file +7
-0+rte_pktmbuf_attach (mc, m); + }else { + mc =rte_pktmbuf_copy (m, conf->mp,0 , conf->snaplen); +/* TODO: dropped stats? */ +if (unlikely (mc ==NULL )) +continue ; + }Both sides could use a bulk allocated array, but would need new variant of
rte_pktmbuf_copyfor that.
I see. I just meant may be something like this could be done before the loop.
Quoted 3 lines
if (conf->flags & RTE_ETH_MIRROR_INDIRECT_FLAG) {
// do bulk alloc -> tosend
}But OK, understood.
Thank you.
Quoted 1 line
PATCH v6 8/13 pcapng: split packet copy from header insertion
In reply to Stephen HemmingerIn new model, the packet was already copied, only need to wrap it in pcapng format.
--- lib/pcapng/rte_pcapng.c | 178 +++++++++++++++++++++------------------- lib/pcapng/rte_pcapng.h | 27 +++++- 2 files changed, 120 insertions(+), 85 deletions(-)
lib/pcapng/rte_pcapng.c +95 -83
@@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2019 Microsoft Corporation */
@@ -432,8 +433,24 @@ pcapng_vlan_insert(struct rte_mbuf *m, uint16_t ether_type, uint16_t tci)return 0 ; } +/* pad the packet to 32 bit boundary */ +static inline int +pcapng_mbuf_pad32 (struct rte_mbuf *m) +{ +uint32_t pkt_len =rte_pktmbuf_pkt_len (m); +uint32_t padding =RTE_ALIGN (pkt_len,sizeof (uint32_t )) - pkt_len; + +if (padding >0 ) { +void *tail =rte_pktmbuf_append (m, padding); +if (tail ==NULL ) +return -1 ; +memset (tail,0 , padding); + } +return 0 ; +} +/* -* The mbufs created use the Pcapng standard enhanced packet block. +* The mbufs created use the Pcapng standard enhanced packet block. * * 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
@@ -468,71 +485,28 @@ pcapng_vlan_insert(struct rte_mbuf *m, uint16_t ether_type, uint16_t tci)* | Block Total Length | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ - -/* Make a copy of original mbuf with pcapng header and options */ -RTE_EXPORT_SYMBOL (rte_pcapng_copy) -struct rte_mbuf * -rte_pcapng_copy (uint16_t port_id,uint32_t queue, -const struct rte_mbuf *md, -struct rte_mempool *mp, -uint32_t length, -enum rte_pcapng_direction direction, -const char *comment) +RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pcapng_insert, 25.07) +int +rte_pcapng_insert (struct rte_mbuf *m,uint32_t queue, +enum rte_pcapng_direction direction,uint32_t orig_len, +uint64_t timestamp,const char *comment) {struct pcapng_enhance_packet_block *epb; -uint32_t orig_len, pkt_len, padding, flags; -struct pcapng_option *opt; -uint64_t timestamp; -uint16_t optlen; -struct rte_mbuf *mc; -bool rss_hash; - -#ifdef RTE_LIBRTE_ETHDEV_DEBUG -RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id,NULL ); -#endif - orig_len =rte_pktmbuf_pkt_len (md); +uint32_t pkt_len =rte_pktmbuf_pkt_len (m); +uint32_t flags; -/* Take snapshot of the data */ - mc =rte_pktmbuf_copy (md, mp,0 , length); -if (unlikely (mc ==NULL )) -return NULL ; - -/* Expand any offloaded VLAN information */ -if ((direction ==RTE_PCAPNG_DIRECTION_IN && - (md->ol_flags &RTE_MBUF_F_RX_VLAN_STRIPPED )) || - (direction ==RTE_PCAPNG_DIRECTION_OUT && - (md->ol_flags &RTE_MBUF_F_TX_VLAN ))) { -if (pcapng_vlan_insert (mc,RTE_ETHER_TYPE_VLAN , - md->vlan_tci) !=0 ) - goto fail; - } +if (unlikely (pcapng_mbuf_pad32 (m) <0 )) +return -1 ; -if ((direction ==RTE_PCAPNG_DIRECTION_IN && - (md->ol_flags &RTE_MBUF_F_RX_QINQ_STRIPPED )) || - (direction ==RTE_PCAPNG_DIRECTION_OUT && - (md->ol_flags &RTE_MBUF_F_TX_QINQ ))) { -if (pcapng_vlan_insert (mc,RTE_ETHER_TYPE_QINQ , - md->vlan_tci_outer) !=0 ) - goto fail; - } +uint16_t optlen =pcapng_optlen (sizeof (flags)); -/* record HASH on incoming packets */ - rss_hash = (direction ==RTE_PCAPNG_DIRECTION_IN && - (md->ol_flags &RTE_MBUF_F_RX_RSS_HASH )); +/* make queue optional? */ + optlen +=pcapng_optlen (sizeof (queue)); -/* pad the packet to 32 bit boundary */ - pkt_len =rte_pktmbuf_pkt_len (mc); - padding =RTE_ALIGN (pkt_len,sizeof (uint32_t )) - pkt_len; -if (padding >0 ) { -void *tail =rte_pktmbuf_append (mc, padding); +/* does packet have valid RSS hash to include */ +bool rss_hash = (direction ==RTE_PCAPNG_DIRECTION_IN && + (m->ol_flags &RTE_MBUF_F_RX_RSS_HASH )); -if (tail ==NULL ) - goto fail; -memset (tail,0 , padding); - } - - optlen =pcapng_optlen (sizeof (flags)); - optlen +=pcapng_optlen (sizeof (queue));if (rss_hash) optlen +=pcapng_optlen (sizeof (uint8_t ) +sizeof (uint32_t ));
@@ -540,10 +514,10 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue, optlen +=pcapng_optlen (strlen (comment));/* reserve trailing options and block length */ - opt = (struct pcapng_option *) -rte_pktmbuf_append (mc, optlen +sizeof (uint32_t )); +struct pcapng_option *opt = (struct pcapng_option *) +rte_pktmbuf_append (m, optlen +sizeof (uint32_t ));if (unlikely (opt ==NULL )) - goto fail; +return -1 ;switch (direction) {case RTE_PCAPNG_DIRECTION_IN :
@@ -556,24 +530,20 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue, flags =0 ; } - opt =pcapng_add_option (opt,PCAPNG_EPB_FLAGS , - &flags,sizeof (flags)); - - opt =pcapng_add_option (opt,PCAPNG_EPB_QUEUE , - &queue,sizeof (queue)); + opt =pcapng_add_option (opt,PCAPNG_EPB_FLAGS , &flags,sizeof (flags)); + opt =pcapng_add_option (opt,PCAPNG_EPB_QUEUE , &queue,sizeof (queue));if (rss_hash) {uint8_t hash_opt[5 ]; -/* The algorithm could be something else if -* using rte_flow_action_rss; but the current API does not -* have a way for ethdev to report this on a per-packet basis. +/* The algorithm could be something else but the current API does not +* have a way for to record this on a per-packet basis +* and the PCAPNG hash types don't match the DPDK types. */ hash_opt[0 ] =PCAPNG_HASH_TOEPLITZ ; -memcpy (&hash_opt[1 ], &md->hash.rss,sizeof (uint32_t )); - opt =pcapng_add_option (opt,PCAPNG_EPB_HASH , - &hash_opt,sizeof (hash_opt)); +memcpy (&hash_opt[1 ], &m->hash.rss,sizeof (uint32_t )); + opt =pcapng_add_option (opt,PCAPNG_EPB_HASH , &hash_opt,sizeof (hash_opt)); }if (comment)
@@ -583,19 +553,14 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,/* Note: END_OPT necessary here. Wireshark doesn't do it. */ /* Add PCAPNG packet header */ - epb = (struct pcapng_enhance_packet_block *) -rte_pktmbuf_prepend (mc,sizeof (*epb)); + epb = (struct pcapng_enhance_packet_block *)rte_pktmbuf_prepend (m,sizeof (*epb));if (unlikely (epb ==NULL )) - goto fail; +return -1 ; epb->block_type =PCAPNG_ENHANCED_PACKET_BLOCK ; - epb->block_length =rte_pktmbuf_pkt_len (mc); - -/* Interface index is filled in later during write */ - mc->port = port_id; + epb->block_length =rte_pktmbuf_pkt_len (m); -/* Put timestamp in cycles here - adjust in packet write */ - timestamp =rte_get_tsc_cycles (); +/* Put timestamp in cycles here - adjusted in packet write */ epb->timestamp_hi = timestamp >>32 ; epb->timestamp_lo = (uint32_t )timestamp; epb->capture_length = pkt_len;
@@ -603,9 +568,56 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,/* set trailer of block length */ *(uint32_t *)opt = epb->block_length; +return 0 ; +} + +/* Make a copy of original mbuf with pcapng header and options */ +RTE_EXPORT_SYMBOL (rte_pcapng_copy) +struct rte_mbuf * +rte_pcapng_copy (uint16_t port_id,uint32_t queue, +const struct rte_mbuf *md, +struct rte_mempool *mp, +uint32_t length, +enum rte_pcapng_direction direction, +const char *comment) +{ +uint32_t orig_len =rte_pktmbuf_pkt_len (md); +struct rte_mbuf *mc; -return mc; +#ifdef RTE_LIBRTE_ETHDEV_DEBUG +RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id,NULL ); +#endif + +/* Take snapshot of the data */ + mc =rte_pktmbuf_copy (md, mp,0 , length); +if (unlikely (mc ==NULL )) +return NULL ; + +/* Expand any offloaded VLAN information */ +if ((direction ==RTE_PCAPNG_DIRECTION_IN && + (md->ol_flags &RTE_MBUF_F_RX_VLAN_STRIPPED )) || + (direction ==RTE_PCAPNG_DIRECTION_OUT && + (md->ol_flags &RTE_MBUF_F_TX_VLAN ))) { +if (pcapng_vlan_insert (mc,RTE_ETHER_TYPE_VLAN , + md->vlan_tci) !=0 ) + goto fail; + } + +if ((direction ==RTE_PCAPNG_DIRECTION_IN && + (md->ol_flags &RTE_MBUF_F_RX_QINQ_STRIPPED )) || + (direction ==RTE_PCAPNG_DIRECTION_OUT && + (md->ol_flags &RTE_MBUF_F_TX_QINQ ))) { +if (pcapng_vlan_insert (mc,RTE_ETHER_TYPE_QINQ , + md->vlan_tci_outer) !=0 ) + goto fail; + } + +/* Interface index is filled in later during write */ + mc->port = port_id; +if (likely (rte_pcapng_insert (mc, queue, direction, orig_len, +rte_get_tsc_cycles (), comment) ==0 )) +return mc; fail:rte_pktmbuf_free (mc);return NULL ;
lib/pcapng/rte_pcapng.h +25 -2
@@ -99,7 +99,7 @@ enum rte_pcapng_direction { };/** -* Format an mbuf for writing to file. +* Make a copy of mbuf for writing to file. * * @param port_id * The Ethernet port on which packet was received
@@ -117,7 +117,7 @@ enum rte_pcapng_direction {* @param direction * The direction of the packer: receive, transmit or unknown. * @param comment -* Packet comment. +* Packet comment (optional). * * @return * - The pointer to the new mbuf formatted for pcapng_write
@@ -129,6 +129,29 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,uint32_t length, enum rte_pcapng_direction direction, const char *comment); +/** +* Format an mbuf for writing to file. +* +* @param m +* The mbuf to modify. +* @param queue +* The queue on the Ethernet port where packet was received +* or is going to be transmitted. +* @param direction +* The direction of the packer: receive, transmit or unknown. +* @param orig_len +* The length of the original packet which maybe less than actual +* packet if only a snapshot was captured. +* @param timestamp +* The timestamp for packet in TSC cycles. +* @param comment +* Packet comment (optional). +*/ +__rte_experimental +int +rte_pcapng_insert (struct rte_mbuf *m,uint32_t queue, +enum rte_pcapng_direction direction,uint32_t orig_len, +uint64_t timestamp,const char *comment);/** * Determine optimum mbuf data size.
Signature · 1 line
2.47.2
Re: [PATCH v6 08/13] pcapng: split packet copy from header insertion
Hi Stephen,
Quoted 1 line · Stephen Hemminger
In new model, the packet was already copied, only need
Copied? But what if it was "indirect attached" instead, as the model envisages?
Perhaps this is a silly question of mine, but it may not be clear what happens in case of 'RTE_ETH_MIRROR_INDIRECT_FLAG' - whether it is safe to modify the mbuf and whether the 'indirect' clone has to be "freed" in the sense of being detached/refcnt updated after successful pcapng write, to avoid memory leaks?
Quoted 20 lines
to wrap it in pcapng format.
Signed-off-by Stephen Hemminger <[email protected]>---
lib/pcapng/rte_pcapng.c| 178 +++++++++++++++++++++-------------------lib/pcapng/rte_pcapng.h| 27 +++++-2 files changed, 120 insertions(+), 85 deletions(-)lib/pcapng/rte_pcapng.c +1
-0@@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2019 Microsoft Corporation */ @@ -432,8 +433,24 @@ pcapng_vlan_insert(struct rte_mbuf *m, uint16_t ether_type, uint16_t tci)return 0 ; }
lib/pcapng/rte_pcapng.c pcapng_vlan_insert(struct rte_mbuf *m, uint16_t ether_type, uint16_t tci) · line 444
Quoted 10 lines
lib/pcapng/rte_pcapng.c +9
-0+/* pad the packet to 32 bit boundary */ +static inline int +pcapng_mbuf_pad32 (struct rte_mbuf *m) +{ +uint32_t pkt_len =rte_pktmbuf_pkt_len (m); +uint32_t padding =RTE_ALIGN (pkt_len,sizeof (uint32_t )) - pkt_len; + +if (padding >0 ) { +void *tail =rte_pktmbuf_append (m, padding);
If the packet was indirectly attached in fact, is this OK to do? Just asking.
Thank you.
Quoted 284 lines
lib/pcapng/rte_pcapng.c +85
-83+if (tail ==NULL ) +return -1 ; +memset (tail,0 , padding); + } +return 0 ; +} +/* -* The mbufs created use the Pcapng standard enhanced packet block. +* The mbufs created use the Pcapng standard enhanced packet block. * * 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 @@ -468,71 +485,28 @@ pcapng_vlan_insert(struct rte_mbuf *m, uint16_t ether_type, uint16_t tci)* | Block Total Length | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ - -/* Make a copy of original mbuf with pcapng header and options */ -RTE_EXPORT_SYMBOL (rte_pcapng_copy) -struct rte_mbuf * -rte_pcapng_copy (uint16_t port_id,uint32_t queue, -const struct rte_mbuf *md, -struct rte_mempool *mp, -uint32_t length, -enum rte_pcapng_direction direction, -const char *comment) +RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pcapng_insert, 25.07) +int +rte_pcapng_insert (struct rte_mbuf *m,uint32_t queue, +enum rte_pcapng_direction direction,uint32_t orig_len, +uint64_t timestamp,const char *comment) {struct pcapng_enhance_packet_block *epb; -uint32_t orig_len, pkt_len, padding, flags; -struct pcapng_option *opt; -uint64_t timestamp; -uint16_t optlen; -struct rte_mbuf *mc; -bool rss_hash; - -#ifdef RTE_LIBRTE_ETHDEV_DEBUG -RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id,NULL ); -#endif - orig_len =rte_pktmbuf_pkt_len (md); +uint32_t pkt_len =rte_pktmbuf_pkt_len (m); +uint32_t flags; -/* Take snapshot of the data */ - mc =rte_pktmbuf_copy (md, mp,0 , length); -if (unlikely (mc ==NULL )) -return NULL ; - -/* Expand any offloaded VLAN information */ -if ((direction ==RTE_PCAPNG_DIRECTION_IN && - (md->ol_flags &RTE_MBUF_F_RX_VLAN_STRIPPED )) || - (direction ==RTE_PCAPNG_DIRECTION_OUT && - (md->ol_flags &RTE_MBUF_F_TX_VLAN ))) { -if (pcapng_vlan_insert (mc,RTE_ETHER_TYPE_VLAN , - md->vlan_tci) !=0 ) - goto fail; - } +if (unlikely (pcapng_mbuf_pad32 (m) <0 )) +return -1 ; -if ((direction ==RTE_PCAPNG_DIRECTION_IN && - (md->ol_flags &RTE_MBUF_F_RX_QINQ_STRIPPED )) || - (direction ==RTE_PCAPNG_DIRECTION_OUT && - (md->ol_flags &RTE_MBUF_F_TX_QINQ ))) { -if (pcapng_vlan_insert (mc,RTE_ETHER_TYPE_QINQ , - md->vlan_tci_outer) !=0 ) - goto fail; - } +uint16_t optlen =pcapng_optlen (sizeof (flags)); -/* record HASH on incoming packets */ - rss_hash = (direction ==RTE_PCAPNG_DIRECTION_IN && - (md->ol_flags &RTE_MBUF_F_RX_RSS_HASH )); +/* make queue optional? */ + optlen +=pcapng_optlen (sizeof (queue)); -/* pad the packet to 32 bit boundary */ - pkt_len =rte_pktmbuf_pkt_len (mc); - padding =RTE_ALIGN (pkt_len,sizeof (uint32_t )) - pkt_len; -if (padding >0 ) { -void *tail =rte_pktmbuf_append (mc, padding); +/* does packet have valid RSS hash to include */ +bool rss_hash = (direction ==RTE_PCAPNG_DIRECTION_IN && + (m->ol_flags &RTE_MBUF_F_RX_RSS_HASH )); -if (tail ==NULL ) - goto fail; -memset (tail,0 , padding); - } - - optlen =pcapng_optlen (sizeof (flags)); - optlen +=pcapng_optlen (sizeof (queue));if (rss_hash) optlen +=pcapng_optlen (sizeof (uint8_t ) +sizeof (uint32_t ));@@ -540,10 +514,10 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue, optlen +=pcapng_optlen (strlen (comment));/* reserve trailing options and block length */ - opt = (struct pcapng_option *) -rte_pktmbuf_append (mc, optlen +sizeof (uint32_t )); +struct pcapng_option *opt = (struct pcapng_option *) +rte_pktmbuf_append (m, optlen +sizeof (uint32_t ));if (unlikely (opt ==NULL )) - goto fail; +return -1 ;switch (direction) {case RTE_PCAPNG_DIRECTION_IN :@@ -556,24 +530,20 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue, flags =0 ; } - opt =pcapng_add_option (opt,PCAPNG_EPB_FLAGS , - &flags,sizeof (flags)); - - opt =pcapng_add_option (opt,PCAPNG_EPB_QUEUE , - &queue,sizeof (queue)); + opt =pcapng_add_option (opt,PCAPNG_EPB_FLAGS , &flags,sizeof (flags)); + opt =pcapng_add_option (opt,PCAPNG_EPB_QUEUE , &queue,sizeof (queue));if (rss_hash) {uint8_t hash_opt[5 ]; -/* The algorithm could be something else if -* using rte_flow_action_rss; but the current API does not -* have a way for ethdev to report this on a per-packet basis. +/* The algorithm could be something else but the current API does not +* have a way for to record this on a per-packet basis +* and the PCAPNG hash types don't match the DPDK types. */ hash_opt[0 ] =PCAPNG_HASH_TOEPLITZ ; -memcpy (&hash_opt[1 ], &md->hash.rss,sizeof (uint32_t )); - opt =pcapng_add_option (opt,PCAPNG_EPB_HASH , - &hash_opt,sizeof (hash_opt)); +memcpy (&hash_opt[1 ], &m->hash.rss,sizeof (uint32_t )); + opt =pcapng_add_option (opt,PCAPNG_EPB_HASH , &hash_opt,sizeof (hash_opt)); }if (comment)@@ -583,19 +553,14 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,/* Note: END_OPT necessary here. Wireshark doesn't do it. */ /* Add PCAPNG packet header */ - epb = (struct pcapng_enhance_packet_block *) -rte_pktmbuf_prepend (mc,sizeof (*epb)); + epb = (struct pcapng_enhance_packet_block *)rte_pktmbuf_prepend (m,sizeof (*epb));if (unlikely (epb ==NULL )) - goto fail; +return -1 ; epb->block_type =PCAPNG_ENHANCED_PACKET_BLOCK ; - epb->block_length =rte_pktmbuf_pkt_len (mc); - -/* Interface index is filled in later during write */ - mc->port = port_id; + epb->block_length =rte_pktmbuf_pkt_len (m); -/* Put timestamp in cycles here - adjust in packet write */ - timestamp =rte_get_tsc_cycles (); +/* Put timestamp in cycles here - adjusted in packet write */ epb->timestamp_hi = timestamp >>32 ; epb->timestamp_lo = (uint32_t )timestamp; epb->capture_length = pkt_len;@@ -603,9 +568,56 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,/* set trailer of block length */ *(uint32_t *)opt = epb->block_length; +return 0 ; +} + +/* Make a copy of original mbuf with pcapng header and options */ +RTE_EXPORT_SYMBOL (rte_pcapng_copy) +struct rte_mbuf * +rte_pcapng_copy (uint16_t port_id,uint32_t queue, +const struct rte_mbuf *md, +struct rte_mempool *mp, +uint32_t length, +enum rte_pcapng_direction direction, +const char *comment) +{ +uint32_t orig_len =rte_pktmbuf_pkt_len (md); +struct rte_mbuf *mc; -return mc; +#ifdef RTE_LIBRTE_ETHDEV_DEBUG +RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id,NULL ); +#endif + +/* Take snapshot of the data */ + mc =rte_pktmbuf_copy (md, mp,0 , length); +if (unlikely (mc ==NULL )) +return NULL ; + +/* Expand any offloaded VLAN information */ +if ((direction ==RTE_PCAPNG_DIRECTION_IN && + (md->ol_flags &RTE_MBUF_F_RX_VLAN_STRIPPED )) || + (direction ==RTE_PCAPNG_DIRECTION_OUT && + (md->ol_flags &RTE_MBUF_F_TX_VLAN ))) { +if (pcapng_vlan_insert (mc,RTE_ETHER_TYPE_VLAN , + md->vlan_tci) !=0 ) + goto fail; + } + +if ((direction ==RTE_PCAPNG_DIRECTION_IN && + (md->ol_flags &RTE_MBUF_F_RX_QINQ_STRIPPED )) || + (direction ==RTE_PCAPNG_DIRECTION_OUT && + (md->ol_flags &RTE_MBUF_F_TX_QINQ ))) { +if (pcapng_vlan_insert (mc,RTE_ETHER_TYPE_QINQ , + md->vlan_tci_outer) !=0 ) + goto fail; + } + +/* Interface index is filled in later during write */ + mc->port = port_id; +if (likely (rte_pcapng_insert (mc, queue, direction, orig_len, +rte_get_tsc_cycles (), comment) ==0 )) +return mc;fail:
rte_pktmbuf_free(mc); return NULL;lib/pcapng/rte_pcapng.h +25
-2@@ -99,7 +99,7 @@ enum rte_pcapng_direction { };/** -* Format an mbuf for writing to file. +* Make a copy of mbuf for writing to file. * * @param port_id * The Ethernet port on which packet was received @@ -117,7 +117,7 @@ enum rte_pcapng_direction {* @param direction * The direction of the packer: receive, transmit or unknown. * @param comment -* Packet comment. +* Packet comment (optional). * * @return * - The pointer to the new mbuf formatted for pcapng_write @@ -129,6 +129,29 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,uint32_t length, enum rte_pcapng_direction direction, const char *comment); +/** +* Format an mbuf for writing to file. +* +* @param m +* The mbuf to modify. +* @param queue +* The queue on the Ethernet port where packet was received +* or is going to be transmitted. +* @param direction +* The direction of the packer: receive, transmit or unknown. +* @param orig_len +* The length of the original packet which maybe less than actual +* packet if only a snapshot was captured. +* @param timestamp +* The timestamp for packet in TSC cycles. +* @param comment +* Packet comment (optional). +*/ +__rte_experimental +int +rte_pcapng_insert (struct rte_mbuf *m,uint32_t queue, +enum rte_pcapng_direction direction,uint32_t orig_len, +uint64_t timestamp,const char *comment);/** * Determine optimum mbuf data size. Signature · 1 line
2.47.2
Re: [PATCH v6 08/13] pcapng: split packet copy from header insertion
Quoted 4 lines · Ivan Malov
Hi Stephen,
On Tue, 22 Jul 2025, Stephen Hemminger wrote:
Quoted 8 lines
Quoted 1 line
In new model, the packet was already copied, only need
Copied? But what if it was "indirect attached" instead, as the model envisages?
Perhaps this is a silly question of mine, but it may not be clear what happens in case of '
RTE_ETH_MIRROR_INDIRECT_FLAG' - whether it is safe to modify the mbuf and whether the 'indirect' clone has to be "freed" in the sense of being detached/refcnt updated after successful pcapng write, to avoid memory leaks?
Presumably, no leaks, - I now see 'rte_pktmbuf_free_bulk' invocation outside the invocation of 'pcap_write_packets'. But the question about INDIRECT stands.
Thank you.
Quoted 329 lines
Quoted 22 lines
to wrap it in pcapng format.
Signed-off-by Stephen Hemminger <[email protected]>---
lib/pcapng/rte_pcapng.c| 178 +++++++++++++++++++++-------------------lib/pcapng/rte_pcapng.h| 27 +++++-2 files changed, 120 insertions(+), 85 deletions(-)lib/pcapng/rte_pcapng.c +1
-0@@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2019 Microsoft Corporation */ @@ -432,8 +433,24 @@ pcapng_vlan_insert(struct rte_mbuf *m, uint16_t ether_type, uint16_t tci)return 0 ; }lib/pcapng/rte_pcapng.c pcapng_vlan_insert(struct rte_mbuf *m, uint16_t · line 445
Quoted 10 lines
lib/pcapng/rte_pcapng.c +9
-0+/* pad the packet to 32 bit boundary */ +static inline int +pcapng_mbuf_pad32 (struct rte_mbuf *m) +{ +uint32_t pkt_len =rte_pktmbuf_pkt_len (m); +uint32_t padding =RTE_ALIGN (pkt_len,sizeof (uint32_t )) - pkt_len; + +if (padding >0 ) { +void *tail =rte_pktmbuf_append (m, padding);If the packet was indirectly attached in fact, is this OK to do? Just asking.
Thank you.
Quoted 291 lines
lib/pcapng/rte_pcapng.c +8
-1+if (tail ==NULL ) +return -1 ; +memset (tail,0 , padding); + } +return 0 ; +} +/* -* The mbufs created use the Pcapng standard enhanced packet block. +* The mbufs created use the Pcapng standard enhanced packet block. * * 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
lib/pcapng/rte_pcapng.c +20
-69@@ -468,71 +485,28 @@ pcapng_vlan_insert(struct rte_mbuf *m, uint16_tether_type, uint16_t tci) * | Block Total Length | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ - -/* Make a copy of original mbuf with pcapng header and options */ -RTE_EXPORT_SYMBOL (rte_pcapng_copy) -struct rte_mbuf * -rte_pcapng_copy (uint16_t port_id,uint32_t queue, -const struct rte_mbuf *md, -struct rte_mempool *mp, -uint32_t length, -enum rte_pcapng_direction direction, -const char *comment) +RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pcapng_insert, 25.07) +int +rte_pcapng_insert (struct rte_mbuf *m,uint32_t queue, +enum rte_pcapng_direction direction,uint32_t orig_len, +uint64_t timestamp,const char *comment) {struct pcapng_enhance_packet_block *epb; -uint32_t orig_len, pkt_len, padding, flags; -struct pcapng_option *opt; -uint64_t timestamp; -uint16_t optlen; -struct rte_mbuf *mc; -bool rss_hash; - -#ifdef RTE_LIBRTE_ETHDEV_DEBUG -RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id,NULL ); -#endif - orig_len =rte_pktmbuf_pkt_len (md); +uint32_t pkt_len =rte_pktmbuf_pkt_len (m); +uint32_t flags; -/* Take snapshot of the data */ - mc =rte_pktmbuf_copy (md, mp,0 , length); -if (unlikely (mc ==NULL )) -return NULL ; - -/* Expand any offloaded VLAN information */ -if ((direction ==RTE_PCAPNG_DIRECTION_IN && - (md->ol_flags &RTE_MBUF_F_RX_VLAN_STRIPPED )) || - (direction ==RTE_PCAPNG_DIRECTION_OUT && - (md->ol_flags &RTE_MBUF_F_TX_VLAN ))) { -if (pcapng_vlan_insert (mc,RTE_ETHER_TYPE_VLAN , - md->vlan_tci) !=0 ) - goto fail; - } +if (unlikely (pcapng_mbuf_pad32 (m) <0 )) +return -1 ; -if ((direction ==RTE_PCAPNG_DIRECTION_IN && - (md->ol_flags &RTE_MBUF_F_RX_QINQ_STRIPPED )) || - (direction ==RTE_PCAPNG_DIRECTION_OUT && - (md->ol_flags &RTE_MBUF_F_TX_QINQ ))) { -if (pcapng_vlan_insert (mc,RTE_ETHER_TYPE_QINQ , - md->vlan_tci_outer) !=0 ) - goto fail; - } +uint16_t optlen =pcapng_optlen (sizeof (flags)); -/* record HASH on incoming packets */ - rss_hash = (direction ==RTE_PCAPNG_DIRECTION_IN && - (md->ol_flags &RTE_MBUF_F_RX_RSS_HASH )); +/* make queue optional? */ + optlen +=pcapng_optlen (sizeof (queue)); -/* pad the packet to 32 bit boundary */ - pkt_len =rte_pktmbuf_pkt_len (mc); - padding =RTE_ALIGN (pkt_len,sizeof (uint32_t )) - pkt_len; -if (padding >0 ) { -void *tail =rte_pktmbuf_append (mc, padding); +/* does packet have valid RSS hash to include */ +bool rss_hash = (direction ==RTE_PCAPNG_DIRECTION_IN && + (m->ol_flags &RTE_MBUF_F_RX_RSS_HASH )); -if (tail ==NULL ) - goto fail; -memset (tail,0 , padding); - } - - optlen =pcapng_optlen (sizeof (flags)); - optlen +=pcapng_optlen (sizeof (queue));if (rss_hash) optlen +=pcapng_optlen (sizeof (uint8_t ) +sizeof (uint32_t ));@@ -540,10 +514,10 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue, optlen +=pcapng_optlen (strlen (comment));/* reserve trailing options and block length */ - opt = (struct pcapng_option *) -rte_pktmbuf_append (mc, optlen +sizeof (uint32_t )); +struct pcapng_option *opt = (struct pcapng_option *) +rte_pktmbuf_append (m, optlen +sizeof (uint32_t ));if (unlikely (opt ==NULL )) - goto fail; +return -1 ;switch (direction) {case RTE_PCAPNG_DIRECTION_IN :@@ -556,24 +530,20 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue, flags =0 ; } - opt =pcapng_add_option (opt,PCAPNG_EPB_FLAGS , - &flags,sizeof (flags)); - - opt =pcapng_add_option (opt,PCAPNG_EPB_QUEUE , - &queue,sizeof (queue)); + opt =pcapng_add_option (opt,PCAPNG_EPB_FLAGS , &flags,sizeof (flags)); + opt =pcapng_add_option (opt,PCAPNG_EPB_QUEUE , &queue,sizeof (queue));if (rss_hash) {uint8_t hash_opt[5 ]; -/* The algorithm could be something else if -* using rte_flow_action_rss; but the current API does not -* have a way for ethdev to report this on a per-packet basis.
lib/pcapng/rte_pcapng.c +1
-0+/* The algorithm could be something else but the current API does not
lib/pcapng/rte_pcapng.c +2
-0+* have a way for to record this on a per-packet basis +* and the PCAPNG hash types don't match the DPDK types. */ hash_opt[0] = PCAPNG_HASH_TOEPLITZ;lib/pcapng/rte_pcapng.c +2
-3-memcpy (&hash_opt[1 ], &md->hash.rss,sizeof (uint32_t )); - opt =pcapng_add_option (opt,PCAPNG_EPB_HASH , - &hash_opt,sizeof (hash_opt)); +memcpy (&hash_opt[1 ], &m->hash.rss,sizeof (uint32_t )); + opt = pcapng_add_option(opt, PCAPNG_EPB_HASH, &hash_opt,sizeof(hash_opt)); } if (comment)lib/pcapng/rte_pcapng.c +4
-9@@ -583,19 +553,14 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,/* Note: END_OPT necessary here. Wireshark doesn't do it. */ /* Add PCAPNG packet header */ - epb = (struct pcapng_enhance_packet_block *) -rte_pktmbuf_prepend (mc,sizeof (*epb)); + epb = (struct pcapng_enhance_packet_block *)rte_pktmbuf_prepend (m,sizeof (*epb));if (unlikely (epb ==NULL )) - goto fail; +return -1 ; epb->block_type =PCAPNG_ENHANCED_PACKET_BLOCK ; - epb->block_length =rte_pktmbuf_pkt_len (mc); - -/* Interface index is filled in later during write */ - mc->port = port_id; + epb->block_length =rte_pktmbuf_pkt_len (m); -/* Put timestamp in cycles here - adjust in packet write */ - timestamp =rte_get_tsc_cycles (); +/* Put timestamp in cycles here - adjusted in packet write */ epb->timestamp_hi = timestamp >>32 ; epb->timestamp_lo = (uint32_t )timestamp;epb->capture_length = pkt_len;lib/pcapng/rte_pcapng.c +48
-1@@ -603,9 +568,56 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,/* set trailer of block length */ *(uint32_t *)opt = epb->block_length; +return 0 ; +} + +/* Make a copy of original mbuf with pcapng header and options */ +RTE_EXPORT_SYMBOL (rte_pcapng_copy) +struct rte_mbuf * +rte_pcapng_copy (uint16_t port_id,uint32_t queue, +const struct rte_mbuf *md, +struct rte_mempool *mp, +uint32_t length, +enum rte_pcapng_direction direction, +const char *comment) +{ +uint32_t orig_len =rte_pktmbuf_pkt_len (md); +struct rte_mbuf *mc; -return mc; +#ifdef RTE_LIBRTE_ETHDEV_DEBUG +RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id,NULL ); +#endif + +/* Take snapshot of the data */ + mc =rte_pktmbuf_copy (md, mp,0 , length); +if (unlikely (mc ==NULL )) +return NULL ; + +/* Expand any offloaded VLAN information */ +if ((direction ==RTE_PCAPNG_DIRECTION_IN && + (md->ol_flags &RTE_MBUF_F_RX_VLAN_STRIPPED )) || + (direction ==RTE_PCAPNG_DIRECTION_OUT && + (md->ol_flags &RTE_MBUF_F_TX_VLAN ))) { +if (pcapng_vlan_insert (mc,RTE_ETHER_TYPE_VLAN , + md->vlan_tci) !=0 ) + goto fail; + } + +if ((direction ==RTE_PCAPNG_DIRECTION_IN && + (md->ol_flags &RTE_MBUF_F_RX_QINQ_STRIPPED )) || + (direction ==RTE_PCAPNG_DIRECTION_OUT && + (md->ol_flags &RTE_MBUF_F_TX_QINQ ))) { +if (pcapng_vlan_insert (mc,RTE_ETHER_TYPE_QINQ , + md->vlan_tci_outer) !=0 ) + goto fail; + } + +/* Interface index is filled in later during write */ + mc->port = port_id; +if (likely (rte_pcapng_insert (mc, queue, direction, orig_len, +rte_get_tsc_cycles (), comment) ==0 )) +return mc;fail:
rte_pktmbuf_free(mc); return NULL;lib/pcapng/rte_pcapng.h +25
-2@@ -99,7 +99,7 @@ enum rte_pcapng_direction { };/** -* Format an mbuf for writing to file. +* Make a copy of mbuf for writing to file. * * @param port_id * The Ethernet port on which packet was received @@ -117,7 +117,7 @@ enum rte_pcapng_direction {* @param direction * The direction of the packer: receive, transmit or unknown. * @param comment -* Packet comment. +* Packet comment (optional). * * @return * - The pointer to the new mbuf formatted for pcapng_write @@ -129,6 +129,29 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,uint32_t length, enum rte_pcapng_direction direction, const char *comment); +/** +* Format an mbuf for writing to file. +* +* @param m +* The mbuf to modify. +* @param queue +* The queue on the Ethernet port where packet was received +* or is going to be transmitted. +* @param direction +* The direction of the packer: receive, transmit or unknown. +* @param orig_len +* The length of the original packet which maybe less than actual +* packet if only a snapshot was captured. +* @param timestamp +* The timestamp for packet in TSC cycles. +* @param comment +* Packet comment (optional). +*/ +__rte_experimental +int +rte_pcapng_insert (struct rte_mbuf *m,uint32_t queue, +enum rte_pcapng_direction direction,uint32_t orig_len, +uint64_t timestamp,const char *comment);/** * Determine optimum mbuf data size. Signature · 1 line
2.47.2
Re: [PATCH v6 08/13] pcapng: split packet copy from header insertion
In reply to Ivan MalovQuoted 4 lines · On Wed, 23 Jul 2025 06:32:45 +0400 (+04) Ivan Malov…
Hi Stephen,
On Tue, 22 Jul 2025, Stephen Hemminger wrote:
Quoted 8 lines
Quoted 1 line
In new model, the packet was already copied, only need
Copied? But what if it was "indirect attached" instead, as the model envisages?
Perhaps this is a silly question of mine, but it may not be clear what happens in case of '
RTE_ETH_MIRROR_INDIRECT_FLAG' - whether it is safe to modify the mbuf and whether the 'indirect' clone has to be "freed" in the sense of being detached/refcnt updated after successful pcapng write, to avoid memory leaks?
The indirect attached is for the direct (no pcap case). Code should have checked for flag conflict.
I dropped the flag in next version, too may possible bugs and not useful for the case of packet capture. The problem is that indirect method assumes that transmit can handle reference counts (won't work with fast free), and on receive that upper layers do not overwrite packet with refcount > 1. The Linux and BSD kernel stack have these semantics, but DPDK does not make the requirement explicit. I.e too many risks for something that is experimental without current users.
PATCH v6 9/13 pcapng: make queue optional
In reply to Stephen HemmingerThe queue field is optional in pcapng received packet. Use UINT16_MAX as flag value.
--- lib/pcapng/rte_pcapng.c | 7 ++++--- lib/pcapng/rte_pcapng.h | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-)
lib/pcapng/rte_pcapng.c +4 -3
@@ -500,8 +500,8 @@ rte_pcapng_insert(struct rte_mbuf *m, uint32_t queue,uint16_t optlen =pcapng_optlen (sizeof (flags)); -/* make queue optional? */ - optlen +=pcapng_optlen (sizeof (queue)); +if (queue !=UINT16_MAX ) + optlen +=pcapng_optlen (sizeof (queue));/* does packet have valid RSS hash to include */ bool rss_hash = (direction == RTE_PCAPNG_DIRECTION_IN &&
@@ -531,7 +531,8 @@ rte_pcapng_insert(struct rte_mbuf *m, uint32_t queue, } opt =pcapng_add_option (opt,PCAPNG_EPB_FLAGS , &flags,sizeof (flags)); - opt =pcapng_add_option (opt,PCAPNG_EPB_QUEUE , &queue,sizeof (queue)); +if (queue !=UINT16_MAX ) + opt =pcapng_add_option (opt,PCAPNG_EPB_QUEUE , &queue,sizeof (queue));if (rss_hash) {uint8_t hash_opt[5 ];
lib/pcapng/rte_pcapng.h +2 -2
@@ -135,8 +135,8 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,* @param m * The mbuf to modify. * @param queue -* The queue on the Ethernet port where packet was received -* or is going to be transmitted. +* The queue on the Ethernet port where packet was received or is going to be transmitted. +* Optional: use UINT16_MAX if not specified. * @param direction * The direction of the packer: receive, transmit or unknown. * @param orig_len
Signature · 1 line
2.47.2
PATCH v6 10/13 test: add tests for ethdev mirror
In reply to Stephen HemmingerSimple API and packet mirroring standalone tests.
--- app/test/meson.build | 1 + app/test/test_ethdev_mirror.c | 286 ++++++++++++++++++++++++++++++++++ 2 files changed, 287 insertions(+) create mode 100644 app/test/test_ethdev_mirror.c
app/test/meson.build +1 -0
@@ -73,6 +73,7 @@ source_file_deps = { 'test_errno.c': [], 'test_ethdev_api.c': ['ethdev'], 'test_ethdev_link.c': ['ethdev'], + 'test_ethdev_mirror.c': ['net_ring', 'ethdev', 'bus_vdev'], 'test_event_crypto_adapter.c': ['cryptodev', 'eventdev', 'bus_vdev'], 'test_event_dma_adapter.c': ['dmadev', 'eventdev', 'bus_vdev'], 'test_event_eth_rx_adapter.c': ['ethdev', 'eventdev', 'bus_vdev'],
app/test/test_ethdev_mirror.c new file +286 -0
286 lines not on this page · raw message
Signature · 1 line
2.47.2
PATCH v6 11/13 app/testpmd: support for port mirroring
In reply to Stephen HemmingerAdd new commands to enable testing of port mirror functionality.
--- app/test-pmd/cmdline.c | 1 + app/test-pmd/cmdline_mirror.c | 129 ++++++++++++++++++++ app/test-pmd/cmdline_mirror.h | 12 ++ app/test-pmd/meson.build | 1 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 15 +++ 5 files changed, 158 insertions(+) create mode 100644 app/test-pmd/cmdline_mirror.c create mode 100644 app/test-pmd/cmdline_mirror.h
app/test-pmd/cmdline.c +1 -0
@@ -66,6 +66,7 @@#include "testpmd.h" #include "cmdline_cman.h" #include "cmdline_mtr.h" +#include "cmdline_mirror.h" #include "cmdline_tm.h" #include "bpf_cmd.h"
app/test-pmd/cmdline_mirror.c new file +129 -0
129 lines not on this page · raw message
app/test-pmd/cmdline_mirror.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Stephen Hemminger <[email protected]> +*/ + +#ifndef _CMDLINE_MIRROR_H_ +#define _CMDLINE_MIRROR_H_ + +/* Port MIRROR commands */ +extern cmdline_parse_inst_t cmd_create_port_mirror; +extern cmdline_parse_inst_t cmd_disable_port_mirror; + +#endif /* _CMDLINE_MIRROR_H_ */
app/test-pmd/meson.build +1 -0
@@ -8,6 +8,7 @@ sources = files( 'cmdline.c', 'cmdline_cman.c', 'cmdline_flow.c', + 'cmdline_mirror.c', 'cmdline_mtr.c', 'cmdline_tm.c', 'cmd_flex_item.c',
doc/guides/testpmd_app_ug/testpmd_funcs.rst +15 -0
@@ -2570,6 +2570,21 @@ where: * ``clear``: Flag that indicates whether the statistics counters should be cleared (i.e. set to zero) immediately after they have been read or not. +create mirror +------------- + +Create a new MIRROR port for an ethernet device:: + + testpmd> create port mirror (port_id) destination (port_id) + +delete mirror +------------- + +Delete an existing MIRROR port on ethernet device:: + + testpmd> delete port mirror (port_id) + + Traffic Management ------------------
Signature · 1 line
2.47.2
PATCH v6 12/13 app/dumpcap: use port mirror instead of pdump
In reply to Stephen HemmingerUse the new port mirror API instead of pdump.
Since filtering is now done in dumpcap process (not primary). For portability use PCAP to do packet filtering. This removes dependency on DPDK implementation of BPF. Filtering will be slower (no JIT) but is portable to Windows. Can revisit later when BPF support is updated.
--- app/dumpcap/main.c | 468 ++++++++++++++++++++++++++++++++-------- app/dumpcap/meson.build | 8 +- 2 files changed, 378 insertions(+), 98 deletions(-)
app/dumpcap/main.c +377 -91
@@ -25,7 +25,6 @@#include <rte_alarm.h> #include <rte_bitops.h> -#include <rte_bpf.h> #include <rte_config.h> #include <rte_debug.h> #include <rte_eal.h>
@@ -36,8 +35,6 @@#include <rte_mbuf.h> #include <rte_mempool.h> #include <rte_pcapng.h> -#include <rte_pdump.h> -#include <rte_ring.h> #include <rte_string_fns.h> #include <rte_thread.h> #include <rte_time.h>
@@ -93,15 +90,26 @@ struct interface {TAILQ_ENTRY (interface) next;uint16_t port;struct capture_options opts; -struct rte_bpf_prm *bpf_prm;char name[RTE_ETH_NAME_MAX_LEN ]; +struct bpf_insn *bpf; +struct rte_eth_stats start_stats;const char *ifname;const char *ifdescr; }; +static int timestamp_dynfield =-1 ; +static uint64_t timestamp_dynflag; +static int mirror_origin_dynfield =-1 ; +static uint64_t mirror_origin_dynflag; +static uint64_t mirror_ingress_dynflag; +static uint64_t mirror_egress_dynflag; + +static bool filtering; +TAILQ_HEAD (interface_list, interface);static struct interface_list interfaces =TAILQ_HEAD_INITIALIZER (interfaces); +static struct interface *port2intf[RTE_MAX_ETHPORTS ];/* Can do either pcap or pcapng format output */ typedef union {
@@ -239,14 +247,16 @@ static void find_interfaces(void) TAILQ_FOREACH(intf, &interfaces, next) {/* if name is valid then just record port */ -if (rte_eth_dev_get_port_by_name (intf->name, &intf->port) ==0 ) -continue ; +if (rte_eth_dev_get_port_by_name (intf->name, &intf->port) !=0 ) { +/* maybe got passed port number string as name */ + intf->port =get_uint (intf->name,"port_number" ,UINT16_MAX ); +if (rte_eth_dev_get_name_by_port (intf->port, intf->name) <0 ) +rte_exit (EXIT_FAILURE ,"Invalid port number %u\n" , + intf->port); + } -/* maybe got passed port number string as name */ - intf->port =get_uint (intf->name,"port_number" ,UINT16_MAX ); -if (rte_eth_dev_get_name_by_port (intf->port, intf->name) <0 ) -rte_exit (EXIT_FAILURE ,"Invalid port number %u\n" , - intf->port); +if (rte_eth_stats_get (intf->port, &intf->start_stats) <0 ) +rte_exit (EXIT_FAILURE ,"Could not read stats for port %u\n" , intf->port); } }
@@ -266,6 +276,10 @@ static void set_default_interface(void) intf =add_interface (name); intf->port = p; + +if (rte_eth_stats_get (intf->port, &intf->start_stats) <0 ) +rte_exit (EXIT_FAILURE , +"Could not read stats for port %u\n" , intf->port);return ; }rte_exit (EXIT_FAILURE ,"No usable interfaces found\n" );
@@ -291,44 +305,40 @@ static void compile_filters(void)struct interface *intf; TAILQ_FOREACH(intf, &interfaces, next) { -struct rte_bpf_prm *bpf_prm;struct bpf_program bf;pcap_t *pcap; +/* cache for filter packets */ + port2intf[intf->port] = intf; + +if (intf->opts.filter ==NULL ) { + intf->bpf =NULL ; +continue ; + } + pcap =pcap_open_dead (DLT_EN10MB , intf->opts.snap_len);if (!pcap)rte_exit (EXIT_FAILURE ,"can not open pcap\n" ); -if (pcap_compile (pcap, &bf, intf->opts.filter, -1 ,PCAP_NETMASK_UNKNOWN ) !=0 ) { +if (pcap_compile (pcap, &bf, intf->opts.filter,1 ,PCAP_NETMASK_UNKNOWN ) !=0 ) {fprintf (stderr,"Invalid capture filter \"%s\": for interface '%s'\n" , intf->opts.filter, intf->name); -rte_exit (EXIT_FAILURE ,"\n%s\n" , -pcap_geterr (pcap)); +rte_exit (EXIT_FAILURE ,"\n%s\n" ,pcap_geterr (pcap)); } - bpf_prm =rte_bpf_convert (&bf); -if (bpf_prm ==NULL ) -rte_exit (EXIT_FAILURE , -"BPF convert interface '%s'\n%s(%d)\n" , - intf->name, -rte_strerror (rte_errno), rte_errno); -if (dump_bpf) {printf ("cBPF program (%u insns)\n" , bf.bf_len);bpf_dump (&bf,1 ); -printf ("\neBPF program (%u insns)\n" , - bpf_prm->nb_ins); -rte_bpf_dump (stdout, bpf_prm->ins, bpf_prm->nb_ins);exit (0 ); } - intf->bpf_prm = bpf_prm; + intf->bpf =malloc (bf.bf_len *sizeof (struct bpf_insn )); +if (!intf->bpf) +rte_exit (EXIT_FAILURE ,"can not allocate memory for bpf\n" ); -/* Don't care about original program any more */ -pcap_freecode (&bf); -pcap_close (pcap); +memcpy (intf->bpf, bf.bf_insns, bf.bf_len *sizeof (struct bpf_insn )); + filtering = true; } }
@@ -518,13 +528,12 @@ static void statistics_loop(void) }static void -cleanup_pdump_resources (void ) +disable_mirror_ports (uint16_t mirror_port) {struct interface *intf; TAILQ_FOREACH(intf, &interfaces, next) { -rte_pdump_disable (intf->port, -RTE_PDUMP_ALL_QUEUES ,RTE_PDUMP_FLAG_RXTX ); +rte_eth_remove_mirror (intf->port, mirror_port);if (intf->opts.promisc_mode)rte_eth_promiscuous_disable (intf->port); }
@@ -541,7 +550,7 @@ monitor_primary(void *arg __rte_unused)rte_eal_alarm_set (MONITOR_INTERVAL , monitor_primary,NULL ); }else {fprintf (stderr, -"Primary process is no longer active, exiting...\n" ); +"\nPrimary process is no longer active, exiting...\n" );rte_atomic_store_explicit (&quit_signal, true, rte_memory_order_relaxed); } }
@@ -552,7 +561,6 @@ enable_primary_monitor(void) {int ret; -/* Once primary exits, so will pdump. */ ret =rte_eal_alarm_set (MONITOR_INTERVAL , monitor_primary,NULL );if (ret <0 )fprintf (stderr,"Fail to enable monitor:%d\n" , ret);
@@ -571,23 +579,24 @@ disable_primary_monitor(void)static void report_packet_stats (dumpcap_out_t out) { -struct rte_pdump_stats pdump_stats;struct interface *intf; -uint64_t ifrecv, ifdrop; -double percent;fputc ('\n' , stderr); + TAILQ_FOREACH(intf, &interfaces, next) { -if (rte_pdump_stats (intf->port, &pdump_stats) <0 ) +uint64_t ifrecv, ifdrop; +struct rte_eth_stats stats; +double percent; + +if (rte_eth_stats_get (intf->port, &stats) <0 )continue ; -/* do what Wiretap does */ - ifrecv = pdump_stats.accepted + pdump_stats.filtered; - ifdrop = pdump_stats.nombuf + pdump_stats.ringfull; + ifrecv = stats.ipackets - intf->start_stats.ipackets; + ifdrop = (stats.rx_nombuf - intf->start_stats.rx_nombuf) + + (stats.imissed - intf->start_stats.imissed);if (use_pcapng) -rte_pcapng_write_stats (out.pcapng, intf->port, - ifrecv, ifdrop,NULL ); +rte_pcapng_write_stats (out.pcapng, intf->port, ifrecv, ifdrop,NULL );if (ifrecv ==0 ) percent =0 ;
@@ -668,12 +677,21 @@ static void dpdk_init(void)rte_exit (EXIT_FAILURE ,"Can not restore original CPU affinity\n" ); } -/* Create packet ring shared between callbacks and process */ -static struct rte_ring *create_ring (void ) +/* Create ring port to redirect packet to. +* This could be much simpler if the ring PMD API (rte_eth_from_rings) +* worked from a secondary process, but it doesn't. +*/ +static struct rte_ring * +create_ring_dev (char *vdev_name,uint16_t *mirror_port) { -struct rte_ring *ring; +struct rte_eth_dev_owner owner = {0 }; +struct rte_eth_conf dev_conf = {0 }; +struct rte_ring *ring =NULL ;char ring_name[RTE_RING_NAMESIZE ]; +char vdev_args[128 ];size_t size, log2; +uint16_t port; +int ret;/* Find next power of 2 >= size. */ size = ring_size;
@@ -686,17 +704,59 @@ static struct rte_ring *create_ring(void) ring_size = size; } -/* Want one ring per invocation of program */ -snprintf (ring_name,sizeof (ring_name), -"dumpcap-%d" ,getpid ()); +/* Use owner as unique Id for ring and to isolate */ + ret =rte_eth_dev_owner_new (&owner.id); +if (ret <0 ) +rte_exit (EXIT_FAILURE ,"rte_eth_dev_owner_new failed: %s\n" , +strerror (-ret)); - ring =rte_ring_create (ring_name, ring_size, -rte_socket_id (),0 ); +/* Give the vdev a unique name */ +snprintf (ring_name,sizeof (ring_name),"dumpcap%" PRIu64, owner.id); + ring =rte_ring_create (ring_name, ring_size,rte_socket_id (), +RING_F_MP_RTS_ENQ |RING_F_SC_DEQ );if (ring ==NULL )rte_exit (EXIT_FAILURE ,"Could not create ring :%s\n" ,rte_strerror (rte_errno)); +strlcpy (owner.name, ring_name,sizeof (owner.name)); + +snprintf (vdev_name,RTE_DEV_NAME_MAX_LEN ,"net_ring-dumpcap%" PRIu64, owner.id); +snprintf (vdev_args,sizeof (vdev_args),"ring=%s" , ring_name); + +if (rte_eal_hotplug_add ("vdev" , vdev_name, vdev_args) <0 ) +rte_exit (EXIT_FAILURE , +"rte_eal_hotplug_add of %s failed:%s\n" , + vdev_name,rte_strerror (rte_errno)); + + ret =rte_eth_dev_get_port_by_name (vdev_name, &port); +if (ret !=0 ) { +fprintf (stderr,"Could not port for %s: %s\n" , + vdev_name,strerror (-ret)); + goto unplug; + } + + ret =rte_eth_dev_owner_set (port, &owner); +if (ret !=0 ) { +fprintf (stderr,"Could not set owner for port for %u: %s\n" , + port,strerror (-ret)); + goto unplug; + } + + ret =rte_eth_dev_configure (port,1 ,1 , &dev_conf); +if (ret <0 ) { +fprintf (stderr,"Could not configure port %u: %s\n" , + port,strerror (-ret)); + goto unplug; + } + + *mirror_port = port;return ring; + +unplug: +rte_eal_hotplug_remove ("vdev" , vdev_name); +rte_ring_free (ring); +rte_eal_cleanup (); +exit (EXIT_FAILURE ); }static struct rte_mempool *create_mempool (void )
@@ -796,7 +856,7 @@ static dumpcap_out_t create_output(void) version(), capture_comment);if (ret.pcapng ==NULL )rte_exit (EXIT_FAILURE ,"pcapng_fdopen failed: %s\n" , -strerror (rte_errno)); +rte_strerror (rte_errno));free (os); TAILQ_FOREACH(intf, &interfaces, next) {
@@ -823,37 +883,32 @@ static dumpcap_out_t create_output(void)return ret; } -static void enable_pdump (struct rte_ring *r,struct rte_mempool *mp) +static int enable_mirror (uint16_t mirror_port,struct rte_mempool *mpool) {struct interface *intf;unsigned int count =0 ; -uint32_t flags;int ret; - flags =RTE_PDUMP_FLAG_RXTX ; -if (use_pcapng) - flags |=RTE_PDUMP_FLAG_PCAPNG ; + ret =rte_eth_dev_start (mirror_port); +if (ret <0 ) +rte_exit (EXIT_FAILURE ,"Could not start mirror port %u: %s\n" , + mirror_port,strerror (-ret)); TAILQ_FOREACH(intf, &interfaces, next) { - ret =rte_pdump_enable_bpf (intf->port,RTE_PDUMP_ALL_QUEUES , - flags, intf->opts.snap_len, - r, mp, intf->bpf_prm); +struct rte_eth_mirror_conf conf = { + .mp = mpool, + .target = mirror_port, + .snaplen = intf->opts.snap_len, + .flags =RTE_ETH_MIRROR_ORIGIN_FLAG |RTE_ETH_MIRROR_TIMESTAMP_FLAG , + .direction =RTE_ETH_MIRROR_DIRECTION_INGRESS | +RTE_ETH_MIRROR_DIRECTION_EGRESS , + }; + + ret =rte_eth_add_mirror (intf->port, &conf);if (ret <0 ) { -const struct interface *intf2; - -/* unwind any previous enables */ - TAILQ_FOREACH(intf2, &interfaces, next) { -if (intf == intf2) -break ; -rte_pdump_disable (intf2->port, -RTE_PDUMP_ALL_QUEUES ,RTE_PDUMP_FLAG_RXTX ); -if (intf2->opts.promisc_mode) -rte_eth_promiscuous_disable (intf2->port); - } -rte_exit (EXIT_FAILURE , -"Packet dump enable on %u:%s failed %s\n" , - intf->port, intf->name, -rte_strerror (rte_errno)); +fprintf (stderr,"Port mirror on %u:%s failed %s\n" , + intf->port, intf->name,strerror (-ret)); +return -1 ; }if (intf->opts.promisc_mode) {
@@ -868,6 +923,60 @@ static void enable_pdump(struct rte_ring *r, struct rte_mempool *mp) } ++count; } +return count; +} + +static int setup_mbuf (void ) +{ +int offset; + + offset =rte_mbuf_dynfield_lookup (RTE_MBUF_DYNFIELD_TIMESTAMP_NAME ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find timestamp dynamic field\n" ); +return -1 ; + } + timestamp_dynfield = offset; + + offset =rte_mbuf_dynflag_lookup (RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find timestamp flag\n" ); +return -1 ; + } + timestamp_dynflag =RTE_BIT64 (offset); + + offset =rte_mbuf_dynfield_lookup (RTE_MBUF_DYNFIELD_MIRROR_ORIGIN ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find mirror origin dynamic field\n" ); +return -1 ; + } + mirror_origin_dynfield = offset; + + offset =rte_mbuf_dynflag_lookup (RTE_MBUF_DYNFLAG_MIRROR_ORIGIN ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find mirror origin dynamic flag\n" ); +return -1 ; + } + mirror_origin_dynflag =RTE_BIT64 (offset); + + offset =rte_mbuf_dynflag_lookup (RTE_MBUF_DYNFLAG_MIRROR_INGRESS ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find mirror ingress flag\n" ); +return -1 ; + } + mirror_ingress_dynflag =RTE_BIT64 (offset); + + offset =rte_mbuf_dynflag_lookup (RTE_MBUF_DYNFLAG_MIRROR_EGRESS ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find mirror egress flag\n" ); +return -1 ; + } + mirror_egress_dynflag =RTE_BIT64 (offset); +return 0 ; +} + +static void show_capturing (unsigned int count) +{ +struct interface *intf;fputs ("Capturing on " , stdout); TAILQ_FOREACH(intf, &interfaces, next) {
@@ -898,6 +1007,47 @@ static void show_count(uint64_t count) bt =fprintf (stderr,"%" PRIu64" " , count); } +static ssize_t +pcapng_write_packets (rte_pcapng_t *pcapng,struct rte_mbuf *pkts[],uint16_t n) +{ +struct rte_mbuf *towrite[BURST_SIZE ]; +unsigned int count =0 ; + +for (unsigned int i =0 ; i < n; i++) { +struct rte_mbuf *m = pkts[i]; +enum rte_pcapng_direction direction =RTE_PCAPNG_DIRECTION_UNKNOWN ; + +/* If no origin flag then why did we get this? */ +if (unlikely (!(m->ol_flags & mirror_origin_dynflag))) { +fprintf (stderr,"Missing origin info in packet\n" ); +return -1 ; + } + +const struct rte_mbuf_origin *origin + = RTE_MBUF_DYNFIELD(m, mirror_origin_dynfield, rte_mbuf_origin_t *); + +if (m->ol_flags & mirror_ingress_dynflag) + direction =RTE_PCAPNG_DIRECTION_IN ; +else if (m->ol_flags & mirror_egress_dynflag) + direction =RTE_PCAPNG_DIRECTION_OUT ; + +uint64_t timestamp; +if (m->ol_flags & timestamp_dynflag) + timestamp = *RTE_MBUF_DYNFIELD (m, timestamp_dynfield, + rte_mbuf_timestamp_t *); +else + timestamp =rte_get_tsc_cycles (); + +if (rte_pcapng_insert (m, origin->queue_id, direction, origin->original_len, + timestamp,NULL ) <0 ) +continue ;/* skip no headroom? */ + + towrite[count++] = m; + } + +return rte_pcapng_write_packets (pcapng, towrite, count); +} +/* Write multiple packets in older pcap format */ static ssize_t pcap_write_packets(pcap_dumper_t *dumper,
@@ -930,16 +1080,129 @@ pcap_write_packets(pcap_dumper_t *dumper,return total; } +/* Do packet filter on incoming packets. +* Some issues to note here: +* - would be better to do before putting into ring +* but that causes ethdev to have dependency on BPF. +* - the filter is per-interface and there maybe more than one interface +* combined into the ring. That means filter is executed once +* per packet (not as burst). +*/ +static unsigned int +filter_packets (struct rte_mbuf *pkts[],unsigned int n) +{ +unsigned int matches =0 ; +unsigned int results[BURST_SIZE ] = {0 }; + +for (unsigned int i =0 ; i < n; i++) { +struct rte_mbuf *m = pkts[i]; + +/* all packets should have origin info, if not just skip */ +if (unlikely (!(m->ol_flags & mirror_origin_dynflag))) +continue ; + +const struct rte_mbuf_origin *origin + = RTE_MBUF_DYNFIELD(m, mirror_origin_dynfield, rte_mbuf_origin_t *); +uint16_t port_id = origin->port_id; + +if (unlikely (port_id >=RTE_MAX_ETHPORTS )) +continue ; + +const struct interface *intf = port2intf[port_id]; +if (intf ==NULL || intf->bpf ==NULL ) +continue ; + + results[i] = bpf_filter(intf->bpf, rte_pktmbuf_mtod(m, u_char *), + origin->original_len, m->data_len); +if (results[i] !=0 ) + ++matches; + } + +if (matches == n) +return n;/* no packets skipped */ + +/* need to shuffle out the skipped packets */ +unsigned int count =0 ; +struct rte_mbuf *towrite[BURST_SIZE ]; +for (unsigned int i =0 ; i < n; i++) { +if (results[i]) + towrite[count++] = pkts[i]; +else +rte_pktmbuf_free (pkts[i]); + } +memcpy (pkts, towrite, count *sizeof (struct rte_mbuf *)); +return count; +} + +/* Make sure configuration of mbuf pool has enough headroom for both vlans */ +static_assert (RTE_PKTMBUF_HEADROOM >2 *sizeof (struct rte_vlan_hdr ), +"not enough mbuf headroom for vlan insertion" ); + +/* +* More general version of rte_vlan_insert() +* Note: mbufs are allocated by rte_eth_mirror_burst() from the +* pool that was passed when setting up mirror. +*/ +static void +vlan_insert (struct rte_mbuf *m,uint16_t ether_type,uint16_t tci) +{ +struct rte_ether_hdr *nh, tmph; +const struct rte_ether_hdr *oh; +struct rte_vlan_hdr *vh; + +RTE_ASSERT (!RTE_MBUF_DIRECT (m)); +RTE_ASSERT (rte_mbuf_refcnt_read (m) ==1 ); + + oh =rte_pktmbuf_read (m,0 ,sizeof (*oh), &tmph); +RTE_ASSERT (oh !=NULL ); + +/* overlay new header */ + nh = (struct rte_ether_hdr *) +rte_pktmbuf_prepend (m,sizeof (struct rte_vlan_hdr )); + +RTE_ASSERT (nh !=NULL ); + +memmove (nh, oh,2 *RTE_ETHER_ADDR_LEN ); + nh->ether_type =rte_cpu_to_be_16 (ether_type); + + vh = (struct rte_vlan_hdr *) (nh +1 ); + vh->vlan_tci =rte_cpu_to_be_16 (tci); +} + +/* Filtering and pcap file format require that VLAN not be offloaded */ +static void +remove_vlan_offload (struct rte_mbuf *pkts[],unsigned int n) +{ +unsigned int i; + +for (i =0 ; i < n; i++) { +struct rte_mbuf *m = pkts[i]; + +if (m->ol_flags & mirror_ingress_dynflag) { +if (m->ol_flags &RTE_MBUF_F_RX_VLAN_STRIPPED ) +vlan_insert (m,RTE_ETHER_TYPE_VLAN , m->vlan_tci); +if (m->ol_flags &RTE_MBUF_F_RX_QINQ_STRIPPED ) +vlan_insert (m,RTE_ETHER_TYPE_QINQ , m->vlan_tci_outer); + } +if (m->ol_flags & mirror_egress_dynflag) { +if (m->ol_flags &RTE_MBUF_F_TX_VLAN ) +vlan_insert (m,RTE_ETHER_TYPE_VLAN , m->vlan_tci); +if (m->ol_flags &RTE_MBUF_F_TX_QINQ ) +vlan_insert (m,RTE_ETHER_TYPE_QINQ , m->vlan_tci_outer); + + } + } +} +/* Process all packets in ring and dump to capture file */ -static int process_ring (dumpcap_out_t out,struct rte_ring *r) +static int process_ring (dumpcap_out_t out,struct rte_ring *ring) {struct rte_mbuf *pkts[BURST_SIZE ]; -unsigned int avail, n; +unsigned int n, avail;static unsigned int empty_count;ssize_t written; - n =rte_ring_sc_dequeue_burst (r, (void **) pkts,BURST_SIZE , - &avail); + n =rte_ring_sc_dequeue_burst (ring, (void **)pkts,BURST_SIZE , &avail);if (n ==0 ) {/* don't consume endless amounts of cpu if idle */ if (empty_count <SLEEP_THRESHOLD )
@@ -948,11 +1211,18 @@ static int process_ring(dumpcap_out_t out, struct rte_ring *r)usleep (10 );return 0 ; } - empty_count = (avail ==0 ); +remove_vlan_offload (pkts, n); + +if (filtering) { + n =filter_packets (pkts, n); +if (n ==0 ) +return 0 ; + } +if (use_pcapng) - written =rte_pcapng_write_packets (out.pcapng, pkts, n); + written =pcapng_write_packets (out.pcapng, pkts, n);else written =pcap_write_packets (out.dumper, pkts, n);
@@ -971,15 +1241,18 @@ static int process_ring(dumpcap_out_t out, struct rte_ring *r)int main (int argc,char **argv) { -struct rte_ring *r;struct rte_mempool *mp;struct sigaction action = { .sa_flags =SA_RESTART , .sa_handler = signal_handler, };struct sigaction origaction; +struct rte_ring *ring =NULL ; +char vdev_name[RTE_DEV_NAME_MAX_LEN ]; +uint16_t mirror_port =UINT16_MAX ;dumpcap_out_t out;char *p; +int ret; p =strrchr (argv[0 ],'/' );if (p ==NULL )
@@ -1018,12 +1291,21 @@ int main(int argc, char **argv)exit (0 ); } - r =create_ring (); mp =create_mempool (); + ring =create_ring_dev (vdev_name, &mirror_port); out =create_output (); + ret =enable_mirror (mirror_port, mp); +if (ret <0 ) + goto cleanup; + + ret =setup_mbuf (); +if (ret <0 ) + goto cleanup; + +show_capturing (ret); + start_time =time (NULL ); -enable_pdump (r, mp);if (!quiet) {fprintf (stderr,"Packets captured: " );
@@ -1031,7 +1313,7 @@ int main(int argc, char **argv) }while (!rte_atomic_load_explicit (&quit_signal, rte_memory_order_relaxed)) { -if (process_ring (out, r) <0 ) { +if (process_ring (out, ring) <0 ) {fprintf (stderr,"pcapng file write failed; %s\n" ,strerror (errno));break ;
@@ -1048,20 +1330,24 @@ int main(int argc, char **argv)break ; } -disable_primary_monitor (); -if (rte_eal_primary_proc_alive (NULL ))report_packet_stats (out); +cleanup: +disable_primary_monitor (); +if (use_pcapng)rte_pcapng_close (out.pcapng);else pcap_dump_close (out.dumper); -cleanup_pdump_resources (); +if (rte_eal_primary_proc_alive (NULL )) { +disable_mirror_ports (mirror_port); -rte_ring_free (r); -rte_mempool_free (mp); +rte_eal_hotplug_remove ("vdev" , vdev_name); +rte_ring_free (ring); +rte_mempool_free (mp); + }return rte_eal_cleanup () ?EXIT_FAILURE :0 ; }
app/dumpcap/meson.build +1 -7
@@ -6,12 +6,6 @@ if not dpdk_conf.has('RTE_HAS_LIBPCAP') reason = 'missing dependency, "libpcap"' endif -if is_windows - build = false - reason = 'not supported on Windows' - subdir_done() -endif - ext_deps += pcap_dep sources = files('main.c') -deps += ['ethdev', 'pdump', 'pcapng', 'bpf'] +deps += ['net_ring', 'ethdev', 'pcapng' ]
Signature · 1 line
2.47.2
Re: [PATCH v6 12/13] app/dumpcap: use port mirror instead of pdump
Hi Stephen,
(please see below)
Quoted 226 lines · Stephen Hemminger
Use the new port mirror API instead of pdump.
Since filtering is now done in dumpcap process (not primary). For portability use PCAP to do packet filtering. This removes dependency on DPDK implementation of BPF. Filtering will be slower (no JIT) but is portable to Windows. Can revisit later when BPF support is updated.
Signed-off-by Stephen Hemminger <[email protected]>---
app/dumpcap/main.c| 468 ++++++++++++++++++++++++++++++++--------
app/dumpcap/meson.build | 8 +-2 files changed, 378 insertions(+), 98 deletions(-)app/dumpcap/main.c +40
-30@@ -25,7 +25,6 @@#include <rte_alarm.h> #include <rte_bitops.h> -#include <rte_bpf.h> #include <rte_config.h> #include <rte_debug.h> #include <rte_eal.h> @@ -36,8 +35,6 @@#include <rte_mbuf.h> #include <rte_mempool.h> #include <rte_pcapng.h> -#include <rte_pdump.h> -#include <rte_ring.h> #include <rte_string_fns.h> #include <rte_thread.h> #include <rte_time.h> @@ -93,15 +90,26 @@ struct interface {TAILQ_ENTRY (interface) next;uint16_t port;struct capture_options opts; -struct rte_bpf_prm *bpf_prm;char name[RTE_ETH_NAME_MAX_LEN ]; +struct bpf_insn *bpf; +struct rte_eth_stats start_stats;const char *ifname;const char *ifdescr; }; +static int timestamp_dynfield =-1 ; +static uint64_t timestamp_dynflag; +static int mirror_origin_dynfield =-1 ; +static uint64_t mirror_origin_dynflag; +static uint64_t mirror_ingress_dynflag; +static uint64_t mirror_egress_dynflag; + +static bool filtering; +TAILQ_HEAD (interface_list, interface);static struct interface_list interfaces =TAILQ_HEAD_INITIALIZER (interfaces); +static struct interface *port2intf[RTE_MAX_ETHPORTS ];/* Can do either pcap or pcapng format output */ typedef union {@@ -239,14 +247,16 @@ static void find_interfaces(void) TAILQ_FOREACH(intf, &interfaces, next) {/* if name is valid then just record port */ -if (rte_eth_dev_get_port_by_name (intf->name, &intf->port) ==0 ) -continue ; +if (rte_eth_dev_get_port_by_name (intf->name, &intf->port) !=0 ) { +/* maybe got passed port number string as name */ + intf->port =get_uint (intf->name,"port_number" ,UINT16_MAX ); +if (rte_eth_dev_get_name_by_port (intf->port, intf->name) <0 ) +rte_exit (EXIT_FAILURE ,"Invalid port number %u\n" , + intf->port); + } -/* maybe got passed port number string as name */ - intf->port =get_uint (intf->name,"port_number" ,UINT16_MAX ); -if (rte_eth_dev_get_name_by_port (intf->port, intf->name) <0 ) -rte_exit (EXIT_FAILURE ,"Invalid port number %u\n" , - intf->port); +if (rte_eth_stats_get (intf->port, &intf->start_stats) <0 ) +rte_exit (EXIT_FAILURE ,"Could not read stats for port %u\n" , intf->port); } }@@ -266,6 +276,10 @@ static void set_default_interface(void) intf =add_interface (name); intf->port = p; + +if (rte_eth_stats_get (intf->port, &intf->start_stats) <0 ) +rte_exit (EXIT_FAILURE , +"Could not read stats for port %u\n" , intf->port);return ; }rte_exit (EXIT_FAILURE ,"No usable interfaces found\n" );@@ -291,44 +305,40 @@ static void compile_filters(void)struct interface *intf; TAILQ_FOREACH(intf, &interfaces, next) { -struct rte_bpf_prm *bpf_prm;struct bpf_program bf;pcap_t *pcap; +/* cache for filter packets */ + port2intf[intf->port] = intf; + +if (intf->opts.filter ==NULL ) { + intf->bpf =NULL ; +continue ; + } + pcap =pcap_open_dead (DLT_EN10MB , intf->opts.snap_len);if (!pcap)rte_exit (EXIT_FAILURE ,"can not open pcap\n" ); -if (pcap_compile (pcap, &bf, intf->opts.filter, -1 ,PCAP_NETMASK_UNKNOWN ) !=0 ) { +if (pcap_compile (pcap, &bf, intf->opts.filter,1 ,PCAP_NETMASK_UNKNOWN ) !=0 ) {fprintf (stderr,"Invalid capture filter \"%s\": for interface '%s'\n" , intf->opts.filter, intf->name); -rte_exit (EXIT_FAILURE ,"\n%s\n" , -pcap_geterr (pcap)); +rte_exit (EXIT_FAILURE ,"\n%s\n" ,pcap_geterr (pcap)); } - bpf_prm =rte_bpf_convert (&bf); -if (bpf_prm ==NULL ) -rte_exit (EXIT_FAILURE , -"BPF convert interface '%s'\n%s(%d)\n" , - intf->name, -rte_strerror (rte_errno), rte_errno); -if (dump_bpf) {printf ("cBPF program (%u insns)\n" , bf.bf_len);bpf_dump (&bf,1 ); -printf ("\neBPF program (%u insns)\n" , - bpf_prm->nb_ins); -rte_bpf_dump (stdout, bpf_prm->ins, bpf_prm->nb_ins);exit (0 ); } - intf->bpf_prm = bpf_prm; + intf->bpf =malloc (bf.bf_len *sizeof (struct bpf_insn )); +if (!intf->bpf) +rte_exit (EXIT_FAILURE ,"can not allocate memory for bpf\n" ); -/* Don't care about original program any more */ -pcap_freecode (&bf); -pcap_close (pcap); +memcpy (intf->bpf, bf.bf_insns, bf.bf_len *sizeof (struct bpf_insn )); + filtering = true; } }@@ -518,13 +528,12 @@ static void statistics_loop(void) }static void
app/dumpcap/main.c +1
-1-cleanup_pdump_resources (void) +disable_mirror_ports(uint16_t mirror_port){ struct interface *intf; TAILQ_FOREACH(intf, &interfaces, next) {app/dumpcap/main.c +1
-2-rte_pdump_disable (intf->port, -RTE_PDUMP_ALL_QUEUES ,RTE_PDUMP_FLAG_RXTX ); +rte_eth_remove_mirror (intf->port, mirror_port);if (intf->opts.promisc_mode) rte_eth_promiscuous_disable(intf->port); }app/dumpcap/main.c +1
-2@@ -541,7 +550,7 @@ monitor_primary(void *arg __rte_unused)rte_eal_alarm_set (MONITOR_INTERVAL , monitor_primary,NULL ); }else {fprintf (stderr, -"Primary process is no longer active, exiting...\n" ); +"\nPrimary process is no longer active, exiting...\n" );rte_atomic_store_explicit (&quit_signal, true, rte_memory_order_relaxed); } }@@ -552,7 +561,6 @@ enable_primary_monitor(void) {int ret; -/* Once primary exits, so will pdump. */ ret =rte_eal_alarm_set (MONITOR_INTERVAL , monitor_primary,NULL );if (ret <0 )fprintf (stderr,"Fail to enable monitor:%d\n" , ret);@@ -571,23 +579,24 @@ disable_primary_monitor(void)static void
report_packet_stats(dumpcap_out_t out)
{app/dumpcap/main.c +0
-1-struct rte_pdump_stats pdump_stats;struct interface *intf;app/dumpcap/main.c +0
-2-uint64_t ifrecv, ifdrop; -double percent;fputc('\n', stderr); + TAILQ_FOREACH(intf, &interfaces, next) {app/dumpcap/main.c +5
-1-if (rte_pdump_stats (intf->port, &pdump_stats) <0 ) +uint64_t ifrecv, ifdrop; +struct rte_eth_stats stats; +double percent; + +if (rte_eth_stats_get (intf->port, &stats) <0 )continue;app/dumpcap/main.c +3
-3-/* do what Wiretap does */ - ifrecv = pdump_stats.accepted + pdump_stats.filtered; - ifdrop = pdump_stats.nombuf + pdump_stats.ringfull; + ifrecv = stats.ipackets - intf->start_stats.ipackets; + ifdrop = (stats.rx_nombuf - intf->start_stats.rx_nombuf) + + (stats.imissed - intf->start_stats.imissed);if (
use_pcapng)app/dumpcap/main.c +1
-2-rte_pcapng_write_stats (out.pcapng, intf->port, - ifrecv, ifdrop,NULL ); +rte_pcapng_write_stats (out.pcapng, intf->port, ifrecv, ifdrop,NULL );if (ifrecv == 0) percent = 0;
app/dumpcap/main.c static void dpdk_init(void) · line 680
Quoted 6 lines
app/dumpcap/main.c +1
-2@@ -668,12 +677,21 @@ static void dpdk_init(void)rte_exit (EXIT_FAILURE ,"Can not restore original CPU affinity\n" ); } -/* Create packet ring shared between callbacks and process */ -static struct rte_ring *create_ring (void ) +/* Create ring port to redirect packet to.
Perhaps adhere to
/*
* comment
*/
style (I do not insist - this is up to you).
Quoted 19 lines
app/dumpcap/main.c +11
-1+* This could be much simpler if the ring PMD API (rte_eth_from_rings) +* worked from a secondary process, but it doesn't. +*/ +static struct rte_ring * +create_ring_dev (char *vdev_name,uint16_t *mirror_port) { -struct rte_ring *ring; +struct rte_eth_dev_owner owner = {0 }; +struct rte_eth_conf dev_conf = {0 }; +struct rte_ring *ring =NULL ;char ring_name[RTE_RING_NAMESIZE ]; +char vdev_args[128 ];size_t size, log2; +uint16_t port; +int ret;/* Find next power of 2 >= size. */ size = ring_size;
app/dumpcap/main.c static struct rte_ring *create_ring(void) · line 707
Quoted 7 lines
app/dumpcap/main.c +1
-3@@ -686,17 +704,59 @@ static struct rte_ring *create_ring(void) ring_size = size; } -/* Want one ring per invocation of program */ -snprintf (ring_name,sizeof (ring_name), -"dumpcap-%d" ,getpid ()); +/* Use owner as unique Id for ring and to isolate */
Perhaps spell 'Id' all-caps: 'ID' (this is up to you).
Quoted 11 lines
app/dumpcap/main.c +8
-2+ ret =rte_eth_dev_owner_new (&owner.id); +if (ret <0 ) +rte_exit (EXIT_FAILURE ,"rte_eth_dev_owner_new failed: %s\n" , +strerror (-ret)); - ring =rte_ring_create (ring_name, ring_size, -rte_socket_id (),0 ); +/* Give the vdev a unique name */ +snprintf (ring_name,sizeof (ring_name),"dumpcap%" PRIu64, owner.id); + ring =rte_ring_create (ring_name, ring_size,rte_socket_id (), +RING_F_MP_RTS_ENQ |RING_F_SC_DEQ );
app/dumpcap/main.c static struct rte_ring *create_ring(void) · line 726
Quoted 10 lines
app/dumpcap/main.c +6
-0if (ring ==NULL )rte_exit (EXIT_FAILURE ,"Could not create ring :%s\n" ,rte_strerror (rte_errno)); +strlcpy (owner.name, ring_name,sizeof (owner.name)); + +snprintf (vdev_name,RTE_DEV_NAME_MAX_LEN ,"net_ring-dumpcap%" PRIu64, owner.id); +snprintf (vdev_args,sizeof (vdev_args),"ring=%s" , ring_name); + +if (rte_eal_hotplug_add ("vdev" , vdev_name, vdev_args) <0 )
Perhaps enclose the multi-line statement with '{' and '}'. Also, if 'rte_exit' frees resources, including the ring created above, then not jumping to 'unplug' is fine, but is slightly inconsistent with below jumps: if jump there, why not also do this here? May be I'm wrong in fact.
May be add a little more elaborate fail ladder instead of just one 'unplug'?
Quoted 4 lines
app/dumpcap/main.c +4
-0+rte_exit (EXIT_FAILURE , +"rte_eal_hotplug_add of %s failed:%s\n" , + vdev_name,rte_strerror (rte_errno)); +
app/dumpcap/main.c static struct rte_ring *create_ring(void) · line 740
Quoted 10 lines
app/dumpcap/main.c +10
-0+ ret =rte_eth_dev_get_port_by_name (vdev_name, &port); +if (ret !=0 ) { +fprintf (stderr,"Could not port for %s: %s\n" , + vdev_name,strerror (-ret)); + goto unplug; + } + + ret =rte_eth_dev_owner_set (port, &owner); +if (ret !=0 ) { + fprintf(stderr, "Could not set owner for port for %u: %s\n",
Redundant 'for' in 'for port for'?
Quoted 155 lines
app/dumpcap/main.c +94
-24+ port, strerror(-ret)); + goto unplug; + } + + ret =rte_eth_dev_configure (port,1 ,1 , &dev_conf); +if (ret <0 ) { +fprintf (stderr,"Could not configure port %u: %s\n" , + port,strerror (-ret)); + goto unplug; + } + + *mirror_port = port;return ring; + +unplug: +rte_eal_hotplug_remove ("vdev" , vdev_name); +rte_ring_free (ring); +rte_eal_cleanup (); +exit (EXIT_FAILURE ); }static struct rte_mempool *create_mempool (void )@@ -796,7 +856,7 @@ static dumpcap_out_t create_output(void) version(), capture_comment);if (ret.pcapng ==NULL )rte_exit (EXIT_FAILURE ,"pcapng_fdopen failed: %s\n" , -strerror (rte_errno)); +rte_strerror (rte_errno));free (os); TAILQ_FOREACH(intf, &interfaces, next) {@@ -823,37 +883,32 @@ static dumpcap_out_t create_output(void)return ret; } -static void enable_pdump (struct rte_ring *r,struct rte_mempool *mp) +static int enable_mirror (uint16_t mirror_port,struct rte_mempool *mpool) {struct interface *intf;unsigned int count =0 ; -uint32_t flags;int ret; - flags =RTE_PDUMP_FLAG_RXTX ; -if (use_pcapng) - flags |=RTE_PDUMP_FLAG_PCAPNG ; + ret =rte_eth_dev_start (mirror_port); +if (ret <0 ) +rte_exit (EXIT_FAILURE ,"Could not start mirror port %u: %s\n" , + mirror_port,strerror (-ret)); TAILQ_FOREACH(intf, &interfaces, next) { - ret =rte_pdump_enable_bpf (intf->port,RTE_PDUMP_ALL_QUEUES , - flags, intf->opts.snap_len, - r, mp, intf->bpf_prm); +struct rte_eth_mirror_conf conf = { + .mp = mpool, + .target = mirror_port, + .snaplen = intf->opts.snap_len, + .flags =RTE_ETH_MIRROR_ORIGIN_FLAG |RTE_ETH_MIRROR_TIMESTAMP_FLAG , + .direction =RTE_ETH_MIRROR_DIRECTION_INGRESS | +RTE_ETH_MIRROR_DIRECTION_EGRESS , + }; + + ret =rte_eth_add_mirror (intf->port, &conf);if (ret <0 ) { -const struct interface *intf2; - -/* unwind any previous enables */ - TAILQ_FOREACH(intf2, &interfaces, next) { -if (intf == intf2) -break ; -rte_pdump_disable (intf2->port, -RTE_PDUMP_ALL_QUEUES ,RTE_PDUMP_FLAG_RXTX ); -if (intf2->opts.promisc_mode) -rte_eth_promiscuous_disable (intf2->port); - } -rte_exit (EXIT_FAILURE , -"Packet dump enable on %u:%s failed %s\n" , - intf->port, intf->name, -rte_strerror (rte_errno)); +fprintf (stderr,"Port mirror on %u:%s failed %s\n" , + intf->port, intf->name,strerror (-ret)); +return -1 ; }if (intf->opts.promisc_mode) {@@ -868,6 +923,60 @@ static void enable_pdump(struct rte_ring *r, struct rte_mempool *mp) } ++count; } +return count; +} + +static int setup_mbuf (void ) +{ +int offset; + + offset =rte_mbuf_dynfield_lookup (RTE_MBUF_DYNFIELD_TIMESTAMP_NAME ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find timestamp dynamic field\n" ); +return -1 ; + } + timestamp_dynfield = offset; + + offset =rte_mbuf_dynflag_lookup (RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find timestamp flag\n" ); +return -1 ; + } + timestamp_dynflag =RTE_BIT64 (offset); + + offset =rte_mbuf_dynfield_lookup (RTE_MBUF_DYNFIELD_MIRROR_ORIGIN ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find mirror origin dynamic field\n" ); +return -1 ; + } + mirror_origin_dynfield = offset; + + offset =rte_mbuf_dynflag_lookup (RTE_MBUF_DYNFLAG_MIRROR_ORIGIN ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find mirror origin dynamic flag\n" ); +return -1 ; + } + mirror_origin_dynflag =RTE_BIT64 (offset); + + offset =rte_mbuf_dynflag_lookup (RTE_MBUF_DYNFLAG_MIRROR_INGRESS ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find mirror ingress flag\n" ); +return -1 ; + } + mirror_ingress_dynflag =RTE_BIT64 (offset); + + offset =rte_mbuf_dynflag_lookup (RTE_MBUF_DYNFLAG_MIRROR_EGRESS ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find mirror egress flag\n" ); +return -1 ; + } + mirror_egress_dynflag =RTE_BIT64 (offset); +return 0 ; +} + +static void show_capturing (unsigned int count) +{ +struct interface *intf;fputs ("Capturing on " , stdout); TAILQ_FOREACH(intf, &interfaces, next) {@@ -898,6 +1007,47 @@ static void show_count(uint64_t count) bt =fprintf (stderr,"%" PRIu64" " , count); } +static ssize_t +pcapng_write_packets (rte_pcapng_t *pcapng,struct rte_mbuf *pkts[],uint16_t n) +{
app/dumpcap/main.c static void show_count(uint64_t count) · line 1022
Quoted 10 lines
app/dumpcap/main.c +10
-0+struct rte_mbuf *towrite[BURST_SIZE ]; +unsigned int count =0 ; + +for (unsigned int i =0 ; i < n; i++) { +struct rte_mbuf *m = pkts[i]; +enum rte_pcapng_direction direction =RTE_PCAPNG_DIRECTION_UNKNOWN ; + +/* If no origin flag then why did we get this? */ +if (unlikely (!(m->ol_flags & mirror_origin_dynflag))) { +fprintf (stderr,"Missing origin info in packet\n" );
And what happens to the rest of mbufs in the 'pkts' batch? Leak?
Quoted 80 lines
app/dumpcap/main.c +28
-0+return -1 ; + } + +const struct rte_mbuf_origin *origin + = RTE_MBUF_DYNFIELD(m, mirror_origin_dynfield, rte_mbuf_origin_t *); + +if (m->ol_flags & mirror_ingress_dynflag) + direction =RTE_PCAPNG_DIRECTION_IN ; +else if (m->ol_flags & mirror_egress_dynflag) + direction =RTE_PCAPNG_DIRECTION_OUT ; + +uint64_t timestamp; +if (m->ol_flags & timestamp_dynflag) + timestamp = *RTE_MBUF_DYNFIELD (m, timestamp_dynfield, + rte_mbuf_timestamp_t *); +else + timestamp =rte_get_tsc_cycles (); + +if (rte_pcapng_insert (m, origin->queue_id, direction, origin->original_len, + timestamp,NULL ) <0 ) +continue ;/* skip no headroom? */ + + towrite[count++] = m; + } + +return rte_pcapng_write_packets (pcapng, towrite, count); +} +/* Write multiple packets in older pcap format */ static
ssize_t
pcap_write_packets(pcap_dumper_t *dumper,app/dumpcap/main.c +45
-0@@ -930,16 +1080,129 @@ pcap_write_packets(pcap_dumper_t *dumper,return total; } +/* Do packet filter on incoming packets. +* Some issues to note here: +* - would be better to do before putting into ring +* but that causes ethdev to have dependency on BPF. +* - the filter is per-interface and there maybe more than one interface +* combined into the ring. That means filter is executed once +* per packet (not as burst). +*/ +static unsigned int +filter_packets (struct rte_mbuf *pkts[],unsigned int n) +{ +unsigned int matches =0 ; +unsigned int results[BURST_SIZE ] = {0 }; + +for (unsigned int i =0 ; i < n; i++) { +struct rte_mbuf *m = pkts[i]; + +/* all packets should have origin info, if not just skip */ +if (unlikely (!(m->ol_flags & mirror_origin_dynflag))) +continue ; + +const struct rte_mbuf_origin *origin + = RTE_MBUF_DYNFIELD(m, mirror_origin_dynfield, rte_mbuf_origin_t *); +uint16_t port_id = origin->port_id; + +if (unlikely (port_id >=RTE_MAX_ETHPORTS )) +continue ; + +const struct interface *intf = port2intf[port_id]; +if (intf ==NULL || intf->bpf ==NULL ) +continue ; + + results[i] = bpf_filter(intf->bpf, rte_pktmbuf_mtod(m, u_char *), + origin->original_len, m->data_len); +if (results[i] !=0 ) + ++matches; + } + +if (matches == n) +return n;/* no packets skipped */ + +/* need to shuffle out the skipped packets */ +unsigned int count =0 ; +struct rte_mbuf *towrite[BURST_SIZE ]; +for (unsigned int i =0 ; i < n; i++) {
app/dumpcap/main.c pcap_write_packets(pcap_dumper_t *dumper, · line 1137
Quoted 10 lines
app/dumpcap/main.c +10
-0+if (results[i]) + towrite[count++] = pkts[i]; +else +rte_pktmbuf_free (pkts[i]); + } +memcpy (pkts, towrite, count *sizeof (struct rte_mbuf *)); +return count; +} + +/* Make sure configuration of mbuf pool has enough headroom for both vlans */
Perhaps spell 'vlans' all-caps: 'VLANs'.
app/dumpcap/main.c pcap_write_packets(pcap_dumper_t *dumper, · line 1139
Quoted 2 lines
app/dumpcap/main.c +2
-0+static_assert (RTE_PKTMBUF_HEADROOM >2 *sizeof (struct rte_vlan_hdr ), +"not enough mbuf headroom for vlan insertion" );
Same here: 'VLAN' (up to you).
Quoted 12 lines
app/dumpcap/main.c +12
-0+ +/* +* More general version of rte_vlan_insert() +* Note: mbufs are allocated by rte_eth_mirror_burst() from the +* pool that was passed when setting up mirror. +*/ +static void +vlan_insert (struct rte_mbuf *m,uint16_t ether_type,uint16_t tci) +{ +struct rte_ether_hdr *nh, tmph; +const struct rte_ether_hdr *oh; +struct rte_vlan_hdr *vh;
app/dumpcap/main.c pcap_write_packets(pcap_dumper_t *dumper, · line 1161
Quoted 10 lines
app/dumpcap/main.c +10
-0+ +RTE_ASSERT (!RTE_MBUF_DIRECT (m)); +RTE_ASSERT (rte_mbuf_refcnt_read (m) ==1 ); + + oh =rte_pktmbuf_read (m,0 ,sizeof (*oh), &tmph); +RTE_ASSERT (oh !=NULL ); + +/* overlay new header */ + nh = (struct rte_ether_hdr *) +rte_pktmbuf_prepend (m,sizeof (struct rte_vlan_hdr ));
Prepend? But what if this is an indirect mbuf. Is it OK? Just asking.
Thank you.
Quoted 177 lines
app/dumpcap/main.c +72
-15+ +RTE_ASSERT (nh !=NULL ); + +memmove (nh, oh,2 *RTE_ETHER_ADDR_LEN ); + nh->ether_type =rte_cpu_to_be_16 (ether_type); + + vh = (struct rte_vlan_hdr *) (nh +1 ); + vh->vlan_tci =rte_cpu_to_be_16 (tci); +} + +/* Filtering and pcap file format require that VLAN not be offloaded */ +static void +remove_vlan_offload (struct rte_mbuf *pkts[],unsigned int n) +{ +unsigned int i; + +for (i =0 ; i < n; i++) { +struct rte_mbuf *m = pkts[i]; + +if (m->ol_flags & mirror_ingress_dynflag) { +if (m->ol_flags &RTE_MBUF_F_RX_VLAN_STRIPPED ) +vlan_insert (m,RTE_ETHER_TYPE_VLAN , m->vlan_tci); +if (m->ol_flags &RTE_MBUF_F_RX_QINQ_STRIPPED ) +vlan_insert (m,RTE_ETHER_TYPE_QINQ , m->vlan_tci_outer); + } +if (m->ol_flags & mirror_egress_dynflag) { +if (m->ol_flags &RTE_MBUF_F_TX_VLAN ) +vlan_insert (m,RTE_ETHER_TYPE_VLAN , m->vlan_tci); +if (m->ol_flags &RTE_MBUF_F_TX_QINQ ) +vlan_insert (m,RTE_ETHER_TYPE_QINQ , m->vlan_tci_outer); + + } + } +} +/* Process all packets in ring and dump to capture file */ -static int process_ring (dumpcap_out_t out,struct rte_ring *r) +static int process_ring (dumpcap_out_t out,struct rte_ring *ring) {struct rte_mbuf *pkts[BURST_SIZE ]; -unsigned int avail, n; +unsigned int n, avail;static unsigned int empty_count;ssize_t written; - n =rte_ring_sc_dequeue_burst (r, (void **) pkts,BURST_SIZE , - &avail); + n =rte_ring_sc_dequeue_burst (ring, (void **)pkts,BURST_SIZE , &avail);if (n ==0 ) {/* don't consume endless amounts of cpu if idle */ if (empty_count <SLEEP_THRESHOLD )@@ -948,11 +1211,18 @@ static int process_ring(dumpcap_out_t out, struct rte_ring *r)usleep (10 );return 0 ; } - empty_count = (avail ==0 ); +remove_vlan_offload (pkts, n); + +if (filtering) { + n =filter_packets (pkts, n); +if (n ==0 ) +return 0 ; + } +if (use_pcapng) - written =rte_pcapng_write_packets (out.pcapng, pkts, n); + written =pcapng_write_packets (out.pcapng, pkts, n);else written =pcap_write_packets (out.dumper, pkts, n);@@ -971,15 +1241,18 @@ static int process_ring(dumpcap_out_t out, struct rte_ring *r)int main (int argc,char **argv) { -struct rte_ring *r;struct rte_mempool *mp;struct sigaction action = { .sa_flags =SA_RESTART , .sa_handler = signal_handler, };struct sigaction origaction; +struct rte_ring *ring =NULL ; +char vdev_name[RTE_DEV_NAME_MAX_LEN ]; +uint16_t mirror_port =UINT16_MAX ;dumpcap_out_t out;char *p; +int ret; p =strrchr (argv[0 ],'/' );if (p ==NULL )@@ -1018,12 +1291,21 @@ int main(int argc, char **argv)exit (0 ); } - r =create_ring (); mp =create_mempool (); + ring =create_ring_dev (vdev_name, &mirror_port); out =create_output (); + ret =enable_mirror (mirror_port, mp); +if (ret <0 ) + goto cleanup; + + ret =setup_mbuf (); +if (ret <0 ) + goto cleanup; + +show_capturing (ret); + start_time =time (NULL ); -enable_pdump (r, mp);if (!quiet) {fprintf (stderr,"Packets captured: " );@@ -1031,7 +1313,7 @@ int main(int argc, char **argv) }while (!rte_atomic_load_explicit (&quit_signal, rte_memory_order_relaxed)) { -if (process_ring (out, r) <0 ) { +if (process_ring (out, ring) <0 ) {fprintf (stderr,"pcapng file write failed; %s\n" ,strerror (errno));break ;@@ -1048,20 +1330,24 @@ int main(int argc, char **argv)break ; } -disable_primary_monitor (); -if (rte_eal_primary_proc_alive (NULL ))report_packet_stats (out); +cleanup: +disable_primary_monitor (); +if (use_pcapng)rte_pcapng_close (out.pcapng);else pcap_dump_close (out.dumper); -cleanup_pdump_resources (); +if (rte_eal_primary_proc_alive (NULL )) { +disable_mirror_ports (mirror_port); -rte_ring_free (r); -rte_mempool_free (mp); +rte_eal_hotplug_remove ("vdev" , vdev_name); +rte_ring_free (ring); +rte_mempool_free (mp); + }return rte_eal_cleanup () ?EXIT_FAILURE :0 ; }app/dumpcap/meson.build +0
-0@@ -6,12 +6,6 @@ if not dpdk_conf.has('RTE_HAS_LIBPCAP') reason = 'missing dependency, "libpcap"'endif
app/dumpcap/meson.build +0
-6-if is_windows - build = false - reason = 'not supported on Windows' - subdir_done() -endif -
ext_deps+=pcap_dep
sources = files('main.c')app/dumpcap/meson.build +1
-1-deps += ['ethdev', 'pdump', 'pcapng', 'bpf'] +deps += ['net_ring', 'ethdev', 'pcapng' ]Signature · 1 line
2.47.2
Re: [PATCH v6 12/13] app/dumpcap: use port mirror instead of pdump
Quoted 510 lines · Ivan Malov
Hi Stephen,
(please see below)
Quoted 240 lines · Stephen Hemminger
Use the new port mirror API instead of pdump.
Since filtering is now done in dumpcap process (not primary). For portability use PCAP to do packet filtering. This removes dependency on DPDK implementation of BPF. Filtering will be slower (no JIT) but is portable to Windows. Can revisit later when BPF support is updated.
Signed-off-by Stephen Hemminger <[email protected]>---
app/dumpcap/main.c| 468 ++++++++++++++++++++++++++++++++--------
app/dumpcap/meson.build | 8 +-2 files changed, 378 insertions(+), 98 deletions(-)app/dumpcap/main.c +21
-11@@ -25,7 +25,6 @@#include <rte_alarm.h> #include <rte_bitops.h> -#include <rte_bpf.h> #include <rte_config.h> #include <rte_debug.h> #include <rte_eal.h> @@ -36,8 +35,6 @@#include <rte_mbuf.h> #include <rte_mempool.h> #include <rte_pcapng.h> -#include <rte_pdump.h> -#include <rte_ring.h> #include <rte_string_fns.h> #include <rte_thread.h> #include <rte_time.h> @@ -93,15 +90,26 @@ struct interface {TAILQ_ENTRY (interface) next;uint16_t port;struct capture_options opts; -struct rte_bpf_prm *bpf_prm;char name[RTE_ETH_NAME_MAX_LEN ]; +struct bpf_insn *bpf; +struct rte_eth_stats start_stats;const char *ifname;const char *ifdescr; }; +static int timestamp_dynfield =-1 ; +static uint64_t timestamp_dynflag; +static int mirror_origin_dynfield =-1 ; +static uint64_t mirror_origin_dynflag; +static uint64_t mirror_ingress_dynflag; +static uint64_t mirror_egress_dynflag; + +static bool filtering; +TAILQ_HEAD (interface_list, interface);static struct interface_list interfaces =TAILQ_HEAD_INITIALIZER (interfaces); +static struct interface *port2intf[RTE_MAX_ETHPORTS ];/* Can do either pcap or pcapng format output */ typedef union {@@ -239,14 +247,16 @@ static void find_interfaces(void) TAILQ_FOREACH(intf, &interfaces, next) {/* if name is valid then just record port */ -if (rte_eth_dev_get_port_by_name (intf->name, &intf->port) == 0) -continue ; +if (rte_eth_dev_get_port_by_name (intf->name, &intf->port) !=0 ) { +/* maybe got passed port number string as name */ + intf->port =get_uint (intf->name,"port_number" ,UINT16_MAX ); +if (rte_eth_dev_get_name_by_port (intf->port, intf->name) <0 ) + rte_exit(EXIT_FAILURE, "Invalid port number %u\n", + intf->port); + } - /* maybe got passed port number string as name */ - intf->port = get_uint(intf->name, "port_number", UINT16_MAX); -if (rte_eth_dev_get_name_by_port (intf->port, intf->name) <0 ) -rte_exit (EXIT_FAILURE ,"Invalid port number %u\n" , - intf->port); +if (rte_eth_stats_get (intf->port, &intf->start_stats) <0 ) + rte_exit(EXIT_FAILURE, "Could not read stats for port%u\n", intf->port); } }app/dumpcap/main.c +4
-0@@ -266,6 +276,10 @@ static void set_default_interface(void) intf =add_interface (name); intf->port = p; + +if (rte_eth_stats_get (intf->port, &intf->start_stats) <0 ) +rte_exit (EXIT_FAILURE , +"Could not read stats for port %u\n" , intf->port);return ; }rte_exit(EXIT_FAILURE, "No usable interfaces found\n");app/dumpcap/main.c +14
-19@@ -291,44 +305,40 @@ static void compile_filters(void)struct interface *intf; TAILQ_FOREACH(intf, &interfaces, next) { -struct rte_bpf_prm *bpf_prm;struct bpf_program bf;pcap_t *pcap; +/* cache for filter packets */ + port2intf[intf->port] = intf; + +if (intf->opts.filter ==NULL ) { + intf->bpf =NULL ; +continue ; + } + pcap =pcap_open_dead (DLT_EN10MB , intf->opts.snap_len);if (!pcap)rte_exit (EXIT_FAILURE ,"can not open pcap\n" ); -if (pcap_compile (pcap, &bf, intf->opts.filter, -1 ,PCAP_NETMASK_UNKNOWN ) !=0 ) { +if (pcap_compile (pcap, &bf, intf->opts.filter,1 ,PCAP_NETMASK_UNKNOWN ) !=0 ) {fprintf (stderr,"Invalid capture filter \"%s\": for interface '%s'\n", intf->opts.filter, intf->name); -rte_exit (EXIT_FAILURE ,"\n%s\n" , -pcap_geterr (pcap)); +rte_exit (EXIT_FAILURE ,"\n%s\n" ,pcap_geterr (pcap)); } - bpf_prm =rte_bpf_convert (&bf); -if (bpf_prm ==NULL ) -rte_exit (EXIT_FAILURE , -"BPF convert interface '%s'\n%s(%d)\n" , - intf->name, -rte_strerror (rte_errno), rte_errno); -if (dump_bpf) {printf ("cBPF program (%u insns)\n" , bf.bf_len);bpf_dump (&bf,1 ); -printf ("\neBPF program (%u insns)\n" , - bpf_prm->nb_ins); -rte_bpf_dump (stdout, bpf_prm->ins, bpf_prm->nb_ins);exit (0 ); } - intf->bpf_prm = bpf_prm; + intf->bpf =malloc (bf.bf_len *sizeof (struct bpf_insn )); +if (!intf->bpf) +rte_exit (EXIT_FAILURE ,"can not allocate memory for bpf\n"); - /* Don't care about original program any more */ - pcap_freecode(&bf); -pcap_close (pcap); + memcpy(intf->bpf, bf.bf_insns, bf.bf_len * sizeof(struct
bpf_insn));app/dumpcap/main.c +1
-0+ filtering = true;} }app/dumpcap/main.c +0
-0@@ -518,13 +528,12 @@ static void statistics_loop(void) }static void
app/dumpcap/main.c +1
-1-cleanup_pdump_resources (void) +disable_mirror_ports(uint16_t mirror_port){ struct interface *intf; TAILQ_FOREACH(intf, &interfaces, next) {app/dumpcap/main.c +1
-2-rte_pdump_disable (intf->port, -RTE_PDUMP_ALL_QUEUES ,RTE_PDUMP_FLAG_RXTX ); +rte_eth_remove_mirror (intf->port, mirror_port);if (intf->opts.promisc_mode) rte_eth_promiscuous_disable(intf->port); }app/dumpcap/main.c +1
-1@@ -541,7 +550,7 @@ monitor_primary(void *arg __rte_unused)rte_eal_alarm_set (MONITOR_INTERVAL , monitor_primary,NULL ); }else {fprintf (stderr, -"Primary process is no longer active, exiting...\n" ); +"\nPrimary process is no longer active, exiting...\n");rte_atomic_store_explicit (&quit_signal, true, rte_memory_order_relaxed);} }app/dumpcap/main.c +0
-1@@ -552,7 +561,6 @@ enable_primary_monitor(void) {int ret; -/* Once primary exits, so will pdump. */ ret =rte_eal_alarm_set (MONITOR_INTERVAL , monitor_primary,NULL );if (ret <0 )fprintf (stderr,"Fail to enable monitor:%d\n" , ret);@@ -571,23 +579,24 @@ disable_primary_monitor(void)static void
report_packet_stats(dumpcap_out_t out)
{app/dumpcap/main.c +0
-1-struct rte_pdump_stats pdump_stats;struct interface *intf;app/dumpcap/main.c +0
-2-uint64_t ifrecv, ifdrop; -double percent;fputc('\n', stderr); + TAILQ_FOREACH(intf, &interfaces, next) {app/dumpcap/main.c +5
-1-if (rte_pdump_stats (intf->port, &pdump_stats) <0 ) +uint64_t ifrecv, ifdrop; +struct rte_eth_stats stats; +double percent; + +if (rte_eth_stats_get (intf->port, &stats) <0 )continue;app/dumpcap/main.c +3
-3-/* do what Wiretap does */ - ifrecv = pdump_stats.accepted + pdump_stats.filtered; - ifdrop = pdump_stats.nombuf + pdump_stats.ringfull; + ifrecv = stats.ipackets - intf->start_stats.ipackets; + ifdrop = (stats.rx_nombuf - intf->start_stats.rx_nombuf) + + (stats.imissed - intf->start_stats.imissed);if (
use_pcapng)app/dumpcap/main.c +1
-2-rte_pcapng_write_stats (out.pcapng, intf->port, - ifrecv, ifdrop,NULL ); + rte_pcapng_write_stats(out.pcapng, intf->port,ifrecv, ifdrop, NULL);
if (ifrecv == 0) percent = 0;app/dumpcap/main.c static void dpdk_init(void) · line 681
Quoted 7 lines
app/dumpcap/main.c +1
-2@@ -668,12 +677,21 @@ static void dpdk_init(void)rte_exit (EXIT_FAILURE ,"Can not restore original CPU affinity\n"); } -/* Create packet ring shared between callbacks and process */ -static struct rte_ring *create_ring (void ) +/* Create ring port to redirect packet to. Perhaps adhere to
/*
* comment
*/
style (I do not insist - this is up to you).Quoted 19 lines
app/dumpcap/main.c +11
-1+* This could be much simpler if the ring PMD API (rte_eth_from_rings) +* worked from a secondary process, but it doesn't. +*/ +static struct rte_ring * +create_ring_dev (char *vdev_name,uint16_t *mirror_port) { -struct rte_ring *ring; +struct rte_eth_dev_owner owner = {0 }; +struct rte_eth_conf dev_conf = {0 }; +struct rte_ring *ring =NULL ;char ring_name[RTE_RING_NAMESIZE ]; +char vdev_args[128 ];size_t size, log2; +uint16_t port; +int ret;/* Find next power of 2 >= size. */ size = ring_size;app/dumpcap/main.c static struct rte_ring *create_ring(void) · line 707
Quoted 7 lines
app/dumpcap/main.c +1
-3@@ -686,17 +704,59 @@ static struct rte_ring *create_ring(void) ring_size = size; } -/* Want one ring per invocation of program */ -snprintf (ring_name,sizeof (ring_name), -"dumpcap-%d" ,getpid ()); +/* Use owner as unique Id for ring and to isolate */ Perhaps spell 'Id' all-caps: 'ID' (this is up to you).
Quoted 12 lines
app/dumpcap/main.c +8
-2+ ret =rte_eth_dev_owner_new (&owner.id); +if (ret <0 ) +rte_exit (EXIT_FAILURE ,"rte_eth_dev_owner_new failed: %s\n" , +strerror (-ret)); - ring =rte_ring_create (ring_name, ring_size, -rte_socket_id (),0 ); +/* Give the vdev a unique name */ +snprintf (ring_name,sizeof (ring_name),"dumpcap%" PRIu64, owner.id); + ring =rte_ring_create (ring_name, ring_size,rte_socket_id (), +RING_F_MP_RTS_ENQ |RING_F_SC_DEQ );if (ring ==NULL )app/dumpcap/main.c static struct rte_ring *create_ring(void) · line 726
Quoted 10 lines
app/dumpcap/main.c +6
-0rte_exit (EXIT_FAILURE ,"Could not create ring :%s\n" ,rte_strerror (rte_errno)); +strlcpy (owner.name, ring_name,sizeof (owner.name)); + +snprintf (vdev_name,RTE_DEV_NAME_MAX_LEN ,"net_ring-dumpcap%" PRIu64, owner.id); +snprintf (vdev_args,sizeof (vdev_args),"ring=%s" , ring_name); + +if (rte_eal_hotplug_add ("vdev" , vdev_name, vdev_args) <0 )Perhaps enclose the multi-line statement with '{' and '}'. Also, if '
rte_exit' frees resources, including the ring created above, then not jumping to 'unplug' is fine, but is slightly inconsistent with below jumps: if jump there, why not also do this here? May be I'm wrong in fact.May be add a little more elaborate fail ladder instead of just one 'unplug'?
Quoted 4 lines
app/dumpcap/main.c +4
-0+rte_exit (EXIT_FAILURE , +"rte_eal_hotplug_add of %s failed:%s\n" , + vdev_name,rte_strerror (rte_errno)); +app/dumpcap/main.c static struct rte_ring *create_ring(void) · line 740
Quoted 10 lines
app/dumpcap/main.c +10
-0+ ret =rte_eth_dev_get_port_by_name (vdev_name, &port); +if (ret !=0 ) { +fprintf (stderr,"Could not port for %s: %s\n" , + vdev_name,strerror (-ret)); + goto unplug; + } + + ret =rte_eth_dev_owner_set (port, &owner); +if (ret !=0 ) { + fprintf(stderr, "Could not set owner for port for %u: %s\n",Redundant 'for' in 'for port for'?
Quoted 174 lines
app/dumpcap/main.c +18
-0+ port, strerror(-ret)); + goto unplug; + } + + ret =rte_eth_dev_configure (port,1 ,1 , &dev_conf); +if (ret <0 ) { +fprintf (stderr,"Could not configure port %u: %s\n" , + port,strerror (-ret)); + goto unplug; + } + + *mirror_port = port;return ring; + +unplug: +rte_eal_hotplug_remove ("vdev" , vdev_name); +rte_ring_free (ring); +rte_eal_cleanup (); +exit (EXIT_FAILURE ); }static struct
rte_mempool*create_mempool(void)app/dumpcap/main.c +19
-24@@ -796,7 +856,7 @@ static dumpcap_out_t create_output(void) version(), capture_comment);if (ret.pcapng ==NULL )rte_exit (EXIT_FAILURE ,"pcapng_fdopen failed: %s\n" , -strerror (rte_errno)); +rte_strerror (rte_errno));free (os); TAILQ_FOREACH(intf, &interfaces, next) {@@ -823,37 +883,32 @@ static dumpcap_out_t create_output(void)return ret; } -static void enable_pdump (struct rte_ring *r,struct rte_mempool *mp) +static int enable_mirror (uint16_t mirror_port,struct rte_mempool *mpool) {struct interface *intf;unsigned int count =0 ; -uint32_t flags;int ret; - flags =RTE_PDUMP_FLAG_RXTX ; -if (use_pcapng) - flags |=RTE_PDUMP_FLAG_PCAPNG ; + ret =rte_eth_dev_start (mirror_port); +if (ret <0 ) + rte_exit(EXIT_FAILURE, "Could not start mirror port %u: %s\n", + mirror_port, strerror(-ret)); TAILQ_FOREACH(intf, &interfaces, next) { - ret =rte_pdump_enable_bpf (intf->port,RTE_PDUMP_ALL_QUEUES , - flags, intf->opts.snap_len, - r, mp, intf->bpf_prm); +struct rte_eth_mirror_conf conf = { + .mp = mpool, + .target = mirror_port, + .snaplen = intf->opts.snap_len, + .flags =RTE_ETH_MIRROR_ORIGIN_FLAG |RTE_ETH_MIRROR_TIMESTAMP_FLAG , + .direction =RTE_ETH_MIRROR_DIRECTION_INGRESS | +RTE_ETH_MIRROR_DIRECTION_EGRESS , + }; + + ret =rte_eth_add_mirror (intf->port, &conf);if (ret <0 ) { -const struct interface *intf2; - -/* unwind any previous enables */ - TAILQ_FOREACH(intf2, &interfaces, next) { -if (intf == intf2) -break ; -rte_pdump_disable (intf2->port, -RTE_PDUMP_ALL_QUEUES , RTE_PDUMP_FLAG_RXTX); -if (intf2->opts.promisc_mode) -rte_eth_promiscuous_disable (intf2->port); - } -rte_exit (EXIT_FAILURE , -"Packet dump enable on %u:%s failed %s\n" , - intf->port, intf->name, -rte_strerror (rte_errno)); +fprintf (stderr,"Port mirror on %u:%s failed %s\n" , + intf->port, intf->name,strerror (-ret)); +return -1 ;} if (intf->opts.promisc_mode) {app/dumpcap/main.c +22
-0@@ -868,6 +923,60 @@ static void enable_pdump(struct rte_ring *r, struct rte_mempool *mp) } ++count; } +return count; +} + +static int setup_mbuf (void ) +{ +int offset; + + offset =rte_mbuf_dynfield_lookup (RTE_MBUF_DYNFIELD_TIMESTAMP_NAME ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find timestamp dynamic field\n" ); +return -1 ; + } + timestamp_dynfield = offset; + + offset =rte_mbuf_dynflag_lookup (RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME ,NULL ); +if (offset <0 ) { +fprintf (stderr,"Could not find timestamp flag\n" ); +return -1 ; + } + timestamp_dynflag =RTE_BIT64 (offset); + + offset = rte_mbuf_dynfield_lookup(RTE_MBUF_DYNFIELD_MIRROR_ORIGIN,NULL);
app/dumpcap/main.c +2
-0+if (offset <0 ) { + fprintf(stderr, "Could not find mirror origin dynamicfield\n");
app/dumpcap/main.c +5
-0+return -1 ; + } + mirror_origin_dynfield = offset; + + offset = rte_mbuf_dynflag_lookup(RTE_MBUF_DYNFLAG_MIRROR_ORIGIN,NULL);
app/dumpcap/main.c +2
-0+if (offset <0 ) { + fprintf(stderr, "Could not find mirror origin dynamicflag\n");
app/dumpcap/main.c +5
-0+return -1 ; + } + mirror_origin_dynflag =RTE_BIT64 (offset); + + offset = rte_mbuf_dynflag_lookup(RTE_MBUF_DYNFLAG_MIRROR_INGRESS,NULL);
app/dumpcap/main.c +7
-0+if (offset <0 ) { +fprintf (stderr,"Could not find mirror ingress flag\n" ); +return -1 ; + } + mirror_ingress_dynflag =RTE_BIT64 (offset); + + offset = rte_mbuf_dynflag_lookup(RTE_MBUF_DYNFLAG_MIRROR_EGRESS,NULL);
app/dumpcap/main.c +11
-0+if (offset <0 ) { +fprintf (stderr,"Could not find mirror egress flag\n" ); +return -1 ; + } + mirror_egress_dynflag =RTE_BIT64 (offset); +return 0 ; +} + +static void show_capturing (unsigned int count) +{ +struct interface *intf;fputs("Capturing on ", stdout); TAILQ_FOREACH(intf, &interfaces, next) {app/dumpcap/main.c +8
-0@@ -898,6 +1007,47 @@ static void show_count(uint64_t count) bt =fprintf (stderr,"%" PRIu64" " , count); } +static ssize_t +pcapng_write_packets (rte_pcapng_t *pcapng,struct rte_mbuf *pkts[],uint16_t n) +{ +struct rte_mbuf *towrite[BURST_SIZE ]; +unsigned int count =0 ; + +for (unsigned int i =0 ; i < n; i++) { +struct rte_mbuf *m = pkts[i];
Quoted 8 lines
app/dumpcap/main.c static void show_count(uint64_t count) · line 1022
Quoted 6 lines
app/dumpcap/main.c +5
-0+enum rte_pcapng_direction direction =RTE_PCAPNG_DIRECTION_UNKNOWN ; + +/* If no origin flag then why did we get this? */ +if (unlikely (!(m->ol_flags & mirror_origin_dynflag))) { +fprintf (stderr,"Missing origin info in packet\n" );And what happens to the rest of mbufs in the 'pkts' batch? Leak?
Sorry, my bad, - I see the whole bulk is freed outside.
Thank you.
Quoted 318 lines
Quoted 87 lines
app/dumpcap/main.c +15
-0+return -1 ; + } + +const struct rte_mbuf_origin *origin + =RTE_MBUF_DYNFIELD (m, mirror_origin_dynfield, rte_mbuf_origin_t *); + +if (m->ol_flags & mirror_ingress_dynflag) + direction =RTE_PCAPNG_DIRECTION_IN ; +else if (m->ol_flags & mirror_egress_dynflag) + direction =RTE_PCAPNG_DIRECTION_OUT ; + +uint64_t timestamp; +if (m->ol_flags & timestamp_dynflag) + timestamp = *RTE_MBUF_DYNFIELD (m, timestamp_dynfield, + rte_mbuf_timestamp_t*);
app/dumpcap/main.c +4
-0+else + timestamp =rte_get_tsc_cycles (); + + if (rte_pcapng_insert(m, origin->queue_id, direction,
origin->original_len,app/dumpcap/main.c +9
-0+ timestamp, NULL) < 0) +continue ;/* skip no headroom? */ + + towrite[count++] = m; + } + +return rte_pcapng_write_packets (pcapng, towrite, count); +} +/* Write multiple packets in older pcap format */ static
ssize_t
pcap_write_packets(pcap_dumper_t *dumper,app/dumpcap/main.c +46
-0@@ -930,16 +1080,129 @@ pcap_write_packets(pcap_dumper_t *dumper,return total; } +/* Do packet filter on incoming packets. +* Some issues to note here: +* - would be better to do before putting into ring +* but that causes ethdev to have dependency on BPF. +* - the filter is per-interface and there maybe more than one interface +* combined into the ring. That means filter is executed once +* per packet (not as burst). +*/ +static unsigned int +filter_packets (struct rte_mbuf *pkts[],unsigned int n) +{ +unsigned int matches =0 ; +unsigned int results[BURST_SIZE ] = {0 }; + +for (unsigned int i =0 ; i < n; i++) { +struct rte_mbuf *m = pkts[i]; + +/* all packets should have origin info, if not just skip */ +if (unlikely (!(m->ol_flags & mirror_origin_dynflag))) +continue ; + +const struct rte_mbuf_origin *origin + =RTE_MBUF_DYNFIELD (m, mirror_origin_dynfield, rte_mbuf_origin_t *); +uint16_t port_id = origin->port_id; + +if (unlikely (port_id >=RTE_MAX_ETHPORTS )) +continue ; + +const struct interface *intf = port2intf[port_id]; +if (intf ==NULL || intf->bpf ==NULL ) +continue ; + + results[i] =bpf_filter (intf->bpf,rte_pktmbuf_mtod (m, u_char *), + origin->original_len, m->data_len); +if (results[i] !=0 ) + ++matches; + } + +if (matches == n) +return n;/* no packets skipped */ + +/* need to shuffle out the skipped packets */ +unsigned int count =0 ; +struct rte_mbuf *towrite[BURST_SIZE ]; +for (unsigned int i =0 ; i < n; i++) { +if (results[i])app/dumpcap/main.c pcap_write_packets(pcap_dumper_t *dumper, · line 1140
Quoted 10 lines
app/dumpcap/main.c +9
-0+ towrite[count++] = pkts[i]; + else +rte_pktmbuf_free (pkts [i]); + } +memcpy (pkts, towrite, count *sizeof (struct rte_mbuf *)); +return count; +} + +/* Make sure configuration of mbuf pool has enough headroom for both vlans */ Perhaps spell 'vlans' all-caps: 'VLANs'.
app/dumpcap/main.c pcap_write_packets(pcap_dumper_t *dumper, · line 1139
Quoted 2 lines
app/dumpcap/main.c +2
-0+static_assert (RTE_PKTMBUF_HEADROOM >2 *sizeof (struct rte_vlan_hdr ), +"not enough mbuf headroom for vlan insertion" );Same here: 'VLAN' (up to you).
Quoted 12 lines
app/dumpcap/main.c +12
-0+ +/* +* More general version of rte_vlan_insert() +* Note: mbufs are allocated by rte_eth_mirror_burst() from the +* pool that was passed when setting up mirror. +*/ +static void +vlan_insert (struct rte_mbuf *m,uint16_t ether_type,uint16_t tci) +{ +struct rte_ether_hdr *nh, tmph; +const struct rte_ether_hdr *oh; +struct rte_vlan_hdr *vh;app/dumpcap/main.c pcap_write_packets(pcap_dumper_t *dumper, · line 1161
Quoted 10 lines
app/dumpcap/main.c +10
-0+ +RTE_ASSERT (!RTE_MBUF_DIRECT (m)); +RTE_ASSERT (rte_mbuf_refcnt_read (m) ==1 ); + + oh =rte_pktmbuf_read (m,0 ,sizeof (*oh), &tmph); +RTE_ASSERT (oh !=NULL ); + +/* overlay new header */ + nh = (struct rte_ether_hdr *) +rte_pktmbuf_prepend (m,sizeof (struct rte_vlan_hdr ));Prepend? But what if this is an indirect mbuf. Is it OK? Just asking.
Thank you.
Quoted 185 lines
app/dumpcap/main.c +37
-2+ +RTE_ASSERT (nh !=NULL ); + +memmove (nh, oh,2 *RTE_ETHER_ADDR_LEN ); + nh->ether_type =rte_cpu_to_be_16 (ether_type); + + vh = (struct rte_vlan_hdr *) (nh +1 ); + vh->vlan_tci =rte_cpu_to_be_16 (tci); +} + +/* Filtering and pcap file format require that VLAN not be offloaded */ +static void +remove_vlan_offload (struct rte_mbuf *pkts[],unsigned int n) +{ +unsigned int i; + +for (i =0 ; i < n; i++) { +struct rte_mbuf *m = pkts[i]; + +if (m->ol_flags & mirror_ingress_dynflag) { +if (m->ol_flags &RTE_MBUF_F_RX_VLAN_STRIPPED ) +vlan_insert (m,RTE_ETHER_TYPE_VLAN , m->vlan_tci); +if (m->ol_flags &RTE_MBUF_F_RX_QINQ_STRIPPED ) +vlan_insert (m,RTE_ETHER_TYPE_QINQ , m->vlan_tci_outer); + } +if (m->ol_flags & mirror_egress_dynflag) { +if (m->ol_flags &RTE_MBUF_F_TX_VLAN ) +vlan_insert (m,RTE_ETHER_TYPE_VLAN , m->vlan_tci); +if (m->ol_flags &RTE_MBUF_F_TX_QINQ ) +vlan_insert (m,RTE_ETHER_TYPE_QINQ , m->vlan_tci_outer); + + } + } +} +/* Process all packets in ring and dump to capture file */ -static int process_ring (dumpcap_out_t out,struct rte_ring *r) +static int process_ring (dumpcap_out_t out,struct rte_ring *ring) {struct rte_mbuf *pkts[BURST_SIZE ]; -unsigned int avail, n; +unsigned int n, avail;static unsigned int empty_count; ssize_t written;app/dumpcap/main.c +1
-2- n =rte_ring_sc_dequeue_burst (r, (void **) pkts,BURST_SIZE , - &avail); + n = rte_ring_sc_dequeue_burst(ring, (void **)pkts, BURST_SIZE,&avail); if (n == 0) { /* don't consume endless amounts of cpu if idle */ if (empty_count < SLEEP_THRESHOLD)app/dumpcap/main.c +13
-3@@ -948,11 +1211,18 @@ static int process_ring(dumpcap_out_t out, struct rte_ring *r) usleep(10);return 0 ; } - empty_count = (avail ==0 ); +remove_vlan_offload (pkts, n); + +if (filtering) { + n =filter_packets (pkts, n); +if (n ==0 ) +return 0 ; + } +if (use_pcapng) - written =rte_pcapng_write_packets (out.pcapng, pkts, n); + written =pcapng_write_packets (out.pcapng, pkts, n);else written =pcap_write_packets (out.dumper, pkts, n);@@ -971,15 +1241,18 @@ static int process_ring(dumpcap_out_t out, struct rte_ring *r)int main (int argc,char **argv) { -struct rte_ring *r;struct rte_mempool *mp;struct sigaction action = { .sa_flags =SA_RESTART , .sa_handler = signal_handler, };struct sigaction origaction; +struct rte_ring *ring =NULL ; +char vdev_name[RTE_DEV_NAME_MAX_LEN ]; +uint16_t mirror_port =UINT16_MAX ;dumpcap_out_t out;char *p; +int ret; p =strrchr (argv[0 ],'/' );if (p == NULL)app/dumpcap/main.c +12
-3@@ -1018,12 +1291,21 @@ int main(int argc, char **argv)exit (0 ); } - r =create_ring (); mp =create_mempool (); + ring =create_ring_dev (vdev_name, &mirror_port); out =create_output (); + ret =enable_mirror (mirror_port, mp); +if (ret <0 ) + goto cleanup; + + ret =setup_mbuf (); +if (ret <0 ) + goto cleanup; + +show_capturing (ret); + start_time =time (NULL ); -enable_pdump (r, mp);if (!quiet) {fprintf (stderr,"Packets captured: " );@@ -1031,7 +1313,7 @@ int main(int argc, char **argv) }while (!rte_atomic_load_explicit (&quit_signal, rte_memory_order_relaxed)) { -if (process_ring (out, r) <0 ) { +if (process_ring (out, ring) <0 ) {fprintf (stderr,"pcapng file write failed; %s\n" ,strerror (errno));break;app/dumpcap/main.c +9
-5@@ -1048,20 +1330,24 @@ int main(int argc, char **argv)break ; } -disable_primary_monitor (); -if (rte_eal_primary_proc_alive (NULL ))report_packet_stats (out); +cleanup: +disable_primary_monitor (); +if (use_pcapng)rte_pcapng_close (out.pcapng);else pcap_dump_close (out.dumper); -cleanup_pdump_resources (); +if (rte_eal_primary_proc_alive (NULL )) { +disable_mirror_ports (mirror_port); -rte_ring_free (r); -rte_mempool_free (mp); +rte_eal_hotplug_remove ("vdev" , vdev_name); +rte_ring_free (ring); +rte_mempool_free (mp); + }return rte_eal_cleanup () ?EXIT_FAILURE :0 ; }app/dumpcap/meson.build +0
-0@@ -6,12 +6,6 @@ if not dpdk_conf.has('RTE_HAS_LIBPCAP') reason = 'missing dependency, "libpcap"'endif
app/dumpcap/meson.build +0
-6-if is_windows - build = false - reason = 'not supported on Windows' - subdir_done() -endif -
ext_deps+=pcap_dep
sources = files('main.c')app/dumpcap/meson.build +1
-1-deps += ['ethdev', 'pdump', 'pcapng', 'bpf'] +deps += ['net_ring', 'ethdev', 'pcapng' ]Signature · 1 line
2.47.2
Re: [PATCH v6 12/13] app/dumpcap: use port mirror instead of pdump
In reply to Ivan MalovQuoted 7 lines · On Wed, 23 Jul 2025 07:16:07 +0400 (+04) Ivan Malov…
app/dumpcap/main.c pcap_write_packets(pcap_dumper_t *dumper, · line 1161
Quoted 3 lines
app/dumpcap/main.c +3
-0+/* overlay new header */ + nh = (struct rte_ether_hdr *) +rte_pktmbuf_prepend (m,sizeof (struct rte_vlan_hdr ));Prepend? But what if this is an indirect mbuf. Is it OK? Just asking.
Thank you.
Dumpcap doesn't use indirect for reasons mentioned in earlier mail.
PATCH v6 13/13 pdump: mark API and application as deprecated
In reply to Stephen HemmingerWhen the pdump application is run print a warning. Add release note about deprecation and mark the API's as deprecated.
--- app/pdump/main.c | 3 +++ app/pdump/meson.build | 1 + app/test-pmd/meson.build | 1 + app/test/meson.build | 6 +++++- doc/guides/howto/packet_capture_framework.rst | 15 +++++++++------ doc/guides/nics/bnxt.rst | 2 +- doc/guides/prog_guide/ethdev/index.rst | 1 + doc/guides/prog_guide/pdump_lib.rst | 4 ++++ doc/guides/rel_notes/deprecation.rst | 3 +++ doc/guides/tools/pdump.rst | 2 ++ lib/pdump/rte_pdump.h | 12 +++++++++--- 11 files changed, 39 insertions(+), 11 deletions(-)
app/pdump/main.c +3 -0
@@ -986,6 +986,9 @@ main(int argc, char **argv)char mp_flag[] ="--proc-type=secondary" ;char *argp[argc +2 ]; + +fprintf (stderr,"%s: is deprecated use dpdk-dumpcap instead\n" , argv[0 ]); +/* catch ctrl-c so we can cleanup on exit */ sigemptyset (&action.sa_mask);sigaction (SIGTERM , &action,NULL );
app/pdump/meson.build +1 -0
@@ -11,3 +11,4 @@ sources = files('main.c') deps += ['ethdev', 'kvargs', 'pdump'] cflags += no_wvla_cflag +cflags += '-Wno-deprecated-declarations'
app/test-pmd/meson.build +1 -0
@@ -60,6 +60,7 @@ if dpdk_conf.has('RTE_LIB_METRICS') endif if dpdk_conf.has('RTE_LIB_PDUMP') deps += 'pdump' + cflags += '-Wno-deprecated-declarations' endif if dpdk_conf.has('RTE_NET_BNXT') deps += 'net_bnxt'
app/test/meson.build +5 -1
@@ -138,7 +138,6 @@ source_file_deps = { 'test_net_ip6.c': ['net'], 'test_pcapng.c': ['ethdev', 'net', 'pcapng', 'bus_vdev'], 'test_pdcp.c': ['eventdev', 'pdcp', 'net', 'timer', 'security'], - 'test_pdump.c': ['pdump'] + sample_packet_forward_deps, 'test_per_lcore.c': [], 'test_pflock.c': [], 'test_pie.c': ['sched'],
@@ -217,6 +216,11 @@ source_file_ext_deps = { 'test_pcapng.c': ['pcap'], } +if dpdk_conf.has('RTE_LIB_PDUMP') + source_file_deps += { 'test_pdump.c': ['pdump'] + sample_packet_forward_deps, } + cflags += '-Wno-deprecated-declarations' +endif + def_lib = get_option('default_library') foreach f, f_deps : source_file_deps has_deps = true
doc/guides/howto/packet_capture_framework.rst +9 -6
@@ -10,11 +10,11 @@ for users of DPDK who want to know more about the Packet Capture feature and for those who want to monitor traffic on DPDK-controlled devices. The DPDK packet capture framework was introduced in DPDK v16.07 -and enhanced in 21.11. +and enhanced in 21.11, and deprecated in 25.11. It is superseded +by the new port mirroring facility of ethdev. + The DPDK packet capture framework consists of the libraries -for collecting packets ``librte_pdump`` -and writing packets to a file ``librte_pcapng``. -There are two sample applications: ``dpdk-dumpcap`` and older ``dpdk-pdump``. +for collecting packets ``librte_pdump`` and an application ``dpdk-pdump``. Introduction ------------
@@ -49,10 +49,13 @@ and then to the Pcapng file. Some things to note: -* All tools using ``librte_pdump`` can only be used in conjunction with a primary +* The ``dpdk-dumpcap`` tool used the ethdev port mirror functionality + to transparently mirror packets to an internal ring device. + +* Older tools using ``librte_pdump`` can only be used in conjunction with a primary application which has the packet capture framework initialized already. In dpdk, only ``testpmd`` is modified to initialize packet capture framework, - other applications remain untouched. So, if the ``dpdk-dumpcap`` tool has to + other applications remain untouched. So, if the ``dpdk-pdump`` tool has to be used with any application other than the testpmd, the user needs to explicitly modify that application to call the packet capture framework initialization code. Refer to the ``app/test-pmd/testpmd.c`` code and look
doc/guides/nics/bnxt.rst +1 -1
@@ -723,7 +723,7 @@ Note that the applications cannot update the firmware using BNXT PMD. Multiple Processes ~~~~~~~~~~~~~~~~~~ -When two or more DPDK applications (e.g., testpmd and dpdk-pdump) share a single +When two or more DPDK applications (e.g., testpmd and dpdk-dumpcap) share a single instance of DPDK, the BNXT PMD supports a single primary application and one or more secondary applications. Note that the DPDK-layer (not the PMD) ensures there is only one primary application.
doc/guides/prog_guide/ethdev/index.rst +1 -0
@@ -10,6 +10,7 @@ Ethernet Device Library ethdev switch_representation flow_offload + port_mirroring traffic_metering_and_policing traffic_management qos_framework
doc/guides/prog_guide/pdump_lib.rst +4 -0
@@ -9,6 +9,10 @@ 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 pdump functionality will not work if secondary process sends and receives +packets. This is not easily fixable therefore this library is now deprecated +and replace by port mirroring functionality of ethdev. + The library uses a generic multi process channel to facilitate communication between primary and secondary process for enabling/disabling packet capture on ports.
doc/guides/rel_notes/deprecation.rst +3 -0
@@ -175,3 +175,6 @@ Deprecation Notices without relying on flow API. Currently there is no alternative API providing the same functionality as with ``repr_matching_en`` set to 0. + +* pdump: The pdump API and application have been deprecated and will + be removed in a later release.
doc/guides/tools/pdump.rst +2 -0
@@ -10,6 +10,8 @@ The ``dpdk-pdump`` tool is a Data Plane Development Kit (DPDK) tool that runs as a DPDK secondary process and is capable of enabling packet capture on dpdk ports. .. Note:: + * The ``dpdk-pdump`` is deprecated, use ``dpdk-dumpcap`` instead. + * The ``dpdk-pdump`` tool can only be used in conjunction with a primary application which has the packet capture framework initialized already. In dpdk, only the ``testpmd`` is modified to initialize packet capture
lib/pdump/rte_pdump.h +9 -3
@@ -39,6 +39,7 @@ enum {* @return * 0 on success, -1 on error */ +__rte_deprecated intrte_pdump_init (void );
@@ -50,6 +51,7 @@ rte_pdump_init(void);* @return * 0 on success, -1 on error */ +__rte_deprecated intrte_pdump_uninit (void );
@@ -75,7 +77,7 @@ rte_pdump_uninit(void);* @return * 0 on success, -1 on error, rte_errno is set accordingly. */ - +__rte_deprecated int rte_pdump_enable(uint16_t port, uint16_t queue, uint32_t flags, struct rte_ring *ring,
@@ -106,6 +108,7 @@ rte_pdump_enable(uint16_t port, uint16_t queue, uint32_t flags,* @return * 0 on success, -1 on error, rte_errno is set accordingly. */ +__rte_deprecated int rte_pdump_enable_bpf(uint16_t port_id, uint16_t queue, uint32_t flags, uint32_t snaplen,
@@ -129,7 +132,7 @@ rte_pdump_enable_bpf(uint16_t port_id, uint16_t queue,* @return * 0 on success, -1 on error, rte_errno is set accordingly. */ - +__rte_deprecated intrte_pdump_disable (uint16_t port,uint16_t queue,uint32_t flags);
@@ -156,7 +159,7 @@ rte_pdump_disable(uint16_t port, uint16_t queue, uint32_t flags);* @return * 0 on success, -1 on error, rte_errno is set accordingly. */ - +__rte_deprecated int rte_pdump_enable_by_deviceid(char *device_id, uint16_t queue, uint32_t flags,
@@ -189,6 +192,7 @@ rte_pdump_enable_by_deviceid(char *device_id, uint16_t queue,* @return * 0 on success, -1 on error, rte_errno is set accordingly. */ +__rte_deprecated int rte_pdump_enable_bpf_by_deviceid(const char *device_id, uint16_t queue, uint32_t flags, uint32_t snaplen,
@@ -215,6 +219,7 @@ rte_pdump_enable_bpf_by_deviceid(const char *device_id, uint16_t queue,* @return * 0 on success, -1 on error, rte_errno is set accordingly. */ +__rte_deprecated intrte_pdump_disable_by_deviceid (char *device_id,uint16_t queue,uint32_t flags);
@@ -243,6 +248,7 @@ struct rte_pdump_stats {* @return * Zero if successful. -1 on error and rte_errno is set. */ +__rte_deprecated intrte_pdump_stats (uint16_t port_id,struct rte_pdump_stats *stats);
Signature · 1 line
2.47.2
v7 cover Port mirroring for packet capture
In reply to Stephen HemmingerThis is a rework of how packet capture is done in DPDK.
The existing mechanism using callbacks has a number of problems:
- can't work when packets are sent and received in secondary process because callbacks only function in the primary process
- requires "opt-in" from application
The new mechanism builds on the concept of port mirroring used in Linux/FreeBSD and also router vendors (SPAN ports).
See: https://en.wikipedia.org/wiki/Port_mirroring for a general description.
The implementation uses two new ethdev API's:
one to add a port mirror, and one to remove it.
The internals of dumpcap are redone but the program command syntax is unchanged (no doc change needed). Using the new mirror mechanism, the dumpcap program creates a port using ring PMD and then directs a port mirror to that new ring PMD instance. Then the packets are extracted from the ring. If capturing on multiple devices, they all get mirrored to the same ring PMD.
The dumpcap program needs to be able to start the ring PMD it created but the existing ethdev API is broken when used from secondary process. One of the patches fixes that, it was also reported previously in Bugzilla.
The mirror API has a restriction that the port being mirrored to must allow lock free transmit. This is because both Rx and Tx as well as multiple queues need to go over the same transmit queue. Although it might be possible to have some complex mapping between multiple ports/queues being mirrored to multiple transmit queues, that gets to be a lot of overhead in API's and implementation. Fixing the ring and null PMD to allow lockless transmit is good enough.
Added tests for the mirror features.
The performance has not been measured but the overhead of checking for mirror port is no more that the overhead of looking at the callback list.
TODO items:
- need release note and documentation
- more through testing on real hardware
- figure out deprecation for pdump
v7 - review feedback
- add statistics
- remove deprecation of pdump
Stephen Hemminger (12):
ethdev: allow start/stop from secondary process
ethdev: make sure all necessary headers included
test: add test for hotplug and secondary process operations net/ring: allow lockfree transmit if ring supports it net/ring: add new devarg to create vdev from existing ring
mbuf: add dynamic flag for use by port mirroring
ethdev: add port mirroring feature
test: add tests for ethdev mirror
pcapng: split packet copy from header insertion
pcapng: make queue optional
app/testpmd: support for port mirroring app/dumpcap: use port mirror instead of pdump
app/dumpcap/main.c | 471 ++++++++++++++++---- app/dumpcap/meson.build | 3 +- app/test-pmd/cmdline.c | 13 + app/test-pmd/cmdline_mirror.c | 194 ++++++++ app/test-pmd/cmdline_mirror.h | 13 + app/test-pmd/meson.build | 1 + app/test/meson.build | 1 + app/test/test_ethdev_mirror.c | 325 ++++++++++++++ app/test/test_mp_secondary.c | 51 ++- config/rte_config.h | 1 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 15 + drivers/net/ring/rte_eth_ring.c | 49 ++ lib/ethdev/ethdev_driver.c | 12 +- lib/ethdev/ethdev_driver.h | 6 + lib/ethdev/ethdev_private.c | 141 ++++++ lib/ethdev/ethdev_private.h | 29 ++ lib/ethdev/ethdev_trace.h | 17 + lib/ethdev/ethdev_trace_points.c | 6 + lib/ethdev/meson.build | 2 + lib/ethdev/rte_ethdev.c | 99 ++-- lib/ethdev/rte_ethdev.h | 23 +- lib/ethdev/rte_ethdev_core.h | 12 +- lib/ethdev/rte_mirror.c | 435 ++++++++++++++++++ lib/ethdev/rte_mirror.h | 145 ++++++ lib/mbuf/rte_mbuf_dyn.h | 9 + lib/pcapng/rte_pcapng.c | 179 ++++---- lib/pcapng/rte_pcapng.h | 27 +- 27 files changed, 2054 insertions(+), 225 deletions(-) create mode 100644 app/test-pmd/cmdline_mirror.c create mode 100644 app/test-pmd/cmdline_mirror.h create mode 100644 app/test/test_ethdev_mirror.c create mode 100644 lib/ethdev/rte_mirror.c create mode 100644 lib/ethdev/rte_mirror.h
Signature · 1 line
2.47.2
PATCH v7 1/12 ethdev: allow start/stop from secondary process
Before this patch if secondary process called start/stop it would only impact the secondary process, the ethdev on the primary process was not started.
With this patch, when start/stop is called from secondary, it calls the primary and does the operation there. The design is generic, and we can later add queue and other operations as needed.
Bugzilla ID: 73
--- lib/ethdev/ethdev_driver.c | 12 ++++- lib/ethdev/ethdev_private.c | 92 +++++++++++++++++++++++++++++++++++++ lib/ethdev/ethdev_private.h | 26 +++++++++++ lib/ethdev/rte_ethdev.c | 82 +++++++++++++++++++-------------- 4 files changed, 176 insertions(+), 36 deletions(-)
lib/ethdev/ethdev_driver.c +11 -1
@@ -114,6 +114,15 @@ rte_eth_dev_allocate(const char *name) goto unlock; } +/* When first port is created, start the multi-process request handler */ +if (eth_dev_shared_data->allocated_ports ==0 && +rte_mp_action_register (ETHDEV_MP , ethdev_server) && + rte_errno !=ENOTSUP ) { +RTE_ETHDEV_LOG_LINE (ERR , +"Could not start %s service" ,ETHDEV_MP ); + goto unlock; + } + eth_dev =eth_dev_get (port_id); eth_dev->flow_fp_ops = &rte_flow_fp_default_ops;strlcpy (eth_dev->data->name, name,sizeof (eth_dev->data->name));
@@ -282,7 +291,8 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)memset (eth_dev->data,0 ,sizeof (struct rte_eth_dev_data )); eth_dev->data =NULL ; - eth_dev_shared_data->allocated_ports--; +if (--eth_dev_shared_data->allocated_ports ==0 ) +rte_mp_action_unregister (ETHDEV_MP );eth_dev_shared_data_release (); }
lib/ethdev/ethdev_private.c +92 -0
101 lines not on this page · raw message
lib/ethdev/ethdev_private.h +26 -0
@@ -79,4 +79,30 @@ void eth_dev_txq_release(struct rte_eth_dev *dev, uint16_t qid);int eth_dev_rx_queue_config (struct rte_eth_dev *dev,uint16_t nb_queues);int eth_dev_tx_queue_config (struct rte_eth_dev *dev,uint16_t nb_queues); +/* Used to allow start/stop from secondary */ +#define ETHDEV_MP "mp_ethdev" + +enum ethdev_mp_operation { +ETH_REQ_START , +ETH_REQ_STOP , +}; + +struct ethdev_mp_request { +uint16_t operation; +uint16_t port_id; +uint32_t reserved; + +uint8_t config[];/* operation specific */ +}; + +struct ethdev_mp_response { +uint16_t res_op; +uint16_t port_id; +int32_t err_value; +}; + +int ethdev_server (const struct rte_mp_msg *mp_msg,const void *peer); +int ethdev_request (uint16_t port_id,enum ethdev_mp_operation op, +const void *buf,size_t buf_len); +#endif /* _ETH_PRIVATE_H_ */
lib/ethdev/rte_ethdev.c +47 -35
108 lines not on this page · raw message
Signature · 1 line
2.47.2
PATCH v7 2/12 ethdev: make sure all necessary headers included
In reply to Stephen HemmingerBest not to depend on other EAL headers to include stuff. Some of the later changes had build failures on some platforms.
--- lib/ethdev/ethdev_private.c | 9 +++++++++ 1 file changed, 9 insertions(+)
lib/ethdev/ethdev_private.c +9 -0
@@ -3,9 +3,18 @@*/ #include <assert.h> +#include <errno.h> +#include <inttypes.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <time.h> #include <eal_export.h> #include <rte_debug.h> +#include <rte_eal.h> +#include <rte_lcore.h> +#include <rte_stdatomic.h> #include "rte_ethdev.h" #include "rte_ethdev_trace_fp.h"
Signature · 1 line
2.47.2
PATCH v7 3/12 test: add test for hotplug and secondary process operations
In reply to Stephen HemmingerUse null device to exercise ethdev start/stop in secondary process.
--- app/test/test_mp_secondary.c | 51 +++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-)
app/test/test_mp_secondary.c +48 -3
@@ -15,6 +15,9 @@#include <string.h> #include <unistd.h> +#include <rte_ethdev.h> +#include <rte_bus_vdev.h> +#ifdef RTE_EXEC_ENV_WINDOWS int test_mp_secondary (void )
@@ -204,6 +207,44 @@ run_object_creation_tests(void)return 0 ; } +static int +run_ethdev_tests (void ) +{ +static const char vdev_name[] ="net_null" ; +struct rte_eth_conf dev_conf = {0 }; +uint16_t port; +int ret; + +printf ("### Testing hotplug and ethdev start/stop\n" ); + +/* use hotplug to make a null vdev */ + ret =rte_eal_hotplug_add ("vdev" , vdev_name,"" ); +TEST_ASSERT (ret ==0 ,"Hotplug add of '%s' failed" , vdev_name); + +printf ("# Checked hotplug_add OK\n" ); + + ret =rte_eth_dev_get_port_by_name (vdev_name, &port); +TEST_ASSERT (ret ==0 ,"Lookup vdev '%s' failed" , vdev_name); + + ret =rte_eth_dev_configure (port,1 ,1 , &dev_conf); +TEST_ASSERT (ret ==0 ,"Configure port %u failed" , port); + + ret =rte_eth_dev_start (port); +TEST_ASSERT (ret ==0 ,"Start port %u failed" , port); + +printf ("# Checked rte_eth_dev_start\n" ); + + ret =rte_eth_dev_stop (port); +TEST_ASSERT (ret ==0 ,"Stop port %u failed" , port); + +printf ("# Checked rte_eth_dev_stop\n" ); + +rte_eal_hotplug_remove ("vdev" , vdev_name); + +printf ("# Checked hotplug_remove OK\n" ); +return 0 ; +} +/* if called in a primary process, just spawns off a secondary process to * run validation tests - which brings us right back here again... * if called in a secondary process, this runs a series of API tests to check
@@ -212,15 +253,19 @@ run_object_creation_tests(void)int test_mp_secondary (void ) { -if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) { +int ret; + +if (rte_eal_process_type () ==RTE_PROC_PRIMARY )return run_secondary_instances (); - }printf ("IN SECONDARY PROCESS\n" ); + ret =run_ethdev_tests (); +if (ret !=0 ) +return ret;return run_object_creation_tests (); }#endif /* !RTE_EXEC_ENV_WINDOWS */ -REGISTER_FAST_TEST (multiprocess_autotest, false, false, test_mp_secondary); +REGISTER_FAST_TEST (multiprocess_autotest, true, true, test_mp_secondary);
Signature · 1 line
2.47.2
PATCH v7 4/12 net/ring: allow lockfree transmit if ring supports it
In reply to Stephen HemmingerNeed to be able have multiple threads all using same transmit queue when using SPAN.
--- drivers/net/ring/rte_eth_ring.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/net/ring/rte_eth_ring.c +17 -0
@@ -177,6 +177,19 @@ eth_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,return 0 ; } +static bool +eth_tx_queue_lockfree (const struct pmd_internals *internals) +{ +unsigned int i; + +for (i =0 ; i < internals->max_tx_queues; i++) { +const struct ring_queue *r = &internals->tx_ring_queues[i]; + +if (r->rng->flags &RING_F_SP_ENQ ) +return false; + } +return true; +} static int eth_dev_info(struct rte_eth_dev *dev,
@@ -189,6 +202,10 @@ eth_dev_info(struct rte_eth_dev *dev, dev_info->max_rx_queues = (uint16_t )internals->max_rx_queues; dev_info->rx_offload_capa =RTE_ETH_RX_OFFLOAD_SCATTER ; dev_info->tx_offload_capa =RTE_ETH_TX_OFFLOAD_MULTI_SEGS ; + +if (eth_tx_queue_lockfree (internals)) + dev_info->tx_offload_capa |=RTE_ETH_TX_OFFLOAD_MT_LOCKFREE ; + dev_info->max_tx_queues = (uint16_t )internals->max_tx_queues; dev_info->min_rx_bufsize =0 ;
Signature · 1 line
2.47.2
PATCH v7 5/12 net/ring: add new devarg to create vdev from existing ring
In reply to Stephen HemmingerNeed ability to allow process like dumpcap to make a ring ethdev with a pre-existing ring. Do this via devargs so it can work with hotplug.
It looked like the API rte_eth_from_ring() would work for this, but it doesn't do the right thing. That API makes new vdev but names the ring based on the parameter.
--- drivers/net/ring/rte_eth_ring.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
drivers/net/ring/rte_eth_ring.c +32 -0
@@ -23,9 +23,12 @@#define ETH_RING_INTERNAL_ARG "internal"#define ETH_RING_INTERNAL_ARG_MAX_LEN 19/* "0x..16chars..\0" */ +#define ETH_RING_RING_ARG "ring" +static const char *valid_arguments[] = {ETH_RING_NUMA_NODE_ACTION_ARG ,ETH_RING_INTERNAL_ARG , +ETH_RING_RING_ARG ,NULL };
@@ -693,6 +696,20 @@ parse_internal_args(const char *key __rte_unused, const char *value,return 0 ; } +static int +parse_ring_arg(const char *key __rte_unused, const char *value, void *data) +{ +struct rte_ring **rp = data; + + *rp =rte_ring_lookup (value); +if (*rp ==NULL ) { +PMD_LOG (ERR ,"ring '%s' not found" , value); +return -1 ; + } + +return 0 ; +} +static int rte_pmd_ring_probe (struct rte_vdev_device *dev) {
@@ -770,6 +787,20 @@ rte_pmd_ring_probe(struct rte_vdev_device *dev) ð_dev);if (ret >=0 ) ret =0 ; + }else if (rte_kvargs_count (kvlist,ETH_RING_RING_ARG ) ==1 ) { +struct rte_ring *rxtx[1 ] = { }; + + ret =rte_kvargs_process (kvlist,ETH_RING_RING_ARG , parse_ring_arg, rxtx); +if (ret <0 ) + goto out_free; + +/* Note: rte_eth_from_ring() does not do what is expected here! */ + ret =do_eth_dev_ring_create (name, dev, rxtx,1 , rxtx,1 , +rte_socket_id (),DEV_ATTACH , ð_dev); +if (ret <0 ) + goto out_free; + + ret =0 ; }else { ret =rte_kvargs_count (kvlist,ETH_RING_NUMA_NODE_ACTION_ARG ); info = rte_zmalloc("struct node_action_list",
@@ -843,4 +874,5 @@ static struct rte_vdev_driver pmd_ring_drv = {RTE_PMD_REGISTER_VDEV (net_ring, pmd_ring_drv);RTE_PMD_REGISTER_ALIAS (net_ring, eth_ring);RTE_PMD_REGISTER_PARAM_STRING (net_ring, +ETH_RING_RING_ARG "=<string> " ETH_RING_NUMA_NODE_ACTION_ARG "=name:node:action(ATTACH|CREATE)" );
Signature · 1 line
2.47.2
PATCH v7 6/12 mbuf: add dynamic flag for use by port mirroring
In reply to Stephen HemmingerAdd names for new port mirror fields.
--- lib/mbuf/rte_mbuf_dyn.h | 9 +++++++++ 1 file changed, 9 insertions(+)
lib/mbuf/rte_mbuf_dyn.h +9 -0
@@ -327,6 +327,15 @@ int rte_mbuf_dyn_tx_timestamp_register(int *field_offset, uint64_t *tx_flag);#define RTE_MBUF_DYNFIELD_IP_REASSEMBLY_NAME "rte_dynfield_ip_reassembly"#define RTE_MBUF_DYNFLAG_IP_REASSEMBLY_INCOMPLETE_NAME "rte_dynflag_ip_reassembly_incomplete" +/** +* The ethdev port mirror needs some extra packet information that +* includes information about the packet before it was copied to the mirror. +*/ +#define RTE_MBUF_DYNFIELD_MIRROR_ORIGIN "rte_dynfield_mirror_origin" +#define RTE_MBUF_DYNFLAG_MIRROR_ORIGIN "rte_dynflag_mirror_origin" +#define RTE_MBUF_DYNFLAG_MIRROR_INGRESS "rte_dynflag_mirror_ingress" +#define RTE_MBUF_DYNFLAG_MIRROR_EGRESS "rte_dynflag_mirror_egress" + #ifdef __cplusplus }#endif
Signature · 1 line
2.47.2