dhcp6_hooks.dox 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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 dhcpv6Hooks The Hooks API for the DHCPv6 Server
  16. @section dhcpv6HooksIntroduction 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 DHCPv6 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 dhcpv6HooksHookPoints Hooks in the DHCPv6 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 dhcpv6HooksBuffer6Receive buffer6_receive
  48. - @b Arguments:
  49. - name: @b query6, type: isc::dhcp::Pkt6Ptr, direction: <b>in/out</b>
  50. - @b Description: This callout is executed when an incoming DHCPv6
  51. packet is received and the data stored in a buffer. The sole argument
  52. "query6" contains a pointer to an @c isc::dhcp::Pkt6 object that contains
  53. the received information stored in the data_ field. Basic information
  54. like protocol, source/destination addresses and ports are set, but
  55. the contents of the buffer have not yet been parsed. That means that
  56. the @c options_ field (that will eventually contain a list of objects
  57. representing the received options) is empty, so none of the methods
  58. that operate on it (e.g., getOption()) will work. The primary purpose
  59. of this early call is to offer the ability to modify incoming packets
  60. in their raw form. Unless you need to access to the raw data, it is
  61. usually better to install your callout on the "pkt6_receive" hook point.
  62. - <b>Next step status</b>: If any callout sets the status to SKIP, the
  63. server will assume that the callout parsed the buffer and added the
  64. necessary option objects to the @c options_ field; the server will not
  65. do any parsing. If the callout sets the skip flag but does not parse
  66. the buffer, the server will most probably drop the packet due to
  67. the absence of mandatory options. If you want to drop the packet,
  68. see the description of the skip flag in the "pkt6_receive" hook point.
  69. @subsection dhcpv6HooksPkt6Receive pkt6_receive
  70. - @b Arguments:
  71. - name: @b query6, type: isc::dhcp::Pkt6Ptr, direction: <b>in/out</b>
  72. - @b Description: This callout is executed when an incoming DHCPv6
  73. packet is received and its content is parsed. The sole argument
  74. "query6" contains a pointer to an @c isc::dhcp::Pkt6 object that contains
  75. all information regarding incoming packet, including its source and
  76. destination addresses, the interface over which it was received, a list
  77. of all options present within and relay information. All fields of
  78. the "query6" object can be modified at this time, except data_. (data_
  79. contains the incoming packet as raw buffer. By the time this hook is
  80. reached, that information has already been parsed and is available though
  81. other fields in the Pkt6 object. For this reason, modification of the
  82. @c data_ field would have no effect.)
  83. - <b>Next step status</b>: If any callout sets the status to SKIP, the server will
  84. drop the packet and start processing the next one. The reason for the drop
  85. will be logged if logging is set to the appropriate debug level.
  86. @subsection dhcpv6HooksSubnet6Select subnet6_select
  87. - @b Arguments:
  88. - name: @b query6, type: isc::dhcp::Pkt6Ptr, direction: <b>in/out</b>
  89. - name: @b subnet6, type: isc::dhcp::Subnet6Ptr, direction: <b>in/out</b>
  90. - name: @b subnet6collection, type: const isc::dhcp::Subnet6Collection *, direction: <b>in</b>
  91. - @b Description: This callout is executed when a subnet is being
  92. selected for the incoming packet. All parameters, addresses and
  93. prefixes will be assigned from that subnet. A callout can select a
  94. different subnet if it wishes so, the list of all subnets currently
  95. configured being provided as "subnet6collection". The list itself must
  96. not be modified.
  97. - <b>Next step status</b>: If any callout installed on "subnet6_select"
  98. sets the status to SKIP, the server will not select any subnet. Packet processing
  99. will continue, but will be severely limited.
  100. @subsection dhcpv6HooksLease6Select lease6_select
  101. - @b Arguments:
  102. - name: @b subnet6, type: isc::dhcp::Subnet6Ptr, direction: <b>in</b>
  103. - name: @b fake_allocation, type: bool, direction: <b>in</b>
  104. - name: @b lease6, type: isc::dhcp::Lease6Ptr, direction: <b>in/out</b>
  105. - @b Description: This callout is executed after the server engine
  106. has selected a lease for client's request but before the lease
  107. has been inserted into the database. Any modifications made to the
  108. "lease6" object will affect the lease's record in the database.
  109. The callout should make sure that any modifications are sanity
  110. checked as the server will use that data as is, with no further
  111. checking.\n\n The server processes lease requests for SOLICIT and
  112. REQUEST in a very similar way. The major difference is that
  113. for SOLICIT the lease is only selected; it is not inserted into
  114. the database. The callouts can distinguish between the SOLICIT and
  115. REQUEST by checking the value of the "fake_allocation" flag: a value
  116. of true means that the lease won't be inserted into the database
  117. (SOLICIT case), a value of false means that it will (REQUEST).
  118. - <b>Next step status</b>: If any callout installed on "lease6_select"
  119. sets the status to SKIP, the server will not assign that particular lease.
  120. Packet processing will continue and the client may get other addresses
  121. or prefixes if it requested more than one address and/or prefix.
  122. @subsection dhcpv6HooksLease6Renew lease6_renew
  123. - @b Arguments:
  124. - name: @b query6, type: isc::dhcp::PktPtr, direction: <b>in</b>
  125. - name: @b lease6, type: isc::dhcp::Lease6Ptr, direction: <b>in/out</b>
  126. - name: @b ia_na, type: boost::shared_ptr<Option6IA>, direction: <b>in/out</b>
  127. - @b Description: This callout is executed when the server engine is
  128. about to renew an existing lease. The client's request is provided as
  129. the "query6" argument and the existing lease with the appropriate fields
  130. already modified is given in the "lease6" argument. The final argument,
  131. ia_na, is the IA_NA option that will be sent back to the client.
  132. Callouts installed on the "lease6_renew" may modify the content of
  133. the "lease6" object. Care should be taken however, as that modified
  134. information will be written to the database without any further
  135. checking. \n\n Although the envisaged usage assumes modification of T1,
  136. T2, preferred and valid lifetimes only, other parameters associated
  137. with the lease may be modified as well. The only exception is the @c addr_
  138. field, which must not be modified as it is used by the database to
  139. select the existing lease to be updated. Care should also be taken to
  140. modify the "ia_na" argument to match any changes in the "lease6" argument.
  141. If a client sends more than one IA_NA option, callouts will be called
  142. separately for each IA_NA instance. The callout will be called only
  143. when the update is valid, i.e. conditions such as an invalid addresses
  144. or invalid iaid renewal attempts will not trigger this hook point.
  145. - <b>Next step status</b>: If any callout installed on "lease6_renew"
  146. sets the status to SKIP, the server will not renew the lease. Under these
  147. circumstances, the callout should modify the "ia_na" argument to reflect
  148. this fact; otherwise the client will think the lease was renewed and continue
  149. to operate under this assumption.
  150. @subsection dhcpv6HooksLease6Decline lease6_decline
  151. - @b Arguments:
  152. - name: @b query6, type: isc::dhcp::PktPtr, direction: <b>in</b>
  153. - name: @b lease6, type: isc::dhcp::Lease6Ptr, direction: <b>in/out</b>
  154. - @b Description: This callout is executed when the server engine is
  155. about to decline an existing lease. The client's request is provided as
  156. the "query6" argument and the existing lease with the appropriate fields
  157. already modified is given in the "lease6" argument. The lease contains
  158. the lease before it is being declined.
  159. - <b>Next step status</b>: If any callout installed on "lease6_decline"
  160. sets the status to SKIP, the server will not decline the lease, but will
  161. continue processing the packet as if it did. It will send the response
  162. that the lease was declined, but the actual database will not be
  163. updated. If any callout installed sets the status to DROP, the packet
  164. processing will be aborted, the lease will not be declined and the
  165. server will not send a response.
  166. @subsection dhcpv6HooksLease6Release lease6_release
  167. - @b Arguments:
  168. - name: @b query6, type: isc::dhcp::PktPtr, direction: <b>in</b>
  169. - name: @b lease6, type: isc::dhcp::Lease6Ptr, direction: <b>in/out</b>
  170. - @b Description: This callout is executed when the server engine is
  171. about to release an existing lease. The client's request is provided
  172. as the "query6" argument and the existing lease is given in the "lease6"
  173. argument. Although the "lease6" structure may be modified, it doesn't
  174. make sense to do so as it will be destroyed immediately the callouts
  175. finish execution.
  176. - <b>Next step status</b>: If any callout installed on "lease6_release"
  177. sets the status to SKIP, the server will not delete the lease, which will
  178. remain in the database until it expires. However, the server will send out
  179. the response back to the client as if it did.
  180. @subsection dhcpv6HooksPkt6Send pkt6_send
  181. - @b Arguments:
  182. - name: @b response6, type: isc::dhcp::Pkt6Ptr, direction: <b>in/out</b>
  183. - @b Description: This callout is executed when server's response
  184. is about to be send back to the client. The sole argument "response6"
  185. contains a pointer to an @c isc::dhcp::Pkt6 object that contains the
  186. packet, with set source and destination addresses, interface over which
  187. it will be send, list of all options and relay information. All fields
  188. of the "response6" object can be modified at this time. It should be
  189. noted that unless the callout sets the skip flag (see below), anything
  190. placed in the @c buffer_out_ field will be overwritten when the callout
  191. returns. (buffer_out_ is scratch space used for constructing the packet.)
  192. - <b>Next step status</b>: If any callout sets the status to SKIP, the server
  193. will assume that the callout did pack the "transaction-id", "message type"
  194. and option objects into the @c buffer_out_ field and will skip packing part.
  195. Note that if the callout sets skip flag, but did not prepare the
  196. output buffer, the server will send a zero sized message that will be
  197. ignored by the client. If you want to drop the packet, please see
  198. skip flag in the "buffer6_send" hook point.
  199. @subsection dhcpv6HooksBuffer6Send buffer6_send
  200. - @b Arguments:
  201. - name: @b response6, type: isc::dhcp::Pkt6Ptr, direction: <b>in/out</b>
  202. - @b Description: This callout is executed when server's response is
  203. assembled into binary form and is about to be send back to the
  204. client. The sole argument "response6" contains a pointer to an
  205. @c isc::dhcp::Pkt6 object that contains the packet, with set source and
  206. destination addresses, interface over which it will be sent, list of
  207. all options and relay information. All options are already encoded
  208. in @c buffer_out_ field. It doesn't make sense to modify anything but the
  209. contents of buffer_out_ at this time (although if it is a requirement
  210. to modify that data, it will probably be found easier to modify the
  211. option objects in a callout attached to the "pkt6_send" hook).
  212. - <b>Next step status</b>: If any callout sets the status to SKIP, the server
  213. will drop this response packet. However, the original request packet
  214. from a client has been processed, so server's state has most likely changed
  215. (e.g. lease was allocated). Setting this flag merely stops the change
  216. being communicated to the client.
  217. @subsection dhcpv6HooksLease6Expire lease6_expire
  218. - @b Arguments:
  219. - name: @b lease6, type: isc::dhcp::Lease6Ptr, direction: <b>in/out</b>
  220. - name: @b remove_lease, type: bool, direction: <b>in</b>
  221. - @b Description: this callout is executed for each expired lease when
  222. the server performs reclamation of the expired leases. During this
  223. process the server executes "lease6_expire" callout, removes the DNS
  224. records associated with this lease and finally removes the lease from
  225. the database or updates its status to "expired-reclaimed". The "lease6"
  226. argument contains the pointer to the lease being reclaimed. The second
  227. argument "remove_lease" indicates if the reclaimed leases should be
  228. removed from the lease database (if true), or their state should be
  229. set to "expired-reclaimed" in the lease database. This argument
  230. is only used by the callout if it takes responsibility for the lease
  231. reclamation, i.e. it sets the "skip" flag to "true". The "remove_lease"
  232. argument is set to "true" if the "flush-reclaimed-timer-wait-time" is
  233. set to 0 in the server configuration file.
  234. - <b>Next step status</b>: if the callout sets the status to SKIP, the server
  235. will assume that the callout has fully reclaimed the lease, i.e.
  236. performed the DNS update and updated the lease in the database. The
  237. server will not perform any further actions on the lease for which the
  238. skip flag has been set. It is important to note that if the callout
  239. sets this flag but fails to reclaim the lease in the database, the
  240. reclamation routine will repeatedly process this lease in subsequent
  241. runs. Therefore, the implementors of this callout must make sure that
  242. skip flag is only set when the lease has been actually reclaimed in the
  243. database by the callout.
  244. */