resolver.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. // Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef __RESOLVER_H
  15. #define __RESOLVER_H 1
  16. #include <string>
  17. #include <vector>
  18. #include <utility>
  19. #include <cc/data.h>
  20. #include <config/ccsession.h>
  21. #include <asiolink/asiolink.h>
  22. #include <resolve/resolver_interface.h>
  23. class ResolverImpl;
  24. /**
  25. * \short The recursive nameserver.
  26. *
  27. * It is a concreate class implementing recursive DNS server protocol
  28. * processing. It is responsible for handling incoming DNS requests. It parses
  29. * them, passes them deeper into the resolving machinery and then creates the
  30. * answer. It doesn't really know about chasing referrals and similar, it
  31. * simply plugs the parts that know into the network handling code.
  32. */
  33. class Resolver : public isc::resolve::ResolverInterface {
  34. ///
  35. /// \name Constructors, Assignment Operator and Destructor.
  36. ///
  37. /// Note: The copy constructor and the assignment operator are
  38. /// intentionally defined as private.
  39. //@{
  40. private:
  41. Resolver(const Resolver& source);
  42. Resolver& operator=(const Resolver& source);
  43. public:
  44. /// The constructor.
  45. Resolver();
  46. ~Resolver();
  47. //@}
  48. virtual void resolve(
  49. const isc::dns::QuestionPtr& question,
  50. const isc::resolve::ResolverInterface::CallbackPtr& callback);
  51. /// \brief Process an incoming DNS message, then signal 'server' to resume
  52. ///
  53. /// A DNS query (or other message) has been received by a \c DNSServer
  54. /// object. Find an answer, then post the \c DNSServer object on the
  55. /// I/O service queue and return. When the server resumes, it can
  56. /// send the reply.
  57. ///
  58. /// \param io_message The raw message received
  59. /// \param query_message Pointer to the query Message object we
  60. /// received from the client
  61. /// \param answer_message Pointer to the anwer Message object we
  62. /// shall return to the client
  63. /// \param buffer Pointer to an \c OutputBuffer for the resposne
  64. /// \param server Pointer to the \c DNSServer
  65. void processMessage(const asiolink::IOMessage& io_message,
  66. isc::dns::MessagePtr query_message,
  67. isc::dns::MessagePtr answer_message,
  68. isc::dns::OutputBufferPtr buffer,
  69. asiolink::DNSServer* server);
  70. /// \brief Set and get the config session
  71. isc::config::ModuleCCSession* getConfigSession() const;
  72. void setConfigSession(isc::config::ModuleCCSession* config_session);
  73. /// \brief Handle commands from the config session
  74. isc::data::ConstElementPtr updateConfig(isc::data::ConstElementPtr config);
  75. /// \brief Assign an ASIO IO Service queue to this Resolver object
  76. void setDNSService(asiolink::DNSService& dnss);
  77. /// \brief Return this object's ASIO IO Service queue
  78. asiolink::DNSService& getDNSService() const { return (*dnss_); }
  79. /// \brief Return pointer to the DNS Lookup callback function
  80. asiolink::DNSLookup* getDNSLookupProvider() { return (dns_lookup_); }
  81. /// \brief Return pointer to the DNS Answer callback function
  82. asiolink::DNSAnswer* getDNSAnswerProvider() { return (dns_answer_); }
  83. /// \brief Return pointer to the Checkin callback function
  84. asiolink::SimpleCallback* getCheckinProvider() { return (checkin_); }
  85. /**
  86. * \brief Specify the list of upstream servers.
  87. *
  88. * Specify the list off addresses of upstream servers to forward queries
  89. * to. If the list is empty, this server is set to full recursive mode.
  90. * If it is non-empty, it switches to forwarder.
  91. *
  92. * @param addresses The list of addresses to use (each one is the address
  93. * and port pair).
  94. */
  95. void setForwardAddresses(const std::vector<std::pair<std::string,
  96. uint16_t> >& addresses);
  97. /**
  98. * \short Get list of upstream addresses.
  99. *
  100. * \see setForwardAddresses.
  101. */
  102. std::vector<std::pair<std::string, uint16_t> > getForwardAddresses() const;
  103. /// Return if we are in forwarding mode (if not, we are in fully recursive)
  104. bool isForwarding() const;
  105. /**
  106. * \brief Specify the list of root nameservers.
  107. *
  108. * Specify the list of addresses of root nameservers
  109. *
  110. * @param addresses The list of addresses to use (each one is the address
  111. * and port pair).
  112. */
  113. void setRootAddresses(const std::vector<std::pair<std::string,
  114. uint16_t> >& addresses);
  115. /**
  116. * \short Get list of root addresses.
  117. *
  118. * \see setRootAddresses.
  119. */
  120. std::vector<std::pair<std::string, uint16_t> > getRootAddresses() const;
  121. /**
  122. * Set and get the addresses we listen on.
  123. */
  124. void setListenAddresses(const std::vector<std::pair<std::string,
  125. uint16_t> >& addresses);
  126. std::vector<std::pair<std::string, uint16_t> > getListenAddresses() const;
  127. /**
  128. * \short Set options related to timeouts.
  129. *
  130. * This sets the time of timeout and number of retries.
  131. * \param query_timeout The timeout we use for queries we send
  132. * \param client_timeout The timeout at which point we send back a
  133. * SERVFAIL (while continuing to resolve the query)
  134. * \param lookup_timeout The timeout at which point we give up and
  135. * stop.
  136. * \param retries The number of retries (0 means try the first time only,
  137. * do not retry).
  138. */
  139. void setTimeouts(int query_timeout = 2000,
  140. int client_timeout = 4000,
  141. int lookup_timeout = 30000,
  142. unsigned retries = 3);
  143. /**
  144. * \short Get info about timeouts.
  145. *
  146. * \returns Timeout and retries (as described in setTimeouts).
  147. */
  148. std::pair<int, unsigned> getTimeouts() const;
  149. /**
  150. * \brief Get the timeout for outgoing queries
  151. *
  152. * \returns Timeout for outgoing queries
  153. */
  154. int getQueryTimeout() const;
  155. /**
  156. * \brief Get the timeout for incoming client queries
  157. *
  158. * After this timeout, a SERVFAIL shall be sent back
  159. * (internal resolving on the query will continue, see
  160. * \c getLookupTimeout())
  161. *
  162. * \returns Timeout for outgoing queries
  163. */
  164. int getClientTimeout() const;
  165. /**
  166. * \brief Get the timeout for lookups
  167. *
  168. * After this timeout, internal processing shall stop
  169. */
  170. int getLookupTimeout() const;
  171. /**
  172. * \brief Get the number of retries for outgoing queries
  173. *
  174. * If a query times out (value of \c getQueryTimeout()), we
  175. * will retry this number of times
  176. */
  177. int getRetries() const;
  178. private:
  179. ResolverImpl* impl_;
  180. asiolink::DNSService* dnss_;
  181. asiolink::SimpleCallback* checkin_;
  182. asiolink::DNSLookup* dns_lookup_;
  183. asiolink::DNSAnswer* dns_answer_;
  184. };
  185. #endif // __RESOLVER_H
  186. // Local Variables:
  187. // mode: c++
  188. // End: