1.. _lease-cmds: 2 3lease_cmds: Lease Commands 4========================== 5 6This section describes the hook library with commands used to manage 7leases. Kea provides a way to store lease information in several 8backends (memfile, MySQL, PostgreSQL, and Cassandra), and this library 9provides an interface that can manipulate leases in a unified, safe way. 10In particular, it allows things previously impossible: lease 11manipulation in memfile while Kea is running, sanity check changes, 12lease existence checks, and removal of all leases belonging to a 13specific subnet. The hook library can also catch more obscure errors, like an attempt 14to add a lease with a subnet-id that does not exist in the 15configuration, or configuring a lease to use an address that is outside 16of the subnet to which it is supposed to belong. The library also 17provides a non-programmatic way to manage user contexts associated with 18leases. 19 20.. note:: 21 22 This library may only be loaded by the ``kea-dhcp4`` or the 23 ``kea-dhcp6`` process. 24 25There are many use cases where an administrative command may be useful; 26for example, during migration between servers or different vendors, when 27a certain network is being retired, or when a device has been 28disconnected and the system administrator knows that it will not be coming 29back. The "get" queries may be useful for automating certain management 30and monitoring tasks. They can also act as preparatory steps for lease 31updates and removals. 32 33This library provides the following commands: 34 35- ``lease4-add`` - adds a new IPv4 lease. 36 37- ``lease6-add`` - adds a new IPv6 lease. 38 39- ``lease6-bulk-apply`` - creates, updates and/or deletes multiple 40 IPv6 leases in a single transaction. 41 42- ``lease4-get`` - checks whether an IPv4 lease with the specified 43 parameters exists and returns it if it does. 44 45- ``lease6-get`` - checks whether an IPv6 lease with the specified 46 parameters exists and returns it if it does. 47 48- ``lease4-get-all`` - returns all IPv4 leases or all IPv4 leases for 49 the specified subnets. 50 51- ``lease6-get-all`` - returns all IPv6 leases or all IPv6 leases for 52 the specified subnets. 53 54- ``lease4-get-page`` - returns a set ("page") of leases from the list 55 of all IPv4 leases in the database. By iterating through the pages it 56 is possible to retrieve all the leases. 57 58- ``lease6-get-page`` - returns a set ("page") of leases from the list 59 of all IPv6 leases in the database. By iterating through the pages it 60 is possible to retrieve all the leases. 61 62- ``lease4-get-by-hw-address`` - return all IPv4 leases with the specified 63 hardware address. 64 65- ``lease4-get-by-client-id`` - return all IPv4 leases with the specified 66 client id. 67 68- ``lease6-get-by-duid`` - returns all IPv6 leases with the specified DUID. 69 70- ``lease4-get-by-hostname`` - return all IPv4 leases with the specified 71 hostname. 72 73- ``lease6-get-by-hostname`` - return all IPv6 leases with the specified 74 hostname. 75 76- ``lease4-del`` - deletes an IPv4 lease with the specified parameters. 77 78- ``lease6-del`` - deletes an IPv6 lease with the specified parameters. 79 80- ``lease4-update`` - updates an IPv4 lease. 81 82- ``lease6-update`` - updates an IPv6 lease. 83 84- ``lease4-wipe`` - removes all leases from a specific IPv4 subnet or 85 from all subnets. 86 87- ``lease6-wipe`` - removes all leases from a specific IPv6 subnet or 88 from all subnets. 89 90- ``lease4-resend-ddns`` - resend a request to update DNS entries for 91 an existing lease. 92 93- ``lease6-resend-ddns`` - resend a request to update DNS entries for 94 an existing lease. 95 96The lease commands library is part of the open source code and is 97available to every Kea user. 98 99All commands use JSON syntax and can be issued either using the control 100channel (see :ref:`ctrl-channel`) or Control Agent (see 101:ref:`kea-ctrl-agent`). 102 103The library can be loaded in the same way as other hook libraries, and 104it does not take any parameters. It supports both DHCPv4 and DHCPv6 105servers. 106 107:: 108 109 "Dhcp6": { 110 "hooks-libraries": [ 111 { 112 "library": "/path/libdhcp_lease_cmds.so" 113 } 114 ... 115 ] 116 } 117 118.. _command-lease4-add: 119 120.. _command-lease6-add: 121 122The lease4-add, lease6-add Commands 123~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 124 125The ``lease4-add`` and ``lease6-add`` commands allow for the creation of 126a new lease. Typically Kea creates a lease when it first sees a new 127device; however, sometimes it may be convenient to create the lease 128manually. The ``lease4-add`` command requires at least two parameters: 129an IPv4 address and an identifier, i.e. hardware (MAC) address. A third 130parameter, subnet-id, is optional. If the subnet-id is not specified or 131the specified value is 0, Kea will try to determine the value by running 132a subnet-selection procedure. If specified, however, its value must 133match the existing subnet. The simplest successful call might look as 134follows: 135 136:: 137 138 { 139 "command": "lease4-add", 140 "arguments": { 141 "ip-address": "192.0.2.202", 142 "hw-address": "1a:1b:1c:1d:1e:1f" 143 } 144 } 145 146The ``lease6-add`` command requires three parameters: an IPv6 address, 147an IAID value (identity association identifier, a value sent by 148clients), and a DUID. As with lease4-add, the subnet-id parameter is 149optional. If the subnet-id is not specified or the provided value is 0, 150Kea will try to determine the value by running a subnet-selection 151procedure. If specified, however, its value must match the existing 152subnet. For example: 153 154:: 155 156 { 157 "command": "lease6-add", 158 "arguments": { 159 "subnet-id": 66, 160 "ip-address": "2001:db8::3", 161 "duid": "1a:1b:1c:1d:1e:1f:20:21:22:23:24", 162 "iaid": 1234 163 } 164 } 165 166``lease6-add`` can also be used to add leases for IPv6 prefixes. In this 167case there are three additional parameters that must be specified: 168subnet-id, type (set to value of "IA_PD"), and prefix length. The actual 169prefix is set using the ip-address field. Note that Kea cannot guess 170subnet-id values for prefixes; they must be specified explicitly. For 171example, to configure a lease for prefix 2001:db8:abcd::/48, the 172following command can be used: 173 174:: 175 176 { 177 "command": "lease6-add", 178 "arguments": { 179 "subnet-id": 66, 180 "type": "IA_PD", 181 "ip-address": "2001:db8:abcd::", 182 "prefix-len": 48, 183 "duid": "1a:1b:1c:1d:1e:1f:20:21:22:23:24", 184 "iaid": 1234 185 } 186 } 187 188The commands can take several additional optional parameters: 189 190- ``valid-lft`` - specifies the lifetime of the lease, expressed in 191 seconds. If not specified, the value configured in the subnet related 192 to the specified subnet-id is used. 193 194- ``expire`` - creates a timestamp of the lease expiration time, 195 expressed in UNIX format (seconds since 1 Jan 1970). If not 196 specified, the default value is now + the lease lifetime (the value 197 of valid-lft). 198 199- ``fqdn-fwd`` - specifies whether the lease should be marked as if a 200 forward DNS update were conducted. Note this only affects the 201 data stored in the lease database, and no DNS update will be 202 performed. If configured, a DNS update to remove the A or AAAA 203 records will be conducted when the lease is removed due to expiration 204 or being released by a client. If not specified, the default value is 205 false. The hostname parameter must be specified if fqdn-fwd is set to 206 true. 207 208- ``fqdn-rev`` - specifies whether the lease should be marked as if 209 reverse DNS update were conducted. Note this only affects the 210 data stored in the lease database, and no DNS update will be 211 performed.. If configured, a DNS update to remove the PTR record will 212 be conducted when the lease is removed due to expiration or being 213 released by a client. If not specified, the default value is false. 214 The hostname parameter must be specified if fqdn-fwd is set to true. 215 216- ``hostname`` - specifies the hostname to be associated with this 217 lease. Its value must be non-empty if either fqdn-fwd or fwdn-rev are 218 set to true. If not specified, the default value is an empty string. 219 220- ``hw-address`` - optionally specifies a hardware (MAC) address for an 221 IPv6 lease. It is a mandatory parameter for an IPv4 lease. 222 223- ``client-id`` - optionally specifies a client identifier for an IPv4 224 lease. 225 226- ``preferred-lft`` - optionally specifies a preferred lifetime for 227 IPv6 leases. If not specified, the value configured for the subnet 228 corresponding to the specified subnet-id is used. This parameter is 229 not used when adding an IPv4 lease. 230 231- ``state`` - specify the state of added lease, can be 0 for ``default``, 232 1 for ``declined`` and 2 for ``expired-reclaimed`` state. Any other 233 value will cause an error. Note that using 1 for a "IA_PD" lease type is 234 illegal and will be rejected. 235 236- ``user-context`` - specifies the user context to be associated with 237 this lease. It must be a JSON map. 238 239Here is an example of a more complex lease addition: 240 241:: 242 243 { 244 "command": "lease6-add", 245 "arguments": { 246 "subnet-id": 66, 247 "ip-address": "2001:db8::3", 248 "duid": "01:02:03:04:05:06:07:08", 249 "iaid": 1234, 250 "hw-address": "1a:1b:1c:1d:1e:1f", 251 "preferred-lft": 500, 252 "valid-lft": 1000, 253 "expire": 12345678, 254 "fqdn-fwd": true, 255 "fqdn-rev": true, 256 "state": 0, 257 "hostname": "urania.example.org", 258 "user-context": { "version": 1 } 259 } 260 } 261 262The command returns a status that indicates either success (result 0) 263or failure (result 1). A failed command always includes a text 264parameter that explains the cause of failure. For example: 265 266:: 267 268 { "result": 0, "text": "Lease added." } 269 270Example failure: 271 272:: 273 274 { "result": 1, "text": "missing parameter 'ip-address' (<string>:3:19)" } 275 276 277.. _command-lease6-bulk-apply: 278 279The lease6-bulk-apply Command 280~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 281 282The ``lease6-bulk-apply`` was implemented to address 283the performance penalty in the High-Availability mode when a single DHCPv6 284transaction resulted in multiple lease updates sent to the partner, if 285multiple address and/or prefix leases were allocated. Consider the case 286when a DHCPv6 client requests the assignment of two IPv6 addresses and two IPv6 287prefixes: that may result in allocation of four leases. In addition, 288DHCPv6 may assign a different address than the one requested by the client during 289the renew or rebind stage, and delete the leases previously used by this client. 290There are six lease changes sent between the HA partners in this case. 291Sending these updates in individual commands, e.g. via ``lease6-update``, 292is highly inefficient and produces unnecessary delays in communication, 293both between the HA partners and in sending the response to the DHCPv6 client. 294 295The ``lease6-bulk-apply`` command deals with this 296problem by aggregating all lease changes in a single command. Both 297deleted leases and new/updated leases are conveyed in a single command. 298The receiving server iterates over the deleted leases and deletes them 299from its lease database. Next, it iterates over the new/updated leases 300and adds them to the database or updates them if they already exist. 301 302Even though High Availability is the major application for 303this command, it can be freely used in all cases when it is desired to 304send multiple lease changes in a single command. 305 306In the following example, we ask to delete two leases and to add 307or update two other leases in the database: 308 309 310:: 311 312 { 313 "command": "lease6-bulk-apply", 314 "arguments": { 315 "deleted-leases": [ 316 { 317 "ip-address": "2001:db8:abcd::", 318 "type": "IA_PD", 319 ... 320 }, 321 { 322 "ip-address": "2001:db8:abcd::234", 323 "type": "IA_NA", 324 ... 325 } 326 ], 327 "leases": [ 328 { 329 "subnet-id": 66, 330 "ip-address": "2001:db8:cafe::", 331 "type": "IA_PD", 332 ... 333 }, 334 { 335 "subnet-id": 66, 336 "ip-address": "2001:db8:abcd::333", 337 "type": "IA_NA", 338 ... 339 } 340 ] 341 } 342 } 343 344If any of the leases are malformed, no lease changes are applied 345to the lease database. If the leases are well-formed but there is a 346failure to apply any of the lease changes to the database, the command 347continues to be processed for other leases. All the leases for which 348the command was unable to apply the changes in the database are 349listed in the response. For example: 350 351:: 352 353 { 354 "result": 0, 355 "text": "Bulk apply of 2 IPv6 leases completed". 356 "arguments": { 357 "failed-deleted-leases": [ 358 { 359 "ip-address": "2001:db8:abcd::", 360 "type": "IA_PD", 361 "result": 3, 362 "error-message": "no lease found" 363 } 364 ], 365 "failed-leases": [ 366 { 367 "ip-address": "2001:db8:cafe::", 368 "type": "IA_PD", 369 "result": 1, 370 "error-message": "unable to communicate with the lease database" 371 } 372 ] 373 } 374 } 375 376The response above indicates that the hooks library was unable to 377delete the lease for prefix "2001:db8:abcd::" and add or update the lease 378for prefix "2001:db8:cafe::". However, there are two other lease changes 379which have been applied as indicated by the text message. The 380``result`` is the status constant that indicates the type 381of the error experienced for the particular lease. The meaning of the 382returned codes are the same as the results returned for the commands. 383In particular, the result of 1 indicates an error while processing the 384lease, e.g. a communication error with the database. The result of 3 385indicates that an attempt to delete the lease was unsuccessful because 386such a lease doesn't exist (empty result). 387 388.. _command-lease4-get: 389 390.. _command-lease6-get: 391 392The lease4-get, lease6-get Commands 393~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 394 395``lease4-get`` or ``lease6-get`` can be used to query the lease database 396and retrieve existing leases. There are two types of parameters the 397``lease4-get`` command supports: (address) or (subnet-id, 398identifier-type, identifier). There are also two types for 399``lease6-get``: (address, type) or (subnet-id, identifier-type, 400identifier, IAID, type). The first type of query is used when the 401address (either IPv4 or IPv6) is known, but the details of the lease are 402not; one common use case of this type of query is to find out whether a 403given address is being used. The second query uses identifiers; 404currently supported identifiers for leases are: "hw-address" (IPv4 405only), "client-id" (IPv4 only), and "duid" (IPv6 only). 406 407An example ``lease4-get`` command for getting a lease using an IPv4 408address is: 409 410:: 411 412 { 413 "command": "lease4-get", 414 "arguments": { 415 "ip-address": "192.0.2.1" 416 } 417 } 418 419An example of the ``lease6-get`` query is: 420 421:: 422 423 { 424 "command": "lease6-get", 425 "arguments": { 426 "ip-address": "2001:db8:1234:ab::", 427 "type": "IA_PD" 428 } 429 } 430 431An example query by "hw-address" for an IPv4 lease looks as follows: 432 433:: 434 435 { 436 "command": "lease4-get", 437 "arguments": { 438 "identifier-type": "hw-address", 439 "identifier": "08:08:08:08:08:08", 440 "subnet-id": 44 441 } 442 } 443 444An example query by "client-id" for an IPv4 lease looks as follows: 445 446:: 447 448 { 449 "command": "lease4-get", 450 "arguments": { 451 "identifier-type": "client-id", 452 "identifier": "01:01:02:03:04:05:06", 453 "subnet-id": 44 454 } 455 } 456 457An example query by (subnet-id, identifier-type, identifier, iaid, type) 458for an IPv6 lease is: 459 460:: 461 462 { 463 "command": "lease4-get", 464 "arguments": { 465 "identifier-type": "duid", 466 "identifier": "08:08:08:08:08:08", 467 "iaid": 1234567, 468 "type": "IA_NA", 469 "subnet-id": 44 470 } 471 } 472 473The type is an optional parameter. Supported values are: IA_NA 474(non-temporary address) and IA_PD (IPv6 prefix). If not specified, IA_NA 475is assumed. 476 477``leaseX-get`` returns a result that indicates a result of the operation 478and lease details, if found. It has one of the following values: 0 479(success), 1 (error), or 3 (empty). An empty result means that a query 480has been completed properly, but the object (a lease in this case) has 481not been found. The lease parameters, if found, are returned as 482arguments. 483 484An example result returned when the host was found: 485 486:: 487 488 { 489 "arguments": { 490 "client-id": "42:42:42:42:42:42:42:42", 491 "cltt": 12345678, 492 "fqdn-fwd": false, 493 "fqdn-rev": true, 494 "hostname": "myhost.example.com.", 495 "hw-address": "08:08:08:08:08:08", 496 "ip-address": "192.0.2.1", 497 "state": 0, 498 "subnet-id": 44, 499 "valid-lft": 3600 500 }, 501 "result": 0, 502 "text": "IPv4 lease found." 503 } 504 505.. _command-lease4-get-all: 506 507.. _command-lease6-get-all: 508 509The lease4-get-all, lease6-get-all Commands 510~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 511 512``lease4-get-all`` and ``lease6-get-all`` are used to retrieve all IPv4 513or IPv6 leases, or all leases for the specified set of subnets. All 514leases are returned when there are no arguments specified with the 515command, as in the following example: 516 517:: 518 519 { 520 "command": "lease4-get-all" 521 } 522 523If arguments are provided, it is expected that they contain the 524"subnets" parameter, which is a list of subnet identifiers for which the 525leases should be returned. For example, in order to retrieve all IPv6 526leases belonging to the subnets with identifiers 1, 2, 3, and 4: 527 528:: 529 530 { 531 "command": "lease6-get-all", 532 "arguments": { 533 "subnets": [ 1, 2, 3, 4 ] 534 } 535 } 536 537The returned response contains a detailed list of leases in the 538following format: 539 540:: 541 542 { 543 "arguments": { 544 "leases": [ 545 { 546 "cltt": 12345678, 547 "duid": "42:42:42:42:42:42:42:42", 548 "fqdn-fwd": false, 549 "fqdn-rev": true, 550 "hostname": "myhost.example.com.", 551 "hw-address": "08:08:08:08:08:08", 552 "iaid": 1, 553 "ip-address": "2001:db8:2::1", 554 "preferred-lft": 500, 555 "state": 0, 556 "subnet-id": 44, 557 "type": "IA_NA", 558 "valid-lft": 3600 559 }, 560 { 561 "cltt": 12345678, 562 "duid": "21:21:21:21:21:21:21:21", 563 "fqdn-fwd": false, 564 "fqdn-rev": true, 565 "hostname": "", 566 "iaid": 1, 567 "ip-address": "2001:db8:0:0:2::", 568 "preferred-lft": 500, 569 "prefix-len": 80, 570 "state": 0, 571 "subnet-id": 44, 572 "type": "IA_PD", 573 "valid-lft": 3600 574 } 575 ] 576 }, 577 "result": 0, 578 "text": "2 IPv6 lease(s) found." 579 } 580 581.. 582 583.. warning:: 584 585 The ``lease4-get-all`` and ``lease6-get-all`` commands may result in 586 very large responses. This may have a negative impact on the DHCP 587 server's responsiveness while the response is generated and 588 transmitted over the control channel, as the server imposes no 589 restriction on the number of leases returned as a result of this 590 command. 591 592.. _command-lease4-get-page: 593 594.. _command-lease6-get-page: 595 596The lease4-get-page, lease6-get-page Commands 597~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 598 599The ``lease4-get-all`` and ``lease6-get-all`` commands may result in 600very large responses; generating such a response may consume CPU 601bandwidth as well as memory. It may even cause the server to become 602unresponsive. In case of large lease databases it is usually better to 603retrieve leases in chunks, using the paging mechanism. 604``lease4-get-page`` and ``lease6-get-page`` implement a paging mechanism 605for DHCPv4 and DHCPv6 servers respectively. The following command 606retrieves the first 1024 IPv4 leases: 607 608:: 609 610 { 611 "command": "lease4-get-page", 612 "arguments": { 613 "from": "start", 614 "limit": 1024 615 } 616 } 617 618The keyword ``start`` denotes that the first page of leases should be 619retrieved. Alternatively, an IPv4 zero address can be specified to 620retrieve the first page: 621 622:: 623 624 { 625 "command": "lease4-get-page", 626 "arguments": { 627 "from": "0.0.0.0", 628 "limit": 1024 629 } 630 } 631 632Similarly, the IPv6 zero address can be specified in the 633``lease6-get-page`` command: 634 635:: 636 637 { 638 "command": "lease6-get-page", 639 "arguments": { 640 "from": "::", 641 "limit": 6 642 } 643 } 644 645The response has the following structure: 646 647:: 648 649 { 650 "arguments": { 651 "leases": [ 652 { 653 "ip-address": "2001:db8:2::1", 654 ... 655 }, 656 { 657 "ip-address": "2001:db8:2::9", 658 ... 659 }, 660 { 661 "ip-address": "2001:db8:3::1", 662 ... 663 }, 664 { 665 "ip-address": "2001:db8:5::3", 666 ... 667 } 668 { 669 "ip-address": "2001:db8:4::1", 670 ... 671 }, 672 { 673 "ip-address": "2001:db8:2::7", 674 ... 675 } 676 677 ], 678 "count": 6 679 }, 680 "result": 0, 681 "text": "6 IPv6 lease(s) found." 682 } 683 684Note that the leases' details were excluded from the response above for 685brevity. 686 687Generally, the returned list is not sorted in any particular order. Some 688lease database backends may sort leases in ascending order of addresses, 689but the controlling client must not rely on this behavior. In cases of 690highly distributed databases, such as Cassandra, ordering may be 691inefficient or even impossible. 692 693The ``count`` parameter contains the number of returned leases on the 694page. 695 696To fetch the next page, the client must use the last address of the 697current page as an input to the next ``lease4-get-page`` or 698``lease6-get-page`` command call. In this example it is: 699 700:: 701 702 { 703 "command": "lease6-get-page", 704 "arguments": { 705 "from": "2001:db8:2::7", 706 "count": 6 707 } 708 } 709 710because 2001:db8:2::7 is the last address on the current page. 711 712The client may assume that it has reached the last page when the 713``count`` value is lower than that specified in the command; this 714includes the case when the ``count`` is equal to 0, meaning that no 715leases were found. 716 717.. _command-lease4-get-by-hw-address: 718 719.. _command-lease4-get-by-client-id: 720 721.. _command-lease6-get-by-duid: 722 723.. _command-lease4-get-by-hostname: 724 725.. _command-lease6-get-by-hostname: 726 727The lease4-get-by-\*, lease6-get-by-\* Commands 728~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 729 730``leaseX-get-by-Y`` can be used to query the lease database and 731retrieve all existing leases with a specified hardware address (IPv4 732only), client id IPv4 only), duid (IPv6 only) identifiers or hostname. 733 734An example ``lease4-get-by-hw-address`` command for getting IPv4 leases 735with a given hardware address is: 736 737:: 738 739 { 740 "command": "lease4-get-by-hw-address", 741 "arguments": { 742 "hw-address": "08:08:08:08:08:08" 743 } 744 } 745 746An example of the ``lease6-get-by-hostname`` is: 747 748:: 749 750 { 751 "command": "lease6-get-by-hostname", 752 "arguments": { 753 "hostname": "myhost.example.org" 754 } 755 } 756 757The by key is the only parameter. The returned response contains a detailed 758list of leases in the same format as ``leaseX-get-all``. This list can be 759empty and usually is never large. 760 761.. _command-lease4-del: 762 763.. _command-lease6-del: 764 765The lease4-del, lease6-del Commands 766~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 767 768``leaseX-del`` can be used to delete a lease from the lease database. 769There are two types of parameters this command supports, similar to the 770leaseX-get commands: (address) for both v4 and v6, (subnet-id, 771identifier-type, identifier) for v4, and (subnet-id, identifier-type, 772identifier, type, IAID) for v6. The first type of query is used when the 773address (either IPv4 or IPv6) is known, but the details of the lease are 774not. One common use case is where an administrator wants a specified 775address to no longer be used. The second form of the command uses 776identifiers. For maximum flexibility, this interface uses identifiers as 777a pair of values: the type and the actual identifier. The currently 778supported identifiers are "hw-address" (IPv4 only), "client-id" (IPv4 779only), and "duid" (IPv6 only). 780 781An example command for deleting a lease by address is 782 783:: 784 785 { 786 "command": "lease4-del", 787 "arguments": { 788 "ip-address": "192.0.2.202" 789 } 790 } 791 792An example IPv4 lease deletion by "hw-address" is: 793 794:: 795 796 { 797 "command": "lease4-del", 798 "arguments": { 799 "identifier": "08:08:08:08:08:08", 800 "identifier-type": "hw-address", 801 "subnet-id": 44 802 } 803 } 804 805 806As of Kea 1.7.10, a new parameter, ``update-ddns``, is supported (IPv4 and IPv6). 807When true it instructs the server to queue a request to kea-dhcp-ddns to 808remove DNS entries after the lease is successfully deleted if: 809 810- DDNS updating is enabled. (i.e. "dhcp-ddns":{ "enable-updates": true }) 811- The lease's hostname is not empty. 812- At least one of the lease's DNS direction flags (fdqn_fwd or fdqn_rev) is true. 813 814This parameter defaults to false. An example of its use is shown below: 815 816:: 817 818 { 819 "command": "lease4-del", 820 "arguments": { 821 "ip-address": "192.0.2.202", 822 "update-ddns": true 823 } 824 } 825 826 827``leaseX-del`` returns a result that indicates the outcome of the 828operation. It has one of the following values: 0 (success), 1 (error), 829or 3 (empty). The empty result means that a query has been completed 830properly, but the object (a lease in this case) has not been found. 831 832.. _command-lease4-update: 833 834.. _command-lease6-update: 835 836The lease4-update, lease6-update Commands 837~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 838 839The ``lease4-update`` and ``lease6-update`` commands can be used to 840update existing leases. Since all lease database backends are indexed by 841IP addresses, it is not possible to update an address, but all other 842fields may be altered. If an address needs to be changed, please use 843``leaseX-del`` followed by ``leaseX-add``. 844 845The subnet-id parameter is optional. If not specified, or if the 846specified value is 0, Kea will try to determine its value by running a 847subnet-selection procedure. If specified, however, its value must match 848the existing subnet. 849 850The optional boolean parameter "force-create" specifies whether the 851lease should be created if it does not exist in the database. It defaults 852to false, which indicates that the lease is not created if it does not 853exist. In such a case, an error is returned as a result of trying to 854update a non-existing lease. If the "force-create" parameter is set to 855true and the updated lease does not exist, the new lease is created as a 856result of receiving the ``leaseX-update``. 857 858An example of a command to update an IPv4 lease is: 859 860:: 861 862 { 863 "command": "lease4-update", 864 "arguments": { 865 "ip-address": "192.0.2.1", 866 "hostname": "newhostname.example.org", 867 "hw-address": "1a:1b:1c:1d:1e:1f", 868 "subnet-id": 44, 869 "force-create": true 870 } 871 } 872 873An example of a command to update an IPv6 lease is: 874 875:: 876 877 { 878 "command": "lease6-update", 879 "arguments": { 880 "ip-address": "2001:db8::1", 881 "duid": "88:88:88:88:88:88:88:88", 882 "iaid": 7654321, 883 "hostname": "newhostname.example.org", 884 "subnet-id": 66, 885 "force-create": false 886 } 887 } 888 889.. _command-lease4-wipe: 890 891.. _command-lease6-wipe: 892 893The lease4-wipe, lease6-wipe Commands 894~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 895 896``lease4-wipe`` and ``lease6-wipe`` are designed to remove all leases 897associated with a given subnet. This administrative task is expected to 898be used when an existing subnet is being retired. Note that the leases 899are not properly expired; no DNS updates are carried out, no log 900messages are created, and hooks are not called for the leases being 901removed. 902 903An example of ``lease4-wipe`` is: 904 905:: 906 907 { 908 "command": "lease4-wipe", 909 "arguments": { 910 "subnet-id": 44 911 } 912 } 913 914An example of ``lease6-wipe`` is: 915 916:: 917 918 { 919 "command": "lease6-wipe", 920 "arguments": { 921 "subnet-id": 66 922 } 923 } 924 925The commands return a text description of the number of leases removed, 926plus the status code 0 (success) if any leases were removed or 3 (empty) 927if there were no leases. Status code 1 (error) may be returned if the 928parameters are incorrect or some other exception is encountered. 929 930Subnet-id 0 has a special meaning; it tells Kea to delete leases from 931all configured subnets. Also, the subnet-id parameter may be omitted. If 932not specified, leases from all subnets are wiped. 933 934Note: not all backends support this command. 935 936.. _command-lease4-resend-ddns: 937 938.. _command-lease6-resend-ddns: 939 940The lease4-resend-ddns, lease6-resend-ddns Commands 941~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 942 943``lease4-resend-ddns`` or ``lease6-resend-ddns`` can be used to generate 944a request to kea-dhcp-ddns to update the DNS entries for an existing 945lease. The desired lease is selected by a single parameter, "ip-address". 946In order for an update request to be generated, DDNS updating must be enabled 947and DNS entries must have already been made (or attempted) for the lease. 948In other words all of the following must be true: 949 950- DDNS updating must be enabled. (i.e. "dhcp-ddns":{ "enable-updates": true"}) 951- The lease's hostname must not be empty. 952- At least one of the lease's DNS direction flags (fdqn_fwd or fdqn_rev) must be true. 953 954An example ``lease4-resend-ddns`` command for getting a lease using an IPv4 955address is: 956 957:: 958 959 { 960 "command": "lease4-resend-ddns", 961 "arguments": { 962 "ip-address": "192.0.2.1" 963 } 964 } 965 966An example of the ``lease6-resend-ddns`` query is: 967 968:: 969 970 { 971 "command": "lease6-resend-ddns", 972 "arguments": { 973 "ip-address": "2001:db8:1::1" 974 } 975 } 976 977``leaseX-resend-ddns`` returns a result that indicates a result of the operation. 978It has one of the following values: 0 (success), 1 (error), or 3 (empty). An empty 979result means that a query has been completed properly, but the object (a lease in 980this case) has not been found. 981 982A successful result does not mean that DNS has been successfully updated. It 983indicates that a request to update DNS has been successfully created and 984queued for transmission to kea-dhcp-ddns. 985 986An example result returned when the lease was found: 987 988:: 989 990 { 991 "result": 0, 992 "text": "NCR generated for: 2001:db8:1::1, hostname: example.com." 993 } 994