Skip to content

Commit eeb6cad

Browse files
shemmingerdavid-marchand
authored andcommitted
app/dumpcap: add file-prefix option
When using dumpcap in container environment or with multiple DPDK processes, it is useful to be able to specify file prefix. This version only accepts the long format option used by other commands. If no prefix is specified then the default is used. Suggested-by: Arshdeep Kaur <arshdeep.kaur@intel.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Acked-by: Arshdeep Kaur <arshdeep.kaur@intel.com>
1 parent 7f3623a commit eeb6cad

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

app/dumpcap/main.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ static char *output_name;
6161
static const char *filter_str;
6262
static unsigned int ring_size = 2048;
6363
static const char *capture_comment;
64+
static const char *file_prefix;
6465
static uint32_t snaplen = RTE_MBUF_DEFAULT_BUF_SIZE;
6566
static bool dump_bpf;
6667
static bool show_interfaces;
@@ -126,6 +127,7 @@ static void usage(void)
126127
" add a capture comment to the output file\n"
127128
"\n"
128129
"Miscellaneous:\n"
130+
" --file-prefix=<prefix> prefix to use for multi-process\n"
129131
" -q don't report packet capture counts\n"
130132
" -v, --version print version information and exit\n"
131133
" -h, --help display this help and exit\n"
@@ -316,6 +318,7 @@ static void parse_opts(int argc, char **argv)
316318
static const struct option long_options[] = {
317319
{ "autostop", required_argument, NULL, 'a' },
318320
{ "capture-comment", required_argument, NULL, 0 },
321+
{ "file-prefix", required_argument, NULL, 0 },
319322
{ "help", no_argument, NULL, 'h' },
320323
{ "interface", required_argument, NULL, 'i' },
321324
{ "list-interfaces", no_argument, NULL, 'D' },
@@ -336,11 +339,13 @@ static void parse_opts(int argc, char **argv)
336339

337340
switch (c) {
338341
case 0:
339-
switch (option_index) {
340-
case 0:
342+
if (!strcmp(long_options[option_index].name,
343+
"capture-comment")) {
341344
capture_comment = optarg;
342-
break;
343-
default:
345+
} else if (!strcmp(long_options[option_index].name,
346+
"file-prefix")) {
347+
file_prefix = optarg;
348+
} else {
344349
usage();
345350
exit(1);
346351
}
@@ -519,12 +524,14 @@ static void dpdk_init(void)
519524
static const char * const args[] = {
520525
"dumpcap", "--proc-type", "secondary",
521526
"--log-level", "notice"
522-
523527
};
524-
const int eal_argc = RTE_DIM(args);
528+
int eal_argc = RTE_DIM(args);
525529
char **eal_argv;
526530
unsigned int i;
527531

532+
if (file_prefix != NULL)
533+
eal_argc += 2;
534+
528535
/* DPDK API requires mutable versions of command line arguments. */
529536
eal_argv = calloc(eal_argc + 1, sizeof(char *));
530537
if (eal_argv == NULL)
@@ -534,6 +541,11 @@ static void dpdk_init(void)
534541
for (i = 1; i < RTE_DIM(args); i++)
535542
eal_argv[i] = strdup(args[i]);
536543

544+
if (file_prefix != NULL) {
545+
eal_argv[i++] = strdup("--file-prefix");
546+
eal_argv[i++] = strdup(file_prefix);
547+
}
548+
537549
if (rte_eal_init(eal_argc, eal_argv) < 0)
538550
rte_exit(EXIT_FAILURE, "EAL init failed: is primary process running?\n");
539551
}

0 commit comments

Comments
 (0)