diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/tcpdump/pdump.c | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/tools/tcpdump/pdump.c b/tools/tcpdump/pdump.c index bf3e83c..787a20d 100644 --- a/tools/tcpdump/pdump.c +++ b/tools/tcpdump/pdump.c @@ -65,6 +65,7 @@ #include <rte_pdump.h> #include <rte_ring.h> #include <rte_time.h> +#include <rte_version.h> #include <sc_pdump.h> #include <time.h> @@ -97,7 +98,7 @@ #define NUM_VDEVS 2 /* true if x is a power of 2 */ -#define POWEROF2(x) ((((x)-1) & (x)) == 0) +#define POWEROF2(x) ((((x) - 1) & (x)) == 0) #define METADATA_MAX_SIZE 256 @@ -922,14 +923,39 @@ static int pcapng_add_interface(struct pdump_tuples * pt) static void write_interface_info(void) { + /* Save PCI devices */ + uint16_t port_id = 0; + RTE_ETH_FOREACH_DEV(port_id) + { + /* The list if ports in pcapng needs to be contiguous */ + port_index[port_id] = interface_index++; + } + +#if RTE_VERSION >= RTE_VERSION_NUM(23, 11, 0, 0) + // In dpdk21-11, the rte_pcapng_fdopen() function automatically calls pcapng_add_interface + // In dpdk-23, you need to manually call rte_pcapng_add_interface() + port_id = 0; + RTE_ETH_FOREACH_DEV(port_id) + { + /* The list if ports in pcapng needs to be contiguous */ + if (rte_pcapng_add_interface(pcapng, port_id, NULL, NULL, NULL) < 0) + { + rte_exit(EXIT_FAILURE, "port id:%u, write interface info err.\n", port_id); + } + } +#endif + for (int i = 0; i < num_tuples; i++) { struct pdump_tuples * pt = &pdump_t[i]; - if (pt->drv_type != MR_DEV_DRV_TYPE_SHMDEV) - continue; - if (pcapng_add_interface(pt) < 0) - rte_exit(EXIT_FAILURE, "Phydev:%s, write interface info err.\n", pt->dev_symbol); - port_index[pt->port_id] = interface_index++; + if (pt->drv_type == MR_DEV_DRV_TYPE_SHMDEV) + { + if (pcapng_add_interface(pt) < 0) + { + rte_exit(EXIT_FAILURE, "Phydev:%s, write interface info err.\n", pt->dev_symbol); + } + port_index[pt->port_id] = interface_index++; + } } } @@ -1120,14 +1146,6 @@ static inline void create_pcap_dumper() rte_exit(EXIT_FAILURE, "Rte bpf convert failed\n"); } - /* Save PCI devices */ - uint16_t port_id = 0; - RTE_ETH_FOREACH_DEV(port_id) - { - /* The list if ports in pcapng needs to be contiguous */ - port_index[port_id] = interface_index++; - } - return; } @@ -1191,12 +1209,12 @@ int main(int argc, char ** argv) /* create dumpfile writer */ create_pcap_dumper(); - /* device enable */ - enable_pdump(); - /* write interface info */ write_interface_info(); + /* device enable */ + enable_pdump(); + /* dump packets */ dump_packets(); |
