From 6bb8d9ac16c7d16e3166ea10d77215ac642b741a Mon Sep 17 00:00:00 2001 From: Niklas Ciecior Date: Wed, 1 Apr 2026 10:38:01 +0200 Subject: [PATCH] Add bridge exclusion Signed-off-by: Niklas Ciecior --- include/nng/supplemental/nanolib/conf.h | 7 +++++++ src/supplemental/nanolib/conf.c | 26 ++++++++++++++++++++++--- src/supplemental/nanolib/conf_ver2.c | 18 ++++++++++++++++- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/include/nng/supplemental/nanolib/conf.h b/include/nng/supplemental/nanolib/conf.h index c9cb13d91..e6f7461b4 100644 --- a/include/nng/supplemental/nanolib/conf.h +++ b/include/nng/supplemental/nanolib/conf.h @@ -222,6 +222,11 @@ typedef struct conf_websocket conf_websocket; #define NO_RETAIN 2 // default retain flag value, none 0, 1 #define NO_QOS 3 // default QoS level value for forwarding bridge msg, 3 = keep old qos +typedef struct { + char *topic; + size_t topic_len; +} exclusions; + typedef struct { char *remote_topic; uint32_t remote_topic_len; @@ -309,10 +314,12 @@ struct conf_bridge_node { uint64_t resend_interval; // resend caching message interval (ms) uint64_t resend_wait; size_t sub_count; + size_t exclusions_count; size_t forwards_count; size_t max_recv_queue_len; size_t max_send_queue_len; topics **forwards_list; + exclusions **exclusions_list; uint64_t parallel; topics **sub_list; conf_tls tls; diff --git a/src/supplemental/nanolib/conf.c b/src/supplemental/nanolib/conf.c index ea02903bd..5721d9d00 100644 --- a/src/supplemental/nanolib/conf.c +++ b/src/supplemental/nanolib/conf.c @@ -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); + } log_info( "%sbridge.mqtt.%s.subscription: ", prefix, node->name); for (size_t k = 0; k < node->sub_count; k++) { diff --git a/src/supplemental/nanolib/conf_ver2.c b/src/supplemental/nanolib/conf_ver2.c index 33fb6e8d6..21ffe9faf 100644 --- a/src/supplemental/nanolib/conf_ver2.c +++ b/src/supplemental/nanolib/conf_ver2.c @@ -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); + 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); }