dhcp6_srv.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // Copyright (C) 2011 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 DHCPV6_SRV_H
  15. #define DHCPV6_SRV_H
  16. #include <boost/shared_ptr.hpp>
  17. #include <boost/noncopyable.hpp>
  18. #include <dhcp/dhcp6.h>
  19. #include <dhcp/pkt6.h>
  20. #include <dhcp/option.h>
  21. #include <iostream>
  22. namespace isc {
  23. namespace dhcp {
  24. /// @brief DHCPv6 server service.
  25. ///
  26. /// This singleton class represents DHCPv6 server. It contains all
  27. /// top-level methods and routines necessary for server operation.
  28. /// In particular, it instantiates IfaceMgr, loads or generates DUID
  29. /// that is going to be used as server-identifier, receives incoming
  30. /// packets, processes them, manages leases assignment and generates
  31. /// appropriate responses.
  32. class Dhcpv6Srv : public boost::noncopyable {
  33. public:
  34. /// @brief Default constructor.
  35. ///
  36. /// Instantiates necessary services, required to run DHCPv6 server.
  37. /// In particular, creates IfaceMgr that will be responsible for
  38. /// network interaction. Will instantiate lease manager, and load
  39. /// old or create new DUID.
  40. ///
  41. /// @param port port on will all sockets will listen
  42. Dhcpv6Srv(uint16_t port = DHCP6_SERVER_PORT);
  43. /// @brief Destructor. Used during DHCPv6 service shutdown.
  44. virtual ~Dhcpv6Srv();
  45. /// @brief Returns server-intentifier option
  46. ///
  47. /// @return server-id option
  48. boost::shared_ptr<isc::dhcp::Option>
  49. getServerID() { return serverid_; }
  50. /// @brief Main server processing loop.
  51. ///
  52. /// Main server processing loop. Receives incoming packets, verifies
  53. /// their correctness, generates appropriate answer (if needed) and
  54. /// transmits respones.
  55. ///
  56. /// @return true, if being shut down gracefully, fail if experienced
  57. /// critical error.
  58. bool run();
  59. protected:
  60. /// @brief Processes incoming SOLICIT and returns response.
  61. ///
  62. /// Processes received SOLICIT message and verifies that its sender
  63. /// should be served. In particular IA, TA and PD options are populated
  64. /// with to-be assinged addresses, temporary addresses and delegated
  65. /// prefixes, respectively. In the usual 4 message exchange, server is
  66. /// expected to respond with ADVERTISE message. However, if client
  67. /// requests rapid-commit and server supports it, REPLY will be sent
  68. /// instead of ADVERTISE and requested leases will be assigned
  69. /// immediately.
  70. ///
  71. /// @param solicit SOLICIT message received from client
  72. ///
  73. /// @return ADVERTISE, REPLY message or NULL
  74. boost::shared_ptr<Pkt6>
  75. processSolicit(boost::shared_ptr<Pkt6> solicit);
  76. /// @brief Processes incoming REQUEST and returns REPLY response.
  77. ///
  78. /// Processes incoming REQUEST message and verifies that its sender
  79. /// should be served. In particular IA, TA and PD options are populated
  80. /// with assinged addresses, temporary addresses and delegated
  81. /// prefixes, respectively. Uses LeaseMgr to allocate or update existing
  82. /// leases.
  83. ///
  84. /// @param request a message received from client
  85. ///
  86. /// @return REPLY message or NULL
  87. boost::shared_ptr<Pkt6>
  88. processRequest(boost::shared_ptr<Pkt6> request);
  89. /// @brief Stub function that will handle incoming RENEW messages.
  90. ///
  91. /// @param renew message received from client
  92. boost::shared_ptr<Pkt6>
  93. processRenew(boost::shared_ptr<Pkt6> renew);
  94. /// @brief Stub function that will handle incoming REBIND messages.
  95. ///
  96. /// @param rebind message received from client
  97. boost::shared_ptr<Pkt6>
  98. processRebind(boost::shared_ptr<Pkt6> rebind);
  99. /// @brief Stub function that will handle incoming CONFIRM messages.
  100. ///
  101. /// @param confirm message received from client
  102. boost::shared_ptr<Pkt6>
  103. processConfirm(boost::shared_ptr<Pkt6> confirm);
  104. /// @brief Stub function that will handle incoming RELEASE messages.
  105. ///
  106. /// @param release message received from client
  107. boost::shared_ptr<Pkt6>
  108. processRelease(boost::shared_ptr<Pkt6> release);
  109. /// @brief Stub function that will handle incoming DECLINE messages.
  110. ///
  111. /// @param decline message received from client
  112. boost::shared_ptr<Pkt6>
  113. processDecline(boost::shared_ptr<Pkt6> decline);
  114. /// @brief Stub function that will handle incoming INF-REQUEST messages.
  115. ///
  116. /// @param infRequest message received from client
  117. boost::shared_ptr<Pkt6>
  118. processInfRequest(boost::shared_ptr<Pkt6> infRequest);
  119. /// @brief Sets server-identifier.
  120. ///
  121. /// This method attempts to set server-identifier DUID. It loads it
  122. /// from a file. If file load fails, it generates new DUID using
  123. /// interface link-layer addresses (EUI-64) + timestamp (DUID type
  124. /// duid-llt, see RFC3315, section 9.2). If there are no suitable
  125. /// interfaces present, exception it thrown
  126. ///
  127. /// @throws isc::Unexpected Failed to read DUID file and no suitable
  128. /// interfaces for new DUID generation are detected.
  129. void setServerID();
  130. /// server DUID (to be sent in server-identifier option)
  131. boost::shared_ptr<isc::dhcp::Option> serverid_;
  132. /// indicates if shutdown is in progress. Setting it to true will
  133. /// initiate server shutdown procedure.
  134. volatile bool shutdown;
  135. };
  136. }; // namespace isc::dhcp
  137. }; // namespace isc
  138. #endif // DHCP6_SRV_H