ctrl_dhcp6_srv.h 5.9 KB

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