dhcp4_hooks.dox 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. - Next step status: the action taken by the server when a callout chooses to set
  40. status to specified value. Actions not listed explicitly are not supported.
  41. If a callout sets status to unsupported value, this specific value will be
  42. ignored and treated as if the status was CONTINUE.
  43. @section dhcpv4HooksHookPoints Hooks in the DHCPv4 Server
  44. The following list is ordered by appearance of specific hook points during
  45. packet processing. Hook points that are not specific to packet processing
  46. (e.g. lease expiration) will be added to the end of this list.
  47. @subsection dhcpv4HooksBuffer4Receive buffer4_receive
  48. - @b Arguments:
  49. - name: @b query4, type: isc::dhcp::Pkt4Ptr, direction: <b>in/out</b>
  50. - @b Description: this callout is executed when the server has received a
  51. buffer containing a DHCPv4 message, but the message hasn't yet been parsed.
  52. The sole argument "query4" contains a pointer to the isc::dhcp::Pkt4
  53. object, which contains the source and destination address of the
  54. received packet, the interface over which the packet has been received, and
  55. a raw buffer, stored in the data_ field, containing the DHCPv4 message
  56. in the wire format. None of the packet fields (op_, hlen_, chaddr_, etc.)
  57. are set yet. Callouts installed on this hook point can modify the data
  58. in the received buffer. The server will parse the buffer afterwards.
  59. - <b>Next step status</b>: If any callout sets the status to SKIP, the server will
  60. skip the buffer parsing. In this case there is an expectation that
  61. the callout will parse the options carried in the buffer, create
  62. @c isc::dhcp::Option objects (or derived) and add them to the "query4"
  63. object using the @c isc::dhcp::Pkt4::addOption.
  64. Otherwise the server will find out that some mandatory options are
  65. missing (e.g. DHCP Message Type) and will drop the message. If you
  66. want to have the capability to drop a message, it is better to use
  67. the skip flag in the "pkt4_receive" callout.
  68. @subsection dhcpv4HooksPkt4Receive pkt4_receive
  69. - @b Arguments:
  70. - name: @b query4, type: isc::dhcp::Pkt4Ptr, direction: <b>in/out</b>
  71. - @b Description: this callout is executed when an incoming DHCPv4
  72. packet is received and its content has been parsed. The sole
  73. argument "query4" contains a pointer to an isc::dhcp::Pkt4 object
  74. that contains all information regarding incoming packet, including
  75. its source and destination addresses, interface over which it was
  76. received, a list of all options present within and the relay
  77. information. All fields of the Pkt4 object can be modified at this
  78. time. By the time this hook is reached, the contents of the data_
  79. field has been already parsed and stored in other fields. Therefore,
  80. the modification in the data_ field has no effect.
  81. - <b>Next step status</b>: If any callout sets the status to SKIP, the server will
  82. drop the packet and start processing the next one. The reason for the drop
  83. will be logged if logging is set to the appropriate debug level.
  84. @subsection dhcpv4HooksSubnet4Select subnet4_select
  85. - @b Arguments:
  86. - name: @b query4, type: isc::dhcp::Pkt4Ptr, direction: <b>in/out</b>
  87. - name: @b subnet4, type: isc::dhcp::Subnet4Ptr, direction: <b>in/out</b>
  88. - name: @b subnet4collection, type: const isc::dhcp::Subnet4Collection *,
  89. direction: <b>in</b>
  90. - @b Description: this callout is executed when a subnet is being
  91. selected for the incoming packet. All parameters and addresses
  92. will be assigned from that subnet. A callout can select a
  93. different subnet if it wishes so. The list of all subnets currently
  94. configured are provided as "subnet4collection". The list itself must
  95. not be modified.
  96. - <b>Next step status</b>: If any callout installed on the "subnet4_select" hook
  97. sets the next step status to SKIP, the server will not select any subnet.
  98. Packet processing will continue, but will be severely limited.
  99. @subsection dhcpv4HooksLeaseSelect lease4_select
  100. - @b Arguments:
  101. - name: @b subnet4, type: isc::dhcp::Subnet4Ptr, direction: <b>in</b>
  102. - name: @b fake_allocation, type: bool, direction: <b>in</b>
  103. - name: @b lease4, type: isc::dhcp::Lease4Ptr, direction: <b>in/out</b>
  104. - @b Description: this callout is executed after the server engine
  105. has selected a lease for the client's request, but before the lease has
  106. been inserted into the database. Any modifications made to the
  107. "lease4" object will affect the lease's record in the database.
  108. The callout should sanity check all modifications as the server will
  109. use that data as is, with no further checking.\n\n
  110. The server processes lease requests for DHCPDISCOVER and DHCPREQUEST in a
  111. very similar way. The only major difference is that for DHCPDISCOVER
  112. the lease is only selected, but not inserted into the database. The callouts
  113. may distinguish between DHCPDISCOVER and DHCPREQUEST by checking the
  114. value of the "fake_allocation" flag: a value of true indicates that the
  115. lease won't be inserted into the database (DHCPDISCOVER case), a value of
  116. false indicates that it will (DHCPREQUEST case).
  117. - <b>Next step status</b>: If any callout installed on the "lease4_select" hook
  118. sets the next step action to SKIP, the server will not assign any lease and
  119. the callouts become responsible for the lease assignment. If the callouts
  120. fail to provide a lease, the packet processing will continue, but client
  121. will not get an address.
  122. @subsection dhcpv4HooksLeaseRenew lease4_renew
  123. - @b Arguments:
  124. - name: @b subnet4, type: isc::dhcp::Subnet4Ptr, direction: <b>in</b>
  125. - name: @b clientid, type: isc::dhcp::ClientId, direction: <b>in</b>
  126. - name: @b hwaddr, type: isc::dhcp::HWAddr, direction: <b>in</b>
  127. - name: @b lease4, type: isc::dhcp::Lease4Ptr, direction: <b>in/out</b>
  128. - @b Description: this callout is executed when the server engine
  129. is about to renew a lease, as a result of receiving DHCPREQUEST/Renewing
  130. packet. The "lease4" argument points to @c isc::dhcp::Lease4 object that
  131. contains the updated values. Callout can modify those values. Care should
  132. be taken as the server will attempt to update the lease in the database
  133. without any additional checks.
  134. - <b>Next step status</b>: If any callout installed on the "lease4_renew" hook
  135. sets the next step action to SKIP, the server will not update the lease in the
  136. database and will continue using the old values instead.
  137. @subsection dhcpv4HooksLeaseRelease lease4_release
  138. - @b Arguments:
  139. - name: @b query4, type: isc::dhcp::Pkt4Ptr, direction: <b>in</b>
  140. - name: @b lease4, type: isc::dhcp::Lease4Ptr, direction: <b>in</b>
  141. - @b Description: this callout is executed when the server engine
  142. is about to release a lease, as a result of receiving DHCPRELEASE packet.
  143. The "lease4" argument points to @c Lease4 object that contains the lease to
  144. be released. It doesn't make sense to modify it at this time.
  145. - <b>Next step status</b>: If any callout installed on the "lease4_release" hook
  146. sets the next step action to SKIP, the server will not delete the lease.
  147. It will be kept in the database and will go through the regular expiration/reuse
  148. process.
  149. @subsection dhcpv4HooksLeaseDecline lease4_decline
  150. - @b Arguments:
  151. - name: @b query4, type: isc::dhcp::Pkt4Ptr, direction: <b>in</b>
  152. - name: @b lease4, type: isc::dhcp::Lease4Ptr, direction: <b>in</b>
  153. - @b Description: this callout is executed when the server engine
  154. is about to decline a lease, as a result of receiving DHCPDECLINE packet.
  155. The server already sanity checked it (the packet is sane, attempts to decline
  156. a lease that is valid and belongs to the client that requests its decline).
  157. The "lease4" argument points to @c Lease4 object that contains the lease to
  158. be released. Note this lease still contains client identifying information.
  159. That data is provided for informational purposes and it doesn't make sense to
  160. modify it at this time. All the information will be removed from the lease
  161. before it is updated in the database.
  162. - <b>Next step status</b>: If any callout installed on the "lease4_release" hook
  163. sets the next step action to DROP, the server will not decline the lease.
  164. Care should be taken when setting this status. The lease will be kept in
  165. the database as it is and the client will incorrectly assume that the server
  166. marked this lease as unavailable. If the client restarts its configuration,
  167. it will get the same (not declined) lease as a result.
  168. @subsection dhcpv4HooksPkt4Send pkt4_send
  169. - @b Arguments:
  170. - name: @b response4, type: isc::dhcp::Pkt4Ptr, direction: <b>in/out</b>
  171. - @b Description: this callout is executed when server's response
  172. is about to be sent back to the client. The sole argument "response4"
  173. contains a pointer to an isc::dhcp::Pkt4 object carrying the
  174. packet, with source and destination addresses set, interface over which
  175. it will be sent, and a list of all options and relay information. All fields
  176. of the @c Pkt4 object can be modified at this time, except @c buffer_out_.
  177. (This is scratch space used for constructing the packet after all
  178. pkt4_send callouts are complete, so any changes to that field will
  179. be overwritten.)
  180. - <b>Next step action</b>: if any callout installed on the "pkt4_send" hook
  181. sets the next step action to SKIP, the server will not construct the raw
  182. buffer. The expectation is that if the callout set skip flag, it is
  183. responsible for constructing raw form on its own. Otherwise the output
  184. packet will be sent with zero length.
  185. @subsection dhcpv4HooksBuffer4Send buffer4_send
  186. - @b Arguments:
  187. - name: @b response4, type: isc::dhcp::Pkt4Ptr, direction: <b>in/out</b>
  188. - @b Description: this callout is executed when server's response
  189. is about to be sent back to the client. The sole argument "response4"
  190. contains a pointer to an @c isc::dhcp::Pkt4 object that contains the
  191. packet, with source and destination addresses set, interface over which
  192. it will be sent, and a list of all options and relay information. The raw
  193. on-wire form is already prepared in @c buffer_out_ (see
  194. @c isc::dhcp::Pkt4::getBuffer())
  195. Callouts should not modify the packet fields or options contents at this
  196. time, because they were already used to construct on-wire buffer. Their
  197. modification would have no effect.
  198. - <b>Next step status</b>: if any callout sets the next step action to SKIP,
  199. the server will drop this response packet. However, the original request
  200. packet from a client was processed, so server's state most likely has changed
  201. (e.g. lease was allocated). Setting this flag merely stops the change
  202. being communicated to the client.
  203. @subsection dhcpv4HooksLease4Expire lease4_expire
  204. - @b Arguments:
  205. - name: @b lease4, type: isc::dhcp::Lease4Ptr, direction: <b>in/out</b>
  206. - name: @b remove_lease, type: bool, direction: <b>in</b>
  207. - @b Description: this callout is executed for each expired lease when
  208. the server performs reclamation of the expired leases. During this
  209. process the server executes "lease4_expire" callout, removes the DNS
  210. records associated with this lease and finally removes the lease from
  211. the database or updates its status to "expired-reclaimed". The "lease4"
  212. argument contains the pointer to the lease being reclaimed. The second
  213. argument "remove_lease" indicates if the reclaimed leases should be
  214. removed from the lease database (if true), or their state should be
  215. set to "expired-reclaimed" in the lease database. This argument
  216. is only used by the callout if it takes responsibility for the lease
  217. reclamation, i.e. it sets the "skip" flag to "true". The "remove_lease"
  218. argument is set to "true" if the "flush-reclaimed-timer-wait-time" is
  219. set to 0 in the server configuration file.
  220. - <b>Next step status</b>: if the callout sets the next step action to SKIP,
  221. the server will assume that the callout has fully reclaimed the lease, i.e.
  222. performed the DNS update and updated the lease in the database. The
  223. server will not perform any further actions on the lease for which the
  224. skip flag has been set. It is important to note that if the callout
  225. sets this flag but fails to reclaim the lease in the database, the
  226. reclamation routine will repeatedly process this lease in subsequent
  227. runs. Therefore, the implementors of this callout must make sure that
  228. skip flag is only set when the lease has been actually reclaimed in the
  229. database by the callout.
  230. @subsection dhcpv4HooksLease4Recover lease4_recover
  231. - @b Arguments:
  232. - name: @b lease4, type: isc::dhcp::Lease4Ptr, direction: <b>in</b>
  233. - @b Description: this callout is executed for each declined lease that
  234. has expired and is being recovered. The lease has already been stripped
  235. from any client identifying information when it was put into declined
  236. state. In principle the callouts can modify the lease in this hook,
  237. but it makes little sense. There's no useful data in the lease, except
  238. the IPv4 address (which must not be modified).
  239. - <b>Next step status</b>: if the callout sets the next step action to SKIP,
  240. the server will skip the lease recovery. In other words, it will keep
  241. the lease as is. This is not recommended in general, as the declined
  242. expired leases will remain in the database and their recovery will
  243. be attempted during the next reclaim cycle.
  244. */