modify interval table and fix some test case

This commit is contained in:
root
2024-08-13 03:35:50 +00:00
parent a786103b94
commit a6c3e26577
13 changed files with 1079 additions and 1111 deletions

View File

@@ -568,12 +568,8 @@ write_interval_line(cJSON *region_json, struct iris_description *p_iris,
cmd_cnt++;
}
json_cmd[cmd_cnt].json_string = "low_boundary";
json_cmd[cmd_cnt].json_type = cJSON_Number;
cmd_cnt++;
json_cmd[cmd_cnt].json_string = "up_boundary";
json_cmd[cmd_cnt].json_type = cJSON_Number;
json_cmd[cmd_cnt].json_string = "interval";
json_cmd[cmd_cnt].json_type = cJSON_String;
cmd_cnt++;
json_cmd[cmd_cnt].json_string = "is_valid";

View File

@@ -25,8 +25,7 @@ struct interval_schema {
int item_id_column;
int group_id_column;
int district_column;
int low_boundary_column;
int up_boundary_column;
int interval_column;
int table_id;
struct table_manager *ref_tbl_mgr;
};
@@ -124,22 +123,12 @@ void *interval_schema_new(cJSON *json, struct table_manager *tbl_mgr,
}
}
custom_item = cJSON_GetObjectItem(item, "low_boundary");
custom_item = cJSON_GetObjectItem(item, "interval");
if (custom_item != NULL && custom_item->type == cJSON_Number) {
schema->low_boundary_column = custom_item->valueint;
schema->interval_column = custom_item->valueint;
} else {
log_fatal(logger, MODULE_INTERVAL,
"[%s:%d] interval table:<%s> schema has no low_boundary column",
__FUNCTION__, __LINE__, table_name);
goto error;
}
custom_item = cJSON_GetObjectItem(item, "up_boundary");
if (custom_item != NULL && custom_item->type == cJSON_Number) {
schema->up_boundary_column = custom_item->valueint;
} else {
log_fatal(logger, MODULE_INTERVAL,
"[%s:%d] interval table:<%s> schema has no up_boundary column",
"[%s:%d] interval table:<%s> schema has no interval column",
__FUNCTION__, __LINE__, table_name);
goto error;
}
@@ -287,6 +276,7 @@ interval_item_new(struct interval_schema *schema, const char *table_name,
size_t column_offset = 0;
size_t column_len = 0;
enum table_type table_type = TABLE_TYPE_INVALID;
char port_str[16] = {0};
struct interval_item *item = ALLOC(struct interval_item, 1);
int ret = get_column_pos(line, schema->item_id_column, &column_offset,
@@ -334,23 +324,20 @@ interval_item_new(struct interval_schema *schema, const char *table_name,
item->district_id = DISTRICT_ANY;
}
ret = get_column_pos(line, schema->low_boundary_column, &column_offset, &column_len);
ret = get_column_pos(line, schema->interval_column, &column_offset, &column_len);
if (ret < 0) {
log_fatal(interval_rt->logger, MODULE_INTERVAL,
"[%s:%d] interval table:<%s> has no low_boundary in line:%s",
"[%s:%d] interval table:<%s> has no interval in line:%s",
__FUNCTION__, __LINE__, table_name, line);
goto error;
}
item->low_boundary = atoi(line + column_offset);
ret = get_column_pos(line, schema->up_boundary_column, &column_offset, &column_len);
if (ret < 0) {
log_fatal(interval_rt->logger, MODULE_INTERVAL,
"[%s:%d] interval table:<%s> has no up_boundary in line:%s",
__FUNCTION__, __LINE__, table_name, line);
goto error;
memcpy(port_str, line + column_offset, column_len);
if (strchr(port_str, '-') != NULL) {
sscanf(port_str, "%d-%d", &item->low_boundary, &item->up_boundary);
} else {
item->low_boundary = atoi(port_str);
item->up_boundary = item->low_boundary;
}
item->up_boundary = atoi(line + column_offset);
return item;
error:

View File

@@ -75,12 +75,11 @@
"table_id":6,
"table_name":"NTC_UNIVERSAL_PROTO_TYPE",
"table_type":"interval",
"valid_column":5,
"valid_column":4,
"custom": {
"item_id":1,
"group_id":2,
"low_boundary":3,
"up_boundary":4
"interval":3
}
},
{

View File

@@ -93,7 +93,7 @@ TEST(ipv6_matcher_match, OneSingleIPv6Rule) {
struct ip_data data;
data.type = IPv6;
inet_pton(AF_INET6, ip1_str, data.ipv6);
inet_pton(AF_INET6, "1001:da8:205:1::101", data.ipv6);
ipv6_ntoh(data.ipv6);
struct scan_result results[MAX_ARRAY_SIZE];

View File

@@ -8841,7 +8841,7 @@ TEST_F(MaatCmd, GroupInMassCompiles) {
long long group3_id = maat_cmd_incrby(maat_inst, "SEQUENCE_GROUP", 1);
long long item3_id = maat_cmd_incrby(maat_inst, "SEQUENCE_REGION", 1);
ret = interval_table_set_line(maat_inst, table_appid, MAAT_OP_ADD, item3_id,
group3_id, 100, 100, NULL, 0);
group3_id, "100", NULL, 0);
EXPECT_EQ(ret, 1);
/* item_url1 -> group1 -> compile[0 ~ COMPILE_ID_NUMS]
@@ -10309,7 +10309,7 @@ TEST_F(MaatCmd, SameScanStatusWhenClauseUpdate_TSG6419) {
long long item21_id = maat_cmd_incrby(maat_inst, "SEQUENCE_REGION", 1);
ret = interval_table_set_line(maat_inst, app_id_table_name, MAAT_OP_ADD,
item21_id, group21_id, 31, 31, NULL, 0);
item21_id, group21_id, "31", NULL, 0);
EXPECT_EQ(ret, 1);
sleep(WAIT_FOR_EFFECTIVE_S * 2);
@@ -10356,7 +10356,7 @@ TEST_F(MaatCmd, SameScanStatusWhenClauseUpdate_TSG6419) {
long long item22_id = maat_cmd_incrby(maat_inst, "SEQUENCE_REGION", 1);
ret = interval_table_set_line(maat_inst, app_id_table_name, MAAT_OP_ADD,
item22_id, group22_id, 32, 32, NULL, 0);
item22_id, group22_id, "32", NULL, 0);
EXPECT_EQ(ret, 1);
sleep(WAIT_FOR_EFFECTIVE_S * 2);
@@ -10418,7 +10418,7 @@ TEST_F(MaatCmd, GroupEdit) {
long long item21_id = maat_cmd_incrby(maat_inst, "SEQUENCE_REGION", 1);
ret = interval_table_set_line(maat_inst, app_id_table_name, MAAT_OP_ADD,
item21_id, group21_id, 41, 41, NULL, 0);
item21_id, group21_id, "41", NULL, 0);
EXPECT_EQ(ret, 1);
sleep(WAIT_FOR_EFFECTIVE_S * 2);
@@ -10458,10 +10458,11 @@ TEST_F(MaatCmd, GroupEdit) {
item21 -> group21 -> clause2 _/
item22 -> /
*/
char scan_app_id_str[8] = {0};
snprintf(scan_app_id_str, sizeof(scan_app_id_str), "%d", scan_app_id);
long long item22_id = maat_cmd_incrby(maat_inst, "SEQUENCE_REGION", 1);
ret = interval_table_set_line(maat_inst, app_id_table_name, MAAT_OP_ADD,
item22_id, group21_id, scan_app_id,
scan_app_id, NULL, 0);
item22_id, group21_id, scan_app_id_str, NULL, 0);
EXPECT_EQ(ret, 1);
sleep(WAIT_FOR_EFFECTIVE_S);
@@ -10497,8 +10498,7 @@ TEST_F(MaatCmd, GroupEdit) {
item21 -> group21 -> clause2 _/
*/
ret = interval_table_set_line(maat_inst, app_id_table_name, MAAT_OP_DEL,
item22_id, group21_id, scan_app_id,
scan_app_id, NULL, 0);
item22_id, group21_id, scan_app_id_str, NULL, 0);
EXPECT_EQ(ret, 1);
sleep(WAIT_FOR_EFFECTIVE_S);

View File

@@ -91,8 +91,10 @@ test_add_integer_command(struct maat *maat_inst, const char *table_name,
EXPECT_EQ(ret, 1);
long long item_id = maat_cmd_incrby(maat_inst, "SEQUENCE_REGION", 1);
char interval_range_str[64] = {0};
snprintf(interval_range_str, sizeof(interval_range_str), "%d-%d", low_boundary, up_boundary);
ret = interval_table_set_line(maat_inst, table_name, MAAT_OP_ADD, item_id,
group_id, low_boundary, up_boundary, NULL, 0);
group_id, interval_range_str, NULL, 0);
EXPECT_EQ(ret, 1);
}

View File

@@ -137,8 +137,7 @@
"table_type": "interval_plus",
"table_content": {
"district": "fqdn_cat_id",
"low_boundary": 1724,
"up_boundary": 1724
"interval": "1724"
}
}
]
@@ -297,8 +296,7 @@
"table_name": "CONTENT_SIZE",
"table_type": "interval",
"table_content": {
"low_boundary": 100,
"up_boundary": 500
"interval": "100-500"
}
}
]
@@ -368,8 +366,7 @@
"table_name": "CONTENT_SIZE",
"table_type": "interval",
"table_content": {
"low_boundary": 2014,
"up_boundary": 2016
"interval": "2014-2016"
}
}
]
@@ -1944,8 +1941,7 @@
"table_type": "interval_plus",
"table_content": {
"district": "interval.plus",
"low_boundary": 2020,
"up_boundary": 2020
"interval": "2020"
}
}
]
@@ -3039,8 +3035,7 @@
"table_type": "interval_plus",
"table_content": {
"district": "interval.plus",
"low_boundary": 2020,
"up_boundary": 2020
"interval": "2020"
}
}
]
@@ -3116,8 +3111,7 @@
"table_name": "INTEGER_PERF_CONFIG",
"table_type": "interval",
"table_content": {
"low_boundary": 3000,
"up_boundary": 3000
"interval": "3000"
}
}
]
@@ -3333,8 +3327,7 @@
"table_name": "CONTENT_SIZE",
"table_type": "interval",
"table_content": {
"low_boundary": 3000,
"up_boundary": 3000
"interval": "3000"
}
}
]

View File

@@ -1,24 +1,24 @@
0000000023
939 922 21 21 1
978 963 21 21 1
743 727 20 20 1
968 951 21 21 1
996 981 5 5 1
853 836 10 10 1
629 613 20 20 1
620 604 20 20 1
626 610 20 20 1
998 983 4 4 1
864 847 7 7 1
932 915 21 21 1
987 972 21 21 1
866 849 5 5 1
861 844 7 7 1
740 724 20 20 1
993 978 21 21 1
848 831 6 6 1
1001 986 21 21 1
850 833 6 6 1
868 851 5 5 1
623 607 20 20 1
975 960 21 21 1
939 922 21 1
978 963 21 1
743 727 20 1
968 951 21 1
996 981 5 1
853 836 10 1
629 613 20 1
620 604 20 1
626 610 20 1
998 983 4 1
864 847 7 1
932 915 21 1
987 972 21 1
866 849 5 1
861 844 7 1
740 724 20 1
993 978 21 1
848 831 6 1
1001 986 21 1
850 833 6 1
868 851 5 1
623 607 20 1
975 960 21 1

View File

@@ -174,12 +174,11 @@
"table_id":13,
"table_name":"CONTENT_SIZE",
"table_type":"interval",
"valid_column":5,
"valid_column":4,
"custom": {
"item_id":1,
"group_id":2,
"low_boundary":3,
"up_boundary":4
"interval":3
}
},
{
@@ -417,13 +416,12 @@
"table_id":35,
"table_name":"INTERGER_PLUS",
"table_type":"interval_plus",
"valid_column":6,
"valid_column":5,
"custom": {
"item_id":1,
"group_id":2,
"district":3,
"low_boundary":4,
"up_boundary":5
"interval":4
}
},
{
@@ -442,12 +440,11 @@
"table_id":37,
"table_name":"APP_ID",
"table_type":"interval",
"valid_column":5,
"valid_column":4,
"custom": {
"item_id":1,
"group_id":2,
"low_boundary":3,
"up_boundary":4
"interval":3
}
},
{
@@ -468,12 +465,11 @@
"table_id":39,
"table_name":"EMPTY_INTERGER",
"table_type":"interval",
"valid_column":5,
"valid_column":4,
"custom": {
"item_id":1,
"group_id":2,
"low_boundary":3,
"up_boundary":4
"interval":3
}
},
{
@@ -572,12 +568,11 @@
"table_id":48,
"table_name":"INTEGER_PERF_CONFIG",
"table_type":"interval",
"valid_column":5,
"valid_column":4,
"custom": {
"item_id":1,
"group_id":2,
"low_boundary":3,
"up_boundary":4
"interval":3
}
},
{

View File

@@ -242,8 +242,7 @@ int expr_table_set_line(struct maat *maat_inst, const char *table_name,
int interval_table_set_line(struct maat *maat_inst, const char *table_name,
enum maat_operation op, long long item_id, long long group_id,
unsigned int low_boundary, unsigned int up_boundary,
const char *district, int expire_after)
const char *port_str, const char *district, int expire_after)
{
char table_line[1024] = {0};
int table_id = maat_get_table_id(maat_inst, table_name);
@@ -257,11 +256,11 @@ int interval_table_set_line(struct maat *maat_inst, const char *table_name,
table_type == TABLE_TYPE_INTERVAL_PLUS);
if (table_type == TABLE_TYPE_INTERVAL_PLUS) {
sprintf(table_line, "%lld\t%lld\t%s\t%u\t%u\t%d",
item_id, group_id, district, low_boundary, up_boundary, op);
sprintf(table_line, "%lld\t%lld\t%s\t%s\t%d",
item_id, group_id, district, port_str, op);
} else {
sprintf(table_line, "%lld\t%lld\t%u\t%u\t%d",
item_id, group_id, low_boundary, up_boundary, op);
sprintf(table_line, "%lld\t%lld\t%s\t%d",
item_id, group_id, port_str, op);
}
struct maat_cmd_line line_rule;

View File

@@ -36,9 +36,8 @@ int expr_table_set_line(struct maat *maat_inst, const char *table_name,
int interval_table_set_line(struct maat *maat_inst, const char *table_name,
enum maat_operation op, long long item_id,
long long group_id, unsigned int low_boundary,
unsigned int up_boundary, const char *district,
int expire_after);
long long group_id, const char *port_str,
const char *district, int expire_after);
int ip_table_set_line(struct maat *maat_inst, const char *table_name,
enum maat_operation op, long long item_id,

View File

@@ -3,12 +3,10 @@
"table_id": 42,
"table_name":"TSG_IP_LOCATION_BUILT_IN",
"table_type":"ip_plugin",
"valid_column":18,
"valid_column":17,
"custom": {
"item_id":1,
"ip_type":3,
"start_ip":4,
"end_ip":5
"ip":4
}
},
{

File diff suppressed because it is too large Load Diff