hooks.xml 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161
  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. <row>
  235. <entry>Subnet Commands</entry>
  236. <entry>Support customers</entry>
  237. <entry>Kea 1.3.0</entry>
  238. <entry>In deployments in which subnet configuration needs to
  239. be frequently updated, it is a hard requirement that such updates be
  240. performed without the need for a full DHCP server reconfiguration
  241. or restart. This hooks library allows for incremental changes
  242. to the subnet configuration such as: adding a subnet, removing
  243. a subnet. It also allows for listing all available subnets and
  244. fetching detailed information about a selected subnet. The
  245. commands exposed by this library do not affect other subnets
  246. or configuration parameters currently used by the server.
  247. </entry>
  248. </row>
  249. </tbody>
  250. </tgroup>
  251. </table>
  252. </para>
  253. <para>
  254. ISC hopes to see more hooks libraries become available as time
  255. progresses, both developed internally and externally. Since
  256. this list may evolve dynamically, we decided to keep it on a
  257. wiki page, available at this link: <ulink
  258. url="http://kea.isc.org/wiki/Hooks">http://kea.isc.org/wiki/Hooks</ulink>.
  259. If you are a developer or are aware of any hooks libraries not
  260. listed there, please send a note to the kea-users or kea-dev
  261. mailing lists and someone will update it.
  262. </para>
  263. <section>
  264. <title>user_chk: Checking User Access</title>
  265. <para>
  266. The user_chk library is the first hooks library published by ISC. It
  267. attempts to serve several purposes:
  268. <itemizedlist>
  269. <listitem>
  270. <para>To assign "new" or "unregistered" users to a
  271. restricted subnet, while "known" or "registered" users are assigned
  272. to unrestricted subnets.</para>
  273. </listitem>
  274. <listitem>
  275. <para>To allow DHCP response options or vendor option
  276. values to be customized based upon user identity. </para>
  277. </listitem>
  278. <listitem>
  279. <para>To provide a real time record of the user registration
  280. activity which can be sampled by an external consumer.</para>
  281. </listitem>
  282. <listitem>
  283. <para> To serve as a demonstration of various capabilities
  284. possible using the hooks interface.</para>
  285. </listitem>
  286. </itemizedlist>
  287. </para>
  288. <para>
  289. Once loaded, the library allows segregating incoming requests into
  290. known and unknown clients. For known clients, the packets are
  291. processed mostly as usual, except it is possible to override certain
  292. options being sent. That can be done on a per host basis. Clients
  293. that are not on the known hosts list will be treated as unknown and
  294. will be assigned to the last subnet defined in the configuration file.
  295. </para>
  296. <para>
  297. As an example of use, this behavior may be used to put unknown users into a
  298. separate subnet that leads to a walled garden, where they can only
  299. access a registration portal. Once they fill in necessary data, their
  300. details are added to the known clients file and they get a proper
  301. address after their device is restarted.
  302. </para>
  303. <note><para>This library was developed several years before the host
  304. reservation mechanism has become available. Currently host reservation is
  305. much more
  306. powerful and flexible, but nevertheless the user_chk capability to consult
  307. and external source of information about clients and alter Kea's
  308. behavior is useful and remains of educational value.
  309. </para></note>
  310. <para>
  311. The library reads the /tmp/user_chk_registry.txt file while being
  312. loaded and each time an incoming packet is processed. The file is expected
  313. to have each line contain a self-contained JSON snippet which must
  314. have the following two entries:
  315. <itemizedlist>
  316. <listitem><para><command>type</command>, whose value
  317. is "HW_ADDR" for IPv4 users or "DUID" for IPv6
  318. users</para></listitem>
  319. <listitem><para><command>id</command>, whose value is
  320. either the hardware address or the DUID from the request
  321. formatted as a string of hex digits, with or without
  322. ":" delimiters.</para></listitem>
  323. </itemizedlist>
  324. and may have the zero or more of the following entries:
  325. <itemizedlist>
  326. <listitem><para><command>bootfile</command> whose value
  327. is the pathname of the desired file</para></listitem>
  328. <listitem><para><command>tftp_server</command> whose
  329. value is the hostname or IP address of the desired
  330. server</para></listitem>
  331. </itemizedlist>
  332. A sample user registry file is shown below:
  333. <screen>{ "type" : "HW_ADDR", "id" : "0c:0e:0a:01:ff:04", "bootfile" : "/tmp/v4bootfile" }
  334. { "type" : "HW_ADDR", "id" : "0c:0e:0a:01:ff:06", "tftp_server" : "tftp.v4.example.com" }
  335. { "type" : "DUID", "id" : "00:01:00:01:19:ef:e6:3b:00:0c:01:02:03:04", "bootfile" : "/tmp/v6bootfile" }
  336. { "type" : "DUID", "id" : "00:01:00:01:19:ef:e6:3b:00:0c:01:02:03:06", "tftp_server" : "tftp.v6.example.com" }</screen>
  337. </para>
  338. <para>As with any other hooks libraries provided by ISC, internals of the
  339. user_chk code are well documented. You can take a look at the <ulink
  340. 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>
  341. that discusses how the code works internally. That, together with
  342. our general entries in <ulink
  343. url="https://jenkins.isc.org/job/Fedora20_32_doxygen_doc/doxygen/">Hooks
  344. Framework section</ulink> should give you some pointers how to extend
  345. this library and perhaps even write your own from scratch.</para>
  346. </section>
  347. <section>
  348. <title>legal_log: Forensic Logging Hooks</title>
  349. <para>
  350. This section describes the forensic log hooks library. This library
  351. provides hooks that record a detailed log of lease assignments
  352. and renewals into a set of log files. Currently this library
  353. is only available to ISC customers with a support contract.
  354. </para>
  355. <para>
  356. In many legal jurisdictions companies, especially ISPs, must record
  357. information about the addresses they have leased to DHCP clients.
  358. This library is designed to help with that requirement. If the
  359. information that it records is sufficient it may be used directly.
  360. If your jurisdiction requires that you save a different set of
  361. information you may use it as a template or example and create your
  362. own custom logging hooks.
  363. </para>
  364. <para>
  365. This logging is done as a set of hooks to allow it to be customized
  366. to any particular need. Modifying a hooks library is easier and
  367. safer than updating the core code. In addition by using the hooks
  368. features those users who don't need to log this information can
  369. leave it out and avoid any performance penalties.
  370. </para>
  371. <section>
  372. <title>Log File Naming</title>
  373. <para>
  374. The names for the log files have the following form:
  375. </para>
  376. <screen>
  377. path/base-name.CCYYMMDD.txt
  378. </screen>
  379. <para>
  380. The &quot;path&quot; and &quot;base-name&quot; are supplied in the
  381. configuration as described below see
  382. <xref linkend="forensic-log-configuration"/>. The next part of the name is
  383. the date the log file was started, with four digits for year, two digits
  384. for month and two digits for day. The file is rotated on a daily basis.
  385. </para>
  386. <note><para>
  387. When running Kea servers for both DHCPv4 and DHCPv6 the log names must
  388. be distinct. See the examples in <xref linkend="forensic-log-configuration"/>.
  389. </para></note>
  390. </section>
  391. <section>
  392. <title>DHCPv4 Log Entries</title>
  393. <para>
  394. For DHCPv4 the library creates entries based on DHCPREQUEST messages
  395. and corresponding DHCPv4 leases intercepted by lease4_select
  396. (for new leases) and lease4_renew (for renewed leases) hooks.
  397. </para>
  398. <para>
  399. An entry is a single string with no embedded end-of-line markers
  400. and has the following sections:
  401. <screen>
  402. address duration device-id {client-info} {relay-info}
  403. </screen>
  404. </para>
  405. <para>
  406. Where:
  407. <itemizedlist>
  408. <listitem><para>
  409. address - the leased IPv4 address given out and whether it was
  410. assigned or renewed.
  411. </para></listitem>
  412. <listitem><para>
  413. duration - the lease lifetime expressed in days (if present),
  414. hours, minutes and seconds. A lease lifetime of 0xFFFFFFFF will be
  415. denoted with the text &quot;infinite duration&quot;.
  416. </para></listitem>
  417. <listitem><para>
  418. device-id - the client's hardware address shown as numerical type
  419. and hex digit string.
  420. </para></listitem>
  421. <listitem><para>
  422. client-info - the DHCP client id option (61) if present, shown as
  423. a hex string.
  424. </para></listitem>
  425. <listitem><para>
  426. relay-info - for relayed packets the giaddr and the RAI circuit-id,
  427. remote-id and subscriber-id options (option 82 sub
  428. options: 1, 2 and 6) if present.
  429. The circuit id and remote id are presented as hex strings
  430. </para></listitem>
  431. </itemizedlist>
  432. </para>
  433. <para>
  434. For instance (line breaks added for readability, they would not
  435. be present in the log file).
  436. <screen>
  437. Address: 192.2.1.100 has been renewed for 1 hrs 52 min 15 secs to a device with
  438. hardware address: hwtype=1 08:00:2b:02:3f:4e, client-id: 17:34:e2:ff:09:92:54
  439. connected via relay at address: 192.2.16.33, identified by circuit-id:
  440. 68:6f:77:64:79 and remote-id: 87:f6:79:77:ef
  441. </screen>
  442. </para>
  443. <para>
  444. In addition to logging lease activity driven by DHCPv4 client traffic, it also
  445. logs entries for the following lease management control channel commands:
  446. lease4-add, lease4-update, and lease4-del. Each entry is a single string
  447. with no embedded end-of-line markers and they will typically have the following
  448. forms:
  449. </para>
  450. <para>
  451. <command>lease4-add:</command>
  452. <screen>
  453. Administrator added a lease of address: *address* to a device with hardware address: *device-id*
  454. </screen>
  455. Dependent on the arguments of the add command, it may also include the
  456. client-id and duration.
  457. </para>
  458. <para>
  459. Example:
  460. <screen>
  461. Administrator added a lease of address: 192.0.2.202 to a device with hardware address: 1a:1b:1c:1d:1e:1f for 1 days 0 hrs 0 mins 0 secs
  462. </screen>
  463. </para>
  464. <para>
  465. <command>lease4-update:</command>
  466. <screen>
  467. Administrator updated information on the lease of address: *address* to a device with hardware address: *device-id*
  468. </screen>
  469. Dependent on the arguments of the update command, it may also include the
  470. client-id and lease duration.
  471. </para>
  472. <para>
  473. Example:
  474. <screen>
  475. Administrator updated information on the lease of address: 192.0.2.202 to a device with hardware address: 1a:1b:1c:1d:1e:1f, client-id: 1234567890
  476. </screen>
  477. </para>
  478. <para>
  479. <command>lease4-del:</command>
  480. Deletes have two forms, one by address and one by identifier and identifier type:
  481. <screen>
  482. Administrator deleted the lease for address: *address*
  483. </screen>
  484. or
  485. <screen>
  486. Administrator deleted a lease for a device identified by: *identifier-type* of *identifier*
  487. </screen>
  488. Currently only a type of @b hw-address (hardware address) is supported.
  489. </para>
  490. <para>
  491. Examples:
  492. <screen>
  493. Administrator deleted the lease for address: 192.0.2.202
  494. Administrator deleted a lease for a device identified by: hw-address of 1a:1b:1c:1d:1e:1f
  495. </screen>
  496. </para>
  497. </section>
  498. <section>
  499. <title>DHCPv6 Log Entries</title>
  500. <para>
  501. For DHCPv6 the library creates entries based on lease management
  502. actions intercepted by the lease6_select (for new leases), lease6_renew
  503. (for renewed leases) and lease6_rebind (for rebound leases).
  504. </para>
  505. <para>
  506. An entry is a single string with no embedded end-of-line markers
  507. and has the following sections:
  508. <screen>
  509. address duration device-id {relay-info}*
  510. </screen>
  511. </para>
  512. <para>
  513. Where:
  514. <itemizedlist>
  515. <listitem><para>
  516. address - the leased IPv6 address or prefix given out and whether
  517. it was assigned or renewed.
  518. </para></listitem>
  519. <listitem><para>
  520. duration - the lease lifetime expressed in days (if present),
  521. hours, minutes and seconds. A lease lifetime of 0xFFFFFFFF will be
  522. denoted with the text "infinite duration".
  523. </para></listitem>
  524. <listitem><para>
  525. device-id - the client's DUID and hardware address (if present).
  526. </para></listitem>
  527. <listitem><para>
  528. relay-info - for relayed packets the content of relay agent
  529. messages, remote-id (code 37), subscriber-id (code 38) and
  530. interface-id (code 18) options if present. Note that
  531. interface-id option, if present, identifies the whole interface the
  532. relay agent received the message on. This typically translates to a
  533. single link in your network, but it depends on your specific network
  534. topology. Nevertheless, this is useful information to better scope
  535. down the location of the device, so it is being recorded, if present.
  536. </para></listitem>
  537. </itemizedlist>
  538. </para>
  539. <para>
  540. For instance (line breaks added for readability, they would not
  541. be present in the log file).
  542. <screen>
  543. Address:2001:db8:1:: has been assigned for 0 hrs 11 mins 53 secs to a device with
  544. DUID: 17:34:e2:ff:09:92:54 and hardware address: hwtype=1 08:00:2b:02:3f:4e
  545. (from Raw Socket) connected via relay at address: fe80::abcd for client on
  546. link address: 3001::1, hop count: 1, identified by remote-id:
  547. 01:02:03:04:0a:0b:0c:0d:0e:0f and subscriber-id: 1a:2b:3c:4d:5e:6f
  548. </screen>
  549. </para>
  550. <para>
  551. In addition to logging lease activity driven by DHCPv6 client traffic, it also
  552. logs entries for the following lease management control channel commands:
  553. lease6-add, lease6-update, and lease6-del. Each entry is a single string
  554. with no embedded end-of-line markers and they will typically have the following
  555. forms:
  556. </para>
  557. <para>
  558. <command>lease6-add:</command>
  559. <screen>
  560. Administrator added a lease of address: *address* to a device with DUID: *DUID*
  561. </screen>
  562. Dependent on the arguments of the add command, it may also include the hardware address and duration.
  563. </para>
  564. <para>
  565. Example:
  566. <screen>
  567. Administrator added a lease of address: 2001:db8::3 to a device with DUID: 1a:1b:1c:1d:1e:1f:20:21:22:23:24 for 1 days 0 hrs 0 mins 0 secs
  568. </screen>
  569. </para>
  570. <para>
  571. <command>lease6-update:</command>
  572. <screen>
  573. Administrator updated information on the lease of address: *address* to a device with DUID: *DUID*
  574. </screen>
  575. Dependent on the arguments of the update command, it may also include the hardware address and lease duration.
  576. </para>
  577. <para>
  578. Example:
  579. <screen>
  580. Administrator updated information on the lease of address: 2001:db8::3 to a device with DUID: 1a:1b:1c:1d:1e:1f:20:21:22:23:24, hardware address: 1a:1b:1c:1d:1e:1f
  581. </screen>
  582. </para>
  583. <para>
  584. <command>lease6-del:</command>
  585. Deletes have two forms, one by address and one by identifier and identifier type:
  586. <screen>
  587. Administrator deleted the lease for address: *address*
  588. </screen>
  589. or
  590. <screen>
  591. Administrator deleted a lease for a device identified by: *identifier-type* of *identifier*
  592. </screen>
  593. Currently only a type of DUID is supported.
  594. </para>
  595. <para>
  596. Examples:
  597. <screen>
  598. Administrator deleted the lease for address: 2001:db8::3
  599. Administrator deleted a lease for a device identified by: duid of 1a:1b:1c:1d:1e:1f:20:21:22:23:24
  600. </screen>
  601. </para>
  602. </section>
  603. <section id="forensic-log-configuration">
  604. <title>Configuring the Forensic Log Hooks</title>
  605. <para>
  606. To use this functionality the hook library must be included in the
  607. configuration of the desired DHCP server modules. The legal_log
  608. library is installed alongside the Kea libraries in
  609. <filename>[kea-install-dir]/lib</filename> where
  610. <filename>kea-install-dir</filename> is determined by the
  611. &quot;--prefix&quot; option of the configure script. It defaults to
  612. <filename>/usr/local</filename>. Assuming the
  613. default value then, configuring kea-dhcp4 to load the legal_log
  614. library could be done with the following Kea4 configuration:
  615. <screen>
  616. "Dhcp4": { <userinput>
  617. "hooks-libraries": [
  618. {
  619. "library": "/usr/local/lib/libdhcp_legal_log.so",
  620. "parameters": {
  621. "path": "/var/kea/var",
  622. "base-name": "kea-forensic4"
  623. }
  624. },
  625. ...
  626. ] </userinput>
  627. }
  628. </screen>
  629. </para>
  630. <para>
  631. To configure it for kea-dhcp6, the commands are simply as shown below:
  632. <screen>
  633. "Dhcp6": { <userinput>
  634. "hooks-libraries": [
  635. {
  636. "library": "/usr/local/lib/libdhcp_legal_log.so",
  637. "parameters": {
  638. "path": "/var/kea/var",
  639. "base-name": "kea-forensic6"
  640. }
  641. },
  642. ...
  643. ] </userinput>
  644. }
  645. </screen>
  646. </para>
  647. <para>
  648. Two Hook Library parameters are supported:
  649. <itemizedlist>
  650. <listitem><para>
  651. path - the directory in which the forensic file(s) will be written. The
  652. default value is
  653. <filename>[prefix]/kea/var</filename>. The directory must exist.
  654. </para></listitem>
  655. <listitem><para>
  656. base-name - an arbitrary value which is used in conjunction with
  657. the current system date to form the current forensic file name. It defaults
  658. to <filename>kea-legal</filename>.
  659. </para></listitem>
  660. </itemizedlist>
  661. </para>
  662. </section>
  663. </section>
  664. <section id="flex-id">
  665. <title>flex_id: Flexible Identifiers for Host Reservations</title>
  666. <para>
  667. This section describes a hook application dedicated to generate
  668. flexible identifiers for host reservation. Kea software provides a way
  669. to handle host reservations that include addresses, prefixes, options,
  670. client classes and other features. The reservation can be based on
  671. hardware address, DUID, circuit-id or client-id in DHCPv4 and using
  672. hardware address or DUID in DHCPv6. However, there are sometimes
  673. scenarios where the reservation is more complex, e.g. uses other
  674. options that mentioned above, uses part of specific options or perhaps
  675. even a combination of several options and fields to uniquely identify
  676. a client. Those scenarios are addressed by the Flexible Identifiers
  677. hook application.</para>
  678. <para>Currently this library is only available to ISC customers with a
  679. support contract.</para>
  680. <para>The library allows for defining an expression, using notation
  681. initially used for client classification only. See <xref
  682. linkend="classification-using-expressions" /> for detailed description
  683. of the syntax available. One notable difference is that for client
  684. classification the expression currently has to evaluate to either true
  685. or false, while the flexible identifier expression is expected to
  686. evaluate to a string that will be used as identifier. It is a valid case
  687. for the expression to evaluate to empty string (e.g. in cases where a
  688. client does not sent specific options). This expression is then
  689. evaluated for each incoming packet. This evaluation generates an
  690. identifier that is used to identify the client. In particular, there may
  691. be host reservations that are tied to specific values of the flexible
  692. identifier.</para>
  693. <para>
  694. The library can be loaded in similar way as other hook libraries. It
  695. takes a mandatory parameter identifier-expression and optional
  696. boolean parameter replace-client-id:
  697. <screen>
  698. "Dhcp6": { <userinput>
  699. "hooks-libraries": [
  700. {
  701. "library": "/path/libdhcp_flex_id.so",
  702. "parameters": {
  703. "identifier-expression": "<userinput>expression</userinput>",
  704. "replace-client-id": "<userinput>false</userinput>"
  705. }
  706. },
  707. ...
  708. ] </userinput>
  709. }
  710. </screen>
  711. </para>
  712. <para>
  713. The flexible identifier library supports both DHCPv4 and DHCPv6.
  714. </para>
  715. <para>
  716. EXAMPLE: Let's consider a case of an IPv6 network that has an
  717. independent interface for each of the connected customers. Customers
  718. are able to plug in whatever device they want, so any type of
  719. identifier (e.g. a client-id) is unreliable. Therefore the operator
  720. may decide to use an option inserted by a relay agent to differentiate
  721. between clients. In this particular deployment, the operator verified
  722. that the interface-id is unique for each customer facing
  723. interface. Therefore it is suitable for usage as reservation. However,
  724. only the first 6 bytes of the interface-id are interesting, because
  725. remaining bytes are either randomly changed or not unique between
  726. devices. Therefore the customer decided to use first 6 bytes of the
  727. interface-id option inserted by the relay agent. After adding "flex-id"
  728. host-reservation-identifiers goal can be achieved by using the
  729. following configuration:
  730. <screen>
  731. "Dhcp6": {
  732. "subnet6": [{ ..., // subnet definition starts here
  733. "reservations": [
  734. <userinput>"flex-id": "'port1234'"</userinput>, // value of the first 8 bytes of the interface-id
  735. "ip-addresses": [ "2001:db8::1" ]
  736. ],
  737. }], // end of subnet definitions
  738. "host-reservation-identifiers": ["duid", "flex-id"], // add "flex-id" to reservation identifiers
  739. "hooks-libraries": [
  740. {
  741. "library": "/path/libdhcp_flex_id.so",
  742. "parameters": {
  743. "identifier-expression": "<userinput>substring(relay6[0].option[18].hex,0,8)</userinput>"
  744. }
  745. },
  746. ...
  747. ]
  748. }
  749. </screen>
  750. </para>
  751. <para>
  752. NOTE: Care should be taken when adjusting the expression. If the
  753. expression changes, then all the flex-id values may change, possibly
  754. rendering all reservations based on flex-id unusable until they're
  755. manually updated. Therefore it is strongly recommended to start with
  756. the expression and a handful reservations, adjust the expression as
  757. needed and only after it was confirmed the expression does exactly
  758. what is expected out of it go forward with host reservations on any
  759. broader scale.
  760. </para>
  761. <para>
  762. flex-id values in host reservations can be specified in two
  763. ways. First, they can be expressed as hex string, e.g. bar string
  764. can be represented as 626174. Alternatively, it can be expressed
  765. as quoted value (using double and single quotes), e.g. "'bar'".
  766. The former is more convenient for printable characters, while hex
  767. string values are more convenient for non-printable characters.
  768. </para>
  769. <screen>
  770. "Dhcp6": {
  771. "subnet6": [{ ..., // subnet definition starts here
  772. "reservations": [
  773. <userinput>"flex-id": "01:02:03:04:05:06"</userinput>, // value of the first 8 bytes of the interface-id
  774. "ip-addresses": [ "2001:db8::1" ]
  775. ],
  776. }], // end of subnet definitions
  777. "host-reservation-identifiers": ["duid", "flex-id"], // add "flex-id" to reservation identifiers
  778. "hooks-libraries": [
  779. {
  780. "library": "/path/libdhcp_flex_id.so",
  781. "parameters": {
  782. "identifier-expression": "<userinput>vendor[4491].option[1026].hex</userinput>"
  783. }
  784. },
  785. ...
  786. ]
  787. }
  788. </screen>
  789. <para>
  790. When "replace-client-id" is set to false (which is the default setting),
  791. the flex-id hook library uses evaluated flexible identifier solely for
  792. identifying host reservations, i.e. searching for reservations within a
  793. database. This is a functional equivalent of other identifiers,
  794. similar to hardware address or circuit-id. However,
  795. this mode of operation has an implication that if a client device is
  796. replaced, it may cause a conflict between an existing lease (allocated
  797. for old device) and the new lease being allocated for the new device. The
  798. conflict arises because the same flexible identifier is computed for the
  799. replaced device and the server will try to allocate the same lease. The
  800. mismatch between client identifiers sent by new device and old device causes
  801. the server to refuse this new allocation until the old lease expires.
  802. A manifestation of this problem is dependant on specific expression
  803. used as flexible identifier and is likely to appear if you only use options
  804. and other parameters that are identifying where the device is
  805. connected (e.g. circuit-id), rather than the device identification
  806. itself (e.g. MAC address).
  807. </para>
  808. <para>
  809. The flex-id library offers a way to overcome the problem with lease conflicts
  810. by dynamically replacing client identifier (or DUID in DHCPv6 case) with a
  811. value derived from flexible identifier. The server processes the client's
  812. query as if flexible identifier was sent in the client identifier (or DUID)
  813. option. This guarantees that returning client (for which the same flexible
  814. identifier is evaluated) will be assigned the same lease desplite the client
  815. identifier and/or MAC address change.
  816. </para>
  817. <para>
  818. The following is a stub configuration that enables this behavior:
  819. <screen>
  820. "Dhcp4": { <userinput>
  821. "hooks-libraries": [
  822. {
  823. "library": "/path/libdhcp_flex_id.so",
  824. "parameters": {
  825. "identifier-expression": "<userinput>expression</userinput>",
  826. "replace-client-id": "<userinput>true</userinput>"
  827. }
  828. },
  829. ...
  830. ] </userinput>
  831. }
  832. </screen>
  833. </para>
  834. <para>
  835. Note that for this mechanism to take effect, the DHCPv4 server must be configured
  836. to respect the client identifier option value during lease allocation, i.e.
  837. "match-client-id" must be set to true. See
  838. <xref linkend="dhcp4-match-client-id"/> for details. No additional settings
  839. are required for DHCPv6.
  840. </para>
  841. <para>
  842. If "replace-client-id" option is set to true, the value of "echo-client-id"
  843. parameter (that governs whether to send back a client-id option or
  844. not) is ignored.
  845. </para>
  846. </section>
  847. <section id="host-cmds">
  848. <title>host_cmds: Host Commands</title>
  849. <para>
  850. This section describes a hook application that offers a number of new
  851. commands used to query and manipulate host reservations. Kea provides
  852. a way to store host reservations in a database. In many larger
  853. deployments it is useful to be able to manage that information while
  854. the server is running. This library provides management commands for
  855. adding, querying and deleting host reservations in a safe way without
  856. restarting the server. In particular, it validates the parameters, so
  857. an attempt to insert incorrect data e.g. add a host with conflicting
  858. identifier in the same subnet will be rejected. Those commands are
  859. exposed via command channel (JSON over unix sockets) and Control Agent
  860. (JSON over RESTful interface). Additional commands and capabilities
  861. related to host reservations will be added in the future.
  862. </para>
  863. <para>Currently this library is only available to ISC customers with a
  864. support contract.</para>
  865. <para>
  866. Currently three commands are supported: reservation-add (which adds
  867. new host reservation), reservation-get (which returns existing
  868. reservation if specified criteria are matched) and reservation-del
  869. (which attempts to delete a reservation matching specified
  870. criteria). To use commands that change the reservation information
  871. (currently these are reservation-add and reservation-del, but this
  872. rule applies to other commands that may be implemented in the future),
  873. hosts database must be specified (see hosts-database description in
  874. <xref linkend="hosts-database-configuration4"/> and <xref
  875. linkend="hosts-database-configuration6"/>) and it must not operate in
  876. read-only mode. If the hosts-database is not specified or is running
  877. in read-only mode, the host_cmds library will load, but any attempts
  878. to use reservation-add or reservation-del will fail.
  879. </para>
  880. <para>
  881. Additional host reservation commands are planned in the future. For
  882. a description of envisaged commands, see
  883. <ulink url="http://kea.isc.org/wiki/ControlAPIRequirements">Control API
  884. Requirements </ulink> document.</para>
  885. <para>
  886. All commands are using JSON syntax. They can be issued either using
  887. control channel (see <xref linkend="ctrl-channel"/>) or via Control
  888. Agent (see <xref linkend="kea-ctrl-agent"/>).
  889. </para>
  890. <para>
  891. The library can be loaded in similar way as other hook libraries. It
  892. does not take any parameters. It supports both DHCPv4 and DHCPv6
  893. servers.
  894. <screen>
  895. "Dhcp6": { <userinput>
  896. "hooks-libraries": [
  897. {
  898. "library": "/path/libdhcp_host_cmds.so"
  899. }
  900. ...
  901. ] </userinput>
  902. }
  903. </screen>
  904. </para>
  905. <section>
  906. <title>reservation-add command</title>
  907. <para>
  908. <command>reservation-add</command> allows insertion of a new host. It
  909. takes a set of arguments that vary depending on the nature of the host
  910. reservation. Any parameters allowed in the configuration file that
  911. pertain to host reservation are permitted here. For details regarding
  912. IPv4 reservations, see <xref linkend="host-reservation-v4"/> and <xref
  913. linkend="host-reservation-v6"/>. There is one notable addition. A
  914. <command>subnet-id</command> must be specified. This parameter is
  915. mandatory, because reservations specified in the configuration file
  916. are always defined within a subnet, so the subnet they belong to is
  917. clear. This is not the case with reservation-add, therefore the
  918. subnet-id must be specified explicitly. An example command can be as
  919. simple as:
  920. <screen>{
  921. "command": "reservation-add",
  922. "arguments": {
  923. <userinput>"reservation": {
  924. "subnet-id": 1,
  925. "hw-address": "1a:1b:1c:1d:1e:1f",
  926. "ip-address": "192.0.2.202"
  927. }</userinput>
  928. }
  929. }</screen> but can also take many more parameters, for example:
  930. <screen>
  931. {
  932. "command": "reservation-add",
  933. "arguments": {
  934. <userinput>"reservation":
  935. {
  936. "subnet-id":1,
  937. "client-id": "01:0a:0b:0c:0d:0e:0f",
  938. "ip-address": "192.0.2.205",
  939. "next-server": "192.0.2.1",
  940. "server-hostname": "hal9000",
  941. "boot-file-name": "/dev/null",
  942. "option-data": [
  943. {
  944. "name": "domain-name-servers",
  945. "data": "10.1.1.202,10.1.1.203"
  946. }
  947. ],
  948. "client-classes": [ "special_snowflake", "office" ]
  949. }</userinput>
  950. }
  951. }</screen>
  952. Here is an example of complex IPv6 reservation:
  953. <screen>
  954. {
  955. "command": "reservation-add",
  956. "arguments": {
  957. <userinput>"reservation":
  958. {
  959. "subnet-id":1,
  960. "duid": "01:02:03:04:05:06:07:08:09:0A",
  961. "ip-addresses": [ "2001:db8:1:cafe::1" ],
  962. "prefixes": [ "2001:db8:2:abcd::/64" ],
  963. "hostname": "foo.example.com",
  964. "option-data": [
  965. {
  966. "name": "vendor-opts",
  967. "data": "4491"
  968. },
  969. {
  970. "name": "tftp-servers",
  971. "space": "vendor-4491",
  972. "data": "3000:1::234"
  973. }
  974. ]
  975. }</userinput>
  976. }
  977. }</screen>
  978. </para>
  979. <para>
  980. The command returns a status that indicates either a success (result
  981. 0) or a failure (result 1). Failed command always includes text
  982. parameter that explains the cause of failure. Example results:
  983. <screen>{ "result": 0, "text": "Host added." }</screen> Example failure:
  984. <screen>{ "result": 1, "text": "Mandatory 'subnet-id' parameter missing." }</screen>
  985. </para>
  986. <para>
  987. As <command>reservation-add</command> is expected to store the host,
  988. hosts-database parameter must be specified in your configuration and
  989. the database must not run in read-only mode. In the future versions
  990. it will be possible to modify the reservations read from a
  991. configuration file. Please contact ISC if you are interested in this
  992. functionality.
  993. </para>
  994. </section>
  995. <section>
  996. <title>reservation-get command</title>
  997. <para><command>reservation-get</command> can be used to query the host
  998. database and retrieve existing reservations. There are two types of
  999. parameters this command supports: (subnet-id, address) or (subnet-id,
  1000. identifier-type, identifier). The first type of query is used when the
  1001. address (either IPv4 or IPv6) is known, but the details of the
  1002. reservation aren't. One common use case of this type of query is to
  1003. find out whether a given address is reserved or not. The second query
  1004. uses identifiers. For maximum flexibility, Kea stores the host
  1005. identifying information as a pair of values: type and the actual
  1006. identifier. Currently supported identifiers are "hw-address", "duid",
  1007. "circuit-id", "client-id" and "flex-id", but additional types may be
  1008. added in the future. If any new identifier types are defined in the
  1009. future, reservation-get command will support them
  1010. automatically.</para>
  1011. <para>
  1012. An example command for getting a host reservation by (subnet-id,
  1013. address) pair looks as follows:
  1014. <screen>
  1015. {
  1016. "command": "reservation-get",
  1017. "arguments": {
  1018. "subnet-id": 1,
  1019. "ip-address": "192.0.2.202"
  1020. }
  1021. }</screen>
  1022. An example query by (subnet-id, identifier-type, identifier) looks as follows:
  1023. <screen>
  1024. {
  1025. "command": "reservation-get",
  1026. "arguments":
  1027. "subnet-id": 4,
  1028. "identifier-type": "hw-address",
  1029. "identifier": "01:02:03:04:05:06"
  1030. }
  1031. }</screen>
  1032. </para>
  1033. <para><command>reservation-get</command> typically returns result 0
  1034. when the query was conducted properly. In particular, 0 is returned
  1035. when the host was not found. If the query was successful a number
  1036. of host parameters will be returned. An example of a query that
  1037. did not find the host looks as follows:
  1038. <screen>{ "result": 0, "text": "Host not found." }</screen>
  1039. An example result returned when the host was found:
  1040. <screen>{
  1041. "arguments": {
  1042. "boot-file-name": "bootfile.efi",
  1043. "client-classes": [
  1044. ],
  1045. "hostname": "somehost.example.org",
  1046. "hw-address": "01:02:03:04:05:06",
  1047. "ip-address": "192.0.2.100",
  1048. "next-server": "192.0.0.2",
  1049. "option-data": [
  1050. ],
  1051. "server-hostname": "server-hostname.example.org"
  1052. },
  1053. "result": 0,
  1054. "text": "Host found."
  1055. }</screen>
  1056. An example result returned when the query was malformed:<screen>
  1057. { "result": 1, "text": "No 'ip-address' provided and 'identifier-type'
  1058. is either missing or not a string." }</screen>
  1059. </para>
  1060. </section>
  1061. <section>
  1062. <title>reservation-del command</title>
  1063. <para><command>reservation-del</command> can be used to delete a
  1064. reservation from the host database. There are two types of parameters
  1065. this command supports: (subnet-id, address) or (subnet-id,
  1066. identifier-type, identifier). The first type of query is used when the
  1067. address (either IPv4 or IPv6) is known, but the details of the
  1068. reservation aren't. One common use case of this type of query is to
  1069. remove a reservation (e.g. you want a specific address to no longer be
  1070. reserved). The second query uses identifiers. For maximum flexibility,
  1071. Kea stores the host identifying information as a pair of values: type
  1072. and the actual identifier. Currently supported identifiers are
  1073. "hw-address", "duid", "circuit-id", "client-id" and "flex-id", but
  1074. additional types may be added in the future. If any new identifier
  1075. types are defined in the future, reservation-get command will support
  1076. them automatically.</para>
  1077. <para>
  1078. An example command for deleting a host reservation by (subnet-id,
  1079. address) pair looks as follows:
  1080. <screen>
  1081. {
  1082. "command": "reservation-del",
  1083. "arguments": {
  1084. "subnet-id": 1,
  1085. "ip-address": "192.0.2.202"
  1086. }
  1087. }</screen>
  1088. An example deletion by (subnet-id, identifier-type, identifier) looks as follows:
  1089. <screen>
  1090. {
  1091. "command": "reservation-del",
  1092. "arguments":
  1093. "subnet-id": 4,
  1094. "identifier-type": "hw-address",
  1095. "identifier": "01:02:03:04:05:06"
  1096. }
  1097. }</screen>
  1098. </para>
  1099. <para>
  1100. <command>reservation-del</command> returns result 0 when the host
  1101. deletion was successful or 1 if it was not. A descriptive text is
  1102. provided in case of error. Example results look as follows:
  1103. <screen>
  1104. {
  1105. "result": 1,
  1106. "text": "Host not deleted (not found)."
  1107. }</screen>
  1108. <screen>
  1109. {
  1110. "result": 0,
  1111. "text": "Host deleted."
  1112. }</screen>
  1113. <screen>
  1114. {
  1115. "result": 1,
  1116. "text": "Unable to delete a host because there is no hosts-database
  1117. configured."
  1118. }</screen>
  1119. </para>
  1120. </section>
  1121. </section>
  1122. <!-- ================================================================= -->
  1123. <!-- === lease_cmds ================================================== -->
  1124. <!-- ================================================================= -->
  1125. <section id="lease-cmds">
  1126. <title>lease_cmds: Lease Commands</title>
  1127. <para>
  1128. This section describes the hook library that offers a number of new
  1129. commands used to manage leases. Kea provides a way to store lease
  1130. information in several backends (memfile, MySQL, PostgreSQL and
  1131. Cassandra). This library provides a unified interface that can
  1132. manipulate leases in an unified, safe way. In particular, it allows
  1133. things previously impossible: manipulate leases in memfile while Kea
  1134. is running, sanity check changes, check lease existence and remove all
  1135. leases belonging to specific subnet. It can also catch more obscure
  1136. errors, like adding a lease with subnet-id that does not exist in the
  1137. configuration or configuring a lease to use an address that is outside
  1138. of the subnet to which it is supposed to belong.
  1139. </para>
  1140. <para>There are many use cases when an administrative command may be
  1141. useful: during migration between servers (possibly even between
  1142. different vendors), when a certain network is being retired, when a
  1143. device has been disconnected and the sysadmin knows for sure that it
  1144. will not be coming back. The "get" queries may be useful for automating
  1145. certain management and monitoring tasks. They can also act as
  1146. preparatory steps for lease updates and removals.</para>
  1147. <para>
  1148. This library provides the following commands:
  1149. <itemizedlist>
  1150. <listitem>
  1151. <para><command>lease4-add</command> - adds new IPv4 lease;</para>
  1152. </listitem>
  1153. <listitem>
  1154. <para><command>lease6-add</command> - adds new IPv6 lease;</para>
  1155. </listitem>
  1156. <listitem>
  1157. <para><command>lease4-get</command> - checks if an IPv4 lease with
  1158. the specified parameters exists and returns it if it does;</para>
  1159. </listitem>
  1160. <listitem>
  1161. <para><command>lease6-get</command> - checks if an IPv6 lease with
  1162. the specified parameters exists and returns it if it does;</para>
  1163. </listitem>
  1164. <listitem>
  1165. <para><command>lease4-del</command> - attempts to delete an IPv4
  1166. lease with the specified parameters;</para>
  1167. </listitem>
  1168. <listitem>
  1169. <para><command>lease6-del</command> - attempts to delete an IPv6
  1170. lease with the specified parameters;</para>
  1171. </listitem>
  1172. <listitem>
  1173. <para><command>lease4-update</command> - updates an IPv4 lease;</para>
  1174. </listitem>
  1175. <listitem>
  1176. <para><command>lease6-update</command> - updates an IPv6 lease;</para>
  1177. </listitem>
  1178. <listitem>
  1179. <para><command>lease4-wipe</command> - removes all leases from a
  1180. specific IPv4 subnet;</para>
  1181. </listitem>
  1182. <listitem>
  1183. <para><command>lease6-wipe</command> - removes all leases from a
  1184. specific IPv6 subnet;</para>
  1185. </listitem>
  1186. </itemizedlist>
  1187. </para>
  1188. <para>Lease commands library is part of the open source code and is
  1189. available to every Kea user.</para>
  1190. <para>
  1191. All commands are using JSON syntax. They can be issued either using
  1192. control channel (see <xref linkend="ctrl-channel"/>) or via Control
  1193. Agent (see <xref linkend="kea-ctrl-agent"/>).
  1194. </para>
  1195. <para>
  1196. The library can be loaded in the same way as other hook libraries. It
  1197. does not take any parameters. It supports both DHCPv4 and DHCPv6
  1198. servers.
  1199. <screen>
  1200. "Dhcp6": { <userinput>
  1201. "hooks-libraries": [
  1202. {
  1203. "library": "/path/libdhcp_lease_cmds.so"
  1204. }
  1205. ...
  1206. ] </userinput>
  1207. }
  1208. </screen>
  1209. </para>
  1210. <section>
  1211. <title>lease4-add, lease6-add commands</title>
  1212. <para>
  1213. <command>lease4-add</command> and <command>lease6-add</command>
  1214. commands allow creation of a new lease. Typically Kea creates a lease
  1215. on its own, when it first sees a new device. However, sometimes it may
  1216. be convenient to create the lease administratively. The
  1217. <command>lease4-add</command> command requires at least three
  1218. parameters: an IPv4 address, a subnet-id and an identifier: hardware
  1219. (MAC) address. The simplest successful call might look as follows:
  1220. <screen>
  1221. {
  1222. "command": "lease4-add",
  1223. "arguments": {
  1224. "subnet-id": 44,
  1225. "ip-address": "192.0.2.202",
  1226. "hw-address": "1a:1b:1c:1d:1e:1f"
  1227. }
  1228. }
  1229. </screen>
  1230. </para>
  1231. <para><command>lease6-add</command> command requires four
  1232. parameters: an IPv6 address, a subnet-id, and IAID value
  1233. (identity association identifier, a value sent by clients) and
  1234. a DUID:
  1235. <screen>
  1236. {
  1237. "command": "lease6-add",
  1238. "arguments": {
  1239. "subnet-id": 66,
  1240. "ip-address": "2001:db8::3",
  1241. "duid": "1a:1b:1c:1d:1e:1f:20:21:22:23:24",
  1242. "iaid": 1234
  1243. }
  1244. }</screen>
  1245. <command>lease6-add</command> can be also used to add leases for IPv6
  1246. prefixes. In this case there are two parameters that must be
  1247. specified: type (set to value of &quot;IA_PD&quot;) and a prefix
  1248. length. The actual prefix is set using ip-address field. For example,
  1249. to configure a lease for prefix 2001:db8:abcd::/48, the following
  1250. command can be used:
  1251. <screen>
  1252. {
  1253. "command": "lease6-add",
  1254. "arguments": {
  1255. "subnet-id": 66,
  1256. "type": "IA_PD",
  1257. "ip-address": "2001:db8:abcd::",
  1258. "prefix-len": 48,
  1259. "duid": "1a:1b:1c:1d:1e:1f:20:21:22:23:24",
  1260. "iaid": 1234
  1261. }
  1262. }</screen>
  1263. The commands can take a number of additional optional parameters:
  1264. <itemizedlist>
  1265. <listitem>
  1266. <para><command>valid-lft</command> - specifies the lifetime of the
  1267. lease, expressed in seconds. If not specified, the value
  1268. configured in the subnet related to specified subnet-id is
  1269. used.</para>
  1270. </listitem>
  1271. <listitem>
  1272. <para><command>expire</command> - timestamp of the lease
  1273. expiration time, expressed in unix format (seconds since 1 Jan
  1274. 1970). If not specified, the default value is now + valid
  1275. lifetime.</para>
  1276. </listitem>
  1277. <listitem>
  1278. <para><command>fqdn-fwd</command> - specifies whether the lease
  1279. should be marked as if forward DNS update was conducted. Note this
  1280. only affects the lease parameter and the actual DNS update will
  1281. not be conducted at the lease insertion time. If configured, a DNS
  1282. update to remove the A or AAAA records will be conducted when the
  1283. lease is removed due to expiration or being released by a
  1284. client. If not specified, the default value is false. Hostname
  1285. parameter must be specified in fqdn-fwd is set to true.</para>
  1286. </listitem>
  1287. <listitem>
  1288. <para><command>fqdn-rev</command> - specifies whether the lease
  1289. should be marked as if reverse DNS update was conducted. Note this
  1290. only affects the lease parameter and the actual DNS update will
  1291. not be conducted at the lease insertion time. If configured, a DNS
  1292. update to remove the PTR record will be conducted when the lease
  1293. is removed due to expiration or being released by a client. If not
  1294. specified, the default value is false. Hostname parameter must be
  1295. specified in fqdn-fwd is set to true.</para>
  1296. </listitem>
  1297. <listitem>
  1298. <para><command>hostname</command> - specifies the hostname to be
  1299. associated with this lease. Its value must be non-empty if either
  1300. fqdn-fwd or fwdn-rev are set to true. If not specified, the
  1301. default value is an empty string.</para>
  1302. </listitem>
  1303. <listitem>
  1304. <para><command>hw-address</command> - hardware (MAC) address can
  1305. be optionally specified for IPv6 lease. It is mandatory parameter
  1306. for IPv4 lease.</para>
  1307. </listitem>
  1308. <listitem>
  1309. <para><command>client-id</command> - client identifier is an
  1310. optional parameter that can be specified for IPv4 lease.</para>
  1311. </listitem>
  1312. <listitem>
  1313. <para><command>preferred-lft</command> - Preferred lifetime is an
  1314. optional parameter for IPv6 leases. If not specified, the value
  1315. configured for the subnet corresponding to the specified subnet-id
  1316. is used. This parameter is not used in IPv4.</para>
  1317. </listitem>
  1318. </itemizedlist>
  1319. </para>
  1320. <para>Here's an example of more complex lease addition:
  1321. <screen>
  1322. {
  1323. "command": "lease6-add",
  1324. "arguments": {
  1325. "subnet-id": 66,
  1326. "ip-address": "2001:db8::3",
  1327. "duid": "01:02:03:04:05:06:07:08",
  1328. "iaid": 1234,
  1329. "hw-address": "1a:1b:1c:1d:1e:1f",
  1330. "preferred-lft": 500,
  1331. "valid-lft": 1000,
  1332. "expire": 12345678,
  1333. "fqdn-fwd": true,
  1334. "fqdn-rev": true,
  1335. "hostname": "urania.example.org"
  1336. }
  1337. }
  1338. </screen>
  1339. </para>
  1340. <para>
  1341. The command returns a status that indicates either a success (result
  1342. 0) or a failure (result 1). Failed command always includes text
  1343. parameter that explains the cause of failure. Example results:
  1344. <screen>{ "result": 0, "text": "Lease added." }</screen> Example failure:
  1345. <screen>{ "result": 1, "text": "missing parameter 'ip-address' (&lt;string&gt;:3:19)" }</screen>
  1346. </para>
  1347. <section>
  1348. <title>lease4-get, lease6-get commands</title>
  1349. <para><command>lease4-get</command> or <command>lease6-get</command>
  1350. can be used to query the lease database and retrieve existing
  1351. leases. There are two types of parameters the
  1352. <command>lease4-get</command> supports: (address) or (subnet-id,
  1353. identifier-type, identifier). There are two types for
  1354. <command>lease6-get</command>: (address,type) or (subnet-id,
  1355. identifier-type, identifier, IAID, type). The first type of query is
  1356. used when the address (either IPv4 or IPv6) is known, but the details
  1357. of the lease aren't. One common use case of this type of query is to
  1358. find out whether a given address is being used or not. The second
  1359. query uses identifiers. For maximum flexibility, Kea stores the host
  1360. identifying information as a pair of values: type and the actual
  1361. identifier. Currently supported identifiers are "hw-address", "duid",
  1362. "circuit-id", "client-id" and "flex-id", but additional types may be
  1363. added in the future. If any new identifier types are defined in the
  1364. future, reservation-get command will support them
  1365. automatically.</para>
  1366. <para>
  1367. An example <command>lease4-get</command> command for getting a lease
  1368. by an IPv4 address looks as follows:
  1369. <screen>
  1370. {
  1371. "command": "lease4-get",
  1372. "arguments": {
  1373. "ip-address": "192.0.2.1"
  1374. }
  1375. }
  1376. </screen>
  1377. </para>
  1378. <para>An example of the <command>lease6-get</command> query
  1379. looks as follows:
  1380. <screen>
  1381. {
  1382. "command": "lease6-get",
  1383. "arguments": {
  1384. "ip-address": "2001:db8:1234:ab::",
  1385. "type": "IA_PD"
  1386. }
  1387. }</screen>
  1388. </para>
  1389. <para>An example query by (subnet-id, identifier-type,
  1390. identifier) for IPv4 lease looks as follows:
  1391. <screen>
  1392. {
  1393. "command": "lease4-get",
  1394. "arguments": {
  1395. "identifier-type": "hw-address",
  1396. "identifier": "08:08:08:08:08:08",
  1397. "subnet-id": 44
  1398. }
  1399. }</screen>
  1400. </para>
  1401. <para>An example query by (subnet-id, identifier-type,
  1402. identifier, iaid, type) for IPv6 lease looks as follows:
  1403. <screen>
  1404. {
  1405. "command": "lease4-get",
  1406. "arguments": {
  1407. "identifier-type": "duid",
  1408. "identifier": "08:08:08:08:08:08",
  1409. "iaid": 1234567,
  1410. "type": "IA_NA",
  1411. "subnet-id": 44
  1412. }
  1413. }</screen>
  1414. The type is an optional parameter. Supported values are: IA_NA
  1415. (non-temporary address) and IA_PD (IPv6 prefix) are supported.
  1416. If not specified, IA_NA is assumed.
  1417. </para>
  1418. <para><command>leaseX-get</command> returns a result that indicates a
  1419. result of the operation and lease details, if found. It has one of the
  1420. following values: 0 (success), 1 (error) or 2 (empty). The empty
  1421. result means that a query has been completed properly, but the object
  1422. (a lease in this case) has not been found. The lease parameters, if
  1423. found, are returned as arguments.
  1424. </para>
  1425. <para>
  1426. An example result returned when the host was found:
  1427. <screen>{
  1428. "arguments": {
  1429. "client-id": "42:42:42:42:42:42:42:42",
  1430. "cltt": 12345678,
  1431. "fqdn-fwd": false,
  1432. "fqdn-rev": true,
  1433. "hostname": "myhost.example.com.",
  1434. "hw-address": "08:08:08:08:08:08",
  1435. "ip-address": "192.0.2.1",
  1436. "state": 0,
  1437. "subnet-id": 44,
  1438. "valid-lft": 3600
  1439. },
  1440. "result": 0,
  1441. "text": "IPv4 lease found."
  1442. }</screen>
  1443. </para>
  1444. </section>
  1445. <section>
  1446. <title>lease4-del, lease6-del commands</title>
  1447. <para><command>leaseX-del</command> can be used to delete a lease from
  1448. the lease database. There are two types of parameters this command
  1449. supports, similar to leaseX-get commands: (address) for both v4 and
  1450. v6, (subnet-id, identifier-type, identifier) for v4 and (subnet-id,
  1451. identifier-type, identifier, type, IAID) for v6. The first type of
  1452. query is used when the address (either IPv4 or IPv6) is known, but the
  1453. details of the lease are not. One common use case of this type of query
  1454. is to remove a lease (e.g. you want a specific address to no longer be
  1455. used, no matter who may use it). The second query uses
  1456. identifiers. For maximum flexibility, this interface uses identifiers
  1457. as a pair of values: type and the actual identifier. Currently
  1458. supported identifiers are "hw-address" and "duid", but additional
  1459. types may be added in the future. </para>
  1460. <para>
  1461. An example command for deleting a host reservation by address looks
  1462. as follows:
  1463. <screen>
  1464. {
  1465. "command": "lease4-del",
  1466. "arguments": {
  1467. "ip-address": "192.0.2.202"
  1468. }
  1469. }</screen>
  1470. An example IPv4 lease deletion by (subnet-id, identifier-type, identifier) looks
  1471. as follows:
  1472. <screen>{
  1473. "command": "lease4-del",
  1474. "arguments": {
  1475. "identifier": "08:08:08:08:08:08",
  1476. "identifier-type": "hw-address",
  1477. "subnet-id": 44
  1478. }
  1479. }</screen>
  1480. </para>
  1481. <para><command>leaseX-get</command> returns a result that
  1482. indicates a outcome of the operation. It has one of the
  1483. following values: 0 (success), 1 (error) or 2 (empty). The
  1484. empty result means that a query has been completed properly,
  1485. but the object (a lease in this case) has not been found.
  1486. </para>
  1487. </section>
  1488. <section>
  1489. <title>lease4-update, lease6-update commands</title>
  1490. <para><command>lease4-update</command> and
  1491. <command>lease6-update</command> commands can be used to update
  1492. existing leases. Since all lease database backends are indexed by IP
  1493. addresses, it is not possible to update an address. All other fields
  1494. may be updated. If an address needs to be changed, please use
  1495. <command>leaseX-del</command> followed by
  1496. <command>leaseX-add</command> commands.</para>
  1497. <para>To use <command>leaseX-update</command> the lease must
  1498. be present in the lease database. If the lease is not there,
  1499. an error will be returned. Please use
  1500. <command>leaseX-add</command> to add new leases. You may
  1501. check if a lease is present using
  1502. <command>leaseX-get</command>, if needed.</para>
  1503. <para>
  1504. An example command updating IPv4 lease looks as follows:
  1505. <screen>{
  1506. "command": "lease4-update",
  1507. "arguments": {
  1508. "ip-address": "192.0.2.1",
  1509. "hostname": "newhostname.example.org",
  1510. "hw-address": "1a:1b:1c:1d:1e:1f",
  1511. "subnet-id": 44
  1512. }
  1513. }</screen>
  1514. </para>
  1515. <para>
  1516. An example command updating IPv6 lease looks as follows:
  1517. <screen>{
  1518. "command": "lease6-update",
  1519. "arguments": {
  1520. "ip-address": "2001:db8::1",
  1521. "duid": "88:88:88:88:88:88:88:88",
  1522. "iaid": 7654321,
  1523. "hostname": "newhostname.example.org",
  1524. "subnet-id": 66
  1525. }
  1526. }</screen>
  1527. </para>
  1528. </section>
  1529. <section>
  1530. <title>lease4-wipe, lease6-wipe commands</title>
  1531. <para><command>lease4-wipe</command> and
  1532. <command>lease6-wipe</command> are designed to remove all
  1533. leases associated with a given subnet. This administrative
  1534. task is expected to be used when existing subnet is being
  1535. retired. Note that the leases are not properly expired,
  1536. there are no DNS updates conducted, no log messages and
  1537. hooks are not called for leases being removed.</para>
  1538. <para>An example of <command>lease4-wipe</command> looks as follows:
  1539. <screen>{
  1540. "command": "lease4-wipe",
  1541. "arguments": {
  1542. "subnet-id": 44
  1543. }
  1544. }</screen>
  1545. </para>
  1546. <para>An example of <command>lease6-wipe</command> looks as follows:
  1547. <screen>{
  1548. "command": "lease6-wipe",
  1549. "arguments": {
  1550. "subnet-id": 66
  1551. }
  1552. }</screen>
  1553. </para>
  1554. <para>The commands return a textual description of the
  1555. number of leases removed and 0 (success) status code if any
  1556. leases were removed and 2 (empty) if there were no
  1557. leases. Status code 1 (error) may be returned in case the
  1558. parameters are incorrect or some other exception is
  1559. encountered.</para>
  1560. <para>Note: not all backends support this command.</para>
  1561. </section>
  1562. </section>
  1563. </section>
  1564. <section id="subnet-cmds">
  1565. <title>subnet_cmds: Subnet Commands</title>
  1566. <para>
  1567. This section describes a hook application that offers a number of new
  1568. commands used to query and manipulate subnet configurations in Kea.
  1569. This application is very useful in deployments with a large number of
  1570. subnets being managed by the DHCP servers and when the subnets are
  1571. frequently updated. The commands offer lightweight approach for
  1572. manipulating subnets without a need to fully reconfigure the server
  1573. and without affecting existing servers' configurations.
  1574. </para>
  1575. <para>Currently this library is only available to ISC customers with a
  1576. support contract.</para>
  1577. <para>The following commands are currently supported:
  1578. <itemizedlist mark='bullet'>
  1579. <listitem>
  1580. <simpara><command>subnet4-list/subnet6-list</command>: lists all configured subnets
  1581. </simpara>
  1582. </listitem>
  1583. <listitem>
  1584. <simpara>
  1585. <command>subnet4-get/subnet6-get</command>: retrieves detailed information about a selected subnet
  1586. </simpara>
  1587. </listitem>
  1588. <listitem>
  1589. <simpara>
  1590. <command>subnet4-add/subnet6-add</command>: adds new subnet into server's configuration
  1591. </simpara>
  1592. </listitem>
  1593. <listitem>
  1594. <simpara>
  1595. <command>subnet4-del/subnet6-del</command>: removes a subnet from the server's configuration
  1596. </simpara>
  1597. </listitem>
  1598. </itemizedlist>
  1599. </para>
  1600. <section>
  1601. <title>subnet4-list command</title>
  1602. <para>
  1603. This command is used to list all currently configured subnets. The
  1604. subnets are returned in a brief form, i.e. a subnet identifier
  1605. and subnet prefix is included for each subnet. In order to retrieve
  1606. the detailed information about the subnet the
  1607. <command>subnet4-get</command> should be used.
  1608. </para>
  1609. <para>
  1610. This command has the simple structure:
  1611. <screen>
  1612. {
  1613. "command": "subnet4-list"
  1614. }
  1615. </screen>
  1616. </para>
  1617. <para>
  1618. The list of subnets returned as a result of this command is returned
  1619. in the following format:
  1620. <screen>
  1621. {
  1622. "result": 0,
  1623. "text": "2 IPv4 subnets found",
  1624. "arguments": {
  1625. "subnets": [
  1626. {
  1627. "id": 10,
  1628. "subnet": "10.0.0.0/8"
  1629. },
  1630. {
  1631. "id": 100,
  1632. "subnet": "192.0.2.0/24"
  1633. }
  1634. ]
  1635. }
  1636. </screen>
  1637. </para>
  1638. <para>
  1639. If no IPv4 subnets are found, an error code is returned along with
  1640. the error description.
  1641. </para>
  1642. </section>
  1643. <section>
  1644. <title>subnet6-list command</title>
  1645. <para>
  1646. This command is used to list all currently configured subnets. The
  1647. subnets are returned in a brief form, i.e. a subnet identifier
  1648. and subnet prefix is included for each subnet. In order to retrieve
  1649. the detailed information about the subnet the
  1650. <command>subnet6-get</command> should be used.
  1651. </para>
  1652. <para>
  1653. This command has the simple structure:
  1654. <screen>
  1655. {
  1656. "command": "subnet6-list"
  1657. }
  1658. </screen>
  1659. </para>
  1660. <para>
  1661. The list of subnets returned as a result of this command is returned
  1662. in the following format:
  1663. <screen>
  1664. {
  1665. "result": 0,
  1666. "text": "2 IPv6 subnets found",
  1667. "arguments": {
  1668. "subnets": [
  1669. {
  1670. "id": 11,
  1671. "subnet": "2001:db8:1::/64"
  1672. },
  1673. {
  1674. "id": 233,
  1675. "subnet": "3000::/16"
  1676. }
  1677. ]
  1678. }
  1679. </screen>
  1680. </para>
  1681. <para>
  1682. If no IPv6 subnets are found, an error code is returned along with
  1683. the error description.
  1684. </para>
  1685. </section>
  1686. <section>
  1687. <title>subnet4-get command</title>
  1688. <para>This command is used to retrieve detailed information about the
  1689. specified subnet. This command usually follows the
  1690. <command>subnet4-list</command>, which is used to discover available
  1691. subnets with their respective subnet identifiers and prefixes. Any of
  1692. those parameters can be then used in <command>subnet4-get</command>
  1693. to fetch subnet information:
  1694. <screen>
  1695. {
  1696. "command": "subnet4-get",
  1697. "arguments": {
  1698. "id": 10
  1699. }
  1700. }</screen>
  1701. or
  1702. <screen>
  1703. {
  1704. "command": "subnet4-get",
  1705. "arguments": {
  1706. "subnet": "10.0.0.0/8"
  1707. }
  1708. }
  1709. </screen>
  1710. </para>
  1711. <para>
  1712. If the subnet exists the response will be similar to this:
  1713. <screen>
  1714. {
  1715. "result": 0,
  1716. "text": "Info about IPv4 subnet 10.0.0.0/8 (id 10) returned",
  1717. "arguments": {
  1718. "subnets": [
  1719. {
  1720. "subnet": "10.0.0.0/8",
  1721. "id": 1,
  1722. "option-data": [
  1723. ....
  1724. ]
  1725. ...
  1726. }
  1727. ]
  1728. }
  1729. }
  1730. </screen>
  1731. </para>
  1732. </section>
  1733. <section>
  1734. <title>subnet6-get command</title>
  1735. <para>This command is used to retrieve detailed information about the
  1736. specified subnet. This command usually follows the
  1737. <command>subnet6-list</command>, which is used to discover available
  1738. subnets with their respective subnet identifiers and prefixes. Any of
  1739. those parameters can be then used in <command>subnet6-get</command>
  1740. to fetch subnet information:
  1741. <screen>
  1742. {
  1743. "command": "subnet6-get",
  1744. "arguments": {
  1745. "id": 11
  1746. }
  1747. }
  1748. </screen>
  1749. or
  1750. <screen>
  1751. {
  1752. "command": "subnet6-get",
  1753. "arguments": {
  1754. "subnet": "2001:db8:1::/64"
  1755. }
  1756. }</screen>
  1757. If the subnet exists the response will be similar to this:
  1758. <screen>
  1759. {
  1760. "result": 0,
  1761. "text": "Info about IPv6 subnet 2001:db8:1::/64 (id 11) returned",
  1762. "arguments": {
  1763. "subnets": [
  1764. {
  1765. "subnet": "2001:db8:1::/64",
  1766. "id": 1,
  1767. "option-data": [
  1768. ...
  1769. ]
  1770. ....
  1771. }
  1772. ]
  1773. }
  1774. }
  1775. </screen>
  1776. </para>
  1777. </section>
  1778. <section>
  1779. <title>subnet4-add</title>
  1780. <para>
  1781. This command is used to create and add new subnet to the existing
  1782. server configuration. This operation has no impact on other
  1783. subnets. The subnet identifier must be specified and must be
  1784. unique among all subnets. If the identifier or a subnet prefix is
  1785. not unique an error is reported and the subnet is not added.
  1786. </para>
  1787. <para>
  1788. The subnet information within this command has the same structure
  1789. as the subnet information in the server configuration file with the
  1790. exception that static host reservations must not be specified
  1791. within <command>subnet4-add</command>. The commands described in
  1792. <xref linkend="host-cmds"/> should be used to add, remove and
  1793. modify static reservations.
  1794. <screen>
  1795. {
  1796. "command": "subnet4-add",
  1797. "arguments": {
  1798. "subnets": [ {
  1799. "id": 123,
  1800. "subnet": "10.20.30.0/24",
  1801. ...
  1802. } ]
  1803. }
  1804. }
  1805. </screen>
  1806. </para>
  1807. <para>
  1808. The response to this command has the following structure:
  1809. <screen>
  1810. {
  1811. "result": 0,
  1812. "text": "IPv4 subnet added",
  1813. "arguments": {
  1814. "subnets": [
  1815. {
  1816. "id": 123,
  1817. "subnet": "10.20.30.0/24"
  1818. }
  1819. ]
  1820. }
  1821. }
  1822. </screen>
  1823. </para>
  1824. </section>
  1825. <section>
  1826. <title>subnet6-add</title>
  1827. <para>
  1828. This command is used to create and add new subnet to the existing
  1829. server configuration. This operation has no impact on other
  1830. subnets. The subnet identifier must be specified and must be
  1831. unique among all subnets. If the identifier or a subnet prefix is
  1832. not unique an error is reported and the subnet is not added.
  1833. </para>
  1834. <para>
  1835. The subnet information within this command has the same structure
  1836. as the subnet information in the server configuration file with the
  1837. exception that static host reservations must not be specified
  1838. within <command>subnet6-add</command>. The commands described in
  1839. <xref linkend="host-cmds"/> should be used to add, remove and
  1840. modify static reservations.
  1841. <screen>
  1842. {
  1843. "command": "subnet6-add",
  1844. "arguments": {
  1845. "subnet6": [ {
  1846. "id": 234,
  1847. "subnet": "2001:db8:1::/64",
  1848. ...
  1849. } ]
  1850. }
  1851. }
  1852. </screen>
  1853. </para>
  1854. <para>
  1855. The response to this command has the following structure:
  1856. <screen>
  1857. {
  1858. "result": 0,
  1859. "text": "IPv6 subnet added",
  1860. "arguments": {
  1861. "subnet6": [
  1862. {
  1863. "id": 234,
  1864. "subnet": "2001:db8:1::/64"
  1865. }
  1866. ]
  1867. }
  1868. }
  1869. </screen>
  1870. </para>
  1871. <para>
  1872. It is recommended, but not mandatory to specify subnet
  1873. id. If not specified, Kea will try to assign the next
  1874. subnet-id value. This automatic ID value generator is
  1875. simple. It returns a previously automatically assigned value
  1876. increased by 1. This works well, unless you manually create
  1877. a subnet with a value bigger than previously used. For
  1878. example, if you call subnet4-add five times, each without
  1879. id, Kea will assign IDs: 1,2,3,4 and 5 and it will work just
  1880. fine. However, if you try to call subnet4-add five times,
  1881. with the first subnet having subnet-id of value 3 and
  1882. remaining ones having no subnet-id, it will fail. The first
  1883. command (with explicit value) will use subnet-id 3, the
  1884. second command will create a subnet with id of 1, the third
  1885. will use value of 2 and finally the fourth will have the
  1886. subnet-id value auto-generated as 3. However, since there is
  1887. already a subnet with that id, it will fail.
  1888. </para>
  1889. <para>
  1890. The general recommendation is to either: never use explicit
  1891. values (so the auto-generated values will always work) or
  1892. always use explicit values (so the auto-generation is never
  1893. used). You can mix those two approaches only if you
  1894. understand how the internal automatic subnet-id generation works.
  1895. </para>
  1896. </section>
  1897. <section>
  1898. <title>subnet4-del command</title>
  1899. <para>
  1900. This command is used to remove a subnet from the server's configuration.
  1901. This command has no effect on other configured subnets but removing
  1902. a subnet has certain implications which the server's administrator
  1903. should be aware of.
  1904. </para>
  1905. <para>
  1906. In most cases the server has assigned some leases to the clients
  1907. belonging to the subnet. The server may also be configured with
  1908. static host reservations which are associated with this subnet.
  1909. The current implementation of the <command>subnet4-del</command>
  1910. removes neither the leases nor host reservations associated with
  1911. a subnet. This is the safest approach because the server doesn't
  1912. loose track of leases assigned to the clients from this subnet.
  1913. However, removal of the subnet may still cause configuration
  1914. errors and conflicts. For example: after removal of the subnet,
  1915. the server administrator may add a new subnet with the ID used
  1916. previously for the removed subnet. This means that the existing
  1917. leases and static reservations will be in conflict with this
  1918. new subnet. Thus, we recommend that this command is used with extreme
  1919. caution.
  1920. </para>
  1921. <para>The command has the following structure:
  1922. <screen>
  1923. {
  1924. "command": "subnet4-del",
  1925. "arguments": {
  1926. "id": 123
  1927. }
  1928. }
  1929. </screen>
  1930. </para>
  1931. <para>
  1932. The example successful response may look like this:
  1933. <screen>
  1934. {
  1935. "result": 0,
  1936. "text": "IPv4 subnet 192.0.2.0/24 (id 123) deleted",
  1937. "arguments": {
  1938. "subnets": [
  1939. {
  1940. "id": 123,
  1941. "subnet": "192.0.2.0/24"
  1942. }
  1943. ]
  1944. }
  1945. }
  1946. </screen>
  1947. </para>
  1948. </section>
  1949. <section>
  1950. <title>subnet6-del command</title>
  1951. <para>
  1952. This command is used to remove a subnet from the server's configuration.
  1953. This command has no effect on other configured subnets but removing
  1954. a subnet has certain implications which the server's administrator
  1955. should be aware of.
  1956. </para>
  1957. <para>
  1958. In most cases the server has assigned some leases to the clients
  1959. belonging to the subnet. The server may also be configured with
  1960. static host reservations which are associated with this subnet.
  1961. The current implementation of the <command>subnet6-del</command>
  1962. removes neither the leases nor host reservations associated with
  1963. a subnet. This is the safest approach because the server doesn't
  1964. loose track of leases assigned to the clients from this subnet.
  1965. However, removal of the subnet may still cause configuration
  1966. errors and conflicts. For example: after removal of the subnet,
  1967. the server administrator may add a new subnet with the ID used
  1968. previously for the removed subnet. This means that the existing
  1969. leases and static reservations will be in conflict with this
  1970. new subnet. Thus, we recommend that this command is used with extreme
  1971. caution.
  1972. </para>
  1973. <para>The command has the following structure:
  1974. <screen>
  1975. {
  1976. "command": "subnet6-del",
  1977. "arguments": {
  1978. "id": 234
  1979. }
  1980. }
  1981. </screen>
  1982. </para>
  1983. <para>
  1984. The example successful response may look like this:
  1985. <screen>
  1986. {
  1987. "result": 0,
  1988. "text": "IPv6 subnet 2001:db8:1::/64 (id 234) deleted",
  1989. "subnets": [
  1990. {
  1991. "id": 234,
  1992. "subnet": "2001:db8:1::/64"
  1993. }
  1994. ]
  1995. }
  1996. </screen>
  1997. </para>
  1998. </section>
  1999. </section>
  2000. </section> <!-- end of subnet commands -->
  2001. <section id="user-context">
  2002. <title>User contexts</title>
  2003. <para>Hook libraries can have their own configuration parameters. That is
  2004. convenient if the parameter applies to the whole library. However,
  2005. sometimes it is very useful if certain configuration entities are extended
  2006. with additional configuration data. This is where the concept of user
  2007. contexts comes in. A sysadmin can define an arbitrary set of data and
  2008. attach it to Kea structures, as long as the data is specified as JSON map.
  2009. In particular, it is possible to define fields that are integers, strings,
  2010. boolean, lists and maps. It is possible to define nested structures of
  2011. arbitrary complexity. Kea does not use that data on its own, simply stores
  2012. and makes it available for the hook libraries.
  2013. </para>
  2014. <para>
  2015. Another use case for user contexts may be storing comments and other
  2016. information that will be retained by Kea. Regular comments are discarded
  2017. when configuration is loaded, but user contexts are retained. This is
  2018. useful if you want your comments to survive config-set, config-get
  2019. operations for example.
  2020. </para>
  2021. <para>
  2022. As of Kea 1.3, the structures that allow user contexts are pools of all
  2023. types (addresses and prefixes) and subnets. These are supported in both
  2024. DHCPv4 and DHCPv6. It is expected that other structures will be extended
  2025. in the future to provide the user context capability.
  2026. </para>
  2027. </section>
  2028. </chapter> <!-- hooks-libraries -->