-
Notifications
You must be signed in to change notification settings - Fork 34
Add bridge exclusion #1479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add bridge exclusion #1479
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3580,6 +3580,19 @@ conf_bridge_node_destroy(conf_bridge_node *node) | |
| cvector_free(node->forwards_list); | ||
| node->forwards_list = NULL; | ||
| } | ||
| if (node->exclusions_count > 0 && node->exclusions_list) { | ||
| for (size_t j = 0; j < node->exclusions_count; j++) { | ||
| exclusions *e = node->exclusions_list[j]; | ||
| if (e->topic) { | ||
| free(e->topic); | ||
| e->topic = NULL; | ||
| } | ||
| NNI_FREE_STRUCT(e); | ||
| } | ||
| node->exclusions_count = 0; | ||
| cvector_free(node->exclusions_list); | ||
| node->exclusions_list = NULL; | ||
| } | ||
| if (node->sub_count > 0 && node->sub_list) { | ||
| for (size_t i = 0; i < node->sub_count; i++) { | ||
| topics *s = node->sub_list[i]; | ||
|
|
@@ -3702,7 +3715,7 @@ print_bridge_conf(conf_bridge *bridge, const char *prefix) | |
| node->name, node->resend_wait); | ||
| log_info("%sbridge.mqtt.%s.cancel_timeout: %ld", prefix, | ||
| node->name, node->cancel_timeout); | ||
| log_info("%sbridge.mqtt.%s.hybrid_bridging : %s", prefix, | ||
| log_info("%sbridge.mqtt.%s.hybrid_bridging: %s", prefix, | ||
| node->name, node->hybrid ? "true" : "false"); | ||
| log_info("%sbridge.mqtt.%s.hybrid_servers: ", prefix, node->name); | ||
| for (size_t j = 0; j < cvector_size(node->hybrid_servers); j++) { | ||
|
|
@@ -3746,14 +3759,21 @@ print_bridge_conf(conf_bridge *bridge, const char *prefix) | |
|
|
||
| for (size_t j = 0; j < node->forwards_count; j++) { | ||
| log_info( | ||
| "\t[%ld] remote topic: %.*s", j, | ||
| "\t[%ld] remote topic:\t\t%.*s", j, | ||
| node->forwards_list[j]->remote_topic_len, | ||
| node->forwards_list[j]->remote_topic); | ||
| log_info( | ||
| "\t[%ld] local topic: %.*s", j, | ||
| "\t[%ld] local topic:\t\t%.*s", j, | ||
| node->forwards_list[j]->local_topic_len, | ||
| node->forwards_list[j]->local_topic); | ||
| } | ||
| log_info("%sbridge.mqtt.%s.exclusions: ", prefix, node->name); | ||
| for (size_t j = 0; j < node->exclusions_count; j++) { | ||
| log_info( | ||
| "\t[%ld] topic:\t\t%.*s", j, | ||
| node->exclusions_list[j]->topic_len, | ||
| node->exclusions_list[j]->topic); | ||
| } | ||
|
Comment on lines
+3770
to
+3776
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential format string issue: The 🛡️ Proposed fix to cast the precision argument log_info("%sbridge.mqtt.%s.exclusions: ", prefix, node->name);
for (size_t j = 0; j < node->exclusions_count; j++) {
log_info(
- "\t[%ld] topic:\t\t%.*s", j,
- node->exclusions_list[j]->topic_len,
+ "\t[%zu] topic:\t\t%.*s", j,
+ (int)node->exclusions_list[j]->topic_len,
node->exclusions_list[j]->topic);
}🤖 Prompt for AI Agents |
||
| log_info( | ||
| "%sbridge.mqtt.%s.subscription: ", prefix, node->name); | ||
| for (size_t k = 0; k < node->sub_count; k++) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1264,6 +1264,23 @@ conf_bridge_node_parse( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| node->forwards_count = cvector_size(node->forwards_list); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cJSON *exclusions_list = hocon_get_obj("exclusions", obj); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cJSON *exclusion = NULL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cJSON_ArrayForEach(exclusion, exclusions_list) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exclusions *exc = NNI_ALLOC_STRUCT(exc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hocon_read_str(exc, topic, exclusion); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| size_t topic_len = exc->topic ? strlen(exc->topic) : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (topic_len == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log_error("Exclusion topic should not be null or empty"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| NNI_FREE_STRUCT(exc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exc->topic_len = topic_len; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cvector_push_back(node->exclusions_list, exc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| node->exclusions_count = cvector_size(node->exclusions_list); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1267
to
+1282
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using When an exclusion has an empty or null topic, the code breaks out of the loop entirely, discarding any subsequent valid exclusions. Consider using Additionally, unlike the similar forwards/subscription parsing, there's no maximum topic length validation here. Extremely long topic strings could cause issues. 🐛 Proposed fix cJSON *exclusions_list = hocon_get_obj("exclusions", obj);
cJSON *exclusion = NULL;
cJSON_ArrayForEach(exclusion, exclusions_list)
{
exclusions *exc = NNI_ALLOC_STRUCT(exc);
hocon_read_str(exc, topic, exclusion);
size_t topic_len = exc->topic ? strlen(exc->topic) : 0;
- if (topic_len == 0) {
- log_error("Exclusion topic should not be null or empty");
- NNI_FREE_STRUCT(exc);
+ if (topic_len == 0 || topic_len > UINT16_MAX) {
+ log_warn("Invalid exclusion topic length: %zu, skipping", topic_len);
+ if (exc->topic) {
+ nng_strfree(exc->topic);
+ }
+ NNI_FREE_STRUCT(exc);
- break;
+ continue;
}
exc->topic_len = topic_len;
cvector_push_back(node->exclusions_list, exc);
}
node->exclusions_count = cvector_size(node->exclusions_list);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cJSON *subscriptions = hocon_get_obj("subscription", obj); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cJSON *subscription = NULL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1919,7 +1936,6 @@ conf_authorization_prase_ver2(conf *config, cJSON *jso) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| conf_auth_http_parse_ver2(config, jso_auth_http); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cJSON *jso_auth_pwd = hocon_get_obj("auth.password", jso); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (jso_auth_pwd) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| conf_auth_parse_ver2(config, jso_auth_pwd); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: nanomq/NanoNNG
Length of output: 72
🏁 Script executed:
Repository: nanomq/NanoNNG
Length of output: 3934
🏁 Script executed:
Repository: nanomq/NanoNNG
Length of output: 654
🏁 Script executed:
Repository: nanomq/NanoNNG
Length of output: 50371
🏁 Script executed:
Repository: nanomq/NanoNNG
Length of output: 462
🏁 Script executed:
Repository: nanomq/NanoNNG
Length of output: 1099
🏁 Script executed:
Repository: nanomq/NanoNNG
Length of output: 278
🏁 Script executed:
Repository: nanomq/NanoNNG
Length of output: 40
🏁 Script executed:
Repository: nanomq/NanoNNG
Length of output: 166
🏁 Script executed:
Repository: nanomq/NanoNNG
Length of output: 6778
Exclusions are parsed but never enforced at runtime.
The
exclusions_listis populated during configuration parsing and freed during destruction, but there's no code that actually uses these exclusions to filter messages during bridge forwarding. This means the feature is incomplete—users can configure exclusions, but they won't have any effect.🤖 Prompt for AI Agents