dhcp4_hooks.dox 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. // Copyright (C) 2013-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. /**
  15. @page dhcpv4Hooks The Hooks API for the DHCPv4 Server
  16. @section dhcpv4HooksIntroduction Introduction
  17. Kea features an API (the "Hooks" API) that allows user-written code to
  18. be integrated into Kea and called at specific points in its processing.
  19. An overview of the API and a tutorial for writing such code can be found in
  20. the @ref hooksdgDevelopersGuide. Information for Kea maintainers can be
  21. found in the @ref hooksComponentDeveloperGuide.
  22. This manual is more specialized and is aimed at developers of hook
  23. code for the DHCPv4 server. It describes each hook point, what the callouts
  24. attached to the hook are able to do, and the arguments passed to the
  25. callouts. Each entry in this manual has the following information:
  26. - Name of the hook point.
  27. - Arguments for the callout. As well as the argument name and data type, the
  28. information includes the direction, which can be one of:
  29. - @b in - the server passes values to the callout but ignored any data
  30. returned.
  31. - @b out - the callout is expected to set this value.
  32. - <b>in/out</b> - the server passes a value to the callout and uses whatever
  33. value the callout sends back. Note that the callout may choose not to
  34. do any modification, in which case the server will use whatever value
  35. it sent to the callout.
  36. - Description of the hook. This explains where in the processing the hook
  37. is located, the possible actions a callout attached to this hook could take,
  38. and a description of the data passed to the callouts.
  39. - Skip flag action: the action taken by the server if a callout chooses to set
  40. the "skip" flag.
  41. @section dhcpv4HooksHookPoints Hooks in the DHCPv4 Server
  42. The following list is ordered by appearance of specific hook points during
  43. packet processing. Hook points that are not specific to packet processing
  44. (e.g. lease expiration) will be added to the end of this list.
  45. @subsection dhcpv4HooksBuffer4Receive buffer4_receive
  46. - @b Arguments:
  47. - name: @b query4, type: isc::dhcp::Pkt4Ptr, direction: <b>in/out</b>
  48. - @b Description: this callout is executed when the server has received a
  49. buffer containing a DHCPv4 message, but the message hasn't yet been parsed.
  50. The sole argument "query4" contains a pointer to the isc::dhcp::Pkt4
  51. object, which contains the source and destination address of the
  52. received packet, the interface over which the packet has been received, and
  53. a raw buffer, stored in the data_ field, containing the DHCPv4 message
  54. in the wire format. None of the packet fields (op_, hlen_, chaddr_, etc.)
  55. are set yet. Callouts installed on this hook point can modify the data
  56. in the received buffer. The server will parse the buffer afterwards.
  57. - <b>Skip flag action</b>: If any callout sets the skip flag, the server will
  58. skip the buffer parsing. In this case there is an expectation that
  59. the callout will parse the options carried in the buffer, create
  60. @c isc::dhcp::Option objects (or derived) and add them to the "query4"
  61. object using the @c isc::dhcp::Pkt4::addOption.
  62. Otherwise the server will find out that some mandatory options are
  63. missing (e.g. DHCP Message Type) and will drop the message. If you
  64. want to have the capability to drop a message, it is better to use
  65. the skip flag in the "pkt4_receive" callout.
  66. @subsection dhcpv4HooksPkt4Receive pkt4_receive
  67. - @b Arguments:
  68. - name: @b query4, type: isc::dhcp::Pkt4Ptr, direction: <b>in/out</b>
  69. - @b Description: this callout is executed when an incoming DHCPv4
  70. packet is received and its content has been parsed. The sole
  71. argument "query4" contains a pointer to an isc::dhcp::Pkt4 object
  72. that contains all information regarding incoming packet, including
  73. its source and destination addresses, interface over which it was
  74. received, a list of all options present within and the relay
  75. information. All fields of the Pkt4 object can be modified at this
  76. time. By the time this hook is reached, the contents of the data_
  77. field has been already parsed and stored in other fields. Therefore,
  78. the modification in the data_ field has no effect.
  79. - <b>Skip flag action</b>: If any callout sets the skip flag, the server will
  80. drop the packet and start processing the next one. The reason for the drop
  81. will be logged if logging is set to the appropriate debug level.
  82. @subsection dhcpv4HooksSubnet4Select subnet4_select
  83. - @b Arguments:
  84. - name: @b query4, type: isc::dhcp::Pkt4Ptr, direction: <b>in/out</b>
  85. - name: @b subnet4, type: isc::dhcp::Subnet4Ptr, direction: <b>in/out</b>
  86. - name: @b subnet4collection, type: const isc::dhcp::Subnet4Collection *,
  87. direction: <b>in</b>
  88. - @b Description: this callout is executed when a subnet is being
  89. selected for the incoming packet. All parameters and addresses
  90. will be assigned from that subnet. A callout can select a
  91. different subnet if it wishes so. The list of all subnets currently
  92. configured are provided as "subnet4collection". The list itself must
  93. not be modified.
  94. - <b>Skip flag action</b>: If any callout, installed on "subnet4_select",
  95. sets the skip flag, the server will not select any subnet. Packet processing
  96. will continue, but will be severely limited.
  97. @subsection dhcpv4HooksLeaseSelect lease4_select
  98. - @b Arguments:
  99. - name: @b subnet4, type: isc::dhcp::Subnet4Ptr, direction: <b>in</b>
  100. - name: @b fake_allocation, type: bool, direction: <b>in</b>
  101. - name: @b lease4, type: isc::dhcp::Lease4Ptr, direction: <b>in/out</b>
  102. - @b Description: this callout is executed after the server engine
  103. has selected a lease for the client's request, but before the lease has
  104. been inserted into the database. Any modifications made to the
  105. "lease4" object will affect the lease's record in the database.
  106. The callout should sanity check all modifications as the server will
  107. use that data as is, with no further checking.\n\n
  108. The server processes lease requests for DHCPDISCOVER and DHCPREQUEST in a
  109. very similar way. The only major difference is that for DHCPDISCOVER
  110. the lease is only selected, but not inserted into the database. The callouts
  111. may distinguish between DHCPDISCOVER and DHCPREQUEST by checking the
  112. value of the "fake_allocation" flag: a value of true indicates that the
  113. lease won't be inserted into the database (DHCPDISCOVER case), a value of
  114. false indicates that it will (DHCPREQUEST case).
  115. - <b>Skip flag action</b>: If any callout installed on "lease4_select"
  116. sets the skip flag, the server will not assign any lease and the callouts
  117. become responsible for the lease assignment. If the callouts fail to provide
  118. a lease, the packet processing will continue, but client will not get
  119. an address.
  120. @subsection dhcpv4HooksLeaseRenew lease4_renew
  121. - @b Arguments:
  122. - name: @b subnet4, type: isc::dhcp::Subnet4Ptr, direction: <b>in</b>
  123. - name: @b clientid, type: isc::dhcp::ClientId, direction: <b>in</b>
  124. - name: @b hwaddr, type: isc::dhcp::HWAddr, direction: <b>in</b>
  125. - name: @b lease4, type: isc::dhcp::Lease4Ptr, direction: <b>in/out</b>
  126. - @b Description: this callout is executed when the server engine
  127. is about to renew a lease, as a result of receiving DHCPREQUEST/Renewing
  128. packet. The "lease4" argument points to @c isc::dhcp::Lease4 object that
  129. contains the updated values. Callout can modify those values. Care should
  130. be taken as the server will attempt to update the lease in the database
  131. without any additional checks.
  132. - <b>Skip flag action</b>: If any callout installed on "lease4_renew"
  133. sets the skip flag, the server will not update the lease in the
  134. database and will continue using the old values instead.
  135. @subsection dhcpv4HooksLeaseRelease lease4_release
  136. - @b Arguments:
  137. - name: @b query4, type: isc::dhcp::Pkt4Ptr, direction: <b>in</b>
  138. - name: @b lease4, type: isc::dhcp::Lease4Ptr, direction: <b>in</b>
  139. - @b Description: this callout is executed when the server engine
  140. is about to release a lease, as a result of receiving DHCPRELEASE packet.
  141. The "lease4" argument points to @c Lease4 object that contains the lease to
  142. be released. It doesn't make sense to modify it at this time.
  143. - <b>Skip flag action</b>: If any callout installed on "lease4_release"
  144. sets the skip flag, the server will not delete the lease. It will be
  145. kept in the database and will go through the regular expiration/reuse
  146. process.
  147. @subsection dhcpv4HooksPkt4Send pkt4_send
  148. - @b Arguments:
  149. - name: @b response4, type: isc::dhcp::Pkt4Ptr, direction: <b>in/out</b>
  150. - @b Description: this callout is executed when server's response
  151. is about to be sent back to the client. The sole argument "response4"
  152. contains a pointer to an isc::dhcp::Pkt4 object carrying the
  153. packet, with source and destination addresses set, interface over which
  154. it will be sent, and a list of all options and relay information. All fields
  155. of the @c Pkt4 object can be modified at this time, except @c buffer_out_.
  156. (This is scratch space used for constructing the packet after all
  157. pkt4_send callouts are complete, so any changes to that field will
  158. be overwritten.)
  159. - <b>Skip flag action</b>: if any callout sets the skip flag, the server
  160. will not construct the raw buffer. The expectation is that if the callout
  161. set skip flag, it is responsible for constructing raw form on its own.
  162. Otherwise the output packet will be sent with zero length.
  163. @subsection dhcpv4HooksBuffer4Send buffer4_send
  164. - @b Arguments:
  165. - name: @b response4, type: isc::dhcp::Pkt4Ptr, direction: <b>in/out</b>
  166. - @b Description: this callout is executed when server's response
  167. is about to be sent back to the client. The sole argument "response4"
  168. contains a pointer to an @c isc::dhcp::Pkt4 object that contains the
  169. packet, with source and destination addresses set, interface over which
  170. it will be sent, and a list of all options and relay information. The raw
  171. on-wire form is already prepared in @c buffer_out_ (see
  172. @c isc::dhcp::Pkt4::getBuffer())
  173. Callouts should not modify the packet fields or options contents at this
  174. time, because they were already used to construct on-wire buffer. Their
  175. modification would have no effect.
  176. - <b>Skip flag action</b>: if any callout sets the skip flag, the server
  177. will drop this response packet. However, the original request packet
  178. from a client was processed, so server's state most likely has changed
  179. (e.g. lease was allocated). Setting this flag merely stops the change
  180. being communicated to the client.
  181. @subsection dhcpv4HooksLease4Expire lease4_expire
  182. - @b Arguments:
  183. - name: @b lease4, type: isc::dhcp::Lease4Ptr, direction: <b>in/out</b>
  184. - name: @b remove_lease, type: bool, direction: <b>in</b>
  185. - @b Description: this callout is executed for each expired lease when
  186. the server performs reclamation of the expired leases. During this
  187. process the server executes "lease4_expire" callout, removes the DNS
  188. records associated with this lease and finally removes the lease from
  189. the database or updates its status to "expired-reclaimed". The "lease4"
  190. argument contains the pointer to the lease being reclaimed. The second
  191. argument "remove_lease" indicates if the reclaimed leases should be
  192. removed from the lease database (if true), or their state should be
  193. set to "expired-reclaimed" in the lease database. This argument
  194. is only used by the callout if it takes responsibility for the lease
  195. reclamation, i.e. it sets the "skip" flag to "true". The "remove_lease"
  196. argument is set to "true" if the "flush-reclaimed-timer-wait-time" is
  197. set to 0 in the server configuration file.
  198. - <b>Skip flag action</b>: if the callout sets the skip flag, the server
  199. will assume that the callout has fully reclaimed the lease, i.e.
  200. performed the DNS update and updated the lease in the database. The
  201. server will not perform any further actions on the lease for which the
  202. skip flag has been set. It is important to note that if the callout
  203. sets this flag but fails to reclaim the lease in the database, the
  204. reclamation routine will repeatedly process this lease in subsequent
  205. runs. Therefore, the implementors of this callout must make sure that
  206. skip flag is only set when the lease has been actually reclaimed in the
  207. database by the callout.
  208. */