hooks.xml 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097
  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. scenario 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 one mandatory parameter identifier-expression:
  696. <screen>
  697. "Dhcp6": { <userinput>
  698. "hooks-libraries": [
  699. {
  700. "library": "/path/libdhcp_flex_id.so",
  701. "parameters": {
  702. "identifier-expression": "<userinput>expression</userinput>"
  703. }
  704. },
  705. ...
  706. ] </userinput>
  707. }
  708. </screen>
  709. </para>
  710. <para>
  711. The flexible identifier library supports both DHCPv4 and DHCPv6.
  712. </para>
  713. <para>
  714. EXAMPLE: Let's consider a case of an IPv6 network that has an
  715. independent interface for each of the connected customers. Customers
  716. are able to plug in whatever device they want, so any type of
  717. identifier (e.g. a client-id) is unreliable. Therefore the operator
  718. may decide to use an option inserted by a relay agent to differentiate
  719. between clients. In this particular deployment, the operator verified
  720. that the interface-id is unique for each customer facing
  721. interface. Therefore it is suitable for usage as reservation. However,
  722. only the first 6 bytes of the interface-id are interesting, because
  723. remaining bytes are either randomly changed or not unique between
  724. devices. Therefore the customer decided to use first 6 bytes of the
  725. interface-id option inserted by the relay agent. After adding "flex-id"
  726. host-reservation-identifiers goal can be achieved by using the
  727. following configuration:
  728. <screen>
  729. "Dhcp6": {
  730. "subnet6": [{ ..., // subnet definition starts here
  731. "reservations": [
  732. <userinput>"flex-id": "'port1234'"</userinput>, // value of the first 8 bytes of the interface-id
  733. "ip-addresses": [ "2001:db8::1" ]
  734. ],
  735. }], // end of subnet definitions
  736. "host-reservation-identifiers": ["duid", "flex-id"], // add "flex-id" to reservation identifiers
  737. "hooks-libraries": [
  738. {
  739. "library": "/path/libdhcp_flex_id.so",
  740. "parameters": {
  741. "identifier-expression": "<userinput>substring(relay6[0].option[18].hex,0,8)</userinput>"
  742. }
  743. },
  744. ...
  745. ]
  746. }
  747. </screen>
  748. </para>
  749. <para>
  750. NOTE: Care should be taken when adjusting the expression. If the
  751. expression changes, then all the flex-id values may change, possibly
  752. rendering all reservations based on flex-id unusable until they're
  753. manually updated. Therefore it is strongly recommended to start with
  754. the expression and a handful reservations, adjust the expression as
  755. needed and only after it was confirmed the expression does exactly
  756. what is expected out of it go forward with host reservations on any
  757. broader scale.
  758. </para>
  759. <para>
  760. flex-id values in host reservations can be specified in two
  761. ways. First, they can be expressed as hex string, e.g. bar string
  762. can be represented as 626174. Alternatively, it can be expressed
  763. as quoted value (using double and single quotes), e.g. "'bar'".
  764. The former is more convenient for printable characters, while hex
  765. string values are more convenient for non-printable characters.
  766. </para>
  767. <screen>
  768. "Dhcp6": {
  769. "subnet6": [{ ..., // subnet definition starts here
  770. "reservations": [
  771. <userinput>"flex-id": "01:02:03:04:05:06"</userinput>, // value of the first 8 bytes of the interface-id
  772. "ip-addresses": [ "2001:db8::1" ]
  773. ],
  774. }], // end of subnet definitions
  775. "host-reservation-identifiers": ["duid", "flex-id"], // add "flex-id" to reservation identifiers
  776. "hooks-libraries": [
  777. {
  778. "library": "/path/libdhcp_flex_id.so",
  779. "parameters": {
  780. "identifier-expression": "<userinput>vendor[4491].option[1026].hex</userinput>"
  781. }
  782. },
  783. ...
  784. ]
  785. }
  786. </screen>
  787. </section>
  788. <section id="host-cmds">
  789. <title>host_cmds: Host Commands</title>
  790. <para>
  791. This section describes a hook application that offers a number of new
  792. commands used to query and manipulate host reservations. Kea provides
  793. a way to store host reservations in a database. In many larger
  794. deployments it is useful to be able to manage that information while
  795. the server is running. This library provides management commands for
  796. adding, querying and deleting host reservations in a safe way without
  797. restarting the server. In particular, it validates the parameters, so
  798. an attempt to insert incorrect data e.g. add a host with conflicting
  799. identifier in the same subnet will be rejected. Those commands are
  800. exposed via command channel (JSON over unix sockets) and Control Agent
  801. (JSON over RESTful interface). Additional commands and capabilities
  802. related to host reservations will be added in the future.
  803. </para>
  804. <para>Currently this library is only available to ISC customers with a
  805. support contract.</para>
  806. <para>
  807. Currently three commands are supported: reservation-add (which adds
  808. new host reservation), reservation-get (which returns existing
  809. reservation if specified criteria are matched) and reservation-del
  810. (which attempts to delete a reservation matching specified
  811. criteria). To use commands that change the reservation information
  812. (currently these are reservation-add and reservation-del, but this
  813. rule applies to other commands that may be implemented in the future),
  814. hosts database must be specified (see hosts-database description in
  815. <xref linkend="hosts-database-configuration4"/> and <xref
  816. linkend="hosts-database-configuration6"/>) and it must not operate in
  817. read-only mode. If the hosts-database is not specified or is running
  818. in read-only mode, the host_cmds library will load, but any attempts
  819. to use reservation-add or reservation-del will fail.
  820. </para>
  821. <para>
  822. Additional host reservation commands are planned in the future. For
  823. a description of envisaged commands, see
  824. <ulink url="http://kea.isc.org/wiki/ControlAPIRequirements">Control API
  825. Requirements </ulink> document.</para>
  826. <para>
  827. All commands are using JSON syntax. They can be issued either using
  828. control channel (see <xref linkend="ctrl-channel"/>) or via Control
  829. Agent (see <xref linkend="kea-ctrl-agent"/>).
  830. </para>
  831. <para>
  832. The library can be loaded in similar way as other hook libraries. It
  833. does not take any parameters. It supports both DHCPv4 and DHCPv6
  834. servers.
  835. <screen>
  836. "Dhcp6": { <userinput>
  837. "hooks-libraries": [
  838. {
  839. "library": "/path/libdhcp_host_cmds.so"
  840. }
  841. ...
  842. ] </userinput>
  843. }
  844. </screen>
  845. </para>
  846. <section>
  847. <title>reservation-add command</title>
  848. <para>
  849. <command>reservation-add</command> allows insertion of a new host. It
  850. takes a set of arguments that vary depending on the nature of the host
  851. reservation. Any parameters allowed in the configuration file that
  852. pertain to host reservation are permitted here. For details regarding
  853. IPv4 reservations, see <xref linkend="host-reservation-v4"/> and <xref
  854. linkend="host-reservation-v6"/>. There is one notable addition. A
  855. <command>subnet-id</command> must be specified. This parameter is
  856. mandatory, because reservations specified in the configuration file
  857. are always defined within a subnet, so the subnet they belong to is
  858. clear. This is not the case with reservation-add, therefore the
  859. subnet-id must be specified explicitly. An example command can be as
  860. simple as:
  861. <screen>{
  862. "command": "reservation-add",
  863. "arguments": {
  864. <userinput>"reservation": {
  865. "subnet-id": 1,
  866. "hw-address": "1a:1b:1c:1d:1e:1f",
  867. "ip-address": "192.0.2.202"
  868. }</userinput>
  869. }
  870. }</screen> but can also take many more parameters, for example:
  871. <screen>
  872. {
  873. "command": "reservation-add",
  874. "arguments": {
  875. <userinput>"reservation":
  876. {
  877. "subnet-id":1,
  878. "client-id": "01:0a:0b:0c:0d:0e:0f",
  879. "ip-address": "192.0.2.205",
  880. "next-server": "192.0.2.1",
  881. "server-hostname": "hal9000",
  882. "boot-file-name": "/dev/null",
  883. "option-data": [
  884. {
  885. "name": "domain-name-servers",
  886. "data": "10.1.1.202,10.1.1.203"
  887. }
  888. ],
  889. "client-classes": [ "special_snowflake", "office" ]
  890. }</userinput>
  891. }
  892. }</screen>
  893. Here is an example of complex IPv6 reservation:
  894. <screen>
  895. {
  896. "command": "reservation-add",
  897. "arguments": {
  898. <userinput>"reservation":
  899. {
  900. "subnet-id":1,
  901. "duid": "01:02:03:04:05:06:07:08:09:0A",
  902. "ip-addresses": [ "2001:db8:1:cafe::1" ],
  903. "prefixes": [ "2001:db8:2:abcd::/64" ],
  904. "hostname": "foo.example.com",
  905. "option-data": [
  906. {
  907. "name": "vendor-opts",
  908. "data": "4491"
  909. },
  910. {
  911. "name": "tftp-servers",
  912. "space": "vendor-4491",
  913. "data": "3000:1::234"
  914. }
  915. ]
  916. }</userinput>
  917. }
  918. }</screen>
  919. </para>
  920. <para>
  921. The command returns a status that indicates either a success (result
  922. 0) or a failure (result 1). Failed command always includes text
  923. parameter that explains the cause of failure. Example results:
  924. <screen>{ "result": 0, "text": "Host added." }</screen> Example failure:
  925. <screen>{ "result": 1, "text": "Mandatory 'subnet-id' parameter missing." }</screen>
  926. </para>
  927. <para>
  928. As <command>reservation-add</command> is expected to store the host,
  929. hosts-database parameter must be specified in your configuration and
  930. the database must not run in read-only mode. In the future versions
  931. it will be possible to modify the reservations read from a
  932. configuration file. Please contact ISC if you are interested in this
  933. functionality.
  934. </para>
  935. </section>
  936. <section>
  937. <title>reservation-get command</title>
  938. <para><command>reservation-get</command> can be used to query the host
  939. database and retrieve existing reservations. There are two types of
  940. parameters this command supports: (subnet-id, address) or (subnet-id,
  941. identifier-type, identifier). The first type of query is used when the
  942. address (either IPv4 or IPv6) is known, but the details of the
  943. reservation aren't. One common use case of this type of query is to
  944. find out whether a given address is reserved or not. The second query
  945. uses identifiers. For maximum flexibility, Kea stores the host
  946. identifying information as a pair of values: type and the actual
  947. identifier. Currently supported identifiers are "hw-address", "duid",
  948. "circuit-id", "client-id" and "flex-id", but additional types may be
  949. added in the future. If any new identifier types are defined in the
  950. future, reservation-get command will support them
  951. automatically.</para>
  952. <para>
  953. An example command for getting a host reservation by (subnet-id,
  954. address) pair looks as follows:
  955. <screen>
  956. {
  957. "command": "reservation-get",
  958. "arguments": {
  959. "subnet-id": 1,
  960. "ip-address": "192.0.2.202"
  961. }
  962. }</screen>
  963. An example query by (subnet-id, identifier-type, identifier) looks as follows:
  964. <screen>
  965. {
  966. "command": "reservation-get",
  967. "arguments":
  968. "subnet-id": 4,
  969. "identifier-type": "hw-address",
  970. "identifier": "01:02:03:04:05:06"
  971. }
  972. }</screen>
  973. </para>
  974. <para><command>reservation-get</command> typically returns result 0
  975. when the query was conducted properly. In particular, 0 is returned
  976. when the host was not found. If the query was successful a number
  977. of host parameters will be returned. An example of a query that
  978. did not find the host looks as follows:
  979. <screen>{ "result": 0, "text": "Host not found." }</screen>
  980. An example result returned when the host was found:
  981. <screen>{
  982. "arguments": {
  983. "boot-file-name": "bootfile.efi",
  984. "client-classes": [
  985. ],
  986. "hostname": "somehost.example.org",
  987. "hw-address": "01:02:03:04:05:06",
  988. "ip-address": "192.0.2.100",
  989. "next-server": "192.0.0.2",
  990. "option-data": [
  991. ],
  992. "server-hostname": "server-hostname.example.org"
  993. },
  994. "result": 0,
  995. "text": "Host found."
  996. }</screen>
  997. An example result returned when the query was malformed:<screen>
  998. { "result": 1, "text": "No 'ip-address' provided and 'identifier-type'
  999. is either missing or not a string." }</screen>
  1000. </para>
  1001. </section>
  1002. <section>
  1003. <title>reservation-del command</title>
  1004. <para><command>reservation-del</command> can be used to delete a
  1005. reservation from the host database. There are two types of parameters
  1006. this command supports: (subnet-id, address) or (subnet-id,
  1007. identifier-type, identifier). The first type of query is used when the
  1008. address (either IPv4 or IPv6) is known, but the details of the
  1009. reservation aren't. One common use case of this type of query is to
  1010. remove a reservation (e.g. you want a specific address to no longer be
  1011. reserved). The second query uses identifiers. For maximum flexibility,
  1012. Kea stores the host identifying information as a pair of values: type
  1013. and the actual identifier. Currently supported identifiers are
  1014. "hw-address", "duid", "circuit-id", "client-id" and "flex-id", but
  1015. additional types may be added in the future. If any new identifier
  1016. types are defined in the future, reservation-get command will support
  1017. them automatically.</para>
  1018. <para>
  1019. An example command for deleting a host reservation by (subnet-id,
  1020. address) pair looks as follows:
  1021. <screen>
  1022. {
  1023. "command": "reservation-del",
  1024. "arguments": {
  1025. "subnet-id": 1,
  1026. "ip-address": "192.0.2.202"
  1027. }
  1028. }</screen>
  1029. An example deletion by (subnet-id, identifier-type, identifier) looks as follows:
  1030. <screen>
  1031. {
  1032. "command": "reservation-del",
  1033. "arguments":
  1034. "subnet-id": 4,
  1035. "identifier-type": "hw-address",
  1036. "identifier": "01:02:03:04:05:06"
  1037. }
  1038. }</screen>
  1039. </para>
  1040. <para>
  1041. <command>reservation-del</command> returns result 0 when the host
  1042. deletion was successful or 1 if it was not. A descriptive text is
  1043. provided in case of error. Example results look as follows:
  1044. <screen>
  1045. {
  1046. "result": 1,
  1047. "text": "Host not deleted (not found)."
  1048. }</screen>
  1049. <screen>
  1050. {
  1051. "result": 0,
  1052. "text": "Host deleted."
  1053. }</screen>
  1054. <screen>
  1055. {
  1056. "result": 1,
  1057. "text": "Unable to delete a host because there is no hosts-database
  1058. configured."
  1059. }</screen>
  1060. </para>
  1061. </section>
  1062. </section>
  1063. <!-- ================================================================= -->
  1064. <!-- === lease_cmds ================================================== -->
  1065. <!-- ================================================================= -->
  1066. <section id="lease-cmds">
  1067. <title>lease_cmds: Lease Commands</title>
  1068. <para>
  1069. This section describes the hook library that offers a number of new
  1070. commands used to manage leases. Kea provides a way to store lease
  1071. information in several backends (memfile, MySQL, PostgreSQL and
  1072. Cassandra). This library provides a unified interface that can
  1073. manipulate leases in an unified, safe way. In particular, it allows
  1074. things previously impossible: manipulate leases in memfile while Kea
  1075. is running, sanity check changes, check lease existence and remove all
  1076. leases belonging to specific subnet. It can also catch more obscure
  1077. errors, like adding a lease with subnet-id that does not exist in the
  1078. configuration or configuring a lease to use an address that is outside
  1079. of the subnet to which it is supposed to belong.
  1080. </para>
  1081. <para>There are many use cases when an administrative command may be
  1082. useful: during migration between servers (possibly even between
  1083. different vendors), when a certain network is being retired, when a
  1084. device has been disconnected and the sysadmin knows for sure that it
  1085. will not be coming back. The "get" queries may be useful for automating
  1086. certain management and monitoring tasks. They can also act as
  1087. preparatory steps for lease updates and removals.</para>
  1088. <para>
  1089. This library provides the following commands:
  1090. <itemizedlist>
  1091. <listitem>
  1092. <para><command>lease4-add</command> - adds new IPv4 lease;</para>
  1093. </listitem>
  1094. <listitem>
  1095. <para><command>lease6-add</command> - adds new IPv6 lease;</para>
  1096. </listitem>
  1097. <listitem>
  1098. <para><command>lease4-get</command> - checks if an IPv4 lease with
  1099. the specified parameters exists and returns it if it does;</para>
  1100. </listitem>
  1101. <listitem>
  1102. <para><command>lease6-get</command> - checks if an IPv6 lease with
  1103. the specified parameters exists and returns it if it does;</para>
  1104. </listitem>
  1105. <listitem>
  1106. <para><command>lease4-del</command> - attempts to delete an IPv4
  1107. lease with the specified parameters;</para>
  1108. </listitem>
  1109. <listitem>
  1110. <para><command>lease6-del</command> - attempts to delete an IPv6
  1111. lease with the specified parameters;</para>
  1112. </listitem>
  1113. <listitem>
  1114. <para><command>lease4-update</command> - updates an IPv4 lease;</para>
  1115. </listitem>
  1116. <listitem>
  1117. <para><command>lease6-update</command> - updates an IPv6 lease;</para>
  1118. </listitem>
  1119. <listitem>
  1120. <para><command>lease4-wipe</command> - removes all leases from a
  1121. specific IPv4 subnet;</para>
  1122. </listitem>
  1123. <listitem>
  1124. <para><command>lease6-wipe</command> - removes all leases from a
  1125. specific IPv6 subnet;</para>
  1126. </listitem>
  1127. </itemizedlist>
  1128. </para>
  1129. <para>Lease commands library is part of the open source code and is
  1130. available to every Kea user.</para>
  1131. <para>
  1132. All commands are using JSON syntax. They can be issued either using
  1133. control channel (see <xref linkend="ctrl-channel"/>) or via Control
  1134. Agent (see <xref linkend="kea-ctrl-agent"/>).
  1135. </para>
  1136. <para>
  1137. The library can be loaded in the same way as other hook libraries. It
  1138. does not take any parameters. It supports both DHCPv4 and DHCPv6
  1139. servers.
  1140. <screen>
  1141. "Dhcp6": { <userinput>
  1142. "hooks-libraries": [
  1143. {
  1144. "library": "/path/libdhcp_lease_cmds.so"
  1145. }
  1146. ...
  1147. ] </userinput>
  1148. }
  1149. </screen>
  1150. </para>
  1151. <section>
  1152. <title>lease4-add, lease6-add commands</title>
  1153. <para>
  1154. <command>lease4-add</command> and <command>lease6-add</command>
  1155. commands allow creation of a new lease. Typically Kea creates a lease
  1156. on its own, when it first sees a new device. However, sometimes it may
  1157. be convenient to create the lease administratively. The
  1158. <command>lease4-add</command> command requires at least three
  1159. parameters: an IPv4 address, a subnet-id and an identifier: hardware
  1160. (MAC) address. The simplest successful call might look as follows:
  1161. <screen>
  1162. {
  1163. "command": "lease4-add",
  1164. "arguments": {
  1165. "subnet-id": 44,
  1166. "ip-address": "192.0.2.202",
  1167. "hw-address": "1a:1b:1c:1d:1e:1f"
  1168. }
  1169. }
  1170. </screen>
  1171. </para>
  1172. <para><command>lease6-add</command> command requires four
  1173. paramaters: an IPv6 address, a subnet-id, and IAID value
  1174. (identity association identifier, a value sent by clients) and
  1175. a DUID:
  1176. <screen>
  1177. {
  1178. "command": "lease6-add",
  1179. "arguments": {
  1180. "subnet-id": 66,
  1181. "ip-address": "2001:db8::3",
  1182. "duid": "1a:1b:1c:1d:1e:1f:20:21:22:23:24",
  1183. "iaid": 1234
  1184. }
  1185. }</screen>
  1186. <command>lease6-add</command> can be also used to add leases for IPv6
  1187. prefixes. In this case there are two parameters that must be
  1188. specified: type (set to value of &quot;IA_PD&quot;) and a prefix
  1189. length. The actual prefix is set using ip-address field. For example,
  1190. to configure a lease for prefix 2001:db8:abcd::/48, the following
  1191. command can be used:
  1192. <screen>
  1193. {
  1194. "command": "lease6-add",
  1195. "arguments": {
  1196. "subnet-id": 66,
  1197. "type": "IA_PD",
  1198. "ip-address": "2001:db8:abcd::",
  1199. "prefix-len": 48,
  1200. "duid": "1a:1b:1c:1d:1e:1f:20:21:22:23:24",
  1201. "iaid": 1234
  1202. }
  1203. }</screen>
  1204. The commands can take a number of additional optional parameters:
  1205. <itemizedlist>
  1206. <listitem>
  1207. <para><command>valid-lft</command> - specifies the lifetime of the
  1208. lease, expressed in seconds. If not specified, the value
  1209. configured in the subnet related to specified subnet-id is
  1210. used.</para>
  1211. </listitem>
  1212. <listitem>
  1213. <para><command>expire</command> - timestamp of the lease
  1214. expiration time, expressed in unix format (seconds since 1 Jan
  1215. 1970). If not specified, the default value is now + valid
  1216. lifetime.</para>
  1217. </listitem>
  1218. <listitem>
  1219. <para><command>fqdn-fwd</command> - specifies whether the lease
  1220. should be marked as if forward DNS update was conducted. Note this
  1221. only affects the lease parameter and the actual DNS update will
  1222. not be conducted at the lease insertion time. If configured, a DNS
  1223. update to remove the A or AAAA records will be conducted when the
  1224. lease is removed due to expiration or being released by a
  1225. client. If not specifed, the default value is false. Hostname
  1226. parameter must be specified in fqdn-fwd is set to true.</para>
  1227. </listitem>
  1228. <listitem>
  1229. <para><command>fqdn-rev</command> - specifies whether the lease
  1230. should be marked as if reverse DNS update was conducted. Note this
  1231. only affects the lease parameter and the actual DNS update will
  1232. not be conducted at the lease insertion time. If configured, a DNS
  1233. update to remove the PTR record will be conducted when the lease
  1234. is removed due to expiration or being released by a client. If not
  1235. specifed, the default value is false. Hostname parameter must be
  1236. specified in fqdn-fwd is set to true.</para>
  1237. </listitem>
  1238. <listitem>
  1239. <para><command>hostname</command> - specifies the hostname to be
  1240. associated with this lease. Its value must be non-empty if either
  1241. fqdn-fwd or fwdn-rev are set to true. If not specified, the
  1242. default value is an empty string.</para>
  1243. </listitem>
  1244. <listitem>
  1245. <para><command>hw-address</command> - hardware (MAC) address can
  1246. be optionally specified for IPv6 lease. It is mandatory parameter
  1247. for IPv4 lease.</para>
  1248. </listitem>
  1249. <listitem>
  1250. <para><command>client-id</command> - client identifier is an
  1251. optional parameter that can be specified for IPv4 lease.</para>
  1252. </listitem>
  1253. <listitem>
  1254. <para><command>preferred-lft</command> - Preferred lifetime is an
  1255. optional parameter for IPv6 leases. If not specified, the value
  1256. configured for the subnet corresponding to the specified subnet-id
  1257. is used. This parameter is not used in IPv4.</para>
  1258. </listitem>
  1259. </itemizedlist>
  1260. </para>
  1261. <para>Here's an example of more complex lease addition:
  1262. <screen>
  1263. {
  1264. "command": "lease6-add",
  1265. "arguments": {
  1266. "subnet-id": 66,
  1267. "ip-address": "2001:db8::3",
  1268. "duid": "01:02:03:04:05:06:07:08",
  1269. "iaid": 1234,
  1270. "hw-address": "1a:1b:1c:1d:1e:1f",
  1271. "preferred-lft": 500,
  1272. "valid-lft": 1000,
  1273. "expire": 12345678,
  1274. "fqdn-fwd": true,
  1275. "fqdn-rev": true,
  1276. "hostname": "urania.example.org"
  1277. }
  1278. }
  1279. </screen>
  1280. </para>
  1281. <para>
  1282. The command returns a status that indicates either a success (result
  1283. 0) or a failure (result 1). Failed command always includes text
  1284. parameter that explains the cause of failure. Example results:
  1285. <screen>{ "result": 0, "text": "Lease added." }</screen> Example failure:
  1286. <screen>{ "result": 1, "text": "missing parameter 'ip-address' (&lt;string&gt;:3:19)" }</screen>
  1287. </para>
  1288. <section>
  1289. <title>lease4-get, lease6-get commands</title>
  1290. <para><command>lease4-get</command> or <command>lease6-get</command>
  1291. can be used to query the lease database and retrieve existing
  1292. leases. There are two types of parameters the
  1293. <command>lease4-get</command> supports: (address) or (subnet-id,
  1294. identifier-type, identifier). There are two types for
  1295. <command>lease6-get</command>: (address,type) or (subnet-id,
  1296. identifier-type, identifier, IAID, type). The first type of query is
  1297. used when the address (either IPv4 or IPv6) is known, but the details
  1298. of the lease aren't. One common use case of this type of query is to
  1299. find out whether a given address is being used or not. The second
  1300. query uses identifiers. For maximum flexibility, Kea stores the host
  1301. identifying information as a pair of values: type and the actual
  1302. identifier. Currently supported identifiers are "hw-address", "duid",
  1303. "circuit-id", "client-id" and "flex-id", but additional types may be
  1304. added in the future. If any new identifier types are defined in the
  1305. future, reservation-get command will support them
  1306. automatically.</para>
  1307. <para>
  1308. An example <command>lease4-get</command> command for getting a lease
  1309. by an IPv4 address looks as follows:
  1310. <screen>
  1311. {
  1312. "command": "lease4-get",
  1313. "arguments": {
  1314. "ip-address": "192.0.2.1"
  1315. }
  1316. }
  1317. </screen>
  1318. </para>
  1319. <para>An example of the <command>lease6-get</command> query
  1320. looks as follows:
  1321. <screen>
  1322. {
  1323. "command": "lease6-get",
  1324. "arguments": {
  1325. "ip-address": "2001:db8:1234:ab::",
  1326. "type": "IA_PD"
  1327. }
  1328. }</screen>
  1329. </para>
  1330. <para>An example query by (subnet-id, identifier-type,
  1331. identifier) for IPv4 lease looks as follows:
  1332. <screen>
  1333. {
  1334. "command": "lease4-get",
  1335. "arguments": {
  1336. "identifier-type": "hw-address",
  1337. "identifier": "08:08:08:08:08:08",
  1338. "subnet-id": 44
  1339. }
  1340. }</screen>
  1341. </para>
  1342. <para>An example query by (subnet-id, identifier-type,
  1343. identifier, iaid, type) for IPv6 lease looks as follows:
  1344. <screen>
  1345. {
  1346. "command": "lease4-get",
  1347. "arguments": {
  1348. "identifier-type": "duid",
  1349. "identifier": "08:08:08:08:08:08",
  1350. "iaid": 1234567,
  1351. "type": "IA_NA",
  1352. "subnet-id": 44
  1353. }
  1354. }</screen>
  1355. The type is an optional parameter. Supported values are: IA_NA
  1356. (non-temporary address) and IA_PD (IPv6 prefix) are supported.
  1357. If not specified, IA_NA is assumed.
  1358. </para>
  1359. <para><command>leaseX-get</command> returns a result that indicates a
  1360. result of the operation and lease details, if found. It has one of the
  1361. following values: 0 (success), 1 (error) or 2 (empty). The empty
  1362. result means that a query has been completed properly, but the object
  1363. (a lease in this case) has not been found. The lease parameters, if
  1364. found, are returned as arguments.
  1365. </para>
  1366. <para>
  1367. An example result returned when the host was found:
  1368. <screen>{
  1369. "arguments": {
  1370. "client-id": "42:42:42:42:42:42:42:42",
  1371. "cltt": 12345678,
  1372. "fqdn-fwd": false,
  1373. "fqdn-rev": true,
  1374. "hostname": "myhost.example.com.",
  1375. "hw-address": "08:08:08:08:08:08",
  1376. "ip-address": "192.0.2.1",
  1377. "state": 0,
  1378. "subnet-id": 44,
  1379. "valid-lft": 3600
  1380. },
  1381. "result": 0,
  1382. "text": "IPv4 lease found."
  1383. }</screen>
  1384. </para>
  1385. </section>
  1386. <section>
  1387. <title>lease4-del, lease6-del commands</title>
  1388. <para><command>leaseX-del</command> can be used to delete a lease from
  1389. the lease database. There are two types of parameters this command
  1390. supports, similar to leaseX-get commands: (address) for both v4 and
  1391. v6, (subnet-id, identifier-type, identifier) for v4 and (subnet-id,
  1392. identifier-type, identifier, type, IAID) for v6. The first type of
  1393. query is used when the address (either IPv4 or IPv6) is known, but the
  1394. details of the lease are not. One common use case of this type of query
  1395. is to remove a lease (e.g. you want a specific address to no longer be
  1396. used, no matter who may use it). The second query uses
  1397. identifiers. For maximum flexibility, this interface uses identifiers
  1398. as a pair of values: type and the actual identifier. Currently
  1399. supported identifiers are "hw-address" and "duid", but additional
  1400. types may be added in the future. </para>
  1401. <para>
  1402. An example command for deleting a host reservation by address looks
  1403. as follows:
  1404. <screen>
  1405. {
  1406. "command": "lease4-del",
  1407. "arguments": {
  1408. "ip-address": "192.0.2.202"
  1409. }
  1410. }</screen>
  1411. An example IPv4 lease deletion by (subnet-id, identifier-type, identifier) looks
  1412. as follows:
  1413. <screen>{
  1414. "command": "lease4-del",
  1415. "arguments": {
  1416. "identifier": "08:08:08:08:08:08",
  1417. "identifier-type": "hw-address",
  1418. "subnet-id": 44
  1419. }
  1420. }</screen>
  1421. </para>
  1422. <para><command>leaseX-get</command> returns a result that
  1423. indicates a outcome of the operation. It has one of the
  1424. following values: 0 (success), 1 (error) or 2 (empty). The
  1425. empty result means that a query has been completed properly,
  1426. but the object (a lease in this case) has not been found.
  1427. </para>
  1428. </section>
  1429. <section>
  1430. <title>lease4-update, lease6-update commands</title>
  1431. <para><command>lease4-update</command> and
  1432. <command>lease6-update</command> commands can be used to update
  1433. existing leases. Since all lease database backends are indexed by IP
  1434. addresses, it is not possible to update an address. All other fields
  1435. may be updated. If an address needs to be changed, please use
  1436. <command>leaseX-del</command> followed by
  1437. <command>leaseX-add</command> commands.</para>
  1438. <para>To use <command>leaseX-update</command> the lease must
  1439. be present in the lease database. If the lease is not there,
  1440. an error will be returned. Please use
  1441. <command>leaseX-add</command> to add new leases. You may
  1442. check if a lease is present using
  1443. <command>leaseX-get</command>, if needed.</para>
  1444. <para>
  1445. An example command updating IPv6 lease looks as follows:
  1446. <screen>{
  1447. "command": "lease4-update",
  1448. "arguments": {
  1449. "ip-address": "192.0.2.1",
  1450. "hostname": "newhostname.example.org",
  1451. "hw-address": "1a:1b:1c:1d:1e:1f",
  1452. "subnet-id": 44
  1453. }
  1454. }</screen>
  1455. </para>
  1456. <para>
  1457. An example command updating IPv6 lease looks as follows:
  1458. <screen>{
  1459. "command": "lease6-update",
  1460. "arguments": {
  1461. "ip-address": "2001:db8::1",
  1462. "duid": "88:88:88:88:88:88:88:88",
  1463. "iaid": 7654321,
  1464. "hostname": "newhostname.example.org",
  1465. "subnet-id": 66
  1466. }
  1467. }</screen>
  1468. </para>
  1469. </section>
  1470. <section>
  1471. <title>lease4-wipe, lease6-wipe commands</title>
  1472. <para><command>lease4-wipe</command> and
  1473. <command>lease6-wipe</command> are designed to remove all
  1474. leases associated with a given subnet. This administrative
  1475. task is expected to be used when existing subnet is being
  1476. retired. Note that the leases are not properly expired,
  1477. there are no DNS updates conducted, no log messages and
  1478. hooks are not called for leases being removed.</para>
  1479. <para>An example of <command>lease4-wipe</command> looks as follows:
  1480. <screen>{
  1481. "command": "lease4-wipe",
  1482. "arguments": {
  1483. "subnet-id": 44
  1484. }
  1485. }</screen>
  1486. </para>
  1487. <para>An example of <command>lease6-wipe</command> looks as follows:
  1488. <screen>{
  1489. "command": "lease6-wipe",
  1490. "arguments": {
  1491. "subnet-id": 66
  1492. }
  1493. }</screen>
  1494. </para>
  1495. <para>The commands return a textual description of the
  1496. number of leases removed and 0 (success) status code if any
  1497. leases were removed and 2 (empty) if there were no
  1498. leases. Status code 1 (error) may be returned in case the
  1499. parameeters are incorrect or some other exception is
  1500. encountered.</para>
  1501. <para>Note: not all backends support this command.</para>
  1502. </section>
  1503. </section>
  1504. </section>
  1505. <section id="subnet-cmds">
  1506. <title>subnet_cmds: Subnet Commands</title>
  1507. <para>
  1508. This section describes a hook application that offers a number of new
  1509. commands used to query and manipulate subnet configurations in Kea.
  1510. This application is very useful in deployments with a large number of
  1511. subnets being managed by the DHCP servers and when the subnets are
  1512. frequently updated. The commands offer lightweight approach for
  1513. manipulating subnets without a need to fully reconfigure the server
  1514. and without affecting existing servers' configurations.
  1515. </para>
  1516. <para>Currently this library is only available to ISC customers with a
  1517. support contract.</para>
  1518. <para>The following commands are currently supported:
  1519. <itemizedlist mark='bullet'>
  1520. <listitem>
  1521. <simpara><command>subnet4-list/subnet6-list</command>: lists all configured subnets
  1522. </simpara>
  1523. </listitem>
  1524. <listitem>
  1525. <simpara>
  1526. <command>subnet4-get/subnet6-get</command>: retrieves detailed information about a selected subnet
  1527. </simpara>
  1528. </listitem>
  1529. <listitem>
  1530. <simpara>
  1531. <command>subnet4-add/subnet6-add</command>: adds new subnet into server's configuration
  1532. </simpara>
  1533. </listitem>
  1534. <listitem>
  1535. <simpara>
  1536. <command>subnet4-del/subnet6-del</command>: removes a subnet from the server's configuration
  1537. </simpara>
  1538. </listitem>
  1539. </itemizedlist>
  1540. </para>
  1541. <section>
  1542. <title>subnet4-list command</title>
  1543. <para>
  1544. This command is used to list all currently configured subnets. The
  1545. subnets are returned in a brief form, i.e. a subnet identifier
  1546. and subnet prefix is included for each subnet. In order to retrieve
  1547. the detailed information about the subnet the
  1548. <command>subnet4-get</command> should be used.
  1549. </para>
  1550. <para>
  1551. This command has the simple structure:
  1552. <screen>
  1553. {
  1554. "command": "subnet4-list"
  1555. }
  1556. </screen>
  1557. </para>
  1558. <para>
  1559. The list of subnets returned as a result of this command is returned
  1560. in the following format:
  1561. <screen>
  1562. {
  1563. "result": 0,
  1564. "text": "2 IPv4 subnets found",
  1565. "arguments": {
  1566. "subnets": [
  1567. {
  1568. "id": 10,
  1569. "subnet": "10.0.0.0/8"
  1570. },
  1571. {
  1572. "id": 100,
  1573. "subnet": "192.0.2.0/24"
  1574. }
  1575. ]
  1576. }
  1577. </screen>
  1578. </para>
  1579. <para>
  1580. If no IPv4 subnets are found, an error code is returned along with
  1581. the error description.
  1582. </para>
  1583. </section>
  1584. <section>
  1585. <title>subnet6-list command</title>
  1586. <para>
  1587. This command is used to list all currently configured subnets. The
  1588. subnets are returned in a brief form, i.e. a subnet identifier
  1589. and subnet prefix is included for each subnet. In order to retrieve
  1590. the detailed information about the subnet the
  1591. <command>subnet6-get</command> should be used.
  1592. </para>
  1593. <para>
  1594. This command has the simple structure:
  1595. <screen>
  1596. {
  1597. "command": "subnet6-list"
  1598. }
  1599. </screen>
  1600. </para>
  1601. <para>
  1602. The list of subnets returned as a result of this command is returned
  1603. in the following format:
  1604. <screen>
  1605. {
  1606. "result": 0,
  1607. "text": "2 IPv6 subnets found",
  1608. "arguments": {
  1609. "subnets": [
  1610. {
  1611. "id": 11,
  1612. "subnet": "2001:db8:1::/64"
  1613. },
  1614. {
  1615. "id": 233,
  1616. "subnet": "3000::/16"
  1617. }
  1618. ]
  1619. }
  1620. </screen>
  1621. </para>
  1622. <para>
  1623. If no IPv6 subnets are found, an error code is returned along with
  1624. the error description.
  1625. </para>
  1626. </section>
  1627. <section>
  1628. <title>subnet4-get command</title>
  1629. <para>This command is used to retrieve detailed information about the
  1630. specified subnet. This command usually follows the
  1631. <command>subnet4-list</command>, which is used to discover available
  1632. subnets with their respective subnet identifiers and prefixes. Any of
  1633. those parameters can be then used in <command>subnet4-get</command>
  1634. to fetch subnet information:
  1635. <screen>
  1636. {
  1637. "command": "subnet4-get",
  1638. "arguments": {
  1639. "id": 10
  1640. }
  1641. }</screen>
  1642. or
  1643. <screen>
  1644. {
  1645. "command": "subnet4-get",
  1646. "arguments": {
  1647. "subnet": "10.0.0.0/8"
  1648. }
  1649. }
  1650. </screen>
  1651. </para>
  1652. <para>
  1653. If the subnet exists the response will be similar to this:
  1654. <screen>
  1655. {
  1656. "result": 0,
  1657. "text": "Info about IPv4 subnet 10.0.0.0/8 (id 10) returned",
  1658. "arguments": {
  1659. "subnets": [
  1660. {
  1661. "subnet": "10.0.0.0/8",
  1662. "id": 1,
  1663. "option-data": [
  1664. ....
  1665. ]
  1666. ...
  1667. }
  1668. ]
  1669. }
  1670. }
  1671. </screen>
  1672. </para>
  1673. </section>
  1674. <section>
  1675. <title>subnet6-get command</title>
  1676. <para>This command is used to retrieve detailed information about the
  1677. specified subnet. This command usually follows the
  1678. <command>subnet6-list</command>, which is used to discover available
  1679. subnets with their respective subnet identifiers and prefixes. Any of
  1680. those parameters can be then used in <command>subnet6-get</command>
  1681. to fetch subnet information:
  1682. <screen>
  1683. {
  1684. "command": "subnet6-get",
  1685. "arguments": {
  1686. "id": 11
  1687. }
  1688. }
  1689. </screen>
  1690. or
  1691. <screen>
  1692. {
  1693. "command": "subnet6-get",
  1694. "arguments": {
  1695. "subnet": "2001:db8:1::/64"
  1696. }
  1697. }</screen>
  1698. If the subnet exists the response will be similar to this:
  1699. <screen>
  1700. {
  1701. "result": 0,
  1702. "text": "Info about IPv6 subnet 2001:db8:1::/64 (id 11) returned",
  1703. "arguments": {
  1704. "subnets": [
  1705. {
  1706. "subnet": "2001:db8:1::/64",
  1707. "id": 1,
  1708. "option-data": [
  1709. ...
  1710. ]
  1711. ....
  1712. }
  1713. ]
  1714. }
  1715. }
  1716. </screen>
  1717. </para>
  1718. </section>
  1719. <section>
  1720. <title>subnet4-add</title>
  1721. <para>
  1722. This command is used to create and add new subnet to the existing
  1723. server configuration. This operation has no impact on other
  1724. subnets. The subnet identifier must be specified and must be
  1725. unique among all subnets. If the identifier or a subnet prefix is
  1726. not unique an error is reported and the subnet is not added.
  1727. </para>
  1728. <para>
  1729. The subnet information within this command has the same structure
  1730. as the subnet information in the server configuration file with the
  1731. exception that static host reservations must not be specified
  1732. within <command>subnet4-add</command>. The commands described in
  1733. <xref linkend="host-cmds"/> should be used to add, remove and
  1734. modify static reservations.
  1735. <screen>
  1736. {
  1737. "command": "subnet4-add",
  1738. "arguments": {
  1739. "subnets": [ {
  1740. "id": 123,
  1741. "subnet": "10.20.30.0/24",
  1742. ...
  1743. } ]
  1744. }
  1745. }
  1746. </screen>
  1747. </para>
  1748. <para>
  1749. The response to this command has the following structure:
  1750. <screen>
  1751. {
  1752. "result": 0,
  1753. "text": "IPv4 subnet added",
  1754. "arguments": {
  1755. "subnets": [
  1756. {
  1757. "id": 123,
  1758. "subnet": "10.20.30.0/24"
  1759. }
  1760. ]
  1761. }
  1762. }
  1763. </screen>
  1764. </para>
  1765. </section>
  1766. <section>
  1767. <title>subnet6-add</title>
  1768. <para>
  1769. This command is used to create and add new subnet to the existing
  1770. server configuration. This operation has no impact on other
  1771. subnets. The subnet identifier must be specified and must be
  1772. unique among all subnets. If the identifier or a subnet prefix is
  1773. not unique an error is reported and the subnet is not added.
  1774. </para>
  1775. <para>
  1776. The subnet information within this command has the same structure
  1777. as the subnet information in the server configuration file with the
  1778. exception that static host reservations must not be specified
  1779. within <command>subnet6-add</command>. The commands described in
  1780. <xref linkend="host-cmds"/> should be used to add, remove and
  1781. modify static reservations.
  1782. <screen>
  1783. {
  1784. "command": "subnet6-add",
  1785. "arguments": {
  1786. "subnet6": [ {
  1787. "id": 234,
  1788. "subnet": "2001:db8:1::/64",
  1789. ...
  1790. } ]
  1791. }
  1792. }
  1793. </screen>
  1794. </para>
  1795. <para>
  1796. The response to this command has the following structure:
  1797. <screen>
  1798. {
  1799. "result": 0,
  1800. "text": "IPv6 subnet added",
  1801. "arguments": {
  1802. "subnet6": [
  1803. {
  1804. "id": 234,
  1805. "subnet": "2001:db8:1::/64"
  1806. }
  1807. ]
  1808. }
  1809. }
  1810. </screen>
  1811. </para>
  1812. <para>
  1813. It is recommended, but not mandatory to specify subnet
  1814. id. If not specified, Kea will try to assign the next
  1815. subnet-id value. This automatic ID value generator is
  1816. simple. It returns a previously automatically assigned value
  1817. increased by 1. This works well, unless you manually create
  1818. a subnet with a value bigger than previously used. For
  1819. example, if you call subnet4-add five times, each without
  1820. id, Kea will assign IDs: 1,2,3,4 and 5 and it will work just
  1821. fine. However, if you try to call subnet4-add five times,
  1822. with the first subnet having subnet-id of value 3 and
  1823. remaining ones having no subnet-id, it will fail. The first
  1824. command (with explicit value) will use subnet-id 3, the
  1825. second command will create a subnet with id of 1, the third
  1826. will use value of 2 and finally the fourth will have the
  1827. subnet-id value auto-generated as 3. However, since there is
  1828. already a subnet with that id, it will fail.
  1829. </para>
  1830. <para>
  1831. The general recommendation is to either: never use explicit
  1832. values (so the auto-generated values will always work) or
  1833. always use explicit values (so the auto-generation is never
  1834. used). You can mix those two approaches only if you
  1835. understand how the internal automatic subnet-id generation works.
  1836. </para>
  1837. </section>
  1838. <section>
  1839. <title>subnet4-del command</title>
  1840. <para>
  1841. This command is used to remove a subnet from the server's configuration.
  1842. This command has no effect on other configured subnets but removing
  1843. a subnet has certain implications which the server's administrator
  1844. should be aware of.
  1845. </para>
  1846. <para>
  1847. In most cases the server has assigned some leases to the clients
  1848. belonging to the subnet. The server may also be configured with
  1849. static host reservations which are associated with this subnet.
  1850. The current implementation of the <command>subnet4-del</command>
  1851. removes neither the leases nor host reservations associated with
  1852. a subnet. This is the safest approach because the server doesn't
  1853. loose track of leases assigned to the clients from this subnet.
  1854. However, removal of the subnet may still cause configuration
  1855. errors and conflicts. For example: after removal of the subnet,
  1856. the server administrator may add a new subnet with the ID used
  1857. previously for the removed subnet. This means that the existing
  1858. leases and static reservations will be in conflict with this
  1859. new subnet. Thus, we recommend that this command is used with extreme
  1860. caution.
  1861. </para>
  1862. <para>The command has the following structure:
  1863. <screen>
  1864. {
  1865. "command": "subnet4-del",
  1866. "arguments": {
  1867. "id": 123
  1868. }
  1869. }
  1870. </screen>
  1871. </para>
  1872. <para>
  1873. The example successful response may look like this:
  1874. <screen>
  1875. {
  1876. "result": 0,
  1877. "text": "IPv4 subnet 192.0.2.0/24 (id 123) deleted",
  1878. "arguments": {
  1879. "subnets": [
  1880. {
  1881. "id": 123,
  1882. "subnet": "192.0.2.0/24"
  1883. }
  1884. ]
  1885. }
  1886. }
  1887. </screen>
  1888. </para>
  1889. </section>
  1890. <section>
  1891. <title>subnet6-del command</title>
  1892. <para>
  1893. This command is used to remove a subnet from the server's configuration.
  1894. This command has no effect on other configured subnets but removing
  1895. a subnet has certain implications which the server's administrator
  1896. should be aware of.
  1897. </para>
  1898. <para>
  1899. In most cases the server has assigned some leases to the clients
  1900. belonging to the subnet. The server may also be configured with
  1901. static host reservations which are associated with this subnet.
  1902. The current implementation of the <command>subnet6-del</command>
  1903. removes neither the leases nor host reservations associated with
  1904. a subnet. This is the safest approach because the server doesn't
  1905. loose track of leases assigned to the clients from this subnet.
  1906. However, removal of the subnet may still cause configuration
  1907. errors and conflicts. For example: after removal of the subnet,
  1908. the server administrator may add a new subnet with the ID used
  1909. previously for the removed subnet. This means that the existing
  1910. leases and static reservations will be in conflict with this
  1911. new subnet. Thus, we recommend that this command is used with extreme
  1912. caution.
  1913. </para>
  1914. <para>The command has the following structure:
  1915. <screen>
  1916. {
  1917. "command": "subnet6-del",
  1918. "arguments": {
  1919. "id": 234
  1920. }
  1921. }
  1922. </screen>
  1923. </para>
  1924. <para>
  1925. The example successful response may look like this:
  1926. <screen>
  1927. {
  1928. "result": 0,
  1929. "text": "IPv6 subnet 2001:db8:1::/64 (id 234) deleted",
  1930. "subnets": [
  1931. {
  1932. "id": 234,
  1933. "subnet": "2001:db8:1::/64"
  1934. }
  1935. ]
  1936. }
  1937. </screen>
  1938. </para>
  1939. </section>
  1940. </section>
  1941. </section> <!-- end of subnet commands -->
  1942. <section id="user-context">
  1943. <title>User contexts</title>
  1944. <para>Hook libraries can have their own configuration parameters. That is
  1945. convenient if the parameter applies to the whole library. However,
  1946. sometimes it is very useful if certain configuration entities are extended
  1947. with additional configuration data. This is where the concept of user
  1948. contexts comes in. A sysadmin can define an arbitrary set of data and
  1949. attach it to Kea structures, as long as the data is specified as JSON map.
  1950. In particular, it is possible to define fields that are integers, strings,
  1951. boolean, lists and maps. It is possible to define nested structures of
  1952. arbitrary complexity. Kea does not use that data on its own, simply stores
  1953. and makes it available for the hook libraries.
  1954. </para>
  1955. <para>
  1956. Another use case for user contexts may be storing comments and other
  1957. information that will be retained by Kea. Regular comments are discarded
  1958. when configuration is loaded, but user contexts are retained. This is
  1959. useful if you want your comments to survive config-set, config-get
  1960. operations for example.
  1961. </para>
  1962. <para>
  1963. As of Kea 1.3, the structures that allow user contexts are pools of all
  1964. types (addresses and prefixes) and subnets. These are supported in both
  1965. DHCPv4 and DHCPv6. It is expected that other structures will be extended
  1966. in the future to provide the user context capability.
  1967. </para>
  1968. </section>
  1969. </chapter> <!-- hooks-libraries -->