MXS-1346: Fix rule handling

The call to update_rules is needed before each query to make sure that the
rules are up to date.

The check whether the rule was active was inverted.
This commit is contained in:
Markus Mäkelä 2017-09-04 19:34:14 +03:00
parent 6067c21c1b
commit 2ccdd93d44
2 changed files with 24 additions and 19 deletions

View File

@ -1051,6 +1051,24 @@ bool replace_rules(Dbfw* instance)
return rval;
}
static bool update_rules(Dbfw* my_instance)
{
bool rval = true;
int rule_version = my_instance->get_rule_version();
if (this_thread.rule_version < rule_version)
{
if (!replace_rules(my_instance))
{
rval = false;
}
this_thread.rule_version = rule_version;
}
return rval;
}
Dbfw::Dbfw(MXS_CONFIG_PARAMETER* params):
m_action((enum fw_actions)config_get_enum(params, "action", action_values)),
m_log_match(0),
@ -1295,6 +1313,11 @@ int DbfwSession::routeQuery(GWBUF* buffer)
int rval = 0;
uint32_t type = 0;
if (!update_rules(m_instance))
{
return rval;
}
if (modutil_is_SQL(buffer) || modutil_is_SQL_prepare(buffer))
{
type = qc_get_type_mask(buffer);
@ -1567,24 +1590,6 @@ bool rule_matches(Dbfw* my_instance,
return matches;
}
static bool update_rules(Dbfw* my_instance)
{
bool rval = true;
int rule_version = my_instance->get_rule_version();
if (this_thread.rule_version < rule_version)
{
if (!replace_rules(my_instance))
{
rval = false;
}
this_thread.rule_version = rule_version;
}
return rval;
}
/**
* Diagnostics routine
*

View File

@ -127,7 +127,7 @@ bool User::do_match(Dbfw* my_instance, DbfwSession* my_session,
rval = true;
for (RuleList::iterator it = rules.begin(); it != rules.end(); it++)
{
if (!rule_is_active(*it))
if (rule_is_active(*it))
{
have_active_rule = true;