Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DNS SRV record retrieval without explicit host #366

Open
stefanoco opened this issue Feb 1, 2017 · 2 comments
Open

DNS SRV record retrieval without explicit host #366

stefanoco opened this issue Feb 1, 2017 · 2 comments
Labels
Component: libmosquitto Type: Enhancement A new feature for a minor or major release.

Comments

@stefanoco
Copy link

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?

@ralight ralight added Type: Enhancement A new feature for a minor or major release. Component: libmosquitto labels Feb 1, 2017
@ralight
Copy link
Contributor

ralight commented Feb 1, 2017

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!

@stefanoco
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: libmosquitto Type: Enhancement A new feature for a minor or major release.
Projects
None yet
Development

No branches or pull requests

2 participants