diff options
author | Dave Barach <dave@barachs.net> | 2019-09-13 17:47:50 -0400 |
---|---|---|
committer | Damjan Marion <dmarion@me.com> | 2019-09-25 22:19:59 +0000 |
commit | 1b696ac9b334aa9305925e4759c6c6f6b47c3328 (patch) | |
tree | 6cbc009453d33c1a7d54b5aca1a4d347bbcf0a8a /src/vnet/interface_cli.c | |
parent | 2abe699d10450553148307bb614979902f2bf4b3 (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
(cherry picked from commit 9137e5400699bed9f7c0095187839a8b38273100)
Diffstat (limited to 'src/vnet/interface_cli.c')
-rw-r--r-- | src/vnet/interface_cli.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/vnet/interface_cli.c b/src/vnet/interface_cli.c index 08d9628730c..4ad0cb025bd 100644 --- a/src/vnet/interface_cli.c +++ b/src/vnet/interface_cli.c @@ -1699,6 +1699,7 @@ 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; @@ -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; @@ -1958,7 +1976,6 @@ VLIB_CLI_COMMAND (pcap_rx_trace_command, static) = { }; /* *INDENT-ON* */ - /* * fd.io coding-style-patch-verification: ON * |