auth_srv.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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 AUTH_SRV_H
  15. #define AUTH_SRV_H 1
  16. #include <config/ccsession.h>
  17. #include <datasrc/factory.h>
  18. #include <datasrc/client_list.h>
  19. #include <datasrc/datasrc_config.h>
  20. #include <dns/message.h>
  21. #include <dns/opcode.h>
  22. #include <util/buffer.h>
  23. #include <asiodns/dns_server.h>
  24. #include <asiodns/dns_service.h>
  25. #include <asiodns/dns_lookup.h>
  26. #include <asiodns/dns_answer.h>
  27. #include <asiolink/io_message.h>
  28. #include <asiolink/io_service.h>
  29. #include <asiolink/simple_callback.h>
  30. #include <asiolink/asiolink.h>
  31. #include <server_common/portconfig.h>
  32. #include <auth/statistics.h>
  33. #include <auth/datasrc_clients_mgr.h>
  34. #include <boost/shared_ptr.hpp>
  35. namespace isc {
  36. namespace util {
  37. namespace io {
  38. class BaseSocketSessionForwarder;
  39. }
  40. namespace thread {
  41. class Mutex;
  42. }
  43. }
  44. namespace datasrc {
  45. class ConfigurableClientList;
  46. }
  47. namespace xfr {
  48. class AbstractXfroutClient;
  49. }
  50. namespace dns {
  51. class TSIGKeyRing;
  52. }
  53. }
  54. /// \brief The implementation class for the \c AuthSrv class using the pimpl
  55. /// idiom.
  56. class AuthSrvImpl;
  57. /// \brief The authoritative nameserver class.
  58. ///
  59. /// \c AuthSrv is a concrete class that implements authoritative DNS server
  60. /// protocol processing.
  61. /// An \c AuthSrv object is primarily responsible for handling incoming DNS
  62. /// requests: It parses the request and dispatches subsequent processing to
  63. /// the corresponding module (which may be an internal library or a separate
  64. /// process) depending on the request type. For normal queries, the
  65. /// \c AuthSrv object searches configured data sources for the answer to the
  66. /// query, and builds a response containing the answer.
  67. ///
  68. /// This class uses the "pimpl" idiom, and hides detailed implementation
  69. /// through the \c impl_ pointer (which points to an instance of the
  70. /// \c AuthSrvImpl class). An \c AuthSrv object is supposed to exist for quite
  71. /// a long period, and only a few \c AuthSrv objects will be created (in fact,
  72. /// in this current implementation there will only be one object), so the
  73. /// construction overhead of this approach should be acceptable.
  74. ///
  75. /// The design of this class is still in flux. It's quite likely to change
  76. /// in future versions.
  77. ///
  78. class AuthSrv {
  79. ///
  80. /// \name Constructors, Assignment Operator and Destructor.
  81. ///
  82. /// Note: The copy constructor and the assignment operator are
  83. /// intentionally defined as private.
  84. //@{
  85. private:
  86. AuthSrv(const AuthSrv& source);
  87. AuthSrv& operator=(const AuthSrv& source);
  88. public:
  89. /// The constructor.
  90. ///
  91. /// \param xfrout_client Communication interface with a separate xfrout
  92. /// process. It's normally a reference to an xfr::XfroutClient object,
  93. /// but can refer to a local mock object for testing (or other
  94. /// experimental) purposes.
  95. AuthSrv(isc::xfr::AbstractXfroutClient& xfrout_client,
  96. isc::util::io::BaseSocketSessionForwarder& ddns_forwarder);
  97. ~AuthSrv();
  98. //@}
  99. /// Stop the server.
  100. ///
  101. /// It stops the internal event loop of the server and subsequently
  102. /// returns the control to the top level context.
  103. ///
  104. /// This method should never throw an exception.
  105. void stop();
  106. /// \brief Process an incoming DNS message, then signal 'server' to resume
  107. ///
  108. /// A DNS query (or other message) has been received by a \c DNSServer
  109. /// object. Find an answer, then post the \c DNSServer object on the
  110. /// I/O service queue and return. When the server resumes, it can
  111. /// send the reply.
  112. ///
  113. /// \param io_message The raw message received
  114. /// \param message the \c Message object
  115. /// \param buffer an \c OutputBuffer for the resposne
  116. /// \param server Pointer to the \c DNSServer
  117. ///
  118. /// \throw isc::Unexpected Protocol type of \a message is unexpected
  119. void processMessage(const isc::asiolink::IOMessage& io_message,
  120. isc::dns::Message& message,
  121. isc::util::OutputBuffer& buffer,
  122. isc::asiodns::DNSServer* server);
  123. /// \brief Updates the configuration for the \c AuthSrv object.
  124. ///
  125. /// On success this method returns a data \c Element (in the form of a
  126. /// pointer like object) indicating the successful result,
  127. /// i.e., {"result": [0]}.
  128. /// Otherwise, it returns a data \c Element explaining the error:
  129. /// {"result": [1, <error-description>]}.
  130. ///
  131. /// This method is mostly exception free (error conditions are represented
  132. /// via the return value). But it may still throw a standard exception
  133. /// if memory allocation fails inside the method.
  134. /// When a standard exception is thrown or an implementation specific
  135. /// exception is triggered and caught internally, this function provides
  136. /// the strong exception guarantee: Unless everything succeeds, currently
  137. /// installed data source (if any) won't be replaced.
  138. ///
  139. /// \param config An immutable pointer-like object to a data \c Element,
  140. /// possibly containing the data source information to be used.
  141. /// \return An immutable pointer-like object to a data \c Element
  142. /// containing the result of the update operation.
  143. isc::data::ConstElementPtr updateConfig(isc::data::ConstElementPtr config);
  144. /// \brief Returns the command and configuration session for the
  145. /// \c AuthSrv.
  146. ///
  147. /// This method never throws an exception.
  148. ///
  149. /// \return A pointer to \c ModuleCCSession object stored in the
  150. /// \c AuthSrv object. In this implementation it could be NULL.
  151. isc::config::ModuleCCSession* getConfigSession() const;
  152. /// \brief Set the command and configuration session for the \c AuthSrv.
  153. ///
  154. /// Note: this interface is tentative. We'll revisit the ASIO and session
  155. /// frameworks, at which point the session will probably be passed on
  156. /// construction of the server.
  157. /// In the current implementation, this method is expected to be called
  158. /// exactly once as part of initialization. If this method is called
  159. /// multiple times, previously specified session is silently overridden.
  160. ///
  161. /// This method never throws an exception.
  162. ///
  163. /// \param config_session A pointer to \c ModuleCCSession object to receive
  164. /// control commands and configuration updates.
  165. void setConfigSession(isc::config::ModuleCCSession* config_session);
  166. /// \brief Return this object's ASIO IO Service queue
  167. isc::asiolink::IOService& getIOService();
  168. /// \brief Return pointer to the DNS Lookup callback function
  169. isc::asiodns::DNSLookup* getDNSLookupProvider() const { return (dns_lookup_); }
  170. /// \brief Return pointer to the DNS Answer callback function
  171. isc::asiodns::DNSAnswer* getDNSAnswerProvider() const { return (dns_answer_); }
  172. /// \brief Return pointer to the Checkin callback function
  173. isc::asiolink::SimpleCallback* getCheckinProvider() const { return (checkin_); }
  174. /// \brief Return data source clients manager.
  175. ///
  176. /// \throw None
  177. isc::auth::DataSrcClientsMgr& getDataSrcClientsMgr();
  178. /// \brief Set the communication session with a separate process for
  179. /// outgoing zone transfers.
  180. ///
  181. /// Note: this interface is tentative. We'll revisit the ASIO and session
  182. /// frameworks, at which point the session will probably be passed on
  183. /// construction of the server.
  184. ///
  185. /// \param xfrin_session A Session object over which NOTIFY message
  186. /// information is exchanged with a XFRIN handler.
  187. /// The session must be established before setting in the server
  188. /// object.
  189. /// Ownership isn't transferred: the caller is responsible for keeping
  190. /// this object to be valid while the server object is working and for
  191. /// disconnecting the session and destroying the object when the server
  192. /// is shutdown.
  193. ///
  194. void setXfrinSession(isc::cc::AbstractSession* xfrin_session);
  195. /// \brief Returns statistics data
  196. ///
  197. /// This function can throw an exception from
  198. /// Counters::get().
  199. ///
  200. /// \return JSON format statistics data.
  201. isc::data::ConstElementPtr getStatistics() const;
  202. /**
  203. * \brief Set and get the addresses we listen on.
  204. */
  205. void setListenAddresses(const isc::server_common::portconfig::AddressList&
  206. addreses);
  207. const isc::server_common::portconfig::AddressList& getListenAddresses()
  208. const;
  209. /// \brief Assign an ASIO DNS Service queue to this Auth object
  210. void setDNSService(isc::asiodns::DNSServiceBase& dnss);
  211. /// \brief Sets the keyring used for verifying and signing
  212. ///
  213. /// The parameter is pointer to shared pointer, because the automatic
  214. /// reloading routines of tsig keys replace the actual keyring object.
  215. /// It is expected the pointer will point to some statically-allocated
  216. /// object, it doesn't take ownership of it.
  217. void setTSIGKeyRing(const boost::shared_ptr<isc::dns::TSIGKeyRing>*
  218. keyring);
  219. /// \brief Create the internal forwarder for DDNS update messages
  220. ///
  221. /// Until this method is called (it is called when the
  222. /// start_ddns_forwarder command is sent to b10-auth), b10-auth will
  223. /// respond to UPDATE messages with a NOTIMP rcode.
  224. /// If the internal forwarder was already created, it is destroyed and
  225. /// created again. This is useful for instance when b10-ddns is shut
  226. /// down and restarted.
  227. void createDDNSForwarder();
  228. /// \brief Destroy the internal forwarder for DDNS update messages
  229. ///
  230. /// After this method has been called (it is called when the
  231. /// stop_ddns_forwarder command is sent to b10-auth), DDNS Update
  232. /// messages are no longer forwarded internally, but b10-auth will
  233. /// immediately respond with a NOTIMP rcode.
  234. /// If there was no forwarder yet, this method does nothing.
  235. void destroyDDNSForwarder();
  236. /// \brief Sets the timeout for incoming TCP connections
  237. ///
  238. /// Incoming TCP connections that have not sent their data
  239. /// within this time are dropped.
  240. ///
  241. /// \param timeout The timeout (in milliseconds). If se to
  242. /// zero, no timeouts are used, and the connection will remain
  243. /// open forever.
  244. void setTCPRecvTimeout(size_t timeout);
  245. private:
  246. AuthSrvImpl* impl_;
  247. isc::asiolink::SimpleCallback* checkin_;
  248. isc::asiodns::DNSLookup* dns_lookup_;
  249. isc::asiodns::DNSAnswer* dns_answer_;
  250. isc::asiodns::DNSServiceBase* dnss_;
  251. };
  252. #endif // AUTH_SRV_H
  253. // Local Variables:
  254. // mode: c++
  255. // End: