dns.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. # $Id$
  2. #
  3. # History:
  4. # --------
  5. # 2006-09-08 created by andrei
  6. # 2007-06-18 added naptr & friends, dns_srv_lb, more compile options (andrei)
  7. #
  8. Overview
  9. The dns subsystem in ser can either directly use libresolv and a combination
  10. of the locally configured dns server, /etc/hosts and the local Network
  11. Information Service (NIS/YP a.s.o) or cache the query results (both positive
  12. and negative) and look first in its internal cache.
  13. When its internal dns cache is enabled, ser can also use dns failover: if
  14. one destination resolves to multiple addresses ser can try all of them until
  15. it finds one to which it can successfully send the packet or it exhausts all
  16. of them. ser (tm to be more precise) uses the dns failover also when the
  17. destination host doesn't send any reply to a forwarded invite within the
  18. sip timeout interval (whose value can be configured using the tm fr_timer
  19. parameter).
  20. When SRV based load balancing is enabled ser can even do DNS based load
  21. balancing (see RFC2782 and the dns_srv_lb option below).
  22. DNS Cache and Failover Drawbacks
  23. Using the dns cache and the dns failover has also some drawbacks:
  24. 1. only the locally configured dns server (usually in /etc/resolv.conf) is
  25. used for the requests (/etc/hosts and the local Network Information Service
  26. are ignored).
  27. Workaround: disable the dns cache (use_dns_cache=off or
  28. compile without -DUSE_DNS_CACHE).
  29. 2. the dns cache uses extra memory
  30. Workaround: disable the dns cache.
  31. 3. the dns failover introduces a very small performance penalty
  32. Workaround: disable the dns failover (use_dns_failover=off).
  33. 4. the dns failover increases the memory usage (the internal structures
  34. used to represent the transaction are bigger when the dns failover support is
  35. compiled).
  36. Workaround: compile without dns failover support (-DUSE_DNS_FAILOVER).
  37. Turning it off from the config file is not enough in this case (the extra
  38. memory will still be used).
  39. On the other hand using the dns cache saves lots of DNS queries and makes
  40. DNS based failover and DNS based load balancing possible. If the destination
  41. blacklist is enabled, ser can do failover even if forwarding in stateless
  42. mode.
  43. In the ideal case with dns cache enabled ser will do only one query for
  44. a NAPTR (if enabled) or SRV lookup and then it will use the results for the
  45. record's TTL (for example if all the resulting records have 1 minute TTL,
  46. ser won't make another query for this domain for 1 minute). Even negative
  47. answers will be cached.
  48. Without the dns cache, each NAPTR or SRV lookup will result in at least 2
  49. queries. These queries will happen every time, for each message (even if
  50. all of them go to the same domain).
  51. DNS Resolver Options
  52. The DNS resolver options control how ser will interact with the external
  53. DNS servers. These options (with the dns_try_ipv6 exception) are passed to
  54. libresolv and are used each time a dns request is made.
  55. The default values are system specific and generally depend on the
  56. /etc/resolv.conf content. For servers doing a lot of DNS requests it is
  57. highly recommended to change the default values in the ser config file
  58. (even if using ser's internal dns cache).
  59. dns_try_ipv6 = on | off - if on and ser listens on at least one ipv6 socket,
  60. ipv6 (AAAA) lookups will be performed if the ipv4 (A) lookups fail.
  61. If off only ipv4 (A) lookups will be used.
  62. Default: on if ser is compiled with ipv6 support.
  63. dns_try_naptr = on | off - if on ser will first try a NAPTR lookup for
  64. destinations that don't have the protocol or port specified and
  65. are not simple ip addresses (as described in RFC 3263). This will
  66. introduce a slight performance penalty and will probably cause extra
  67. DNS lookups. For example a lookup for a non-existing domain will
  68. produce one extra query: NAPTR(domain), SRV(_sip._udp.domain)
  69. and A/AAAA(domain).
  70. If the result of a query contains several NAPTR records, ser will select
  71. among them according to the RFC2915 and ser preference towards a
  72. specific protocol (see dns_udp_pref, dns_tcp_pref and dns_tls_pref
  73. below). For an RFC3263 compliant configuration (choose the remote side
  74. preferred protocol if supported), set dns_udp_pref, dns_tcp_pref and
  75. dns_tls_pref to the same value (>=0), e.g. 0.
  76. Default: off
  77. dns_udp_pref = number - udp protocol preference when doing NAPTR lookups.
  78. This option works together with dns_tcp_pref and dns_tls_pref. If all
  79. this options have the same positive value and more NAPTR records are
  80. available, ser will select the NAPTR record preferred by the remote side
  81. (according to RFC2915). If the values are positive but different, ser
  82. will select the NAPTR record whose protocol it prefers the most
  83. (the protocol with the highest dns_<proto>_pref number). If there are
  84. several NAPTR records with the same preferred protocol, ser will select
  85. among them based on their order and preference (see RFC2915).
  86. To completely disable selecting a specific protocol, use a negative
  87. number. For example dns_tcp_pref=-1 will completely disable selection
  88. of tcp NAPTR records, even if this will result in the NAPTR lookup
  89. failure.
  90. Default: dns_udp_pref=3, dns_tcp_pref=2 and dns_tls_pref=1
  91. (prefer udp, but if no udp NAPTR record found or no SRV-resolvable
  92. udp NAPTR record found use tcp records and if this fails too use tls)
  93. dns_tcp_pref = number (see dns_udp_pref above)
  94. dns_tls_pref = number (see dns_udp_pref above)
  95. dns_retr_time = time - time in s before retrying a dns request.
  96. Default: system specific, depends also on the/etc/resolv.conf content
  97. (usually 5 s).
  98. dns_retr_no = no. - number of dns retransmissions before giving up.
  99. Default: see above (usually 4)
  100. dns_servers_no = no. - how many dns servers from the ones defined in
  101. /etc/resolv.conf will be used. Default: all of them.
  102. dns_use_search_list= yes/no - if no, the search list in /etc/resolv.conf
  103. will be ignored (=> fewer lookups => gives up faster).
  104. Default: yes.
  105. HINT: even if you don't have a search list defined, setting this option
  106. to "no" will still be "faster", because an empty search list is in
  107. fact search "" (so even if the search list is empty/missing there will
  108. still be 2 dns queries, eg. foo+'.' and foo+""+'.')
  109. dns_search_full_match = yes/no - controls the check of the name part
  110. which is found in the answer expanding the searched name before
  111. the answer is treated as correct and "link" (fake CNAME record)
  112. between the short name (query) and long name (answer) is created
  113. which is then stored in dns_cache and reused for next queries.
  114. If set to no - no additional check is done.
  115. If set to yes - the additional part is checked against the search list.
  116. The maximum time a dns request can take (before failing) is:
  117. (dns_retr_time*dns_retr_no)*(search_list_domains) If dns_try_ipv6 is yes,
  118. mutliply it again by 2.
  119. The option combination that produces the "fastest" dns resolver config
  120. (the "faster" in the sense that it gives up the quickest) is:
  121. dns_try_ipv6=no
  122. dns_retr_time=1
  123. dns_retr_no=1
  124. dns_servers_no=1
  125. dns_use_search_list=no
  126. The recommended dns configuration is to have a "close" dns caching recursive
  127. server configured in /etc/resolv.conf, set the dns resolver options in ser's
  128. config as in the above example and enable the dns cache (in ser).
  129. Pay particular attention to dns_servers_no and dns_use_search_list. It's a
  130. good idea to make sure you don't need / use the search list or more then one
  131. dns server (to avoid unnecessary extra lookups).
  132. DNS Resolver Compile Options
  133. USE_NAPTR - if defined the naptr lookup support will be compiled in.
  134. NAPTR support still has to be enabled from ser's config file (it's
  135. off by default).
  136. RESOLVE_DBG - if defined, the resolver will be very verbose: it will log
  137. a lot of debugging information at L_DBG level.
  138. NAPTR_DBG - if defined the NAPTR related resolver functions will be very
  139. verbose.
  140. DNS Cache and Failover Config Variables
  141. use_dns_cache = on | off - if off the dns cache won't be used (all dns
  142. lookups will result into a dns request). When on all the dns request
  143. results will be cached.
  144. WARNING: when enabled /etc/hosts will be completely bypassed, all the dns
  145. request will go directly to the system configured (resolv.conf) dns
  146. server.
  147. Default: on.
  148. use_dns_failover = on |off - if on and sending a request fails (due to not
  149. being allowed from an onsend_route, send failure, blacklisted destination
  150. or, when using tm, invite timeout), and the destination resolves to
  151. multiple ip addresses and/or multiple SRV records, the send will be
  152. re-tried using the next ip/record. In tm's case a new branch will be
  153. created for each new send attempt.
  154. Default: off.
  155. Depends on use_dns_cache being on. If tm is used along with dns failover is
  156. recommended to also turn on dst_blacklist.
  157. dns_srv_lb = on | off or
  158. dns_srv_loadbalancing = on | off - if on instead of doing simple dns
  159. failover (like above), ser will load balance requests to different srv
  160. records of the same priority based on the srv records weights (like
  161. described in RFC2782). For a destination which has different priorities
  162. for all its srv records, this option will be equivalent with simple
  163. dns failover.
  164. Note: this option requires having dns failover enabled (see
  165. use_dns_failover above).
  166. Default: off.
  167. dns_try_ipv6 = on | off - shared with the resolver (see resolver
  168. description).
  169. dns_try_naptr = on | off - shared with the resolver (see resolver
  170. description).
  171. dns_udp_pref = number - shared with the resolver (see resolver
  172. description).
  173. dns_tcp_pref = number - shared with the resolver (see resolver
  174. description).
  175. dns_tls_pref = number - shared with the resolver (see resolver
  176. description).
  177. dns_cache_flags = dns cache specific resolver flags, used for overriding
  178. the default behaviour (low level).
  179. Possible values:
  180. 1 - ipv4 only: only DNS A requests are performed, even if ser listens
  181. also on ipv6 addresses.
  182. 2 - ipv6 only: only DNS AAAA requests are performed. Ignored if
  183. dns_try_ipv6 is off or ser doesn't listen on any ipv6
  184. address.
  185. 4 - prefer ipv6: try first to resolve a host name to an ipv6 address
  186. (DNS AAAA request) and only if this fails try an ipv4
  187. address (DNS A request).
  188. By default the ipv4 addresses are preferred.
  189. Default: 0
  190. dns_cache_negative_ttl = time to live for negative results ("not found") in
  191. seconds. Use 0 to disable.
  192. Default: 60 s.
  193. dns_cache_min_ttl = minimum accepted time to live for a record, in seconds.
  194. If a record has a lower ttl, its value will be discarded and
  195. dns_cache_min_ttl will be used instead.
  196. Default: 0
  197. dns_cache_max_ttl = maximum accepted time to live for a record, in seconds.
  198. If a record has a higher ttl, its value will be discarded and
  199. dns_cache_max_ttl will be used instead.
  200. Default: MAXINT
  201. dns_cache_mem = maximum memory used for the dns cache in Kb.
  202. Default: 500 Kb
  203. dns_cache_gc_interval = how often (in s) the dns cache will be garbage
  204. collected.
  205. Default: 120 s.
  206. dns_cache_del_nonexp = yes | no or
  207. dns_cache_delete_nonexpired = yes | no - allow deletion of non-expired
  208. records from the cache when there is no more space left for new
  209. ones. The last-recently used entries are deleted first.
  210. Default: no
  211. dns_cache_init = on | off - if off, the dns cache is not initialized
  212. at startup and cannot be enabled runtime, that saves some memory.
  213. Default: on
  214. DNS Cache Compile Options
  215. USE_DNS_CACHE - if defined the dns cache support will be compiled in
  216. (default). If not needed/wanted the dns_cache can be disabled from the
  217. ser's config file. The only advantages for not compiling the dns cache
  218. support is a slight decrease of the executable size and an extremely
  219. small performance increase (1 less comparison per dns request).
  220. USE_DNS_FAILOVER - if defined the dns failover support will be compiled in.
  221. (default). Compiling the dns failover support has a few disadvantages,
  222. see the "Drawbacks" section.
  223. DNS_SRV_LB - if defined (default) support for load balancing using
  224. srv records weights (as described in RFC2782) will be compiled in.
  225. Note however that it still must be enabled from the ser config, it's
  226. disabled by default (see the dns_srv_lb config option).
  227. USE_NAPTR - (shared with the resolver) if defined NAPTR support will
  228. be compiled in (default). Note that even if compiled, NAPTR support
  229. must be enabled also from the ser config (see the dns_try_naptr option).
  230. NAPTR_CACHE_ALL_ARS - if defined all the additional records in a NAPTR
  231. answer will be cached. Normally ser would cache only "related" records
  232. (records that are directly referred), but for answers with lots of
  233. A/AAAA records it might happen that not all of the SRV records will fit
  234. in the AR section. In this case, without this compile option ser will
  235. not cache the un-referred A/AAAA records. BY default this option is
  236. disabled.
  237. CACHE_RELEVANT_RECS_ONLY - if defined (default), records in the AR section
  238. of an answer will be cached only if they are "related" to the query.
  239. For example if the query is for a SRV record, A & AAAA records in the
  240. AR section will be cached only if there are SRV records pointing to
  241. them. This avoids adding possible garbage to the cache.
  242. If this option is not defined (experimental), everything in the AR
  243. section will be added to the cache.
  244. DNS_CACHE_DEBUG - if defined the dns cache will be very verbose (it will
  245. log lots of messages at the L_DBG levell).
  246. Note: To remove a compile options, edit ser's Makefile.defs and remove it
  247. form DEFS list. To add a compile options add it to the make command line,
  248. e.g.: make proper; make all extra_defs=-DUSE_DNS_FAILOVER
  249. or for a permanent solution, edit Makefile.defs and add it to DEFS
  250. (don't foget to prefix it with -D). Some options require editing
  251. dns_cache.c or resolve.[ch] (just grep after them).