修正部分maat回调表指针的问题
This commit is contained in:
@@ -24,14 +24,14 @@ void policy_table_ex_data_free(struct policy_table_ex_data * object)
|
||||
void policy_table_ex_data_dup_cb(int table_id, MAAT_PLUGIN_EX_DATA * to,
|
||||
MAAT_PLUGIN_EX_DATA * from, long argl, void * argp)
|
||||
{
|
||||
struct policy_table_ex_data * ex_data = (struct policy_table_ex_data *)from;
|
||||
struct policy_table_ex_data * ex_data = (struct policy_table_ex_data *)*from;
|
||||
__sync_add_and_fetch(&ex_data->atomic_refcnt, 1);
|
||||
*to = (void *)ex_data;
|
||||
}
|
||||
|
||||
void policy_table_ex_data_free_cb(int table_id, MAAT_PLUGIN_EX_DATA * ad, long argl, void * argp)
|
||||
{
|
||||
struct policy_table_ex_data * ex_data = (struct policy_table_ex_data *)argp;
|
||||
struct policy_table_ex_data * ex_data = (struct policy_table_ex_data *)*ad;
|
||||
policy_table_ex_data_free(ex_data);
|
||||
}
|
||||
|
||||
@@ -100,19 +100,18 @@ void policy_table_ex_data_new_cb(int table_id, const char * key, const char * ta
|
||||
goto ignore;
|
||||
}
|
||||
|
||||
ex_data->profile_id = json_item->valueint;
|
||||
|
||||
success:
|
||||
TFE_LOG_DEBUG(instance->logger, "table line in PXY_INTERCEPT_COMPILE added: %s", table_line);
|
||||
TFE_LOG_DEBUG(instance->logger, "traffic mirror policy, key %s: enable = %d, profile = %d",
|
||||
key, ex_data->enable, ex_data->profile_id);
|
||||
|
||||
*ad = ex_data;
|
||||
|
||||
fprintf(stderr, "---- ex_data = %p, atomic_refcnt = %d, enable = %d, profile_id = %d\n",
|
||||
ex_data, ex_data->atomic_refcnt, ex_data->profile_id);
|
||||
|
||||
ex_data = nullptr;
|
||||
goto out;
|
||||
|
||||
ignore:
|
||||
TFE_LOG_ERROR(instance->logger, "table line in PXY_INTERCEPT_COMPILE ignored: %s", table_line);
|
||||
*ad = nullptr;
|
||||
TFE_LOG_ERROR(instance->logger, "table line in PXY_INTERCEPT_COMPILE ignored %s: %s", key, table_line);
|
||||
goto out;
|
||||
|
||||
out:
|
||||
@@ -129,14 +128,14 @@ void profile_table_ex_data_free(struct profile_table_ex_data * object)
|
||||
void profile_table_ex_data_dup_cb(int table_id, MAAT_PLUGIN_EX_DATA * to,
|
||||
MAAT_PLUGIN_EX_DATA * from, long argl, void * argp)
|
||||
{
|
||||
struct profile_table_ex_data * ex_data = (struct profile_table_ex_data *)from;
|
||||
struct profile_table_ex_data * ex_data = (struct profile_table_ex_data *)*from;
|
||||
__sync_add_and_fetch(&ex_data->atomic_refcnt, 1);
|
||||
*to = (void *)ex_data;
|
||||
}
|
||||
|
||||
void profile_table_ex_data_free_cb(int table_id, MAAT_PLUGIN_EX_DATA * ad, long argl, void * argp)
|
||||
{
|
||||
struct profile_table_ex_data * ex_data = (struct profile_table_ex_data *)ad;
|
||||
struct profile_table_ex_data * ex_data = (struct profile_table_ex_data *)*ad;
|
||||
profile_table_ex_data_free(ex_data);
|
||||
}
|
||||
|
||||
@@ -263,12 +262,11 @@ success:
|
||||
*ad = (void *)ex_data;
|
||||
ex_data = nullptr;
|
||||
|
||||
TFE_LOG_DEBUG(instance->logger, "table line in PXY_PROFILE_TRAFFIC_MIRROR added: %s", table_line);
|
||||
TFE_LOG_DEBUG(instance->logger, "traffic mirror profile %s: %s", key, str_json);
|
||||
goto out;
|
||||
|
||||
ignore:
|
||||
TFE_LOG_ERROR(instance->logger, "table line in PXY_PROFILE_TRAFFIC_MIRROR ignored: %s", table_line);
|
||||
*ad = nullptr;
|
||||
TFE_LOG_ERROR(instance->logger, "table line in PXY_PROFILE_TRAFFIC_MIRROR ignored %s: %s", key, table_line);
|
||||
goto out;
|
||||
|
||||
out:
|
||||
@@ -396,6 +394,31 @@ error_out:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int traffic_mirror_ethdev_init(struct traffic_mirror_instance * instance)
|
||||
{
|
||||
char str_ethdev[TFE_SYMBOL_MAX] = {0};
|
||||
const char * profile = "./conf/tfe/tfe.conf";
|
||||
|
||||
int ret = MESA_load_profile_string_nodef(profile, "traffic_mirror", "device",
|
||||
str_ethdev, sizeof(str_ethdev));
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
TFE_LOG_ERROR(instance->logger, "failed at reading conffile, "
|
||||
"[traffic_mirror]device is not defined.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
instance->ethdev = traffic_mirror_ethdev_pcap_create(str_ethdev, instance->logger);
|
||||
if (!instance->ethdev)
|
||||
{
|
||||
TFE_LOG_ERROR(instance->logger, "failed at traffic mirror device init ");
|
||||
return -2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int traffic_mirror_init(struct tfe_proxy * proxy)
|
||||
{
|
||||
int result = 0;
|
||||
@@ -455,6 +478,11 @@ int traffic_mirror_init(struct tfe_proxy * proxy)
|
||||
"table_id = %d, ret = %d", instance->policy_table_id, result);
|
||||
}
|
||||
|
||||
if (traffic_mirror_ethdev_init(instance) < 0)
|
||||
{
|
||||
goto errout;
|
||||
}
|
||||
|
||||
errout:
|
||||
return 0;
|
||||
}
|
||||
@@ -490,8 +518,6 @@ int traffic_mirror_on_open_cb(const struct tfe_stream * stream, unsigned int thr
|
||||
policy_ex_data = (struct policy_table_ex_data *)Maat_plugin_get_EX_data(instance->maat_feather,
|
||||
instance->policy_table_id, str_policy_id);
|
||||
|
||||
fprintf(stderr, "--- policy lookup, str_policy_id = %s, opt_val = %u\n", str_policy_id, opt_val);
|
||||
|
||||
if (!policy_ex_data)
|
||||
{
|
||||
TFE_LOG_ERROR(instance->logger, "failed at getting policy %s's EXDATA, detach the stream", str_policy_id);
|
||||
@@ -516,7 +542,7 @@ int traffic_mirror_on_open_cb(const struct tfe_stream * stream, unsigned int thr
|
||||
|
||||
|
||||
me = ALLOC(struct traffic_mirror_me, 1);
|
||||
me->rebuild_ctx = traffic_mirror_rebuild_create(stream->addr, profile_ex_data, NULL);
|
||||
me->rebuild_ctx = traffic_mirror_rebuild_create(stream->addr, profile_ex_data, instance->ethdev);
|
||||
me->profile_ex_data = profile_ex_data;
|
||||
|
||||
/* profile_ex_data's ownership is transfer to me */
|
||||
|
||||
Reference in New Issue
Block a user