[FEATURE]Refactor NOT clause, NOTE:forward incompatibility!!!

This commit is contained in:
刘文坛
2023-10-18 03:32:53 +00:00
parent 48af7e7aac
commit 613b5b3dcf
19 changed files with 1609 additions and 498 deletions

View File

@@ -1016,17 +1016,6 @@ int maat_bool_plugin_table_get_ex_data(struct maat *maat_inst, int table_id,
ex_data_array, array_size);
}
static inline int scan_status_should_compile_NOT(struct maat_state *state)
{
if (state && (COMPILE_NOT_SET == state->compile_NOT_flag) &&
state->compile_state &&
maat_compile_state_has_NOT_clause(state->compile_state)) {
return 1;
}
return 0;
}
static size_t hit_group_to_compile(void *compile_runtime, long long *compile_ids,
size_t compile_ids_size, struct maat_state *state)
{
@@ -1287,18 +1276,13 @@ int maat_scan_flag(struct maat *maat_inst, int table_id,
maat_runtime_ref_inc(maat_rt, state->thread_id);
size_t sum_hit_compile_cnt = 0;
if (hit_group_cnt > 0 || scan_status_should_compile_NOT(state)) {
if (hit_group_cnt > 0) {
sum_hit_compile_cnt = group_to_compile(maat_inst, results, n_result, state);
*n_hit_result = sum_hit_compile_cnt;
}
if (sum_hit_compile_cnt > 0) {
alignment_int64_array_add(maat_inst->stat->hit_cnt, state->thread_id, 1);
if (0 == hit_group_cnt) {
//hit NOT group
alignment_int64_array_add(maat_inst->stat->not_grp_hit_cnt,
state->thread_id, 1);
}
}
void *flag_rt = table_manager_get_runtime(maat_inst->tbl_mgr, phy_table_id);
@@ -1376,18 +1360,13 @@ int maat_scan_integer(struct maat *maat_inst, int table_id,
maat_runtime_ref_inc(maat_rt, state->thread_id);
size_t sum_hit_compile_cnt = 0;
if (hit_group_cnt > 0 || scan_status_should_compile_NOT(state)) {
if (hit_group_cnt > 0) {
sum_hit_compile_cnt = group_to_compile(maat_inst, results, n_result, state);
*n_hit_result = sum_hit_compile_cnt;
}
if (sum_hit_compile_cnt > 0) {
alignment_int64_array_add(maat_inst->stat->hit_cnt, state->thread_id, 1);
if (0 == hit_group_cnt) {
//hit NOT group
alignment_int64_array_add(maat_inst->stat->not_grp_hit_cnt,
state->thread_id, 1);
}
}
void *interval_rt = table_manager_get_runtime(maat_inst->tbl_mgr, phy_table_id);
@@ -1465,18 +1444,13 @@ int maat_scan_ipv4(struct maat *maat_inst, int table_id, uint32_t ip_addr,
maat_runtime_ref_inc(maat_rt, state->thread_id);
size_t sum_hit_compile_cnt = 0;
if (hit_group_cnt > 0 || scan_status_should_compile_NOT(state)) {
if (hit_group_cnt > 0) {
sum_hit_compile_cnt = group_to_compile(maat_inst, results, n_result, state);
*n_hit_result = sum_hit_compile_cnt;
}
if (sum_hit_compile_cnt > 0) {
alignment_int64_array_add(maat_inst->stat->hit_cnt, state->thread_id, 1);
if (0 == hit_group_cnt) {
//hit NOT group
alignment_int64_array_add(maat_inst->stat->not_grp_hit_cnt,
state->thread_id, 1);
}
}
void *ip_rt = table_manager_get_runtime(maat_inst->tbl_mgr, phy_table_id);
@@ -1555,18 +1529,13 @@ int maat_scan_ipv6(struct maat *maat_inst, int table_id,
maat_runtime_ref_inc(maat_rt, state->thread_id);
size_t sum_hit_compile_cnt = 0;
if (hit_group_cnt > 0 || scan_status_should_compile_NOT(state)) {
if (hit_group_cnt > 0) {
sum_hit_compile_cnt = group_to_compile(maat_inst, results, n_result, state);
*n_hit_result = sum_hit_compile_cnt;
}
if (sum_hit_compile_cnt > 0) {
alignment_int64_array_add(maat_inst->stat->hit_cnt, state->thread_id, 1);
if (0 == hit_group_cnt) {
//hit NOT group
alignment_int64_array_add(maat_inst->stat->not_grp_hit_cnt,
state->thread_id, 1);
}
}
void *ip_rt = table_manager_get_runtime(maat_inst->tbl_mgr, phy_table_id);
@@ -1644,18 +1613,13 @@ int maat_scan_string(struct maat *maat_inst, int table_id, const char *data,
maat_runtime_ref_inc(maat_rt, state->thread_id);
size_t sum_hit_compile_cnt = 0;
if (hit_group_cnt > 0 || scan_status_should_compile_NOT(state)) {
if (hit_group_cnt > 0) {
sum_hit_compile_cnt = group_to_compile(maat_inst, results, n_result, state);
*n_hit_result = sum_hit_compile_cnt;
}
if (sum_hit_compile_cnt > 0) {
alignment_int64_array_add(maat_inst->stat->hit_cnt, state->thread_id, 1);
if (0 == hit_group_cnt) {
//hit NOT group
alignment_int64_array_add(maat_inst->stat->not_grp_hit_cnt,
state->thread_id, 1);
}
}
void *expr_rt = table_manager_get_runtime(maat_inst->tbl_mgr, phy_table_id);
@@ -1772,18 +1736,13 @@ int maat_stream_scan(struct maat_stream *maat_stream, const char *data, int data
}
size_t sum_hit_compile_cnt = 0;
if (hit_group_cnt > 0 || scan_status_should_compile_NOT(state)) {
if (hit_group_cnt > 0) {
sum_hit_compile_cnt = group_to_compile(maat_inst, results, n_result, state);
*n_hit_result = sum_hit_compile_cnt;
}
if (sum_hit_compile_cnt > 0) {
alignment_int64_array_add(maat_inst->stat->hit_cnt, maat_stream->thread_id, 1);
if (0 == hit_group_cnt) {
//hit NOT group
alignment_int64_array_add(maat_inst->stat->not_grp_hit_cnt,
maat_stream->thread_id, 1);
}
}
if (1 == maat_inst->opts.perf_on) {
@@ -1836,7 +1795,6 @@ struct maat_state *maat_state_new(struct maat *maat_inst, int thread_id)
state->maat_inst = maat_inst;
state->is_set_district = DISTRICT_FLAG_UNSET;
state->compile_NOT_flag = COMPILE_NOT_UNSET;
state->district_id = DISTRICT_ANY;
state->thread_id = thread_id;
@@ -1854,7 +1812,6 @@ void maat_state_reset(struct maat_state *state)
state->compile_table_id = 0;
state->is_set_district = DISTRICT_FLAG_UNSET;
state->compile_NOT_flag = COMPILE_NOT_UNSET;
state->district_id = DISTRICT_ANY;
state->scan_cnt = 0;
@@ -1960,36 +1917,6 @@ int maat_state_set_scan_district(struct maat_state *state, int table_id,
return 0;
}
int maat_state_enable_compile_NOT(struct maat_state *state)
{
if (NULL == state) {
return -1;
}
struct maat *maat_inst = state->maat_inst;
assert(maat_inst != NULL);
if (NULL == maat_inst->maat_rt) {
return -1;
}
assert(state->compile_NOT_flag == COMPILE_NOT_UNSET);
state->compile_NOT_flag = COMPILE_NOT_SET;
return 0;
}
int maat_state_disable_compile_NOT(struct maat_state *state)
{
if (NULL == state) {
return -1;
}
state->compile_NOT_flag = COMPILE_NOT_UNSET;
return 0;
}
int maat_state_set_scan_compile_table(struct maat_state *state, int compile_table_id)
{
if (NULL == state || compile_table_id < 0) {