02-dhcp.dox 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /**
  2. * @page dhcpv4 DHCPv4 Server Component
  3. *
  4. * BIND10 offers DHCPv4 server implementation. It is implemented as
  5. * b10-dhcp4 component. Its primary code is located in
  6. * isc::dhcp::Dhcpv4Srv class. It uses \ref libdhcp extensively,
  7. * especially isc::dhcp::Pkt4, isc::dhcp::Option and
  8. * isc::dhcp::IfaceMgr classes. Currently this code offers skeleton
  9. * functionality, i.e. it is able to receive and process incoming
  10. * requests and trasmit responses. However, it does not have database
  11. * management, so it returns only one, hardcoded lease to whoever asks
  12. * for it.
  13. *
  14. * DHCPv4 server component does not support direct traffic (relayed
  15. * only), as support for transmission to hosts without IPv4 address
  16. * assigned is not implemented in IfaceMgr yet.
  17. *
  18. * DHCPv4 server component does not use BIND10 logging yet.
  19. *
  20. * @section dhcpv4Session BIND10 message queue integration
  21. *
  22. * DHCPv4 server component is now integrated with BIND10 message queue.
  23. * The integration is performed by establishSession() and disconnectSession()
  24. * functions in isc::dhcp::ControlledDhcpv4Srv class. main() method deifined
  25. * in the src/bin/dhcp4/main.cc file instantiates isc::dhcp::ControlledDhcpv4Srv
  26. * class that establishes connection with msgq and install necessary handlers
  27. * for receiving commands and configuration updates. It is derived from
  28. * a base isc::dhcp::Dhcpv4Srv class that implements DHCPv4 server functionality,
  29. * without any controlling mechanisms.
  30. *
  31. * ControlledDhcpv4Srv instantiates several components to make management
  32. * session possible. In particular, isc::cc::Session cc_session
  33. * object uses ASIO for establishing connection. It registers its socket
  34. * in isc::asiolink::IOService io_service object. Typically, other components
  35. * (e.g. auth or resolver) that use ASIO for their communication, register their
  36. * other sockets in the
  37. * same io_service and then just call io_service.run() method that does
  38. * not return, until one of the callback decides that it is time to shut down
  39. * the whole component cal calls io_service.stop(). DHCPv4 works in a
  40. * different way. It does receive messages using select()
  41. * (see isc::dhcp::IfaceMgr::receive4()), which is incompatible with ASIO.
  42. * To solve this problem, socket descriptor is extracted from cc_session
  43. * object and is passed to IfaceMgr by using isc::dhcp::IfaceMgr::set_session_socket().
  44. * IfaceMgr then uses this socket in its select() call. If there is some
  45. * data to be read, it calls registered callback that is supposed to
  46. * read and process incoming data.
  47. *
  48. * This somewhat complicated approach is needed for a simple reason. In
  49. * embedded deployments there will be no message queue. Not referring directly
  50. * to anything related to message queue in isc::dhcp::Dhcpv4Srv and
  51. * isc::dhcp::IfaceMgr classes brings in two benefits. First, the can
  52. * be used with and without message queue. Second benefit is related to the
  53. * first one: \ref libdhcp is supposed to be simple and robust and not require
  54. * many dependencies. One notable example of a use case that benefits from
  55. * this approach is a perfdhcp tool. Finally, the idea is that it should be
  56. * possible to instantiate Dhcpv4Srv object directly, thus getting a server
  57. * that does not support msgq. That is useful for embedded environments.
  58. * It may also be useful in validation.
  59. *
  60. * @page dhcpv6 DHCPv6 Server Component
  61. *
  62. * BIND10 offers DHCPv6 server implementation. It is implemented as
  63. * b10-dhcp6 component. Its primary code is located in
  64. * isc::dhcp::Dhcpv6Srv class. It uses \ref libdhcp extensively,
  65. * especially lib::dhcp::Pkt6, isc::dhcp::Option and
  66. * isc::dhcp::IfaceMgr classes. Currently this code offers skeleton
  67. * functionality, i.e. it is able to receive and process incoming
  68. * requests and trasmit responses. However, it does not have database
  69. * management, so it returns only one, hardcoded lease to whoever asks
  70. * for it.
  71. *
  72. * DHCPv6 server component does not support relayed traffic yet, as
  73. * support for relay decapsulation is not implemented yet.
  74. *
  75. * DHCPv6 server component does not listen to BIND10 message queue.
  76. *
  77. * DHCPv6 server component does not use BIND10 logging yet.
  78. *
  79. * DHCPv6 server component is not integrated with boss yet.
  80. *
  81. * @page libdhcp libdhcp++
  82. *
  83. * @section libdhcpIntro Libdhcp++ Library Introduction
  84. *
  85. * libdhcp++ is an all-purpose DHCP-manipulation library, written in
  86. * C++. It offers packet parsing and assembly, DHCPv4 and DHCPv6
  87. * options parsing and ssembly, interface detection (currently on
  88. * Linux systems only) and socket operations. Following classes are
  89. * implemented:
  90. *
  91. * - isc::dhcp::Pkt4 - represents DHCPv4 packet.
  92. * - isc::dhcp::Pkt6 - represents DHCPv6 packet.
  93. *
  94. * There are two pointer types defined: Pkt4Ptr and Pkt6Ptr. They are
  95. * smart pointer and are using boost::shared_ptr. There are not const
  96. * versions defined, as we assume that hooks can modify any aspect of
  97. * the packet at almost any stage of processing.
  98. *
  99. * Both packets use collection of Option objects to represent DHCPv4
  100. * and DHCPv6 options. The base class -- Option -- can be used to
  101. * represent generic option that contains collection of
  102. * bytes. Depending on if the option is instantiated as v4 or v6
  103. * option, it will adjust its header (DHCPv4 options use 1 octet for
  104. * type and 1 octet for length, while DHCPv6 options use 2 bytes for
  105. * each).
  106. *
  107. * There are many specialized classes that are intended to handle options with
  108. * specific content:
  109. * - isc::dhcp::Option4AddrLst -- DHCPv4 option, contains one or more IPv4 addresses;
  110. * - isc::dhcp::Option6AddrLst -- DHCPv6 option, contains one or more IPv6 addresses;
  111. * - isc::dhcp::Option6IAAddr -- DHCPv6 option, represents IAADDR_OPTION (an option that
  112. * contains IPv6 address with extra parameters);
  113. * - isc::dhcp::Option6IA -- DHCPv6 option used to store IA_NA and its suboptions.
  114. *
  115. * All options can store sub-options (i.e. options that are stored within option
  116. * rather than in a message directly). This functionality is commonly used in
  117. * DHCPv6, but is rarely used in DHCPv4. isc::dhcp::Option::addOption(),
  118. * isc::dhcp::Option::delOption(), isc::dhcp::Option::getOption() can be used
  119. * for that purpose.
  120. *
  121. * @section libdhcpIfaceMgr Interface Manager
  122. *
  123. * Interface Manager (or IfaceMgr) is an abstraction layer about low-level
  124. * network operations. In particlar, it provides information about existing
  125. * network interfaces See isc::dhcp::IfaceMgr::Iface class and
  126. * isc::dhcp::IfaceMgr::detectIfaces() and isc::dhcp::IfaceMgr::getIface().
  127. *
  128. * Currently there is interface detection is implemented in Linux only. There
  129. * are plans to implement such support for other OSes, but they remain low
  130. * priority for now.
  131. *
  132. * Generic parts of the code are isc::dhcp::IfaceMgr class in
  133. * src/lib/dhcp/iface_mgr.cc file. OS-specific code is located in separate
  134. * files, e.g. iface_mgr_linux.cc. Such separation should be maintained when
  135. * additional code will be developed.
  136. *
  137. * For systems that interface detection is not supported on, there is a stub
  138. * mechanism implemented. It assumes that interface name is read from a text
  139. * file. This is a temporary solution and will be removed as soon as proper
  140. * interface detection is implemented. It is not going to be developed further.
  141. * To use this feature, store interfaces.txt file. It uses a simple syntax.
  142. * Each line represents an interface name, followed by IPv4 or IPv6 address
  143. * that follows it. This is usually link-local IPv6 address that the server
  144. * should bind to. In theory this mechanism also supports IPv4, but it was
  145. * never tested. The code currently supports only a single interface defined
  146. * that way.
  147. *
  148. * Another useful methods are dedicated to transmission
  149. * (isc::dhcp::IfaceMgr::send(), 2 overloads) and reception
  150. * (isc::dhcp::IfaceMgr::receive4() and isc::dhcp::IfaceMgr::receive6()).
  151. * Note that receive4() and receive6() methods may return NULL, e.g.
  152. * when timeout is reached or if dhcp daemon receives a signal.
  153. */