hooks.xml 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019
  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 customization. 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</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 scenarios 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. <row>
  218. <entry>Host Commands</entry>
  219. <entry>Support customers</entry>
  220. <entry>Kea 1.2.0</entry>
  221. <entry>Kea provides a way to store host reservations in a
  222. database. In many larger deployments it is useful to be able to
  223. manage that information while the server is running. This library
  224. provides management commands for adding, querying and deleting
  225. host reservations in a safe way without restarting the server.
  226. In particular, it validates the parameters, so an attempt to
  227. insert incorrect data, e.g. add a host with conflicting identifier
  228. in the same subnet will be rejected. Those commands are
  229. exposed via command channel (JSON over unix sockets) and Control
  230. Agent (JSON over RESTful interface). Additional commands and
  231. capabilities related to host reservations will be added in the
  232. future.</entry>
  233. </row>
  234. </tbody>
  235. </tgroup>
  236. </table>
  237. </para>
  238. <para>
  239. ISC hopes to see more hooks libraries become available as time
  240. progresses, both developed internally and externally. Since
  241. this list may evolve dynamically, we decided to keep it on a
  242. wiki page, available at this link: <ulink
  243. url="http://kea.isc.org/wiki/Hooks">http://kea.isc.org/wiki/Hooks</ulink>.
  244. If you are a developer or are aware of any hooks libraries not
  245. listed there, please send a note to the kea-users or kea-dev
  246. mailing lists and someone will update it.
  247. </para>
  248. <section>
  249. <title>user_chk: Checking User Access</title>
  250. <para>
  251. The user_chk library is the first hooks library published by ISC. It
  252. attempts to serve several purposes:
  253. <itemizedlist>
  254. <listitem>
  255. <para>To assign "new" or "unregistered" users to a
  256. restricted subnet, while "known" or "registered" users are assigned
  257. to unrestricted subnets.</para>
  258. </listitem>
  259. <listitem>
  260. <para>To allow DHCP response options or vendor option
  261. values to be customized based upon user identity. </para>
  262. </listitem>
  263. <listitem>
  264. <para>To provide a real time record of the user registration
  265. activity which can be sampled by an external consumer.</para>
  266. </listitem>
  267. <listitem>
  268. <para> To serve as a demonstration of various capabilities
  269. possible using the hooks interface.</para>
  270. </listitem>
  271. </itemizedlist>
  272. </para>
  273. <para>
  274. Once loaded, the library allows segregating incoming requests into
  275. known and unknown clients. For known clients, the packets are
  276. processed mostly as usual, except it is possible to override certain
  277. options being sent. That can be done on a per host basis. Clients
  278. that are not on the known hosts list will be treated as unknown and
  279. will be assigned to the last subnet defined in the configuration file.
  280. </para>
  281. <para>
  282. As an example of use, this behavior may be used to put unknown users into a
  283. separate subnet that leads to a walled garden, where they can only
  284. access a registration portal. Once they fill in necessary data, their
  285. details are added to the known clients file and they get a proper
  286. address after their device is restarted.
  287. </para>
  288. <note><para>This library was developed several years before the host
  289. reservation mechanism has become available. Currently host reservation is
  290. much more
  291. powerful and flexible, but nevertheless the user_chk capability to consult
  292. and external source of information about clients and alter Kea's
  293. behavior is useful and remains of educational value.
  294. </para></note>
  295. <para>
  296. The library reads the /tmp/user_chk_registry.txt file while being
  297. loaded and each time an incoming packet is processed. The file is expected
  298. to have each line contain a self-contained JSON snippet which must
  299. have the following two entries:
  300. <itemizedlist>
  301. <listitem><para><command>type</command>, whose value
  302. is "HW_ADDR" for IPv4 users or "DUID" for IPv6
  303. users</para></listitem>
  304. <listitem><para><command>id</command>, whose value is
  305. either the hardware address or the DUID from the request
  306. formatted as a string of hex digits, with or without
  307. ":" delimiters.</para></listitem>
  308. </itemizedlist>
  309. and may have the zero or more of the following entries:
  310. <itemizedlist>
  311. <listitem><para><command>bootfile</command> whose value
  312. is the pathname of the desired file</para></listitem>
  313. <listitem><para><command>tftp_server</command> whose
  314. value is the hostname or IP address of the desired
  315. server</para></listitem>
  316. </itemizedlist>
  317. A sample user registry file is shown below:
  318. <screen>{ "type" : "HW_ADDR", "id" : "0c:0e:0a:01:ff:04", "bootfile" : "/tmp/v4bootfile" }
  319. { "type" : "HW_ADDR", "id" : "0c:0e:0a:01:ff:06", "tftp_server" : "tftp.v4.example.com" }
  320. { "type" : "DUID", "id" : "00:01:00:01:19:ef:e6:3b:00:0c:01:02:03:04", "bootfile" : "/tmp/v6bootfile" }
  321. { "type" : "DUID", "id" : "00:01:00:01:19:ef:e6:3b:00:0c:01:02:03:06", "tftp_server" : "tftp.v6.example.com" }</screen>
  322. </para>
  323. <para>As with any other hooks libraries provided by ISC, internals of the
  324. user_chk code are well documented. You can take a look at the <ulink
  325. 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>
  326. that discusses how the code works internally. That, together with
  327. our general entries in <ulink
  328. url="https://jenkins.isc.org/job/Fedora20_32_doxygen_doc/doxygen/">Hooks
  329. Framework section</ulink> should give you some pointers how to extend
  330. this library and perhaps even write your own from scratch.</para>
  331. </section>
  332. <section>
  333. <title>legal_log: Forensic Logging Hooks</title>
  334. <para>
  335. This section describes the forensic log hooks library. This library
  336. provides hooks that record a detailed log of lease assignments
  337. and renewals into a set of log files. Currently this library
  338. is only available to ISC customers with a support contract.
  339. </para>
  340. <para>
  341. In many legal jurisdictions companies, especially ISPs, must record
  342. information about the addresses they have leased to DHCP clients.
  343. This library is designed to help with that requirement. If the
  344. information that it records is sufficient it may be used directly.
  345. If your jurisdiction requires that you save a different set of
  346. information you may use it as a template or example and create your
  347. own custom logging hooks.
  348. </para>
  349. <para>
  350. This logging is done as a set of hooks to allow it to be customized
  351. to any particular need. Modifying a hooks library is easier and
  352. safer than updating the core code. In addition by using the hooks
  353. features those users who don't need to log this information can
  354. leave it out and avoid any performance penalties.
  355. </para>
  356. <section>
  357. <title>Log File Naming</title>
  358. <para>
  359. The names for the log files have the following form:
  360. </para>
  361. <screen>
  362. path/base-name.CCYYMMDD.txt
  363. </screen>
  364. <para>
  365. The &quot;path&quot; and &quot;base-name&quot; are supplied in the
  366. configuration as described below see
  367. <xref linkend="forensic-log-configuration"/>. The next part of the name is
  368. the date the log file was started, with four digits for year, two digits
  369. for month and two digits for day. The file is rotated on a daily basis.
  370. </para>
  371. <note><para>
  372. When running Kea servers for both DHCPv4 and DHCPv6 the log names must
  373. be distinct. See the examples in <xref linkend="forensic-log-configuration"/>.
  374. </para></note>
  375. </section>
  376. <section>
  377. <title>DHCPv4 Log Entries</title>
  378. <para>
  379. For DHCPv4 the library creates entries based on DHCPREQUEST messages
  380. and corresponding DHCPv4 leases intercepted by lease4_select
  381. (for new leases) and lease4_renew (for renewed leases) hooks.
  382. </para>
  383. <para>
  384. An entry is a single string with no embedded end-of-line markers
  385. and has the following sections:
  386. <screen>
  387. address duration device-id {client-info} {relay-info}
  388. </screen>
  389. </para>
  390. <para>
  391. Where:
  392. <itemizedlist>
  393. <listitem><para>
  394. address - the leased IPv4 address given out and whether it was
  395. assigned or renewed.
  396. </para></listitem>
  397. <listitem><para>
  398. duration - the lease lifetime expressed in days (if present),
  399. hours, minutes and seconds. A lease lifetime of 0xFFFFFFFF will be
  400. denoted with the text &quot;infinite duration&quot;.
  401. </para></listitem>
  402. <listitem><para>
  403. device-id - the client's hardware address shown as numerical type
  404. and hex digit string.
  405. </para></listitem>
  406. <listitem><para>
  407. client-info - the DHCP client id option (61) if present, shown as
  408. a hex string.
  409. </para></listitem>
  410. <listitem><para>
  411. relay-info - for relayed packets the giaddr and the RAI circuit-id,
  412. remote-id and subscriber-id options (option 82 sub
  413. options: 1, 2 and 6) if present.
  414. The circuit id and remote id are presented as hex strings
  415. </para></listitem>
  416. </itemizedlist>
  417. </para>
  418. <para>
  419. For instance (line breaks added for readability, they would not
  420. be present in the log file).
  421. <screen>
  422. Address: 192.2.1.100 has been renewed for 1 hrs 52 min 15 secs to a device with
  423. hardware address: hwtype=1 08:00:2b:02:3f:4e, client-id: 17:34:e2:ff:09:92:54
  424. connected via relay at address: 192.2.16.33, identified by circuit-id:
  425. 68:6f:77:64:79 and remote-id: 87:f6:79:77:ef
  426. </screen>
  427. </para>
  428. </section>
  429. <section>
  430. <title>DHCPv6 Log Entries</title>
  431. <para>
  432. For DHCPv6 the library creates entries based on lease management
  433. actions intercepted by the lease6_select (for new leases), lease6_renew
  434. (for renewed leases) and lease6_rebind (for rebound leases).
  435. </para>
  436. <para>
  437. An entry is a single string with no embedded end-of-line markers
  438. and has the following sections:
  439. <screen>
  440. address duration device-id {relay-info}*
  441. </screen>
  442. </para>
  443. <para>
  444. Where:
  445. <itemizedlist>
  446. <listitem><para>
  447. address - the leased IPv6 address or prefix given out and whether
  448. it was assigned or renewed.
  449. </para></listitem>
  450. <listitem><para>
  451. duration - the lease lifetime expressed in days (if present),
  452. hours, minutes and seconds. A lease lifetime of 0xFFFFFFFF will be
  453. denoted with the text "infinite duration".
  454. </para></listitem>
  455. <listitem><para>
  456. device-id - the client's DUID and hardware address (if present).
  457. </para></listitem>
  458. <listitem><para>
  459. relay-info - for relayed packets the content of relay agent
  460. messages, remote-id (code 37), subscriber-id (code 38) and
  461. interface-id (code 18) options if present. Note that
  462. interface-id option, if present, identifies the whole interface the
  463. relay agent received the message on. This typically translates to a
  464. single link in your network, but it depends on your specific network
  465. topology. Nevertheless, this is useful information to better scope
  466. down the location of the device, so it is being recorded, if present.
  467. </para></listitem>
  468. </itemizedlist>
  469. </para>
  470. <para>
  471. For instance (line breaks added for readability, they would not
  472. be present in the log file).
  473. <screen>
  474. Address:2001:db8:1:: has been assigned for 0 hrs 11 mins 53 secs to a device with
  475. DUID: 17:34:e2:ff:09:92:54 and hardware address: hwtype=1 08:00:2b:02:3f:4e
  476. (from Raw Socket) connected via relay at address: fe80::abcd for client on
  477. link address: 3001::1, hop count: 1, identified by remote-id:
  478. 01:02:03:04:0a:0b:0c:0d:0e:0f and subscriber-id: 1a:2b:3c:4d:5e:6f
  479. </screen>
  480. </para>
  481. </section>
  482. <section id="forensic-log-configuration">
  483. <title>Configuring the Forensic Log Hooks</title>
  484. <para>
  485. To use this functionality the hook library must be included in the
  486. configuration of the desired DHCP server modules. The legal_log
  487. library is installed alongside the Kea libraries in
  488. <filename>[kea-install-dir]/lib</filename> where
  489. <filename>kea-install-dir</filename> is determined by the
  490. &quot;--prefix&quot; option of the configure script. It defaults to
  491. <filename>/usr/local</filename>. Assuming the
  492. default value then, configuring kea-dhcp4 to load the legal_log
  493. library could be done with the following Kea4 configuration:
  494. <screen>
  495. "Dhcp4": { <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-forensic4"
  502. }
  503. },
  504. ...
  505. ] </userinput>
  506. }
  507. </screen>
  508. </para>
  509. <para>
  510. To configure it for kea-dhcp6, the commands are simply as shown below:
  511. <screen>
  512. "Dhcp6": { <userinput>
  513. "hooks-libraries": [
  514. {
  515. "library": "/usr/local/lib/libdhcp_legal_log.so",
  516. "parameters": {
  517. "path": "/var/kea/var",
  518. "base-name": "kea-forensic6"
  519. }
  520. },
  521. ...
  522. ] </userinput>
  523. }
  524. </screen>
  525. </para>
  526. <para>
  527. Two Hook Library parameters are supported:
  528. <itemizedlist>
  529. <listitem><para>
  530. path - the directory in which the forensic file(s) will be written. The
  531. default value is
  532. <filename>[prefix]/kea/var</filename>. The directory must exist.
  533. </para></listitem>
  534. <listitem><para>
  535. base-name - an arbitrary value which is used in conjunction with
  536. the current system date to form the current forensic file name. It defaults
  537. to <filename>kea-legal</filename>.
  538. </para></listitem>
  539. </itemizedlist>
  540. </para>
  541. </section>
  542. </section>
  543. <section id="flex-id">
  544. <title>flex_id: Flexible Identifiers for Host Reservations</title>
  545. <para>
  546. This section describes a hook application dedicated to generate
  547. flexible identifiers for host reservation. Kea software provides a way
  548. to handle host reservations that include addresses, prefixes, options,
  549. client classes and other features. The reservation can be based on
  550. hardware address, DUID, circuit-id or client-id in DHCPv4 and using
  551. hardware address or DUID in DHCPv6. However, there are sometimes
  552. scenario where the reservation is more complex, e.g. uses other
  553. options that mentioned above, uses part of specific options or perhaps
  554. even a combination of several options and fields to uniquely identify
  555. a client. Those scenarios are addressed by the Flexible Identifiers
  556. hook application.</para>
  557. <para>Currently this library is only available to ISC customers with a
  558. support contract.</para>
  559. <para>The library allows for defining an expression, using notation
  560. initially used for client classification only. See <xref
  561. linkend="classification-using-expressions" /> for detailed description
  562. of the syntax available. One notable difference is that for client
  563. classification the expression currently has to evaluate to either true
  564. or false, while the flexible identifier expression is expected to
  565. evaluate to a string that will be used as identifier. It is a valid case
  566. for the expression to evaluate to empty string (e.g. in cases where a
  567. client does not sent specific options). This expression is then
  568. evaluated for each incoming packet. This evaluation generates an
  569. identifier that is used to identify the client. In particular, there may
  570. be host reservations that are tied to specific values of the flexible
  571. identifier.</para>
  572. <para>
  573. The library can be loaded in similar way as other hook libraries. It
  574. takes one mandatory parameter identifier-expression:
  575. <screen>
  576. "Dhcp6": { <userinput>
  577. "hooks-libraries": [
  578. {
  579. "library": "/path/libdhcp_flex_id.so",
  580. "parameters": {
  581. "identifier-expression": "<userinput>expression</userinput>"
  582. }
  583. },
  584. ...
  585. ] </userinput>
  586. }
  587. </screen>
  588. </para>
  589. <para>
  590. The flexible identifier library supports both DHCPv4 and DHCPv6.
  591. </para>
  592. <para>
  593. EXAMPLE: Let's consider a case of an IPv6 network that has an
  594. independent interface for each of the connected customers. Customers
  595. are able to plug in whatever device they want, so any type of
  596. identifier (e.g. a client-id) is unreliable. Therefore the operator
  597. may decide to use an option inserted by a relay agent to differentiate
  598. between clients. In this particular deployment, the operator verified
  599. that the interface-id is unique for each customer facing
  600. interface. Therefore it is suitable for usage as reservation. However,
  601. only the first 6 bytes of the interface-id are interesting, because
  602. remaining bytes are either randomly changed or not unique between
  603. devices. Therefore the customer decided to use first 6 bytes of the
  604. interface-id option inserted by the relay agent. After adding "flex-id"
  605. host-reservation-identifiers goal can be achieved by using the
  606. following configuration:
  607. <screen>
  608. "Dhcp6": {
  609. "subnet6": [{ ..., // subnet definition starts here
  610. "reservations": [
  611. <userinput>"flex-id": "'port1234'"</userinput>, // value of the first 8 bytes of the interface-id
  612. "ip-addresses": [ "2001:db8::1" ]
  613. ],
  614. }], // end of subnet definitions
  615. "host-reservation-identifiers": ["duid", "flex-id"], // add "flex-id" to reservation identifiers
  616. "hooks-libraries": [
  617. {
  618. "library": "/path/libdhcp_flex_id.so",
  619. "parameters": {
  620. "identifier-expression": "<userinput>substring(relay6[0].option[18].hex,0,8)</userinput>"
  621. }
  622. },
  623. ...
  624. ]
  625. }
  626. </screen>
  627. </para>
  628. <para>
  629. NOTE: Care should be taken when adjusting the expression. If the
  630. expression changes, then all the flex-id values may change, possibly
  631. rendering all reservations based on flex-id unusable until they're
  632. manually updated. Therefore it is strongly recommended to start with
  633. the expression and a handful reservations, adjust the expression as
  634. needed and only after it was confirmed the expression does exactly
  635. what is expected out of it go forward with host reservations on any
  636. broader scale.
  637. </para>
  638. <para>
  639. flex-id values in host reservations can be specified in two
  640. ways. First, they can be expressed as hex string, e.g. bar string
  641. can be represented as 626174. Alternatively, it can be expressed
  642. as quoted value (using double and single quotes), e.g. "'bar'".
  643. The former is more convenient for printable characters, while hex
  644. string values are more convenient for non-printable characters.
  645. </para>
  646. <screen>
  647. "Dhcp6": {
  648. "subnet6": [{ ..., // subnet definition starts here
  649. "reservations": [
  650. <userinput>"flex-id": "01:02:03:04:05:06"</userinput>, // value of the first 8 bytes of the interface-id
  651. "ip-addresses": [ "2001:db8::1" ]
  652. ],
  653. }], // end of subnet definitions
  654. "host-reservation-identifiers": ["duid", "flex-id"], // add "flex-id" to reservation identifiers
  655. "hooks-libraries": [
  656. {
  657. "library": "/path/libdhcp_flex_id.so",
  658. "parameters": {
  659. "identifier-expression": "<userinput>vendor[4491].option[1026].hex</userinput>"
  660. }
  661. },
  662. ...
  663. ]
  664. }
  665. </screen>
  666. </section>
  667. <section id="host-cmds">
  668. <title>host_cmds: Host Commands</title>
  669. <para>
  670. This section describes a hook application that offers a number of new
  671. commands used to query and manipulate host reservations. Kea provides
  672. a way to store host reservations in a database. In many larger
  673. deployments it is useful to be able to manage that information while
  674. the server is running. This library provides management commands for
  675. adding, querying and deleting host reservations in a safe way without
  676. restarting the server. In particular, it validates the parameters, so
  677. an attempt to insert incorrect data e.g. add a host with conflicting
  678. identifier in the same subnet will be rejected. Those commands are
  679. exposed via command channel (JSON over unix sockets) and Control Agent
  680. (JSON over RESTful interface). Additional commands and capabilities
  681. related to host reservations will be added in the future.
  682. </para>
  683. <para>Currently this library is only available to ISC customers with a
  684. support contract.</para>
  685. <para>
  686. Currently three commands are supported: reservation-add (which adds
  687. new host reservation), reservation-get (which returns existing
  688. reservation if specified criteria are matched) and reservation-del
  689. (which attempts to delete a reservation matching specified
  690. criteria). To use commands that change the reservation information
  691. (currently these are reservation-add and reservation-del, but this
  692. rule applies to other commands that may be implemented in the future),
  693. hosts database must be specified (see hosts-database description in
  694. <xref linkend="hosts-database-configuration4"/> and <xref
  695. linkend="hosts-database-configuration6"/>) and it must not operate in
  696. read-only mode. If the hosts-database is not specified or is running
  697. in read-only mode, the host_cmds library will load, but any attempts
  698. to use reservation-add or reservation-del will fail.
  699. </para>
  700. <para>
  701. Additional host reservation commands are planned in the future. For
  702. a description of envisaged commands, see
  703. <ulink url="http://kea.isc.org/wiki/ControlAPIRequirements">Control API
  704. Requirements </ulink> document.</para>
  705. <para>
  706. All commands are using JSON syntax. They can be issued either using
  707. control channel (see <xref linkend="ctrl-channel"/>) or via Control
  708. Agent (see <xref linkend="kea-ctrl-agent"/>).
  709. </para>
  710. <para>
  711. The library can be loaded in similar way as other hook libraries. It
  712. does not take any parameters. It supports both DHCPv4 and DHCPv6
  713. servers.
  714. <screen>
  715. "Dhcp6": { <userinput>
  716. "hooks-libraries": [
  717. {
  718. "library": "/path/libdhcp_host_cmds.so"
  719. }
  720. ...
  721. ] </userinput>
  722. }
  723. </screen>
  724. </para>
  725. <section>
  726. <title>reservation-add command</title>
  727. <para>
  728. <command>reservation-add</command> allows insertion of a new host. It
  729. takes a set of arguments that vary depending on the nature of the host
  730. reservation. Any parameters allowed in the configuration file that
  731. pertain to host reservation are permitted here. For details regarding
  732. IPv4 reservations, see <xref linkend="host-reservation-v4"/> and <xref
  733. linkend="host-reservation-v6"/>. There is one notable addition. A
  734. <command>subnet-id</command> must be specified. This parameter is
  735. mandatory, because reservations specified in the configuration file
  736. are always defined within a subnet, so the subnet they belong to is
  737. clear. This is not the case with reservation-add, therefore the
  738. subnet-id must be specified explicitly. An example command can be as
  739. simple as:
  740. <screen>{
  741. "command": "reservation-add",
  742. "arguments": {
  743. <userinput>"reservation": {
  744. "subnet-id": 1,
  745. "hw-address": "1a:1b:1c:1d:1e:1f",
  746. "ip-address": "192.0.2.202"
  747. }</userinput>
  748. }
  749. }</screen> but can also take many more parameters, for example:
  750. <screen>
  751. {
  752. "command": "reservation-add",
  753. "arguments": {
  754. <userinput>"reservation":
  755. {
  756. "subnet-id":1,
  757. "client-id": "01:0a:0b:0c:0d:0e:0f",
  758. "ip-address": "192.0.2.205",
  759. "next-server": "192.0.2.1",
  760. "server-hostname": "hal9000",
  761. "boot-file-name": "/dev/null",
  762. "option-data": [
  763. {
  764. "name": "domain-name-servers",
  765. "data": "10.1.1.202,10.1.1.203"
  766. }
  767. ],
  768. "client-classes": [ "special_snowflake", "office" ]
  769. }</userinput>
  770. }
  771. }</screen>
  772. Here is an example of complex IPv6 reservation:
  773. <screen>
  774. {
  775. "command": "reservation-add",
  776. "arguments": {
  777. <userinput>"reservation":
  778. {
  779. "subnet-id":1,
  780. "duid": "01:02:03:04:05:06:07:08:09:0A",
  781. "ip-addresses": [ "2001:db8:1:cafe::1" ],
  782. "prefixes": [ "2001:db8:2:abcd::/64" ],
  783. "hostname": "foo.example.com",
  784. "option-data": [
  785. {
  786. "name": "vendor-opts",
  787. "data": "4491"
  788. },
  789. {
  790. "name": "tftp-servers",
  791. "space": "vendor-4491",
  792. "data": "3000:1::234"
  793. }
  794. ]
  795. }</userinput>
  796. }
  797. }</screen>
  798. </para>
  799. <para>
  800. The command returns a status that indicates either a success (result
  801. 0) or a failure (result 1). Failed command always includes text
  802. parameter that explains the cause of failure. Example results:
  803. <screen>{ "result": 0, "text": "Host added." }</screen> Example failure:
  804. <screen>{ "result": 1, "text": "Mandatory 'subnet-id' parameter missing." }</screen>
  805. </para>
  806. <para>
  807. As <command>reservation-add</command> is expected to store the host,
  808. hosts-database parameter must be specified in your configuration and
  809. the database must not run in read-only mode. In the future versions
  810. it will be possible to modify the reservations read from a
  811. configuration file. Please contact ISC if you are interested in this
  812. functionality.
  813. </para>
  814. </section>
  815. <section>
  816. <title>reservation-get command</title>
  817. <para><command>reservation-get</command> can be used to query the host
  818. database and retrieve existing reservations. There are two types of
  819. parameters this command supports: (subnet-id, address) or (subnet-id,
  820. identifier-type, identifier). The first type of query is used when the
  821. address (either IPv4 or IPv6) is known, but the details of the
  822. reservation aren't. One common use case of this type of query is to
  823. find out whether a given address is reserved or not. The second query
  824. uses identifiers. For maximum flexibility, Kea stores the host
  825. identifying information as a pair of values: type and the actual
  826. identifier. Currently supported identifiers are "hw-address", "duid",
  827. "circuit-id", "client-id" and "flex-id", but additional types may be
  828. added in the future. If any new identifier types are defined in the
  829. future, reservation-get command will support them
  830. automatically.</para>
  831. <para>
  832. An example command for getting a host reservation by (subnet-id,
  833. address) pair looks as follows:
  834. <screen>
  835. {
  836. "command": "reservation-get",
  837. "arguments": {
  838. "subnet-id": 1,
  839. "ip-address": "192.0.2.202"
  840. }
  841. }</screen>
  842. An example query by (subnet-id, identifier-type, identifier) looks as follows:
  843. <screen>
  844. {
  845. "command": "reservation-get",
  846. "arguments":
  847. "subnet-id": 4,
  848. "identifier-type": "hw-address",
  849. "identifier": "01:02:03:04:05:06"
  850. }
  851. }</screen>
  852. </para>
  853. <para><command>reservation-get</command> typically returns result 0
  854. when the query was conducted properly. In particular, 0 is returned
  855. when the host was not found. If the query was successful a number
  856. of host parameters will be returned. An example of a query that
  857. did not find the host looks as follows:
  858. <screen>{ "result": 0, "text": "Host not found." }</screen>
  859. An example result returned when the host was found:
  860. <screen>{
  861. "arguments": {
  862. "boot-file-name": "bootfile.efi",
  863. "client-classes": [
  864. ],
  865. "hostname": "somehost.example.org",
  866. "hw-address": "01:02:03:04:05:06",
  867. "ip-address": "192.0.2.100",
  868. "next-server": "192.0.0.2",
  869. "option-data": [
  870. ],
  871. "server-hostname": "server-hostname.example.org"
  872. },
  873. "result": 0,
  874. "text": "Host found."
  875. }</screen>
  876. An example result returned when the query was malformed:<screen>
  877. { "result": 1, "text": "No 'ip-address' provided and 'identifier-type'
  878. is either missing or not a string." }</screen>
  879. </para>
  880. </section>
  881. <section>
  882. <title>reservation-del command</title>
  883. <para><command>reservation-del</command> can be used to delete a
  884. reservation from the host database. There are two types of parameters
  885. this command supports: (subnet-id, address) or (subnet-id,
  886. identifier-type, identifier). The first type of query is used when the
  887. address (either IPv4 or IPv6) is known, but the details of the
  888. reservation aren't. One common use case of this type of query is to
  889. remove a reservation (e.g. you want a specific address to no longer be
  890. reserved). The second query uses identifiers. For maximum flexibility,
  891. Kea stores the host identifying information as a pair of values: type
  892. and the actual identifier. Currently supported identifiers are
  893. "hw-address", "duid", "circuit-id", "client-id" and "flex-id", but
  894. additional types may be added in the future. If any new identifier
  895. types are defined in the future, reservation-get command will support
  896. them automatically.</para>
  897. <para>
  898. An example command for deleting a host reservation by (subnet-id,
  899. address) pair looks as follows:
  900. <screen>
  901. {
  902. "command": "reservation-del",
  903. "arguments": {
  904. "subnet-id": 1,
  905. "ip-address": "192.0.2.202"
  906. }
  907. }</screen>
  908. An example deletion by (subnet-id, identifier-type, identifier) looks as follows:
  909. <screen>
  910. {
  911. "command": "reservation-del",
  912. "arguments":
  913. "subnet-id": 4,
  914. "identifier-type": "hw-address",
  915. "identifier": "01:02:03:04:05:06"
  916. }
  917. }</screen>
  918. </para>
  919. <para>
  920. <command>reservation-del</command> returns result 0 when the host
  921. deletion was successful or 1 if it was not. A descriptive text is
  922. provided in case of error. Example results look as follows:
  923. <screen>
  924. {
  925. "result": 1,
  926. "text": "Host not deleted (not found)."
  927. }</screen>
  928. <screen>
  929. {
  930. "result": 0,
  931. "text": "Host deleted."
  932. }</screen>
  933. <screen>
  934. {
  935. "result": 1,
  936. "text": "Unable to delete a host because there is no hosts-database
  937. configured."
  938. }</screen>
  939. </para>
  940. </section>
  941. </section>
  942. </section>
  943. <section id="user-context">
  944. <title>User contexts</title>
  945. <para>Hook libraries can have their own configuration parameters. That is
  946. convenient if the parameter applies to the whole library. However,
  947. sometimes it is very useful if certain configuration entities are extended
  948. with additional configuration data. This is where the concept of user
  949. contexts comes in. A sysadmin can define an arbitrary set of data and
  950. attach it to Kea structures, as long as the data is specified as JSON map.
  951. In particular, it is possible to define fields that are integers, strings,
  952. boolean, lists and maps. It is possible to define nested structures of
  953. arbitrary complexity. Kea does not use that data on its own, simply stores
  954. and makes it available for the hook libraries.
  955. </para>
  956. <para>
  957. As of Kea 1.2, the only structures that allow user contexts are address
  958. and prefix pools, but it is expected to extend other structures with the
  959. user context capability.
  960. </para>
  961. </section>
  962. </chapter> <!-- hooks-libraries -->