-#define PCAP_DEF_PKT_TO_CAPTURE (100)
-
- unformat_input_t _line_input, *line_input = &_line_input;
- dpdk_main_t *dm = &dpdk_main;
- u8 *filename;
- u8 *chroot_filename = 0;
- u32 max = 0;
- int enabled = 0;
- int errorFlag = 0;
- clib_error_t *error = 0;
-
- /* Get a line of input. */
- if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
-
- while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (line_input, "on"))
- {
- if (dm->tx_pcap_enable == 0)
- {
- enabled = 1;
- }
- else
- {
- vlib_cli_output (vm, "pcap tx capture already on...");
- errorFlag = 1;
- break;
- }
- }
- else if (unformat (line_input, "off"))
- {
- if (dm->tx_pcap_enable)
- {
- vlib_cli_output (vm, "captured %d pkts...",
- dm->pcap_main.n_packets_captured + 1);
- if (dm->pcap_main.n_packets_captured)
- {
- dm->pcap_main.n_packets_to_capture =
- dm->pcap_main.n_packets_captured;
- error = pcap_write (&dm->pcap_main);
- if (error)
- clib_error_report (error);
- else
- vlib_cli_output (vm, "saved to %s...", dm->pcap_filename);
- }
-
- dm->tx_pcap_enable = 0;
- }
- else
- {
- vlib_cli_output (vm, "pcap tx capture already off...");
- errorFlag = 1;
- break;
- }
- }
- else if (unformat (line_input, "max %d", &max))
- {
- if (dm->tx_pcap_enable)
- {
- vlib_cli_output (vm,
- "can't change max value while pcap tx capture active...");
- errorFlag = 1;
- break;
- }
- }
- else if (unformat (line_input, "intfc %U",
- unformat_vnet_sw_interface, dm->vnet_main,
- &dm->pcap_sw_if_index))
- ;
-
- else if (unformat (line_input, "intfc any"))
- {
- dm->pcap_sw_if_index = 0;
- }
- else if (unformat (line_input, "file %s", &filename))
- {
- if (dm->tx_pcap_enable)
- {
- vlib_cli_output (vm,
- "can't change file while pcap tx capture active...");
- errorFlag = 1;
- break;
- }
-
- /* Brain-police user path input */
- if (strstr ((char *) filename, "..")
- || index ((char *) filename, '/'))
- {
- vlib_cli_output (vm, "illegal characters in filename '%s'",
- filename);
- vlib_cli_output (vm,
- "Hint: Only filename, do not enter directory structure.");
- vec_free (filename);
- errorFlag = 1;
- break;
- }
-
- chroot_filename = format (0, "/tmp/%s%c", filename, 0);
- vec_free (filename);
- }
- else if (unformat (line_input, "status"))
- {
- if (dm->pcap_sw_if_index == 0)
- {
- vlib_cli_output (vm, "max is %d for any interface to file %s",
- dm->
- pcap_pkts_to_capture ? dm->pcap_pkts_to_capture
- : PCAP_DEF_PKT_TO_CAPTURE,
- dm->
- pcap_filename ? dm->pcap_filename : (u8 *)
- "/tmp/vpe.pcap");
- }
- else
- {
- vlib_cli_output (vm, "max is %d for interface %U to file %s",
- dm->
- pcap_pkts_to_capture ? dm->pcap_pkts_to_capture
- : PCAP_DEF_PKT_TO_CAPTURE,
- format_vnet_sw_if_index_name, dm->vnet_main,
- dm->pcap_sw_if_index,
- dm->
- pcap_filename ? dm->pcap_filename : (u8 *)
- "/tmp/vpe.pcap");
- }
-
- if (dm->tx_pcap_enable == 0)
- {
- vlib_cli_output (vm, "pcap tx capture is off...");
- }
- else
- {
- vlib_cli_output (vm, "pcap tx capture is on: %d of %d pkts...",
- dm->pcap_main.n_packets_captured,
- dm->pcap_main.n_packets_to_capture);
- }
- break;
- }
-
- else
- {
- error = clib_error_return (0, "unknown input `%U'",
- format_unformat_error, line_input);
- errorFlag = 1;
- break;
- }
- }
- unformat_free (line_input);
-
-
- if (errorFlag == 0)
- {
- /* Since no error, save configured values. */
- if (chroot_filename)
- {
- if (dm->pcap_filename)
- vec_free (dm->pcap_filename);
- vec_add1 (chroot_filename, 0);
- dm->pcap_filename = chroot_filename;
- }
-
- if (max)
- dm->pcap_pkts_to_capture = max;
-
-
- if (enabled)
- {
- if (dm->pcap_filename == 0)
- dm->pcap_filename = format (0, "/tmp/vpe.pcap%c", 0);
-
- memset (&dm->pcap_main, 0, sizeof (dm->pcap_main));
- dm->pcap_main.file_name = (char *) dm->pcap_filename;
- dm->pcap_main.n_packets_to_capture = PCAP_DEF_PKT_TO_CAPTURE;
- if (dm->pcap_pkts_to_capture)
- dm->pcap_main.n_packets_to_capture = dm->pcap_pkts_to_capture;
-
- dm->pcap_main.packet_type = PCAP_PACKET_TYPE_ethernet;
- dm->tx_pcap_enable = 1;
- vlib_cli_output (vm, "pcap tx capture on...");
- }
- }
- else if (chroot_filename)
- vec_free (chroot_filename);