On 2013-09-30 at 09:36, Daniel-Constantin Mierla wrote:
> Hello,
> 
> thanks for digging further, I will check it and commit if all looks good.

Found an unrelated bug while testing more. If using dns_cache and
use_dns_failover=off, it will not resolve A/AAAA-only hosts.

Note that srv-lookups is still broken in the use_dns_failover=on case, as
it only attempts one srv lookup, usually udp.

From the logs of a stock Kamailio lastest 4.0:
DEBUG: <core> [dns_cache.c:569]: _dns_hash_find(): 
dns_hash_find(sip-services.uninett.no(23), 35), h=412
DEBUG: <core> [resolve.c:757]: get_record(): get_record: 
lookup(sip-services.uninett.no, 35) failed
DEBUG: <core> [dns_cache.c:897]: dns_cache_mk_bad_entry(): 
dns_cache_mk_bad_entry(sip-services.uninett.no, 35, 60, 1)
DEBUG: <core> [dns_cache.c:830]: dns_cache_add(): dns_cache_add: adding 
sip-services.uninett.no(23) 35 (flags=1) at 412
DEBUG: <core> [dns_cache.c:569]: _dns_hash_find(): 
dns_hash_find(_sip._udp.sip-services.uninett.no(33), 33), h=64
DEBUG: <core> [resolve.c:757]: get_record(): get_record: 
lookup(_sip._udp.sip-services.uninett.no, 33) failed
DEBUG: <core> [dns_cache.c:897]: dns_cache_mk_bad_entry(): 
dns_cache_mk_bad_entry(_sip._udp.sip-services.uninett.no, 33, 60, 1)
DEBUG: <core> [dns_cache.c:830]: dns_cache_add(): dns_cache_add: adding 
_sip._udp.sip-services.uninett.no(33) 33 (flags=1) at 64
ERROR: <core> [resolve.c:1728]: sip_hostport2su(): ERROR: sip_hostport2su: 
could not resolve hostname: "sip-services.uninett.no"
ERROR: tm [ut.h:337]: uri2dst2(): failed to resolve "sip-services.uninett.no"
ERROR: tm [t_fwd.c:1534]: t_forward_nonack(): ERROR: t_forward_nonack: failure 
to add branches
DEBUG: tm [t_funcs.c:357]: t_relay_to(): ERROR:tm:t_relay_to:  t_forward_nonack 
returned error
DEBUG: tm [t_funcs.c:374]: t_relay_to(): -478 error reply generation delayed

And corresponding tcpdump:
27971+ NAPTR? sip-services.uninett.no. (41)
27971 0/1/0 (93)
57279+ SRV? _sip._udp.sip-services.uninett.no. (51)
57279 NXDomain 0/1/0 (103)

With the attached patch, it works. See logs:

DEBUG: <core> [dns_cache.c:569]: _dns_hash_find(): 
dns_hash_find(sip-services.uninett.no(23), 35), h=412
DEBUG: <core> [resolve.c:757]: get_record(): get_record: 
lookup(sip-services.uninett.no, 35) failed
DEBUG: <core> [dns_cache.c:897]: dns_cache_mk_bad_entry(): 
dns_cache_mk_bad_entry(sip-services.uninett.no, 35, 60, 1)
DEBUG: <core> [dns_cache.c:830]: dns_cache_add(): dns_cache_add: adding 
sip-services.uninett.no(23) 35 (flags=1) at 412
DEBUG: <core> [dns_cache.c:569]: _dns_hash_find(): 
dns_hash_find(_sip._udp.sip-services.uninett.no(33), 33), h=64
DEBUG: <core> [resolve.c:757]: get_record(): get_record: 
lookup(_sip._udp.sip-services.uninett.no, 33) failed
DEBUG: <core> [dns_cache.c:897]: dns_cache_mk_bad_entry(): 
dns_cache_mk_bad_entry(_sip._udp.sip-services.uninett.no, 33, 60, 1)
DEBUG: <core> [dns_cache.c:830]: dns_cache_add(): dns_cache_add: adding 
_sip._udp.sip-services.uninett.no(33) 33 (flags=1) at 64
DEBUG: <core> [dns_cache.c:569]: _dns_hash_find(): 
dns_hash_find(_sip._tcp.sip-services.uninett.no(33), 33), h=871
DEBUG: <core> [resolve.c:757]: get_record(): get_record: 
lookup(_sip._tcp.sip-services.uninett.no, 33) failed
DEBUG: <core> [dns_cache.c:897]: dns_cache_mk_bad_entry(): 
dns_cache_mk_bad_entry(_sip._tcp.sip-services.uninett.no, 33, 60, 1)
DEBUG: <core> [dns_cache.c:830]: dns_cache_add(): dns_cache_add: adding 
_sip._tcp.sip-services.uninett.no(33) 33 (flags=1) at 871
DEBUG: <core> [dns_cache.c:569]: _dns_hash_find(): 
dns_hash_find(sip-services.uninett.no(23), 1), h=412
DEBUG: <core> [resolve.c:954]: get_record(): get_record: skipping 5 NS 
(p=0x82a6a59, end=0x82a6b86)
DEBUG: <core> [resolve.c:970]: get_record(): get_record: parsing 9 ARs 
(p=0x82a6ac6, end=0x82a6b86)
DEBUG: <core> [dns_cache.c:1779]: dns_get_related(): dns_get_related(0xb5d8a5f8 
(sip-services.uninett.no, 1), 1, *0xb7c24e98) (0)
DEBUG: <core> [dns_cache.c:872]: dns_cache_add_unsafe(): dns_cache_add: adding 
sip-services.uninett.no(23) 1 (flags=0) at 412

and new tcpdump:
61793+ NAPTR? sip-services.uninett.no. (41)
61793 0/1/0 (93)
46996+ SRV? _sip._udp.sip-services.uninett.no. (51)
46996 NXDomain 0/1/0 (103)
1104+ SRV? _sip._tcp.sip-services.uninett.no. (51)
1104 NXDomain 0/1/0 (103)
22158+ A? sip-services.uninett.no. (41)
22158 1/5/9 A sip-services.uninett.no (358)

-- 
Øyvind Kolbu
diff --git a/dns_cache.c b/dns_cache.c
index 1243c92..3ee8e59 100644
--- a/dns_cache.c
+++ b/dns_cache.c
@@ -2857,8 +2857,10 @@ struct hostent* dns_naptr_sip_resolvehost(str* name, 
unsigned short* port,
        naptr_bmp_t tried_bmp;
        struct dns_hash_entry* e;
        char n_proto;
+        char origproto;
        str srv_name;
 
+        origproto=*proto;
        he=0;
        if (dns_hash==0){ /* not init => use normal, non-cached version */
                LOG(L_WARN, "WARNING: dns_sip_resolvehost: called before dns 
cache"
@@ -2903,7 +2905,13 @@ struct hostent* dns_naptr_sip_resolvehost(str* name, 
unsigned short* port,
                dns_hash_put(e);
        }
 naptr_not_found:
-       return no_naptr_srv_sip_resolvehost(name,port,proto);
+        *proto = origproto;
+       he = no_naptr_srv_sip_resolvehost(name,port,proto);
+        /* fallback all the way down to A/AAAA */
+        if (he==0) {
+                he=dns_get_he(name,dns_flags);
+        }
+        return he;
 }
 #endif /* USE_NAPTR */
 
diff --git a/resolve.c b/resolve.c
index e739f4b..1d5d66c 100644
--- a/resolve.c
+++ b/resolve.c
@@ -1519,21 +1519,8 @@ struct hostent* no_naptr_srv_sip_resolvehost(str* name, 
unsigned short* port, ch
                        }
                        if (default_order){
                                for (i=0; i<list_len;i++) {
-                                       switch ( srv_proto_list[i].proto) {
-                                               case PROTO_UDP:
-                                                       
srv_proto_list[i].proto_pref=4;
-                                                       break;
-                                               case PROTO_TCP:
-                                                       
srv_proto_list[i].proto_pref=3;
-                                                       break;
-                                               case PROTO_TLS:
-                                                       
srv_proto_list[i].proto_pref=2;
-                                                       break;
-                                               case PROTO_SCTP:
-                                                       
srv_proto_list[i].proto_pref=1;
-                                                       break;
-                                       }
-                               }
+                                        
srv_proto_list[i].proto_pref=proto_pref_score(i);;
+                                }
                        }
 
                        /* sorting the list */
@@ -1592,6 +1579,9 @@ struct hostent* no_naptr_srv_sip_resolvehost(str* name, 
unsigned short* port, ch
                        if ((port)&&(*port==0)){
                                
*port=(srv_proto_list[i].proto==PROTO_TLS)?SIPS_PORT:SIP_PORT; /* just in case 
we don't find another */
                        }
+                        if ((proto)&&(*proto==0)){
+                                *proto = PROTO_UDP;
+                        }
                        srv_name.s=tmp_srv;
                        srv_name.len=len;
                        #ifdef USE_DNS_CACHE
@@ -1632,9 +1622,9 @@ struct hostent* naptr_sip_resolvehost(str* name,  
unsigned short* port,
        char n_proto;
        str srv_name;
        naptr_bmp_t tried_bmp; /* tried bitmap */
+        char origproto;
 
-
-
+        origproto = *proto;
        naptr_head=0;
        he=0;
        if (name->len >= MAX_DNS_NAME) {
@@ -1673,7 +1663,12 @@ struct hostent* naptr_sip_resolvehost(str* name,  
unsigned short* port,
 #endif
        }
        /* fallback to srv lookup */
+        *proto = origproto;
        he=no_naptr_srv_sip_resolvehost(name,port,proto);
+        /* fallback all the way down to A/AAAA */
+        if (he==0) {
+            he=dns_get_he(name,dns_flags);
+        }
 end:
        if (naptr_head)
                free_rdata_list(naptr_head);
_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users

Reply via email to