vnet_pcap_dispatch_trace_configure (vnet_pcap_dispatch_trace_args_t * a)
{
vlib_main_t *vm = vlib_get_main ();
+ vnet_main_t *vnm = vnet_get_main ();
vlib_rx_or_tx_t rxtx = a->rxtx;
vnet_pcap_t *pp = &vm->pcap[rxtx];
pcap_main_t *pm = &pp->pcap_main;
if (a->status)
{
- if (pp->pcap_enable == 0)
+ if (pp->pcap_enable)
{
vlib_cli_output
(vm, "pcap %s dispatch capture enabled: %d of %d pkts...",
&& (pm->n_packets_to_capture != a->packets_to_capture))
return VNET_API_ERROR_INVALID_VALUE_2;
+ if (a->enable && a->filter
+ && (vec_len (vnm->classify_filter_table_indices) == 0))
+ return VNET_API_ERROR_NO_SUCH_LABEL;
+
if (a->enable)
{
/* Clean up from previous run, if any */
pm->packet_type = PCAP_PACKET_TYPE_ethernet;
pm->n_packets_to_capture = a->packets_to_capture;
pp->pcap_sw_if_index = a->sw_if_index;
+ if (a->filter)
+ pp->filter_classify_table_index =
+ vnm->classify_filter_table_indices[0];
+ else
+ pp->filter_classify_table_index = ~0;
pp->pcap_enable = 1;
}
else
vlib_cli_output (vm, "Write %d packets to %s, and stop capture...",
pm->n_packets_captured, pm->file_name);
error = pcap_write (pm);
- if (pm->file_descriptor >= 0)
+ if (pm->flags & PCAP_MAIN_INIT_DONE)
pcap_close (pm);
/* Report I/O errors... */
if (error)
int rv;
int enable = 0;
int status = 0;
+ int filter = 0;
u32 sw_if_index = 0;
/* Get a line of input. */
;
else if (unformat (line_input, "intfc any"))
sw_if_index = 0;
+ else if (unformat (line_input, "filter"))
+ filter = 1;
else
{
return clib_error_return (0, "unknown input `%U'",
a->packets_to_capture = max;
a->rxtx = rxtx;
a->sw_if_index = sw_if_index;
+ a->filter = filter;
rv = vnet_pcap_dispatch_trace_configure (a);
case VNET_API_ERROR_NO_SUCH_ENTRY:
return clib_error_return (0, "No packets captured...");
+ case VNET_API_ERROR_NO_SUCH_LABEL:
+ return clib_error_return
+ (0, "No classify filter configured, see 'classify filter...'");
+
default:
vlib_cli_output (vm, "WARNING: trace configure returned %d", rv);
break;
};
/* *INDENT-ON* */
-
/*
* fd.io coding-style-patch-verification: ON
*