aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/interface_cli.c
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2019-09-13 17:47:50 -0400
committerFlorin Coras <florin.coras@gmail.com>2019-09-20 15:55:25 +0000
commit9137e5400699bed9f7c0095187839a8b38273100 (patch)
treeb4f0b34583c8e4add09b34e8a4c52a5606b2dc55 /src/vnet/interface_cli.c
parent864d857c6c223be8ec11c588d65e8c5c2e211814 (diff)
misc: classifier-based packet trace filter
See .../src/vnet/classify/trace_classify.h for the business end of the scheme. It would be best to hash pkts, prefetch buckets, and do the primary table lookups two at a time. The inline as given works, but perf tuning will be required. "At least it works..." Add "classify filter" debug cli, for example: classify filter mask l3 ip4 src dst \ match l3 ip4 dst 192.168.2.10 src 192.168.1.10 Add "pcap rx | tx trace ... filter" to use the current classify filter chain Patch includes sphinx documentation and doxygen tags. Next step: device-driver integration Type: feature Signed-off-by: Dave Barach <dave@barachs.net> Change-Id: I05b1358a769f61e6d32470e0c87058f640486b26
Diffstat (limited to 'src/vnet/interface_cli.c')
-rw-r--r--src/vnet/interface_cli.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/vnet/interface_cli.c b/src/vnet/interface_cli.c
index 95e1684be8b..8f1fde7e852 100644
--- a/src/vnet/interface_cli.c
+++ b/src/vnet/interface_cli.c
@@ -1699,13 +1699,14 @@ int
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...",
@@ -1734,6 +1735,10 @@ vnet_pcap_dispatch_trace_configure (vnet_pcap_dispatch_trace_args_t * a)
&& (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 */
@@ -1754,6 +1759,11 @@ vnet_pcap_dispatch_trace_configure (vnet_pcap_dispatch_trace_args_t * a)
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
@@ -1796,6 +1806,7 @@ pcap_trace_command_internal (vlib_main_t * vm,
int rv;
int enable = 0;
int status = 0;
+ int filter = 0;
u32 sw_if_index = 0;
/* Get a line of input. */
@@ -1826,6 +1837,8 @@ pcap_trace_command_internal (vlib_main_t * vm,
;
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'",
@@ -1842,6 +1855,7 @@ pcap_trace_command_internal (vlib_main_t * vm,
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);
@@ -1866,6 +1880,10 @@ pcap_trace_command_internal (vlib_main_t * vm,
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;
@@ -1959,7 +1977,6 @@ VLIB_CLI_COMMAND (pcap_rx_trace_command, static) = {
};
/* *INDENT-ON* */
-
/*
* fd.io coding-style-patch-verification: ON
*