summaryrefslogtreecommitdiff
path: root/src/entry/Maat_api.cpp
diff options
context:
space:
mode:
authorzhengchao <[email protected]>2021-07-15 21:37:48 +0800
committerzhengchao <[email protected]>2021-07-19 20:55:12 +0800
commit233bc2f0ef613cb77905a7ff128352f124c0e2ec (patch)
treeb3260806e53b48308b6dfa31f789e7b6614d49da /src/entry/Maat_api.cpp
parent99e8ffb5105b90b88e150c5f80be4b194aa18ac7 (diff)
Maat_set_scan_status可以设置MAAT_SET_SCAN_NO_COUNT类型参数, 指示下一次扫描不进行计数,以减少hit path的存储开销。
Diffstat (limited to 'src/entry/Maat_api.cpp')
-rw-r--r--src/entry/Maat_api.cpp48
1 files changed, 42 insertions, 6 deletions
diff --git a/src/entry/Maat_api.cpp b/src/entry/Maat_api.cpp
index d465711..4a5774f 100644
--- a/src/entry/Maat_api.cpp
+++ b/src/entry/Maat_api.cpp
@@ -76,6 +76,19 @@ int insert_set_id(unsigned long long **set, size_t* size, size_t cnt, unsigned l
}
}
+void scan_staus_count_inc(struct _OUTER_scan_status_t* _mid)
+{
+ if(_mid->is_no_count_scan)
+ {
+ _mid->is_no_count_scan=0;
+ }
+ else
+ {
+ _mid->scan_cnt++;
+ }
+ return;
+}
+
void fill_maat_rule(struct Maat_rule_t *rule, const struct Maat_rule_head* rule_head, const char* srv_def, int srv_def_len)
{
memcpy(rule, rule_head, sizeof(struct Maat_rule_head));
@@ -1353,7 +1366,7 @@ int Maat_full_scan_string_detail(Maat_feather_t feather,int table_id
clock_gettime(CLOCK_MONOTONIC,&start);
}
_mid=grab_mid(mid,_feather, thread_num, 0);
- _mid->scan_cnt++;
+ scan_staus_count_inc(_mid);
if(data==NULL||data_len<=0)
{
return -1;
@@ -1500,7 +1513,7 @@ int Maat_scan_intval(Maat_feather_t feather,int table_id
clock_gettime(CLOCK_MONOTONIC,&start);
}
_mid=grab_mid(mid, _feather, thread_num, 0);
- _mid->scan_cnt++;
+ scan_staus_count_inc(_mid);
int virtual_table_id=0;
p_table=Maat_table_get_scan_by_id(_feather->table_mgr, table_id, SCAN_TYPE_INTERVAL, &virtual_table_id);
@@ -1602,7 +1615,7 @@ int Maat_similar_scan_string(Maat_feather_t feather,int table_id
clock_gettime(CLOCK_MONOTONIC,&start);
}
_mid=grab_mid(mid, _feather, thread_num, 0);
- _mid->scan_cnt++;
+ scan_staus_count_inc(_mid);
int virtual_table_id=0;
p_table=Maat_table_get_scan_by_id(_feather->table_mgr, table_id, SCAN_TYPE_STRING, &virtual_table_id);
@@ -1805,7 +1818,7 @@ int Maat_scan_proto_addr(Maat_feather_t feather,int table_id
clock_gettime(CLOCK_MONOTONIC,&start);
}
_mid=grab_mid(mid, _feather, thread_num, 0);
- _mid->scan_cnt++;
+ scan_staus_count_inc(_mid);
int virtual_table_id=0;
enum MAAT_TABLE_TYPE table_type=TABLE_TYPE_INVALID;
table_type=Maat_table_get_type_by_id(_feather->table_mgr, table_id);
@@ -1993,7 +2006,7 @@ int Maat_stream_scan_string_detail(stream_para_t* stream_para
clock_gettime(CLOCK_MONOTONIC, &start);
}
_mid=grab_mid(mid, sp->feather, sp->thread_num, 0);
- _mid->scan_cnt++;
+ scan_staus_count_inc(_mid);
if(data==NULL||data_len<=0||scanner==NULL)
{
return 0;
@@ -2288,7 +2301,7 @@ int Maat_stream_scan_digest(stream_para_t * stream_para, const char * data, int
clock_gettime(CLOCK_MONOTONIC,&start);
}
_mid=grab_mid(mid, sp->feather, sp->thread_num, 0);
- _mid->scan_cnt++;
+ scan_staus_count_inc(_mid);
if(data==NULL||data_len<=0)
{
@@ -2423,6 +2436,25 @@ int Maat_read_rule(Maat_feather_t feather, const struct Maat_rule_t* rule, enum
}
return ret;
}
+
+int Maat_apply_scan_status(Maat_feather_t feather, scan_status_t *mid,
+ struct Maat_rule_t*result, int rule_num, int thread_num)
+{
+ struct _OUTER_scan_status_t* _mid=(struct _OUTER_scan_status_t*)(*mid);
+ struct _Maat_feather_t* _feather=(_Maat_feather_t*)feather;
+ struct scan_region_hit_wraper region_hit_wraper;
+ int ret=0;
+ if(!_mid||! (_mid->compile_mid))
+ {
+ return 0;
+ }
+ memset(&region_hit_wraper, 0, sizeof(region_hit_wraper));
+ region_hit_wraper.Nth_scan=_mid->scan_cnt;
+ region_hit_wraper.n_hit_region=0;
+ ret=region_compile(_feather, _mid->compile_mid, &region_hit_wraper, result, rule_num, thread_num);
+ return ret;
+}
+
int Maat_set_scan_status(Maat_feather_t feather,scan_status_t* mid,enum MAAT_SCAN_OPT type,const void* value,int size)
{
struct _Maat_feather_t* _feather=(_Maat_feather_t*)feather;
@@ -2458,6 +2490,10 @@ int Maat_set_scan_status(Maat_feather_t feather,scan_status_t* mid,enum MAAT_SCA
assert(_mid->is_last_region==0);
_mid->is_last_region=1;
break;
+ case MAAT_SET_SCAN_NO_COUNT:
+ assert(_mid->is_no_count_scan==0);
+ _mid->is_no_count_scan=1;
+ break;
default:
_feather->scan_err_cnt++;
return -1;