diff options
| author | 刘畅 <[email protected]> | 2023-07-05 01:54:46 +0000 |
|---|---|---|
| committer | 刘畅 <[email protected]> | 2023-07-05 01:54:46 +0000 |
| commit | d81e4555cc5acaaf76b5df01494ec8504063584e (patch) | |
| tree | 190e9e1434ed017fb57223c62d15b9f8e5c833d4 | |
| parent | e11ba15dbb2309aa7e3f3ea6659056befbca174e (diff) | |
| parent | 99d4d6cf8850c3b0a5a02316e363fe462633bd3d (diff) | |
Merge branch 'stop_shape_while_rule_disabled' into 'rel'v1.2.7
Stop shape while rule disabled
See merge request tango/shaping-engine!35
| -rw-r--r-- | shaping/include/shaper.h | 7 | ||||
| -rw-r--r-- | shaping/include/shaper_maat.h | 1 | ||||
| -rw-r--r-- | shaping/src/shaper.cpp | 27 | ||||
| -rw-r--r-- | shaping/src/shaper_maat.cpp | 14 | ||||
| -rw-r--r-- | shaping/src/shaper_session.cpp | 2 |
5 files changed, 42 insertions, 9 deletions
diff --git a/shaping/include/shaper.h b/shaping/include/shaper.h index cc7c608..2be4d65 100644 --- a/shaping/include/shaper.h +++ b/shaping/include/shaper.h @@ -32,6 +32,7 @@ struct shaping_system_conf { int cpu_affinity_enable; int firewall_sid; unsigned long long cpu_affinity_mask; + int check_rule_enable_interval_sec; }; struct shaping_thread_ctx { @@ -46,9 +47,7 @@ struct shaping_thread_ctx { struct shaping_maat_info *maat_info; struct session_table *session_table; int session_need_reset; - unsigned int session_queue_len_max; - int polling_node_num_max[SHAPING_PRIORITY_NUM_MAX]; - int firewall_sid; + struct shaping_system_conf conf; }; struct shaping_ctx { @@ -100,6 +99,7 @@ struct shaping_rule_info { struct shaping_profile_info primary; struct shaping_profile_info borrowing[SHAPING_REF_PROFILE_NUM_MAX]; int borrowing_num; + int is_enabled; }; struct shaping_packet_wrapper { @@ -141,6 +141,7 @@ struct shaping_flow { struct metadata ctrl_meta; unsigned long long processed_pkts; struct timespec stat_update_time; + time_t check_rule_time; }; struct shaper_flow_instance { diff --git a/shaping/include/shaper_maat.h b/shaping/include/shaper_maat.h index df3558f..51db653 100644 --- a/shaping/include/shaper_maat.h +++ b/shaping/include/shaper_maat.h @@ -32,6 +32,7 @@ void shaper_profile_ex_new(const char *table_name, int table_id, const char *key void shaper_profile_ex_dup(int table_id, void **to, void **from, long argl, void *argp); void shaper_profile_ex_free(int table_id, void **ad, long argl, void *argp); +int shaper_rule_is_enabled(struct shaping_thread_ctx *ctx, long long rule_id); void shaper_rules_update(struct shaping_thread_ctx *ctx, struct shaping_flow *sf, long long *rule_compile_ids, int rule_num); struct shaping_maat_info* shaper_maat_init(const char *instance_name); diff --git a/shaping/src/shaper.cpp b/shaping/src/shaper.cpp index ca2893b..ddb23c5 100644 --- a/shaping/src/shaper.cpp +++ b/shaping/src/shaper.cpp @@ -176,7 +176,7 @@ static int shaper_packet_enqueue(struct shaping_thread_ctx *ctx, struct shaping_ struct shaping_packet_wrapper *s_pkt = NULL; struct timespec curr_time; - if (sf->queue_len == ctx->session_queue_len_max) { + if (sf->queue_len == ctx->conf.session_queue_len_max) { return -1; } @@ -588,6 +588,23 @@ static int shaper_profile_is_priority_blocked(struct shaping_thread_ctx *ctx, st static int shaper_token_consume(struct shaping_thread_ctx *ctx, struct shaping_flow *sf, int req_token_bytes, struct shaping_profile_info *profile, int profile_type, unsigned char direction) { + struct shaping_rule_info *rule = &sf->matched_rule_infos[sf->anchor]; + time_t curr_time = time(NULL); + + if (curr_time - sf->check_rule_time >= ctx->conf.check_rule_enable_interval_sec) { + sf->check_rule_time = curr_time; + if (shaper_rule_is_enabled(ctx, rule->id) != 1) { + rule->is_enabled = 0; + return 0;//rule is disabled, don't need to get token and forward packet + } else { + rule->is_enabled = 1; + } + } + + if (rule->is_enabled != 1) { + return 0; + } + if (shaper_profile_is_priority_blocked(ctx, sf, profile)) { return -1; } else { @@ -910,7 +927,7 @@ void polling_entry(struct shaper *sp, struct shaping_stat *stat, struct shaping_ int ret; for (int i = 0; i < SHAPING_PRIORITY_NUM_MAX; i++) { - sf_num = shaper_flow_in_order_get(sp, sf_ins, i, ctx->polling_node_num_max[i]); + sf_num = shaper_flow_in_order_get(sp, sf_ins, i, ctx->conf.polling_node_num_max[i]); if (sf_num == 0) { continue; } @@ -1124,6 +1141,8 @@ int shaper_global_conf_init(struct shaping_system_conf *conf) MESA_load_profile_uint_def(SHAPING_GLOBAL_CONF_FILE, "CONFIG", "SESSION_QUEUE_LEN_MAX", &conf->session_queue_len_max, 128); MESA_load_profile_uint_def(SHAPING_GLOBAL_CONF_FILE, "CONFIG", "PRIORITY_QUEUE_LEN_MAX", &conf->priority_queue_len_max, 1024); + MESA_load_profile_int_def(SHAPING_GLOBAL_CONF_FILE, "CONFIG", "CHECK_RULE_ENABLE_INTERVAL_SEC", &conf->check_rule_enable_interval_sec, 120); + return 0; ERROR: @@ -1213,9 +1232,7 @@ struct shaping_ctx *shaping_engine_init() ctx->thread_ctx[i].marsio_info = ctx->marsio_info; ctx->thread_ctx[i].swarmkv_db = ctx->swarmkv_db; ctx->thread_ctx[i].ref_ctx = ctx; - ctx->thread_ctx[i].session_queue_len_max = conf.session_queue_len_max; - memcpy(ctx->thread_ctx[i].polling_node_num_max, conf.polling_node_num_max, sizeof(conf.polling_node_num_max)); - ctx->thread_ctx[i].firewall_sid = conf.firewall_sid; + memcpy(&ctx->thread_ctx[i].conf, &conf, sizeof(conf)); } return ctx; diff --git a/shaping/src/shaper_maat.cpp b/shaping/src/shaper_maat.cpp index e11538f..4b4f21f 100644 --- a/shaping/src/shaper_maat.cpp +++ b/shaping/src/shaper_maat.cpp @@ -296,6 +296,8 @@ static void shaper_rule_update(struct shaping_thread_ctx *ctx, struct shaping_fl s_rule_info->fair_factor = s_rule->fair_factor; s_rule_info->vsys_id = s_rule->vsys_id; + s_rule_info->is_enabled = 1; + snprintf(pf_id_key, sizeof(pf_id_key), "%d", s_rule->primary_pf_id); s_pf = (struct shaping_profile *)maat_plugin_table_get_ex_data(g_maat_instance, ctx->maat_info->profile_table_id, pf_id_key, strlen(pf_id_key)); if (!s_pf) { @@ -348,6 +350,18 @@ static void shaper_profiles_priority_update(struct shaping_flow *sf) return; } +int shaper_rule_is_enabled(struct shaping_thread_ctx *ctx, long long rule_id) +{ + struct shaping_rule *s_rule = (struct shaping_rule*)maat_plugin_table_get_ex_data(g_maat_instance, ctx->maat_info->rule_table_id, (char *)&rule_id, sizeof(rule_id)); + + if (s_rule) { + shaper_rule_ex_free(ctx->maat_info->rule_table_id, (void **)&s_rule, 0, NULL); + return 1; + } + + return 0; +} + void shaper_rules_update(struct shaping_thread_ctx *ctx, struct shaping_flow *sf, long long *rule_compile_ids, int rule_num) { int i, j; diff --git a/shaping/src/shaper_session.cpp b/shaping/src/shaper_session.cpp index 946a56f..f43f76f 100644 --- a/shaping/src/shaper_session.cpp +++ b/shaping/src/shaper_session.cpp @@ -140,7 +140,7 @@ static void shaper_session_log_send(struct shaping_thread_ctx *ctx, struct shapi goto END; } - sids.elems[0] = ctx->firewall_sid; + sids.elems[0] = ctx->conf.firewall_sid; sids.num = 1; if (marsio_buff_set_sid_list(tx_buff, sids.elems, sids.num) != 0) { LOG_ERROR("%s: marsio_buff_set_sid_list failed for session %s", LOG_TAG_SHAPING, addr_str); |
