TRACE_RULE_EVAL = 0x2,
TRACE_BUFFER_MINIMAL = 0x4,
TRACE_BUFFER_VERBOSE = 0x8,
- TRACE_RULE_VARS = 0x10
+ TRACE_RULE_VARS = 0x10,
+ TRACE_FP_SEARCH = 0x20
};
void clear_trace_cursor_info();
return -1;
OptFpList* next = nullptr;
- bool only_literal = !MpseManager::is_regex_capable(fp->get_search_api());
- pmv = get_fp_content(otn, next, srvc, only_literal);
+ bool exclude, only_literal = !MpseManager::is_regex_capable(fp->get_search_api());
+ pmv = get_fp_content(otn, next, srvc, only_literal, exclude);
if ( !pmv.empty() )
{
}
}
+ if ( exclude )
+ return 0;
+
// no fast pattern added
if (fpFinishPortGroupRule(sc, pg, otn, nullptr, fp) != 0)
return -1;
s_group = srvc;
/*
- * add each rule to the port group pattern matchers,
+ * add each rule to the service group pattern matchers,
* or to the no-content rule list
*/
SF_LNODE* cursor;
otn;
otn = (OptTreeNode*)sflist_next(&cursor) )
{
- if (fpAddPortGroupRule(sc, pg, otn, fp, true) != 0)
- continue;
+ fpAddPortGroupRule(sc, pg, otn, fp, true);
}
if (fpFinishPortGroup(sc, pg, fp) != 0)
{
if ( Mpse* so = omd->pg->mpse[pmt] )
{
- trace_logf(detection, TRACE_RULE_EVAL,
- "inspector %s, buffer type %s\n",
- gadget->get_name(),pm_type_strings[pmt]);
+ trace_logf(detection, TRACE_FP_SEARCH, "%ld fp %s.%s[%d]\n",
+ pc.total_from_daq, gadget->get_name(), pm_type_strings[pmt], buf.len);
search_data(so, omd, buf.data, buf.len, cnt);
}
pattern_match_size = p->alt_dsize;
if ( pattern_match_size )
- search_data(so, omd, p->data, pattern_match_size, pc.pkt_searches);
+ {
+ trace_logf(detection, TRACE_FP_SEARCH, "%ld fp %s[%d]\n",
+ pc.total_from_daq, pm_type_strings[PM_TYPE_PKT], pattern_match_size);
- if ( pattern_match_size )
+ search_data(so, omd, p->data, pattern_match_size, pc.pkt_searches);
p->is_cooked() ? pc.cooked_searches++ : pc.raw_searches++;
+ }
}
}
if ( file_data.len )
{
- trace_log(detection, TRACE_RULE_EVAL, "Searching file data\n");
+ trace_logf(detection, TRACE_FP_SEARCH, "%ld fp search %s[%d]\n",
+ pc.total_from_daq, pm_type_strings[PM_TYPE_FILE], file_data.len);
+
search_data(so, omd, file_data.data, file_data.len, pc.file_searches);
}
}
}
bool FpSelector::is_better_than(
- FpSelector& rhs, bool srvc, RuleDirection dir, bool only_literals)
+ FpSelector& rhs, bool /*srvc*/, RuleDirection /*dir*/, bool only_literals)
{
if ( !pmd_can_be_fp(pmd, cat, only_literals) )
{
if ( !rhs.pmd )
return true;
- if ( !srvc )
- {
- if ( cat == CAT_SET_RAW and rhs.cat != CAT_SET_RAW )
- return true;
-
- if ( cat != CAT_SET_RAW and rhs.cat == CAT_SET_RAW )
- return false;
- }
- else if ( dir == RULE_FROM_SERVER )
- {
- if ( cat != CAT_SET_KEY and rhs.cat == CAT_SET_KEY )
- return true;
-
- if ( cat == CAT_SET_KEY and rhs.cat != CAT_SET_KEY )
- return false;
- }
if ( pmd->is_fast_pattern() )
{
if ( rhs.pmd->is_fast_pattern() )
//--------------------------------------------------------------------------
PatternMatchVector get_fp_content(
- OptTreeNode* otn, OptFpList*& next, bool srvc, bool only_literals)
+ OptTreeNode* otn, OptFpList*& next, bool srvc, bool only_literals, bool& exclude)
{
CursorActionType curr_cat = CAT_SET_RAW;
FpSelector best;
}
}
+ if ( best.pmd and best.cat != CAT_SET_RAW and !srvc and otn->sigInfo.num_services > 0 )
+ {
+ pmds.clear(); // just include in service group
+ exclude = true;
+ }
+ else
+ exclude = false;
+
if ( best.pmd and otn->proto == SNORT_PROTO_FILE and best.cat != CAT_SET_FILE )
{
ParseWarning(WARN_RULES, "file rule %u:%u does not have file_data fast pattern",
set_pmd(p1, 0x0, "foo");
FpSelector s1(CAT_SET_FILE, &p1);
- CHECK(s0.is_better_than(s1, false, RULE_WO_DIR));
+ CHECK(!s0.is_better_than(s1, false, RULE_WO_DIR));
CHECK(!s1.is_better_than(s0, false, RULE_WO_DIR));
}
set_pmd(p1, 0x0, "longer");
FpSelector s1(CAT_SET_KEY, &p1);
- CHECK(s0.is_better_than(s1, false, RULE_WO_DIR));
+ CHECK(!s0.is_better_than(s1, false, RULE_WO_DIR));
}
TEST_CASE("fp_pkt_key_port_user", "[FastPatternSelect]")
set_pmd(p1, 0x0, "longer");
FpSelector s1(CAT_SET_KEY, &p1);
- CHECK(s0.is_better_than(s1, true, RULE_FROM_SERVER));
- CHECK(!s1.is_better_than(s0, true, RULE_FROM_SERVER));
+ CHECK(!s0.is_better_than(s1, true, RULE_FROM_SERVER));
+ CHECK(s1.is_better_than(s0, true, RULE_FROM_SERVER));
}
#endif
bool set_fp_content(OptTreeNode*);
std::vector <PatternMatchData*> get_fp_content(
- OptTreeNode*, OptFpList*&, bool srvc, bool only_literals);
+ OptTreeNode*, OptFpList*&, bool srvc, bool only_literals, bool& exclude);
#endif