OpenSIPS / opensips

OpenSIPS is a GPL implementation of a multi-functionality SIP Server that targets to deliver a high-level technical solution (performance, security and quality) to be used in professional SIP server platforms.
https://opensips.org
Other
1.28k stars 581 forks source link

Use the Additional section of SRV queries instead of doing extra requests #675

Open Esya opened 9 years ago

Esya commented 9 years ago

It seems like opensips when using SRV records does not read and use the ADDITIONAL RECORDS, and instead sends another DNS request to get the IP for the host, which is inefficient and could be supported just like mentioned in the RFC 2782 :

For each element in the new list

  query the DNS for address records for the Target or
  use any such records found in the Additional Data
  section of the earlier SRV response.

Example, for our _sip._udp service using our service discovery tool :

;; ANSWER SECTION:
_sip._udp.service.consul. 15  IN  SRV 1 1 5063 ourserver.node.us.consul.
_sip._udp.service.consul. 15  IN  SRV 1 1 5060 ourserver.node.us.consul.
_sip._udp.service.consul. 15  IN  SRV 1 1 5062 ourserver.node.us.consul.
_sip._udp.service.consul. 15  IN  SRV 1 1 5061 ourserver.node.us.consul.

;; ADDITIONAL SECTION:
ourserver.node.us.consul. 15 IN A 98.XXX.XXX.XXX

It has all the information it needs but it still does an extra A query, which is an issue for us as some of our services run on different interfaces. I'm looking at resolve.c and trying to see how this can be implemented (See how Kamailio is doing it for example) but I've ran into issues with the dns_cache. Any thoughts or anyone that would like to take on this issue?

vladpaiu commented 9 years ago

Hello,

This would be a great feature to implement - though I can't really find such a SRV record ( with additional records ) out in the wild, in order to have something to test against.. Could you please provide such a SRV DNS record that I can test with ?

Best Regards, Vlad

Esya commented 9 years ago

Hi @vladpaiu,

I just pushed a dummy DNS Server on new.esya.me that serves the right format for you; you can try this :

# dig _sip._udp.example.org @new.esya.me SRV
;; QUESTION SECTION:
;_sip._udp.example.org.     IN  SRV

;; ANSWER SECTION:
_sip._udp.example.org.  600 IN  SRV 1 1 5062 hostA.example.org.
_sip._udp.example.org.  600 IN  SRV 1 1 5061 hostB.example.org.

;; AUTHORITY SECTION:
dummy.          600 IN  NS  ignoreme.

;; ADDITIONAL SECTION:
hostA.example.org.  600 IN  A   1.1.1.1
hostA.example.org.  600 IN  A   2.2.2.2

You should therefore be able to do a simple redirect on example.org and opensips will automatically append _sip._udp. This server will have empty answers for anything other than SRV lookup for _sip._udp.example.org and is listening on both UDP and TCP. I've included an authority section just to make sure that it is properly skipped by the client.

Best, Tristan

vladpaiu commented 9 years ago

Hello,

Thanks for the help with this - the record looks fine.

Will work on it and update the ticket when it's done.

Regards, Vlad