diff options
| author | songyanchao <[email protected]> | 2024-01-18 08:46:13 +0000 |
|---|---|---|
| committer | songyanchao <[email protected]> | 2024-01-18 09:07:33 +0000 |
| commit | cd77b85573e3e0a6a135310830eaecec7b921af2 (patch) | |
| tree | 98a0ebc1a89fdffc38a334a442d9c4fbd5b0ef70 | |
| parent | e0433fc974a91a2ec7a6939325a47a74b01f450e (diff) | |
🎈 perf(DPISDN-32): Add rules changed check to Classifier dynamic rules loading process.
Add rules changed check to Classifier dynamic rules loading process.
| -rw-r--r-- | infra/include/common.h | 4 | ||||
| -rw-r--r-- | service/src/node_classifier.c | 51 |
2 files changed, 51 insertions, 4 deletions
diff --git a/infra/include/common.h b/infra/include/common.h index 7cf8e62..9916cf8 100644 --- a/infra/include/common.h +++ b/infra/include/common.h @@ -126,8 +126,8 @@ extern unsigned int g_eal_started; { \ if (g_logger_to_stdout && LEVEL <= g_logger_level) \ { \ - fprintf(stdout, __VA_ARGS__); \ - fprintf(stdout, "\n"); \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr, "\n"); \ } \ } while (0) diff --git a/service/src/node_classifier.c b/service/src/node_classifier.c index f64c072..ee21765 100644 --- a/service/src/node_classifier.c +++ b/service/src/node_classifier.c @@ -32,6 +32,7 @@ struct node_classifier_main unsigned int ignore_all_icmp_pkts; unsigned int ignore_all_icmp6_pkts; struct pkt_classifier_engine * pkt_classifier_engine; + struct rule_list_parsed rule_list_parsed; }; static struct node_classifier_main classifier_main = {0}; @@ -42,6 +43,42 @@ static inline struct node_classifier_main * node_classifier_main_get(void) return &classifier_main; } +static inline int classifier_rules_changed(struct rule_list_parsed * old_rules, struct rule_list_parsed * new_rules) +{ + if (old_rules->nr_rules != new_rules->nr_rules) + { + return RT_SUCCESS; + } + + for (uint32_t index = 0; index < old_rules->nr_rules; index++) + { + int is_found = 0; + struct rule_field_parser * new_rule = &new_rules->rules[index]; + + for (uint32_t old_index = 0; old_index < old_rules->nr_rules; old_index++) + { + struct rule_field_parser * old_rule = &old_rules->rules[old_index]; + if (new_rule->rule_id == old_rule->rule_id) + { + if (memcmp(new_rule, old_rule, sizeof(struct rule_field_parser)) != 0) + { + return RT_SUCCESS; + } + + is_found = 1; + break; + } + } + + if (!is_found) + { + return RT_SUCCESS; + } + } + + return RT_ERR; +} + /* Each ruleset type should implement its own 'rules verify' function to validate its unique match fields. */ static inline int classifier_rules_verify(const struct rule_list_parsed rule_list[]) { @@ -176,6 +213,14 @@ int classifier_rule_update(struct sc_main * sc) return RT_ERR; } + ret = classifier_rules_changed(&classifier_main->rule_list_parsed, &rule_list_parsed); + + if (ret != RT_SUCCESS) + { + MR_INFO("The classifier rules are not changed.\n"); + return RT_SUCCESS; + } + /* Verify the classifier rule. */ ret = classifier_rules_verify(&rule_list_parsed); if (ret != RT_SUCCESS) @@ -197,7 +242,8 @@ int classifier_rule_update(struct sc_main * sc) } /* Display information about the packet classifier rules. */ - classifier_rule_dump(&rule_list_parsed); + memcpy(&classifier_main->rule_list_parsed, &rule_list_parsed, sizeof(struct rule_list_parsed)); + classifier_rule_dump(&classifier_main->rule_list_parsed); pkt_classifier_engine_info_dump(pkt_classifier_engine); return RT_SUCCESS; @@ -270,7 +316,8 @@ int classifier_init(struct sc_main * sc) } /* Display information about the packet classifier rules. */ - classifier_rule_dump(&rule_list_parsed); + memcpy(&classifier_main->rule_list_parsed, &rule_list_parsed, sizeof(struct rule_list_parsed)); + classifier_rule_dump(&classifier_main->rule_list_parsed); pkt_classifier_engine_info_dump(pkt_classifier_engine); return RT_SUCCESS; } |
