dhcp6_hooks.dox 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. // Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. /**
  7. @page dhcpv6Hooks The Hooks API for the DHCPv6 Server
  8. @section dhcpv6HooksIntroduction Introduction
  9. Kea features an API (the "Hooks" API) that allows user-written code to
  10. be integrated into Kea and called at specific points in its processing.
  11. An overview of the API and a tutorial for writing such code can be found in
  12. the @ref hooksdgDevelopersGuide. Information for Kea maintainers can be
  13. found in the @ref hooksComponentDeveloperGuide.
  14. This manual is more specialized and is aimed at developers of hook
  15. code for the DHCPv6 server. It describes each hook point, what the callouts
  16. attached to the hook are able to do, and the arguments passed to the
  17. callouts. Each entry in this manual has the following information:
  18. - Name of the hook point.
  19. - Arguments for the callout. As well as the argument name and data type, the
  20. information includes the direction, which can be one of:
  21. - @b in - the server passes values to the callout but ignored any data
  22. returned.
  23. - @b out - the callout is expected to set this value.
  24. - <b>in/out</b> - the server passes a value to the callout and uses whatever
  25. value the callout sends back. Note that the callout may choose not to
  26. do any modification, in which case the server will use whatever value
  27. it sent to the callout.
  28. - Description of the hook. This explains where in the processing the hook
  29. is located, the possible actions a callout attached to this hook could take,
  30. and a description of the data passed to the callouts.
  31. - Next step status: the action taken by the server when a callout chooses to set
  32. status to specified value. Actions not listed explicitly are not supported.
  33. If a callout sets status to unsupported value, this specific value will be
  34. ignored and treated as if the status was CONTINUE.
  35. @section dhcpv6HooksHookPoints Hooks in the DHCPv6 Server
  36. The following list is roughly ordered by appearance of specific hook points during
  37. packet processing, but the exact order depends on the actual processing. Hook points
  38. that are not specific to packet processing (e.g. lease expiration) will be added
  39. to the end of this list.
  40. @subsection dhcpv6HooksBuffer6Receive buffer6_receive
  41. - @b Arguments:
  42. - name: @b query6, type: isc::dhcp::Pkt6Ptr, direction: <b>in/out</b>
  43. - @b Description: This callout is executed when an incoming DHCPv6
  44. packet is received and the data stored in a buffer. The sole argument
  45. "query6" contains a pointer to an @c isc::dhcp::Pkt6 object that contains
  46. the received information stored in the data_ field. Basic information
  47. like protocol, source/destination addresses and ports are set, but
  48. the contents of the buffer have not yet been parsed. That means that
  49. the @c options_ field (that will eventually contain a list of objects
  50. representing the received options) is empty, so none of the methods
  51. that operate on it (e.g., getOption()) will work. The primary purpose
  52. of this early call is to offer the ability to modify incoming packets
  53. in their raw form. Unless you need to access to the raw data, it is
  54. usually better to install your callout on the "pkt6_receive" hook point.
  55. - <b>Next step status</b>: If any callout sets the status to SKIP, the
  56. server will assume that the callout parsed the buffer and added the
  57. necessary option objects to the @c options_ field; the server will not
  58. do any parsing. If the callout sets the skip flag but does not parse
  59. the buffer, the server will most probably drop the packet due to
  60. the absence of mandatory options. If you want to drop the packet,
  61. see the description of the skip flag in the "pkt6_receive" hook point.
  62. @subsection dhcpv6HooksPkt6Receive pkt6_receive
  63. - @b Arguments:
  64. - name: @b query6, type: isc::dhcp::Pkt6Ptr, direction: <b>in/out</b>
  65. - @b Description: This callout is executed when an incoming DHCPv6
  66. packet is received and its content is parsed. The sole argument
  67. "query6" contains a pointer to an @c isc::dhcp::Pkt6 object that contains
  68. all information regarding incoming packet, including its source and
  69. destination addresses, the interface over which it was received, a list
  70. of all options present within and relay information. All fields of
  71. the "query6" object can be modified at this time, except data_. (data_
  72. contains the incoming packet as raw buffer. By the time this hook is
  73. reached, that information has already been parsed and is available though
  74. other fields in the Pkt6 object. For this reason, modification of the
  75. @c data_ field would have no effect.)
  76. - <b>Next step status</b>: If any callout sets the status to SKIP, the server will
  77. drop the packet and start processing the next one. The reason for the drop
  78. will be logged if logging is set to the appropriate debug level.
  79. @subsection dhcpv6HooksSubnet6Select subnet6_select
  80. - @b Arguments:
  81. - name: @b query6, type: isc::dhcp::Pkt6Ptr, direction: <b>in/out</b>
  82. - name: @b subnet6, type: isc::dhcp::Subnet6Ptr, direction: <b>in/out</b>
  83. - name: @b subnet6collection, type: const isc::dhcp::Subnet6Collection *, direction: <b>in</b>
  84. - @b Description: This callout is executed when a subnet is being
  85. selected for the incoming packet. All parameters, addresses and
  86. prefixes will be assigned from that subnet. A callout can select a
  87. different subnet if it wishes so, the list of all subnets currently
  88. configured being provided as "subnet6collection". The list itself must
  89. not be modified.
  90. - <b>Next step status</b>: If any callout installed on "subnet6_select"
  91. sets the status to SKIP, the server will not select any subnet. Packet processing
  92. will continue, but will be severely limited.
  93. @subsection dhcpv6HooksHost6Identifier host6_identifier
  94. - @b Arguments:
  95. - name: @b query6, type isc::dhcp::Pkt6Ptr, direction: <b>in</b>
  96. - name: @b id_type, type isc::dhcp::Host::IdentifierType, direction: <b>in/out</b>
  97. - name: @b id_value, type std::vector<uint8_t>, direction: <b>out</b>
  98. - @b Description: this callout is executed only if flexible identifiers are
  99. enabled, i.e. host-reservation-identifiers contain 'flex-id' value. This
  100. callout enables external library to provide values for flexible identifiers.
  101. To be able to use this feature, flex_id hook library is needed.
  102. - <b>Next step status</b>: If a callout installed on the "host6_identifier" hook
  103. point sets the next step status to value other than NEXT_STEP_CONTINUE, the
  104. identifier will not be used.
  105. @subsection dhcpv6HooksLease6Select lease6_select
  106. - @b Arguments:
  107. - name: @b query6, type: isc::dhcp::Pkt6Ptr, direction: <b>in</b>
  108. - name: @b subnet6, type: isc::dhcp::Subnet6Ptr, direction: <b>in</b>
  109. - name: @b fake_allocation, type: bool, direction: <b>in</b>
  110. - name: @b lease6, type: isc::dhcp::Lease6Ptr, direction: <b>in/out</b>
  111. - @b Description: This callout is executed after the server engine
  112. has selected a lease for client's request but before the lease
  113. has been inserted into the database. Any modifications made to the
  114. "lease6" object will affect the lease's record in the database.
  115. The callout should make sure that any modifications are sanity
  116. checked as the server will use that data as is, with no further
  117. checking.\n\n The server processes lease requests for SOLICIT and
  118. REQUEST in a very similar way. The major difference is that
  119. for SOLICIT the lease is only selected; it is not inserted into
  120. the database. The callouts can distinguish between the SOLICIT and
  121. REQUEST by checking the value of the "fake_allocation" flag: a value
  122. of true means that the lease won't be inserted into the database
  123. (SOLICIT case), a value of false means that it will (REQUEST).
  124. - <b>Next step status</b>: If any callout installed on "lease6_select"
  125. sets the status to SKIP, the server will not assign that particular lease.
  126. Packet processing will continue and the client may get other addresses
  127. or prefixes if it requested more than one address and/or prefix.
  128. @subsection dhcpv6HooksLease6Renew lease6_renew
  129. - @b Arguments:
  130. - name: @b query6, type: isc::dhcp::PktPtr, direction: <b>in</b>
  131. - name: @b lease6, type: isc::dhcp::Lease6Ptr, direction: <b>in/out</b>
  132. - name: @b ia_na, type: boost::shared_ptr<Option6IA>, direction: <b>in/out</b>
  133. - @b Description: This callout is executed when the server engine is
  134. about to renew an existing lease. The client's request is provided as
  135. the "query6" argument and the existing lease with the appropriate fields
  136. already modified is given in the "lease6" argument. The final argument,
  137. ia_na, is the IA_NA option that will be sent back to the client.
  138. Callouts installed on the "lease6_renew" may modify the content of
  139. the "lease6" object. Care should be taken however, as that modified
  140. information will be written to the database without any further
  141. checking. \n\n Although the envisaged usage assumes modification of T1,
  142. T2, preferred and valid lifetimes only, other parameters associated
  143. with the lease may be modified as well. The only exception is the @c addr_
  144. field, which must not be modified as it is used by the database to
  145. select the existing lease to be updated. Care should also be taken to
  146. modify the "ia_na" argument to match any changes in the "lease6" argument.
  147. If a client sends more than one IA_NA option, callouts will be called
  148. separately for each IA_NA instance. The callout will be called only
  149. when the update is valid, i.e. conditions such as an invalid addresses
  150. or invalid iaid renewal attempts will not trigger this hook point.
  151. - <b>Next step status</b>: If any callout installed on "lease6_renew"
  152. sets the status to SKIP, the server will not renew the lease. Under these
  153. circumstances, the callout should modify the "ia_na" argument to reflect
  154. this fact; otherwise the client will think the lease was renewed and continue
  155. to operate under this assumption.
  156. @subsection dhcpv6HooksLease6Rebind lease6_rebind
  157. - @b Arguments:
  158. - name: @b query6, type: isc::dhcp::PktPtr, direction: <b>in</b>
  159. - name: @b lease6, type: isc::dhcp::Lease6Ptr, direction: <b>in/out</b>
  160. - name: @b ia_na, type: boost::shared_ptr<Option6IA>, direction: <b>in/out</b>
  161. - @b Description: This callout is executed when the server engine is
  162. about to rebind an existing lease. The client's request is provided as
  163. the "query6" argument and the existing lease with the appropriate fields
  164. already modified is given in the "lease6" argument. The final argument,
  165. ia_na, is the IA_NA option that will be sent back to the client.
  166. Callouts installed on the "lease6_rebind" may modify the content of
  167. the "lease6" object. Care should be taken however, as that modified
  168. information will be written to the database without any further
  169. checking. \n\n Although the envisaged usage assumes modification of T1,
  170. T2, preferred and valid lifetimes only, other parameters associated
  171. with the lease may be modified as well. The only exception is the @c addr_
  172. field, which must not be modified as it is used by the database to
  173. select the existing lease to be updated. Care should also be taken to
  174. modify the "ia_na" argument to match any changes in the "lease6" argument.
  175. If a client sends more than one IA_NA option, callouts will be called
  176. separately for each IA_NA instance. The callout will be called only
  177. when the update is valid, i.e. conditions such as an invalid addresses
  178. or invalid iaid rebinding attempts will not trigger this hook point.
  179. - <b>Next step status</b>: If any callout installed on "lease6_rebind"
  180. sets the status to SKIP, the server will not rebind the lease. Under these
  181. circumstances, the callout should modify the "ia_na" argument to reflect
  182. this fact; otherwise the client will think the lease was rebound and continue
  183. to operate under this assumption.
  184. @subsection dhcpv6HooksLease6Decline lease6_decline
  185. - @b Arguments:
  186. - name: @b query6, type: isc::dhcp::PktPtr, direction: <b>in</b>
  187. - name: @b lease6, type: isc::dhcp::Lease6Ptr, direction: <b>in/out</b>
  188. - @b Description: This callout is executed when the server engine is
  189. about to decline an existing lease. The client's DECLINE is provided as
  190. the "query6" argument and the existing lease with the appropriate fields
  191. already modified is given in the "lease6" argument. The lease contains
  192. the lease before it is being declined.
  193. - <b>Next step status</b>: If any callout installed on "lease6_decline"
  194. sets the status to SKIP, the server will not decline the lease, but will
  195. continue processing the packet as if it did. It will send the response
  196. that the lease was declined, but the actual database will not be
  197. updated. If any callout installed sets the status to DROP, the packet
  198. processing will be aborted, the lease will not be declined and the
  199. server will not send a response.
  200. @subsection dhcpv6HooksLease6Release lease6_release
  201. - @b Arguments:
  202. - name: @b query6, type: isc::dhcp::PktPtr, direction: <b>in</b>
  203. - name: @b lease6, type: isc::dhcp::Lease6Ptr, direction: <b>in/out</b>
  204. - @b Description: This callout is executed when the server engine is
  205. about to release an existing lease. The client's request is provided
  206. as the "query6" argument and the existing lease is given in the "lease6"
  207. argument. Although the "lease6" structure may be modified, it doesn't
  208. make sense to do so as it will be destroyed immediately the callouts
  209. finish execution.
  210. - <b>Next step status</b>: If any callout installed on "lease6_release"
  211. sets the status to SKIP, the server will not delete the lease, which will
  212. remain in the database until it expires. However, the server will send out
  213. the response back to the client as if it did.
  214. @subsection dhcpv6HooksPkt6Send pkt6_send
  215. - @b Arguments:
  216. - name: @b query6, type: isc::dhcp::Pkt6Ptr, direction: <b>in</b>
  217. - name: @b response6, type: isc::dhcp::Pkt6Ptr, direction: <b>in/out</b>
  218. - @b Description: This callout is executed when server's response
  219. is about to be send back to the client. The sole argument "response6"
  220. contains a pointer to an @c isc::dhcp::Pkt6 object that contains the
  221. packet, with set source and destination addresses, interface over which
  222. it will be send, list of all options and relay information. All fields
  223. of the "response6" object can be modified at this time. It should be
  224. noted that unless the callout sets the skip flag (see below), anything
  225. placed in the @c buffer_out_ field will be overwritten when the callout
  226. returns. (buffer_out_ is scratch space used for constructing the packet.)
  227. - <b>Next step status</b>: If any callout sets the status to SKIP, the server
  228. will assume that the callout did pack the "transaction-id", "message type"
  229. and option objects into the @c buffer_out_ field and will skip packing part.
  230. Note that if the callout sets skip flag, but did not prepare the
  231. output buffer, the server will send a zero sized message that will be
  232. ignored by the client. If you want to drop the packet, please see
  233. skip flag in the "buffer6_send" hook point.
  234. @subsection dhcpv6HooksBuffer6Send buffer6_send
  235. - @b Arguments:
  236. - name: @b response6, type: isc::dhcp::Pkt6Ptr, direction: <b>in/out</b>
  237. - @b Description: This callout is executed when server's response is
  238. assembled into binary form and is about to be send back to the
  239. client. The sole argument "response6" contains a pointer to an
  240. @c isc::dhcp::Pkt6 object that contains the packet, with set source and
  241. destination addresses, interface over which it will be sent, list of
  242. all options and relay information. All options are already encoded
  243. in @c buffer_out_ field. It doesn't make sense to modify anything but the
  244. contents of buffer_out_ at this time (although if it is a requirement
  245. to modify that data, it will probably be found easier to modify the
  246. option objects in a callout attached to the "pkt6_send" hook).
  247. - <b>Next step status</b>: If any callout sets the status to SKIP, the server
  248. will drop this response packet. However, the original request packet
  249. from a client has been processed, so server's state has most likely changed
  250. (e.g. lease was allocated). Setting this flag merely stops the change
  251. being communicated to the client.
  252. @subsection dhcpv6HooksLease6Expire lease6_expire
  253. - @b Arguments:
  254. - name: @b lease6, type: isc::dhcp::Lease6Ptr, direction: <b>in/out</b>
  255. - name: @b remove_lease, type: bool, direction: <b>in</b>
  256. - @b Description: this callout is executed for each expired lease when
  257. the server performs reclamation of the expired leases. During this
  258. process the server executes "lease6_expire" callout, removes the DNS
  259. records associated with this lease and finally removes the lease from
  260. the database or updates its status to "expired-reclaimed". The "lease6"
  261. argument contains the pointer to the lease being reclaimed. The second
  262. argument "remove_lease" indicates if the reclaimed leases should be
  263. removed from the lease database (if true), or their state should be
  264. set to "expired-reclaimed" in the lease database. This argument
  265. is only used by the callout if it takes responsibility for the lease
  266. reclamation, i.e. it sets the "skip" flag to "true". The "remove_lease"
  267. argument is set to "true" if the "flush-reclaimed-timer-wait-time" is
  268. set to 0 in the server configuration file.
  269. - <b>Next step status</b>: if the callout sets the status to SKIP, the server
  270. will assume that the callout has fully reclaimed the lease, i.e.
  271. performed the DNS update and updated the lease in the database. The
  272. server will not perform any further actions on the lease for which the
  273. skip flag has been set. It is important to note that if the callout
  274. sets this flag but fails to reclaim the lease in the database, the
  275. reclamation routine will repeatedly process this lease in subsequent
  276. runs. Therefore, the implementors of this callout must make sure that
  277. skip flag is only set when the lease has been actually reclaimed in the
  278. database by the callout.
  279. @subsection dhcpv6HooksLease6Recover lease6_recover
  280. - @b Arguments:
  281. - name: @b lease6, type: isc::dhcp::Lease6Ptr, direction: <b>in</b>
  282. - @b Description: this callout is executed for each declined lease that
  283. has expired (was put aside for the duration of decline-probation-period)
  284. and is being recovered. The lease has already been stripped
  285. from any client identifying information when it was put into declined
  286. state. In principle the callouts can modify the lease in this hook,
  287. but it makes little sense. There's no useful data in the lease, except
  288. the IPv6 address (which must not be modified).
  289. - <b>Next step status</b>: if the callout sets the next step action to SKIP,
  290. the server will skip the lease recovery. In other words, it will keep
  291. the lease as is. This is not recommended in general, as the declined
  292. expired leases will remain in the database and their recovery will
  293. be attempted during the next reclaim cycle.
  294. @subsection dhcpv6HooksControlCommandReceive control_command_receive
  295. - @b Arguments:
  296. - name: @b command, type: ConstElementPtr, direction: <b>in/out</b>
  297. - name: @b response, type: ConstElementPtr, direction: <b>in/out</b>
  298. - @b Description: this callout is executed when DHCPv4 server receives a
  299. control command over the command channel (typically unix domain socket).
  300. The "command" argument is a pointer to the parsed JSON structure
  301. including command name and command arguments. If the callout implements
  302. the specified command, it handles the command and creates appropriate
  303. response. The response should be returned in the "response" argument.
  304. In most cases, the callout which handles the command will set the next
  305. step action to SKIP, to prevent the server from trying to handle the
  306. command on its own and overriding the response created by the callouts.
  307. A notable exception is the 'list-commands' command for which the callouts
  308. should not set the next step action to SKIP. The server has a special
  309. code path for this command which combines the list of commands returned
  310. by the callouts with the list of commands supported by the server. If
  311. the callout sets the next step action to SKIP in this case, the server
  312. will only return the list of commands supported by the hook library.
  313. The callout can modify the command arguments to influence the command
  314. processing by the Command Manager. For example, it may freely modify
  315. the configuration received in 'set-config' before it is processed by
  316. the server. The SKIP action is not set in this case.
  317. - <b>Next step status</b>: if any callout sets the next step action to SKIP,
  318. the server will assume that the command has been handled by the callouts
  319. and will expect that the response is provided in the "response" argument.
  320. The server will not handle the command in this case but simply return the
  321. response returned by the callout to the caller.
  322. @section dhcpv6HooksOptionsAccess Accessing DHCPv6 Options within a Packet
  323. When the server constructs a response message to a client it includes
  324. DHCP options configured for this client in a response message. Apart
  325. from the dynamically created options, such as IA_NA or ClientFQDN, it
  326. typically includes many options specified in the server configuration
  327. and held within the configuration structures by @c CfgMgr. Option
  328. instances are created once, during server configuration, and the
  329. @c CfgMgr holds pointers to those instances until the next server
  330. reconfiguration.
  331. When the server includes an option in a response message it copies
  332. a pointer to the instance of this option, rather than entire option.
  333. This ensures the good performance of response message creation. However,
  334. it also implies that any modification to the option carried in the
  335. DHCP response will affect an instance of this option in the server
  336. configuration structures. This is obviously not desired as it would
  337. affect all subsequent DHCP transactions involving this option. The
  338. DHCP server code avoids modifying the options included in the messages
  339. so it is possible to ensure good performance without a risk of
  340. accidentally modifying server configuration. The situation is
  341. different with hooks libraries which purpose is, in many cases,
  342. to modify values of options inserted by the server.
  343. Thus, @c Pkt class provides a mechanism to return a copy of an
  344. option to a caller (e.g. a callout), rather than an instance
  345. shared with the @c CfgMgr. This mechanism is enabled for all instances
  346. of @c Pkt6 passed to the callouts, i.e. "query6" and "response6"
  347. arguments. It is also automatically disabled when the callout
  348. returns the control back to the server.
  349. At every hook point, where the server passes an instance of a packet
  350. to the callouts, the server calls
  351. @c isc::dhcp::Pkt6::setCopyRetrievedOptions (true)
  352. to force copying options retrieved by @c isc::dhcp::Pkt6::getOption,
  353. @c isc::dhcp::Pkt6::getOptions, @c isc::dhcp::Pkt6::getRelayOption
  354. and @c isc::dhcp::Pkt6::getAnyRelayOption within callouts. The copied
  355. option replaces an original option within the packet and any
  356. modification to the option content by the callout would only affect
  357. the option instance associated with the packet.
  358. On the other hand, copying each retrieved option may be expensive.
  359. If performance of a hook library is a concern, it is possible for the
  360. hook library to disable copying retrieved options by calling
  361. @c isc::dhcp::Pkt6::setCopyRetrievedOptions (false) within a callout.
  362. In this case however, the hook library implementer must be aware that
  363. any modification of the option instance would affect the server
  364. configuration and may disrupt server's operation. Thus, disabling
  365. copying of retrieved options is not recommended unless the hook
  366. library is not intended to modify configured options carried
  367. within a packet.
  368. */