plugin table support integer&pointer key type
This commit is contained in:
@@ -49,8 +49,9 @@ int bool_plugin_runtime_commit(void *bool_plugin_runtime, const char *table_name
|
||||
|
||||
struct ex_data_runtime *bool_plugin_runtime_get_ex_data_rt(void *bool_plugin_runtime);
|
||||
|
||||
int bool_plugin_runtime_get_ex_data(void *fqdn_plugin_runtime, unsigned long long *item_ids,
|
||||
size_t n_item, void **ex_data_array, size_t n_ex_data);
|
||||
int bool_plugin_runtime_get_ex_data(void *bool_plugin_runtime, void *bool_plugin_schema,
|
||||
unsigned long long *item_ids, size_t n_item,
|
||||
void **ex_data_array, size_t n_ex_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -64,9 +64,6 @@ struct ex_data_schema *ex_data_schema_new(maat_ex_new_func_t *new_func,
|
||||
long argl, void *argp);
|
||||
void ex_data_schema_free(struct ex_data_schema *ex_schema);
|
||||
|
||||
void ex_data_runtime_set_schema(struct ex_data_runtime *ex_data_rt,
|
||||
struct ex_data_schema *schema);
|
||||
|
||||
/* set user_ctx API */
|
||||
void ex_data_runtime_set_ex_container_schema(struct ex_data_runtime *ex_data_rt,
|
||||
struct ex_container_schema *container_schema);
|
||||
@@ -78,7 +75,8 @@ struct ex_container *ex_container_new(void *ex_data, void *custom_data);
|
||||
void ex_container_free(void *ctx, void *data);
|
||||
|
||||
/* ex_data_runtime ex data API */
|
||||
void *ex_data_runtime_row2ex_data(struct ex_data_runtime *ex_data_rt,
|
||||
void *ex_data_runtime_row2ex_data(struct ex_data_runtime *ex_data_rt,
|
||||
struct ex_data_schema *ex_schema,
|
||||
const char *row, const char *key,
|
||||
size_t key_len);
|
||||
|
||||
@@ -96,10 +94,12 @@ size_t ex_data_runtime_ex_container_count(struct ex_data_runtime *ex_data_rt);
|
||||
|
||||
int ex_data_runtime_is_updating(struct ex_data_runtime *ex_data_rt);
|
||||
|
||||
void *ex_data_runtime_get_ex_data_by_key(struct ex_data_runtime *ex_data_rt,
|
||||
void *ex_data_runtime_get_ex_data_by_key(struct ex_data_runtime *ex_data_rt,
|
||||
struct ex_data_schema *ex_schema,
|
||||
const char *key, size_t key_len);
|
||||
|
||||
void *ex_data_runtime_get_ex_data_by_container(struct ex_data_runtime *ex_data_rt,
|
||||
struct ex_data_schema *ex_schema,
|
||||
struct ex_container *ex_container);
|
||||
|
||||
void *ex_data_runtime_get_custom_data(struct ex_data_runtime *ex_data_rt,
|
||||
|
||||
@@ -49,8 +49,8 @@ int fqdn_plugin_runtime_commit(void *fqdn_plugin_runtime, const char *table_name
|
||||
|
||||
struct ex_data_runtime *fqdn_plugin_runtime_get_ex_data_rt(void *fqdn_plugin_runtime);
|
||||
|
||||
int fqdn_plugin_runtime_get_ex_data(void *fqdn_plugin_runtime, const char *fqdn,
|
||||
void **ex_data_array, size_t n_ex_data);
|
||||
int fqdn_plugin_runtime_get_ex_data(void *fqdn_plugin_runtime, void *fqdn_plugin_schema,
|
||||
const char *fqdn, void **ex_data_array, size_t n_ex_data);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -49,8 +49,9 @@ int ip_plugin_runtime_commit(void *ip_plugin_runtime, const char *table_name);
|
||||
|
||||
struct ex_data_runtime *ip_plugin_runtime_get_ex_data_rt(void *ip_plugin_runtime);
|
||||
|
||||
int ip_plugin_runtime_get_ex_data(void *ip_plugin_runtime, const struct ip_addr *ip_addr,
|
||||
void **ex_data_array, size_t n_ex_data_array);
|
||||
int ip_plugin_runtime_get_ex_data(void *ip_plugin_runtime, void *ip_plugin_schema,
|
||||
const struct ip_addr *ip_addr, void **ex_data_array,
|
||||
size_t n_ex_data_array);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -601,34 +601,33 @@ int generic_plugin_table_set_ex_schema(struct table_manager *tbl_mgr, int table_
|
||||
void generic_plugin_runtime_commit_ex_schema(void *runtime, void *schema, int table_id,
|
||||
enum table_type table_type, int valid_column)
|
||||
{
|
||||
struct ex_data_schema *ex_data_schema = NULL;
|
||||
struct ex_data_schema *ex_schema = NULL;
|
||||
struct ex_data_runtime *ex_data_rt = NULL;
|
||||
|
||||
switch (table_type) {
|
||||
case TABLE_TYPE_PLUGIN:
|
||||
ex_data_schema = plugin_table_get_ex_data_schema(schema);
|
||||
ex_schema = plugin_table_get_ex_data_schema(schema);
|
||||
ex_data_rt = plugin_runtime_get_ex_data_rt(runtime);
|
||||
break;
|
||||
case TABLE_TYPE_IP_PLUGIN:
|
||||
ex_data_schema = ip_plugin_table_get_ex_data_schema(schema);
|
||||
ex_schema = ip_plugin_table_get_ex_data_schema(schema);
|
||||
ex_data_rt = ip_plugin_runtime_get_ex_data_rt(runtime);
|
||||
break;
|
||||
case TABLE_TYPE_FQDN_PLUGIN:
|
||||
ex_data_schema = fqdn_plugin_table_get_ex_data_schema(schema);
|
||||
ex_schema = fqdn_plugin_table_get_ex_data_schema(schema);
|
||||
ex_data_rt = fqdn_plugin_runtime_get_ex_data_rt(runtime);
|
||||
break;
|
||||
case TABLE_TYPE_BOOL_PLUGIN:
|
||||
ex_data_schema = bool_plugin_table_get_ex_data_schema(schema);
|
||||
ex_schema = bool_plugin_table_get_ex_data_schema(schema);
|
||||
ex_data_rt = bool_plugin_runtime_get_ex_data_rt(runtime);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
ex_data_runtime_set_schema(ex_data_rt, ex_data_schema);
|
||||
struct ex_container_schema *container_schema = ALLOC(struct ex_container_schema, 1);
|
||||
container_schema->table_id = table_id;
|
||||
container_schema->ex_schema = ex_data_schema;
|
||||
container_schema->ex_schema = ex_schema;
|
||||
ex_data_runtime_set_ex_container_schema(ex_data_rt, container_schema);
|
||||
|
||||
size_t n_cached_row = ex_data_runtime_cached_row_count(ex_data_rt);
|
||||
@@ -809,7 +808,16 @@ int maat_ip_plugin_table_get_ex_data(struct maat *maat_instance, int table_id,
|
||||
return -1;
|
||||
}
|
||||
|
||||
int n_hit_ex_data = ip_plugin_runtime_get_ex_data(ip_plugin_rt, ip_addr, ex_data_array, n_ex_data);
|
||||
void *ip_plugin_schema = table_manager_get_schema(maat_rt->ref_tbl_mgr, table_id);
|
||||
if (NULL == ip_plugin_schema) {
|
||||
log_error(maat_instance->logger, MODULE_MAAT_API,
|
||||
"[%s:%d] table(table_id:%d) schema is NULL",
|
||||
__FUNCTION__, __LINE__, table_id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int n_hit_ex_data = ip_plugin_runtime_get_ex_data(ip_plugin_rt, ip_plugin_schema, ip_addr,
|
||||
ex_data_array, n_ex_data);
|
||||
if (n_hit_ex_data < 0) {
|
||||
log_error(maat_instance->logger, MODULE_MAAT_API,
|
||||
"[%s:%d] ip_plugin table(table_id:%d) get ex_data error.",
|
||||
@@ -848,7 +856,16 @@ int maat_fqdn_plugin_table_get_ex_data(struct maat *maat_instance, int table_id,
|
||||
return -1;
|
||||
}
|
||||
|
||||
int n_hit_ex_data = fqdn_plugin_runtime_get_ex_data(fqdn_plugin_rt, fqdn, ex_data_array, n_ex_data);
|
||||
void *fqdn_plugin_schema = table_manager_get_schema(maat_rt->ref_tbl_mgr, table_id);
|
||||
if (NULL == fqdn_plugin_schema) {
|
||||
log_error(maat_instance->logger, MODULE_MAAT_API,
|
||||
"[%s:%d] table(table_id:%d) schema is NULL",
|
||||
__FUNCTION__, __LINE__, table_id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int n_hit_ex_data = fqdn_plugin_runtime_get_ex_data(fqdn_plugin_rt, fqdn_plugin_schema,
|
||||
fqdn, ex_data_array, n_ex_data);
|
||||
if (n_hit_ex_data < 0) {
|
||||
log_error(maat_instance->logger, MODULE_MAAT_API,
|
||||
"[%s:%d] fqdn_plugin table(table_id:%d) get ex_data error.",
|
||||
@@ -887,7 +904,17 @@ 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, ex_data_array, n_ex_data);
|
||||
void *bool_plugin_schema = table_manager_get_schema(maat_rt->ref_tbl_mgr, table_id);
|
||||
if (NULL == bool_plugin_schema) {
|
||||
log_error(maat_instance->logger, MODULE_MAAT_API,
|
||||
"[%s:%d] table(table_id:%d) schema is NULL",
|
||||
__FUNCTION__, __LINE__, table_id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int n_hit_ex_data = bool_plugin_runtime_get_ex_data(bool_plugin_rt, bool_plugin_schema,
|
||||
item_ids, n_item, ex_data_array,
|
||||
n_ex_data);
|
||||
if (n_hit_ex_data < 0) {
|
||||
log_error(maat_instance->logger, MODULE_MAAT_API,
|
||||
"[%s:%d] bool_plugin table(table_id:%d) get ex_data error.",
|
||||
|
||||
@@ -212,6 +212,7 @@ void bool_plugin_runtime_free(void *bool_plugin_runtime)
|
||||
}
|
||||
|
||||
int bool_plugin_runtime_update_row(struct bool_plugin_runtime *bool_plugin_rt,
|
||||
struct ex_data_schema *ex_schema,
|
||||
const char *row, char *key, size_t key_len,
|
||||
struct bool_expr *expr, int is_valid)
|
||||
{
|
||||
@@ -226,7 +227,7 @@ int bool_plugin_runtime_update_row(struct bool_plugin_runtime *bool_plugin_rt,
|
||||
}
|
||||
} else {
|
||||
// add
|
||||
void *ex_data = ex_data_runtime_row2ex_data(ex_data_rt, row, key, key_len);
|
||||
void *ex_data = ex_data_runtime_row2ex_data(ex_data_rt, ex_schema, row, key, key_len);
|
||||
struct ex_container *ex_container = ex_container_new(ex_data, (void *)expr);
|
||||
ret = ex_data_runtime_add_ex_container(ex_data_rt, key, key_len, ex_container);
|
||||
if (ret < 0) {
|
||||
@@ -369,7 +370,8 @@ int bool_plugin_runtime_update(void *bool_plugin_runtime, void *bool_plugin_sche
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (schema->ex_schema != NULL) {
|
||||
struct ex_data_schema *ex_schema = schema->ex_schema;
|
||||
if (ex_schema != NULL) {
|
||||
if (1 == is_valid) {
|
||||
// add
|
||||
bool_expr = bool_plugin_expr_new(line, schema, bool_plugin_rt->logger);
|
||||
@@ -379,7 +381,7 @@ int bool_plugin_runtime_update(void *bool_plugin_runtime, void *bool_plugin_sche
|
||||
}
|
||||
|
||||
char *key = (char *)&item_id;
|
||||
int ret = bool_plugin_runtime_update_row(bool_plugin_rt, line, key,
|
||||
int ret = bool_plugin_runtime_update_row(bool_plugin_rt, ex_schema, line, key,
|
||||
sizeof(long long), bool_expr, is_valid);
|
||||
if (ret < 0) {
|
||||
if (bool_expr != NULL) {
|
||||
@@ -475,10 +477,17 @@ struct ex_data_runtime *bool_plugin_runtime_get_ex_data_rt(void *bool_plugin_run
|
||||
return bool_plugin_rt->ex_data_rt;
|
||||
}
|
||||
|
||||
int bool_plugin_runtime_get_ex_data(void *bool_plugin_runtime, unsigned long long *item_ids,
|
||||
size_t n_item, void **ex_data_array, size_t n_ex_data)
|
||||
int bool_plugin_runtime_get_ex_data(void *bool_plugin_runtime, void *bool_plugin_schema,
|
||||
unsigned long long *item_ids, size_t n_item,
|
||||
void **ex_data_array, size_t n_ex_data)
|
||||
{
|
||||
if (NULL == bool_plugin_runtime) {
|
||||
if (NULL == bool_plugin_runtime || NULL == bool_plugin_schema) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct bool_plugin_schema *schema = (struct bool_plugin_schema *)bool_plugin_schema;
|
||||
struct ex_data_schema *ex_schema = schema->ex_schema;
|
||||
if (NULL == ex_schema) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -494,7 +503,7 @@ int bool_plugin_runtime_get_ex_data(void *bool_plugin_runtime, unsigned long lon
|
||||
assert(bool_plugin_rt->matcher != NULL);
|
||||
int n_result = bool_matcher_match(bool_plugin_rt->matcher, item_ids, n_item, results, n_ex_data);
|
||||
for (int i = 0; i < n_result; i++) {
|
||||
ex_data_array[i] = ex_data_runtime_get_ex_data_by_container(bool_plugin_rt->ex_data_rt,
|
||||
ex_data_array[i] = ex_data_runtime_get_ex_data_by_container(bool_plugin_rt->ex_data_rt, ex_schema,
|
||||
(struct ex_container *)results[i].user_tag);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ struct ex_data_runtime {
|
||||
size_t cache_size;
|
||||
|
||||
struct rcu_hash_table *htable;
|
||||
struct ex_data_schema *ref_ex_schema;
|
||||
struct maat_garbage_bin *ref_garbage_bin;
|
||||
int table_id;
|
||||
|
||||
@@ -158,16 +157,6 @@ void ex_data_schema_free(struct ex_data_schema *ex_schema)
|
||||
|
||||
}
|
||||
|
||||
void ex_data_runtime_set_schema(struct ex_data_runtime *ex_data_rt,
|
||||
struct ex_data_schema *schema)
|
||||
{
|
||||
if (NULL == ex_data_rt) {
|
||||
return;
|
||||
}
|
||||
|
||||
ex_data_rt->ref_ex_schema = schema;
|
||||
}
|
||||
|
||||
void ex_data_runtime_set_ex_container_schema(struct ex_data_runtime *ex_data_rt,
|
||||
struct ex_container_schema *container_schema)
|
||||
{
|
||||
@@ -188,14 +177,15 @@ ex_data_runtime_get_ex_container_schema(struct ex_data_runtime *ex_data_rt)
|
||||
return (struct ex_container_schema *)rcu_hash_get_user_ctx(ex_data_rt->htable);
|
||||
}
|
||||
|
||||
void *ex_data_runtime_row2ex_data(struct ex_data_runtime *ex_data_rt, const char *row,
|
||||
const char *key, size_t key_len)
|
||||
void *ex_data_runtime_row2ex_data(struct ex_data_runtime *ex_data_rt,
|
||||
struct ex_data_schema *ex_schema,
|
||||
const char *row, const char *key,
|
||||
size_t key_len)
|
||||
{
|
||||
void *ex_data = NULL;
|
||||
struct ex_data_schema *ex_schema = ex_data_rt->ref_ex_schema;
|
||||
|
||||
ex_schema->new_func(ex_data_rt->table_id, key, row, &ex_data,
|
||||
ex_schema->argl, ex_schema->argp);
|
||||
|
||||
return ex_data;
|
||||
}
|
||||
|
||||
@@ -252,7 +242,8 @@ int ex_data_runtime_del_ex_container(struct ex_data_runtime *ex_data_rt,
|
||||
return rcu_hash_del(ex_data_rt->htable, key, key_len);
|
||||
}
|
||||
|
||||
void *ex_data_runtime_get_ex_data_by_key(struct ex_data_runtime *ex_data_rt,
|
||||
void *ex_data_runtime_get_ex_data_by_key(struct ex_data_runtime *ex_data_rt,
|
||||
struct ex_data_schema *ex_schema,
|
||||
const char *key, size_t key_len)
|
||||
{
|
||||
struct ex_container *ex_container = NULL;
|
||||
@@ -264,21 +255,18 @@ void *ex_data_runtime_get_ex_data_by_key(struct ex_data_runtime *ex_data_rt,
|
||||
}
|
||||
|
||||
void *dup_ex_data = NULL;
|
||||
ex_data_rt->ref_ex_schema->dup_func(ex_data_rt->table_id, &dup_ex_data,
|
||||
&(ex_container->ex_data),
|
||||
ex_data_rt->ref_ex_schema->argl,
|
||||
ex_data_rt->ref_ex_schema->argp);
|
||||
ex_schema->dup_func(ex_data_rt->table_id, &dup_ex_data, &(ex_container->ex_data),
|
||||
ex_schema->argl, ex_schema->argp);
|
||||
return dup_ex_data;
|
||||
}
|
||||
|
||||
void *ex_data_runtime_get_ex_data_by_container(struct ex_data_runtime *ex_data_rt,
|
||||
void *ex_data_runtime_get_ex_data_by_container(struct ex_data_runtime *ex_data_rt,
|
||||
struct ex_data_schema *ex_schema,
|
||||
struct ex_container *ex_container)
|
||||
{
|
||||
void *dup_ex_data = NULL;
|
||||
ex_data_rt->ref_ex_schema->dup_func(ex_data_rt->table_id, &dup_ex_data,
|
||||
&(ex_container->ex_data),
|
||||
ex_data_rt->ref_ex_schema->argl,
|
||||
ex_data_rt->ref_ex_schema->argp);
|
||||
ex_schema->dup_func(ex_data_rt->table_id, &dup_ex_data, &(ex_container->ex_data),
|
||||
ex_schema->argl, ex_schema->argp);
|
||||
return dup_ex_data;
|
||||
}
|
||||
|
||||
|
||||
@@ -304,7 +304,8 @@ void fqdn_plugin_rule_free(struct FQDN_rule *rule)
|
||||
}
|
||||
|
||||
int fqdn_plugin_runtime_update_row(struct fqdn_plugin_runtime *fqdn_plugin_rt,
|
||||
const char *row, const char *key, size_t key_len,
|
||||
struct ex_data_schema *ex_schema, const char *row,
|
||||
const char *key, size_t key_len,
|
||||
struct FQDN_rule *fqdn_plugin_rule, int is_valid)
|
||||
{
|
||||
int ret = -1;
|
||||
@@ -318,7 +319,7 @@ int fqdn_plugin_runtime_update_row(struct fqdn_plugin_runtime *fqdn_plugin_rt,
|
||||
}
|
||||
} else {
|
||||
// add
|
||||
void *ex_data = ex_data_runtime_row2ex_data(ex_data_rt, row, key, key_len);
|
||||
void *ex_data = ex_data_runtime_row2ex_data(ex_data_rt, ex_schema, row, key, key_len);
|
||||
struct ex_container *ex_container = ex_container_new(ex_data, (void *)fqdn_plugin_rule);
|
||||
ret = ex_data_runtime_add_ex_container(ex_data_rt, key, key_len, ex_container);
|
||||
if (ret < 0) {
|
||||
@@ -350,7 +351,8 @@ int fqdn_plugin_runtime_update(void *fqdn_plugin_runtime, void *fqdn_plugin_sche
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (schema->ex_schema != NULL) {
|
||||
struct ex_data_schema *ex_schema = schema->ex_schema;
|
||||
if (ex_schema != NULL) {
|
||||
if (1 == is_valid) {
|
||||
// add
|
||||
fqdn_plugin_rule = fqdn_plugin_rule_new(line, schema, fqdn_plugin_rt->logger);
|
||||
@@ -360,19 +362,13 @@ int fqdn_plugin_runtime_update(void *fqdn_plugin_runtime, void *fqdn_plugin_sche
|
||||
}
|
||||
|
||||
char *key = (char *)&item_id;
|
||||
int ret = fqdn_plugin_runtime_update_row(fqdn_plugin_rt, line, key, sizeof(long long),
|
||||
int ret = fqdn_plugin_runtime_update_row(fqdn_plugin_rt, ex_schema, line, key, sizeof(long long),
|
||||
fqdn_plugin_rule, is_valid);
|
||||
if (ret < 0) {
|
||||
if (fqdn_plugin_rule != NULL) {
|
||||
fqdn_plugin_rule_free(fqdn_plugin_rule);
|
||||
}
|
||||
return -1;
|
||||
} else {
|
||||
if (0 == is_valid) {
|
||||
fqdn_plugin_rt->rule_num--;
|
||||
} else {
|
||||
fqdn_plugin_rt->rule_num++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//ex_schema not set
|
||||
@@ -462,10 +458,17 @@ struct ex_data_runtime *fqdn_plugin_runtime_get_ex_data_rt(void *fqdn_plugin_run
|
||||
}
|
||||
|
||||
|
||||
int fqdn_plugin_runtime_get_ex_data(void *fqdn_plugin_runtime, const char *query_fqdn,
|
||||
void **ex_data_array, size_t n_ex_data)
|
||||
int fqdn_plugin_runtime_get_ex_data(void *fqdn_plugin_runtime, void *fqdn_plugin_schema,
|
||||
const char *query_fqdn, void **ex_data_array,
|
||||
size_t n_ex_data)
|
||||
{
|
||||
if (NULL == fqdn_plugin_runtime) {
|
||||
if (NULL == fqdn_plugin_runtime || NULL == fqdn_plugin_schema) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct fqdn_plugin_schema *schema = (struct fqdn_plugin_schema *)fqdn_plugin_schema;
|
||||
struct ex_data_schema *ex_schema = schema->ex_schema;
|
||||
if (NULL == ex_schema) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -480,7 +483,7 @@ int fqdn_plugin_runtime_get_ex_data(void *fqdn_plugin_runtime, const char *query
|
||||
assert(fqdn_plugin_rt->engine != NULL);
|
||||
int n_result = FQDN_engine_search(fqdn_plugin_rt->engine, query_fqdn, strlen(query_fqdn), results, n_ex_data);
|
||||
for (int i = 0; i < n_result; i++) {
|
||||
ex_data_array[i] = ex_data_runtime_get_ex_data_by_container(fqdn_plugin_rt->ex_data_rt,
|
||||
ex_data_array[i] = ex_data_runtime_get_ex_data_by_container(fqdn_plugin_rt->ex_data_rt, ex_schema,
|
||||
(struct ex_container *)results[i].user_tag);
|
||||
}
|
||||
|
||||
|
||||
@@ -311,8 +311,9 @@ void ip_plugin_table_set_ex_data_schema(void *ip_plugin_schema,
|
||||
}
|
||||
|
||||
int ip_plugin_runtime_update_row(struct ip_plugin_runtime *ip_plugin_rt,
|
||||
const char *row, char *key, size_t key_len,
|
||||
struct ip_rule *ip_plugin_rule, int is_valid)
|
||||
struct ex_data_schema *ex_schema,
|
||||
const char *row, char *key, size_t key_len,
|
||||
struct ip_rule *ip_plugin_rule, int is_valid)
|
||||
{
|
||||
int ret = -1;
|
||||
struct ex_data_runtime *ex_data_rt = ip_plugin_rt->ex_data_rt;
|
||||
@@ -328,7 +329,7 @@ int ip_plugin_runtime_update_row(struct ip_plugin_runtime *ip_plugin_rt,
|
||||
}
|
||||
} else {
|
||||
// add
|
||||
void *ex_data = ex_data_runtime_row2ex_data(ex_data_rt, row, key, key_len);
|
||||
void *ex_data = ex_data_runtime_row2ex_data(ex_data_rt, ex_schema, row, key, key_len);
|
||||
struct ex_container *ex_container = ex_container_new(ex_data, (void *)ip_plugin_rule);
|
||||
ret = ex_data_runtime_add_ex_container(ex_data_rt, key, key_len, ex_container);
|
||||
if (ret < 0) {
|
||||
@@ -399,7 +400,8 @@ int ip_plugin_runtime_update(void *ip_plugin_runtime, void *ip_plugin_schema,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (schema->ex_schema != NULL) {
|
||||
struct ex_data_schema *ex_schema = schema->ex_schema;
|
||||
if (ex_schema != NULL) {
|
||||
if (1 == is_valid) {
|
||||
// add
|
||||
ip_plugin_rule = ip_plugin_rule_new(line, schema, ip_plugin_rt->logger);
|
||||
@@ -409,8 +411,9 @@ int ip_plugin_runtime_update(void *ip_plugin_runtime, void *ip_plugin_schema,
|
||||
}
|
||||
|
||||
char *key = (char *)&item_id;
|
||||
int ret = ip_plugin_runtime_update_row(ip_plugin_rt, line, key, sizeof(long long),
|
||||
ip_plugin_rule, is_valid);
|
||||
int ret = ip_plugin_runtime_update_row(ip_plugin_rt, ex_schema, line, key,
|
||||
sizeof(long long), ip_plugin_rule,
|
||||
is_valid);
|
||||
if (ret < 0) {
|
||||
if (ip_plugin_rule != NULL) {
|
||||
ip_plugin_rule_free(ip_plugin_rule);
|
||||
@@ -505,10 +508,17 @@ struct ex_data_runtime *ip_plugin_runtime_get_ex_data_rt(void *ip_plugin_runtime
|
||||
return ip_plugin_rt->ex_data_rt;
|
||||
}
|
||||
|
||||
int ip_plugin_runtime_get_ex_data(void *ip_plugin_runtime, const struct ip_addr *ip_addr,
|
||||
void **ex_data_array, size_t n_ex_data)
|
||||
int ip_plugin_runtime_get_ex_data(void *ip_plugin_runtime, void *ip_plugin_schema,
|
||||
const struct ip_addr *ip_addr, void **ex_data_array,
|
||||
size_t n_ex_data)
|
||||
{
|
||||
if (NULL == ip_plugin_runtime) {
|
||||
if (NULL == ip_plugin_runtime || NULL == ip_plugin_schema) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct ip_plugin_schema *schema = (struct ip_plugin_schema *)ip_plugin_schema;
|
||||
struct ex_data_schema *ex_schema = schema->ex_schema;
|
||||
if (NULL == ex_schema) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -530,7 +540,7 @@ int ip_plugin_runtime_get_ex_data(void *ip_plugin_runtime, const struct ip_addr
|
||||
assert(ip_plugin_rt->ip_matcher != NULL);
|
||||
int n_result = ip_matcher_match(ip_plugin_rt->ip_matcher, &ip_data, results, n_ex_data);
|
||||
for (int i = 0; i < n_result; i++) {
|
||||
ex_data_array[i] = ex_data_runtime_get_ex_data_by_container(ip_plugin_rt->ex_data_rt,
|
||||
ex_data_array[i] = ex_data_runtime_get_ex_data_by_container(ip_plugin_rt->ex_data_rt, ex_schema,
|
||||
(struct ex_container *)results[i].tag);
|
||||
}
|
||||
return n_result;
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "log/log.h"
|
||||
#include "maat_utils.h"
|
||||
@@ -20,6 +22,12 @@
|
||||
|
||||
#define MODULE_PLUGIN module_name_str("maat.plugin")
|
||||
|
||||
enum plugin_key_type {
|
||||
PLUGIN_KEY_TYPE_INVALID = 0,
|
||||
PLUGIN_KEY_TYPE_POINTER,
|
||||
PLUGIN_KEY_TYPE_INTEGER
|
||||
};
|
||||
|
||||
struct plugin_callback_schema {
|
||||
maat_start_callback_t *start;
|
||||
maat_update_callback_t *update;
|
||||
@@ -40,6 +48,7 @@ struct plugin_runtime {
|
||||
#define MAX_PLUGIN_PER_TABLE 32
|
||||
struct plugin_schema {
|
||||
int key_column;
|
||||
enum plugin_key_type key_type;
|
||||
int rule_tag_column;
|
||||
int n_foreign;
|
||||
int foreign_columns[MAX_FOREIGN_CLMN_NUM];
|
||||
@@ -102,6 +111,26 @@ void *plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
|
||||
}
|
||||
schema->key_column = custom_item->valueint;
|
||||
|
||||
custom_item = cJSON_GetObjectItem(item, "key_type");
|
||||
if (NULL == custom_item || custom_item->type != cJSON_String) {
|
||||
log_error(logger, MODULE_PLUGIN,
|
||||
"[%s:%d] plugin table: %s has no key_type column",
|
||||
__FUNCTION__, __LINE__, table_name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (strcmp(custom_item->valuestring, "pointer") == 0) {
|
||||
schema->key_type = PLUGIN_KEY_TYPE_POINTER;
|
||||
} else if (strcmp(custom_item->valuestring, "integer") == 0) {
|
||||
schema->key_type = PLUGIN_KEY_TYPE_INTEGER;
|
||||
} else {
|
||||
log_error(logger, MODULE_PLUGIN,
|
||||
"[%s:%d] plugin table: %s key_type:%s illegal",
|
||||
__FUNCTION__, __LINE__, table_name,
|
||||
custom_item->valuestring);
|
||||
goto error;
|
||||
}
|
||||
|
||||
custom_item = cJSON_GetObjectItem(item, "tag");
|
||||
if (custom_item != NULL && custom_item->type == cJSON_Number) {
|
||||
schema->rule_tag_column = custom_item->valueint;
|
||||
@@ -281,7 +310,7 @@ int plugin_runtime_update_row(struct plugin_runtime *plugin_rt,
|
||||
}
|
||||
} else {
|
||||
// add
|
||||
void *ex_data = ex_data_runtime_row2ex_data(plugin_rt->ex_data_rt, row, key, key_len);
|
||||
void *ex_data = ex_data_runtime_row2ex_data(plugin_rt->ex_data_rt, ex_schema, row, key, key_len);
|
||||
struct ex_container *ex_container = ex_container_new(ex_data, NULL);
|
||||
ret = ex_data_runtime_add_ex_container(plugin_rt->ex_data_rt, key, key_len, ex_container);
|
||||
if (ret < 0) {
|
||||
@@ -452,9 +481,18 @@ 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 (NULL == schema->ex_schema) {
|
||||
struct ex_data_schema *ex_schema = schema->ex_schema;
|
||||
if (NULL == ex_schema) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ex_data_runtime_get_ex_data_by_key(plugin_rt->ex_data_rt, key, key_len);
|
||||
if (schema->key_type == PLUGIN_KEY_TYPE_INTEGER) {
|
||||
char key_str[MAX_KEYWORDS_STR] = {0};
|
||||
long long key_int = *(long long *)key;
|
||||
sprintf(key_str, "%lld", key_int);
|
||||
key_len = strlen(key_str);
|
||||
return ex_data_runtime_get_ex_data_by_key(plugin_rt->ex_data_rt, ex_schema, key_str, key_len);
|
||||
} else {
|
||||
return ex_data_runtime_get_ex_data_by_key(plugin_rt->ex_data_rt, ex_schema, key, key_len);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user