From 1b696ac9b334aa9305925e4759c6c6f6b47c3328 Mon Sep 17 00:00:00 2001 From: Dave Barach Date: Fri, 13 Sep 2019 17:47:50 -0400 Subject: 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 Change-Id: I05b1358a769f61e6d32470e0c87058f640486b26 (cherry picked from commit 9137e5400699bed9f7c0095187839a8b38273100) --- src/vnet/interface_output.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/vnet/interface_output.c') diff --git a/src/vnet/interface_output.c b/src/vnet/interface_output.c index bf21587ae4d..250d0dbe251 100644 --- a/src/vnet/interface_output.c +++ b/src/vnet/interface_output.c @@ -43,6 +43,7 @@ #include #include #include +#include typedef struct { @@ -813,13 +814,29 @@ static_always_inline void vnet_interface_pcap_tx_trace else sw_if_index = ~0; + vnet_main_t *vnm = vnet_get_main (); n_left_from = frame->n_vectors; from = vlib_frame_vector_args (frame); while (n_left_from > 0) { + int classify_filter_result; u32 bi0 = from[0]; vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0); + from++; + n_left_from--; + + if (vec_len (vnm->classify_filter_table_indices)) + { + classify_filter_result = + vnet_is_packet_traced_inline + (b0, vnm->classify_filter_table_indices[0], + 0 /* full classify */ ); + if (classify_filter_result) + pcap_add_buffer (&vlib_global_main.pcap[VLIB_TX].pcap_main, vm, + bi0, 512); + continue; + } if (sw_if_index_from_buffer) sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX]; @@ -828,8 +845,6 @@ static_always_inline void vnet_interface_pcap_tx_trace vlib_global_main.pcap[VLIB_TX].pcap_sw_if_index == sw_if_index) pcap_add_buffer (&vlib_global_main.pcap[VLIB_TX].pcap_main, vm, bi0, 512); - from++; - n_left_from--; } } -- cgit 1.2.3-korg