dumpcap: small enhancements
cover dumpcap: small enhancements
Cover a few more options and statistics mode to be add more compatiablity with wireshark dumpcap.
Stephen Hemminger (3):
dumpcap: add --interface to help
dumpcap: support temp-dir option
dumpcap: add support statistics mode
app/dumpcap/main.c | 67 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 8 deletions(-)
Signature · 1 line
2.39.0
PATCH 1/3 dumpcap: add --interface to help
Make the help more complete, add all supported options.
--- app/dumpcap/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
app/dumpcap/main.c +2 -1
@@ -102,7 +102,8 @@ static void usage(void) {printf ("Usage: %s [options] ...\n\n" , progname);printf ("Capture Interface:\n" -" -i <interface> name or port index of interface\n" +" -i <interface>, --interface <interface>\n" +" name or port index of interface\n" " -f <capture filter> packet filter in libpcap filter syntax\n" ); printf(" -s <snaplen>, --snapshot-length <snaplen>\n" " packet snapshot length (def: %u)\n",
Signature · 1 line
2.39.0
PATCH 2/3 dumpcap: support temp-dir option
In reply to Stephen HemmingerOption for putting output files in different directory. Same syntax as wireshark.
--- app/dumpcap/main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
app/dumpcap/main.c +8 -1
@@ -58,6 +58,7 @@ static bool quiet;static bool promiscuous_mode = true;static bool use_pcapng = true;static char *output_name; +static const char *tmp_dir ="/tmp" ;static const char *filter_str;static unsigned int ring_size =2048 ;static const char *capture_comment;
@@ -126,6 +127,8 @@ static void usage(void)" -P use libpcap format instead of pcapng\n" " --capture-comment <comment>\n" " add a capture comment to the output file\n" +" --temp-dir <directory> write temporary files to this directory\n" +" (default: /tmp)\n" "\n" "Miscellaneous:\n" " --file-prefix=<prefix> prefix to use for multi-process\n"
@@ -327,6 +330,7 @@ static void parse_opts(int argc, char **argv) { "output-file", required_argument, NULL, 'w' }, { "ring-buffer", required_argument, NULL, 'b' }, { "snapshot-length", required_argument, NULL, 's' }, + { "temp-dir", required_argument, NULL, 0 }, { "version", no_argument, NULL, 'v' }, { NULL }, };
@@ -346,6 +350,9 @@ static void parse_opts(int argc, char **argv) }else if (!strcmp (long_options[option_index].name,"file-prefix" )) { file_prefix = optarg; + }else if (!strcmp (long_options[option_index].name, +"temp-dir" )) { + tmp_dir = optarg; }else {usage ();exit (1 );
@@ -642,7 +649,7 @@ static dumpcap_out_t create_output(void)strftime (ts,sizeof (ts),"%Y%m%d%H%M%S" , tm);snprintf (tmp_path,sizeof (tmp_path), -"/tmp/%s_%u_%s_%s.%s" , +"%s/%s_%u_%s_%s.%s" , tmp_dir, progname, intf->port, intf->name, ts, use_pcapng ?"pcapng" :"pcap" ); output_name = tmp_path;
Signature · 1 line
2.39.0
PATCH 3/3 dumpcap: add support statistics mode
In reply to Stephen HemmingerThis add new -S option which does the same thing as wireshark's dumpcap -S option.
It loops over all interfaces and prints the number of received and dropped packets. In this mode, actual packet capture is not done.
--- app/dumpcap/main.c | 55 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 6 deletions(-)
app/dumpcap/main.c +49 -6
@@ -66,6 +66,7 @@ static const char *file_prefix;static uint32_t snaplen =RTE_MBUF_DEFAULT_BUF_SIZE ;static bool dump_bpf;static bool show_interfaces; +static bool print_stats;static bool select_interfaces;const char *interface_arg;
@@ -113,6 +114,7 @@ static void usage(void)" don't capture in promiscuous mode\n" " -D, --list-interfaces print list of interfaces and exit\n" " -d print generated BPF code for capture filter\n" +" -S print statistics for each interface once per second\n" "\n" "Stop conditions:\n" " -c <packet count> stop after n packets (def: infinite)\n"
@@ -337,7 +339,7 @@ static void parse_opts(int argc, char **argv)int option_index, c;for (;;) { - c =getopt_long (argc, argv,"a:b:c:dDf:ghi:nN:pPqs:vw:" , + c =getopt_long (argc, argv,"a:b:c:dDf:ghi:nN:pPqSs:vw:" , long_options, &option_index);if (c ==-1 )break ;
@@ -406,6 +408,9 @@ static void parse_opts(int argc, char **argv)case 's' : snaplen =get_uint (optarg,"snap_len" ,0 );break ; +case 'S' : + print_stats = true; +break ;case 'w' : output_name = optarg;break ;
@@ -427,6 +432,39 @@ signal_handler(int sig_num __rte_unused)__atomic_store_n (&quit_signal, true, __ATOMIC_RELAXED); } + +/* Instead of capturing, it tracks interface statistics */ +static void statistics_loop (void ) +{ +struct rte_eth_stats stats; +char name[RTE_ETH_NAME_MAX_LEN ]; +uint16_t p; +int r; + +printf ("%-15s %10s %10s\n" , +"Interface" ,"Received" ,"Dropped" ); + +while (!__atomic_load_n (&quit_signal, __ATOMIC_RELAXED)) { +RTE_ETH_FOREACH_DEV (p) { +if (rte_eth_dev_get_name_by_port (p, name) <0 ) +continue ; + + r =rte_eth_stats_get (p, &stats); +if (r <0 ) { +fprintf (stderr, +"stats_get for port %u failed: %d (%s)\n" , + p, r,strerror (r)); +return ; + } + +printf ("%-15s %10" PRIu64" %10" PRIu64"\n" , + name, stats.ipackets, + stats.imissed + stats.ierrors + stats.rx_nombuf); + } +sleep (1 ); + } +} +/* Return the time since 1/1/1970 in nanoseconds */ static uint64_t create_timestamp (void ) {
@@ -834,6 +872,16 @@ int main(int argc, char **argv)if (TAILQ_EMPTY (&interfaces))set_default_interface (); +signal (SIGINT , signal_handler); +signal (SIGPIPE ,SIG_IGN ); + +enable_primary_monitor (); + +if (print_stats) { +statistics_loop (); +exit (0 ); + } + r =create_ring (); mp =create_mempool (); out =create_output ();
@@ -841,11 +889,6 @@ int main(int argc, char **argv) start_time =create_timestamp ();enable_pdump (r, mp); -signal (SIGINT , signal_handler); -signal (SIGPIPE ,SIG_IGN ); - -enable_primary_monitor (); -if (!quiet) {fprintf (stderr,"Packets captured: " );show_count (0 );
Signature · 1 line
2.39.0
Thomas Monjalon
AppliedQuoted 4 lines
Stephen Hemminger (3):
dumpcap: add --interface to help
dumpcap: support temp-dir option
dumpcap: add support statistics mode
Applied, thanks.