使用一个API同时获取第三方设备状态和MAC Address
This commit is contained in:
@@ -209,8 +209,6 @@ const char *session_action_reason_to_string(enum session_action_reason session_a
|
||||
return "bypass_due_failure_action";
|
||||
case ACTION_BYPASS_DUE_INVALID_POLICY:
|
||||
return "bypass_due_invalid_policy";
|
||||
case ACTION_BYPASS_DUE_INVALID_SF_MAC:
|
||||
return "bypass_due_invalid_sf_mac";
|
||||
case ACTION_BLOCK_DUE_UNAVAILABLE_ACTION:
|
||||
return "block_due_unavailable_action";
|
||||
case ACTION_BLOCK_DUE_FAILURE_ACTION:
|
||||
@@ -838,14 +836,6 @@ static void sf_param_new_cb(int table_id, const char *key, const char *table_lin
|
||||
}
|
||||
memcpy(param->sf_connectivity.dest_ip, item->valuestring, strlen(item->valuestring));
|
||||
LOG_DEBUG("%s: parse sf profile: %d, connectivity->dest_ip: %s", LOG_TAG_POLICY, param->sf_profile_id, item->valuestring);
|
||||
|
||||
// CM does not send this field, but only reads it from json, which is used for debugging
|
||||
item = cJSON_GetObjectItem(root1, "dest_mac");
|
||||
if (item && cJSON_IsString(item))
|
||||
{
|
||||
memcpy(param->sf_connectivity.dest_mac, item->valuestring, strlen(item->valuestring));
|
||||
LOG_DEBUG("%s: parse sf profile: %d, connectivity->dst_mac: %s", LOG_TAG_POLICY, param->sf_profile_id, item->valuestring);
|
||||
}
|
||||
}
|
||||
|
||||
// health_check
|
||||
@@ -1029,13 +1019,12 @@ static void select_sf_by_nearby_and_active(struct policy_enforcer *enforcer, str
|
||||
// return : SESSION_ACTION_BYPASS, not care selected_sf_profile_id
|
||||
// return : SESSION_ACTION_BLOCK, not care selected_sf_profile_id
|
||||
// return : SESSION_ACTION_FORWARD, care selected_sf_profile_id
|
||||
static enum session_action select_sf_by_ldbc(uint64_t hash, struct sff_param *sff_param, struct fixed_num_array *array, int *selected_sf_profile_id, enum session_action_reason *sf_action_reason, struct session_ctx *s_ctx)
|
||||
static enum session_action select_sf_by_ldbc(uint64_t hash, struct sff_param *sff_param, struct fixed_num_array *array, int *selected_sf_profile_id, enum session_action_reason *sf_action_reason, char *sf_dst_mac, struct session_ctx *s_ctx)
|
||||
{
|
||||
struct thread_ctx *thread = (struct thread_ctx *)s_ctx->ref_thread_ctx;
|
||||
struct global_metrics *g_metrics = thread->ref_metrics;
|
||||
|
||||
*selected_sf_profile_id = -1;
|
||||
int sf_is_active = 0;
|
||||
int sf_profile_id = 0;
|
||||
int sf_profile_index = 0;
|
||||
int sf_profile_num = 0;
|
||||
@@ -1046,9 +1035,9 @@ static enum session_action select_sf_by_ldbc(uint64_t hash, struct sff_param *sf
|
||||
{
|
||||
sf_profile_index = (int)(hash % sf_profile_num);
|
||||
sf_profile_id = fixed_num_array_index_elem(array, sf_profile_index);
|
||||
sf_is_active = health_check_session_get_status(sf_profile_id);
|
||||
|
||||
if (sf_is_active == 1)
|
||||
memset(sf_dst_mac, 0, 32);
|
||||
if (health_check_session_get_mac(sf_profile_id, sf_dst_mac) == 0)
|
||||
{
|
||||
__atomic_fetch_add(&g_metrics->sf_active_times, 1, __ATOMIC_RELAXED);
|
||||
|
||||
@@ -1488,7 +1477,7 @@ void policy_enforce_select_chaining(struct selected_chaining *chaining, struct p
|
||||
}
|
||||
|
||||
hash_value = raw_packet_parser_get_hash_value(parser, sff_param->sff_ldbc.method, dir_is_internal);
|
||||
item->sf_action = select_sf_by_ldbc(hash_value, sff_param, &array, &(item->sf_profile_id), &(item->sf_action_reason), s_ctx);
|
||||
item->sf_action = select_sf_by_ldbc(hash_value, sff_param, &array, &(item->sf_profile_id), &(item->sf_action_reason), item->sf_dst_mac, s_ctx);
|
||||
LOG_DEBUG("%s: chaining policy %d -> sff_profile %d sf_profile_ids_num %d (after filter ldbc)", LOG_TAG_POLICY, policy_id, item->sff_profile_id, fixed_num_array_count_elem(&array));
|
||||
if (item->sf_action != SESSION_ACTION_FORWARD)
|
||||
{
|
||||
@@ -1514,32 +1503,8 @@ void policy_enforce_select_chaining(struct selected_chaining *chaining, struct p
|
||||
item->sf_connectivity.int_vlan_tag = sf_param->sf_connectivity.int_vlan_tag;
|
||||
item->sf_connectivity.ext_vlan_tag = sf_param->sf_connectivity.ext_vlan_tag;
|
||||
memcpy(item->sf_connectivity.dest_ip, sf_param->sf_connectivity.dest_ip, strlen(sf_param->sf_connectivity.dest_ip));
|
||||
|
||||
memcpy(item->sf_dst_ip, sf_param->sf_connectivity.dest_ip, strlen(sf_param->sf_connectivity.dest_ip));
|
||||
if (strlen(sf_param->sf_connectivity.dest_mac))
|
||||
{
|
||||
// CM does not send this field, but only reads it from json, which is used for debugging
|
||||
memcpy(item->sf_dst_mac, sf_param->sf_connectivity.dest_ip, strlen(sf_param->sf_connectivity.dest_ip));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (health_check_session_get_mac(item->sf_profile_id, item->sf_dst_mac) == 0)
|
||||
{
|
||||
__atomic_fetch_add(&g_metrics->sf_mac_exist_times, 1, __ATOMIC_RELAXED);
|
||||
}
|
||||
else
|
||||
{
|
||||
__atomic_fetch_add(&g_metrics->sf_mac_noexist_times, 1, __ATOMIC_RELAXED);
|
||||
|
||||
LOG_ERROR("%s: failed to get sf mac address of selected profile %d, bypass current sff !!!", LOG_TAG_POLICY, item->sf_profile_id);
|
||||
item->sf_action = SESSION_ACTION_BYPASS;
|
||||
item->sf_action_reason = ACTION_BYPASS_DUE_INVALID_SF_MAC;
|
||||
chaining->chaining_used++;
|
||||
sff_param_free(sff_param);
|
||||
sf_param_free(sf_param);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
chaining->chaining_used++;
|
||||
|
||||
sf_param_free(sf_param);
|
||||
|
||||
Reference in New Issue
Block a user