Maat_set_scan_status可以设置MAAT_SET_SCAN_NO_COUNT类型参数, 指示下一次扫描不进行计数,以减少hit path的存储开销。

This commit is contained in:
zhengchao
2021-07-15 21:37:48 +08:00
parent 99e8ffb510
commit 233bc2f0ef
7 changed files with 188 additions and 11 deletions

View File

@@ -4083,6 +4083,130 @@ TEST_F(MaatCmdTest, SameScanStatusWhenClauseUpdate_TSG6419)
Maat_clean_status(&mid);
}
#define ScanStatus_Set_No_Count
TEST_F(MaatCmdTest, ScanStatusSetNoCount)
{
Maat_feather_t feather=MaatCmdTest::_shared_feather;
const char* g2c_tn="GROUP2COMPILE";
const char* compile_table_name="COMPILE";
const char* ip_table_name="IP_PLUS_CONFIG", *app_id_table_name="APP_ID";
struct Maat_rule_t compile1;
struct Maat_cmd_group2compile group11, group21, group22;
struct Maat_cmd_region region11, region21, region22;
memset(&compile1, 0, sizeof(compile1));
compile1.config_id=(int)Maat_cmd_incrby(feather, "TEST_SEQ", 1);
Maat_command_raw_set_compile(feather, MAAT_OP_ADD, &compile1, compile_table_name, NULL, 2, 0, 0);
//region11->group11--clause1-->compile1
// /
//region21->group21--clause2--/
memset(&group11, 0, sizeof(group11));
group11.group_id=Maat_command_get_new_group_id(feather);
group11.table_name=g2c_tn;
group11.compile_id=compile1.config_id;
group11.clause_index=1;
Maat_command_raw_set_group2compile(feather, MAAT_OP_ADD, &group11);
memset(&region11, 0, sizeof(region11));
region11.region_id=Maat_command_get_new_region_id(feather);
region11.region_type=REGION_IP_PLUS;
region11.table_name=ip_table_name;
region11.ip_plus_rule.addr_type=ADDR_TYPE_IPv4;
region11.ip_plus_rule.saddr_format="range";
region11.ip_plus_rule.src_ip1="192.168.3.1";
region11.ip_plus_rule.src_ip2="192.168.3.4";
region11.ip_plus_rule.sport_format="range";
region11.ip_plus_rule.src_port1=region11.ip_plus_rule.src_port2=0;
region11.ip_plus_rule.daddr_format="mask";
region11.ip_plus_rule.dst_ip1="0.0.0.0";
region11.ip_plus_rule.dst_ip2="255.255.255.255";
region11.ip_plus_rule.dport_format="range";
region11.ip_plus_rule.dst_port1=region11.ip_plus_rule.dst_port2=0;
Maat_command_raw_set_region(feather, MAAT_OP_ADD, &region11, group11.group_id);
memset(&group21, 0, sizeof(group21));
group21.group_id=Maat_command_get_new_group_id(feather);
group21.table_name=g2c_tn;
group21.compile_id=compile1.config_id;
group21.clause_index=2;
Maat_command_raw_set_group2compile(feather, MAAT_OP_ADD, &group21);
region21.region_id=Maat_command_get_new_region_id(feather);
region21.region_type=REGION_INTERVAL;
region21.table_name=app_id_table_name;
region21.interval_rule.up_boundary=region21.interval_rule.low_boundary=41;
Maat_command_raw_set_region(feather, MAAT_OP_ADD, &region21, group21.group_id);
sleep(1);
int table_id=0, ret=0, i=0;
struct Maat_rule_t result[4];
scan_status_t mid=NULL;
struct ipaddr ipv4_addr;
struct stream_tuple4_v4 v4_addr;
ipv4_addr_set(&ipv4_addr, &v4_addr, "192.168.3.2", 50001, "10.0.6.201", 80);
int scan_app_id=42;
memset(result, 0, sizeof(result));
table_id=Maat_table_register(feather, ip_table_name);
ret=Maat_scan_proto_addr(feather,table_id, &ipv4_addr, 6, result, 4, &mid,0);
EXPECT_EQ(ret, -2);
table_id=Maat_table_register(feather, app_id_table_name);
ret=Maat_scan_intval(feather, table_id, scan_app_id, result, 4, &mid, 0);
EXPECT_EQ(ret, 0);
//region11->group11--clause1-->compile1
// /
//region21->group21--clause2---/
// /
//region22->group22-/
memset(&group22, 0, sizeof(group22));
group22.group_id=Maat_command_get_new_group_id(feather);
group22.table_name=g2c_tn;
group22.compile_id=compile1.config_id;
group22.clause_index=2;
Maat_command_raw_set_group2compile(feather, MAAT_OP_ADD, &group22);
region22.region_id=Maat_command_get_new_region_id(feather);
region22.region_type=REGION_INTERVAL;
region22.table_name=app_id_table_name;
region22.interval_rule.up_boundary=region22.interval_rule.low_boundary=42;
Maat_command_raw_set_region(feather, MAAT_OP_ADD, &region22, group22.group_id);
sleep(1);
ret=Maat_scan_intval(feather, table_id, scan_app_id, result, 4, &mid, 0);
EXPECT_EQ(ret, 1);
EXPECT_EQ(result[0].config_id, compile1.config_id);
for(i=0; i<100; i++)
{
Maat_set_scan_status(feather, &mid, MAAT_SET_SCAN_NO_COUNT, NULL, 0);
ret=Maat_scan_intval(feather, table_id, scan_app_id, result, 4, &mid, 0);
}
struct Maat_hit_path_t hit_path[128];
memset(hit_path, 0, sizeof(hit_path));
int n_read=0;
n_read=Maat_get_scan_status(feather, &mid, MAAT_GET_SCAN_HIT_PATH, hit_path, sizeof(hit_path));
EXPECT_EQ(n_read, 2);
Maat_clean_status(&mid);
}
TEST_F(MaatCmdTest, CompileDelete_TSG6548)
{
Maat_feather_t feather=MaatCmdTest::_shared_feather;