DNS SRV record retrieval without explicit host
I'm starting experiments with the very useful DNS SRV record for broker address discovery/retrieval. My setup is (now) a local dnsmasq server serving SRV records with (partial config):
$ cat /etc/dnsmasq.conf
.
.
.
domain=bwlocal.it
srv-host=_secure-mqtt._tcp,things-xxxx.bluewind.it,8883
srv-host=_mqtt._tcp,things-xxxx.bluewind.it,1883
.
.
.
so sort of a strange test setup only, but should work: my "local" network is composed of hosts named like "anyhost.bwlocal.it" and the DNS should direct MQTT related traffic to some externally hosted broker.
This works as expected with commands like:
$ mosquitto_sub -h bwlocal.it -S -v -t "#"
$ mosquitto_sub -h bwlocal.it -S -v -t "#" --cafile ~/ca.crt
but always fails with:
$ mosquitto_sub -S -v -t "#"
$ mosquitto_sub -S -v -t "#" --cafile ~/ca.crt
and dnsmasq logs reveal that the DNS query is something like:
tail -f /var/log/syslog
dnsmasq[24887]: query[SRV] _secure-mqtt._tcp.localhost.bwlocal.it from 192.168.0.27
dnsmasq[24887]: config _secure-mqtt._tcp.localhost.bwlocal.it is NXDOMAIN
so it seems to me that Mosquitto is trying to guess the domain for building the query and the resulting fqdn is "localhost.bwlocal.it" instead of "bwlocal.it", of course some misconfiguration of our linux hosts can also be a cause but I'm really not finding any possible reason. Hints on where to start searching inside Mosquitto code base?
You'll need to look at two places:
client/client_shared.c
- if(!cfg->host){
+ if(!cfg->host && cfg->use_srv == false){
cfg->host = "localhost";
}
And this then goes on to influence lib/srv_mosq.c:
int mosquitto_connect_srv(struct mosquitto *mosq, const char *host, int keepalive, const char *bind_address)
{
#ifdef WITH_SRV
...
if(!host){
// get local domain
}else{
I'm sure you can see the problem!
Yes I can indeed... so maybe writing // get local domain with something similar to what's currently in use inside client_id_generate() could be worth trying? I will try to apply a patch.