From 4165224885aebb9f78ac327a241753dcb3dfeba7 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 19 Jan 2021 10:16:06 +0000 Subject: [PATCH] Fix reloading of listeners where multiple listeners have the same port. This is only possible where they have different bind addresses. Closes #2029. Thanks to Simon Aldrich. --- ChangeLog.txt | 2 ++ src/conf.c | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index f818c003ab..02ceae9a1a 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -7,6 +7,8 @@ Broker: - Add notes that libsystemd-dev or similar is needed if building with systemd support. Closes #2019. - Improve logging in obscure cases when a client disconnects. Closes #2017. +- Fix reloading of listeners where multiple listeners have been defined with + the same port but different bind addresses. Closes #2029. Apps: - Allow command line arguments to override config file options in diff --git a/src/conf.c b/src/conf.c index 611a62035b..9c9de4f479 100644 --- a/src/conf.c +++ b/src/conf.c @@ -1417,8 +1417,21 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct { for(i=0; ilistener_count; i++){ if(config->listeners[i].port == tmp_int){ - cur_listener = &config->listeners[i]; - break; + /* Now check we have a matching bind address, if defined */ + if(config->listeners[i].host){ + if(token && !strcmp(config->listeners[i].host, token)){ + /* They both have a bind address, and they match */ + cur_listener = &config->listeners[i]; + break; + } + }else{ + if(token == NULL){ + /* Neither this config nor the new config have a bind address, + * so they match. */ + cur_listener = &config->listeners[i]; + break; + } + } } } }