hooks.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
  4. <!ENTITY mdash "&#x2014;" >
  5. ]>
  6. <chapter id="hooks-libraries">
  7. <title>Hooks Libraries</title>
  8. <section id="hooks-libraries-introduction">
  9. <title>Introduction</title>
  10. <para>
  11. Although Kea offers a lot of flexibility, there may be cases where
  12. its behavior needs customisation. To accommodate this possibility,
  13. Kea includes the idea of "Hooks". This feature lets Kea load one
  14. or more dynamically-linked libraries (known as "hooks libraries")
  15. and, at various points in its processing ("hook points"), call
  16. functions in them. Those functions perform whatever custom
  17. processing is required.
  18. </para>
  19. <para>
  20. Hooks libraries are attached to individual Kea processes, not to
  21. Kea as a whole. This means (for example) that it is possible
  22. to associate one set of libraries with the DHCP4 server and a
  23. different set to the DHCP6 server.
  24. </para>
  25. <para>
  26. Another point to note is that it is possible for a process to
  27. load multiple libraries. When processing reaches a hook point,
  28. Kea calls the hooks library functions attached to it. If multiple
  29. libraries have attached a function to a given hook point, Kea calls
  30. all of them, in the order in which the libraries are specified in
  31. the configuration file. The order may be important: consult the
  32. documentation of the libraries to see if this is the case.
  33. </para>
  34. <para>
  35. The next section describes how to configure hooks libraries. If you
  36. are interested in writing your own hooks library, information can be
  37. found in the <ulink url="http://git.kea.isc.org/~tester/kea/doxygen">Kea
  38. Developer's Guide</ulink>.
  39. </para>
  40. </section> <!-- end Introduction -->
  41. <section>
  42. <title>Configuring Hooks Libraries</title>
  43. <para>
  44. The hooks libraries for a given process are configured using the
  45. <command>hooks-libraries</command> keyword in the
  46. configuration for that process. (Note that
  47. the word "hooks" is plural). The value of the keyword
  48. is an array of map structures, each structure corresponding to a hooks
  49. library. For example, to set up two hooks libraries for the DHCPv4
  50. server, the configuration would be:
  51. <screen>
  52. <userinput>"Dhcp4": {
  53. :
  54. "hooks-libraries": [
  55. {
  56. "library": "/opt/charging.so"
  57. },
  58. {
  59. "library": "/opt/local/notification.so",
  60. "parameters": {
  61. "mail": "spam@example.com",
  62. "floor": 13,
  63. "debug": false,
  64. "users": [ "alice", "bob", "charlie" ],
  65. "languages": {
  66. "french": "bonjour",
  67. "klingon": "yl'el"
  68. }
  69. }
  70. }
  71. ]
  72. :
  73. }</userinput>
  74. </screen>
  75. </para>
  76. <note><para>
  77. This is a change to the syntax used in Kea 0.9.2 and earlier, where
  78. hooks-libraries was a list of strings, each string being the name of
  79. a library. The change has been made in Kea 1.0 to facilitate the
  80. specification of library-specific parameters, a feature that will be
  81. added to a future version of Kea.
  82. </para></note>
  83. <note>
  84. <para>
  85. The library reloading behavior has changed in Kea 1.1. Libraries are
  86. reloaded, even if their list hasn't changed. Kea does that, because
  87. the parameters specified for the library (or the files those
  88. parameters point to) may have changed.
  89. </para>
  90. </note>
  91. <para>
  92. Libraries may have additional parameters. Those are not mandatory in the
  93. sense that there may be libraries that don't require them. However, for
  94. specific library there is often specific requirement for specify certain
  95. set of parameters. Please consult the documentation for your library
  96. for details. In the example above, the first library has no parameters.
  97. The second library has five parameters, specifying mail (string
  98. parameter), floor (integer parameter), debug (boolean parameter) and
  99. even lists (list of strings) and maps (containing strings). Nested
  100. parameters could be used if the library supports it. This topic is
  101. explained in detail in the Hooks Developer's Guide in Configuring Hooks
  102. Libraries section.
  103. </para>
  104. <para>
  105. Notes:
  106. <itemizedlist mark='bullet'>
  107. <listitem><para>
  108. The full path to each library should be given.
  109. </para></listitem>
  110. <listitem><para>
  111. As noted above, order may be important - consult the documentation for
  112. each library.
  113. </para></listitem>
  114. <listitem><para>
  115. An empty list has the same effect as omitting the
  116. <command>hooks-libraries</command> configuration element all together.
  117. </para>
  118. <note><para>
  119. There is one case where this is not true: if Kea
  120. is running with a configuration that contains a
  121. <command>hooks-libraries</command> item, and that item is
  122. removed and the configuration reloaded, the removal will be
  123. ignored and the libraries remain loaded. As a workaround,
  124. instead of removing the <command>hooks-libraries</command>
  125. item, change it to an empty list. This will be fixed in a
  126. future version of Kea.
  127. </para></note>
  128. </listitem>
  129. </itemizedlist>
  130. </para>
  131. <para>
  132. At the present time, only the kea-dhcp4 and kea-dhcp6 processes support
  133. hooks libraries.
  134. </para>
  135. </section>
  136. <section>
  137. <title>Available Hooks Libraries</title>
  138. <para>
  139. As described above the hooks functionality provides a way to customize
  140. a Kea server without modifying the core code. ISC has chosen to take
  141. advantage of this feature to provide functions that may not be useful
  142. to all users. To this end ISC has created some hooks libraries which
  143. are discussed in the following sections.
  144. </para>
  145. <para>
  146. Some of these libraries will be available with the base code while
  147. others will only be available via a support contract.
  148. </para>
  149. <section>
  150. <title>Forensic Logging Hooks</title>
  151. <para>
  152. This section describes the forensic log hooks library. This library
  153. povides hooks that record a detailed log of lease assignments
  154. and renewals into a set of log files. Currently this library
  155. is only available to customers with a support contract.
  156. </para>
  157. <para>
  158. In many legal jurisdictions companies, especially ISPs, must record
  159. information about the addresses they have leased to DHCP clients.
  160. This library is designed to help with that requirement. If the
  161. information that it records is sufficient it may be used directly.
  162. If your jurisdiction requires that you save a different set of
  163. information you may use it as a template or example and create your
  164. own custom logging hooks.
  165. </para>
  166. <para>
  167. This logging is done as a set of hooks to allow it to be customized
  168. to any particular need. Modifying a hooks library is easier and
  169. safer than updating the core code. In addition by using the hooks
  170. features those users who don't need to log this information can
  171. leave it out and avoid any performance penalties.
  172. </para>
  173. <section>
  174. <title>Log File Naming</title>
  175. <para>
  176. The names for the log files have the following form:
  177. </para>
  178. <screen>
  179. path/base-name.CCYYMMDD.txt
  180. </screen>
  181. <para>
  182. The &quot;path&quot; and &quot;base-name&quot; are supplied in the
  183. configuration as described below see
  184. <xref linkend="forensic-log-configuration"/>. The next part of the name is
  185. the date the log file was started, with four digits for year, two digits
  186. for month and two digits for day. The file is rotated on a daily basis.
  187. </para>
  188. <note><para>
  189. When running Kea servers for both DHCPv4 and DHCPv6 the log names must
  190. be distinct. See the examples in <xref linkend="forensic-log-configuration"/>.
  191. </para></note>
  192. </section>
  193. <section>
  194. <title>DHCPv4 Log Entries</title>
  195. <para>
  196. For DHCPv4 the library creates entries based on DHCPREQUEST messages
  197. and corresponding DHCPv4 leases intercepted by lease4_select
  198. (for new leases) and lease4_renew (for renewed leases) hooks.
  199. </para>
  200. <para>
  201. An entry is a single string with no embedded end-of-line markers
  202. and has the following sections:
  203. <screen>
  204. address duration device-id {client-info} {relay-info}
  205. </screen>
  206. </para>
  207. <para>
  208. Where:
  209. <itemizedlist>
  210. <listitem><para>
  211. address - the leased IPv4 address given out and whether it was
  212. assigned or renewed.
  213. </para></listitem>
  214. <listitem><para>
  215. duration - the lease lifetime expressed in days (if present),
  216. hours, minutes and seconds. A lease lifetime of 0xFFFFFFFF will be
  217. denoted with the text &quot;infinite duration&quot;.
  218. </para></listitem>
  219. <listitem><para>
  220. device-id - the client's hardware address shown as numerical type
  221. and hex digit string.
  222. </para></listitem>
  223. <listitem><para>
  224. client-info - the DHCP client id option (61) if present, shown as
  225. a hex string.
  226. </para></listitem>
  227. <listitem><para>
  228. relay-info - for relayed packets the giaddr and the RAI circuit id
  229. and remote id options (option 82 sub options 1 and 2) if present.
  230. The circuit id and remote id are presented as hex strings
  231. </para></listitem>
  232. </itemizedlist>
  233. </para>
  234. <para>
  235. For instance (line breaks added for readability, they would not
  236. be present in the log file).
  237. <screen>
  238. Address: 192.2.1.100 has been renewed for 1 hrs 52 min 15 secs to a device with
  239. hardware address: hwtype=1 08:00:2b:02:3f:4e, client-id: 17:34:e2:ff:09:92:54
  240. connected via relay at address: 192.2.16.33, identified by circuit-id:
  241. 68:6f:77:64:79 and remote-id: 87:f6:79:77:ef
  242. </screen>
  243. </para>
  244. </section>
  245. <section>
  246. <title>DHCPv6 Log Entries</title>
  247. <para>
  248. For DHCPv6 the library creates entries based on lease management
  249. actions intercepted by the lease6_select (for new leases), lease6_renew
  250. (for renewed leases) and lease6_rebind (for rebound leases).
  251. </para>
  252. <para>
  253. An entry is a single string with no embedded end-of-line markers
  254. and has the following sections:
  255. <screen>
  256. address duration device-id {relay-info}*
  257. </screen>
  258. </para>
  259. <para>
  260. Where:
  261. <itemizedlist>
  262. <listitem><para>
  263. address - the leased IPv6 address or prefix given out and whether
  264. it was assigned or renewed.
  265. </para></listitem>
  266. <listitem><para>
  267. duration - the lease lifetime expressed in days (if present),
  268. hours, minutes and seconds. A lease lifetime of 0xFFFFFFFF will be
  269. denoted with the text "infinite duration".
  270. </para></listitem>
  271. <listitem><para>
  272. device-id - the client's DUID and hardware address (if present).
  273. </para></listitem>
  274. <listitem><para>
  275. relay-info - for relayed packets the content of relay agent
  276. messages, remote id and subscriber id options (x and xx) if present.
  277. </para></listitem>
  278. </itemizedlist>
  279. </para>
  280. <para>
  281. For instance (line breaks added for readability, they would not
  282. be present in the log file).
  283. <screen>
  284. Address:2001:db8:1:: has been assigned for 0 hrs 11 mins 53 secs to a device with
  285. DUID: 17:34:e2:ff:09:92:54 and hardware address: hwtype=1 08:00:2b:02:3f:4e
  286. (from Raw Socket) connected via relay at address: fe80::abcd for client on
  287. link address: 3001::1, hop count: 1, identified by remote-id:
  288. 01:02:03:04:0a:0b:0c:0d:0e:0f and subscriber-id: 1a:2b:3c:4d:5e:6f
  289. </screen>
  290. </para>
  291. </section>
  292. <section id="forensic-log-configuration">
  293. <title>Configuring the Forensic Log Hooks</title>
  294. <para>
  295. To use this functionality the hook library must be included in the
  296. configuration of the desired DHCP server modules. The legal_log
  297. library is installed alongside the Kea libraries in
  298. <filename>[kea-install-dir]/lib</filename> where
  299. <filename>kea-install-dir</filename> is determined by the
  300. &quot;--prefix&quot; option of the configure script. It defaults to
  301. <filename>/usr/local</filename>. Assuming the
  302. default value then, configuring kea-dhcp4 to load the legal_log
  303. library could be done with the following Kea4 configuration:
  304. <screen>
  305. "Dhcp4": { <userinput>
  306. "hooks-libraries": [
  307. {
  308. "library": "/usr/local/lib/libdhcp_legal_log.so",
  309. "parameters": {
  310. "path": "/var/kea/var",
  311. "base-name": "kea-forensic4"
  312. }
  313. },
  314. ...
  315. ] </userinput>
  316. }
  317. </screen>
  318. </para>
  319. <para>
  320. To configure it for kea-dhcp6, the commands are simply as shown below:
  321. <screen>
  322. "Dhcp6": { <userinput>
  323. "hooks-libraries": [
  324. {
  325. "library": "/usr/local/lib/libdhcp_legal_log.so",
  326. "parameters": {
  327. "path": "/var/kea/var",
  328. "base-name": "kea-forensic6"
  329. }
  330. },
  331. ...
  332. ] </userinput>
  333. }
  334. </screen>
  335. </para>
  336. <para>
  337. Two Hook Library parameters are supported:
  338. <itemizedlist>
  339. <listitem><para>
  340. path - the directory in which the forensic file(s) will be written. The
  341. default value is
  342. <filename>[prefix]/kea/var</filename>. The directory must exist.
  343. </para></listitem>
  344. <listitem><para>
  345. base-name - an arbitrary value which is used in conjunction with
  346. the current system date to form the current foresnic file name. It defaults
  347. to <filename>kea-legal</filename>.
  348. </para></listitem>
  349. </itemizedlist>
  350. </para>
  351. </section>
  352. </section>
  353. </section>
  354. </chapter> <!-- hooks-libraries -->