hooks.xml 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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="https://jenkins.isc.org/job/Fedora20_32_doxygen_doc/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 capability
  81. available since Kea 1.1.0-beta.
  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. <note><para>
  146. Some of these libraries will be available with the base code while others
  147. will be shared with organizations supporting development of the Kea
  148. project, possibly as a 'benefit' or 'thank you' for helping to sustain
  149. the larger Kea project. If you would like to get access to those
  150. libraries, please consider signing up a support contract. It also features a
  151. professional support, advance security notifications, input into our
  152. roadmap planning, consulting hours and many other benefits, while helping
  153. making Kea sustainable in the long term.
  154. </para></note>
  155. <para>Currently the following libraries are available or planned from ISC:
  156. <table frame="all" id="hook-libs">
  157. <title>List of available hook libraries</title>
  158. <tgroup cols='3'>
  159. <colspec colname='name' />
  160. <colspec colname='avail' />
  161. <colspec colname='description' />
  162. <thead>
  163. <row>
  164. <entry>Name</entry>
  165. <entry>Availability</entry>
  166. <entry>Since</entry>
  167. <entry>Description</entry>
  168. </row>
  169. </thead>
  170. <tbody>
  171. <row>
  172. <entry>user_chk</entry>
  173. <entry>Kea sources</entry>
  174. <entry>Kea 0.8</entry>
  175. <entry>Reads known users list from a file. it will be assigned a
  176. lease from the last subnet defined in the configuration file,
  177. e.g. to redirect him into a captive portal. This showcases how
  178. externals source of information can be used to influence Kea
  179. allocation engine. This hook is part of the Kea sources and is
  180. available in src/hooks/dhcp/user_chk directory.</entry>
  181. </row>
  182. <row>
  183. <entry>Forensic Logging</entry>
  184. <entry>Support customers</entry>
  185. <entry>Kea 1.1.0</entry>
  186. <entry>This library povides hooks that record a detailed log of
  187. lease assignments and renewals into a set of log files. In many
  188. legal jurisdictions companies, especially ISPs, must record
  189. information about the addresses they have leased to DHCP
  190. clients. This library is designed to help with that
  191. requirement. If the information that it records is sufficient it
  192. may be used directly. If your jurisdiction requires that you save
  193. a different set of information you may use it as a template or
  194. example and create your own custom logging hooks.</entry>
  195. </row>
  196. <row>
  197. <entry>Lightweight 4over6</entry>
  198. <entry>Support customers</entry>
  199. <entry>Autumn 2016</entry>
  200. <entry>Lightweight 4over6 (RFC7596) is a new IPv6 transition
  201. technology that provides IPv4 as a service in IPv6-only
  202. network. It assumes that dual-stack clients will get regular IPv6
  203. address and IPv6 prefix, but only a fraction of IPv4 address. The
  204. fraction is specified as port-set, which is essentially a range of
  205. TCP and UDP ports a client can use. By doing the transition on the
  206. client side, this technology eliminates the need to deploy
  207. expensive Carrier Grade NATs withing operator's network. The
  208. problem on the DHCP side is the non-trivial logic behind it: each
  209. client needs to receive an unique set of lw4over6 options
  210. (RFC7598), that include IPv4 address (shared among several
  211. clients), port-set (which is unique among clients sharing the same
  212. IPv4 address and a number of additional parameters. This hook
  213. library will generate values of those options dynamically, thus
  214. eliminating the need to manually configure values for each client
  215. separately.
  216. </entry>
  217. </row>
  218. </tbody>
  219. </tgroup>
  220. </table>
  221. </para>
  222. <para>
  223. ISC hopes to see more hook libraries become available as time
  224. progresses, both developed internally and externally. Since
  225. this list may eveolve dynamically, we decided to keep it on a
  226. wiki page, available at this link: <ulink
  227. url="http://kea.isc.org/wiki/Hooks">http://kea.isc.org/wiki/Hooks</ulink>.
  228. If you are a developer or are aware of any hook libraries not
  229. listed there, please send a note to kea-users or kea-dev
  230. mailing lists and someone will update it.
  231. </para>
  232. <section>
  233. <title>user_chk: Checking user access</title>
  234. <para>
  235. User_chk library is the first hook library published by ISC. It
  236. attempts to serve several purposes:
  237. <itemizedlist>
  238. <listitem>
  239. <para>To assign "new" or "unregistered" users to a
  240. restricted subnet, while "known" or "registered" users are assigned
  241. to unrestricted subnets.</para>
  242. </listitem>
  243. <listitem>
  244. <para>To allow DHCP response options or vendor option
  245. values to be customized based upon user identity. </para>
  246. </listitem>
  247. <listitem>
  248. <para>To provide a real time record of the user registration
  249. activity which can be sampled by an external consumer.</para>
  250. </listitem>
  251. <listitem>
  252. <para> To serve as a demonstration of various capabilities
  253. possible using hook interface.</para>
  254. </listitem>
  255. </itemizedlist>
  256. </para>
  257. <para>
  258. Once loaded, the library allows segregating incomings requests into
  259. known and unknown clients. For known clients, the packets are
  260. processed mostly as usual, except it is possible to override certain
  261. options being sent. That can be done on a per host basis. Clients
  262. that are not on the known hosts list will be treated as unknown and
  263. will be assigned to the last subnet defined in the configuration file.
  264. </para>
  265. <para>
  266. For example this behavior may be used to put unknown users into a
  267. separate subnet that leads to a walled garden, where they can only
  268. access a registration portal. Once they fill in necessary data, their
  269. details are added to the known clients file, and they get a proper
  270. address after their device is restarted.
  271. </para>
  272. <note><para>This library has been developed several years before host
  273. reservation mechanism has become available. Currently HR is much more
  274. powerful and flexible, but nevertheless user_chk capability to consult
  275. and external source of information about clients and alter Kea's
  276. behavior is useful and remains to have educational value.
  277. </para></note>
  278. <para>
  279. The library reads the /tmp/user_chk_registry.txt file while being
  280. loaded and processing every incoming packet. The file is expected
  281. to have each line contain a self-contained JSON snippet which must
  282. have the following two entries:
  283. <itemizedlist>
  284. <listitem><para>"type" whose value is "HW_ADDR" for IPv4 users or
  285. "DUID" for IPv6 users</para></listitem>
  286. <listitem><para>"id" whose value is either the hardware address or
  287. the DUID from the equest formatted as a string of hex digits, with
  288. or without ":" delimiters.</para></listitem>
  289. </itemizedlist>
  290. and may have the zero or more of the following entries:
  291. <itemizedlist>
  292. <listitem><para>"bootfile" whose value is the pathname of the
  293. desired file</para></listitem>
  294. <listitem><para>"tftp_server" whose value is the hostname or IP
  295. address of the desired server</para></listitem>
  296. </itemizedlist>
  297. Sample user registry file is shown below:
  298. <screen>{ "type" : "HW_ADDR", "id" : "0c:0e:0a:01:ff:04", "bootfile" : "/tmp/v4bootfile" }
  299. { "type" : "HW_ADDR", "id" : "0c:0e:0a:01:ff:06", "tftp_server" : "tftp.v4.example.com" }
  300. { "type" : "DUID", "id" : "00:01:00:01:19:ef:e6:3b:00:0c:01:02:03:04", "bootfile" : "/tmp/v6bootfile" }
  301. { "type" : "DUID", "id" : "00:01:00:01:19:ef:e6:3b:00:0c:01:02:03:06", "tftp_server" : "tftp.v6.example.com" }</screen>
  302. </para>
  303. <para>As with any other hook libraries provided by ISC, internals of the
  304. user_chk code are well documented. You can take a look at the <ulink
  305. url="https://jenkins.isc.org/job/Fedora20_32_doxygen_doc/doxygen/d8/db2/libdhcp_user_chk.html">Kea Developer's Guide section dedicated to the user_chk library</ulink>
  306. that discusses how the code works internally. That, together with
  307. our general entries in <ulink
  308. url="https://jenkins.isc.org/job/Fedora20_32_doxygen_doc/doxygen/">Hooks
  309. Framework section</ulink> should give you some pointers how to extend
  310. this library and perhaps even write your own from scratch.</para>
  311. </section>
  312. <section>
  313. <title>Forensic Logging Hooks</title>
  314. <para>
  315. This section describes the forensic log hooks library. This library
  316. povides hooks that record a detailed log of lease assignments
  317. and renewals into a set of log files. Currently this library
  318. is only available to customers with a support contract.
  319. </para>
  320. <para>
  321. In many legal jurisdictions companies, especially ISPs, must record
  322. information about the addresses they have leased to DHCP clients.
  323. This library is designed to help with that requirement. If the
  324. information that it records is sufficient it may be used directly.
  325. If your jurisdiction requires that you save a different set of
  326. information you may use it as a template or example and create your
  327. own custom logging hooks.
  328. </para>
  329. <para>
  330. This logging is done as a set of hooks to allow it to be customized
  331. to any particular need. Modifying a hooks library is easier and
  332. safer than updating the core code. In addition by using the hooks
  333. features those users who don't need to log this information can
  334. leave it out and avoid any performance penalties.
  335. </para>
  336. <section>
  337. <title>Log File Naming</title>
  338. <para>
  339. The names for the log files have the following form:
  340. </para>
  341. <screen>
  342. path/base-name.CCYYMMDD.txt
  343. </screen>
  344. <para>
  345. The &quot;path&quot; and &quot;base-name&quot; are supplied in the
  346. configuration as described below see
  347. <xref linkend="forensic-log-configuration"/>. The next part of the name is
  348. the date the log file was started, with four digits for year, two digits
  349. for month and two digits for day. The file is rotated on a daily basis.
  350. </para>
  351. <note><para>
  352. When running Kea servers for both DHCPv4 and DHCPv6 the log names must
  353. be distinct. See the examples in <xref linkend="forensic-log-configuration"/>.
  354. </para></note>
  355. </section>
  356. <section>
  357. <title>DHCPv4 Log Entries</title>
  358. <para>
  359. For DHCPv4 the library creates entries based on DHCPREQUEST messages
  360. and corresponding DHCPv4 leases intercepted by lease4_select
  361. (for new leases) and lease4_renew (for renewed leases) hooks.
  362. </para>
  363. <para>
  364. An entry is a single string with no embedded end-of-line markers
  365. and has the following sections:
  366. <screen>
  367. address duration device-id {client-info} {relay-info}
  368. </screen>
  369. </para>
  370. <para>
  371. Where:
  372. <itemizedlist>
  373. <listitem><para>
  374. address - the leased IPv4 address given out and whether it was
  375. assigned or renewed.
  376. </para></listitem>
  377. <listitem><para>
  378. duration - the lease lifetime expressed in days (if present),
  379. hours, minutes and seconds. A lease lifetime of 0xFFFFFFFF will be
  380. denoted with the text &quot;infinite duration&quot;.
  381. </para></listitem>
  382. <listitem><para>
  383. device-id - the client's hardware address shown as numerical type
  384. and hex digit string.
  385. </para></listitem>
  386. <listitem><para>
  387. client-info - the DHCP client id option (61) if present, shown as
  388. a hex string.
  389. </para></listitem>
  390. <listitem><para>
  391. relay-info - for relayed packets the giaddr and the RAI circuit id
  392. and remote id options (option 82 sub options 1 and 2) if present.
  393. The circuit id and remote id are presented as hex strings
  394. </para></listitem>
  395. </itemizedlist>
  396. </para>
  397. <para>
  398. For instance (line breaks added for readability, they would not
  399. be present in the log file).
  400. <screen>
  401. Address: 192.2.1.100 has been renewed for 1 hrs 52 min 15 secs to a device with
  402. hardware address: hwtype=1 08:00:2b:02:3f:4e, client-id: 17:34:e2:ff:09:92:54
  403. connected via relay at address: 192.2.16.33, identified by circuit-id:
  404. 68:6f:77:64:79 and remote-id: 87:f6:79:77:ef
  405. </screen>
  406. </para>
  407. </section>
  408. <section>
  409. <title>DHCPv6 Log Entries</title>
  410. <para>
  411. For DHCPv6 the library creates entries based on lease management
  412. actions intercepted by the lease6_select (for new leases), lease6_renew
  413. (for renewed leases) and lease6_rebind (for rebound leases).
  414. </para>
  415. <para>
  416. An entry is a single string with no embedded end-of-line markers
  417. and has the following sections:
  418. <screen>
  419. address duration device-id {relay-info}*
  420. </screen>
  421. </para>
  422. <para>
  423. Where:
  424. <itemizedlist>
  425. <listitem><para>
  426. address - the leased IPv6 address or prefix given out and whether
  427. it was assigned or renewed.
  428. </para></listitem>
  429. <listitem><para>
  430. duration - the lease lifetime expressed in days (if present),
  431. hours, minutes and seconds. A lease lifetime of 0xFFFFFFFF will be
  432. denoted with the text "infinite duration".
  433. </para></listitem>
  434. <listitem><para>
  435. device-id - the client's DUID and hardware address (if present).
  436. </para></listitem>
  437. <listitem><para>
  438. relay-info - for relayed packets the content of relay agent
  439. messages, remote id and subscriber id options (x and xx) if present.
  440. </para></listitem>
  441. </itemizedlist>
  442. </para>
  443. <para>
  444. For instance (line breaks added for readability, they would not
  445. be present in the log file).
  446. <screen>
  447. Address:2001:db8:1:: has been assigned for 0 hrs 11 mins 53 secs to a device with
  448. DUID: 17:34:e2:ff:09:92:54 and hardware address: hwtype=1 08:00:2b:02:3f:4e
  449. (from Raw Socket) connected via relay at address: fe80::abcd for client on
  450. link address: 3001::1, hop count: 1, identified by remote-id:
  451. 01:02:03:04:0a:0b:0c:0d:0e:0f and subscriber-id: 1a:2b:3c:4d:5e:6f
  452. </screen>
  453. </para>
  454. </section>
  455. <section id="forensic-log-configuration">
  456. <title>Configuring the Forensic Log Hooks</title>
  457. <para>
  458. To use this functionality the hook library must be included in the
  459. configuration of the desired DHCP server modules. The legal_log
  460. library is installed alongside the Kea libraries in
  461. <filename>[kea-install-dir]/lib</filename> where
  462. <filename>kea-install-dir</filename> is determined by the
  463. &quot;--prefix&quot; option of the configure script. It defaults to
  464. <filename>/usr/local</filename>. Assuming the
  465. default value then, configuring kea-dhcp4 to load the legal_log
  466. library could be done with the following Kea4 configuration:
  467. <screen>
  468. "Dhcp4": { <userinput>
  469. "hooks-libraries": [
  470. {
  471. "library": "/usr/local/lib/libdhcp_legal_log.so",
  472. "parameters": {
  473. "path": "/var/kea/var",
  474. "base-name": "kea-forensic4"
  475. }
  476. },
  477. ...
  478. ] </userinput>
  479. }
  480. </screen>
  481. </para>
  482. <para>
  483. To configure it for kea-dhcp6, the commands are simply as shown below:
  484. <screen>
  485. "Dhcp6": { <userinput>
  486. "hooks-libraries": [
  487. {
  488. "library": "/usr/local/lib/libdhcp_legal_log.so",
  489. "parameters": {
  490. "path": "/var/kea/var",
  491. "base-name": "kea-forensic6"
  492. }
  493. },
  494. ...
  495. ] </userinput>
  496. }
  497. </screen>
  498. </para>
  499. <para>
  500. Two Hook Library parameters are supported:
  501. <itemizedlist>
  502. <listitem><para>
  503. path - the directory in which the forensic file(s) will be written. The
  504. default value is
  505. <filename>[prefix]/kea/var</filename>. The directory must exist.
  506. </para></listitem>
  507. <listitem><para>
  508. base-name - an arbitrary value which is used in conjunction with
  509. the current system date to form the current foresnic file name. It defaults
  510. to <filename>kea-legal</filename>.
  511. </para></listitem>
  512. </itemizedlist>
  513. </para>
  514. </section>
  515. </section>
  516. </section>
  517. </chapter> <!-- hooks-libraries -->