dhcp6_hooks.dox 13 KB

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