Skip to content

Commit

Permalink
add option to control whether sub errors are fatal for bridge connect…
Browse files Browse the repository at this point in the history
…ions

Signed-off-by: Abilio Marques <[email protected]>
  • Loading branch information
abiliojr committed Oct 26, 2023
1 parent 355fc4c commit 1bf9acc
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ Broker:
choose TLS v1.1, but this is not recommended and will be removed in a future
version.
- Add -q option to allow logging to be disabled at the command line.
- Add `bridge_outgoing_retain` option to control what happens when a bridge
fails to subscribe to a topic.

Plugins / plugin interface:
- Add persist-sqlite plugin.
Expand Down
1 change: 1 addition & 0 deletions fuzzing/corpora/broker_conf.dict
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"bridge_max_packet_size"
"bridge_max_topic_alias"
"bridge_outgoing_retain"
"bridge_fatal_sub_errors"
"bridge_protocol_version"
"bridge_psk"
"bridge_receive_maximum"
Expand Down
11 changes: 10 additions & 1 deletion man/mosquitto.conf.5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1899,7 +1899,16 @@ openssl dhparam -out dhparam.pem 2048</programlisting>
other setting. Defaults to <replaceable>true</replaceable>.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>bridge_fatal_sub_errors</option> [ true | false ]</term>
<listitem>
<para> A failure to subscribe to a topic will cause an immediate
disconnection. The hope is that a temporary failure will disappear
after reconnecting. If you desire to silently ignore subscription
errors (not advised), you can set the bridge_fatal_sub_errors
option to false. Defaults to <replaceable>true</replaceable>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>bridge_protocol_version</option> <replaceable>version</replaceable></term>
<listitem>
Expand Down
6 changes: 6 additions & 0 deletions mosquitto.conf
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,12 @@
# all outgoing messages to that bridge, regardless of any other setting.
#bridge_outgoing_retain true

# A failure to subscribe to a topic will cause an immediate disconnection. The
# hope is that a temporary failure will disappear after reconnecting. If you
# desire to silently ignore subscription errors (not advised), you can set the
# bridge_fatal_sub_errors option to false.
#bridge_fatal_sub_errors true

# If you wish to restrict the size of messages sent to a remote bridge, use the
# bridge_max_packet_size option. This sets the maximum number of bytes for
# the total message, including headers and payload.
Expand Down
2 changes: 1 addition & 1 deletion src/bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ int bridge__on_connect(struct mosquitto *context)
}

int bridge__on_suback(struct mosquitto *context, int qos) {
if (qos > 2) {
if (qos > 2 && context->bridge->fatal_sub_errors) {
log__printf(NULL, MOSQ_LOG_ERR, "Error on bridge subscription: %s", mosquitto_reason_string(qos));
do_disconnect(context, MOSQ_ERR_CONN_LOST);
}
Expand Down
8 changes: 8 additions & 0 deletions src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,13 @@ static int config__read_file_core(struct mosquitto__config *config, bool reload,
if(conf__parse_bool(&token, "bridge_outgoing_retain", &cur_bridge->outgoing_retain, &saveptr)) return MOSQ_ERR_INVAL;
#else
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Bridge support not available.");
#endif
}else if(!strcmp(token, "bridge_fatal_sub_errors")){
#if defined(WITH_BRIDGE)
REQUIRE_BRIDGE(token);
if(conf__parse_bool(&token, "bridge_fatal_sub_errors", &cur_bridge->fatal_sub_errors, &saveptr)) return MOSQ_ERR_INVAL;
#else
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Bridge support not available.");
#endif
}else if(!strcmp(token, "bridge_keyfile")){
#if defined(WITH_BRIDGE) && defined(WITH_TLS)
Expand Down Expand Up @@ -1585,6 +1592,7 @@ static int config__read_file_core(struct mosquitto__config *config, bool reload,
cur_bridge->protocol_version = mosq_p_mqtt311;
cur_bridge->primary_retry_sock = INVALID_SOCKET;
cur_bridge->outgoing_retain = true;
cur_bridge->fatal_sub_errors = true;
cur_bridge->clean_start_local = -1;
cur_bridge->reload_type = brt_lazy;
cur_bridge->max_topic_alias = 10;
Expand Down
1 change: 1 addition & 0 deletions src/mosquitto_broker_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ struct mosquitto__bridge{
bool attempt_unsubscribe;
bool initial_notification_done;
bool outgoing_retain;
bool fatal_sub_errors;
enum mosquitto_bridge_reload_type reload_type;
uint16_t max_topic_alias;
#ifdef WITH_TLS
Expand Down

0 comments on commit 1bf9acc

Please sign in to comment.