dhcp4o6_ipc.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Copyright (C) 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 DHCP4O6_IPC_H
  15. #define DHCP4O6_IPC_H
  16. /// @file dhcp4o6_ipc.h Defines the Dhcp4o6IpcBase class.
  17. /// This file defines the class Kea uses as a base for
  18. /// DHCPv4-over-DHCPv6 communication between servers.
  19. ///
  20. #include <exceptions/exceptions.h>
  21. #include <dhcp/pkt6.h>
  22. #include <boost/noncopyable.hpp>
  23. #include <stdint.h>
  24. namespace isc {
  25. namespace dhcp {
  26. /// @brief Exception thrown when error occurs as a result of use of IPC.
  27. class Dhcp4o6IpcError : public Exception {
  28. public:
  29. Dhcp4o6IpcError(const char* file, size_t line, const char* what) :
  30. isc::Exception(file, line, what) { };
  31. };
  32. /// @brief Base class implementing transmission of the DHCPv4 over
  33. /// DHCPv6 messages (RFC 7341) between the Kea servers.
  34. ///
  35. /// When the DHCPv6 server receives the DHCPv4 query message it needs
  36. /// to forward it to the DHCPv4 server for processing. The DHCPv4
  37. /// server processes the message and answers with the DHCPv4 response
  38. /// message to the DHCPv6 server. The server forwards it back to the
  39. /// client. This class implements the communication between the DHCPv4
  40. /// and DHCPv6 servers to allow for transmission of the DHCPv4 query
  41. /// and DHCPv6 response messages.
  42. ///
  43. /// This class creates a socket (when @c open is called) and binds it
  44. /// to a port, depending on the configuration. The port number is
  45. /// explicitly specified in the server configuration. This explicit
  46. /// port value is used directly on the DHCPv6 server side. The DHCPv4
  47. /// server uses the port specified + 1.
  48. ///
  49. /// The DHCPv4 and DHCPv6 servers use distict instances of classes derived
  50. /// from this base class. Each of these instances is used to send and
  51. /// receive messages sent by the other server.
  52. ///
  53. /// In order to make address allocation decisions, the DHCPv4 server
  54. /// requires information about the interface and the source address of
  55. /// the original DHCPv4 query message sent by the client. This
  56. /// information is known by the DHCPv6 server and needs to be conveyed
  57. /// to the DHCPv4 server. The IPC conveys it in the
  58. /// @c ISC_V6_4O6_INTERFACE and @c ISC_V6_4O6_SRC_ADDRESS options
  59. /// within the Vendor Specific Information option, with ISC
  60. /// enterprise id. These options are added by the IPC sender and removed
  61. /// by the IPC receiver.
  62. class Dhcp4o6IpcBase : public boost::noncopyable {
  63. public:
  64. /// @brief Endpoint type: DHCPv4 or DHCPv6 server.
  65. enum EndpointType {
  66. ENDPOINT_TYPE_V4,
  67. ENDPOINT_TYPE_V6
  68. };
  69. protected:
  70. /// @brief Constructor
  71. ///
  72. /// Default constructor
  73. Dhcp4o6IpcBase();
  74. /// @brief Destructor.
  75. virtual ~Dhcp4o6IpcBase();
  76. /// @brief Open communication socket (from base class).
  77. ///
  78. /// @param port Port number to use. The socket is bound to this port
  79. /// if the endpoint type is DHCPv6 server, otherwise the port + 1
  80. /// value is used.
  81. /// @param endpoint_type Endpoint type (DHCPv4 or DHCPv6 server).
  82. ///
  83. /// @return New socket descriptor.
  84. int open(const uint16_t port, const EndpointType& endpoint_type);
  85. public:
  86. /// @brief Open communication socket (for derived classes).
  87. virtual void open() = 0;
  88. /// @brief Close communication socket.
  89. void close();
  90. /// @brief Receive message over IPC.
  91. ///
  92. /// @return a pointer to a DHCPv6 message with interface and remote
  93. /// address set from the IPC message
  94. Pkt6Ptr receive();
  95. /// @brief Send message over IPC.
  96. ///
  97. /// The IPC uses @c ISC_V6_4O6_INTERFACE and @c ISC_V6_4O6_SRC_ADDRESS
  98. /// options conveyed within the Vendor Specific Information option, with
  99. /// ISC enterprise id, to communicate the client remote address and the
  100. /// interface on which the DHCPv4 query was received. These options will
  101. /// be removed by the receiver.
  102. ///
  103. /// @param pkt Pointer to a DHCPv6 message with interface and remote
  104. /// address.
  105. void send(const Pkt6Ptr& pkt);
  106. protected:
  107. /// @brief Port number configured for IPC communication.
  108. uint16_t port_;
  109. /// @brief Socket descriptor.
  110. int socket_fd_;
  111. };
  112. } // namespace isc
  113. } // namespace dhcp
  114. #endif