From d942ed7eec1619bc60d3997fecddb85b2fecaa37 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 9 Sep 2021 12:19:13 +0100 Subject: [PATCH] Fix `max_keepalive` option not being able to be set to 0. --- ChangeLog.txt | 7 +++++++ man/mosquitto.conf.5.xml | 10 +++++++++- mosquitto.conf | 9 +++++++-- src/conf.c | 2 +- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 0380f397..fa0c4742 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,10 @@ +2.0.13 - 2021-xx-xx +=================== + +Broker: +- Fix `max_keepalive` option not being able to be set to 0. + + 2.0.12 - 2021-08-31 =================== diff --git a/man/mosquitto.conf.5.xml b/man/mosquitto.conf.5.xml index 078d8eba..06055a4b 100644 --- a/man/mosquitto.conf.5.xml +++ b/man/mosquitto.conf.5.xml @@ -599,7 +599,15 @@ log_timestamp_format %Y-%m-%dT%H:%M:%S be sent a server keepalive telling them to use max_keepalive. This only applies to MQTT v5 clients. The maximum value allowable, and default value, is - 65535. Do not set below 10 seconds. + 65535. + + + Set to 0 to allow clients to set keepalive = 0, which + means no keepalive checks are made and the client will + never be disconnected by the broker if no messages are + received. You should be very sure this is the behaviour + that you want. + For MQTT v3.1.1 and v3.1 clients, there is no mechanism diff --git a/mosquitto.conf b/mosquitto.conf index ee107308..c46802e0 100644 --- a/mosquitto.conf +++ b/mosquitto.conf @@ -79,8 +79,13 @@ # use the new keepalive value. The max_keepalive option allows you to specify # that clients may only connect with keepalive less than or equal to this # value, otherwise they will be sent a server keepalive telling them to use -# max_keepalive. This only applies to MQTT v5 clients. The maximum value -# allowable is 65535. Do not set below 10. +# max_keepalive. This only applies to MQTT v5 clients. The default, and maximum +# value allowable, is 65535. +# +# Set to 0 to allow clients to set keepalive = 0, which means no keepalive +# checks are made and the client will never be disconnected by the broker if no +# messages are received. You should be very sure this is the behaviour that you +# want. # # For MQTT v3.1.1 and v3.1 clients, there is no mechanism to tell the client # what keepalive value they should use. If an MQTT v3.1.1 or v3.1 client diff --git a/src/conf.c b/src/conf.c index 73a0700b..559eb553 100644 --- a/src/conf.c +++ b/src/conf.c @@ -1671,7 +1671,7 @@ static int config__read_file_core(struct mosquitto__config *config, bool reload, config->max_inflight_messages = (uint16_t)tmp_int; }else if(!strcmp(token, "max_keepalive")){ if(conf__parse_int(&token, "max_keepalive", &tmp_int, saveptr)) return MOSQ_ERR_INVAL; - if(tmp_int < 10 || tmp_int > UINT16_MAX){ + if(tmp_int < 0 || tmp_int > UINT16_MAX){ log__printf(NULL, MOSQ_LOG_ERR, "Error: Invalid max_keepalive value (%d).", tmp_int); return MOSQ_ERR_INVAL; }