02-mixed-recursive-authority-setup 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. Mixed recursive & authoritative setup
  2. =====================================
  3. Ideally we will run the authoritative server independently of the
  4. recursive resolver.
  5. We need a way to run both an authoritative and a recursive resolver on
  6. the same machine and listening on the same IP/port. But we need a way to
  7. run only one of them as well.
  8. This is mostly the same problem as we have with DDNS packets and xfr-out
  9. requests, but they aren't that performance sensitive as auth & resolver.
  10. There are a number of possible approaches to this:
  11. One fat module
  12. --------------
  13. With some build system or dynamic linker tricks, we create three modules:
  14. * Stand-alone auth
  15. * Stand-alone resolver
  16. * Compound module containing both
  17. The user then chooses either one stand-alone module, or the compound one,
  18. depending on the requirements.
  19. Advantages
  20. ~~~~~~~~~~
  21. * It is easier to switch between processing and ask authoritative questions
  22. from within the resolver processing.
  23. Disadvantages
  24. ~~~~~~~~~~~~~
  25. * The code is not separated (one bugs takes down both, admin can't see which
  26. one takes how much CPU).
  27. * BIND 9 does this and its code is a jungle. Maybe it's not just a
  28. coincidence.
  29. * Limits flexibility -- for example, we can't then decide to make the resolver
  30. threaded (or we would have to make sure the auth processing doesn't break
  31. with threads, which will be hard).
  32. There's also the idea of putting the auth into a loadable library and the
  33. resolver could load and use it somehow. But the advantages and disadvantages
  34. are probably the same.
  35. Auth first
  36. ----------
  37. We do the same as with xfrout and ddns. When a query comes, it is examined and
  38. if the `RD` bit is set, it is forwarded to the resolver.
  39. Advantages
  40. ~~~~~~~~~~
  41. * Separate auth and resolver modules
  42. * Minimal changes to auth
  43. * No slowdown on the auth side
  44. Disadvantages
  45. ~~~~~~~~~~~~~
  46. * Counter-intuitive asymmetric design
  47. * Possible slowdown on the resolver side
  48. * Resolver needs to know both modes (for running stand-alone too)
  49. There's also the possibility of the reverse -- resolver first. It may make
  50. more sense for performance (the more usual scenario would probably be a
  51. high-load resolver with just few low-volume authoritative zones). On the other
  52. hand, auth already has some forwarding tricks.
  53. Auth with cache
  54. ---------------
  55. This is mostly the same as ``Auth first'', however, the cache is in the auth
  56. server. If it is in the cache, it is answered right away. If not, it is then
  57. forwarded to the resolver. The resolver then updates the cache too.
  58. Advantages
  59. ~~~~~~~~~~
  60. * Probably good performance
  61. Disadvantages
  62. ~~~~~~~~~~~~~
  63. * Cache duplication (several auth modules, it doesn't feel like it would work
  64. with shared memory without locking).
  65. * Cache is probably very different from authoritative zones, it would
  66. complicate auth processing.
  67. * The resolver needs own copy of cache (to be able to get partial results),
  68. probably a different one than the auth server.
  69. Receptionist
  70. ------------
  71. One module does only the listening. It doesn't process the queries itself, it
  72. only looks into them and forwards them to the processing modules.
  73. Advantages
  74. ~~~~~~~~~~
  75. * Clean design with separated modules
  76. * Easy to run modules stand-alone
  77. * Allows for solving the xfrout & ddns forwarding without auth running
  78. * Allows for views (different auths with different configurations)
  79. * Allows balancing/clustering across multiple machines
  80. * Easy to create new modules for different kinds of DNS handling and share
  81. port with them too
  82. Disadvantages
  83. ~~~~~~~~~~~~~
  84. * Need to set up another module (not a problem if we have inter-module
  85. dependencies in b10-init)
  86. * Possible performance impact. However, experiments show this is not an issue,
  87. and the receptionist can actually increase the throughput with some tuning
  88. and the increase in RTT is not big.
  89. Implementation ideas
  90. ~~~~~~~~~~~~~~~~~~~~
  91. * Let's have a new TCP transport, where we send not only the DNS messages,
  92. but also the source and destination ports and addresses (two reasons --
  93. ACLs in target module and not keeping state in the receptionist). It would
  94. allow for transfer of a batch of messages at once, to save some calls to
  95. kernel (like a length of block of messages, it is read at once, then they
  96. are all parsed one by one, the whole block of answers is sent back).
  97. * A module creates a listening socket (UNIX by default) on startup and
  98. contacts all the receptionists. It sends what kind of packets to send
  99. to the module and the address of the UNIX socket. All the receptionists
  100. connect to the module. This allows for auto-configuring the receptionist.
  101. * The queries are sent from the receptionist in batches, the answers are sent
  102. back to the receptionist in batches too.
  103. * It is possible to fine-tune and use OS-specific tricks (like epoll or
  104. sending multiple UDP messages by single call to sendmmsg()).
  105. Proposal
  106. --------
  107. Implement the receptionist in a way we can still work without it (not throwing
  108. the current UDPServer and TCPServer in asiodns away).
  109. The way we handle xfrout and DDNS needs some changes, since we can't forward
  110. sockets for the query. We would implement the receptionist protocol on them,
  111. which would allow the receptionist to forward messages to them. We would then
  112. modify auth to be able to forward the queries over the receptionist protocol,
  113. so ordinary users don't need to start the receptionist.