From d77d36f42151dfb6c6c1aca842e09ad897acc4a3 Mon Sep 17 00:00:00 2001 From: Liong Sauw Ming Date: Thu, 27 Oct 2016 05:47:06 +0000 Subject: Fixed #1974: Various fixes for DNS IPv6 git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5471 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib-util/src/pjlib-util/resolver.c | 11 +++++------ pjlib-util/src/pjlib-util/srv_resolver.c | 17 +++++++++++++++-- pjsip/src/pjsip/sip_resolve.c | 14 +++++++------- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/pjlib-util/src/pjlib-util/resolver.c b/pjlib-util/src/pjlib-util/resolver.c index 0a9819f1..debf8cd2 100644 --- a/pjlib-util/src/pjlib-util/resolver.c +++ b/pjlib-util/src/pjlib-util/resolver.c @@ -856,7 +856,7 @@ PJ_DEF(pj_status_t) pj_dns_resolver_start_query( pj_dns_resolver *resolver, pj_time_val now; struct res_key key; struct cached_res *cache; - pj_dns_async_query *q; + pj_dns_async_query *q, *p_q = NULL; pj_uint32_t hval; pj_status_t status = PJ_SUCCESS; @@ -870,9 +870,6 @@ PJ_DEF(pj_status_t) pj_dns_resolver_start_query( pj_dns_resolver *resolver, /* Check type */ PJ_ASSERT_RETURN(type > 0 && type < 0xFFFF, PJ_EINVAL); - if (p_query) - *p_query = NULL; - /* Build resource key for looking up hash tables */ init_res_key(&key, type, name); @@ -991,10 +988,12 @@ PJ_DEF(pj_status_t) pj_dns_resolver_start_query( pj_dns_resolver *resolver, pj_hash_set_np(resolver->hquerybyres, &q->key, sizeof(q->key), 0, q->hbufkey, q); - if (p_query) - *p_query = q; + p_q = q; on_return: + if (p_query) + *p_query = p_q; + pj_mutex_unlock(resolver->mutex); return status; } diff --git a/pjlib-util/src/pjlib-util/srv_resolver.c b/pjlib-util/src/pjlib-util/srv_resolver.c index 339e5de6..8a4a599e 100644 --- a/pjlib-util/src/pjlib-util/srv_resolver.c +++ b/pjlib-util/src/pjlib-util/srv_resolver.c @@ -187,9 +187,12 @@ PJ_DEF(pj_status_t) pj_dns_srv_cancel_query(pj_dns_srv_async_query *query, has_pending = PJ_TRUE; } if (srv->q_aaaa) { - pj_dns_resolver_cancel_query(srv->q_aaaa, PJ_FALSE); + /* Check if it is a dummy query. */ + if (srv->q_aaaa != (pj_dns_async_query*)0x1) { + pj_dns_resolver_cancel_query(srv->q_aaaa, PJ_FALSE); + has_pending = PJ_TRUE; + } srv->q_aaaa = NULL; - has_pending = PJ_TRUE; } } @@ -485,12 +488,22 @@ static pj_status_t resolve_hostnames(pj_dns_srv_async_query *query_job) srv->common.type = PJ_DNS_TYPE_A; srv->common_aaaa.type = PJ_DNS_TYPE_AAAA; srv->parent = query_job; + srv->q_a = NULL; + srv->q_aaaa = NULL; status = PJ_SUCCESS; /* Start DNA A record query */ if ((query_job->option & PJ_DNS_SRV_RESOLVE_AAAA_ONLY) == 0) { + if ((query_job->option & PJ_DNS_SRV_RESOLVE_AAAA) != 0) { + /* If there will be DNS AAAA query too, let's setup + * a dummy one here, otherwise app callback may be called + * immediately (before DNS AAAA query is sent) when + * DNS A record is available in the cache. + */ + srv->q_aaaa = (pj_dns_async_query*)0x1; + } status = pj_dns_resolver_start_query(query_job->resolver, &srv->target_name, PJ_DNS_TYPE_A, 0, diff --git a/pjsip/src/pjsip/sip_resolve.c b/pjsip/src/pjsip/sip_resolve.c index e41e6e13..5053defc 100644 --- a/pjsip/src/pjsip/sip_resolve.c +++ b/pjsip/src/pjsip/sip_resolve.c @@ -453,7 +453,7 @@ PJ_DEF(void) pjsip_resolve( pjsip_resolver_t *resolver, } /* Resolve DNS AAAA record if address family is not fixed to IPv4 */ - if (af != pj_AF_INET()) { + if (af != pj_AF_INET() && status == PJ_SUCCESS) { status = pj_dns_resolver_start_query(resolver->res, &query->naptr[0].name, PJ_DNS_TYPE_AAAA, 0, @@ -531,9 +531,9 @@ static void dns_a_callback(void *user_data, ++srv->count; } - - } else { - + } + + if (status != PJ_SUCCESS) { char errmsg[PJ_ERR_MSG_SIZE]; /* Log error */ @@ -594,9 +594,9 @@ static void dns_aaaa_callback(void *user_data, ++srv->count; } - - } else { - + } + + if (status != PJ_SUCCESS) { char errmsg[PJ_ERR_MSG_SIZE]; /* Log error */ -- cgit v1.2.3