From 0060bbb7df7062785c211324f9d325fe40596319 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Thu, 4 Dec 2014 17:04:16 +0200 Subject: [PATCH] Updated the diagnostic to print rules, their types and how many times they have been matched. --- server/modules/filter/fwfilter.c | 45 +++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/server/modules/filter/fwfilter.c b/server/modules/filter/fwfilter.c index d3537c662..19c31cf7e 100644 --- a/server/modules/filter/fwfilter.c +++ b/server/modules/filter/fwfilter.c @@ -108,7 +108,7 @@ static FILTER_OBJECT MyObject = { * Rule types */ typedef enum { - RT_UNDEFINED, + RT_UNDEFINED = 0x00, RT_COLUMN, RT_THROTTLE, RT_PERMISSION, @@ -117,6 +117,17 @@ typedef enum { RT_CLAUSE }ruletype_t; +const char* rule_names[] = { + "RT_UNDEFINED", + "RT_COLUMN", + "RT_THROTTLE", + "RT_PERMISSION", + "RT_WILDCARD", + "RT_REGEX", + "RT_CLAUSE" +}; + + /** * Linked list of strings. */ @@ -155,6 +166,7 @@ typedef struct rule_t{ ruletype_t type; skygw_query_op_t on_queries; bool allow; + int times_matched; TIMERANGE* active; }RULE; @@ -1384,7 +1396,12 @@ bool rule_matches(FW_INSTANCE* my_instance, FW_SESSION* my_session, GWBUF *queue queryresolved: if(msg){ my_session->errmsg = msg; - } + } + + if(matches){ + rulelist->rule->times_matched++; + } + return matches; } @@ -1588,9 +1605,29 @@ static void diagnostic(FILTER *instance, void *fsession, DCB *dcb) { FW_INSTANCE *my_instance = (FW_INSTANCE *)instance; - + RULELIST* rules; + int type; + if (my_instance) { - dcb_printf(dcb, "\t\tFirewall Filter\n"); + spinlock_acquire(my_instance->lock); + rules = my_instance->rules; + + dcb_printf(dcb, "Firewall Filter\n"); + dcb_printf(dcb, "%-24s%-24s%-24s\n","Rule","Type","Times Matched"); + while(rules){ + if((int)rules->rule->type > 0 && + (int)rules->rule->type < sizeof(rule_names)/sizeof(char**)){ + type = (int)rules->rule->type; + }else{ + type = 0; + } + dcb_printf(dcb,"%-24s%-24s%-24d\n", + rules->rule->name, + rule_names[type], + rules->rule->times_matched); + rules = rules->next; + } + spinlock_release(my_instance->lock); } }