auth_srv.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. /// \param ddns_forwarder Forwarder to which DDNS UPDATE requests
  96. /// are passed to
  97. AuthSrv(isc::xfr::AbstractXfroutClient& xfrout_client,
  98. isc::util::io::BaseSocketSessionForwarder& ddns_forwarder);
  99. ~AuthSrv();
  100. //@}
  101. /// Stop the server.
  102. ///
  103. /// It stops the internal event loop of the server and subsequently
  104. /// returns the control to the top level context.
  105. ///
  106. /// This method should never throw an exception.
  107. void stop();
  108. /// \brief Process an incoming DNS message, then signal 'server' to resume
  109. ///
  110. /// A DNS query (or other message) has been received by a \c DNSServer
  111. /// object. Find an answer, then post the \c DNSServer object on the
  112. /// I/O service queue and return. When the server resumes, it can
  113. /// send the reply.
  114. ///
  115. /// \param io_message The raw message received
  116. /// \param message the \c Message object
  117. /// \param buffer an \c OutputBuffer for the resposne
  118. /// \param server Pointer to the \c DNSServer
  119. ///
  120. /// \throw isc::Unexpected Protocol type of \a message is unexpected
  121. void processMessage(const isc::asiolink::IOMessage& io_message,
  122. isc::dns::Message& message,
  123. isc::util::OutputBuffer& buffer,
  124. isc::asiodns::DNSServer* server);
  125. /// \brief Updates the configuration for the \c AuthSrv object.
  126. ///
  127. /// On success this method returns a data \c Element (in the form of a
  128. /// pointer like object) indicating the successful result,
  129. /// i.e., {"result": [0]}.
  130. /// Otherwise, it returns a data \c Element explaining the error:
  131. /// {"result": [1, <error-description>]}.
  132. ///
  133. /// This method is mostly exception free (error conditions are represented
  134. /// via the return value). But it may still throw a standard exception
  135. /// if memory allocation fails inside the method.
  136. /// When a standard exception is thrown or an implementation specific
  137. /// exception is triggered and caught internally, this function provides
  138. /// the strong exception guarantee: Unless everything succeeds, currently
  139. /// installed data source (if any) won't be replaced.
  140. ///
  141. /// \param config An immutable pointer-like object to a data \c Element,
  142. /// possibly containing the data source information to be used.
  143. /// \return An immutable pointer-like object to a data \c Element
  144. /// containing the result of the update operation.
  145. isc::data::ConstElementPtr updateConfig(isc::data::ConstElementPtr config);
  146. /// \brief Returns the command and configuration session for the
  147. /// \c AuthSrv.
  148. ///
  149. /// This method never throws an exception.
  150. ///
  151. /// \return A pointer to \c ModuleCCSession object stored in the
  152. /// \c AuthSrv object. In this implementation it could be NULL.
  153. isc::config::ModuleCCSession* getConfigSession() const;
  154. /// \brief Set the command and configuration session for the \c AuthSrv.
  155. ///
  156. /// Note: this interface is tentative. We'll revisit the ASIO and session
  157. /// frameworks, at which point the session will probably be passed on
  158. /// construction of the server.
  159. /// In the current implementation, this method is expected to be called
  160. /// exactly once as part of initialization. If this method is called
  161. /// multiple times, previously specified session is silently overridden.
  162. ///
  163. /// This method never throws an exception.
  164. ///
  165. /// \param config_session A pointer to \c ModuleCCSession object to receive
  166. /// control commands and configuration updates.
  167. void setConfigSession(isc::config::ModuleCCSession* config_session);
  168. /// \brief Return this object's ASIO IO Service queue
  169. isc::asiolink::IOService& getIOService();
  170. /// \brief Return pointer to the DNS Lookup callback function
  171. isc::asiodns::DNSLookup* getDNSLookupProvider() const { return (dns_lookup_); }
  172. /// \brief Return pointer to the DNS Answer callback function
  173. isc::asiodns::DNSAnswer* getDNSAnswerProvider() const { return (dns_answer_); }
  174. /// \brief Return pointer to the Checkin callback function
  175. isc::asiolink::SimpleCallback* getCheckinProvider() const { return (checkin_); }
  176. /// \brief Return data source clients manager.
  177. ///
  178. /// \throw None
  179. isc::auth::DataSrcClientsMgr& getDataSrcClientsMgr();
  180. /// \brief Set the communication session with a separate process for
  181. /// outgoing zone transfers.
  182. ///
  183. /// Note: this interface is tentative. We'll revisit the ASIO and session
  184. /// frameworks, at which point the session will probably be passed on
  185. /// construction of the server.
  186. ///
  187. /// \param xfrin_session A Session object over which NOTIFY message
  188. /// information is exchanged with a XFRIN handler.
  189. /// The session must be established before setting in the server
  190. /// object.
  191. /// Ownership isn't transferred: the caller is responsible for keeping
  192. /// this object to be valid while the server object is working and for
  193. /// disconnecting the session and destroying the object when the server
  194. /// is shutdown.
  195. ///
  196. void setXfrinSession(isc::cc::AbstractSession* xfrin_session);
  197. /// \brief Returns statistics data
  198. ///
  199. /// This function can throw an exception from
  200. /// Counters::get().
  201. ///
  202. /// \return JSON format statistics data.
  203. isc::data::ConstElementPtr getStatistics() const;
  204. /**
  205. * \brief Set and get the addresses we listen on.
  206. */
  207. void setListenAddresses(const isc::server_common::portconfig::AddressList&
  208. addresses);
  209. const isc::server_common::portconfig::AddressList& getListenAddresses()
  210. const;
  211. /// \brief Assign an ASIO DNS Service queue to this Auth object
  212. void setDNSService(isc::asiodns::DNSServiceBase& dnss);
  213. /// \brief Sets the keyring used for verifying and signing
  214. ///
  215. /// The parameter is pointer to shared pointer, because the automatic
  216. /// reloading routines of tsig keys replace the actual keyring object.
  217. /// It is expected the pointer will point to some statically-allocated
  218. /// object, it doesn't take ownership of it.
  219. void setTSIGKeyRing(const boost::shared_ptr<isc::dns::TSIGKeyRing>*
  220. keyring);
  221. /// \brief Create the internal forwarder for DDNS update messages
  222. ///
  223. /// Until this method is called (it is called when the
  224. /// start_ddns_forwarder command is sent to b10-auth), b10-auth will
  225. /// respond to UPDATE messages with a NOTIMP rcode.
  226. /// If the internal forwarder was already created, it is destroyed and
  227. /// created again. This is useful for instance when b10-ddns is shut
  228. /// down and restarted.
  229. void createDDNSForwarder();
  230. /// \brief Destroy the internal forwarder for DDNS update messages
  231. ///
  232. /// After this method has been called (it is called when the
  233. /// stop_ddns_forwarder command is sent to b10-auth), DDNS Update
  234. /// messages are no longer forwarded internally, but b10-auth will
  235. /// immediately respond with a NOTIMP rcode.
  236. /// If there was no forwarder yet, this method does nothing.
  237. void destroyDDNSForwarder();
  238. /// \brief Sets the timeout for incoming TCP connections
  239. ///
  240. /// Incoming TCP connections that have not sent their data
  241. /// within this time are dropped.
  242. ///
  243. /// \param timeout The timeout (in milliseconds). If se to
  244. /// zero, no timeouts are used, and the connection will remain
  245. /// open forever.
  246. void setTCPRecvTimeout(size_t timeout);
  247. private:
  248. AuthSrvImpl* impl_;
  249. isc::asiolink::SimpleCallback* checkin_;
  250. isc::asiodns::DNSLookup* dns_lookup_;
  251. isc::asiodns::DNSAnswer* dns_answer_;
  252. isc::asiodns::DNSServiceBase* dnss_;
  253. };
  254. #endif // AUTH_SRV_H
  255. // Local Variables:
  256. // mode: c++
  257. // End: