diff --git a/src/entry/Maat_command.cpp b/src/entry/Maat_command.cpp index d84e5a8..3c19bbd 100644 --- a/src/entry/Maat_command.cpp +++ b/src/entry/Maat_command.cpp @@ -745,7 +745,7 @@ FULL_UPDATE: *list=s_rule_array; *update_type=CM_UPDATE_TYPE_FULL; MESA_handle_runtime_log(logger, RLOG_LV_INFO, maat_redis_monitor, - "Full update %d keys of version %lld.", rule_num, new_version); + "Full update %d keys of version %lld.", rule_num, *new_version); return rule_num ; } diff --git a/test/maat_json.json b/test/maat_json.json index 8f835c3..7fcc610 100644 --- a/test/maat_json.json +++ b/test/maat_json.json @@ -70,6 +70,32 @@ } ] }, + { + "group_name": "IPv4-composition-source-only", + "regions": [ + { + "table_type": "ip_plus", + "table_name": "IP_PLUS_CONFIG", + "table_content": { + "addr_type": "ipv4", + "saddr_format": "range", + "src_ip1": "192.168.50.24", + "src_ip2": "192.168.50.24", + "sport_format": "range", + "src_port1": "1", + "src_port2": "40000", + "daddr_format": "mask", + "dst_ip1": "0.0.0.0", + "dst_ip2": "255.255.255.0", + "dport_format": "range", + "dst_port1": "0", + "dst_port2": "65535", + "protocol": 6, + "direction": "double" + } + } + ] + }, { "group_name": "FQDN_OBJ1", "regions": [ @@ -1903,6 +1929,23 @@ "clause_index":0 } ] + }, + { + "compile_id": 181, + "service": 0, + "action": 0, + "do_blacklist": 0, + "do_log": 0, + "effective_rage": 0, + "user_region": "ipv4_composition.match", + "is_valid": "yes", + "groups": [ + { + "group_name":"IPv4-composition-source-only", + "virtual_table":"COMPOSITION_IP_SOURCE", + "not_flag":0 + } + ] } ], "plugin_table": [ diff --git a/test/perf_test_maatframe.cpp b/test/perf_test_maatframe.cpp index 57c9ead..fe7395c 100644 --- a/test/perf_test_maatframe.cpp +++ b/test/perf_test_maatframe.cpp @@ -5,6 +5,7 @@ #include #include #include +#define WAIT_FOR_EFFECTIVE_SECOND 4 void ipv4_addr_set_copy(struct ipaddr *ipv4_addr, struct stream_tuple4_v4* v4_addr, const char* src_ip, unsigned short sport, const char* dest_ip, unsigned short dport) @@ -26,7 +27,8 @@ void random_keyword_generate(char* keyword_buf, size_t sz) len=random()%(sz-1-MIN_KEYWORD_LEN)+MIN_KEYWORD_LEN; for(i=0; irule_id=atoi(table_line+column_offset); + ret=Maat_helper_read_column(table_line, 5, &column_offset, &column_len); + EXPECT_EQ(ret, 0); + ud->buffer=(char*)calloc(sizeof(char), column_len+1); + strncpy(ud->buffer, table_line+column_offset, column_len); + ud->ref_cnt=1; + *ad=ud; + (*counter)++; + return; +} +void ip_plugin_EX_free_cb(int table_id, MAAT_PLUGIN_EX_DATA* ad, long argl, void *argp) +{ + struct ip_plugin_ud* u=(struct ip_plugin_ud*)(*ad); + u->ref_cnt--; + if(u->ref_cnt>0) return; + free(u->buffer); + free(u); + *ad=NULL; +} +void ip_plugin_EX_dup_cb(int table_id, MAAT_PLUGIN_EX_DATA *to, MAAT_PLUGIN_EX_DATA *from, long argl, void *argp) +{ + struct ip_plugin_ud* u=(struct ip_plugin_ud*)(*from); + u->ref_cnt++; + *to=u; +} + +TEST_F(MaatCMDPerfTest, UpdateIPPlugin) +{ +#define IP_Plugin_EX_data + Maat_feather_t feather=MaatCMDPerfTest::_shared_feather; + + int ret=0, i=0; + int table_id=0, ip_plugin_ex_data_counter=0; + const char* table_name="TEST_IP_PLUGIN_WITH_EXDATA"; + + + const int TEST_CMD_LINE_NUM=4; + const struct Maat_cmd_line *p_line[TEST_CMD_LINE_NUM]; + struct Maat_cmd_line line_rule[TEST_CMD_LINE_NUM]; + const char* table_line[TEST_CMD_LINE_NUM]={ + "101\t4\t192.168.30.99\t192.168.30.101\tSomething-like-json\t1", + "102\t4\t192.168.30.90\t192.168.30.128\tBigger-range-should-in-the-back\t1", + "103\t6\t2001:db8:1234::\t2001:db8:1235::\tBigger-range-should-in-the-back\t1", + "104\t6\t2001:db8:1234::1\t2001:db8:1234::5210\tSomething-like-json\t1" + }; + table_id=Maat_table_register(feather, table_name); + ASSERT_GT(table_id, 0); + memset(&line_rule,0,sizeof(line_rule)); + for(i=0;i=0); + EXPECT_EQ(ip_plugin_ex_data_counter, 4); + struct ip_address ipv4, ipv6; + struct ip_plugin_ud* result[4]; + ipv4.ip_type=4; + inet_pton(AF_INET, "192.168.30.100", &(ipv4.ipv4)); + memset(&result, 0, sizeof(result)); + ret=Maat_ip_plugin_get_EX_data(feather, table_id, &ipv4, (void**)result, 4); + ASSERT_EQ(ret, 2); + EXPECT_EQ(result[0]->rule_id, 101); + EXPECT_EQ(result[1]->rule_id, 102); + for(i=0; irule_id, 104); + EXPECT_EQ(result[1]->rule_id, 103); + for(i=0; irule_id=atoi(table_line+column_offset); + ret=Maat_helper_read_column(table_line, 4, &column_offset, &column_len); + EXPECT_EQ(ret, 0); + sscanf(table_line+column_offset, "catid=%d",&ud->catid); + ud->ref_cnt=1; + *ad=ud; + (*counter)++; + return; +} +void fqdn_plugin_EX_free_cb(int table_id, MAAT_PLUGIN_EX_DATA* ad, long argl, void *argp) +{ + struct fqdn_plugin_ud* u=(struct fqdn_plugin_ud*)(*ad); + u->ref_cnt--; + if(u->ref_cnt>0) return; + free(u); + *ad=NULL; +} +void fqdn_plugin_EX_dup_cb(int table_id, MAAT_PLUGIN_EX_DATA *to, MAAT_PLUGIN_EX_DATA *from, long argl, void *argp) +{ + struct fqdn_plugin_ud* u=(struct fqdn_plugin_ud*)(*from); + u->ref_cnt++; + *to=u; +} + +TEST_F(MaatCMDPerfTest, UpdateFQDNPlugin) +{ +#define FQDN_Plugin_EX_data + Maat_feather_t feather=MaatCMDPerfTest::_shared_feather; + + int ret=0, i=0; + int table_id=0, fqdn_plugin_ex_data_counter=0; + const char* table_name="TEST_FQDN_PLUGIN_WITH_EXDATA"; + + + const int TEST_CMD_LINE_NUM=5; + const struct Maat_cmd_line *p_line[TEST_CMD_LINE_NUM]; + struct Maat_cmd_line line_rule[TEST_CMD_LINE_NUM]; + const char* table_line[TEST_CMD_LINE_NUM]={ + "201\t0\twww.example1.com\tcatid=1\t1", + "202\t1\t.example1.com\tcatid=1\t1", + "203\t0\tnews.example1.com\tcatid=2\t1", + "204\t0\tr3---sn-i3belne6.example2.com\tcatid=3\t1", + "205\t0\tr3---sn-i3belne6.example2.com\tcatid=3\t1" + }; + table_id=Maat_table_register(feather, table_name); + ASSERT_GT(table_id, 0); + memset(&line_rule,0,sizeof(line_rule)); + for(i=0;i=0); + EXPECT_EQ(fqdn_plugin_ex_data_counter, 5); + + + struct fqdn_plugin_ud* result[4]; + + ret=Maat_fqdn_plugin_get_EX_data(feather, table_id, "r3---sn-i3belne6.example2.com", (void**)result, 4); + ASSERT_EQ(ret, 2); + for(i=0; i