When using ADNS, don't ask for all network protocols when connecting.

This can lead to confusing "Protocol not supported" errors if the
network is down, because UDP sockets are provided.

Thanks to jsaak.

Closes #1062.

Bug: https://github.com/eclipse/mosquitto/issues/1062
This commit is contained in:
Roger A. Light 2018-12-04 12:39:00 +00:00
parent d29dac087d
commit e169f1c7c2
3 changed files with 31 additions and 2 deletions

View File

@ -6,6 +6,9 @@ Broker:
This is required to work around a problem in libwebsockets that means This is required to work around a problem in libwebsockets that means
sockets only listen on IPv6 by default if IPv6 support is compiled in. sockets only listen on IPv6 by default if IPv6 support is compiled in.
Closes #1004. Closes #1004.
- When using ADNS, don't ask for all network protocols when connecting,
because this can lead to confusing "Protocol not supported" errors if the
network is down. Closes #1062.
Client: Client:
- Always print leading zeros in mosquitto_sub when output format is hex. - Always print leading zeros in mosquitto_sub when output format is hex.

View File

@ -208,21 +208,39 @@ int net__try_connect_step1(struct mosquitto *mosq, const char *host)
{ {
int s; int s;
void *sevp = NULL; void *sevp = NULL;
struct addrinfo *hints;
if(mosq->adns){ if(mosq->adns){
gai_cancel(mosq->adns);
mosquitto__free((struct addrinfo *)mosq->adns->ar_request);
mosquitto__free(mosq->adns); mosquitto__free(mosq->adns);
} }
mosq->adns = mosquitto__calloc(1, sizeof(struct gaicb)); mosq->adns = mosquitto__calloc(1, sizeof(struct gaicb));
if(!mosq->adns){ if(!mosq->adns){
return MOSQ_ERR_NOMEM; return MOSQ_ERR_NOMEM;
} }
hints = mosquitto__calloc(1, sizeof(struct addrinfo));
if(!hints){
mosquitto__free(mosq->adns);
mosq->adns = NULL;
return MOSQ_ERR_NOMEM;
}
hints->ai_family = AF_UNSPEC;
hints->ai_socktype = SOCK_STREAM;
mosq->adns->ar_name = host; mosq->adns->ar_name = host;
mosq->adns->ar_request = hints;
s = getaddrinfo_a(GAI_NOWAIT, &mosq->adns, 1, sevp); s = getaddrinfo_a(GAI_NOWAIT, &mosq->adns, 1, sevp);
if(s){ if(s){
errno = s; errno = s;
if(mosq->adns){
mosquitto__free((struct addrinfo *)mosq->adns->ar_request);
mosquitto__free(mosq->adns); mosquitto__free(mosq->adns);
mosq->adns = NULL; mosq->adns = NULL;
}
return MOSQ_ERR_EAI; return MOSQ_ERR_EAI;
} }
@ -278,6 +296,7 @@ int net__try_connect_step2(struct mosquitto *mosq, uint16_t port, mosq_sock_t *s
freeaddrinfo(mosq->adns->ar_result); freeaddrinfo(mosq->adns->ar_result);
mosq->adns->ar_result = NULL; mosq->adns->ar_result = NULL;
mosquitto__free((struct addrinfo *)mosq->adns->ar_request);
mosquitto__free(mosq->adns); mosquitto__free(mosq->adns);
mosq->adns = NULL; mosq->adns = NULL;

View File

@ -197,6 +197,13 @@ void context__cleanup(struct mosquitto_db *db, struct mosquitto *context, bool d
context->queued_msgs = NULL; context->queued_msgs = NULL;
context->last_queued_msg = NULL; context->last_queued_msg = NULL;
} }
#if defined(WITH_BROKER) && defined(__GLIBC__) && defined(WITH_ADNS)
if(context->adns){
gai_cancel(context->adns);
mosquitto__free((struct addrinfo *)context->adns->ar_request);
mosquitto__free(context->adns);
}
#endif
if(do_free){ if(do_free){
mosquitto__free(context); mosquitto__free(context);
} }