summaryrefslogtreecommitdiff
path: root/third-party/pjproject/patches/0006-r5471-svn-backport-Various-fixes-for-DNS-IPv6.patch
blob: 98c33e51105042cdd7127fc325283c339b7fe4f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
From 2ab7a9f67caf73be3f2215473f72882cfaef4972 Mon Sep 17 00:00:00 2001
From: Richard Mudgett <rmudgett@digium.com>
Date: Fri, 28 Oct 2016 12:11:30 -0500
Subject: [PATCH 1/3] r5471 svn backport Various fixes for DNS IPv6

Fixed #1974: Various fixes for DNS IPv6
---
 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 e5e1bed..d24ef9d 100644
--- a/pjlib-util/src/pjlib-util/resolver.c
+++ b/pjlib-util/src/pjlib-util/resolver.c
@@ -835,7 +835,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;
 
@@ -849,9 +849,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);
 
@@ -970,10 +967,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 02672aa..ff9c979 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 ed326ba..3f3654d 100644
--- a/pjsip/src/pjsip/sip_resolve.c
+++ b/pjsip/src/pjsip/sip_resolve.c
@@ -452,7 +452,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, 
@@ -530,9 +530,9 @@ static void dns_a_callback(void *user_data,
 
 	    ++srv->count;
 	}
-
-    } else {
-
+    }
+    
+    if (status != PJ_SUCCESS) {
 	char errmsg[PJ_ERR_MSG_SIZE];
 
 	/* Log error */
@@ -593,9 +593,9 @@ static void dns_aaaa_callback(void *user_data,
 
 	    ++srv->count;
 	}
-
-    } else {
-
+    }
+    
+    if (status != PJ_SUCCESS) {
 	char errmsg[PJ_ERR_MSG_SIZE];
 
 	/* Log error */
-- 
1.7.9.5