hooks.xml 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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 was made in Kea 1.0 to facilitate the
  80. specification of library-specific parameters, a capability
  81. available in Kea 1.1.0 onwards.
  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 the "Configuring
  102. Hooks 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 only be useful
  142. to a subset of Kea users. To this end ISC has created some hooks
  143. libraries; these 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 Kea
  148. , 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 taking out a support contract: this includes
  151. professional support, advance security notifications, input into our
  152. roadmap planning, 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 hooks 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. Unknown users
  176. will be assigned a
  177. lease from the last subnet defined in the configuration file,
  178. e.g. to redirect them a captive portal. This demonstrates how an
  179. external source of information can be used to influence the Kea
  180. allocation engine. This hook is part of the Kea source code and is
  181. available in the src/hooks/dhcp/user_chk directory.</entry>
  182. </row>
  183. <row>
  184. <entry>Forensic Logging</entry>
  185. <entry>Support customers</entry>
  186. <entry>Kea 1.1.0</entry>
  187. <entry>This library provides hooks that record a detailed log of
  188. lease assignments and renewals into a set of log files. In many
  189. legal jurisdictions companies, especially ISPs, must record
  190. information about the addresses they have leased to DHCP
  191. clients. This library is designed to help with that
  192. requirement. If the information that it records is sufficient it
  193. may be used directly. If your jurisdiction requires that you save
  194. a different set of information, you may use it as a template or
  195. example and create your own custom logging hooks.</entry>
  196. </row>
  197. <row>
  198. <entry>Flexible Identifier</entry>
  199. <entry>Support customers</entry>
  200. <entry>Kea 1.2.0 beta</entry>
  201. <entry>Kea software provides a way to handle host reservations
  202. that include addresses, prefixes, options, client classes and
  203. other features. The reservation can be based on hardware address,
  204. DUID, circuit-id or client-id in DHCPv4 and using hardware address
  205. or DUID in DHCPv6. However, there are sometimes scenario where the
  206. reservation is more complex, e.g. uses other options that
  207. mentioned above, uses part of specific options or perhaps even a
  208. combination of several options and fields to uniquely identify a
  209. client. Those scenarios are addressed by the Flexible Identifiers
  210. hook application. It allows defining an expression, similar to
  211. the one used in client classification,
  212. e.g. substring(relay6[0].option[37],0,6). Each incoming packet is
  213. evaluated against that expression and its value is then searched
  214. in the reservations database.
  215. </entry>
  216. </row>
  217. </tbody>
  218. </tgroup>
  219. </table>
  220. </para>
  221. <para>
  222. ISC hopes to see more hooks libraries become available as time
  223. progresses, both developed internally and externally. Since
  224. this list may evolve dynamically, we decided to keep it on a
  225. wiki page, available at this link: <ulink
  226. url="http://kea.isc.org/wiki/Hooks">http://kea.isc.org/wiki/Hooks</ulink>.
  227. If you are a developer or are aware of any hooks libraries not
  228. listed there, please send a note to the kea-users or kea-dev
  229. mailing lists and someone will update it.
  230. </para>
  231. <section>
  232. <title>user_chk: Checking User Access</title>
  233. <para>
  234. The user_chk library is the first hooks library published by ISC. It
  235. attempts to serve several purposes:
  236. <itemizedlist>
  237. <listitem>
  238. <para>To assign "new" or "unregistered" users to a
  239. restricted subnet, while "known" or "registered" users are assigned
  240. to unrestricted subnets.</para>
  241. </listitem>
  242. <listitem>
  243. <para>To allow DHCP response options or vendor option
  244. values to be customized based upon user identity. </para>
  245. </listitem>
  246. <listitem>
  247. <para>To provide a real time record of the user registration
  248. activity which can be sampled by an external consumer.</para>
  249. </listitem>
  250. <listitem>
  251. <para> To serve as a demonstration of various capabilities
  252. possible using the hooks interface.</para>
  253. </listitem>
  254. </itemizedlist>
  255. </para>
  256. <para>
  257. Once loaded, the library allows segregating incoming requests into
  258. known and unknown clients. For known clients, the packets are
  259. processed mostly as usual, except it is possible to override certain
  260. options being sent. That can be done on a per host basis. Clients
  261. that are not on the known hosts list will be treated as unknown and
  262. will be assigned to the last subnet defined in the configuration file.
  263. </para>
  264. <para>
  265. As an example of use, this behavior may be used to put unknown users into a
  266. separate subnet that leads to a walled garden, where they can only
  267. access a registration portal. Once they fill in necessary data, their
  268. details are added to the known clients file and they get a proper
  269. address after their device is restarted.
  270. </para>
  271. <note><para>This library was developed several years before the host
  272. reservation mechanism has become available. Currently host reservation is
  273. much more
  274. powerful and flexible, but nevertheless the user_chk capability to consult
  275. and external source of information about clients and alter Kea's
  276. behavior is useful and remains of educational value.
  277. </para></note>
  278. <para>
  279. The library reads the /tmp/user_chk_registry.txt file while being
  280. loaded and each time an incoming packet is processed. 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><command>type</command>, whose value
  285. is "HW_ADDR" for IPv4 users or "DUID" for IPv6
  286. users</para></listitem>
  287. <listitem><para><command>id</command>, whose value is
  288. either the hardware address or the DUID from the request
  289. formatted as a string of hex digits, with or without
  290. ":" delimiters.</para></listitem>
  291. </itemizedlist>
  292. and may have the zero or more of the following entries:
  293. <itemizedlist>
  294. <listitem><para><command>bootfile</command> whose value
  295. is the pathname of the desired file</para></listitem>
  296. <listitem><para><command>tftp_server</command> whose
  297. value is the hostname or IP address of the desired
  298. server</para></listitem>
  299. </itemizedlist>
  300. A sample user registry file is shown below:
  301. <screen>{ "type" : "HW_ADDR", "id" : "0c:0e:0a:01:ff:04", "bootfile" : "/tmp/v4bootfile" }
  302. { "type" : "HW_ADDR", "id" : "0c:0e:0a:01:ff:06", "tftp_server" : "tftp.v4.example.com" }
  303. { "type" : "DUID", "id" : "00:01:00:01:19:ef:e6:3b:00:0c:01:02:03:04", "bootfile" : "/tmp/v6bootfile" }
  304. { "type" : "DUID", "id" : "00:01:00:01:19:ef:e6:3b:00:0c:01:02:03:06", "tftp_server" : "tftp.v6.example.com" }</screen>
  305. </para>
  306. <para>As with any other hooks libraries provided by ISC, internals of the
  307. user_chk code are well documented. You can take a look at the <ulink
  308. 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>
  309. that discusses how the code works internally. That, together with
  310. our general entries in <ulink
  311. url="https://jenkins.isc.org/job/Fedora20_32_doxygen_doc/doxygen/">Hooks
  312. Framework section</ulink> should give you some pointers how to extend
  313. this library and perhaps even write your own from scratch.</para>
  314. </section>
  315. <section>
  316. <title>legal_log: Forensic Logging Hooks</title>
  317. <para>
  318. This section describes the forensic log hooks library. This library
  319. provides hooks that record a detailed log of lease assignments
  320. and renewals into a set of log files. Currently this library
  321. is only available to ISC customers with a support contract.
  322. </para>
  323. <para>
  324. In many legal jurisdictions companies, especially ISPs, must record
  325. information about the addresses they have leased to DHCP clients.
  326. This library is designed to help with that requirement. If the
  327. information that it records is sufficient it may be used directly.
  328. If your jurisdiction requires that you save a different set of
  329. information you may use it as a template or example and create your
  330. own custom logging hooks.
  331. </para>
  332. <para>
  333. This logging is done as a set of hooks to allow it to be customized
  334. to any particular need. Modifying a hooks library is easier and
  335. safer than updating the core code. In addition by using the hooks
  336. features those users who don't need to log this information can
  337. leave it out and avoid any performance penalties.
  338. </para>
  339. <section>
  340. <title>Log File Naming</title>
  341. <para>
  342. The names for the log files have the following form:
  343. </para>
  344. <screen>
  345. path/base-name.CCYYMMDD.txt
  346. </screen>
  347. <para>
  348. The &quot;path&quot; and &quot;base-name&quot; are supplied in the
  349. configuration as described below see
  350. <xref linkend="forensic-log-configuration"/>. The next part of the name is
  351. the date the log file was started, with four digits for year, two digits
  352. for month and two digits for day. The file is rotated on a daily basis.
  353. </para>
  354. <note><para>
  355. When running Kea servers for both DHCPv4 and DHCPv6 the log names must
  356. be distinct. See the examples in <xref linkend="forensic-log-configuration"/>.
  357. </para></note>
  358. </section>
  359. <section>
  360. <title>DHCPv4 Log Entries</title>
  361. <para>
  362. For DHCPv4 the library creates entries based on DHCPREQUEST messages
  363. and corresponding DHCPv4 leases intercepted by lease4_select
  364. (for new leases) and lease4_renew (for renewed leases) hooks.
  365. </para>
  366. <para>
  367. An entry is a single string with no embedded end-of-line markers
  368. and has the following sections:
  369. <screen>
  370. address duration device-id {client-info} {relay-info}
  371. </screen>
  372. </para>
  373. <para>
  374. Where:
  375. <itemizedlist>
  376. <listitem><para>
  377. address - the leased IPv4 address given out and whether it was
  378. assigned or renewed.
  379. </para></listitem>
  380. <listitem><para>
  381. duration - the lease lifetime expressed in days (if present),
  382. hours, minutes and seconds. A lease lifetime of 0xFFFFFFFF will be
  383. denoted with the text &quot;infinite duration&quot;.
  384. </para></listitem>
  385. <listitem><para>
  386. device-id - the client's hardware address shown as numerical type
  387. and hex digit string.
  388. </para></listitem>
  389. <listitem><para>
  390. client-info - the DHCP client id option (61) if present, shown as
  391. a hex string.
  392. </para></listitem>
  393. <listitem><para>
  394. relay-info - for relayed packets the giaddr and the RAI circuit-id,
  395. remote-id and subscriber-id options (option 82 sub
  396. options: 1, 2 and 6) if present.
  397. The circuit id and remote id are presented as hex strings
  398. </para></listitem>
  399. </itemizedlist>
  400. </para>
  401. <para>
  402. For instance (line breaks added for readability, they would not
  403. be present in the log file).
  404. <screen>
  405. Address: 192.2.1.100 has been renewed for 1 hrs 52 min 15 secs to a device with
  406. hardware address: hwtype=1 08:00:2b:02:3f:4e, client-id: 17:34:e2:ff:09:92:54
  407. connected via relay at address: 192.2.16.33, identified by circuit-id:
  408. 68:6f:77:64:79 and remote-id: 87:f6:79:77:ef
  409. </screen>
  410. </para>
  411. </section>
  412. <section>
  413. <title>DHCPv6 Log Entries</title>
  414. <para>
  415. For DHCPv6 the library creates entries based on lease management
  416. actions intercepted by the lease6_select (for new leases), lease6_renew
  417. (for renewed leases) and lease6_rebind (for rebound leases).
  418. </para>
  419. <para>
  420. An entry is a single string with no embedded end-of-line markers
  421. and has the following sections:
  422. <screen>
  423. address duration device-id {relay-info}*
  424. </screen>
  425. </para>
  426. <para>
  427. Where:
  428. <itemizedlist>
  429. <listitem><para>
  430. address - the leased IPv6 address or prefix given out and whether
  431. it was assigned or renewed.
  432. </para></listitem>
  433. <listitem><para>
  434. duration - the lease lifetime expressed in days (if present),
  435. hours, minutes and seconds. A lease lifetime of 0xFFFFFFFF will be
  436. denoted with the text "infinite duration".
  437. </para></listitem>
  438. <listitem><para>
  439. device-id - the client's DUID and hardware address (if present).
  440. </para></listitem>
  441. <listitem><para>
  442. relay-info - for relayed packets the content of relay agent
  443. messages, remote-id (code 37), subscriber-id (code 38) and
  444. interface-id (code 18) options if present. Note that
  445. interface-id option, if present, identifies the whole interface the
  446. relay agent received the message on. This typically translates to a
  447. single link in your network, but it depends on your specific network
  448. topology. Nevertheless, this is useful information to better scope
  449. down the location of the device, so it is being recorded, if present.
  450. </para></listitem>
  451. </itemizedlist>
  452. </para>
  453. <para>
  454. For instance (line breaks added for readability, they would not
  455. be present in the log file).
  456. <screen>
  457. Address:2001:db8:1:: has been assigned for 0 hrs 11 mins 53 secs to a device with
  458. DUID: 17:34:e2:ff:09:92:54 and hardware address: hwtype=1 08:00:2b:02:3f:4e
  459. (from Raw Socket) connected via relay at address: fe80::abcd for client on
  460. link address: 3001::1, hop count: 1, identified by remote-id:
  461. 01:02:03:04:0a:0b:0c:0d:0e:0f and subscriber-id: 1a:2b:3c:4d:5e:6f
  462. </screen>
  463. </para>
  464. </section>
  465. <section id="forensic-log-configuration">
  466. <title>Configuring the Forensic Log Hooks</title>
  467. <para>
  468. To use this functionality the hook library must be included in the
  469. configuration of the desired DHCP server modules. The legal_log
  470. library is installed alongside the Kea libraries in
  471. <filename>[kea-install-dir]/lib</filename> where
  472. <filename>kea-install-dir</filename> is determined by the
  473. &quot;--prefix&quot; option of the configure script. It defaults to
  474. <filename>/usr/local</filename>. Assuming the
  475. default value then, configuring kea-dhcp4 to load the legal_log
  476. library could be done with the following Kea4 configuration:
  477. <screen>
  478. "Dhcp4": { <userinput>
  479. "hooks-libraries": [
  480. {
  481. "library": "/usr/local/lib/libdhcp_legal_log.so",
  482. "parameters": {
  483. "path": "/var/kea/var",
  484. "base-name": "kea-forensic4"
  485. }
  486. },
  487. ...
  488. ] </userinput>
  489. }
  490. </screen>
  491. </para>
  492. <para>
  493. To configure it for kea-dhcp6, the commands are simply as shown below:
  494. <screen>
  495. "Dhcp6": { <userinput>
  496. "hooks-libraries": [
  497. {
  498. "library": "/usr/local/lib/libdhcp_legal_log.so",
  499. "parameters": {
  500. "path": "/var/kea/var",
  501. "base-name": "kea-forensic6"
  502. }
  503. },
  504. ...
  505. ] </userinput>
  506. }
  507. </screen>
  508. </para>
  509. <para>
  510. Two Hook Library parameters are supported:
  511. <itemizedlist>
  512. <listitem><para>
  513. path - the directory in which the forensic file(s) will be written. The
  514. default value is
  515. <filename>[prefix]/kea/var</filename>. The directory must exist.
  516. </para></listitem>
  517. <listitem><para>
  518. base-name - an arbitrary value which is used in conjunction with
  519. the current system date to form the current forensic file name. It defaults
  520. to <filename>kea-legal</filename>.
  521. </para></listitem>
  522. </itemizedlist>
  523. </para>
  524. </section>
  525. </section>
  526. <section>
  527. <title>flex_id: Flexible Identifiers for Host Reservations</title>
  528. <para>
  529. This section describes a hook application dedicated to generate
  530. flexible identifiers for host reservation. Kea software provides a way
  531. to handle host reservations that include addresses, prefixes, options,
  532. client classes and other features. The reservation can be based on
  533. hardware address, DUID, circuit-id or client-id in DHCPv4 and using
  534. hardware address or DUID in DHCPv6. However, there are sometimes
  535. scenario where the reservation is more complex, e.g. uses other
  536. options that mentioned above, uses part of specific options or perhaps
  537. even a combination of several options and fields to uniquely identify
  538. a client. Those scenarios are addressed by the Flexible Identifiers
  539. hook application.</para>
  540. <para>The library allows defining an expression, using notation
  541. initially used for client classification only. See <xref
  542. linkend="classification-using-expressions" /> for detailed description
  543. of the syntax available. One notable difference is that for client
  544. classification the expression currently has to evaluate to either true
  545. or false, while the flexible identifier expression is expected to
  546. evaluate to a string that will be used as identifier. It is a valid case
  547. for the expression to evaluate to empty string (e.g. in cases where a
  548. client does not sent specific options). This expression is then
  549. evaluated for each incoming packet. This evaluation generates an
  550. identifier that is used to identify the client. In particular, there may
  551. be host reservations that are tied to specific values of the flexible
  552. identifier.</para>
  553. <para>
  554. The library can be loaded in similar way as other hook libraries. It
  555. takes one mandatory parameter identifier-expression:
  556. <screen>
  557. "Dhcp6": { <userinput>
  558. "hooks-libraries": [
  559. {
  560. "library": "/path/libdhcp_flex_id.so",
  561. "parameters": {
  562. "identifier-expression": "<userinput>expression</userinput>"
  563. }
  564. },
  565. ...
  566. ] </userinput>
  567. }
  568. </screen>
  569. </para>
  570. <para>
  571. The flexible identifier library supports both DHCPv4 and DHCPv6.
  572. </para>
  573. <para>
  574. EXAMPLE: Let's consider a case of an IPv6 network that has an
  575. independent interface for each of the connected customers. Customers
  576. are able to plug in whatever device they want, so any type of
  577. identifier (e.g. a client-id) is unreliable. Therefore the operator
  578. may decide to use an option inserted by a relay agent to differentiate
  579. between clients. In this particular deployment, the operator verified
  580. that the interface-id is unique for each customer facing
  581. interface. Therefore it is suitable for usage as reservation. However,
  582. only the first 6 bytes of the interface-id are interesting, because
  583. remaining bytes are either randomly changed or not unique between
  584. devices. Therefore the customer decided to use first 6 bytes of the
  585. interface-id option inserted by the relay agent. This could be
  586. achieved by using the following configuration:
  587. <screen>
  588. "Dhcp6": {
  589. "subnet6": [{ ..., // subnet definition starts here
  590. "reservations": [
  591. <userinput>"flex-id": "'port1234'"</userinput>, // value of the first 8 bytes of the interface-id
  592. "ip-addresses": [ "2001:db8::1" ]
  593. ],
  594. }], // end of subnet definitions
  595. "hooks-libraries": [
  596. {
  597. "library": "/path/libdhcp_flex_id.so",
  598. "parameters": {
  599. "identifier-expression": "<userinput>substring(relay6[0].option[18],0,8)</userinput>"
  600. }
  601. },
  602. ...
  603. ]
  604. }
  605. </screen>
  606. </para>
  607. <para>
  608. NOTE: Care should be taken when adjusting the expression. If the
  609. expression changes, then all the flex-id values may change, possibly
  610. rendering all reservations based on flex-id unusable until they're
  611. manually updated. Therefore it is strongly recommended to start with
  612. the expression and a handful reservations, adjust the expression as
  613. needed and only after it was confirmed the expression does exactly
  614. what is expected out of it go forward with host reservations on any
  615. broader scale.
  616. </para>
  617. <para>
  618. flex-id values in host reservations can be specified in two
  619. ways. First, they can be expressed as hex string, e.g. bar string
  620. can be represented as 626174. Alternatively, it can be expressed
  621. as quoted value (using double and single quotes), e.g. "'bar'".
  622. The former is more convenient for printable characters, while hex
  623. string values are more convenient for non-printable characters.
  624. </para>
  625. </section>
  626. </section>
  627. <section id="user-context">
  628. <title>User contexts</title>
  629. <para>Hook libraries can have their own configuration parameters. That is
  630. convenient if the parameter applies to the whole library. However,
  631. sometimes it is very useful if certain configuration entities are extended
  632. with additional configuration data. This is where the concept of user
  633. contexts comes in. A sysadmin can define an arbitrary set of data and
  634. attach it to Kea structures, as long as the data is specified as JSON map.
  635. In particular, it is possible to define fields that are integers, strings,
  636. boolean, lists and maps. It is possible to define nested structures of
  637. arbitrary complexity. Kea does not use that data on its own, simply stores
  638. and makes it available for the hook libraries.
  639. </para>
  640. <para>
  641. As of Kea 1.2, the only structures that allow user contexts are address
  642. and prefix pools, but it is expected to extend other structures with the
  643. user context capability.
  644. </para>
  645. </section>
  646. </chapter> <!-- hooks-libraries -->