diff options
author | Dave Barach <dave@barachs.net> | 2019-12-04 17:19:12 -0500 |
---|---|---|
committer | Dave Barach <dave@barachs.net> | 2020-02-12 09:42:05 -0500 |
commit | 7c5a3536ce4c2fd4157c466367c495cefecaa52e (patch) | |
tree | fe6e70be8b1d2e0a594b0268d7a51962155b65a5 /src/vlib | |
parent | d28bac409409ea821cd9ce2ec4f84a7786cbcb73 (diff) |
classify: vpp packet tracer support
Configure n-tuple classifier filters which apply to the vpp packet
tracer.
Update the documentation to reflect the new feature.
Add a test vector.
Type: feature
Signed-off-by: Dave Barach <dave@barachs.net>
Change-Id: Iefa911716c670fc12e4825b937b62044433fec36
(cherry picked from commit 87d24db65facb89ca524c951b8379ca2ec4dbc7a)
Diffstat (limited to 'src/vlib')
-rw-r--r-- | src/vlib/main.h | 10 | ||||
-rw-r--r-- | src/vlib/trace.c | 33 | ||||
-rw-r--r-- | src/vlib/trace_funcs.h | 16 |
3 files changed, 58 insertions, 1 deletions
diff --git a/src/vlib/main.h b/src/vlib/main.h index e230ddf8419..af6539efc75 100644 --- a/src/vlib/main.h +++ b/src/vlib/main.h @@ -73,6 +73,13 @@ typedef struct u32 filter_classify_table_index; } vnet_pcap_t; +typedef struct +{ + u8 trace_filter_enable; + u32 trace_classify_table_index; + u32 trace_filter_set_index; +} vlib_trace_filter_t; + typedef struct vlib_main_t { CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); @@ -165,6 +172,9 @@ typedef struct vlib_main_t /* pcap rx / tx tracing */ vnet_pcap_t pcap; + /* Packet trace capture filter */ + vlib_trace_filter_t trace_filter; + /* Error handling. */ vlib_error_main_t error_main; diff --git a/src/vlib/trace.c b/src/vlib/trace.c index 530598d349d..7ee1b63f07e 100644 --- a/src/vlib/trace.c +++ b/src/vlib/trace.c @@ -351,6 +351,13 @@ VLIB_CLI_COMMAND (show_trace_cli,static) = { }; /* *INDENT-ON* */ +int vlib_enable_disable_pkt_trace_filter (int enable) __attribute__ ((weak)); +int +vlib_enable_disable_pkt_trace_filter (int enable) +{ + return 0; +} + static clib_error_t * cli_add_trace_buffer (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) @@ -361,6 +368,7 @@ cli_add_trace_buffer (vlib_main_t * vm, vlib_trace_node_t *tn; u32 node_index, add; u8 verbose = 0; + int filter = 0; clib_error_t *error = 0; if (!unformat_user (input, unformat_line_input, line_input)) @@ -376,6 +384,8 @@ cli_add_trace_buffer (vlib_main_t * vm, ; else if (unformat (line_input, "verbose")) verbose = 1; + else if (unformat (line_input, "filter")) + filter = 1; else { error = clib_error_create ("expected NODE COUNT, got `%U'", @@ -395,6 +405,15 @@ cli_add_trace_buffer (vlib_main_t * vm, goto done; } + if (filter) + { + if (vlib_enable_disable_pkt_trace_filter (1 /* enable */ )) + { + error = clib_error_create ("No packet trace filter configured..."); + goto done; + } + } + /* *INDENT-OFF* */ foreach_vlib_main (( { @@ -421,7 +440,6 @@ VLIB_CLI_COMMAND (add_trace_cli,static) = { }; /* *INDENT-ON* */ - /* * Configure a filter for packet traces. * @@ -523,6 +541,7 @@ static clib_error_t * cli_clear_trace_buffer (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { + vlib_enable_disable_pkt_trace_filter (0 /* enable */ ); clear_trace_buffer (); return 0; } @@ -541,6 +560,18 @@ vlib_trace_cli_reference (void) { } +int +vnet_is_packet_traced (vlib_buffer_t * b, + u32 classify_table_index, int func) +__attribute__ ((weak)); + +int +vnet_is_packet_traced (vlib_buffer_t * b, u32 classify_table_index, int func) +{ + clib_warning ("BUG: STUB called"); + return 1; +} + /* * fd.io coding-style-patch-verification: ON * diff --git a/src/vlib/trace_funcs.h b/src/vlib/trace_funcs.h index 257c3a3a4ff..4261f675aec 100644 --- a/src/vlib/trace_funcs.h +++ b/src/vlib/trace_funcs.h @@ -61,6 +61,9 @@ vlib_add_trace (vlib_main_t * vm, ASSERT (vnet_trace_dummy); + if (PREDICT_FALSE ((b->flags & VLIB_BUFFER_IS_TRACED) == 0)) + return vnet_trace_dummy; + if (PREDICT_FALSE (tm->add_trace_callback != 0)) { return tm->add_trace_callback ((struct vlib_main_t *) vm, @@ -118,6 +121,9 @@ vlib_trace_next_frame (vlib_main_t * vm, } void trace_apply_filter (vlib_main_t * vm); +int vnet_is_packet_traced (vlib_buffer_t * b, + u32 classify_table_index, int func); + /* Mark buffer as traced and allocate trace buffer. */ always_inline void @@ -131,6 +137,16 @@ vlib_trace_buffer (vlib_main_t * vm, if (PREDICT_FALSE (tm->trace_enable == 0)) return; + /* Classifier filter in use? */ + if (PREDICT_FALSE (vlib_global_main.trace_filter.trace_filter_enable)) + { + /* See if we're supposed to trace this packet... */ + if (vnet_is_packet_traced + (b, vlib_global_main.trace_filter.trace_classify_table_index, + 0 /* full classify */ ) != 1) + return; + } + /* * Apply filter to existing traces to keep number of allocated traces low. * Performed each time around the main loop. |