[PATCH] maat_plugin_table_get_ex_data add key_len (23.06)
This commit is contained in:
@@ -149,9 +149,12 @@ int maat_plugin_table_ex_schema_register(struct maat *instance, const char *tabl
|
||||
long argl, void *argp);
|
||||
/**
|
||||
* returned data is duplicated by dup_func of maat_plugin_table_ex_schema_register,
|
||||
* caller is responsible to free the data.
|
||||
* caller is responsible to free the data.
|
||||
* NOTE: support three key type(integer, pointer, ip_addr) specified in table_info.conf
|
||||
* if use ip_addr key type, then key should be ip address in network order.
|
||||
*/
|
||||
void *maat_plugin_table_get_ex_data(struct maat *instance, int table_id, const char *key);
|
||||
void *maat_plugin_table_get_ex_data(struct maat *instance, int table_id,
|
||||
const char *key, size_t key_len);
|
||||
|
||||
int maat_ip_plugin_table_get_ex_data(struct maat *instance, int table_id,
|
||||
const struct ip_addr *ip, void **ex_data_array,
|
||||
|
||||
@@ -33,7 +33,8 @@ inline long long alignment_int64_array_sum(long long *array, int size)
|
||||
return sum;
|
||||
}
|
||||
|
||||
inline long long alignment_int64_array_add(long long *array, int offset, long long op_val)
|
||||
inline long long alignment_int64_array_add(long long *array, int offset,
|
||||
long long op_val)
|
||||
{
|
||||
int idx = (CPU_CACHE_ALIGMENT / sizeof(long long)) * offset;
|
||||
array[idx] += op_val;
|
||||
|
||||
@@ -105,7 +105,8 @@ struct iris_table *query_table_info(struct iris_description *p_iris,
|
||||
strlen(table_name)));
|
||||
snprintf(table_info->table_path, sizeof(table_info->table_path),
|
||||
"%s/%s.local", p_iris->tmp_iris_dir, table_info->table_name);
|
||||
HASH_ADD_KEYPTR(hh, p_iris->iris_table_map, table_info->table_name, strlen(table_name), table_info);
|
||||
HASH_ADD_KEYPTR(hh, p_iris->iris_table_map, table_info->table_name,
|
||||
strlen(table_name), table_info);
|
||||
}
|
||||
|
||||
return table_info;
|
||||
@@ -127,11 +128,13 @@ int set_iris_descriptor(const char *json_file, cJSON *json,
|
||||
struct iris_description *iris_cfg)
|
||||
{
|
||||
memset(iris_cfg, 0, sizeof(struct iris_description));
|
||||
snprintf(iris_cfg->tmp_iris_dir, sizeof(iris_cfg->tmp_iris_dir), "%s_iris_tmp", json_file);
|
||||
snprintf(iris_cfg->tmp_iris_dir, sizeof(iris_cfg->tmp_iris_dir),
|
||||
"%s_iris_tmp", json_file);
|
||||
snprintf(iris_cfg->tmp_iris_index_dir, sizeof(iris_cfg->tmp_iris_index_dir),
|
||||
"%s_iris_tmp/index", json_file);
|
||||
snprintf(iris_cfg->index_path, sizeof(iris_cfg->index_path), "%s/full_config_index.%010d",
|
||||
iris_cfg->tmp_iris_index_dir, json_version);
|
||||
snprintf(iris_cfg->index_path, sizeof(iris_cfg->index_path),
|
||||
"%s/full_config_index.%010d", iris_cfg->tmp_iris_index_dir,
|
||||
json_version);
|
||||
|
||||
iris_cfg->redis_write_ctx = redis_write_ctx;
|
||||
iris_cfg->str2int_map = maat_kv_store_new();
|
||||
@@ -173,9 +176,12 @@ int set_iris_descriptor(const char *json_file, cJSON *json,
|
||||
maat_kv_register(iris_cfg->str2int_map, "hexbin", 1);
|
||||
maat_kv_register(iris_cfg->str2int_map, "case plain", 2);
|
||||
|
||||
iris_cfg->compile_table = query_table_info(iris_cfg, compile_tn, TABLE_TYPE_COMPILE);
|
||||
iris_cfg->group2compile_table = query_table_info(iris_cfg, group2compile_tn, TABLE_TYPE_GROUP2COMPILE);
|
||||
iris_cfg->group2group_table = query_table_info(iris_cfg, group2group_tn, TABLE_TYPE_GROUP2GROUP);
|
||||
iris_cfg->compile_table = query_table_info(iris_cfg, compile_tn,
|
||||
TABLE_TYPE_COMPILE);
|
||||
iris_cfg->group2compile_table = query_table_info(iris_cfg, group2compile_tn,
|
||||
TABLE_TYPE_GROUP2COMPILE);
|
||||
iris_cfg->group2group_table = query_table_info(iris_cfg, group2group_tn,
|
||||
TABLE_TYPE_GROUP2GROUP);
|
||||
|
||||
if (encrypt_key && encrypt_algo) {
|
||||
iris_cfg->encrypt_key = maat_strdup(encrypt_key);
|
||||
@@ -236,8 +242,9 @@ int write_plugin_line(cJSON *plug_table_json, int sequence,
|
||||
cJSON *item = cJSON_GetObjectItem(plug_table_json, "table_name");
|
||||
if (NULL == item || item->type != cJSON_String) {
|
||||
log_error(logger, MODULE_JSON2IRIS,
|
||||
"[%s:%d] The %d plugin_table's table_name not defined or format error",
|
||||
__FUNCTION__, __LINE__, sequence);
|
||||
"[%s:%d] The %d plugin_table's table_name "
|
||||
"not defined or format error", __FUNCTION__,
|
||||
__LINE__, sequence);
|
||||
return -1;
|
||||
}
|
||||
const char *table_name = item->valuestring;
|
||||
@@ -250,7 +257,8 @@ int write_plugin_line(cJSON *plug_table_json, int sequence,
|
||||
return -1;
|
||||
}
|
||||
int line_cnt = cJSON_GetArraySize(table_content);
|
||||
struct iris_table *table_info = query_table_info(p_iris, table_name, TABLE_TYPE_PLUGIN);
|
||||
struct iris_table *table_info = query_table_info(p_iris, table_name,
|
||||
TABLE_TYPE_PLUGIN);
|
||||
|
||||
cJSON *each_line = NULL;
|
||||
const char *line_content = NULL;
|
||||
@@ -265,7 +273,8 @@ int write_plugin_line(cJSON *plug_table_json, int sequence,
|
||||
|
||||
line_content = each_line->valuestring;
|
||||
table_info->write_pos += memcat(&(table_info->buff), table_info->write_pos,
|
||||
&(table_info->buff_sz), line_content, strlen(line_content));
|
||||
&(table_info->buff_sz), line_content,
|
||||
strlen(line_content));
|
||||
table_info->write_pos += memcat(&(table_info->buff), table_info->write_pos,
|
||||
&(table_info->buff_sz), "\n", 1);
|
||||
table_info->line_count++;
|
||||
@@ -315,7 +324,8 @@ static struct group_info *group_info_add_unsafe(struct iris_description *p_iris,
|
||||
group_info = ALLOC(struct group_info, 1);
|
||||
group_info->group_id = get_group_seq(p_iris);
|
||||
strncpy(group_info->group_name, group_name, sizeof(group_info->group_name));
|
||||
HASH_ADD_KEYPTR(hh, p_iris->group_name_map, group_info->group_name, strlen(group_name), group_info);
|
||||
HASH_ADD_KEYPTR(hh, p_iris->group_name_map, group_info->group_name,
|
||||
strlen(group_name), group_info);
|
||||
}
|
||||
return group_info;
|
||||
}
|
||||
@@ -327,7 +337,7 @@ static int get_region_seq(struct iris_description *iris_cfg)
|
||||
if (NULL == iris_cfg->redis_write_ctx) {
|
||||
sequence = iris_cfg->region_cnt;
|
||||
} else {
|
||||
redisReply *data_reply = maat_cmd_wrap_redis_command(iris_cfg->redis_write_ctx,
|
||||
redisReply *data_reply = maat_cmd_wrap_redis_command(iris_cfg->redis_write_ctx,
|
||||
"INCRBY %s 1", mr_region_id_var);
|
||||
sequence = (int)data_reply->integer - 1;
|
||||
freeReplyObject(data_reply);
|
||||
@@ -608,8 +618,8 @@ int write_region_rule(cJSON *region_json, int compile_id, int group_id,
|
||||
cJSON *item = cJSON_GetObjectItem(region_json, "table_name");
|
||||
if (NULL == item || item->type != cJSON_String) {
|
||||
log_error(logger, MODULE_JSON2IRIS,
|
||||
"[%s:%d] compile rule %d's table_name not defined or format error",
|
||||
__FUNCTION__, __LINE__, compile_id);
|
||||
"[%s:%d] compile rule %d's table_name not defined "
|
||||
"or format error", __FUNCTION__, __LINE__, compile_id);
|
||||
return -1;
|
||||
}
|
||||
const char *table_name = item->valuestring;
|
||||
@@ -617,8 +627,9 @@ int write_region_rule(cJSON *region_json, int compile_id, int group_id,
|
||||
item = cJSON_GetObjectItem(region_json, "table_type");
|
||||
if (NULL == item || item->type != cJSON_String) {
|
||||
log_error(logger, MODULE_JSON2IRIS,
|
||||
"[%s:%d] compile rule %d's table name %s's table_type not defined or format error",
|
||||
__FUNCTION__, __LINE__, compile_id, table_name);
|
||||
"[%s:%d] compile rule %d's table name %s's table_type "
|
||||
"not defined or format error", __FUNCTION__, __LINE__,
|
||||
compile_id, table_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -635,8 +646,9 @@ int write_region_rule(cJSON *region_json, int compile_id, int group_id,
|
||||
cJSON *table_content = cJSON_GetObjectItem(region_json, "table_content");
|
||||
if (NULL == table_content || table_content->type != cJSON_Object) {
|
||||
log_error(logger, MODULE_JSON2IRIS,
|
||||
"[%s:%d] compile rule %d table name %s's table_content not defined or format error",
|
||||
__FUNCTION__, __LINE__, compile_id, table_name);
|
||||
"[%s:%d] compile rule %d table name %s's table_content "
|
||||
"not defined or format error", __FUNCTION__, __LINE__,
|
||||
compile_id, table_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -645,7 +657,8 @@ int write_region_rule(cJSON *region_json, int compile_id, int group_id,
|
||||
cJSON_AddNumberToObject(table_content, "group_id", group_id);
|
||||
cJSON_AddNumberToObject(table_content, "is_valid", 1);
|
||||
|
||||
struct iris_table *table_info = query_table_info(p_iris, table_name, table_type_int);
|
||||
struct iris_table *table_info = query_table_info(p_iris, table_name,
|
||||
table_type_int);
|
||||
switch (table_type_int) {
|
||||
case TABLE_TYPE_FLAG:
|
||||
case TABLE_TYPE_FLAG_PLUS:
|
||||
@@ -686,9 +699,9 @@ int write_group2compile_line(int group_id, int compile_id, int group_not_flag,
|
||||
table = p_iris->group2compile_table;
|
||||
}
|
||||
|
||||
snprintf(buff, sizeof(buff), "%d\t%d\t1\t%d\t%s\t%d\n", group_id, compile_id,
|
||||
snprintf(buff, sizeof(buff), "%d\t%d\t1\t%d\t%s\t%d\n", group_id, compile_id,
|
||||
group_not_flag, vtable, clause_index);
|
||||
table->write_pos += memcat(&(table->buff), table->write_pos, &(table->buff_sz),
|
||||
table->write_pos += memcat(&(table->buff), table->write_pos, &(table->buff_sz),
|
||||
buff, strlen(buff));
|
||||
table->line_count++;
|
||||
|
||||
@@ -779,8 +792,8 @@ int write_group_rule(cJSON *group_json, int parent_id,
|
||||
if (region_json != NULL) {
|
||||
cJSON *region_rule = NULL;
|
||||
cJSON_ArrayForEach(region_rule, region_json) {
|
||||
ret = write_region_rule(region_rule, tracking_compile_id, group_info->group_id,
|
||||
p_iris, logger);
|
||||
ret = write_region_rule(region_rule, tracking_compile_id,
|
||||
group_info->group_id, p_iris, logger);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_JSON2IRIS,
|
||||
"[%s:%d] compile rule %d write region error",
|
||||
@@ -806,7 +819,8 @@ int write_group_rule(cJSON *group_json, int parent_id,
|
||||
|
||||
if (NULL == region_json && NULL == sub_groups) {
|
||||
log_info(logger, MODULE_JSON2IRIS,
|
||||
"[%s:%d] A group of compile rule %d has neither regions, sub groups, nor refered another exisited group",
|
||||
"[%s:%d] A group of compile rule %d has neither regions, "
|
||||
"sub groups, nor refered another exisited group",
|
||||
__FUNCTION__, __LINE__, tracking_compile_id);
|
||||
}
|
||||
}
|
||||
|
||||
140
src/maat_api.c
140
src/maat_api.c
@@ -733,13 +733,15 @@ int maat_plugin_table_ex_schema_register(struct maat *maat_instance,
|
||||
pthread_mutex_lock(&(maat_instance->background_update_mutex));
|
||||
|
||||
int ret = -1;
|
||||
enum table_type table_type = table_manager_get_table_type(maat_instance->tbl_mgr, table_id);
|
||||
enum table_type table_type = table_manager_get_table_type(maat_instance->tbl_mgr,
|
||||
table_id);
|
||||
if (TABLE_TYPE_COMPILE == table_type) {
|
||||
ret = compile_table_ex_schema_register(maat_instance, table_id, new_func, free_func,
|
||||
dup_func, argl, argp);
|
||||
ret = compile_table_ex_schema_register(maat_instance, table_id, new_func,
|
||||
free_func, dup_func, argl, argp);
|
||||
} else {
|
||||
ret = generic_plugin_table_ex_schema_register(maat_instance, table_name, table_id, new_func,
|
||||
free_func, dup_func, argl, argp);
|
||||
ret = generic_plugin_table_ex_schema_register(maat_instance, table_name,
|
||||
table_id, new_func, free_func,
|
||||
dup_func, argl, argp);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&(maat_instance->background_update_mutex));
|
||||
@@ -747,7 +749,7 @@ int maat_plugin_table_ex_schema_register(struct maat *maat_instance,
|
||||
}
|
||||
|
||||
void *maat_plugin_table_get_ex_data(struct maat *maat_instance, int table_id,
|
||||
const char *key)
|
||||
const char *key, size_t key_len)
|
||||
{
|
||||
|
||||
if (NULL == maat_instance || table_id < 0 || table_id >= MAX_TABLE_NUM
|
||||
@@ -771,11 +773,12 @@ void *maat_plugin_table_get_ex_data(struct maat *maat_instance, int table_id,
|
||||
}
|
||||
|
||||
void *ret = NULL;
|
||||
enum table_type table_type = table_manager_get_table_type(maat_instance->tbl_mgr, table_id);
|
||||
enum table_type table_type = table_manager_get_table_type(maat_instance->tbl_mgr,
|
||||
table_id);
|
||||
if (TABLE_TYPE_COMPILE == table_type) {
|
||||
ret = compile_runtime_get_ex_data(runtime, schema, *(long long *)key);
|
||||
} else if (TABLE_TYPE_PLUGIN == table_type) {
|
||||
ret = plugin_runtime_get_ex_data(runtime, schema, key, strlen(key));
|
||||
ret = plugin_runtime_get_ex_data(runtime, schema, key, key_len);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
@@ -858,7 +861,7 @@ int maat_bool_plugin_table_get_ex_data(struct maat *maat_instance, int table_id,
|
||||
return -1;
|
||||
}
|
||||
|
||||
int n_hit_ex_data = bool_plugin_runtime_get_ex_data(bool_plugin_rt, item_ids, n_item,
|
||||
int n_hit_ex_data = bool_plugin_runtime_get_ex_data(bool_plugin_rt, item_ids, n_item,
|
||||
ex_data_array, n_ex_data);
|
||||
if (n_hit_ex_data < 0) {
|
||||
return -1;
|
||||
@@ -889,7 +892,8 @@ int flag_scan(struct table_manager *tbl_mgr, int thread_id, long long flag,
|
||||
int physical_table_id, int vtable_id, struct maat_state *state)
|
||||
{
|
||||
enum table_type table_type = table_manager_get_table_type(tbl_mgr, physical_table_id);
|
||||
if (table_type == TABLE_TYPE_FLAG_PLUS && DISTRICT_FLAG_UNSET == state->is_set_district) {
|
||||
if (table_type == TABLE_TYPE_FLAG_PLUS &&
|
||||
DISTRICT_FLAG_UNSET == state->is_set_district) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1148,7 +1152,8 @@ int maat_scan_flag(struct maat *maat_instance, int table_id,
|
||||
alignment_int64_array_add(maat_instance->stat->hit_cnt, state->thread_id, 1);
|
||||
if (0 == hit_group_cnt) {
|
||||
//hit NOT group
|
||||
alignment_int64_array_add(maat_instance->stat->not_grp_hit_cnt, state->thread_id, 1);
|
||||
alignment_int64_array_add(maat_instance->stat->not_grp_hit_cnt,
|
||||
state->thread_id, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1196,9 +1201,11 @@ int maat_scan_integer(struct maat *maat_instance, int table_id,
|
||||
|
||||
int vtable_id = 0;
|
||||
int physical_table_id = -1;
|
||||
enum table_type table_type = table_manager_get_table_type(maat_instance->tbl_mgr, table_id);
|
||||
enum table_type table_type = table_manager_get_table_type(maat_instance->tbl_mgr,
|
||||
table_id);
|
||||
if (table_type == TABLE_TYPE_VIRTUAL) {
|
||||
physical_table_id = vtable_get_physical_table_id(maat_instance->tbl_mgr, table_id);
|
||||
physical_table_id = vtable_get_physical_table_id(maat_instance->tbl_mgr,
|
||||
table_id);
|
||||
vtable_id = table_id;
|
||||
} else {
|
||||
physical_table_id = table_id;
|
||||
@@ -1235,11 +1242,13 @@ int maat_scan_integer(struct maat *maat_instance, int table_id,
|
||||
alignment_int64_array_add(maat_instance->stat->hit_cnt, state->thread_id, 1);
|
||||
if (0 == hit_group_cnt) {
|
||||
//hit NOT group
|
||||
alignment_int64_array_add(maat_instance->stat->not_grp_hit_cnt, state->thread_id, 1);
|
||||
alignment_int64_array_add(maat_instance->stat->not_grp_hit_cnt,
|
||||
state->thread_id, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void *interval_rt = table_manager_get_runtime(maat_instance->tbl_mgr, physical_table_id);
|
||||
void *interval_rt = table_manager_get_runtime(maat_instance->tbl_mgr,
|
||||
physical_table_id);
|
||||
assert(interval_rt != NULL);
|
||||
|
||||
if (1 == maat_instance->opts.perf_on) {
|
||||
@@ -1260,9 +1269,8 @@ int maat_scan_integer(struct maat *maat_instance, int table_id,
|
||||
}
|
||||
}
|
||||
|
||||
int maat_scan_ipv4(struct maat *maat_instance, int table_id,
|
||||
uint32_t ip_addr, uint16_t port, int protocol,
|
||||
long long *results, size_t n_result,
|
||||
int maat_scan_ipv4(struct maat *maat_instance, int table_id, uint32_t ip_addr,
|
||||
uint16_t port, int protocol, long long *results, size_t n_result,
|
||||
size_t *n_hit_result, struct maat_state *state)
|
||||
{
|
||||
if ((NULL == maat_instance) || table_id < 0 || table_id >= MAX_TABLE_NUM
|
||||
@@ -1284,9 +1292,11 @@ int maat_scan_ipv4(struct maat *maat_instance, int table_id,
|
||||
|
||||
int vtable_id = 0;
|
||||
int physical_table_id = -1;
|
||||
enum table_type table_type = table_manager_get_table_type(maat_instance->tbl_mgr, table_id);
|
||||
enum table_type table_type = table_manager_get_table_type(maat_instance->tbl_mgr,
|
||||
table_id);
|
||||
if (table_type == TABLE_TYPE_VIRTUAL) {
|
||||
physical_table_id = vtable_get_physical_table_id(maat_instance->tbl_mgr, table_id);
|
||||
physical_table_id = vtable_get_physical_table_id(maat_instance->tbl_mgr,
|
||||
table_id);
|
||||
vtable_id = table_id;
|
||||
} else {
|
||||
physical_table_id = table_id;
|
||||
@@ -1306,8 +1316,8 @@ int maat_scan_ipv4(struct maat *maat_instance, int table_id,
|
||||
maat_runtime_ref_inc(maat_instance->maat_rt, state->thread_id);
|
||||
alignment_int64_array_add(maat_instance->stat->thread_call_cnt, state->thread_id, 1);
|
||||
|
||||
int hit_group_cnt = ipv4_scan(maat_instance->tbl_mgr, state->thread_id, ip_addr, port, protocol,
|
||||
physical_table_id, vtable_id, state);
|
||||
int hit_group_cnt = ipv4_scan(maat_instance->tbl_mgr, state->thread_id, ip_addr,
|
||||
port, protocol, physical_table_id, vtable_id, state);
|
||||
if (hit_group_cnt < 0) {
|
||||
maat_instance->stat->scan_err_cnt++;
|
||||
return MAAT_SCAN_ERR;
|
||||
@@ -1323,7 +1333,8 @@ int maat_scan_ipv4(struct maat *maat_instance, int table_id,
|
||||
alignment_int64_array_add(maat_instance->stat->hit_cnt, state->thread_id, 1);
|
||||
if (0 == hit_group_cnt) {
|
||||
//hit NOT group
|
||||
alignment_int64_array_add(maat_instance->stat->not_grp_hit_cnt, state->thread_id, 1);
|
||||
alignment_int64_array_add(maat_instance->stat->not_grp_hit_cnt,
|
||||
state->thread_id, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1372,9 +1383,11 @@ int maat_scan_ipv6(struct maat *maat_instance, int table_id,
|
||||
|
||||
int vtable_id = 0;
|
||||
int physical_table_id = -1;
|
||||
enum table_type table_type = table_manager_get_table_type(maat_instance->tbl_mgr, table_id);
|
||||
enum table_type table_type = table_manager_get_table_type(maat_instance->tbl_mgr,
|
||||
table_id);
|
||||
if (table_type == TABLE_TYPE_VIRTUAL) {
|
||||
physical_table_id = vtable_get_physical_table_id(maat_instance->tbl_mgr, table_id);
|
||||
physical_table_id = vtable_get_physical_table_id(maat_instance->tbl_mgr,
|
||||
table_id);
|
||||
vtable_id = table_id;
|
||||
} else {
|
||||
physical_table_id = table_id;
|
||||
@@ -1394,8 +1407,8 @@ int maat_scan_ipv6(struct maat *maat_instance, int table_id,
|
||||
maat_runtime_ref_inc(maat_instance->maat_rt, state->thread_id);
|
||||
alignment_int64_array_add(maat_instance->stat->thread_call_cnt, state->thread_id, 1);
|
||||
|
||||
int hit_group_cnt = ipv6_scan(maat_instance->tbl_mgr, state->thread_id, ip_addr, port, protocol,
|
||||
physical_table_id, vtable_id, state);
|
||||
int hit_group_cnt = ipv6_scan(maat_instance->tbl_mgr, state->thread_id, ip_addr,
|
||||
port, protocol, physical_table_id, vtable_id, state);
|
||||
if (hit_group_cnt < 0) {
|
||||
maat_instance->stat->scan_err_cnt++;
|
||||
return MAAT_SCAN_ERR;
|
||||
@@ -1411,7 +1424,8 @@ int maat_scan_ipv6(struct maat *maat_instance, int table_id,
|
||||
alignment_int64_array_add(maat_instance->stat->hit_cnt, state->thread_id, 1);
|
||||
if (0 == hit_group_cnt) {
|
||||
//hit NOT group
|
||||
alignment_int64_array_add(maat_instance->stat->not_grp_hit_cnt, state->thread_id, 1);
|
||||
alignment_int64_array_add(maat_instance->stat->not_grp_hit_cnt,
|
||||
state->thread_id, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1459,9 +1473,11 @@ int maat_scan_string(struct maat *maat_instance, int table_id, const char *data,
|
||||
|
||||
int vtable_id = 0;
|
||||
int physical_table_id = -1;
|
||||
enum table_type table_type = table_manager_get_table_type(maat_instance->tbl_mgr, table_id);
|
||||
enum table_type table_type = table_manager_get_table_type(maat_instance->tbl_mgr,
|
||||
table_id);
|
||||
if (table_type == TABLE_TYPE_VIRTUAL) {
|
||||
physical_table_id = vtable_get_physical_table_id(maat_instance->tbl_mgr, table_id);
|
||||
physical_table_id = vtable_get_physical_table_id(maat_instance->tbl_mgr,
|
||||
table_id);
|
||||
vtable_id = table_id;
|
||||
} else {
|
||||
physical_table_id = table_id;
|
||||
@@ -1481,7 +1497,7 @@ int maat_scan_string(struct maat *maat_instance, int table_id, const char *data,
|
||||
maat_runtime_ref_inc(maat_instance->maat_rt, state->thread_id);
|
||||
alignment_int64_array_add(maat_instance->stat->thread_call_cnt, state->thread_id, 1);
|
||||
|
||||
int hit_group_cnt = string_scan(maat_instance->tbl_mgr, state->thread_id, data, data_len,
|
||||
int hit_group_cnt = string_scan(maat_instance->tbl_mgr, state->thread_id, data, data_len,
|
||||
physical_table_id, vtable_id, state);
|
||||
if (hit_group_cnt < 0) {
|
||||
maat_instance->stat->scan_err_cnt++;
|
||||
@@ -1498,7 +1514,8 @@ int maat_scan_string(struct maat *maat_instance, int table_id, const char *data,
|
||||
alignment_int64_array_add(maat_instance->stat->hit_cnt, state->thread_id, 1);
|
||||
if (0 == hit_group_cnt) {
|
||||
//hit NOT group
|
||||
alignment_int64_array_add(maat_instance->stat->not_grp_hit_cnt, state->thread_id, 1);
|
||||
alignment_int64_array_add(maat_instance->stat->not_grp_hit_cnt,
|
||||
state->thread_id, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1537,9 +1554,11 @@ struct maat_stream *maat_stream_new(struct maat *maat_instance, int table_id,
|
||||
stream->thread_id = state->thread_id;
|
||||
stream->logger = maat_instance->logger;
|
||||
|
||||
enum table_type table_type = table_manager_get_table_type(maat_instance->tbl_mgr, table_id);
|
||||
enum table_type table_type = table_manager_get_table_type(maat_instance->tbl_mgr,
|
||||
table_id);
|
||||
if (table_type == TABLE_TYPE_VIRTUAL) {
|
||||
stream->physical_table_id = vtable_get_physical_table_id(maat_instance->tbl_mgr, table_id);
|
||||
stream->physical_table_id = vtable_get_physical_table_id(maat_instance->tbl_mgr,
|
||||
table_id);
|
||||
stream->vtable_id = table_id;
|
||||
} else {
|
||||
stream->physical_table_id = table_id;
|
||||
@@ -1550,7 +1569,8 @@ struct maat_stream *maat_stream_new(struct maat *maat_instance, int table_id,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
table_type = table_manager_get_table_type(maat_instance->tbl_mgr, stream->physical_table_id);
|
||||
table_type = table_manager_get_table_type(maat_instance->tbl_mgr,
|
||||
stream->physical_table_id);
|
||||
if (table_type != TABLE_TYPE_EXPR && table_type != TABLE_TYPE_EXPR_PLUS) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -1595,7 +1615,8 @@ int maat_stream_scan(struct maat_stream *maat_stream, const char *data, int data
|
||||
return MAAT_SCAN_OK;
|
||||
}
|
||||
|
||||
void *expr_rt = table_manager_get_runtime(maat_instance->tbl_mgr, maat_stream->physical_table_id);
|
||||
void *expr_rt = table_manager_get_runtime(maat_instance->tbl_mgr,
|
||||
maat_stream->physical_table_id);
|
||||
assert(expr_rt != NULL);
|
||||
|
||||
long long cur_expr_rt_version = expr_runtime_get_version(expr_rt);
|
||||
@@ -1603,7 +1624,8 @@ int maat_stream_scan(struct maat_stream *maat_stream, const char *data, int data
|
||||
return MAAT_SCAN_OK;
|
||||
}
|
||||
|
||||
alignment_int64_array_add(maat_instance->stat->thread_call_cnt, maat_stream->thread_id, 1);
|
||||
alignment_int64_array_add(maat_instance->stat->thread_call_cnt,
|
||||
maat_stream->thread_id, 1);
|
||||
|
||||
int hit_group_cnt = expr_stream_scan(maat_stream, data, data_len, state);
|
||||
if (hit_group_cnt < 0) {
|
||||
@@ -1621,7 +1643,8 @@ int maat_stream_scan(struct maat_stream *maat_stream, const char *data, int data
|
||||
alignment_int64_array_add(maat_instance->stat->hit_cnt, maat_stream->thread_id, 1);
|
||||
if (0 == hit_group_cnt) {
|
||||
//hit NOT group
|
||||
alignment_int64_array_add(maat_instance->stat->not_grp_hit_cnt, maat_stream->thread_id, 1);
|
||||
alignment_int64_array_add(maat_instance->stat->not_grp_hit_cnt,
|
||||
maat_stream->thread_id, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1711,7 +1734,8 @@ void maat_state_free(struct maat_state *state)
|
||||
state->maat_instance = NULL;
|
||||
FREE(state);
|
||||
|
||||
alignment_int64_array_add(maat_instance->stat->maat_state_cnt, thread_id, -1);
|
||||
alignment_int64_array_add(maat_instance->stat->maat_state_cnt,
|
||||
thread_id, -1);
|
||||
}
|
||||
|
||||
int maat_state_set_scan_district(struct maat_state *state, int vtable_id,
|
||||
@@ -1730,7 +1754,8 @@ int maat_state_set_scan_district(struct maat_state *state, int vtable_id,
|
||||
return -1;
|
||||
}
|
||||
|
||||
enum table_type table_type = table_manager_get_table_type(maat_instance->tbl_mgr, vtable_id);
|
||||
enum table_type table_type = table_manager_get_table_type(maat_instance->tbl_mgr,
|
||||
vtable_id);
|
||||
if (table_type != TABLE_TYPE_FLAG_PLUS && table_type != TABLE_TYPE_EXPR_PLUS &&
|
||||
table_type != TABLE_TYPE_INTERVAL_PLUS && table_type != TABLE_TYPE_VIRTUAL) {
|
||||
log_error(maat_instance->logger, MODULE_MAAT_API,
|
||||
@@ -1740,26 +1765,32 @@ int maat_state_set_scan_district(struct maat_state *state, int vtable_id,
|
||||
|
||||
int physical_table_id = vtable_id;
|
||||
if (table_type == TABLE_TYPE_VIRTUAL) {
|
||||
physical_table_id = vtable_get_physical_table_id(maat_instance->tbl_mgr, vtable_id);
|
||||
physical_table_id = vtable_get_physical_table_id(maat_instance->tbl_mgr,
|
||||
vtable_id);
|
||||
}
|
||||
|
||||
int ret = -1;
|
||||
table_type = table_manager_get_table_type(maat_instance->tbl_mgr, physical_table_id);
|
||||
void *runtime = table_manager_get_runtime(maat_instance->tbl_mgr, physical_table_id);
|
||||
table_type = table_manager_get_table_type(maat_instance->tbl_mgr,
|
||||
physical_table_id);
|
||||
void *runtime = table_manager_get_runtime(maat_instance->tbl_mgr,
|
||||
physical_table_id);
|
||||
assert(runtime != NULL);
|
||||
|
||||
switch (table_type) {
|
||||
case TABLE_TYPE_FLAG_PLUS:
|
||||
ret = flag_runtime_set_scan_district((struct flag_runtime *)runtime, district,
|
||||
district_len, &(state->district_id));
|
||||
ret = flag_runtime_set_scan_district((struct flag_runtime *)runtime,
|
||||
district, district_len,
|
||||
&(state->district_id));
|
||||
break;
|
||||
case TABLE_TYPE_EXPR_PLUS:
|
||||
ret = expr_runtime_set_scan_district((struct expr_runtime *)runtime, district,
|
||||
district_len, &(state->district_id));
|
||||
ret = expr_runtime_set_scan_district((struct expr_runtime *)runtime,
|
||||
district, district_len,
|
||||
&(state->district_id));
|
||||
break;
|
||||
case TABLE_TYPE_INTERVAL_PLUS:
|
||||
ret = interval_runtime_set_scan_district((struct interval_runtime *)runtime, district,
|
||||
district_len, &(state->district_id));
|
||||
ret = interval_runtime_set_scan_district((struct interval_runtime *)runtime,
|
||||
district, district_len,
|
||||
&(state->district_id));
|
||||
break;
|
||||
default:
|
||||
log_error(maat_instance->logger, MODULE_MAAT_API,
|
||||
@@ -1814,7 +1845,8 @@ int maat_state_set_scan_compile_table(struct maat_state *state, int compile_tabl
|
||||
return 0;
|
||||
}
|
||||
|
||||
int maat_state_get_hit_paths(struct maat_state *state, struct maat_hit_path *paths, size_t n_path)
|
||||
int maat_state_get_hit_paths(struct maat_state *state, struct maat_hit_path *paths,
|
||||
size_t n_path)
|
||||
{
|
||||
if (NULL == state || NULL == paths || 0 == n_path) {
|
||||
return -1;
|
||||
@@ -1834,12 +1866,14 @@ int maat_state_get_hit_paths(struct maat_state *state, struct maat_hit_path *pat
|
||||
compile_table_id = maat_instance->default_compile_table_id;
|
||||
}
|
||||
|
||||
void *compile_rt = table_manager_get_runtime(maat_instance->tbl_mgr, compile_table_id);
|
||||
void *compile_rt = table_manager_get_runtime(maat_instance->tbl_mgr,
|
||||
compile_table_id);
|
||||
if (NULL == compile_rt) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
void *g2g_runtime = table_manager_get_runtime(maat_instance->tbl_mgr, maat_instance->g2g_table_id);
|
||||
void *g2g_runtime = table_manager_get_runtime(maat_instance->tbl_mgr,
|
||||
maat_instance->g2g_table_id);
|
||||
size_t internal_hit_path_cnt = maat_compile_state_get_internal_hit_paths(state->compile_state,
|
||||
(struct compile_runtime *)compile_rt,
|
||||
(struct group2group_runtime *)g2g_runtime,
|
||||
@@ -1863,4 +1897,4 @@ int maat_state_get_hit_groups(struct maat_state *state, struct maat_hit_group *g
|
||||
int maat_hit_group_compile_id(struct maat *instance, struct maat_hit_group *group)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1227,8 +1227,7 @@ struct compile_rule *compile_rule_clone(struct compile_rule *rule)
|
||||
new_rule->table_line = ALLOC(char, new_rule->table_line_len);
|
||||
memcpy(new_rule->table_line, rule->table_line, new_rule->table_line_len);
|
||||
|
||||
if (1 == rule->ref_schema->set_flag)
|
||||
{
|
||||
if (1 == rule->ref_schema->set_flag) {
|
||||
*(new_rule->ex_data) = rule_ex_data_new(rule->table_name, rule->ref_schema->table_id,
|
||||
rule->table_line, &(rule->ref_schema->ex_schema));
|
||||
}
|
||||
|
||||
@@ -84,7 +84,8 @@ void maat_kv_store_free(struct maat_kv_store *store)
|
||||
FREE(store);
|
||||
}
|
||||
|
||||
int maat_kv_register_unNull(struct maat_kv_store *store, const char *key, size_t keylen, long long value)
|
||||
int maat_kv_register_unNull(struct maat_kv_store *store, const char *key,
|
||||
size_t keylen, long long value)
|
||||
{
|
||||
if (keylen > MAAT_KV_MAX_KEY_LEN) {
|
||||
return -1;
|
||||
@@ -112,7 +113,8 @@ int maat_kv_register(struct maat_kv_store* store, const char *key, long long val
|
||||
return ret;
|
||||
}
|
||||
|
||||
int maat_kv_read_unNull(struct maat_kv_store *store, const char* key, size_t keylen, long long *value)
|
||||
int maat_kv_read_unNull(struct maat_kv_store *store, const char* key,
|
||||
size_t keylen, long long *value)
|
||||
{
|
||||
struct maat_kv_pair *kv = NULL;
|
||||
char key_lowercase[MAAT_KV_MAX_KEY_LEN] = {0};
|
||||
@@ -136,7 +138,8 @@ int maat_kv_read(struct maat_kv_store *store, const char * key, long long *value
|
||||
return maat_kv_read_unNull(store, key, strlen(key), value);
|
||||
}
|
||||
|
||||
int maat_kv_write_unNull(struct maat_kv_store* store, const char* key, size_t keylen, long long value)
|
||||
int maat_kv_write_unNull(struct maat_kv_store* store, const char* key,
|
||||
size_t keylen, long long value)
|
||||
{
|
||||
struct maat_kv_pair *kv = NULL;
|
||||
char key_lowercase[MAAT_KV_MAX_KEY_LEN] = {0};
|
||||
|
||||
@@ -43,14 +43,16 @@ struct plugin_runtime {
|
||||
enum plugin_key_type {
|
||||
PLUGIN_KEY_TYPE_INVALID = 0,
|
||||
PLUGIN_KEY_TYPE_POINTER,
|
||||
PLUGIN_KEY_TYPE_INTEGER
|
||||
PLUGIN_KEY_TYPE_INTEGER,
|
||||
PLUGIN_KEY_TYPE_IP_ADDR
|
||||
};
|
||||
|
||||
#define MAX_PLUGIN_PER_TABLE 32
|
||||
struct plugin_schema {
|
||||
enum plugin_key_type key_type;
|
||||
int addr_type_column;
|
||||
int key_len;
|
||||
int key_column;
|
||||
int addr_type_column;
|
||||
int rule_tag_column;
|
||||
int n_foreign;
|
||||
int foreign_columns[MAX_FOREIGN_CLMN_NUM];
|
||||
@@ -120,12 +122,31 @@ void *plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
schema->key_type = PLUGIN_KEY_TYPE_POINTER;
|
||||
} else if (strcmp(custom_item->valuestring, "integer") == 0) {
|
||||
schema->key_type = PLUGIN_KEY_TYPE_INTEGER;
|
||||
custom_item = cJSON_GetObjectItem(item, "key_len");
|
||||
if (NULL == custom_item || custom_item->type != cJSON_Number) {
|
||||
log_error(logger, MODULE_PLUGIN,
|
||||
"[%s:%d]plugin table:<%s> schema integer key must"
|
||||
" have key_len column", __FUNCTION__, __LINE__,
|
||||
table_name);
|
||||
goto error;
|
||||
}
|
||||
schema->key_len = custom_item->valueint;
|
||||
} else if (strcmp(custom_item->valuestring, "ip_addr") == 0) {
|
||||
schema->key_type = PLUGIN_KEY_TYPE_IP_ADDR;
|
||||
custom_item = cJSON_GetObjectItem(item, "addr_type");
|
||||
if (NULL == custom_item || custom_item->type != cJSON_Number) {
|
||||
log_error(logger, MODULE_PLUGIN,
|
||||
"[%s:%d]plugin table:<%s> schema ip_addr key must"
|
||||
" have addr_type column", __FUNCTION__, __LINE__,
|
||||
table_name);
|
||||
goto error;
|
||||
}
|
||||
schema->addr_type_column = custom_item->valueint;
|
||||
} else {
|
||||
log_error(logger, MODULE_PLUGIN,
|
||||
"[%s:%d]plugin table:<%s> schema key_type:%s is illegal, "
|
||||
"just allow {pointer}, {integer}",
|
||||
__FUNCTION__, __LINE__, table_name,
|
||||
custom_item->valuestring);
|
||||
"just allow {pointer}, {integer}, {ip_addr}",
|
||||
__FUNCTION__, __LINE__, table_name, custom_item->valuestring);
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -142,8 +163,7 @@ void *plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
MAX_FOREIGN_CLMN_NUM);
|
||||
} else if (custom_item->type == cJSON_Array) {
|
||||
schema->n_foreign = cJSON_GetArraySize(custom_item);
|
||||
for (int i = 0; i < schema->n_foreign; i++)
|
||||
{
|
||||
for (int i = 0; i < schema->n_foreign; i++) {
|
||||
cJSON *foreign_item = cJSON_GetArrayItem(custom_item, i);
|
||||
assert(foreign_item->type == cJSON_Number);
|
||||
schema->foreign_columns[i] = foreign_item->valueint;
|
||||
@@ -197,7 +217,8 @@ int plugin_table_add_callback(void *plugin_schema, int table_id,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void plugin_table_all_callback_start(struct plugin_schema *plugin_schema, int update_type)
|
||||
void plugin_table_all_callback_start(struct plugin_schema *plugin_schema,
|
||||
int update_type)
|
||||
{
|
||||
for (size_t i = 0; i < plugin_schema->cb_cnt; i++) {
|
||||
if (plugin_schema->cb[i].start != NULL) {
|
||||
@@ -241,8 +262,9 @@ int plugin_table_set_ex_container_schema(void *plugin_schema, int table_id,
|
||||
|
||||
if (1 == schema->container_schema.set_flag) {
|
||||
log_error(schema->logger, MODULE_PLUGIN,
|
||||
"[%s:%d] plugin table(table_id:%d) ex_container_schema has been set, can't set again",
|
||||
__FUNCTION__, __LINE__, table_id);
|
||||
"[%s:%d] plugin table(table_id:%d) ex_container_schema"
|
||||
" has been set, can't set again", __FUNCTION__, __LINE__,
|
||||
table_id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -258,7 +280,8 @@ int plugin_table_set_ex_container_schema(void *plugin_schema, int table_id,
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct ex_container_schema *plugin_table_get_ex_container_schema(void *plugin_schema)
|
||||
struct ex_container_schema *
|
||||
plugin_table_get_ex_container_schema(void *plugin_schema)
|
||||
{
|
||||
struct plugin_schema *schema = (struct plugin_schema *)plugin_schema;
|
||||
|
||||
@@ -337,7 +360,8 @@ int plugin_runtime_update_row(struct plugin_runtime *plugin_rt,
|
||||
size_t cb_count = plugin_schema->cb_cnt;
|
||||
if (cb_count > 0) {
|
||||
for (size_t i = 0; i < cb_count; i++) {
|
||||
plugin_schema->cb[i].update(plugin_schema->table_id, row, plugin_schema->cb[i].u_para);
|
||||
plugin_schema->cb[i].update(plugin_schema->table_id, row,
|
||||
plugin_schema->cb[i].u_para);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,11 +380,13 @@ int plugin_accept_tag_match(struct plugin_schema *schema, const char *table_name
|
||||
size_t n_tag = table_manager_accept_tags_count(schema->ref_tbl_mgr);
|
||||
|
||||
if (schema->rule_tag_column > 0 && n_tag > 0) {
|
||||
int ret = get_column_pos(line, schema->rule_tag_column, &column_offset, &column_len);
|
||||
int ret = get_column_pos(line, schema->rule_tag_column, &column_offset,
|
||||
&column_len);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_PLUGIN,
|
||||
"[%s:%d] table: <%s> has no rule_tag(column_seq:%d) in table_line:%s",
|
||||
__FUNCTION__, __LINE__, table_name, schema->rule_tag_column, line);
|
||||
"[%s:%d] table: <%s> has no rule_tag(column_seq:%d) "
|
||||
"in table_line:%s", __FUNCTION__, __LINE__, table_name,
|
||||
schema->rule_tag_column, line);
|
||||
return TAG_MATCH_ERR;
|
||||
}
|
||||
|
||||
@@ -388,6 +414,97 @@ int plugin_accept_tag_match(struct plugin_schema *schema, const char *table_name
|
||||
return TAG_MATCH_MATCHED;
|
||||
}
|
||||
|
||||
int plugin_table_line_get_key(struct plugin_schema *schema, const char *table_name,
|
||||
const char *line, char *dst_key, size_t *dst_key_len,
|
||||
struct log_handle *logger)
|
||||
{
|
||||
size_t key_offset = 0, key_len = 0;
|
||||
|
||||
int ret = get_column_pos(line, schema->key_column, &key_offset, &key_len);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_PLUGIN,
|
||||
"[%s:%d] plugin table:<%s> has no key(column seq:%d)"
|
||||
" in table_line:%s", __FUNCTION__, __LINE__, table_name,
|
||||
schema->key_column, line);
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *common_key = line + key_offset;
|
||||
if (schema->key_type == PLUGIN_KEY_TYPE_POINTER) {
|
||||
memcpy(dst_key, common_key, key_len);
|
||||
*dst_key_len = key_len;
|
||||
} else if (schema->key_type == PLUGIN_KEY_TYPE_INTEGER) {
|
||||
if (schema->key_len == sizeof(long long)) {
|
||||
long long key_ll = atoll(common_key);
|
||||
memcpy(dst_key, (char *)&key_ll, schema->key_len);
|
||||
} else {
|
||||
int key_int = atoi(common_key);
|
||||
memcpy(dst_key, (char *)&key_int, schema->key_len);
|
||||
}
|
||||
*dst_key_len = schema->key_len;
|
||||
} else if (schema->key_type == PLUGIN_KEY_TYPE_IP_ADDR) {
|
||||
if (key_len >= INET6_ADDRSTRLEN) {
|
||||
log_error(logger, MODULE_PLUGIN,
|
||||
"[%s:%d] plugin table:<%s> ip_key too long(illegal) in "
|
||||
"table_line:%s", __FUNCTION__, __LINE__, table_name, line);
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t addr_type_offset = 0, addr_type_len = 0;
|
||||
|
||||
ret = get_column_pos(line, schema->addr_type_column, &addr_type_offset,
|
||||
&addr_type_len);
|
||||
if (ret < 0) {
|
||||
log_error(logger, MODULE_PLUGIN,
|
||||
"[%s:%d] plugin table:<%s> has no addr_type(column seq:%d)"
|
||||
" in table_line:%s", __FUNCTION__, __LINE__, table_name,
|
||||
schema->addr_type_column, line);
|
||||
return -1;
|
||||
}
|
||||
|
||||
char ip_key[INET6_ADDRSTRLEN] = {0};
|
||||
//snprintf() write at most (key_len+1) bytes (including the terminating null{'\0}) to ip_key.
|
||||
snprintf(ip_key, key_len + 1, "%s", common_key);
|
||||
|
||||
int addr_type = atoi(line + addr_type_offset);
|
||||
if (IPV4 == addr_type) {
|
||||
uint32_t ipv4_addr;
|
||||
ret = inet_pton(AF_INET, ip_key, &ipv4_addr);
|
||||
if (ret <= 0) {
|
||||
log_error(logger, MODULE_PLUGIN,
|
||||
"[%s:%d] plugin table:<%s> ipv4 key(column seq:%d)"
|
||||
" illegal in table_line:%s", __FUNCTION__, __LINE__,
|
||||
table_name, schema->key_column, line);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(dst_key, (char *)&ipv4_addr, sizeof(ipv4_addr));
|
||||
*dst_key_len = sizeof(ipv4_addr);
|
||||
} else if (IPV6 == addr_type) {
|
||||
uint8_t ipv6_addr[16];
|
||||
ret = inet_pton(AF_INET6, ip_key, ipv6_addr);
|
||||
if (ret <= 0) {
|
||||
log_error(logger, MODULE_PLUGIN,
|
||||
"[%s:%d] plugin table:<%s> ipv6 key(column seq:%d)"
|
||||
" illegal in table_line:%s", __FUNCTION__, __LINE__,
|
||||
table_name, schema->key_column, line);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(dst_key, (char *)&ipv6_addr, sizeof(ipv6_addr));
|
||||
*dst_key_len = sizeof(ipv6_addr);
|
||||
} else {
|
||||
log_error(logger, MODULE_PLUGIN,
|
||||
"[%s:%d] plugin table:<%s> addr_type:%d illegal, just"
|
||||
" allow{4, 6}, table_line:%s", __FUNCTION__, __LINE__,
|
||||
table_name, addr_type, line);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int plugin_runtime_update(void *plugin_runtime, void *plugin_schema,
|
||||
const char *table_name, const char *line,
|
||||
int valid_column)
|
||||
@@ -415,21 +532,15 @@ int plugin_runtime_update(void *plugin_runtime, void *plugin_schema,
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t key_offset = 0, key_len = 0;
|
||||
ret = get_column_pos(line, schema->key_column, &key_offset, &key_len);
|
||||
char key[MAX_KEYWORDS_STR] = {0};
|
||||
size_t key_len = 0;
|
||||
ret = plugin_table_line_get_key(schema, table_name, line, key, &key_len,
|
||||
plugin_rt->logger);
|
||||
if (ret < 0) {
|
||||
plugin_rt->update_err_cnt++;
|
||||
return -1;
|
||||
}
|
||||
|
||||
long long key_int = 0;
|
||||
const char *key = line + key_offset;
|
||||
if (schema->key_type == PLUGIN_KEY_TYPE_INTEGER) {
|
||||
key_int = atoll(key);
|
||||
key = (char *)&key_int;
|
||||
key_len = sizeof(long long);
|
||||
}
|
||||
|
||||
ret = plugin_runtime_update_row(plugin_rt, schema, table_name, line,
|
||||
key, key_len, is_valid);
|
||||
if (ret < 0) {
|
||||
@@ -539,10 +650,10 @@ void *plugin_runtime_get_ex_data(void *plugin_runtime, void *plugin_schema,
|
||||
|
||||
struct plugin_runtime *plugin_rt = (struct plugin_runtime *)plugin_runtime;
|
||||
struct plugin_schema *schema = (struct plugin_schema *)plugin_schema;
|
||||
|
||||
if (schema->key_type == PLUGIN_KEY_TYPE_INTEGER) {
|
||||
key_len = sizeof(long long);
|
||||
if (schema->key_type == PLUGIN_KEY_TYPE_INTEGER &&
|
||||
schema->key_len != key_len) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
return ex_data_runtime_get_ex_data_by_key(plugin_rt->ex_data_rt, key, key_len);
|
||||
}
|
||||
@@ -367,7 +367,8 @@ static int compare_each_tag(cJSON *tag_obj, const struct rule_tag *accept_tags,
|
||||
}
|
||||
|
||||
//@param tag_set likes [{"tag":"location","value":["北京/朝阳/华严北里","上海/浦东/陆家嘴"]},{"tag":"isp","value":["电信","移动"]}]
|
||||
static int compare_each_tag_set(cJSON *tag_set, const struct rule_tag *accept_tags, size_t n_accept_tag)
|
||||
static int compare_each_tag_set(cJSON *tag_set, const struct rule_tag *accept_tags,
|
||||
size_t n_accept_tag)
|
||||
{
|
||||
int matched = 0;
|
||||
|
||||
@@ -433,8 +434,8 @@ error:
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *maat_table_schema_new(cJSON *json, const char *table_name,
|
||||
enum table_type table_type,
|
||||
void *maat_table_schema_new(cJSON *json, const char *table_name,
|
||||
enum table_type table_type,
|
||||
struct table_manager *tbl_mgr,
|
||||
struct log_handle *logger)
|
||||
{
|
||||
|
||||
@@ -296,7 +296,8 @@ int crypt_memory(const unsigned char *inbuf, size_t inlen, unsigned char **pp_ou
|
||||
OPENSSL_assert(EVP_CIPHER_CTX_iv_length(ctx) == 16);
|
||||
|
||||
/* Now we can set key and IV */
|
||||
//It should be set to 1 for encryption, 0 for decryption and -1 to leave the value unchanged (the actual value of 'enc' being supplied in a previous call).
|
||||
//It should be set to 1 for encryption, 0 for decryption and -1
|
||||
//to leave the value unchanged (the actual value of 'enc' being supplied in a previous call).
|
||||
EVP_CipherInit_ex(ctx, NULL, NULL, cipher_key, cipher_iv, -1);
|
||||
int out_blk_len = 0;
|
||||
int out_buff_offset = 0;
|
||||
@@ -389,7 +390,8 @@ int gzip_uncompress(const unsigned char *in_compressed_data, size_t in_compresse
|
||||
break;
|
||||
case Z_BUF_ERROR:
|
||||
buffer_sz *= 2;
|
||||
*out_uncompressed_data = (unsigned char *)realloc(*out_uncompressed_data, buffer_sz);
|
||||
*out_uncompressed_data = (unsigned char *)realloc(*out_uncompressed_data,
|
||||
buffer_sz);
|
||||
memset(*out_uncompressed_data, 0, buffer_sz);
|
||||
break;
|
||||
default:
|
||||
@@ -440,7 +442,7 @@ enum port_format port_format_str2int(const char *format)
|
||||
return PORT_FORMAT_UNKNOWN;
|
||||
}
|
||||
|
||||
int ip_format2range(int ip_type, enum ip_format format, const char *ip1, const char *ip2,
|
||||
int ip_format2range(int ip_type, enum ip_format format, const char *ip1, const char *ip2,
|
||||
uint32_t range_begin[], uint32_t range_end[])
|
||||
{
|
||||
int cidr = 0;
|
||||
|
||||
@@ -43,7 +43,7 @@ void *virtual_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
item = cJSON_GetObjectItem(json, "physical_table");
|
||||
if (NULL == item || item->type != cJSON_String) {
|
||||
log_error(logger, MODULE_VIRTUAL,
|
||||
"[%s:%d] virtual table:<%s> schema has no physical_table column",
|
||||
"[%s:%d] virtual table:<%s> schema has no physical_table column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
@@ -51,11 +51,11 @@ void *virtual_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
schema->physical_table_id = table_manager_get_table_id(tbl_mgr, item->valuestring);
|
||||
if (schema->physical_table_id < 0) {
|
||||
log_error(logger, MODULE_VIRTUAL,
|
||||
"[%s:%d] virtual table:<%s>'s physical table:<%s> unregistered.",
|
||||
"[%s:%d] virtual table:<%s>'s physical table:<%s> unregistered.",
|
||||
__FUNCTION__, __LINE__, table_name, item->valuestring);
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
return schema;
|
||||
error:
|
||||
FREE(schema);
|
||||
|
||||
@@ -2594,7 +2594,7 @@ TEST_F(PluginTable, EX_DATA) {
|
||||
const char *key1 = "HeBei";
|
||||
struct plugin_ud *ud = NULL;
|
||||
ud = (struct plugin_ud *)maat_plugin_table_get_ex_data(maat_instance, table_id,
|
||||
key1);
|
||||
key1, strlen(key1));
|
||||
ASSERT_TRUE(ud != NULL);
|
||||
EXPECT_STREQ(ud->value, "Shijiazhuang");
|
||||
EXPECT_EQ(ud->id, 1);
|
||||
@@ -2602,15 +2602,15 @@ TEST_F(PluginTable, EX_DATA) {
|
||||
|
||||
const char *key2 = "ShanDong";
|
||||
ud = (struct plugin_ud *)maat_plugin_table_get_ex_data(maat_instance, table_id,
|
||||
key2);
|
||||
key2, strlen(key2));
|
||||
ASSERT_TRUE(ud != NULL);
|
||||
EXPECT_STREQ(ud->value, "Jinan");
|
||||
EXPECT_EQ(ud->id, 3);
|
||||
plugin_EX_free_cb(table_id, (void **)&ud, 0, NULL);
|
||||
}
|
||||
|
||||
TEST_F(PluginTable, KEY_TYPE) {
|
||||
const char *table_name = "TEST_PLUGIN_KEY_TYPE_TABLE";
|
||||
TEST_F(PluginTable, LONG_KEY_TYPE) {
|
||||
const char *table_name = "TEST_PLUGIN_LONG_KEY_TYPE_TABLE";
|
||||
struct maat *maat_instance = PluginTable::_shared_maat_instance;
|
||||
|
||||
int table_id = maat_get_table_id(maat_instance, table_name);
|
||||
@@ -2628,7 +2628,7 @@ TEST_F(PluginTable, KEY_TYPE) {
|
||||
long long key1 = 11111111;
|
||||
struct plugin_ud *ud = NULL;
|
||||
ud = (struct plugin_ud *)maat_plugin_table_get_ex_data(maat_instance, table_id,
|
||||
(char *)&key1);
|
||||
(char *)&key1, sizeof(long long));
|
||||
ASSERT_TRUE(ud != NULL);
|
||||
EXPECT_STREQ(ud->value, "Shijiazhuang");
|
||||
EXPECT_EQ(ud->id, 1);
|
||||
@@ -2636,11 +2636,117 @@ TEST_F(PluginTable, KEY_TYPE) {
|
||||
|
||||
long long key2 = 33333333;
|
||||
ud = (struct plugin_ud *)maat_plugin_table_get_ex_data(maat_instance, table_id,
|
||||
(char *)&key2);
|
||||
(char *)&key2, sizeof(long long));
|
||||
ASSERT_TRUE(ud != NULL);
|
||||
EXPECT_STREQ(ud->value, "Jinan");
|
||||
EXPECT_EQ(ud->id, 3);
|
||||
plugin_EX_free_cb(table_id, (void **)&ud, 0, NULL);
|
||||
|
||||
int key3 = 22222222;
|
||||
ud = (struct plugin_ud *)maat_plugin_table_get_ex_data(maat_instance, table_id,
|
||||
(char *)&key3, sizeof(key3));
|
||||
ASSERT_TRUE(ud == NULL);
|
||||
}
|
||||
|
||||
TEST_F(PluginTable, INT_KEY_TYPE) {
|
||||
const char *table_name = "TEST_PLUGIN_INT_KEY_TYPE_TABLE";
|
||||
struct maat *maat_instance = PluginTable::_shared_maat_instance;
|
||||
|
||||
int table_id = maat_get_table_id(maat_instance, table_name);
|
||||
ASSERT_GT(table_id, 0);
|
||||
|
||||
int plugin_ex_data_counter = 0;
|
||||
int ret = maat_plugin_table_ex_schema_register(maat_instance, table_name,
|
||||
plugin_EX_new_cb,
|
||||
plugin_EX_free_cb,
|
||||
plugin_EX_dup_cb,
|
||||
0, &plugin_ex_data_counter);
|
||||
EXPECT_EQ(ret, 0);
|
||||
EXPECT_EQ(plugin_ex_data_counter, 4);
|
||||
|
||||
int key1 = 101;
|
||||
struct plugin_ud *ud = NULL;
|
||||
ud = (struct plugin_ud *)maat_plugin_table_get_ex_data(maat_instance, table_id,
|
||||
(char *)&key1, sizeof(key1));
|
||||
ASSERT_TRUE(ud != NULL);
|
||||
EXPECT_STREQ(ud->value, "China");
|
||||
EXPECT_EQ(ud->id, 1);
|
||||
plugin_EX_free_cb(table_id, (void **)&ud, 0, NULL);
|
||||
|
||||
int key2 = 102;
|
||||
ud = (struct plugin_ud *)maat_plugin_table_get_ex_data(maat_instance, table_id,
|
||||
(char *)&key2, sizeof(key2));
|
||||
ASSERT_TRUE(ud != NULL);
|
||||
EXPECT_STREQ(ud->value, "America");
|
||||
EXPECT_EQ(ud->id, 2);
|
||||
plugin_EX_free_cb(table_id, (void **)&ud, 0, NULL);
|
||||
|
||||
long long key3 = 103;
|
||||
ud = (struct plugin_ud *)maat_plugin_table_get_ex_data(maat_instance, table_id,
|
||||
(char *)&key3, sizeof(key3));
|
||||
ASSERT_TRUE(ud == NULL);
|
||||
}
|
||||
|
||||
TEST_F(PluginTable, IP_KEY_TYPE) {
|
||||
const char *table_name = "TEST_PLUGIN_IP_KEY_TYPE_TABLE";
|
||||
struct maat *maat_instance = PluginTable::_shared_maat_instance;
|
||||
|
||||
int table_id = maat_get_table_id(maat_instance, table_name);
|
||||
ASSERT_GT(table_id, 0);
|
||||
|
||||
int plugin_ex_data_counter = 0;
|
||||
int ret = maat_plugin_table_ex_schema_register(maat_instance, table_name,
|
||||
plugin_EX_new_cb,
|
||||
plugin_EX_free_cb,
|
||||
plugin_EX_dup_cb,
|
||||
0, &plugin_ex_data_counter);
|
||||
EXPECT_EQ(ret, 0);
|
||||
EXPECT_EQ(plugin_ex_data_counter, 4);
|
||||
|
||||
uint32_t ipv4_addr1;
|
||||
ret = inet_pton(AF_INET, "100.64.1.1", &ipv4_addr1);
|
||||
EXPECT_EQ(ret, 1);
|
||||
|
||||
struct plugin_ud *ud = NULL;
|
||||
ud = (struct plugin_ud *)maat_plugin_table_get_ex_data(maat_instance, table_id,
|
||||
(char *)&ipv4_addr1, sizeof(ipv4_addr1));
|
||||
ASSERT_TRUE(ud != NULL);
|
||||
EXPECT_STREQ(ud->value, "XiZang");
|
||||
EXPECT_EQ(ud->id, 4);
|
||||
plugin_EX_free_cb(table_id, (void **)&ud, 0, NULL);
|
||||
|
||||
uint32_t ipv4_addr2;
|
||||
ret = inet_pton(AF_INET, "100.64.1.2", &ipv4_addr2);
|
||||
EXPECT_EQ(ret, 1);
|
||||
|
||||
ud = (struct plugin_ud *)maat_plugin_table_get_ex_data(maat_instance, table_id,
|
||||
(char *)&ipv4_addr2, sizeof(ipv4_addr2));
|
||||
ASSERT_TRUE(ud != NULL);
|
||||
EXPECT_STREQ(ud->value, "XinJiang");
|
||||
EXPECT_EQ(ud->id, 4);
|
||||
plugin_EX_free_cb(table_id, (void **)&ud, 0, NULL);
|
||||
|
||||
uint8_t ipv6_addr1[16];
|
||||
ret = inet_pton(AF_INET6, "2001:da8:205:1::101", ipv6_addr1);
|
||||
EXPECT_EQ(ret, 1);
|
||||
|
||||
ud = (struct plugin_ud *)maat_plugin_table_get_ex_data(maat_instance, table_id,
|
||||
(char *)ipv6_addr1, sizeof(ipv6_addr1));
|
||||
ASSERT_TRUE(ud != NULL);
|
||||
EXPECT_STREQ(ud->value, "GuiZhou");
|
||||
EXPECT_EQ(ud->id, 6);
|
||||
plugin_EX_free_cb(table_id, (void **)&ud, 0, NULL);
|
||||
|
||||
uint8_t ipv6_addr2[16];
|
||||
ret = inet_pton(AF_INET6, "1001:da8:205:1::101", ipv6_addr2);
|
||||
EXPECT_EQ(ret, 1);
|
||||
|
||||
ud = (struct plugin_ud *)maat_plugin_table_get_ex_data(maat_instance, table_id,
|
||||
(char *)ipv6_addr2, sizeof(ipv6_addr2));
|
||||
ASSERT_TRUE(ud != NULL);
|
||||
EXPECT_STREQ(ud->value, "SiChuan");
|
||||
EXPECT_EQ(ud->id, 6);
|
||||
plugin_EX_free_cb(table_id, (void **)&ud, 0, NULL);
|
||||
}
|
||||
|
||||
class IPPluginTable : public testing::Test
|
||||
@@ -3443,7 +3549,7 @@ TEST_F(Policy, CompileEXData) {
|
||||
EXPECT_EQ(results[0], 198);
|
||||
|
||||
void *ex_data = maat_plugin_table_get_ex_data(maat_instance, compile_table_id,
|
||||
(char *)&results[0]);
|
||||
(char *)&results[0], sizeof(long long));
|
||||
ASSERT_TRUE(ex_data!=NULL);
|
||||
struct rule_ex_param *param = (struct rule_ex_param *)ex_data;
|
||||
EXPECT_EQ(param->id, 7799);
|
||||
@@ -4898,7 +5004,7 @@ TEST_F(MaatCmdTest, PluginEXData) {
|
||||
struct user_info *uinfo = NULL;
|
||||
const char *key1 = "192.168.0.2";
|
||||
uinfo = (struct user_info *)maat_plugin_table_get_ex_data(maat_instance, table_id,
|
||||
key1);
|
||||
key1, strlen(key1));
|
||||
ASSERT_TRUE(uinfo != NULL);
|
||||
EXPECT_EQ(0, strcmp(uinfo->name, "liuqiangdong"));
|
||||
EXPECT_EQ(uinfo->id, 2);
|
||||
@@ -4916,7 +5022,7 @@ TEST_F(MaatCmdTest, PluginEXData) {
|
||||
sleep(WAIT_FOR_EFFECTIVE_S);
|
||||
const char *key2 = "192.168.0.2";
|
||||
uinfo = (struct user_info *)maat_plugin_table_get_ex_data(maat_instance, table_id,
|
||||
key2);
|
||||
key2, strlen(key2));
|
||||
ASSERT_TRUE(uinfo == NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -2970,15 +2970,6 @@
|
||||
"4\tShanXi\tTaiyuan\t1\t0"
|
||||
]
|
||||
},
|
||||
{
|
||||
"table_name": "TEST_PLUGIN_KEY_TYPE_TABLE",
|
||||
"table_content": [
|
||||
"1\t11111111\tShijiazhuang\t1\t0",
|
||||
"2\t22222222\tZhengzhou\t1\t0",
|
||||
"3\t33333333\tJinan\t1\t0",
|
||||
"4\t44444444\tTaiyuan\t1\t0"
|
||||
]
|
||||
},
|
||||
{
|
||||
"table_name": "TEST_EFFECTIVE_RANGE_TABLE",
|
||||
"table_content": [
|
||||
@@ -3027,6 +3018,35 @@
|
||||
"305\t0&1&2&3&4&5&6&7\ttunnel5\t1",
|
||||
"306\t101&101\tinvalid\t1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"table_name": "TEST_PLUGIN_LONG_KEY_TYPE_TABLE",
|
||||
"table_content": [
|
||||
"1\t11111111\tShijiazhuang\t1\t0",
|
||||
"2\t22222222\tZhengzhou\t1\t0",
|
||||
"3\t33333333\tJinan\t1\t0",
|
||||
"4\t44444444\tTaiyuan\t1\t0"
|
||||
]
|
||||
},
|
||||
{
|
||||
"table_name": "TEST_PLUGIN_INT_KEY_TYPE_TABLE",
|
||||
"table_content": [
|
||||
"1\t101\tChina\t1\t0",
|
||||
"2\t102\tAmerica\t1\t0",
|
||||
"3\t103\tRussia\t1\t0",
|
||||
"4\t104\tJapan\t1\t0"
|
||||
]
|
||||
},
|
||||
{
|
||||
"table_name": "TEST_PLUGIN_IP_KEY_TYPE_TABLE",
|
||||
"table_content": [
|
||||
"4\t100.64.1.1\tXiZang\t1\t0",
|
||||
"4\t100.64.1.2\tXinJiang\t1\t0",
|
||||
"6\t2001:da8:205:1::101\tGuiZhou\t1\t0",
|
||||
"6\t1001:da8:205:1::101\tSiChuan\t1\t0",
|
||||
"7\t100.64.1.3\tQingHai\t1\t0",
|
||||
"6\t100.64.1.4\tGanSu\t1\t0"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -128,6 +128,7 @@
|
||||
"valid_column":4,
|
||||
"custom": {
|
||||
"key_type":"integer",
|
||||
"key_len":8,
|
||||
"key":1
|
||||
}
|
||||
},
|
||||
@@ -167,6 +168,7 @@
|
||||
"valid_column":4,
|
||||
"custom": {
|
||||
"key_type":"integer",
|
||||
"key_len":8,
|
||||
"key":1,
|
||||
"tag":5
|
||||
}
|
||||
@@ -450,13 +452,37 @@
|
||||
},
|
||||
{
|
||||
"table_id":38,
|
||||
"table_name":"TEST_PLUGIN_KEY_TYPE_TABLE",
|
||||
"table_name":"TEST_PLUGIN_LONG_KEY_TYPE_TABLE",
|
||||
"table_type":"plugin",
|
||||
"valid_column":4,
|
||||
"custom": {
|
||||
"key_type":"integer",
|
||||
"key_len":8,
|
||||
"key":2,
|
||||
"tag":5
|
||||
}
|
||||
},
|
||||
{
|
||||
"table_id":39,
|
||||
"table_name":"TEST_PLUGIN_INT_KEY_TYPE_TABLE",
|
||||
"table_type":"plugin",
|
||||
"valid_column":4,
|
||||
"custom": {
|
||||
"key_type":"integer",
|
||||
"key_len":4,
|
||||
"key":2,
|
||||
"tag":5
|
||||
}
|
||||
},
|
||||
{
|
||||
"table_id":40,
|
||||
"table_name":"TEST_PLUGIN_IP_KEY_TYPE_TABLE",
|
||||
"table_type":"plugin",
|
||||
"valid_column":4,
|
||||
"custom": {
|
||||
"key_type":"ip_addr",
|
||||
"addr_type":1,
|
||||
"key":2
|
||||
}
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user