diff options
| author | luwenpeng <[email protected]> | 2023-11-23 15:12:13 +0800 |
|---|---|---|
| committer | luwenpeng <[email protected]> | 2023-11-23 16:36:29 +0800 |
| commit | cbac7fea291ded728a630227e196e17543f4646d (patch) | |
| tree | 486a9cfd6a0777c7f6a322391d98043113cba32f /platform/src | |
| parent | b48b58cd4c7e3e036bd3f4bc6340a3a9fa36c702 (diff) | |
maat_plugin_table_get_ex_data的key从pointer改为integer以减少CPU的占用
Diffstat (limited to 'platform/src')
| -rw-r--r-- | platform/src/policy.cpp | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/platform/src/policy.cpp b/platform/src/policy.cpp index 1898f6d..9ee012c 100644 --- a/platform/src/policy.cpp +++ b/platform/src/policy.cpp @@ -341,7 +341,7 @@ static void chaining_param_new_cb(const char *table_name, int table_id, const ch } param = (struct chaining_param *)calloc(1, sizeof(struct chaining_param)); - param->rule_id = atoll(key); + param->rule_id = *((uint64_t *)key); param->ref_cnt = 1; // vsys_id @@ -499,7 +499,7 @@ static void sff_param_new_cb(const char *table_name, int table_id, const char *k } param = (struct sff_param *)calloc(1, sizeof(struct sff_param)); - param->sff_profile_id = atoi(key); + param->sff_profile_id = *((int *)key); param->sff_ref_cnt = 1; // type @@ -736,7 +736,7 @@ static void sf_param_new_cb(const char *table_name, int table_id, const char *ke param = (struct sf_param *)calloc(1, sizeof(struct sf_param)); param->sf_vsys_id = vsys_id; - param->sf_profile_id = atoi(key); + param->sf_profile_id = *((int *)key); param->sf_ref_cnt = 1; // device_group @@ -1223,19 +1223,18 @@ static void select_sf_by_ldbc(struct sff_param *sff_param, struct selected_sf *s static void select_sf_from_sff(struct policy_enforcer *enforcer, struct sff_param *sff_param, struct selected_sf *selected_sf, struct session_ctx *s_ctx, uint64_t packet_hash) { + int profile_id; UT_array *sf_array; UT_icd sf_icd = {sizeof(struct sf_param), NULL, NULL, NULL}; utarray_new(sf_array, &sf_icd); for (int i = 0; i < sff_param->sf_profile_ids_num; i++) { - char profile_id[16] = {0}; - snprintf(profile_id, sizeof(profile_id), "%u", sff_param->sf_profile_ids[i]); - - struct sf_param *sf = (struct sf_param *)maat_plugin_table_get_ex_data(enforcer->maat, enforcer->sf_table_id, profile_id, strlen(profile_id)); + profile_id = sff_param->sf_profile_ids[i]; + struct sf_param *sf = (struct sf_param *)maat_plugin_table_get_ex_data(enforcer->maat, enforcer->sf_table_id, (const char *)&profile_id, sizeof(profile_id)); if (sf == NULL) { - LOG_ERROR("%s: failed to get sf parameter of profile %d", LOG_TAG_POLICY, sff_param->sf_profile_ids[i]); + LOG_ERROR("%s: failed to get sf parameter of profile %d", LOG_TAG_POLICY, profile_id); continue; } @@ -1674,11 +1673,9 @@ int policy_enforce_chaining_size(struct policy_enforcer *enforcer) void policy_enforce_select_chainings(struct policy_enforcer *enforcer, struct selected_chainings *chainings, struct session_ctx *s_ctx, struct packet *data_pkt, uint64_t rule_id, int dir_is_i2e) { - char buffer[16] = {0}; + int sff_profile_id; struct selected_chaining *chaining = NULL; - - snprintf(buffer, sizeof(buffer), "%lu", rule_id); - struct chaining_param *chaining_param = (struct chaining_param *)maat_plugin_table_get_ex_data(enforcer->maat, enforcer->compile_table_id, buffer, strlen(buffer)); + struct chaining_param *chaining_param = (struct chaining_param *)maat_plugin_table_get_ex_data(enforcer->maat, enforcer->compile_table_id, (const char *)&rule_id, sizeof(rule_id)); if (chaining_param == NULL) { LOG_ERROR("%s: session %lu %s failed to get chaining parameter of policy %lu", LOG_TAG_POLICY, s_ctx->session_id, s_ctx->session_addr, rule_id); @@ -1700,12 +1697,11 @@ void policy_enforce_select_chainings(struct policy_enforcer *enforcer, struct se struct selected_sf *selected_sf = &(chaining->chaining[chaining->chaining_used]); selected_sf_init(selected_sf); - memset(buffer, 0, sizeof(buffer)); - snprintf(buffer, sizeof(buffer), "%u", chaining_param->sff_profile_ids[i]); - struct sff_param *sff_param = (struct sff_param *)maat_plugin_table_get_ex_data(enforcer->maat, enforcer->sff_table_id, buffer, strlen(buffer)); + sff_profile_id = chaining_param->sff_profile_ids[i]; + struct sff_param *sff_param = (struct sff_param *)maat_plugin_table_get_ex_data(enforcer->maat, enforcer->sff_table_id, (const char *)&sff_profile_id, sizeof(sff_profile_id)); if (sff_param == NULL) { - LOG_ERROR("%s: session %lu %s failed to get sff parameter of profile %d, bypass current sff !!!", LOG_TAG_POLICY, chaining->session_id, chaining->session_addr, chaining_param->sff_profile_ids[i]); + LOG_ERROR("%s: session %lu %s failed to get sff parameter of profile %d, bypass current sff !!!", LOG_TAG_POLICY, chaining->session_id, chaining->session_addr, sff_profile_id); continue; } @@ -1715,7 +1711,7 @@ void policy_enforce_select_chainings(struct policy_enforcer *enforcer, struct se selected_sf->traffic_type = chaining_param->traffic_type; // sff info - selected_sf->sff_profile_id = chaining_param->sff_profile_ids[i]; + selected_sf->sff_profile_id = sff_profile_id; selected_sf->sff_forward_type = sff_param->sff_forward_type; // sf_index |
