ctrl_dhcp6_srv.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Copyright (C) 2012 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/session.h>
  19. #include <config/ccsession.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 establishing connection
  26. /// with msqg (receving commands and configuration). This is an extended
  27. /// version of Dhcpv6Srv class that is purely a DHCPv6 server, without
  28. /// external control. ControlledDhcpv6Srv should be used in typical BIND10
  29. /// (i.e. featuring msgq) environment, while Dhcpv6Srv should be used in
  30. /// embedded environments.
  31. ///
  32. /// For detailed explanation or relations between main(), ControlledDhcpv6Srv,
  33. /// Dhcpv6Srv and other classes, see \ref dhcpv6Session.
  34. class ControlledDhcpv6Srv : public isc::dhcp::Dhcpv6Srv {
  35. public:
  36. /// @brief Constructor
  37. ///
  38. /// @param port UDP port to be opened for DHCP traffic
  39. /// @param dbconfig Lease manager database configuration string
  40. ControlledDhcpv6Srv(uint16_t port = DHCP6_SERVER_PORT,
  41. const char* dbconfig = "type=memfile");
  42. /// @brief Destructor.
  43. ~ControlledDhcpv6Srv();
  44. /// @brief Establishes msgq session.
  45. ///
  46. /// Creates session that will be used to receive commands and updated
  47. /// configuration from boss (or indirectly from user via bindctl).
  48. void establishSession();
  49. /// @brief Terminates existing msgq session.
  50. ///
  51. /// This method terminates existing session with msgq. After calling
  52. /// it, no further messages over msgq (commands or configuration updates)
  53. /// may be received.
  54. ///
  55. /// It is ok to call this method when session is disconnected already.
  56. void disconnectSession();
  57. /// @brief Initiates shutdown procedure for the whole DHCPv6 server.
  58. void shutdown();
  59. /// @brief Session callback, processes received commands.
  60. ///
  61. /// @param command Text represenation of the command (e.g. "shutdown")
  62. /// @param args Optional parameters
  63. ///
  64. /// @return status of the command
  65. static isc::data::ConstElementPtr
  66. execDhcpv6ServerCommand(const std::string& command,
  67. isc::data::ConstElementPtr args);
  68. protected:
  69. /// @brief Static pointer to the sole instance of the DHCP server.
  70. ///
  71. /// This is required for config and command handlers to gain access to
  72. /// the server
  73. static ControlledDhcpv6Srv* server_;
  74. /// @brief A callback for handling incoming configuration updates.
  75. ///
  76. /// As pointer to this method is used a callback in ASIO used in
  77. /// ModuleCCSession, it has to be static.
  78. ///
  79. /// @param new_config textual representation of the new configuration
  80. ///
  81. /// @return status of the config update
  82. static isc::data::ConstElementPtr
  83. dhcp6ConfigHandler(isc::data::ConstElementPtr new_config);
  84. /// @brief A callback for handling incoming commands.
  85. ///
  86. /// @param command textual representation of the command
  87. /// @param args parameters of the command
  88. ///
  89. /// @return status of the processed command
  90. static isc::data::ConstElementPtr
  91. dhcp6CommandHandler(const std::string& command, isc::data::ConstElementPtr args);
  92. /// @brief Callback that will be called from iface_mgr when command/config arrives.
  93. ///
  94. /// This static callback method is called from IfaceMgr::receive6() method,
  95. /// when there is a new command or configuration sent over msgq.
  96. static void sessionReader(void);
  97. /// @brief IOService object, used for all ASIO operations.
  98. isc::asiolink::IOService io_service_;
  99. /// @brief Helper session object that represents raw connection to msgq.
  100. isc::cc::Session* cc_session_;
  101. /// @brief Session that receives configuation and commands
  102. isc::config::ModuleCCSession* config_session_;
  103. };
  104. }; // namespace isc::dhcp
  105. }; // namespace isc
  106. #endif