Feature/scan ip port together support endpoint object
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
set(MAAT_FRAME_MAJOR_VERSION 4)
|
||||
set(MAAT_FRAME_MINOR_VERSION 0)
|
||||
set(MAAT_FRAME_PATCH_VERSION 14)
|
||||
set(MAAT_FRAME_MINOR_VERSION 1)
|
||||
set(MAAT_FRAME_PATCH_VERSION 0)
|
||||
set(MAAT_FRAME_VERSION ${MAAT_FRAME_MAJOR_VERSION}.${MAAT_FRAME_MINOR_VERSION}.${MAAT_FRAME_PATCH_VERSION})
|
||||
|
||||
message(STATUS "Maat Frame, Version: ${MAAT_FRAME_VERSION}")
|
||||
|
||||
@@ -42,7 +42,7 @@ long long ip_runtime_ipv6_rule_count(void *ip_runtime);
|
||||
|
||||
/* ip runtime scan API */
|
||||
int ip_runtime_scan(struct ip_runtime *ip_rt, int thread_id, int ip_type,
|
||||
uint8_t *ip_addr, int vtable_id, struct maat_state *state);
|
||||
uint8_t *ip_addr, int port, int vtable_id, struct maat_state *state);
|
||||
|
||||
void ip_runtime_perf_stat(struct ip_runtime *ip_rt, struct timespec *start,
|
||||
struct timespec *end, int thread_id);
|
||||
|
||||
@@ -22,6 +22,7 @@ extern "C"
|
||||
#include "log/log.h"
|
||||
#include "hiredis/hiredis.h"
|
||||
#include "maat_command.h"
|
||||
#include "maat_limits.h"
|
||||
#include "uthash/uthash.h"
|
||||
|
||||
struct foreign_key {
|
||||
|
||||
@@ -126,7 +126,6 @@ struct maat_options {
|
||||
int maat_json_is_gzipped;
|
||||
|
||||
int gc_timeout_ms;
|
||||
int rule_effect_interval_ms;
|
||||
int rule_update_checking_interval_ms;
|
||||
|
||||
enum maat_expr_engine expr_engine;
|
||||
|
||||
@@ -29,7 +29,7 @@ enum table_type {
|
||||
TABLE_TYPE_FLAG_PLUS,
|
||||
TABLE_TYPE_EXPR,
|
||||
TABLE_TYPE_EXPR_PLUS,
|
||||
TABLE_TYPE_IP_PLUS,
|
||||
TABLE_TYPE_IP,
|
||||
TABLE_TYPE_INTERVAL,
|
||||
TABLE_TYPE_INTERVAL_PLUS,
|
||||
TABLE_TYPE_PLUGIN,
|
||||
|
||||
@@ -150,7 +150,7 @@ static int set_iris_descriptor(const char *json_file, cJSON *json,
|
||||
|
||||
maat_kv_register(iris_cfg->str2int_map, "flag", TABLE_TYPE_FLAG);
|
||||
maat_kv_register(iris_cfg->str2int_map, "flag_plus", TABLE_TYPE_FLAG_PLUS);
|
||||
maat_kv_register(iris_cfg->str2int_map, "ip_plus", TABLE_TYPE_IP_PLUS);
|
||||
maat_kv_register(iris_cfg->str2int_map, "ip", TABLE_TYPE_IP);
|
||||
maat_kv_register(iris_cfg->str2int_map, "string", TABLE_TYPE_EXPR);
|
||||
maat_kv_register(iris_cfg->str2int_map, "expr", TABLE_TYPE_EXPR);
|
||||
maat_kv_register(iris_cfg->str2int_map, "expr_plus", TABLE_TYPE_EXPR_PLUS);
|
||||
@@ -503,7 +503,7 @@ static int write_expr_line(cJSON *region_json, struct iris_description *p_iris,
|
||||
json_cmd, cmd_cnt, table, logger);
|
||||
}
|
||||
|
||||
static int write_ip_plus_line(cJSON *region_json, struct iris_description *p_iris,
|
||||
static int write_ip_line(cJSON *region_json, struct iris_description *p_iris,
|
||||
struct iris_table *table, struct log_handle *logger)
|
||||
{
|
||||
struct translate_command json_cmd[MAX_COLUMN_NUM];
|
||||
@@ -541,6 +541,12 @@ static int write_ip_plus_line(cJSON *region_json, struct iris_description *p_iri
|
||||
json_cmd[cmd_cnt].default_string = "255.255.255.255";
|
||||
cmd_cnt++;
|
||||
|
||||
json_cmd[cmd_cnt].json_string = "port";
|
||||
json_cmd[cmd_cnt].json_type = cJSON_String;
|
||||
json_cmd[cmd_cnt].empty_allowed = 1;
|
||||
json_cmd[cmd_cnt].default_string = "0-65535";
|
||||
cmd_cnt++;
|
||||
|
||||
json_cmd[cmd_cnt].json_string = "is_valid";
|
||||
json_cmd[cmd_cnt].json_type = cJSON_Number;
|
||||
cmd_cnt++;
|
||||
@@ -642,8 +648,8 @@ static int write_region_rule(cJSON *region_json, int compile_id, int group_id,
|
||||
case TABLE_TYPE_EXPR_PLUS:
|
||||
ret = write_expr_line(table_content, p_iris, table_info, logger);
|
||||
break;
|
||||
case TABLE_TYPE_IP_PLUS:
|
||||
ret = write_ip_plus_line(table_content, p_iris, table_info, logger);
|
||||
case TABLE_TYPE_IP:
|
||||
ret = write_ip_line(table_content, p_iris, table_info, logger);
|
||||
break;
|
||||
case TABLE_TYPE_INTERVAL:
|
||||
case TABLE_TYPE_INTERVAL_PLUS:
|
||||
@@ -701,7 +707,7 @@ static int write_group2group_line(int group_id, UT_array *incl_sub_group_ids,
|
||||
UT_array *excl_sub_group_ids,
|
||||
struct iris_description *p_iris)
|
||||
{
|
||||
char buff[MAX_BUFF_LEN] = {0};
|
||||
char buff[MAX_BUFF_LEN*4] = {0};
|
||||
struct iris_table *table = p_iris->group2group_table;
|
||||
if (NULL == table) {
|
||||
return -1;
|
||||
|
||||
@@ -72,7 +72,6 @@ struct maat_options* maat_options_new(void)
|
||||
|
||||
options->nr_worker_thread = 1;
|
||||
options->deferred_load_on = 0;
|
||||
options->rule_effect_interval_ms = 60 * 1000;
|
||||
options->rule_update_checking_interval_ms = 1 * 1000;
|
||||
options->gc_timeout_ms = 10 * 1000;
|
||||
options->input_mode = DATA_SOURCE_NONE;
|
||||
@@ -111,16 +110,6 @@ int maat_options_set_accept_tags(struct maat_options *opts, const char *accept_t
|
||||
return 0;
|
||||
}
|
||||
|
||||
int maat_options_set_rule_effect_interval_ms(struct maat_options *opts, int interval_ms)
|
||||
{
|
||||
if (NULL == opts || interval_ms < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
opts->rule_effect_interval_ms = interval_ms;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int maat_options_set_rule_update_checking_interval_ms(struct maat_options *opts, int interval_ms)
|
||||
{
|
||||
if (NULL == opts || interval_ms < 0) {
|
||||
@@ -387,8 +376,7 @@ struct maat *maat_new(struct maat_options *opts, const char *table_info_path)
|
||||
maat_inst->maat_version = 0;
|
||||
maat_inst->last_full_version = 0;
|
||||
|
||||
garbage_gc_timeout_s = (maat_inst->opts.rule_effect_interval_ms / 1000) +
|
||||
(maat_inst->opts.gc_timeout_ms / 1000);
|
||||
garbage_gc_timeout_s = MAX(1, (maat_inst->opts.gc_timeout_ms / 1000) );
|
||||
|
||||
if (maat_inst->opts.input_mode != DATA_SOURCE_IRIS_FILE &&
|
||||
maat_inst->opts.input_mode != DATA_SOURCE_JSON_FILE &&
|
||||
@@ -429,6 +417,7 @@ struct maat *maat_new(struct maat_options *opts, const char *table_info_path)
|
||||
pthread_create(&(maat_inst->cfg_mon_thread), NULL, rule_monitor_loop, (void *)maat_inst);
|
||||
|
||||
return maat_inst;
|
||||
|
||||
failed:
|
||||
_maat_free(maat_inst);
|
||||
return NULL;
|
||||
@@ -1079,12 +1068,12 @@ static int interval_scan(struct table_manager *tbl_mgr, int thread_id, long long
|
||||
return group_hit_cnt;
|
||||
}
|
||||
|
||||
static int ipv4_scan(struct table_manager *tbl_mgr, int thread_id, uint32_t ip_addr,
|
||||
static int ipv4_scan(struct table_manager *tbl_mgr, int thread_id, uint32_t ip_addr, int port,
|
||||
int phy_table_id, int vtable_id, struct maat_state *state)
|
||||
{
|
||||
|
||||
enum table_type table_type = table_manager_get_table_type(tbl_mgr, phy_table_id);
|
||||
if (table_type != TABLE_TYPE_IP_PLUS) {
|
||||
if (table_type != TABLE_TYPE_IP) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1094,7 +1083,7 @@ static int ipv4_scan(struct table_manager *tbl_mgr, int thread_id, uint32_t ip_a
|
||||
}
|
||||
|
||||
int group_hit_cnt = ip_runtime_scan((struct ip_runtime *)ip_rt, thread_id, IPv4,
|
||||
(uint8_t *)&ip_addr, vtable_id, state);
|
||||
(uint8_t *)&ip_addr, port, vtable_id, state);
|
||||
if (group_hit_cnt <= 0) {
|
||||
return group_hit_cnt;
|
||||
}
|
||||
@@ -1105,12 +1094,12 @@ static int ipv4_scan(struct table_manager *tbl_mgr, int thread_id, uint32_t ip_a
|
||||
}
|
||||
|
||||
static int ipv6_scan(struct table_manager *tbl_mgr, int thread_id,
|
||||
uint8_t *ip_addr, int phy_table_id, int vtable_id,
|
||||
uint8_t *ip_addr, int port, int phy_table_id, int vtable_id,
|
||||
struct maat_state *state)
|
||||
{
|
||||
|
||||
enum table_type table_type = table_manager_get_table_type(tbl_mgr, phy_table_id);
|
||||
if (table_type != TABLE_TYPE_IP_PLUS) {
|
||||
if (table_type != TABLE_TYPE_IP) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1120,7 +1109,7 @@ static int ipv6_scan(struct table_manager *tbl_mgr, int thread_id,
|
||||
}
|
||||
|
||||
int group_hit_cnt = ip_runtime_scan((struct ip_runtime *)ip_rt, thread_id, IPv6,
|
||||
ip_addr, vtable_id, state);
|
||||
ip_addr, port, vtable_id, state);
|
||||
if (group_hit_cnt <= 0) {
|
||||
return group_hit_cnt;
|
||||
}
|
||||
@@ -1349,7 +1338,7 @@ int maat_scan_integer(struct maat *maat_inst, int table_id,
|
||||
}
|
||||
}
|
||||
|
||||
int maat_scan_ipv4(struct maat *maat_inst, int table_id, uint32_t ip_addr,
|
||||
int maat_scan_ipv4_port(struct maat *maat_inst, int table_id, uint32_t ip_addr, int port,
|
||||
long long *results, size_t n_result, size_t *n_hit_result,
|
||||
struct maat_state *state)
|
||||
{
|
||||
@@ -1387,13 +1376,13 @@ int maat_scan_ipv4(struct maat *maat_inst, int table_id, uint32_t ip_addr,
|
||||
}
|
||||
|
||||
table_type = table_manager_get_table_type(maat_inst->tbl_mgr, phy_table_id);
|
||||
if (table_type != TABLE_TYPE_IP_PLUS) {
|
||||
if (table_type != TABLE_TYPE_IP) {
|
||||
maat_inst->stat->scan_err_cnt++;
|
||||
return MAAT_SCAN_ERR;
|
||||
}
|
||||
|
||||
alignment_int64_array_add(maat_inst->stat->thread_call_cnt, state->thread_id, 1);
|
||||
int hit_group_cnt = ipv4_scan(maat_inst->tbl_mgr, state->thread_id, ip_addr,
|
||||
int hit_group_cnt = ipv4_scan(maat_inst->tbl_mgr, state->thread_id, ip_addr, port,
|
||||
phy_table_id, vtable_id, state);
|
||||
if (hit_group_cnt < 0) {
|
||||
maat_inst->stat->scan_err_cnt++;
|
||||
@@ -1434,7 +1423,7 @@ int maat_scan_ipv4(struct maat *maat_inst, int table_id, uint32_t ip_addr,
|
||||
}
|
||||
}
|
||||
|
||||
int maat_scan_ipv6(struct maat *maat_inst, int table_id, uint8_t *ip_addr,
|
||||
int maat_scan_ipv6_port(struct maat *maat_inst, int table_id, uint8_t *ip_addr, int port,
|
||||
long long *results, size_t n_result, size_t *n_hit_result,
|
||||
struct maat_state *state)
|
||||
{
|
||||
@@ -1472,13 +1461,13 @@ int maat_scan_ipv6(struct maat *maat_inst, int table_id, uint8_t *ip_addr,
|
||||
}
|
||||
|
||||
table_type = table_manager_get_table_type(maat_inst->tbl_mgr, phy_table_id);
|
||||
if (table_type != TABLE_TYPE_IP_PLUS) {
|
||||
if (table_type != TABLE_TYPE_IP) {
|
||||
maat_inst->stat->scan_err_cnt++;
|
||||
return MAAT_SCAN_ERR;
|
||||
}
|
||||
|
||||
alignment_int64_array_add(maat_inst->stat->thread_call_cnt, state->thread_id, 1);
|
||||
int hit_group_cnt = ipv6_scan(maat_inst->tbl_mgr, state->thread_id, ip_addr,
|
||||
int hit_group_cnt = ipv6_scan(maat_inst->tbl_mgr, state->thread_id, ip_addr, port,
|
||||
phy_table_id, vtable_id, state);
|
||||
if (hit_group_cnt < 0) {
|
||||
maat_inst->stat->scan_err_cnt++;
|
||||
@@ -1518,7 +1507,19 @@ int maat_scan_ipv6(struct maat *maat_inst, int table_id, uint8_t *ip_addr,
|
||||
return MAAT_SCAN_OK;
|
||||
}
|
||||
}
|
||||
|
||||
#define PORT_IGNORED -1
|
||||
inline int maat_scan_ipv6(struct maat *instance, int table_id, uint8_t *ip_addr,
|
||||
long long *results, size_t n_result, size_t *n_hit_result,
|
||||
struct maat_state *state)
|
||||
{
|
||||
return maat_scan_ipv6_port(instance, table_id, ip_addr, PORT_IGNORED, results, n_result, n_hit_result, state);
|
||||
}
|
||||
inline int maat_scan_ipv4(struct maat *instance, int table_id, uint32_t ip_addr,
|
||||
long long *results, size_t n_result, size_t *n_hit_result,
|
||||
struct maat_state *state)
|
||||
{
|
||||
return maat_scan_ipv4_port(instance, table_id, ip_addr, PORT_IGNORED, results, n_result, n_hit_result, state);
|
||||
}
|
||||
int maat_scan_string(struct maat *maat_inst, int table_id,
|
||||
const char *data, size_t data_len,
|
||||
long long *results, size_t n_result,
|
||||
|
||||
@@ -31,6 +31,7 @@ struct ip_schema {
|
||||
int ip1_column;
|
||||
int ip2_column;
|
||||
int table_id;
|
||||
int port_column;
|
||||
struct table_manager *ref_tbl_mgr;
|
||||
};
|
||||
|
||||
@@ -53,6 +54,8 @@ struct ip_item {
|
||||
struct ipv6_item_rule ipv6;
|
||||
};
|
||||
enum ip_format ip_format;
|
||||
int port_start;
|
||||
int port_end;
|
||||
};
|
||||
|
||||
struct ip_runtime {
|
||||
@@ -158,6 +161,12 @@ void *ip_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
goto error;
|
||||
}
|
||||
|
||||
custom_item = cJSON_GetObjectItem(item, "port");
|
||||
if (custom_item != NULL && custom_item->type == cJSON_Number) {
|
||||
ip_schema->port_column = custom_item->valueint;
|
||||
} else {
|
||||
ip_schema->port_column = 0;
|
||||
}
|
||||
ip_schema->ref_tbl_mgr = tbl_mgr;
|
||||
return ip_schema;
|
||||
error:
|
||||
@@ -275,7 +284,33 @@ ip_item_new(struct ip_schema *ip_schema, const char *table_name,
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
if(ip_schema->port_column>0)
|
||||
{
|
||||
ret = get_column_pos(line, ip_schema->port_column, &column_offset,
|
||||
&column_len);
|
||||
if (ret < 0) {
|
||||
log_fatal(logger, MODULE_IP,
|
||||
"[%s:%d] ip table:<%s> has no port in line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, line);
|
||||
goto error;
|
||||
}
|
||||
char port_range[20] = {0};
|
||||
memcpy(port_range, (line + column_offset), column_len);
|
||||
|
||||
//port range is port or port_start-port_end
|
||||
if(strchr(port_range,'-')!=NULL){
|
||||
char *port_start = strtok(port_range,"-");
|
||||
char *port_end = strtok(NULL,"-");
|
||||
ip_item->port_start = atoi(port_start);
|
||||
ip_item->port_end = atoi(port_end);
|
||||
} else {
|
||||
ip_item->port_start = atoi(port_range);
|
||||
ip_item->port_end = atoi(port_range);
|
||||
}
|
||||
} else {
|
||||
ip_item->port_start = 0;
|
||||
ip_item->port_end = 65535;
|
||||
}
|
||||
return ip_item;
|
||||
error:
|
||||
FREE(ip_item);
|
||||
@@ -306,7 +341,6 @@ void *ip_runtime_new(void *ip_schema, size_t max_thread_num,
|
||||
}
|
||||
|
||||
struct ip_runtime *ip_rt = ALLOC(struct ip_runtime, 1);
|
||||
|
||||
ip_rt->item_hash = rcu_hash_new(ip_item_free_cb, NULL, 0);
|
||||
ip_rt->n_worker_thread = max_thread_num;
|
||||
ip_rt->ref_garbage_bin = garbage_bin;
|
||||
@@ -561,7 +595,7 @@ long long ip_runtime_ipv6_rule_count(void *ip_runtime)
|
||||
}
|
||||
|
||||
int ip_runtime_scan(struct ip_runtime *ip_rt, int thread_id, int ip_type,
|
||||
uint8_t *ip_addr, int vtable_id, struct maat_state *state)
|
||||
uint8_t *ip_addr, int port, int vtable_id, struct maat_state *state)
|
||||
{
|
||||
if (0 == ip_rt->rule_num) {
|
||||
//empty ip table
|
||||
@@ -608,7 +642,16 @@ int ip_runtime_scan(struct ip_runtime *ip_rt, int thread_id, int ip_type,
|
||||
// item config has been deleted
|
||||
continue;
|
||||
}
|
||||
|
||||
if(port < 0 && ip_item->port_start!=0 && ip_item->port_end!=65535)
|
||||
{
|
||||
//If port is not speicified, an IP should NOT match rules with port range.
|
||||
continue;
|
||||
}
|
||||
if(port >= 0 && (port<ip_item->port_start || port>ip_item->port_end)){
|
||||
//If port is specified, the port should within the port range.
|
||||
continue;
|
||||
}
|
||||
|
||||
hit_maat_items[real_hit_item_cnt].item_id = ip_results[i].rule_id;
|
||||
hit_maat_items[real_hit_item_cnt].group_id = ip_item->group_id;
|
||||
real_hit_item_cnt++;
|
||||
|
||||
158
src/maat_rule.c
158
src/maat_rule.c
@@ -452,94 +452,82 @@ void *rule_monitor_loop(void *arg)
|
||||
}
|
||||
|
||||
usleep(maat_inst->opts.rule_update_checking_interval_ms * 1000);
|
||||
|
||||
if (0 == pthread_mutex_trylock(&(maat_inst->background_update_mutex))) {
|
||||
switch (maat_inst->opts.input_mode) {
|
||||
case DATA_SOURCE_REDIS:
|
||||
redis_monitor_traverse(maat_inst->maat_version,
|
||||
&(maat_inst->opts.redis_ctx),
|
||||
maat_start_cb, maat_update_cb, maat_finish_cb,
|
||||
maat_inst);
|
||||
break;
|
||||
case DATA_SOURCE_IRIS_FILE:
|
||||
config_monitor_traverse(maat_inst->maat_version,
|
||||
maat_inst->opts.iris_ctx.inc_idx_dir,
|
||||
maat_start_cb, maat_update_cb, maat_finish_cb,
|
||||
maat_inst, maat_inst->opts.decrypt_key,
|
||||
maat_inst->logger);
|
||||
break;
|
||||
case DATA_SOURCE_JSON_FILE:
|
||||
memset(md5_tmp, 0, sizeof(md5_tmp));
|
||||
stat(maat_inst->opts.json_ctx.json_file, &attrib);
|
||||
if (memcmp(&attrib.st_ctim, &(maat_inst->opts.json_ctx.last_md5_time),
|
||||
sizeof(attrib.st_ctim))) {
|
||||
maat_inst->opts.json_ctx.last_md5_time = attrib.st_ctim;
|
||||
md5_file(maat_inst->opts.json_ctx.json_file, md5_tmp);
|
||||
if (0 != strcmp(md5_tmp, maat_inst->opts.json_ctx.effective_json_md5)) {
|
||||
ret = load_maat_json_file(maat_inst, maat_inst->opts.json_ctx.json_file,
|
||||
err_str, sizeof(err_str));
|
||||
if (ret < 0) {
|
||||
log_fatal(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"[%s:%d] Maat re-initiate with JSON file %s (md5=%s)failed: %s\n",
|
||||
__FUNCTION__, __LINE__, maat_inst->opts.json_ctx.json_file,
|
||||
md5_tmp, err_str);
|
||||
} else {
|
||||
config_monitor_traverse(0, maat_inst->opts.json_ctx.iris_file,
|
||||
maat_start_cb, maat_update_cb, maat_finish_cb,
|
||||
maat_inst, maat_inst->opts.decrypt_key,
|
||||
maat_inst->logger);
|
||||
log_info(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"Maat re-initiate with JSON file %s success, md5: %s\n",
|
||||
maat_inst->opts.json_ctx.json_file, md5_tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (maat_inst->creating_maat_rt != NULL) {
|
||||
struct maat_runtime *old_maat_rt = maat_inst->maat_rt;
|
||||
maat_inst->maat_rt = maat_inst->creating_maat_rt;
|
||||
|
||||
if (old_maat_rt != NULL) {
|
||||
if (maat_inst->maat_rt->version > old_maat_rt->version) {
|
||||
log_info(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"Maat version updated %lld -> %lld\n",
|
||||
old_maat_rt->version, maat_inst->maat_rt->version);
|
||||
} else {
|
||||
log_info(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"Maat version roll back %lld -> %lld\n",
|
||||
old_maat_rt->version, maat_inst->maat_rt->version);
|
||||
pthread_mutex_lock(&(maat_inst->background_update_mutex));
|
||||
|
||||
switch (maat_inst->opts.input_mode) {
|
||||
case DATA_SOURCE_REDIS:
|
||||
redis_monitor_traverse(maat_inst->maat_version,
|
||||
&(maat_inst->opts.redis_ctx),
|
||||
maat_start_cb, maat_update_cb, maat_finish_cb,
|
||||
maat_inst);
|
||||
break;
|
||||
case DATA_SOURCE_IRIS_FILE:
|
||||
config_monitor_traverse(maat_inst->maat_version,
|
||||
maat_inst->opts.iris_ctx.inc_idx_dir,
|
||||
maat_start_cb, maat_update_cb, maat_finish_cb,
|
||||
maat_inst, maat_inst->opts.decrypt_key,
|
||||
maat_inst->logger);
|
||||
break;
|
||||
case DATA_SOURCE_JSON_FILE:
|
||||
memset(md5_tmp, 0, sizeof(md5_tmp));
|
||||
stat(maat_inst->opts.json_ctx.json_file, &attrib);
|
||||
if (memcmp(&attrib.st_ctim, &(maat_inst->opts.json_ctx.last_md5_time),
|
||||
sizeof(attrib.st_ctim))) {
|
||||
maat_inst->opts.json_ctx.last_md5_time = attrib.st_ctim;
|
||||
md5_file(maat_inst->opts.json_ctx.json_file, md5_tmp);
|
||||
if (0 != strcmp(md5_tmp, maat_inst->opts.json_ctx.effective_json_md5)) {
|
||||
ret = load_maat_json_file(maat_inst, maat_inst->opts.json_ctx.json_file,
|
||||
err_str, sizeof(err_str));
|
||||
if (ret < 0) {
|
||||
log_fatal(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"[%s:%d] Maat re-initiate with JSON file %s (md5=%s)failed: %s\n",
|
||||
__FUNCTION__, __LINE__, maat_inst->opts.json_ctx.json_file,
|
||||
md5_tmp, err_str);
|
||||
} else {
|
||||
config_monitor_traverse(0, maat_inst->opts.json_ctx.iris_file,
|
||||
maat_start_cb, maat_update_cb, maat_finish_cb,
|
||||
maat_inst, maat_inst->opts.decrypt_key,
|
||||
maat_inst->logger);
|
||||
log_info(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"Maat re-initiate with JSON file %s success, md5: %s\n",
|
||||
maat_inst->opts.json_ctx.json_file, md5_tmp);
|
||||
}
|
||||
}
|
||||
|
||||
maat_inst->stat->zombie_rs_stream +=
|
||||
alignment_int64_array_sum(old_maat_rt->ref_cnt,
|
||||
maat_inst->opts.nr_worker_thread);
|
||||
maat_garbage_bagging(maat_inst->garbage_bin, old_maat_rt, NULL,
|
||||
garbage_maat_runtime_destroy);
|
||||
}
|
||||
|
||||
maat_inst->creating_maat_rt = NULL;
|
||||
maat_inst->maat_version = maat_inst->maat_rt->version;
|
||||
maat_inst->last_full_version = maat_inst->maat_rt->version;
|
||||
}
|
||||
|
||||
if (maat_inst->maat_rt != NULL) {
|
||||
time_t time_window = time(NULL) - maat_inst->maat_rt->last_update_time;
|
||||
|
||||
if (time_window >= maat_inst->opts.rule_effect_interval_ms / 1000) {
|
||||
maat_runtime_commit(maat_inst->maat_rt, MAAT_UPDATE_TYPE_INC,
|
||||
maat_inst->maat_rt->version, maat_inst->logger);
|
||||
log_info(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"Actual update config version %u, %d entries load to maat runtime.",
|
||||
maat_inst->maat_rt->version, maat_inst->maat_rt->rule_num);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&(maat_inst->background_update_mutex));
|
||||
}
|
||||
if (maat_inst->creating_maat_rt != NULL) {
|
||||
struct maat_runtime *old_maat_rt = maat_inst->maat_rt;
|
||||
maat_inst->maat_rt = maat_inst->creating_maat_rt;
|
||||
|
||||
if (old_maat_rt != NULL) {
|
||||
if (maat_inst->maat_rt->version > old_maat_rt->version) {
|
||||
log_info(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"Maat version updated %lld -> %lld\n",
|
||||
old_maat_rt->version, maat_inst->maat_rt->version);
|
||||
} else {
|
||||
log_info(maat_inst->logger, MODULE_MAAT_RULE,
|
||||
"Maat version roll back %lld -> %lld\n",
|
||||
old_maat_rt->version, maat_inst->maat_rt->version);
|
||||
}
|
||||
|
||||
maat_inst->stat->zombie_rs_stream +=
|
||||
alignment_int64_array_sum(old_maat_rt->ref_cnt,
|
||||
maat_inst->opts.nr_worker_thread);
|
||||
maat_garbage_bagging(maat_inst->garbage_bin, old_maat_rt, NULL,
|
||||
garbage_maat_runtime_destroy);
|
||||
}
|
||||
|
||||
maat_inst->creating_maat_rt = NULL;
|
||||
maat_inst->maat_version = maat_inst->maat_rt->version;
|
||||
maat_inst->last_full_version = maat_inst->maat_rt->version;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&(maat_inst->background_update_mutex));
|
||||
|
||||
|
||||
maat_garbage_collect_routine(maat_inst->garbage_bin);
|
||||
maat_plugin_table_garbage_collect_routine(maat_inst->tbl_mgr);
|
||||
|
||||
@@ -283,7 +283,7 @@ static void fs_table_row_output(FILE *fp, struct maat_stat *stat, int perf_on)
|
||||
case TABLE_TYPE_EXPR_PLUS:
|
||||
regex_rule_num = expr_runtime_regex_rule_count(runtime);
|
||||
break;
|
||||
case TABLE_TYPE_IP_PLUS:
|
||||
case TABLE_TYPE_IP:
|
||||
ipv6_rule_num = ip_runtime_ipv6_rule_count(runtime);
|
||||
break;
|
||||
default:
|
||||
@@ -350,7 +350,7 @@ static void fs_table_row_output(FILE *fp, struct maat_stat *stat, int perf_on)
|
||||
total_hit_pattern_num += hit_pattern_num;
|
||||
}
|
||||
|
||||
if (table_type == TABLE_TYPE_IP_PLUS) {
|
||||
if (table_type == TABLE_TYPE_IP) {
|
||||
fieldstat_easy_counter_set(stat->fs_handle, 0,
|
||||
stat->fs_column_id[COLUMN_REGEX_NUM],
|
||||
&cell_tag, 1, ipv6_rule_num);
|
||||
|
||||
@@ -155,7 +155,7 @@ struct table_operations table_ops[TABLE_TYPE_MAX] = {
|
||||
.update_err_count = expr_runtime_update_err_count
|
||||
},
|
||||
{
|
||||
.type = TABLE_TYPE_IP_PLUS,
|
||||
.type = TABLE_TYPE_IP,
|
||||
.new_schema = ip_schema_new,
|
||||
.free_schema = ip_schema_free,
|
||||
.new_runtime = ip_runtime_new,
|
||||
@@ -499,7 +499,7 @@ static void register_reserved_word(struct maat_kv_store *reserved_word_map)
|
||||
maat_kv_register(reserved_word_map, "expr_plus", TABLE_TYPE_EXPR_PLUS);
|
||||
maat_kv_register(reserved_word_map, "interval", TABLE_TYPE_INTERVAL);
|
||||
maat_kv_register(reserved_word_map, "interval_plus", TABLE_TYPE_INTERVAL_PLUS);
|
||||
maat_kv_register(reserved_word_map, "ip_plus", TABLE_TYPE_IP_PLUS);
|
||||
maat_kv_register(reserved_word_map, "ip", TABLE_TYPE_IP);
|
||||
maat_kv_register(reserved_word_map, "plugin", TABLE_TYPE_PLUGIN);
|
||||
maat_kv_register(reserved_word_map, "ip_plugin", TABLE_TYPE_IP_PLUGIN);
|
||||
maat_kv_register(reserved_word_map, "ipport_plugin", TABLE_TYPE_IPPORT_PLUGIN);
|
||||
|
||||
Reference in New Issue
Block a user