aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/tracedump
diff options
context:
space:
mode:
authorMohammed Hawari <mohammed@hawari.fr>2023-05-26 14:52:50 +0200
committerDamjan Marion <dmarion@0xa5.net>2023-06-30 11:35:44 +0000
commit52fa5f21b911aaf1c50feb560dd3683b83625d2f (patch)
treef29e6ba9e62b6102284988d5bde7494c93e23407 /src/plugins/tracedump
parent60527bd6df4772bb4215403f2eea1b61b8b10157 (diff)
vlib: introduce trace filter functions
Change-Id: I7a988fafe98599e4fcf7cdaa307a69b9d76650f0 Signed-off-by: Mohammed Hawari <mohammed@hawari.fr> Type: improvement
Diffstat (limited to 'src/plugins/tracedump')
-rw-r--r--src/plugins/tracedump/tracedump.api20
-rw-r--r--src/plugins/tracedump/tracedump.c55
-rw-r--r--src/plugins/tracedump/tracedump_test.c32
3 files changed, 107 insertions, 0 deletions
diff --git a/src/plugins/tracedump/tracedump.api b/src/plugins/tracedump/tracedump.api
index ed6dd3f13bd..1b3813fb184 100644
--- a/src/plugins/tracedump/tracedump.api
+++ b/src/plugins/tracedump/tracedump.api
@@ -192,4 +192,24 @@ define trace_v2_details {
bool more;
string trace_data[];
+};
+
+autoreply define trace_set_filter_function
+{
+ u32 client_index;
+ u32 context;
+
+ string filter_function_name[];
+};
+
+define trace_filter_function_dump {
+ u32 client_index;
+ u32 context;
+};
+
+define trace_filter_function_details {
+ u32 context;
+
+ bool selected;
+ string name[];
}; \ No newline at end of file
diff --git a/src/plugins/tracedump/tracedump.c b/src/plugins/tracedump/tracedump.c
index 10107ac799e..6510a948c57 100644
--- a/src/plugins/tracedump/tracedump.c
+++ b/src/plugins/tracedump/tracedump.c
@@ -473,6 +473,61 @@ vl_api_trace_clear_cache_t_handler (vl_api_trace_clear_cache_t *mp)
REPLY_MACRO (VL_API_TRACE_CLEAR_CACHE_REPLY);
}
+static void
+vl_api_trace_set_filter_function_t_handler (
+ vl_api_trace_set_filter_function_t *mp)
+{
+ vl_api_trace_set_filter_function_reply_t *rmp;
+ tracedump_main_t *tdmp = &tracedump_main;
+ unformat_input_t input = { 0 };
+ vlib_is_packet_traced_fn_t *f;
+ char *filter_name;
+ int rv = 0;
+ filter_name = vl_api_from_api_to_new_c_string (&mp->filter_function_name);
+ unformat_init_cstring (&input, filter_name);
+ if (unformat (&input, "%U", unformat_vlib_trace_filter_function, &f) == 0)
+ {
+ rv = -1;
+ goto done;
+ }
+ vlib_set_trace_filter_function (f);
+done:
+ unformat_free (&input);
+ vec_free (filter_name);
+ REPLY_MACRO (VL_API_TRACE_SET_FILTER_FUNCTION_REPLY);
+}
+
+static void
+vl_api_trace_filter_function_dump_t_handler (
+ vl_api_trace_filter_function_dump_t *mp)
+{
+ vl_api_registration_t *rp;
+ vl_api_trace_filter_function_details_t *dmp;
+ tracedump_main_t *tdmp = &tracedump_main;
+ vlib_trace_filter_main_t *tfm = &vlib_trace_filter_main;
+ vlib_trace_filter_function_registration_t *reg =
+ tfm->trace_filter_registration;
+ vlib_main_t *vm = vlib_get_main ();
+ vlib_is_packet_traced_fn_t *current =
+ vm->trace_main.current_trace_filter_function;
+ rp = vl_api_client_index_to_registration (mp->client_index);
+
+ if (rp == 0)
+ return;
+
+ while (reg)
+ {
+ dmp = vl_msg_api_alloc (sizeof (*dmp) + strlen (reg->name));
+ dmp->_vl_msg_id =
+ htons (VL_API_TRACE_FILTER_FUNCTION_DETAILS + (tdmp->msg_id_base));
+ dmp->context = mp->context;
+ vl_api_c_string_to_api_string (reg->name, &dmp->name);
+ dmp->selected = current == reg->function;
+ vl_api_send_msg (rp, (u8 *) dmp);
+ reg = reg->next;
+ }
+}
+
/* API definitions */
#include <tracedump/tracedump.api.c>
diff --git a/src/plugins/tracedump/tracedump_test.c b/src/plugins/tracedump/tracedump_test.c
index 97fd4092d89..b813acc3ecc 100644
--- a/src/plugins/tracedump/tracedump_test.c
+++ b/src/plugins/tracedump/tracedump_test.c
@@ -274,6 +274,38 @@ api_trace_clear_cache (vat_main_t *vam)
return ret;
}
+static int
+api_trace_set_filter_function (vat_main_t *vam)
+{
+ vl_api_trace_set_filter_function_t *mp;
+ int ret;
+
+ M (TRACE_SET_FILTER_FUNCTION, mp);
+ S (mp);
+ W (ret);
+ return ret;
+}
+
+static int
+api_trace_filter_function_dump (vat_main_t *vam)
+{
+ vl_api_trace_filter_function_dump_t *mp;
+ int ret;
+
+ M (TRACE_FILTER_FUNCTION_DUMP, mp);
+ S (mp);
+ W (ret);
+ return ret;
+}
+
+static void
+vl_api_trace_filter_function_details_t_handler (
+ vl_api_trace_filter_function_details_t *dmp)
+{
+ fformat (stdout, "name: %U, selected: %u\n\n", vl_api_format_string,
+ &dmp->name, dmp->selected);
+}
+
#define vl_endianfun
#include <tracedump/tracedump.api.h>
#undef vl_endianfun