ctrl_dhcp6_srv.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // Copyright (C) 2012-2015 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 CTRL_DHCPV6_SRV_H
  15. #define CTRL_DHCPV6_SRV_H
  16. #include <asiolink/asiolink.h>
  17. #include <cc/data.h>
  18. #include <cc/command_interpreter.h>
  19. #include <dhcpsrv/timer_mgr.h>
  20. #include <dhcp6/dhcp6_srv.h>
  21. namespace isc {
  22. namespace dhcp {
  23. /// @brief Controlled version of the DHCPv6 server
  24. ///
  25. /// This is a class that is responsible for DHCPv6 server being controllable,
  26. /// by reading configuration file from disk.
  27. class ControlledDhcpv6Srv : public isc::dhcp::Dhcpv6Srv {
  28. public:
  29. /// @brief Constructor
  30. ///
  31. /// @param port UDP port to be opened for DHCP traffic
  32. ControlledDhcpv6Srv(uint16_t port = DHCP6_SERVER_PORT);
  33. /// @brief Destructor.
  34. virtual ~ControlledDhcpv6Srv();
  35. /// @brief Initializes the server.
  36. ///
  37. /// Depending on the configuration backend, it establishes msgq session,
  38. /// reads the JSON file from disk or may perform any other setup
  39. /// operation. For specific details, see actual implementation in
  40. /// *_backend.cc
  41. ///
  42. /// This method may throw if initialization fails. Exception types may be
  43. /// specific to used configuration backend.
  44. void init(const std::string& config_file);
  45. /// @brief Performs cleanup, immediately before termination
  46. ///
  47. /// This method performs final clean up, just before the Dhcpv6Srv object
  48. /// is destroyed. Currently it is a no-op.
  49. void cleanup();
  50. /// @brief Initiates shutdown procedure for the whole DHCPv6 server.
  51. void shutdown();
  52. /// @brief command processor
  53. ///
  54. /// This method is uniform for all config backends. It processes received
  55. /// command (as a string + JSON arguments). Internally, it's just a
  56. /// wrapper that calls process*Command() methods and catches exceptions
  57. /// in them.
  58. ///
  59. /// Currently supported commands are:
  60. /// - shutdown
  61. /// - libreload
  62. /// - config-reload
  63. ///
  64. /// @note It never throws.
  65. ///
  66. /// @param command Text representation of the command (e.g. "shutdown")
  67. /// @param args Optional parameters
  68. ///
  69. /// @return status of the command
  70. static isc::data::ConstElementPtr
  71. processCommand(const std::string& command, isc::data::ConstElementPtr args);
  72. /// @brief configuration processor
  73. ///
  74. /// This is a method for handling incoming configuration updates.
  75. /// This method should be called by all configuration backends when the
  76. /// server is starting up or when configuration has changed.
  77. ///
  78. /// As pointer to this method is used a callback in ASIO used in
  79. /// ModuleCCSession, it has to be static.
  80. ///
  81. /// @param new_config textual representation of the new configuration
  82. ///
  83. /// @return status of the config update
  84. static isc::data::ConstElementPtr
  85. processConfig(isc::data::ConstElementPtr new_config);
  86. /// @brief returns pointer to the sole instance of Dhcpv6Srv
  87. ///
  88. /// @return server instance (may return NULL, if called before server is spawned)
  89. static ControlledDhcpv6Srv* getInstance() {
  90. return (server_);
  91. }
  92. private:
  93. /// @brief Callback that will be called from iface_mgr when data
  94. /// is received over control socket.
  95. ///
  96. /// This static callback method is called from IfaceMgr::receive6() method,
  97. /// when there is a new command or configuration sent over control socket
  98. /// (that was sent from some yet unspecified sender).
  99. static void sessionReader(void);
  100. /// @brief handler for processing 'shutdown' command
  101. ///
  102. /// This handler processes shutdown command, which initializes shutdown
  103. /// procedure.
  104. /// @param command (parameter ignored)
  105. /// @param args (parameter ignored)
  106. ///
  107. /// @return status of the command
  108. isc::data::ConstElementPtr
  109. commandShutdownHandler(const std::string& command,
  110. isc::data::ConstElementPtr args);
  111. /// @brief handler for processing 'libreload' command
  112. ///
  113. /// This handler processes libreload command, which unloads all hook
  114. /// libraries and reloads them.
  115. ///
  116. /// @param command (parameter ignored)
  117. /// @param args (parameter ignored)
  118. ///
  119. /// @return status of the command
  120. isc::data::ConstElementPtr
  121. commandLibReloadHandler(const std::string& command,
  122. isc::data::ConstElementPtr args);
  123. /// @brief handler for processing 'config-reload' command
  124. ///
  125. /// This handler processes config-reload command, which processes
  126. /// configuration specified in args parameter.
  127. ///
  128. /// @param command (parameter ignored)
  129. /// @param args configuration to be processed
  130. ///
  131. /// @return status of the command
  132. isc::data::ConstElementPtr
  133. commandConfigReloadHandler(const std::string& command,
  134. isc::data::ConstElementPtr args);
  135. /// @brief Static pointer to the sole instance of the DHCP server.
  136. ///
  137. /// This is required for config and command handlers to gain access to
  138. /// the server. Some of them need to be static methods.
  139. static ControlledDhcpv6Srv* server_;
  140. /// @brief IOService object, used for all ASIO operations.
  141. isc::asiolink::IOService io_service_;
  142. /// @brief Instance of the @c TimerMgr.
  143. ///
  144. /// Shared pointer to the instance of timer @c TimerMgr is held here to
  145. /// make sure that the @c TimerMgr outlives instance of this class.
  146. TimerMgrPtr timer_mgr_;
  147. };
  148. }; // namespace isc::dhcp
  149. }; // namespace isc
  150. #endif