Kea 3.1.0
lease_cmds.cc
Go to the documentation of this file.
1// Copyright (C) 2017-2025 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
9#include <config/cmds_impl.h>
11#include <cc/data.h>
12#include <asiolink/io_address.h>
14#include <dhcpsrv/cfgmgr.h>
16#include <dhcpsrv/lease_mgr.h>
20#include <dhcpsrv/subnet_id.h>
22#include <dhcp/duid.h>
23#include <hooks/hooks.h>
25#include <lease_cmds.h>
27#include <lease_parser.h>
28#include <lease_cmds_log.h>
29#include <stats/stats_mgr.h>
30#include <util/encode/encode.h>
31#include <util/filesystem.h>
33
34#include <boost/scoped_ptr.hpp>
35#include <boost/algorithm/string.hpp>
36#include <string>
37#include <sstream>
38
39using namespace isc::dhcp;
40using namespace isc::data;
41using namespace isc::dhcp_ddns;
42using namespace isc::config;
43using namespace isc::asiolink;
44using namespace isc::hooks;
45using namespace isc::stats;
46using namespace isc::util;
47using namespace isc::util::file;
48using namespace isc::log;
49using namespace std;
50
51namespace isc {
52namespace lease_cmds {
53
55class LeaseCmdsImpl : private CmdsImpl {
56public:
57
59 class Parameters {
60 public:
61
69
72
75
78
81
84
94 static Type txtToType(const std::string& txt) {
95 if (txt == "address") {
96 return (Parameters::TYPE_ADDR);
97 } else if (txt == "hw-address") {
99 } else if (txt == "duid") {
100 return (Parameters::TYPE_DUID);
101 } else if (txt == "client-id") {
103 } else {
104 isc_throw(BadValue, "Incorrect identifier type: "
105 << txt << ", the only supported values are: "
106 "address, hw-address, duid");
107 }
108 }
109
112
115
117 uint32_t iaid;
118
121
124 : subnet_id(0), addr("::"), query_type(TYPE_ADDR),
125 lease_type(Lease::TYPE_NA), iaid(0), updateDDNS(false) {
126 }
127 };
128
129public:
130
139 int
141
151 int
153
162 int
164
176 int
178
194 int
196
206 int
208
218 int
220
230 int
232
243 int
245
254 int
256
265 int
267
276 int
278
287 int
289
298 int
300
309 int
311
321
331
340 int
342
354 Parameters getParameters(bool v6, const ConstElementPtr& args);
355
373 Lease6Ptr getIPv6LeaseForDelete(const Parameters& parameters) const;
374
390 const IOAddress& lease_address,
391 const DuidPtr& duid,
392 const int control_result,
393 const std::string& error_message) const;
394
405 IOAddress getAddressParam(ConstElementPtr params, const std::string name,
406 short family = AF_INET) const;
407
411 static void updateStatsOnAdd(const Lease4Ptr& lease);
412
416 static void updateStatsOnAdd(const Lease6Ptr& lease);
417
422 static void updateStatsOnUpdate(const Lease4Ptr& existing,
423 const Lease4Ptr& lease);
424
429 static void updateStatsOnUpdate(const Lease6Ptr& existing,
430 const Lease6Ptr& lease);
431
435 static void updateStatsOnDelete(const Lease4Ptr& lease);
436
440 static void updateStatsOnDelete(const Lease6Ptr& lease);
441
450 static bool addOrUpdate4(Lease4Ptr lease, bool force_create);
451
460 static bool addOrUpdate6(Lease6Ptr lease, bool force_create);
461
466 inline static ConstElementPtr getExtendedInfo6(const Lease6Ptr& lease) {
467 ConstElementPtr user_context = lease->getContext();
468 if (!user_context || (user_context->getType() != Element::map)) {
469 return (ConstElementPtr());
470 }
471 ConstElementPtr isc = user_context->get("ISC");
472 if (!isc || (isc->getType() != Element::map)) {
473 return (ConstElementPtr());
474 }
475 return (isc->get("relay-info"));
476 }
477
491 static void lease4Offer(CalloutHandle& callout_handle,
493
505 static void leases4Committed(CalloutHandle& callout_handle,
507
519 static void leases6Committed(CalloutHandle& callout_handle,
521};
522
523void
525 if (!lease->stateExpiredReclaimed()) {
527 StatsMgr::generateName("subnet", lease->subnet_id_,
528 "assigned-addresses"),
529 static_cast<int64_t>(1));
530
531 PoolPtr pool;
532 auto const& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(lease->subnet_id_);
533 if (subnet) {
534 pool = subnet->getPool(Lease::TYPE_V4, lease->addr_, false);
535 if (pool) {
537 StatsMgr::generateName("subnet", subnet->getID(),
538 StatsMgr::generateName("pool", pool->getID(),
539 "assigned-addresses")),
540 static_cast<int64_t>(1));
541 }
542 }
543
544 if (lease->stateDeclined()) {
545 StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(1));
546
548 StatsMgr::generateName("subnet", lease->subnet_id_,
549 "declined-addresses"),
550 static_cast<int64_t>(1));
551
552 if (pool) {
554 StatsMgr::generateName("subnet", subnet->getID(),
555 StatsMgr::generateName("pool", pool->getID(),
556 "declined-addresses")),
557 static_cast<int64_t>(1));
558 }
559 }
560 }
561}
562
563void
565 if (lease->stateRegistered()) {
567 StatsMgr::generateName("subnet", lease->subnet_id_, "registered-nas"),
568 static_cast<int64_t>(1));
569 } else if (!lease->stateExpiredReclaimed()) {
571 StatsMgr::generateName("subnet", lease->subnet_id_,
572 lease->type_ == Lease::TYPE_NA ?
573 "assigned-nas" : "assigned-pds"),
574 static_cast<int64_t>(1));
575
576 PoolPtr pool;
577 auto const& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(lease->subnet_id_);
578 if (subnet) {
579 pool = subnet->getPool(lease->type_, lease->addr_, false);
580 if (pool) {
582 StatsMgr::generateName("subnet", subnet->getID(),
583 StatsMgr::generateName(lease->type_ == Lease::TYPE_NA ?
584 "pool" : "pd-pool", pool->getID(),
585 lease->type_ == Lease::TYPE_NA ?
586 "assigned-nas" : "assigned-pds")),
587 static_cast<int64_t>(1));
588 }
589 }
590
591 if (lease->stateDeclined()) {
592 StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(1));
593
595 StatsMgr::generateName("subnet", lease->subnet_id_,
596 "declined-addresses"),
597 static_cast<int64_t>(1));
598
599 if (pool) {
601 StatsMgr::generateName("subnet", subnet->getID(),
602 StatsMgr::generateName("pool", pool->getID(),
603 "declined-addresses")),
604 static_cast<int64_t>(1));
605 }
606 }
607 }
608}
609
610void
612 const Lease4Ptr& lease) {
613 if (!existing->stateExpiredReclaimed()) {
614 ConstSubnet4Ptr subnet;
615 PoolPtr pool;
616
617 // old lease is non expired-reclaimed
618 if (existing->subnet_id_ != lease->subnet_id_) {
620 StatsMgr::generateName("subnet", existing->subnet_id_,
621 "assigned-addresses"),
622 static_cast<int64_t>(-1));
623
624 subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(existing->subnet_id_);
625 if (subnet) {
626 pool = subnet->getPool(Lease::TYPE_V4, existing->addr_, false);
627 if (pool) {
629 StatsMgr::generateName("subnet", subnet->getID(),
630 StatsMgr::generateName("pool", pool->getID(),
631 "assigned-addresses")),
632 static_cast<int64_t>(-1));
633 }
634 }
635 }
636
637 if (existing->stateDeclined()) {
638 // old lease is declined
639 StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(-1));
640
642 StatsMgr::generateName("subnet", existing->subnet_id_,
643 "declined-addresses"),
644 static_cast<int64_t>(-1));
645
646 if (pool) {
648 StatsMgr::generateName("subnet", subnet->getID(),
649 StatsMgr::generateName("pool", pool->getID(),
650 "declined-addresses")),
651 static_cast<int64_t>(-1));
652 }
653 }
654
655 pool.reset();
656
657 if (!lease->stateExpiredReclaimed()) {
658 // new lease is non expired-reclaimed
659 if (existing->subnet_id_ != lease->subnet_id_) {
661 StatsMgr::generateName("subnet", lease->subnet_id_,
662 "assigned-addresses"),
663 static_cast<int64_t>(1));
664
665 subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(lease->subnet_id_);
666 if (subnet) {
667 pool = subnet->getPool(Lease::TYPE_V4, lease->addr_, false);
668 if (pool) {
670 StatsMgr::generateName("subnet", subnet->getID(),
671 StatsMgr::generateName("pool", pool->getID(),
672 "assigned-addresses")),
673 static_cast<int64_t>(1));
674 }
675 }
676 }
677
678 if (lease->stateDeclined()) {
679 // new lease is declined
680 StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(1));
681
683 StatsMgr::generateName("subnet", lease->subnet_id_,
684 "declined-addresses"),
685 static_cast<int64_t>(1));
686
687 if (pool) {
689 StatsMgr::generateName("subnet", subnet->getID(),
690 StatsMgr::generateName("pool", pool->getID(),
691 "declined-addresses")),
692 static_cast<int64_t>(1));
693 }
694 }
695 }
696 } else {
697 // old lease is expired-reclaimed
698 if (!lease->stateExpiredReclaimed()) {
699 // new lease is non expired-reclaimed
701 StatsMgr::generateName("subnet", lease->subnet_id_,
702 "assigned-addresses"),
703 static_cast<int64_t>(1));
704
705 PoolPtr pool;
706 auto const& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(lease->subnet_id_);
707 if (subnet) {
708 pool = subnet->getPool(Lease::TYPE_V4, lease->addr_, false);
709 if (pool) {
711 StatsMgr::generateName("subnet", subnet->getID(),
712 StatsMgr::generateName("pool", pool->getID(),
713 "assigned-addresses")),
714 static_cast<int64_t>(1));
715 }
716 }
717
718 if (lease->stateDeclined()) {
719 // new lease is declined
720 StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(1));
721
723 StatsMgr::generateName("subnet", lease->subnet_id_,
724 "declined-addresses"),
725 static_cast<int64_t>(1));
726
727 if (pool) {
729 StatsMgr::generateName("subnet", subnet->getID(),
730 StatsMgr::generateName("pool", pool->getID(),
731 "declined-addresses")),
732 static_cast<int64_t>(1));
733 }
734 }
735 }
736 }
737}
738
739void
741 const Lease6Ptr& lease) {
742 // Does not cover registered <-> not registered transition.
743 if (existing->stateRegistered()) {
744 if (existing->subnet_id_ != lease->subnet_id_) {
746 StatsMgr::generateName("subnet", existing->subnet_id_,
747 "registered-nas"),
748 static_cast<int64_t>(-1));
750 StatsMgr::generateName("subnet", lease->subnet_id_,
751 "registered-nas"),
752 static_cast<int64_t>(1));
753 }
754 } else if (!existing->stateExpiredReclaimed()) {
755 ConstSubnet6Ptr subnet;
756 PoolPtr pool;
757
758 // old lease is non expired-reclaimed
759 if (existing->subnet_id_ != lease->subnet_id_) {
761 StatsMgr::generateName("subnet", existing->subnet_id_,
762 lease->type_ == Lease::TYPE_NA ?
763 "assigned-nas" : "assigned-pds"),
764 static_cast<int64_t>(-1));
765
766 subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(existing->subnet_id_);
767 if (subnet) {
768 pool = subnet->getPool(existing->type_, existing->addr_, false);
769 if (pool) {
771 StatsMgr::generateName("subnet", subnet->getID(),
772 StatsMgr::generateName(existing->type_ == Lease::TYPE_NA ?
773 "pool" : "pd-pool", pool->getID(),
774 existing->type_ == Lease::TYPE_NA ?
775 "assigned-nas" : "assigned-pds")),
776 static_cast<int64_t>(-1));
777 }
778 }
779 }
780
781 if (existing->stateDeclined()) {
782 // old lease is declined
783 StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(-1));
784
786 StatsMgr::generateName("subnet", existing->subnet_id_,
787 "declined-addresses"),
788 static_cast<int64_t>(-1));
789
790 if (pool) {
792 StatsMgr::generateName("subnet", subnet->getID(),
793 StatsMgr::generateName("pool", pool->getID(),
794 "declined-addresses")),
795 static_cast<int64_t>(-1));
796 }
797 }
798
799 pool.reset();
800
801 if (!lease->stateExpiredReclaimed()) {
802 // new lease is non expired-reclaimed
803 if (existing->subnet_id_ != lease->subnet_id_) {
805 StatsMgr::generateName("subnet", lease->subnet_id_,
806 lease->type_ == Lease::TYPE_NA ?
807 "assigned-nas" : "assigned-pds"),
808 static_cast<int64_t>(1));
809
810 subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(lease->subnet_id_);
811 if (subnet) {
812 pool = subnet->getPool(lease->type_, lease->addr_, false);
813 if (pool) {
815 StatsMgr::generateName("subnet", subnet->getID(),
816 StatsMgr::generateName(lease->type_ == Lease::TYPE_NA ?
817 "pool" : "pd-pool", pool->getID(),
818 lease->type_ == Lease::TYPE_NA ?
819 "assigned-nas" : "assigned-pds")),
820 static_cast<int64_t>(1));
821 }
822 }
823 }
824
825 if (lease->stateDeclined()) {
826 // new lease is declined
827 StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(1));
828
830 StatsMgr::generateName("subnet", lease->subnet_id_,
831 "declined-addresses"),
832 static_cast<int64_t>(1));
833
834 if (pool) {
836 StatsMgr::generateName("subnet", subnet->getID(),
837 StatsMgr::generateName("pool", pool->getID(),
838 "declined-addresses")),
839 static_cast<int64_t>(1));
840 }
841 }
842 }
843 } else {
844 // old lease is expired-reclaimed
845 if (!lease->stateExpiredReclaimed()) {
846 // new lease is non expired-reclaimed
848 StatsMgr::generateName("subnet", lease->subnet_id_,
849 lease->type_ == Lease::TYPE_NA ?
850 "assigned-nas" : "assigned-pds"),
851 static_cast<int64_t>(1));
852
853 PoolPtr pool;
854 auto const& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(lease->subnet_id_);
855 if (subnet) {
856 pool = subnet->getPool(lease->type_, lease->addr_, false);
857 if (pool) {
859 StatsMgr::generateName("subnet", subnet->getID(),
860 StatsMgr::generateName(lease->type_ == Lease::TYPE_NA ?
861 "pool" : "pd-pool", pool->getID(),
862 lease->type_ == Lease::TYPE_NA ?
863 "assigned-nas" : "assigned-pds")),
864 static_cast<int64_t>(1));
865 }
866 }
867
868 if (lease->stateDeclined()) {
869 // new lease is declined
870 StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(1));
871
873 StatsMgr::generateName("subnet", lease->subnet_id_,
874 "declined-addresses"),
875 static_cast<int64_t>(1));
876
877 if (pool) {
879 StatsMgr::generateName("subnet", subnet->getID(),
880 StatsMgr::generateName("pool", pool->getID(),
881 "declined-addresses")),
882 static_cast<int64_t>(1));
883 }
884 }
885 }
886 }
887}
888
889void
891 if (!lease->stateExpiredReclaimed()) {
893 StatsMgr::generateName("subnet", lease->subnet_id_,
894 "assigned-addresses"),
895 static_cast<int64_t>(-1));
896
897 PoolPtr pool;
898 auto const& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(lease->subnet_id_);
899 if (subnet) {
900 pool = subnet->getPool(Lease::TYPE_V4, lease->addr_, false);
901 if (pool) {
903 StatsMgr::generateName("subnet", subnet->getID(),
904 StatsMgr::generateName("pool", pool->getID(),
905 "assigned-addresses")),
906 static_cast<int64_t>(-1));
907 }
908 }
909
910 if (lease->stateDeclined()) {
911 StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(-1));
912
914 StatsMgr::generateName("subnet", lease->subnet_id_,
915 "declined-addresses"),
916 static_cast<int64_t>(-1));
917
918 if (pool) {
920 StatsMgr::generateName("subnet", subnet->getID(),
921 StatsMgr::generateName("pool", pool->getID(),
922 "declined-addresses")),
923 static_cast<int64_t>(-1));
924 }
925 }
926 }
927}
928
929void
931 if (lease->stateRegistered()) {
933 StatsMgr::generateName("subnet", lease->subnet_id_,
934 "registered-nas"),
935 static_cast<int64_t>(-1));
936 } else if (!lease->stateExpiredReclaimed()) {
938 StatsMgr::generateName("subnet", lease->subnet_id_,
939 lease->type_ == Lease::TYPE_NA ?
940 "assigned-nas" : "assigned-pds"),
941 static_cast<int64_t>(-1));
942
943 PoolPtr pool;
944 auto const& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(lease->subnet_id_);
945 if (subnet) {
946 pool = subnet->getPool(lease->type_, lease->addr_, false);
947 if (pool) {
949 StatsMgr::generateName("subnet", subnet->getID(),
950 StatsMgr::generateName(lease->type_ == Lease::TYPE_NA ?
951 "pool" : "pd-pool", pool->getID(),
952 lease->type_ == Lease::TYPE_NA ?
953 "assigned-nas" : "assigned-pds")),
954 static_cast<int64_t>(-1));
955 }
956 }
957
958 if (lease->stateDeclined()) {
959 StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(-1));
960
962 StatsMgr::generateName("subnet", lease->subnet_id_,
963 "declined-addresses"),
964 static_cast<int64_t>(-1));
965
966 if (pool) {
968 StatsMgr::generateName("subnet", subnet->getID(),
969 StatsMgr::generateName("pool", pool->getID(),
970 "declined-addresses")),
971 static_cast<int64_t>(-1));
972 }
973 }
974 }
975}
976
977bool
978LeaseCmdsImpl::addOrUpdate4(Lease4Ptr lease, bool force_create) {
979 Lease4Ptr existing = LeaseMgrFactory::instance().getLease4(lease->addr_);
980 if (force_create && !existing) {
981 // lease does not exist
982 if (!LeaseMgrFactory::instance().addLease(lease)) {
984 "lost race between calls to get and add");
985 }
987 return (true);
988 }
989 if (existing) {
990 // Update lease current expiration time with value received from the
991 // database. Some database backends reject operations on the lease if
992 // the current expiration time value does not match what is stored.
993 Lease::syncCurrentExpirationTime(*existing, *lease);
994 }
995 try {
997 } catch (const NoSuchLease&) {
998 isc_throw(LeaseCmdsConflict, "failed to update the lease with address "
999 << lease->addr_ << " either because the lease has been "
1000 "deleted or it has changed in the database, in both cases a "
1001 "retry might succeed");
1002 }
1003
1004 LeaseCmdsImpl::updateStatsOnUpdate(existing, lease);
1005 return (false);
1006}
1007
1008bool
1009LeaseCmdsImpl::addOrUpdate6(Lease6Ptr lease, bool force_create) {
1010 Lease6Ptr existing =
1011 LeaseMgrFactory::instance().getLease6(lease->type_, lease->addr_);
1012 if (force_create && !existing) {
1013 // lease does not exist
1014 if (!LeaseMgrFactory::instance().addLease(lease)) {
1016 "lost race between calls to get and add");
1017 }
1019 return (true);
1020 }
1021 if (existing) {
1022 // Refuse used <-> registered transitions.
1023 if (existing->stateRegistered() && !lease->stateRegistered()) {
1024 isc_throw(BadValue, "illegal reuse of registered address "
1025 << lease->addr_);
1026 } else if (!existing->stateRegistered() && lease->stateRegistered()) {
1027 isc_throw(BadValue, "address in use: " << lease->addr_
1028 << " can't be registered");
1029 }
1030
1031 // Update lease current expiration time with value received from the
1032 // database. Some database backends reject operations on the lease if
1033 // the current expiration time value does not match what is stored.
1034 Lease::syncCurrentExpirationTime(*existing, *lease);
1035
1036 // Check what is the action about extended info.
1037 ConstElementPtr old_extended_info = getExtendedInfo6(existing);
1038 ConstElementPtr extended_info = getExtendedInfo6(lease);
1039 if ((!old_extended_info && !extended_info) ||
1040 (old_extended_info && extended_info &&
1041 (*old_extended_info == *extended_info))) {
1042 // Leave the default Lease6::ACTION_IGNORE.
1043 } else {
1044 lease->extended_info_action_ = Lease6::ACTION_UPDATE;
1045 }
1046 }
1047 try {
1049 } catch (const NoSuchLease&) {
1050 isc_throw(LeaseCmdsConflict, "failed to update the lease with address "
1051 << lease->addr_ << " either because the lease has been "
1052 "deleted or it has changed in the database, in both cases a "
1053 "retry might succeed");
1054 }
1055
1056 LeaseCmdsImpl::updateStatsOnUpdate(existing, lease);
1057 return (false);
1058}
1059
1060int
1062 // Arbitrary defaulting to DHCPv4 or with other words extractCommand
1063 // below is not expected to throw...
1064 bool v4 = true;
1065 stringstream resp;
1066 string lease_address = "unknown";
1067 try {
1068 extractCommand(handle);
1069 v4 = (cmd_name_ == "lease4-add");
1070 if (!cmd_args_) {
1071 isc_throw(isc::BadValue, "no parameters specified for the command");
1072 }
1073
1075
1076 // This parameter is ignored for the commands adding the lease.
1077 bool force_create = false;
1078 Lease4Ptr lease4;
1079 Lease6Ptr lease6;
1080 if (v4) {
1081 Lease4Parser parser;
1082 lease4 = parser.parse(config, cmd_args_, force_create);
1083 if (lease4) {
1084 lease_address = lease4->addr_.toText();
1085 bool success;
1086 if (!MultiThreadingMgr::instance().getMode()) {
1087 // Not multi-threading.
1088 success = LeaseMgrFactory::instance().addLease(lease4);
1089 } else {
1090 // Multi-threading, try to lock first to avoid a race.
1091 ResourceHandler4 resource_handler;
1092 if (resource_handler.tryLock4(lease4->addr_)) {
1093 success = LeaseMgrFactory::instance().addLease(lease4);
1094 } else {
1096 "ResourceBusy: IP address:" << lease4->addr_
1097 << " could not be added.");
1098 }
1099 }
1100
1101 if (!success) {
1102 isc_throw(LeaseCmdsConflict, "IPv4 lease already exists.");
1103 }
1104
1106 resp << "Lease for address " << lease4->addr_.toText()
1107 << ", subnet-id " << lease4->subnet_id_ << " added.";
1108 }
1109 } else {
1110 Lease6Parser parser;
1111 lease6 = parser.parse(config, cmd_args_, force_create);
1112 if (lease6) {
1113 lease_address = lease6->addr_.toText();
1114 bool success;
1115 if (!MultiThreadingMgr::instance().getMode()) {
1116 // Not multi-threading.
1117 success = LeaseMgrFactory::instance().addLease(lease6);
1118 } else {
1119 // Multi-threading, try to lock first to avoid a race.
1120 ResourceHandler resource_handler;
1121 if (resource_handler.tryLock(lease6->type_, lease6->addr_)) {
1122 success = LeaseMgrFactory::instance().addLease(lease6);
1123 } else {
1125 "ResourceBusy: IP address:" << lease6->addr_
1126 << " could not be added.");
1127 }
1128 }
1129
1130 if (!success) {
1131 isc_throw(LeaseCmdsConflict, "IPv6 lease already exists.");
1132 }
1133
1135 if (lease6->type_ == Lease::TYPE_NA) {
1136 resp << "Lease for address " << lease6->addr_.toText()
1137 << ", subnet-id " << lease6->subnet_id_ << " added.";
1138 } else {
1139 resp << "Lease for prefix " << lease6->addr_.toText()
1140 << "/" << static_cast<int>(lease6->prefixlen_)
1141 << ", subnet-id " << lease6->subnet_id_ << " added.";
1142 }
1143 }
1144 }
1145 } catch (const LeaseCmdsConflict& ex) {
1147 .arg(cmd_args_ ? cmd_args_->str() : "<no args>")
1148 .arg(ex.what());
1150 return (0);
1151
1152 } catch (const std::exception& ex) {
1154 .arg(cmd_args_ ? cmd_args_->str() : "<no args>")
1155 .arg(ex.what());
1156 setErrorResponse(handle, ex.what());
1157 return (1);
1158 }
1159
1162 .arg(lease_address);
1163 setSuccessResponse(handle, resp.str());
1164 return (0);
1165}
1166
1169 Parameters x;
1170
1171 if (!params || params->getType() != Element::map) {
1172 isc_throw(BadValue, "Parameters missing or are not a map.");
1173 }
1174
1175 if (params->contains("update-ddns")) {
1176 ConstElementPtr tmp = params->get("update-ddns");
1177 if (tmp->getType() != Element::boolean) {
1178 isc_throw(BadValue, "'update-ddns' is not a boolean");
1179 } else {
1180 x.updateDDNS = tmp->boolValue();
1181 }
1182 }
1183
1184 // We support several sets of parameters for leaseX-get/lease-del:
1185 // lease-get(type, address)
1186 // lease-get(type, subnet-id, identifier-type, identifier)
1187
1188 if (params->contains("type")) {
1189 string t = params->get("type")->stringValue();
1190 if (t == "IA_NA" || t == "0") {
1192 } else if (t == "IA_TA" || t == "1") {
1194 } else if (t == "IA_PD" || t == "2") {
1196 } else if (t == "V4" || t == "3") {
1198 } else {
1199 isc_throw(BadValue, "Invalid lease type specified: "
1200 << t << ", only supported values are: IA_NA, IA_TA,"
1201 << " IA_PD and V4");
1202 }
1203 }
1204
1205 ConstElementPtr tmp = params->get("ip-address");
1206 if (tmp) {
1207 if (tmp->getType() != Element::string) {
1208 isc_throw(BadValue, "'ip-address' is not a string.");
1209 }
1210
1211 x.addr = IOAddress(tmp->stringValue());
1212
1213 if ((v6 && !x.addr.isV6()) || (!v6 && !x.addr.isV4())) {
1214 stringstream txt;
1215 txt << "Invalid " << (v6 ? "IPv6" : "IPv4")
1216 << " address specified: " << tmp->stringValue();
1217 isc_throw(BadValue, txt.str());
1218 }
1219
1221 return (x);
1222 }
1223
1224 tmp = params->get("subnet-id");
1225 if (!tmp) {
1226 isc_throw(BadValue, "Mandatory 'subnet-id' parameter missing.");
1227 }
1228 if (tmp->getType() != Element::integer) {
1229 isc_throw(BadValue, "'subnet-id' parameter is not integer.");
1230 }
1231 x.subnet_id = tmp->intValue();
1232
1233 if (params->contains("iaid")) {
1234 x.iaid = params->get("iaid")->intValue();
1235 }
1236
1237 // No address specified. Ok, so it must be identifier based query.
1238 // "identifier-type": "duid",
1239 // "identifier": "aa:bb:cc:dd:ee:..."
1240
1241 ConstElementPtr type = params->get("identifier-type");
1242 ConstElementPtr ident = params->get("identifier");
1243 if (!type || type->getType() != Element::string) {
1244 isc_throw(BadValue, "No 'ip-address' provided"
1245 " and 'identifier-type' is either missing or not a string.");
1246 }
1247 if (!ident || ident->getType() != Element::string) {
1248 isc_throw(BadValue, "No 'ip-address' provided"
1249 " and 'identifier' is either missing or not a string.");
1250 }
1251
1252 // Got the parameters. Let's see if their values make sense.
1253 // Try to convert identifier-type
1254 x.query_type = Parameters::txtToType(type->stringValue());
1255
1256 switch (x.query_type) {
1258 HWAddr hw = HWAddr::fromText(ident->stringValue());
1259 x.hwaddr = HWAddrPtr(new HWAddr(hw));
1260 break;
1261 }
1263 x.client_id = ClientId::fromText(ident->stringValue());
1264 break;
1265 }
1266 case Parameters::TYPE_DUID: {
1267 DUID duid = DUID::fromText(ident->stringValue());
1268 x.duid = DuidPtr(new DUID(duid));
1269 break;
1270 }
1271 case Parameters::TYPE_ADDR: {
1272 // We should never get here. The address clause should have been caught
1273 // earlier.
1274 return (x);
1275 }
1276 default: {
1277 isc_throw(BadValue, "Identifier type " << type->stringValue() <<
1278 " is not supported.");
1279 }
1280 }
1281
1282 return (x);
1283}
1284
1285int
1287 Parameters p;
1288 Lease4Ptr lease4;
1289 Lease6Ptr lease6;
1290 bool v4 = true;
1291 try {
1292 extractCommand(handle);
1293 v4 = (cmd_name_ == "lease4-get");
1294 p = getParameters(!v4, cmd_args_);
1295 switch (p.query_type) {
1296 case Parameters::TYPE_ADDR: {
1297 // Query by address
1298 if (v4) {
1300 } else {
1302 }
1303 break;
1304 }
1306 if (v4) {
1307 if (!p.hwaddr) {
1308 isc_throw(InvalidParameter, "Program error: Query by hw-address "
1309 "requires hwaddr to be specified");
1310 }
1311
1313 } else {
1314 isc_throw(isc::InvalidParameter, "Query by hw-address is not allowed in v6.");
1315 }
1316 break;
1317
1319 if (!v4) {
1320 if (!p.duid) {
1321 isc_throw(InvalidParameter, "Program error: Query by duid "
1322 "requires duid to be specified");
1323 }
1324
1326 p.iaid, p.subnet_id);
1327 } else {
1328 isc_throw(InvalidParameter, "Query by duid is not allowed in v4.");
1329 }
1330 break;
1331
1333 if (v4) {
1334 if (!p.client_id) {
1335 isc_throw(InvalidParameter, "Program error: Query by client-id "
1336 "requires client-id to be specified");
1337 }
1338
1340 } else {
1341 isc_throw(isc::InvalidParameter, "Query by client-id is not allowed in v6.");
1342 }
1343 break;
1344
1345 default: {
1346 isc_throw(InvalidOperation, "Unknown query type: " << static_cast<int>(p.query_type));
1347 break;
1348 }
1349 }
1350 } catch (const std::exception& ex) {
1352 .arg(cmd_args_ ? cmd_args_->str() : "<no args>")
1353 .arg(ex.what());
1354 setErrorResponse(handle, ex.what());
1355 return (1);
1356 }
1357
1358 ElementPtr lease_json;
1359 if (v4 && lease4) {
1360 lease_json = lease4->toElement();
1362 "IPv4 lease found.", lease_json);
1363 setResponse(handle, response);
1364 } else if (!v4 && lease6) {
1365 lease_json = lease6->toElement();
1367 "IPv6 lease found.", lease_json);
1368 setResponse(handle, response);
1369 } else {
1370 // If we got here, the lease has not been found.
1371 setErrorResponse(handle, "Lease not found.", CONTROL_RESULT_EMPTY);
1372 }
1373
1374 return (0);
1375}
1376
1377int
1379 bool v4 = true;
1380 try {
1381 extractCommand(handle);
1382 v4 = (cmd_name_ == "lease4-get-all");
1383
1384 ElementPtr leases_json = Element::createList();
1385
1386 // The argument may contain a list of subnets for which leases should
1387 // be returned.
1388 if (cmd_args_) {
1389 ConstElementPtr subnets = cmd_args_->get("subnets");
1390 if (!subnets) {
1391 isc_throw(BadValue, "'subnets' parameter not specified");
1392 }
1393 if (subnets->getType() != Element::list) {
1394 isc_throw(BadValue, "'subnets' parameter must be a list");
1395 }
1396
1397 const std::vector<ElementPtr>& subnet_ids = subnets->listValue();
1398 for (auto const& subnet_id : subnet_ids) {
1399 if (subnet_id->getType() != Element::integer) {
1400 isc_throw(BadValue, "listed subnet identifiers must be numbers");
1401 }
1402
1403 if (v4) {
1404 Lease4Collection leases =
1405 LeaseMgrFactory::instance().getLeases4(subnet_id->intValue());
1406 for (auto const& lease : leases) {
1407 ElementPtr lease_json = lease->toElement();
1408 leases_json->add(lease_json);
1409 }
1410 } else {
1411 Lease6Collection leases =
1412 LeaseMgrFactory::instance().getLeases6(subnet_id->intValue());
1413 for (auto const& lease : leases) {
1414 ElementPtr lease_json = lease->toElement();
1415 leases_json->add(lease_json);
1416 }
1417 }
1418 }
1419
1420 } else {
1421 // There is no 'subnets' argument so let's return all leases.
1422 if (v4) {
1424 for (auto const& lease : leases) {
1425 ElementPtr lease_json = lease->toElement();
1426 leases_json->add(lease_json);
1427 }
1428 } else {
1430 for (auto const& lease : leases) {
1431 ElementPtr lease_json = lease->toElement();
1432 leases_json->add(lease_json);
1433 }
1434 }
1435 }
1436
1437 std::ostringstream s;
1438 s << leases_json->size()
1439 << " IPv" << (v4 ? "4" : "6")
1440 << " lease(s) found.";
1442 args->set("leases", leases_json);
1443 ConstElementPtr response =
1444 createAnswer(leases_json->size() > 0 ?
1447 s.str(), args);
1448 setResponse(handle, response);
1449
1450 } catch (const std::exception& ex) {
1451 setErrorResponse(handle, ex.what());
1452 return (CONTROL_RESULT_ERROR);
1453 }
1454
1455 return (0);
1456}
1457
1458int
1460 bool v4 = true;
1461 try {
1462 extractCommand(handle);
1463 v4 = (cmd_name_ == "lease4-get-page");
1464
1465 // arguments must always be present
1466 if (!cmd_args_) {
1467 isc_throw(BadValue, "no parameters specified for the " << cmd_name_
1468 << " command");
1469 }
1470
1471 // The 'from' argument denotes from which lease we should start the
1472 // results page. The results page excludes this lease.
1473 ConstElementPtr from = cmd_args_->get("from");
1474 if (!from) {
1475 isc_throw(BadValue, "'from' parameter not specified");
1476 }
1477
1478 // The 'from' argument is a string. It may contain a 'start' keyword or
1479 // an IP address.
1480 if (from->getType() != Element::string) {
1481 isc_throw(BadValue, "'from' parameter must be a string");
1482 }
1483
1484 boost::scoped_ptr<IOAddress> from_address;
1485 try {
1486 if (from->stringValue() == "start") {
1487 from_address.reset(new IOAddress(v4 ? "0.0.0.0" : "::"));
1488
1489 } else {
1490 // Conversion of a string to an IP address may throw.
1491 from_address.reset(new IOAddress(from->stringValue()));
1492 }
1493
1494 } catch (...) {
1495 isc_throw(BadValue, "'from' parameter value is neither 'start' keyword nor "
1496 "a valid IPv" << (v4 ? "4" : "6") << " address");
1497 }
1498
1499 // It must be either IPv4 address for lease4-get-page or IPv6 address for
1500 // lease6-get-page.
1501 if (v4 && (!from_address->isV4())) {
1502 isc_throw(BadValue, "'from' parameter value " << from_address->toText()
1503 << " is not an IPv4 address");
1504
1505 } else if (!v4 && from_address->isV4()) {
1506 isc_throw(BadValue, "'from' parameter value " << from_address->toText()
1507 << " is not an IPv6 address");
1508 }
1509
1510 // The 'limit' is a desired page size. It must always be present.
1511 ConstElementPtr page_limit = cmd_args_->get("limit");
1512 if (!page_limit) {
1513 isc_throw(BadValue, "'limit' parameter not specified");
1514 }
1515
1516 // The 'limit' must be a number.
1517 if (page_limit->getType() != Element::integer) {
1518 isc_throw(BadValue, "'limit' parameter must be a number");
1519 }
1520
1521 // Retrieve the desired page size.
1522 size_t page_limit_value = static_cast<size_t>(page_limit->intValue());
1523
1524 ElementPtr leases_json = Element::createList();
1525
1526 if (v4) {
1527 // Get page of IPv4 leases.
1528 Lease4Collection leases =
1529 LeaseMgrFactory::instance().getLeases4(*from_address,
1530 LeasePageSize(page_limit_value));
1531
1532 // Convert leases into JSON list.
1533 for (auto const& lease : leases) {
1534 ElementPtr lease_json = lease->toElement();
1535 leases_json->add(lease_json);
1536 }
1537
1538 } else {
1539 // Get page of IPv6 leases.
1540 Lease6Collection leases =
1541 LeaseMgrFactory::instance().getLeases6(*from_address,
1542 LeasePageSize(page_limit_value));
1543 // Convert leases into JSON list.
1544 for (auto const& lease : leases) {
1545 ElementPtr lease_json = lease->toElement();
1546 leases_json->add(lease_json);
1547 }
1548 }
1549
1550 // Prepare textual status.
1551 std::ostringstream s;
1552 s << leases_json->size()
1553 << " IPv" << (v4 ? "4" : "6")
1554 << " lease(s) found.";
1556
1557 // Put gathered data into arguments map.
1558 args->set("leases", leases_json);
1559 args->set("count", Element::create(static_cast<int64_t>(leases_json->size())));
1560
1561 // Create the response.
1562 ConstElementPtr response =
1563 createAnswer(leases_json->size() > 0 ?
1566 s.str(), args);
1567 setResponse(handle, response);
1568
1569 } catch (const std::exception& ex) {
1570 setErrorResponse(handle, ex.what());
1571 return (CONTROL_RESULT_ERROR);
1572 }
1573
1574 return (CONTROL_RESULT_SUCCESS);
1575}
1576
1577int
1579 try {
1580 extractCommand(handle);
1581
1582 // arguments must always be present
1583 if (!cmd_args_ || (cmd_args_->getType() != Element::map)) {
1584 isc_throw(BadValue, "Command arguments missing or a not a map.");
1585 }
1586
1587 // the hw-address parameter is mandatory.
1588 ConstElementPtr hw_address = cmd_args_->get("hw-address");
1589 if (!hw_address) {
1590 isc_throw(BadValue, "'hw-address' parameter not specified");
1591 }
1592
1593 // The 'hw-address' argument is a string.
1594 if (hw_address->getType() != Element::string) {
1595 isc_throw(BadValue, "'hw-address' parameter must be a string");
1596 }
1597
1598 HWAddr hwaddr = HWAddr::fromText(hw_address->stringValue());
1599
1600 Lease4Collection leases =
1602 ElementPtr leases_json = Element::createList();
1603 for (auto const& lease : leases) {
1604 ElementPtr lease_json = lease->toElement();
1605 leases_json->add(lease_json);
1606 }
1607
1608 std::ostringstream s;
1609 s << leases_json->size() << " IPv4 lease(s) found.";
1611 args->set("leases", leases_json);
1612 ConstElementPtr response =
1613 createAnswer(leases_json->size() > 0 ?
1616 s.str(), args);
1617 setResponse(handle, response);
1618
1619 } catch (const std::exception& ex) {
1620 setErrorResponse(handle, ex.what());
1621 return (CONTROL_RESULT_ERROR);
1622 }
1623
1624 return (0);
1625}
1626
1627int
1629 try {
1630 extractCommand(handle);
1631
1632 // arguments must always be present
1633 if (!cmd_args_ || (cmd_args_->getType() != Element::map)) {
1634 isc_throw(BadValue, "Command arguments missing or a not a map.");
1635 }
1636
1637 // the client-id parameter is mandatory.
1638 ConstElementPtr client_id = cmd_args_->get("client-id");
1639 if (!client_id) {
1640 isc_throw(BadValue, "'client-id' parameter not specified");
1641 }
1642
1643 // The 'client-id' argument is a string.
1644 if (client_id->getType() != Element::string) {
1645 isc_throw(BadValue, "'client-id' parameter must be a string");
1646 }
1647
1648 ClientIdPtr clientid = ClientId::fromText(client_id->stringValue());
1649
1650 Lease4Collection leases =
1652 ElementPtr leases_json = Element::createList();
1653 for (auto const& lease : leases) {
1654 ElementPtr lease_json = lease->toElement();
1655 leases_json->add(lease_json);
1656 }
1657
1658 std::ostringstream s;
1659 s << leases_json->size() << " IPv4 lease(s) found.";
1661 args->set("leases", leases_json);
1662 ConstElementPtr response =
1663 createAnswer(leases_json->size() > 0 ?
1666 s.str(), args);
1667 setResponse(handle, response);
1668
1669 } catch (const std::exception& ex) {
1670 setErrorResponse(handle, ex.what());
1671 return (CONTROL_RESULT_ERROR);
1672 }
1673
1674 return (0);
1675}
1676
1677int
1679 try {
1680 extractCommand(handle);
1681
1682 // arguments must always be present
1683 if (!cmd_args_ || (cmd_args_->getType() != Element::map)) {
1684 isc_throw(BadValue, "Command arguments missing or a not a map.");
1685 }
1686
1687 // the duid parameter is mandatory.
1688 ConstElementPtr duid = cmd_args_->get("duid");
1689 if (!duid) {
1690 isc_throw(BadValue, "'duid' parameter not specified");
1691 }
1692
1693 // The 'duid' argument is a string.
1694 if (duid->getType() != Element::string) {
1695 isc_throw(BadValue, "'duid' parameter must be a string");
1696 }
1697
1698 DUID duid_ = DUID::fromText(duid->stringValue());
1699
1700 Lease6Collection leases =
1702 ElementPtr leases_json = Element::createList();
1703 for (auto const& lease : leases) {
1704 ElementPtr lease_json = lease->toElement();
1705 leases_json->add(lease_json);
1706 }
1707
1708 std::ostringstream s;
1709 s << leases_json->size() << " IPv6 lease(s) found.";
1711 args->set("leases", leases_json);
1712 ConstElementPtr response =
1713 createAnswer(leases_json->size() > 0 ?
1716 s.str(), args);
1717 setResponse(handle, response);
1718
1719 } catch (const std::exception& ex) {
1720 setErrorResponse(handle, ex.what());
1721 return (CONTROL_RESULT_ERROR);
1722 }
1723
1724 return (0);
1725}
1726
1727int
1729 bool v4 = true;
1730 try {
1731 extractCommand(handle);
1732 v4 = (cmd_name_ == "lease4-get-by-hostname");
1733
1734 // arguments must always be present
1735 if (!cmd_args_ || (cmd_args_->getType() != Element::map)) {
1736 isc_throw(BadValue, "Command arguments missing or a not a map.");
1737 }
1738
1739 // the hostname parameter is mandatory.
1740 ConstElementPtr hostname = cmd_args_->get("hostname");
1741 if (!hostname) {
1742 isc_throw(BadValue, "'hostname' parameter not specified");
1743 }
1744
1745 // The 'hostname' argument is a string.
1746 if (hostname->getType() != Element::string) {
1747 isc_throw(BadValue, "'hostname' parameter must be a string");
1748 }
1749
1750 std::string hostname_ = hostname->stringValue();
1752 if (hostname_.empty()) {
1753 isc_throw(BadValue, "'hostname' parameter is empty");
1754 }
1755 boost::algorithm::to_lower(hostname_);
1756
1757 ElementPtr leases_json = Element::createList();
1758 if (v4) {
1759 Lease4Collection leases =
1761
1762 for (auto const& lease : leases) {
1763 ElementPtr lease_json = lease->toElement();
1764 leases_json->add(lease_json);
1765 }
1766 } else {
1767 Lease6Collection leases =
1769
1770 for (auto const& lease : leases) {
1771 ElementPtr lease_json = lease->toElement();
1772 leases_json->add(lease_json);
1773 }
1774 }
1775
1776 std::ostringstream s;
1777 s << leases_json->size()
1778 << " IPv" << (v4 ? "4" : "6")
1779 << " lease(s) found.";
1781 args->set("leases", leases_json);
1782 ConstElementPtr response =
1783 createAnswer(leases_json->size() > 0 ?
1786 s.str(), args);
1787 setResponse(handle, response);
1788
1789 } catch (const std::exception& ex) {
1790 setErrorResponse(handle, ex.what());
1791 return (CONTROL_RESULT_ERROR);
1792 }
1793
1794 return (0);
1795}
1796
1797int
1799 Parameters p;
1800 Lease4Ptr lease4;
1801 try {
1802 extractCommand(handle);
1803 p = getParameters(false, cmd_args_);
1804 switch (p.query_type) {
1805 case Parameters::TYPE_ADDR: {
1806 // If address was specified explicitly, let's use it as is.
1808 if (!lease4) {
1809 setErrorResponse(handle, "IPv4 lease not found.", CONTROL_RESULT_EMPTY);
1810 return (0);
1811 }
1812 break;
1813 }
1815 if (!p.hwaddr) {
1816 isc_throw(InvalidParameter, "Program error: Query by hw-address "
1817 "requires hwaddr to be specified");
1818 }
1819
1820 // Let's see if there's such a lease at all.
1822 if (!lease4) {
1823 setErrorResponse(handle, "IPv4 lease not found.", CONTROL_RESULT_EMPTY);
1824 return (0);
1825 }
1826 break;
1827 }
1829 if (!p.client_id) {
1830 isc_throw(InvalidParameter, "Program error: Query by client-id "
1831 "requires client-id to be specified");
1832 }
1833
1834 // Let's see if there's such a lease at all.
1836 if (!lease4) {
1837 setErrorResponse(handle, "IPv4 lease not found.", CONTROL_RESULT_EMPTY);
1838 return (0);
1839 }
1840 break;
1841 }
1842 case Parameters::TYPE_DUID: {
1843 isc_throw(InvalidParameter, "Delete by duid is not allowed in v4.");
1844 break;
1845 }
1846 default: {
1847 isc_throw(InvalidOperation, "Unknown query type: " << static_cast<int>(p.query_type));
1848 break;
1849 }
1850 }
1851
1852 if (LeaseMgrFactory::instance().deleteLease(lease4)) {
1853 setSuccessResponse(handle, "IPv4 lease deleted.");
1855 } else {
1856 setErrorResponse (handle, "IPv4 lease not found.", CONTROL_RESULT_EMPTY);
1857 }
1858
1859 // Queue an NCR to remove DNS if configured and the lease has it.
1860 if (p.updateDDNS) {
1861 queueNCR(CHG_REMOVE, lease4);
1862 }
1863
1864 } catch (const std::exception& ex) {
1866 .arg(cmd_args_ ? cmd_args_->str() : "<no args>")
1867 .arg(ex.what());
1868 setErrorResponse(handle, ex.what());
1869 return (1);
1870 }
1872 .arg(lease4->addr_.toText());
1873 return (0);
1874}
1875
1876int
1878 try {
1879 extractCommand(handle);
1880
1881 // Arguments are mandatory.
1882 if (!cmd_args_ || (cmd_args_->getType() != Element::map)) {
1883 isc_throw(BadValue, "Command arguments missing or a not a map.");
1884 }
1885
1886 // At least one of the 'deleted-leases' or 'leases' must be present.
1887 auto deleted_leases = cmd_args_->get("deleted-leases");
1888 auto leases = cmd_args_->get("leases");
1889
1890 if (!deleted_leases && !leases) {
1891 isc_throw(BadValue, "neither 'deleted-leases' nor 'leases' parameter"
1892 " specified");
1893 }
1894
1895 // Make sure that 'deleted-leases' is a list, if present.
1896 if (deleted_leases && (deleted_leases->getType() != Element::list)) {
1897 isc_throw(BadValue, "the 'deleted-leases' parameter must be a list");
1898 }
1899
1900 // Make sure that 'leases' is a list, if present.
1901 if (leases && (leases->getType() != Element::list)) {
1902 isc_throw(BadValue, "the 'leases' parameter must be a list");
1903 }
1904
1905 // Parse deleted leases without deleting them from the database
1906 // yet. If any of the deleted leases or new leases appears to be
1907 // malformed we can easily rollback.
1908 std::list<std::pair<Parameters, Lease6Ptr> > parsed_deleted_list;
1909 if (deleted_leases) {
1910 auto leases_list = deleted_leases->listValue();
1911
1912 // Iterate over leases to be deleted.
1913 for (auto const& lease_params : leases_list) {
1914 // Parsing the lease may throw and it means that the lease
1915 // information is malformed.
1916 Parameters p = getParameters(true, lease_params);
1917 auto lease = getIPv6LeaseForDelete(p);
1918 parsed_deleted_list.push_back(std::make_pair(p, lease));
1919 }
1920 }
1921
1922 // Parse new/updated leases without affecting the database to detect
1923 // any errors that should cause an error response.
1924 std::list<Lease6Ptr> parsed_leases_list;
1925 if (leases) {
1927
1928 // Iterate over all leases.
1929 auto leases_list = leases->listValue();
1930 for (auto const& lease_params : leases_list) {
1931
1932 Lease6Parser parser;
1933 bool force_update;
1934
1935 // If parsing the lease fails we throw, as it indicates that the
1936 // command is malformed.
1937 Lease6Ptr lease6 = parser.parse(config, lease_params, force_update);
1938 parsed_leases_list.push_back(lease6);
1939 }
1940 }
1941
1942 // Count successful deletions and updates.
1943 size_t success_count = 0;
1944
1945 ElementPtr failed_deleted_list;
1946 if (!parsed_deleted_list.empty()) {
1947
1948 // Iterate over leases to be deleted.
1949 for (auto const& lease_params_pair : parsed_deleted_list) {
1950
1951 // This part is outside of the try-catch because an exception
1952 // indicates that the command is malformed.
1953 Parameters p = lease_params_pair.first;
1954 auto lease = lease_params_pair.second;
1955
1956 try {
1957 if (lease) {
1958 // This may throw if the lease couldn't be deleted for
1959 // any reason, but we still want to proceed with other
1960 // leases.
1961 if (LeaseMgrFactory::instance().deleteLease(lease)) {
1962 ++success_count;
1964
1965 } else {
1966 // Lazy creation of the list of leases which failed to delete.
1967 if (!failed_deleted_list) {
1968 failed_deleted_list = Element::createList();
1969 }
1970
1971 // If the lease doesn't exist we also want to put it
1972 // on the list of leases which failed to delete. That
1973 // corresponds to the lease6-del command which returns
1974 // an error when the lease doesn't exist.
1975 failed_deleted_list->add(createFailedLeaseMap(p.lease_type,
1976 p.addr, p.duid,
1978 "lease not found"));
1979 }
1980 }
1981
1982 } catch (const std::exception& ex) {
1983 // Lazy creation of the list of leases which failed to delete.
1984 if (!failed_deleted_list) {
1985 failed_deleted_list = Element::createList();
1986 }
1987 failed_deleted_list->add(createFailedLeaseMap(p.lease_type,
1988 p.addr, p.duid,
1990 ex.what()));
1991 }
1992 }
1993 }
1994
1995 // Process leases to be added or/and updated.
1996 ElementPtr failed_leases_list;
1997 if (!parsed_leases_list.empty()) {
1999
2000 // Iterate over all leases.
2001 for (auto const& lease : parsed_leases_list) {
2002
2003 auto result = CONTROL_RESULT_SUCCESS;
2004 std::ostringstream text;
2005 try {
2006 if (!MultiThreadingMgr::instance().getMode()) {
2007 // Not multi-threading.
2008 addOrUpdate6(lease, true);
2009 } else {
2010 // Multi-threading, try to lock first to avoid a race.
2011 ResourceHandler resource_handler;
2012 if (resource_handler.tryLock(lease->type_, lease->addr_)) {
2013 addOrUpdate6(lease, true);
2014 } else {
2016 "ResourceBusy: IP address:" << lease->addr_
2017 << " could not be updated.");
2018 }
2019 }
2020
2021 ++success_count;
2022 } catch (const LeaseCmdsConflict& ex) {
2023 result = CONTROL_RESULT_CONFLICT;
2024 text << ex.what();
2025
2026 } catch (const std::exception& ex) {
2027 result = CONTROL_RESULT_ERROR;
2028 text << ex.what();
2029 }
2030 // Handle an error.
2031 if (result != CONTROL_RESULT_SUCCESS) {
2032 // Lazy creation of the list of leases which failed to add/update.
2033 if (!failed_leases_list) {
2034 failed_leases_list = Element::createList();
2035 }
2036 failed_leases_list->add(createFailedLeaseMap(lease->type_,
2037 lease->addr_,
2038 lease->duid_,
2039 result,
2040 text.str()));
2041 }
2042 }
2043 }
2044
2045 // Start preparing the response.
2046 ElementPtr args;
2047
2048 if (failed_deleted_list || failed_leases_list) {
2049 // If there are any failed leases, let's include them in the response.
2050 args = Element::createMap();
2051
2052 // failed-deleted-leases
2053 if (failed_deleted_list) {
2054 args->set("failed-deleted-leases", failed_deleted_list);
2055 }
2056
2057 // failed-leases
2058 if (failed_leases_list) {
2059 args->set("failed-leases", failed_leases_list);
2060 }
2061 }
2062
2063 // Send the success response and include failed leases.
2064 std::ostringstream resp_text;
2065 resp_text << "Bulk apply of " << success_count << " IPv6 leases completed.";
2066 auto answer = createAnswer(success_count > 0 ? CONTROL_RESULT_SUCCESS :
2067 CONTROL_RESULT_EMPTY, resp_text.str(), args);
2068 setResponse(handle, answer);
2069
2072 .arg(success_count);
2073
2074 } catch (const std::exception& ex) {
2075 // Unable to parse the command and similar issues.
2077 .arg(cmd_args_ ? cmd_args_->str() : "<no args>")
2078 .arg(ex.what());
2079 setErrorResponse(handle, ex.what());
2080 return (CONTROL_RESULT_ERROR);
2081 }
2082
2083 return (0);
2084}
2085
2086int
2088 Parameters p;
2089 Lease6Ptr lease6;
2091 try {
2092 extractCommand(handle);
2093 p = getParameters(true, cmd_args_);
2094
2095 switch (p.query_type) {
2096 case Parameters::TYPE_ADDR: {
2097 // If address was specified explicitly, let's use it as is.
2098
2099 // Let's see if there's such a lease at all.
2101 if (!lease6) {
2102 setErrorResponse(handle, "IPv6 lease not found.", CONTROL_RESULT_EMPTY);
2103 return (0);
2104 }
2105 break;
2106 }
2108 isc_throw(InvalidParameter, "Delete by hw-address is not allowed in v6.");
2109 break;
2110 }
2111 case Parameters::TYPE_DUID: {
2112 if (!p.duid) {
2113 isc_throw(InvalidParameter, "Program error: Query by duid "
2114 "requires duid to be specified");
2115 }
2116
2117 // Let's see if there's such a lease at all.
2119 p.iaid, p.subnet_id);
2120 if (!lease6) {
2121 setErrorResponse(handle, "IPv6 lease not found.", CONTROL_RESULT_EMPTY);
2122 return (0);
2123 }
2124 break;
2125 }
2126 default: {
2127 isc_throw(InvalidOperation, "Unknown query type: " << static_cast<int>(p.query_type));
2128 break;
2129 }
2130 }
2131
2132 if (LeaseMgrFactory::instance().deleteLease(lease6)) {
2133 setSuccessResponse(handle, "IPv6 lease deleted.");
2135 } else {
2136 setErrorResponse (handle, "IPv6 lease not found.", CONTROL_RESULT_EMPTY);
2137 }
2138
2139 // Queue an NCR to remove DNS if configured and the lease has it.
2140 if (p.updateDDNS) {
2141 queueNCR(CHG_REMOVE, lease6);
2142 }
2143
2144 } catch (const std::exception& ex) {
2146 .arg(cmd_args_ ? cmd_args_->str() : "<no args>")
2147 .arg(ex.what());
2148 setErrorResponse(handle, ex.what());
2149 return (1);
2150 }
2151
2153 .arg(lease6->addr_.toText());
2154 return (0);
2155}
2156
2157int
2159 try {
2160 extractCommand(handle);
2161
2162 // We need the lease to be specified.
2163 if (!cmd_args_) {
2164 isc_throw(isc::BadValue, "no parameters specified for lease4-update command");
2165 }
2166
2167 // Get the parameters specified by the user first.
2169 Lease4Ptr lease4;
2170 Lease4Parser parser;
2171 bool force_create = false;
2172
2173 // The parser does sanity checks (if the address is in scope, if
2174 // subnet-id is valid, etc)
2175 lease4 = parser.parse(config, cmd_args_, force_create);
2176 bool added = false;
2177 if (!MultiThreadingMgr::instance().getMode()) {
2178 // Not multi-threading.
2179 added = addOrUpdate4(lease4, force_create);
2180 } else {
2181 // Multi-threading, try to lock first to avoid a race.
2182 ResourceHandler4 resource_handler;
2183 if (resource_handler.tryLock4(lease4->addr_)) {
2184 added = addOrUpdate4(lease4, force_create);
2185 } else {
2187 "ResourceBusy: IP address:" << lease4->addr_
2188 << " could not be updated.");
2189 }
2190 }
2191
2192 if (added) {
2193 setSuccessResponse(handle, "IPv4 lease added.");
2194 } else {
2195 setSuccessResponse(handle, "IPv4 lease updated.");
2196 }
2199 .arg(lease4->addr_.toText());
2200
2201 } catch (const LeaseCmdsConflict& ex) {
2203 .arg(cmd_args_ ? cmd_args_->str() : "<no args>")
2204 .arg(ex.what());
2206 return (0);
2207
2208 } catch (const std::exception& ex) {
2210 .arg(cmd_args_ ? cmd_args_->str() : "<no args>")
2211 .arg(ex.what());
2212 setErrorResponse(handle, ex.what());
2213 return (1);
2214 }
2215
2216 return (0);
2217}
2218
2219int
2221 try {
2222 extractCommand(handle);
2223
2224 // We need the lease to be specified.
2225 if (!cmd_args_) {
2226 isc_throw(isc::BadValue, "no parameters specified for lease6-update command");
2227 }
2228
2229 // Get the parameters specified by the user first.
2231 Lease6Ptr lease6;
2232 Lease6Parser parser;
2233 bool force_create = false;
2234
2235 // The parser does sanity checks (if the address is in scope, if
2236 // subnet-id is valid, etc)
2237 lease6 = parser.parse(config, cmd_args_, force_create);
2238 bool added = false;
2239 if (!MultiThreadingMgr::instance().getMode()) {
2240 // Not multi-threading.
2241 added = addOrUpdate6(lease6, force_create);
2242 } else {
2243 // Multi-threading, try to lock first to avoid a race.
2244 ResourceHandler resource_handler;
2245 if (resource_handler.tryLock(lease6->type_, lease6->addr_)) {
2246 added = addOrUpdate6(lease6, force_create);
2247 } else {
2249 "ResourceBusy: IP address:" << lease6->addr_
2250 << " could not be updated.");
2251 }
2252 }
2253
2254 if (added) {
2255 setSuccessResponse(handle, "IPv6 lease added.");
2256 } else {
2257 setSuccessResponse(handle, "IPv6 lease updated.");
2258 }
2261 .arg(lease6->addr_.toText());
2262
2263 } catch (const LeaseCmdsConflict& ex) {
2265 .arg(cmd_args_ ? cmd_args_->str() : "<no args>")
2266 .arg(ex.what());
2268 return (0);
2269
2270 } catch (const std::exception& ex) {
2272 .arg(cmd_args_ ? cmd_args_->str() : "<no args>")
2273 .arg(ex.what());
2274 setErrorResponse(handle, ex.what());
2275 return (1);
2276 }
2277
2278 return (0);
2279}
2280
2281int
2283 try {
2284 extractCommand(handle);
2285
2286 SimpleParser parser;
2287 SubnetID id = 0;
2288
2289 size_t num = 0; // number of leases deleted
2290 stringstream ids; // a text with subnet-ids being wiped
2291
2292 // The subnet-id parameter is now optional.
2293 if (cmd_args_ && cmd_args_->contains("subnet-id")) {
2294 id = parser.getUint32(cmd_args_, "subnet-id");
2295 }
2296
2297 if (id) {
2298 // Wipe a single subnet.
2300 ids << " " << id;
2301
2302 auto observation = StatsMgr::instance().getObservation(
2303 StatsMgr::generateName("subnet", id, "declined-addresses"));
2304
2305 int64_t previous_declined = 0;
2306
2307 if (observation) {
2308 previous_declined = observation->getInteger().first;
2309 }
2310
2312 StatsMgr::generateName("subnet", id, "assigned-addresses"),
2313 static_cast<int64_t>(0));
2314
2316 StatsMgr::generateName("subnet", id, "declined-addresses"),
2317 static_cast<int64_t>(0));
2318
2319 auto const& sub = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getBySubnetId(id);
2320 if (sub) {
2321 for (auto const& pool : sub->getPools(Lease::TYPE_V4)) {
2322 const std::string& name_aa(StatsMgr::generateName("subnet", sub->getID(),
2323 StatsMgr::generateName("pool", pool->getID(),
2324 "assigned-addresses")));
2325 if (!StatsMgr::instance().getObservation(name_aa)) {
2326 StatsMgr::instance().setValue(name_aa, static_cast<int64_t>(0));
2327 }
2328
2329 const std::string& name_da(StatsMgr::generateName("subnet", sub->getID(),
2330 StatsMgr::generateName("pool", pool->getID(),
2331 "declined-addresses")));
2332 if (!StatsMgr::instance().getObservation(name_da)) {
2333 StatsMgr::instance().setValue(name_da, static_cast<int64_t>(0));
2334 }
2335 }
2336 }
2337
2338 StatsMgr::instance().addValue("declined-addresses", -previous_declined);
2339 } else {
2340 // Wipe them all!
2342 ConstCfgSubnets4Ptr subnets = config->getCfgSubnets4();
2343 const Subnet4Collection* subs = subnets->getAll();
2344
2345 // Go over all subnets and wipe leases in each of them.
2346 for (auto const& sub : *subs) {
2347 num += LeaseMgrFactory::instance().wipeLeases4(sub->getID());
2348 ids << " " << sub->getID();
2350 StatsMgr::generateName("subnet", sub->getID(), "assigned-addresses"),
2351 static_cast<int64_t>(0));
2352
2354 StatsMgr::generateName("subnet", sub->getID(), "declined-addresses"),
2355 static_cast<int64_t>(0));
2356
2357 for (auto const& pool : sub->getPools(Lease::TYPE_V4)) {
2358 const std::string& name_aa(StatsMgr::generateName("subnet", sub->getID(),
2359 StatsMgr::generateName("pool", pool->getID(),
2360 "assigned-addresses")));
2361 if (!StatsMgr::instance().getObservation(name_aa)) {
2362 StatsMgr::instance().setValue(name_aa, static_cast<int64_t>(0));
2363 }
2364
2365 const std::string& name_da(StatsMgr::generateName("subnet", sub->getID(),
2366 StatsMgr::generateName("pool", pool->getID(),
2367 "declined-addresses")));
2368 if (!StatsMgr::instance().getObservation(name_da)) {
2369 StatsMgr::instance().setValue(name_da, static_cast<int64_t>(0));
2370 }
2371 }
2372 }
2373
2374 StatsMgr::instance().setValue("declined-addresses", static_cast<int64_t>(0));
2375 }
2376
2377 stringstream tmp;
2378 tmp << "Deleted " << num << " IPv4 lease(s) from subnet(s)" << ids.str();
2380 : CONTROL_RESULT_EMPTY, tmp.str());
2381 setResponse(handle, response);
2382 } catch (const std::exception& ex) {
2384 .arg(cmd_args_ ? cmd_args_->str() : "<no args>")
2385 .arg(ex.what());
2386 setErrorResponse(handle, ex.what());
2387 return (1);
2388 }
2389
2391 .arg(cmd_args_ ? cmd_args_->str() : "<no args>");
2392 return (0);
2393}
2394
2395int
2397 try {
2398 extractCommand(handle);
2399
2400 SimpleParser parser;
2401 SubnetID id = 0;
2402
2403 size_t num = 0; // number of leases deleted
2404 stringstream ids; // a text with subnet-ids being wiped
2405
2410
2411 // The subnet-id parameter is now optional.
2412 if (cmd_args_ && cmd_args_->contains("subnet-id")) {
2413 id = parser.getUint32(cmd_args_, "subnet-id");
2414 }
2415
2416 if (id) {
2417 // Wipe a single subnet.
2419 ids << " " << id;
2420
2421 auto observation = StatsMgr::instance().getObservation(
2422 StatsMgr::generateName("subnet", id, "declined-addresses"));
2423
2424 int64_t previous_declined = 0;
2425
2426 if (observation) {
2427 previous_declined = observation->getInteger().first;
2428 }
2429
2431 StatsMgr::generateName("subnet", id, "assigned-nas" ),
2432 static_cast<int64_t>(0));
2433
2435 StatsMgr::generateName("subnet", id, "assigned-pds"),
2436 static_cast<int64_t>(0));
2437
2439 StatsMgr::generateName("subnet", id, "declined-addresses"),
2440 static_cast<int64_t>(0));
2441
2443 StatsMgr::generateName("subnet", id, "registered-nas"),
2444 static_cast<int64_t>(0));
2445
2446 auto const& sub = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(id);
2447 if (sub) {
2448 for (auto const& pool : sub->getPools(Lease::TYPE_NA)) {
2449 const std::string& name_anas(StatsMgr::generateName("subnet", sub->getID(),
2450 StatsMgr::generateName("pool", pool->getID(),
2451 "assigned-nas")));
2452 if (!StatsMgr::instance().getObservation(name_anas)) {
2453 StatsMgr::instance().setValue(name_anas, static_cast<int64_t>(0));
2454 }
2455
2456 const std::string& name_da(StatsMgr::generateName("subnet", sub->getID(),
2457 StatsMgr::generateName("pool", pool->getID(),
2458 "declined-addresses")));
2459 if (!StatsMgr::instance().getObservation(name_da)) {
2460 StatsMgr::instance().setValue(name_da, static_cast<int64_t>(0));
2461 }
2462 }
2463
2464 for (auto const& pool : sub->getPools(Lease::TYPE_PD)) {
2465 const std::string& name_apds(StatsMgr::generateName("subnet", sub->getID(),
2466 StatsMgr::generateName("pd-pool", pool->getID(),
2467 "assigned-pds")));
2468 if (!StatsMgr::instance().getObservation(name_apds)) {
2469 StatsMgr::instance().setValue(name_apds, static_cast<int64_t>(0));
2470 }
2471 }
2472 }
2473
2474 StatsMgr::instance().addValue("declined-addresses", -previous_declined);
2475 } else {
2476 // Wipe them all!
2478 ConstCfgSubnets6Ptr subnets = config->getCfgSubnets6();
2479 const Subnet6Collection* subs = subnets->getAll();
2480
2481 // Go over all subnets and wipe leases in each of them.
2482 for (auto const& sub : *subs) {
2483 num += LeaseMgrFactory::instance().wipeLeases6(sub->getID());
2484 ids << " " << sub->getID();
2486 StatsMgr::generateName("subnet", sub->getID(), "assigned-nas" ),
2487 static_cast<int64_t>(0));
2488
2490 StatsMgr::generateName("subnet", sub->getID(), "assigned-pds"),
2491 static_cast<int64_t>(0));
2492
2494 StatsMgr::generateName("subnet", sub->getID(), "declined-addresses"),
2495 static_cast<int64_t>(0));
2496
2498 StatsMgr::generateName("subnet", sub->getID(), "registered-nas"),
2499 static_cast<int64_t>(0));
2500
2501 for (auto const& pool : sub->getPools(Lease::TYPE_NA)) {
2502 const std::string& name_anas(StatsMgr::generateName("subnet", sub->getID(),
2503 StatsMgr::generateName("pool", pool->getID(),
2504 "assigned-nas")));
2505 if (!StatsMgr::instance().getObservation(name_anas)) {
2506 StatsMgr::instance().setValue(name_anas, static_cast<int64_t>(0));
2507 }
2508
2509 const std::string& name_da(StatsMgr::generateName("subnet", sub->getID(),
2510 StatsMgr::generateName("pool", pool->getID(),
2511 "declined-addresses")));
2512 if (!StatsMgr::instance().getObservation(name_da)) {
2513 StatsMgr::instance().setValue(name_da, static_cast<int64_t>(0));
2514 }
2515 }
2516
2517 for (auto const& pool : sub->getPools(Lease::TYPE_PD)) {
2518 const std::string& name_apds(StatsMgr::generateName("subnet", sub->getID(),
2519 StatsMgr::generateName("pd-pool", pool->getID(),
2520 "assigned-pds")));
2521 if (!StatsMgr::instance().getObservation(name_apds)) {
2522 StatsMgr::instance().setValue(name_apds, static_cast<int64_t>(0));
2523 }
2524 }
2525 }
2526
2527 StatsMgr::instance().setValue("declined-addresses", static_cast<int64_t>(0));
2528 }
2529
2530 stringstream tmp;
2531 tmp << "Deleted " << num << " IPv6 lease(s) from subnet(s)" << ids.str();
2533 : CONTROL_RESULT_EMPTY, tmp.str());
2534 setResponse(handle, response);
2535 } catch (const std::exception& ex) {
2537 .arg(cmd_args_ ? cmd_args_->str() : "<no args>")
2538 .arg(ex.what());
2539 setErrorResponse(handle, ex.what());
2540 return (1);
2541 }
2542
2544 .arg(cmd_args_ ? cmd_args_->str() : "<no args>");
2545 return (0);
2546}
2547
2550 Lease6Ptr lease6;
2551
2552 switch (parameters.query_type) {
2553 case Parameters::TYPE_ADDR: {
2554 // If address was specified explicitly, let's use it as is.
2555
2556 // Let's see if there's such a lease at all.
2557 lease6 = LeaseMgrFactory::instance().getLease6(parameters.lease_type,
2558 parameters.addr);
2559 if (!lease6) {
2560 lease6.reset(new Lease6());
2561 lease6->addr_ = parameters.addr;
2562 }
2563 break;
2564 }
2566 isc_throw(InvalidParameter, "Delete by hw-address is not allowed in v6.");
2567 break;
2568 }
2569 case Parameters::TYPE_DUID: {
2570 if (!parameters.duid) {
2571 isc_throw(InvalidParameter, "Program error: Query by duid "
2572 "requires duid to be specified");
2573 }
2574
2575 // Let's see if there's such a lease at all.
2576 lease6 = LeaseMgrFactory::instance().getLease6(parameters.lease_type,
2577 *parameters.duid,
2578 parameters.iaid,
2579 parameters.subnet_id);
2580 break;
2581 }
2582 default:
2583 isc_throw(InvalidOperation, "Unknown query type: "
2584 << static_cast<int>(parameters.query_type));
2585 }
2586
2587 return (lease6);
2588}
2589
2592 short family) const {
2593 ConstElementPtr param = params->get(name);
2594 if (!param) {
2595 isc_throw(BadValue, "'" << name << "' parameter is missing.");
2596 }
2597
2598 if (param->getType() != Element::string) {
2599 isc_throw(BadValue, "'" << name << "' is not a string.");
2600 }
2601
2602 IOAddress addr(0);
2603 try {
2604 addr = IOAddress(param->stringValue());
2605 } catch (const std::exception& ex) {
2606 isc_throw(BadValue, "'" << param->stringValue()
2607 << "' is not a valid IP address.");
2608 }
2609
2610 if (addr.getFamily() != family) {
2611 isc_throw(BadValue, "Invalid "
2612 << (family == AF_INET6 ? "IPv6" : "IPv4")
2613 << " address specified: " << param->stringValue());
2614 }
2615
2616 return (addr);
2617}
2618
2619int
2621 std::stringstream ss;
2622 int resp_code = CONTROL_RESULT_ERROR;
2623
2624 try {
2625 extractCommand(handle);
2626
2627 // Get the target lease address. Invalid value will throw.
2628 IOAddress addr = getAddressParam(cmd_args_, "ip-address", AF_INET);
2629
2630 if (!CfgMgr::instance().getD2ClientMgr().ddnsEnabled()) {
2631 ss << "DDNS updating is not enabled";
2632 resp_code = CONTROL_RESULT_CONFLICT;
2633 } else {
2634 // Find the lease.
2636 if (!lease) {
2637 ss << "No lease found for: " << addr.toText();
2638 resp_code = CONTROL_RESULT_EMPTY;
2639 } else if (lease->hostname_.empty()) {
2640 ss << "Lease for: " << addr.toText()
2641 << ", has no hostname, nothing to update";
2642 resp_code = CONTROL_RESULT_CONFLICT;
2643 } else if (!lease->fqdn_fwd_ && !lease->fqdn_rev_) {
2644 ss << "Neither forward nor reverse updates enabled for lease for: "
2645 << addr.toText();
2646 resp_code = CONTROL_RESULT_CONFLICT;
2647 } else {
2648 // We have a lease with a hostname and updates in at least
2649 // one direction enabled. Queue an NCR for it.
2650 queueNCR(CHG_ADD, lease);
2651 ss << "NCR generated for: " << addr.toText()
2652 << ", hostname: " << lease->hostname_;
2653 setSuccessResponse(handle, ss.str());
2655 return (0);
2656 }
2657 }
2658 } catch (const std::exception& ex) {
2659 ss << ex.what();
2660 }
2661
2663 setErrorResponse(handle, ss.str(), resp_code);
2664 return (resp_code == CONTROL_RESULT_EMPTY || resp_code == CONTROL_RESULT_CONFLICT ? 0 : 1);
2665}
2666
2667int
2669 std::stringstream ss;
2670 int resp_code = CONTROL_RESULT_ERROR;
2671
2672 try {
2673 extractCommand(handle);
2674
2675 // Get the target lease address. Invalid value will throw.
2676 IOAddress addr = getAddressParam(cmd_args_, "ip-address", AF_INET6);
2677
2678 if (!CfgMgr::instance().getD2ClientMgr().ddnsEnabled()) {
2679 ss << "DDNS updating is not enabled";
2680 resp_code = CONTROL_RESULT_CONFLICT;
2681 } else {
2682 // Find the lease.
2684 if (!lease) {
2685 ss << "No lease found for: " << addr.toText();
2686 resp_code = CONTROL_RESULT_EMPTY;
2687 } else if (lease->hostname_.empty()) {
2688 ss << "Lease for: " << addr.toText()
2689 << ", has no hostname, nothing to update";
2690 resp_code = CONTROL_RESULT_CONFLICT;
2691 } else if (!lease->fqdn_fwd_ && !lease->fqdn_rev_) {
2692 ss << "Neither forward nor reverse updates enabled for lease for: "
2693 << addr.toText();
2694 resp_code = CONTROL_RESULT_CONFLICT;
2695 } else {
2696 // We have a lease with a hostname and updates in at least
2697 // one direction enabled. Queue an NCR for it.
2698 queueNCR(CHG_ADD, lease);
2699 ss << "NCR generated for: " << addr.toText()
2700 << ", hostname: " << lease->hostname_;
2701 setSuccessResponse(handle, ss.str());
2703 return (0);
2704 }
2705 }
2706 } catch (const std::exception& ex) {
2707 ss << ex.what();
2708 }
2709
2711 setErrorResponse(handle, ss.str(), resp_code);
2712 return (resp_code == CONTROL_RESULT_EMPTY ? 0 : 1);
2713}
2714
2717 const IOAddress& lease_address,
2718 const DuidPtr& duid,
2719 const int control_result,
2720 const std::string& error_message) const {
2721 auto failed_lease_map = Element::createMap();
2722 failed_lease_map->set("type", Element::create(Lease::typeToText(lease_type)));
2723
2724 if (!lease_address.isV6Zero()) {
2725 failed_lease_map->set("ip-address", Element::create(lease_address.toText()));
2726
2727 } else if (duid) {
2728 failed_lease_map->set("duid", Element::create(duid->toText()));
2729 }
2730
2731 // Associate the result with the lease.
2732 failed_lease_map->set("result", Element::create(control_result));
2733 failed_lease_map->set("error-message", Element::create(error_message));
2734
2735 return (failed_lease_map);
2736}
2737
2738int
2740 bool v4 = true;
2741 try {
2742 extractCommand(handle);
2743 v4 = (cmd_name_ == "lease4-write");
2744
2745 if (!cmd_args_) {
2746 isc_throw(isc::BadValue, "no parameters specified for the command");
2747 }
2748
2749 ConstElementPtr file = cmd_args_->get("filename");
2750 if (!file) {
2751 isc_throw(BadValue, "'filename' parameter not specified");
2752 }
2753 if (file->getType() != Element::string) {
2754 isc_throw(BadValue, "'filename' parameter must be a string");
2755 }
2756
2757 std::string filename;
2758 try {
2759 filename = CfgMgr::instance().validatePath(file->stringValue());
2760 } catch (const SecurityWarn& ex) {
2762 .arg(ex.what());
2763 filename = file->stringValue();
2764 } catch (const std::exception& ex) {
2765 isc_throw(BadValue, "'filename' parameter is invalid: " << ex.what());
2766 }
2767
2768 if (v4) {
2770 } else {
2772 }
2773
2774 ostringstream s;
2775 s << (v4 ? "IPv4" : "IPv6")
2776 << " lease database into '"
2777 << filename << "'.";
2779 setResponse(handle, response);
2780 } catch (const std::exception& ex) {
2781 setErrorResponse(handle, ex.what());
2782 return (CONTROL_RESULT_ERROR);
2783 }
2784
2785 return (0);
2786}
2787
2788void
2791 uint32_t offer_lifetime;
2792 callout_handle.getArgument("offer_lifetime", offer_lifetime);
2793 if (!offer_lifetime) {
2794 // Offers leases are not being persisted, nothing to do.
2795 return;
2796 }
2797
2798 // Get the remaining arguments we need.
2799 Pkt4Ptr query;
2800 Pkt4Ptr response;
2801 Lease4CollectionPtr leases;
2802
2803 callout_handle.getArgument("query4", query);
2804 callout_handle.getArgument("response4", response);
2805 callout_handle.getArgument("leases4", leases);
2806
2807 if (!leases || leases->empty() || !((*leases)[0])) {
2808 isc_throw(Unexpected, "lease4Offer - no lease!");
2809 }
2810
2811 Lease4Ptr lease = (*leases)[0];
2812 try {
2813 if (mgr->evaluateVariables(query, response, lease)) {
2815 }
2816 } catch (const NoSuchLease&) {
2817 isc_throw(LeaseCmdsConflict, "failed to update"
2818 " the lease with address " << lease->addr_ <<
2819 " either because the lease has been"
2820 " deleted or it has changed in the database");
2821 } catch (const std::exception& ex) {
2822 isc_throw(Unexpected, "evaluating binding variables failed for: "
2823 << query->getLabel() << ", :" << ex.what());
2824 }
2825}
2826
2827void
2830 Pkt4Ptr query;
2831 Pkt4Ptr response;
2832 Lease4CollectionPtr leases;
2833
2834 // Get the necessary arguments.
2835 callout_handle.getArgument("query4", query);
2836 callout_handle.getArgument("response4", response);
2837 callout_handle.getArgument("leases4", leases);
2838
2839 if (!leases) {
2840 isc_throw(Unexpected, "leases4Committed - leases is null");
2841 }
2842
2843 // In some cases we may have no lease, e.g. DHCPNAK,
2844 // or no response e.g. DHCPRELEASE.
2845 if (leases->empty() || !response || (response->getType() != DHCPACK)) {
2846 return;
2847 }
2848
2849 Lease4Ptr lease = (*leases)[0];
2850 if (!lease) {
2851 isc_throw(Unexpected, "leases4Committed - lease is null");
2852 }
2853
2854 try {
2855 if (mgr->evaluateVariables(query, response, lease)) {
2857 }
2858 } catch (const NoSuchLease&) {
2859 isc_throw(LeaseCmdsConflict, "failed to update"
2860 " the lease with address " << lease->addr_ <<
2861 " either because the lease has been"
2862 " deleted or it has changed in the database");
2863 } catch (const std::exception& ex) {
2864 isc_throw(Unexpected, "evaluating binding variables failed for: "
2865 << query->getLabel() << ", :" << ex.what());
2866 }
2867}
2868
2869void
2872 Pkt6Ptr query;
2873 Pkt6Ptr response;
2874 Lease6CollectionPtr leases;
2875
2876 // Get the necessary arguments.
2877 callout_handle.getArgument("query6", query);
2878 callout_handle.getArgument("response6", response);
2879 callout_handle.getArgument("leases6", leases);
2880
2881 if (!leases) {
2882 isc_throw(Unexpected, "leases6Committed - leases is null");
2883 }
2884
2885 // In some cases we may have no active leases or no response.
2886 if (leases->empty() || !response) {
2887 return;
2888 }
2889
2890 int attempted = 0;
2891 int failed = 0;
2892 for (auto lease : *leases) {
2893 try {
2894 if (!lease) {
2895 isc_throw(Unexpected, "leases6Committed - lease is null");
2896 }
2897
2903 // Only update a lease if its active.
2904 if (lease->valid_lft_) {
2905 ++attempted;
2906 if (mgr->evaluateVariables(query, response, lease)) {
2908 }
2909 }
2910 } catch (const NoSuchLease&) {
2911 ++failed;
2913 .arg(lease->addr_.toText())
2914 .arg(query->getLabel());
2915 } catch (const std::exception& ex) {
2916 ++failed;
2918 .arg(query->getLabel())
2919 .arg(lease->addr_.toText())
2920 .arg(ex.what());
2921 }
2922 }
2923
2924 if (failed) {
2925 isc_throw(Unexpected, failed << " out of " << attempted
2926 << " leases failed to update for "
2927 << query->getLabel());
2928 }
2929}
2930
2931int
2933 return (impl_->leaseAddHandler(handle));
2934}
2935
2936int
2938 return (impl_->lease6BulkApplyHandler(handle));
2939}
2940
2941int
2943 return (impl_->leaseGetHandler(handle));
2944}
2945
2946int
2948 return (impl_->leaseGetAllHandler(handle));
2949}
2950
2951int
2953 return (impl_->leaseGetPageHandler(handle));
2954}
2955
2956int
2958 return (impl_->leaseGetByHwAddressHandler(handle));
2959}
2960
2961int
2963 return (impl_->leaseGetByClientIdHandler(handle));
2964}
2965
2966int
2968 return (impl_->leaseGetByDuidHandler(handle));
2969}
2970
2971int
2973 return (impl_->leaseGetByHostnameHandler(handle));
2974}
2975
2976int
2978 return (impl_->lease4DelHandler(handle));
2979}
2980
2981int
2983 return (impl_->lease6DelHandler(handle));
2984}
2985
2986int
2988 return (impl_->lease4UpdateHandler(handle));
2989}
2990
2991int
2993 return (impl_->lease6UpdateHandler(handle));
2994}
2995
2996int
2999 return (impl_->lease4WipeHandler(handle));
3000}
3001
3002int
3005 return (impl_->lease6WipeHandler(handle));
3006}
3007
3008int
3010 return (impl_->lease4ResendDdnsHandler(handle));
3011}
3012
3013int
3015 return (impl_->lease6ResendDdnsHandler(handle));
3016}
3017
3018int
3020 return (impl_->leaseWriteHandler(handle));
3021}
3022
3024}
3025
3026
3027void
3030 impl_->lease4Offer(callout_handle, mgr);
3031}
3032
3033void
3036 impl_->leases4Committed(callout_handle, mgr);
3037}
3038
3039void
3042 impl_->leases6Committed(callout_handle, mgr);
3043}
3044
3045} // end of namespace lease_cmds
3046} // end of namespace isc
static DUID fromText(const std::string &text)
Create DUID from the textual format.
Definition duid.cc:50
static ElementPtr create(const Position &pos=ZERO_POSITION())
Definition data.cc:249
@ map
Definition data.h:147
@ integer
Definition data.h:140
@ boolean
Definition data.h:142
@ list
Definition data.h:146
@ string
Definition data.h:144
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition data.cc:304
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
Definition data.cc:299
Exception thrown when a command failed due to a conflict.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown if a function is called in a prohibited way.
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
A generic exception that is thrown when an unexpected error condition occurs.
Base class that command handler implementers may use for common tasks.
Definition cmds_impl.h:21
std::string cmd_name_
Stores the command name extracted by a call to extractCommand.
Definition cmds_impl.h:69
void setErrorResponse(hooks::CalloutHandle &handle, const std::string &text, int status=CONTROL_RESULT_ERROR)
Set the callout argument "response" to indicate an error.
Definition cmds_impl.h:54
data::ConstElementPtr cmd_args_
Stores the command arguments extracted by a call to extractCommand.
Definition cmds_impl.h:72
void extractCommand(hooks::CalloutHandle &handle)
Extracts the command name and arguments from a Callout handle.
Definition cmds_impl.h:29
void setSuccessResponse(hooks::CalloutHandle &handle, const std::string &text)
Set the callout argument "response" to indicate success.
Definition cmds_impl.h:43
void setResponse(hooks::CalloutHandle &handle, data::ConstElementPtr &response)
Set the callout argument "response" to the given response.
Definition cmds_impl.h:64
uint32_t getUint32(isc::data::ConstElementPtr scope, const std::string &name)
Returns a value converted to uint32_t.
std::string validatePath(const std::string data_path) const
Validates a file path against the supported directory for DHDP data.
Definition cfgmgr.cc:40
static CfgMgr & instance()
returns a single instance of Configuration Manager
Definition cfgmgr.cc:29
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
Definition cfgmgr.cc:116
static ClientIdPtr fromText(const std::string &text)
Create client identifier from the textual format.
Definition duid.cc:73
Holds DUID (DHCPv6 Unique Identifier)
Definition duid.h:142
static TrackingLeaseMgr & instance()
Return current lease manager.
virtual Lease6Collection getLeases6(Lease::Type type, const DUID &duid, uint32_t iaid) const =0
Returns existing IPv6 leases for a given DUID+IA combination.
virtual size_t wipeLeases6(const SubnetID &subnet_id)=0
Virtual method which removes specified leases.
virtual Lease4Collection getLeases4(SubnetID subnet_id) const =0
Returns all IPv4 leases for the particular subnet identifier.
virtual void writeLeases6(const std::string &filename)=0
Write V6 leases to a file.
virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress &addr) const =0
Returns an IPv4 lease for specified IPv4 address.
virtual bool addLease(const Lease4Ptr &lease)=0
Adds an IPv4 lease.
virtual size_t wipeLeases4(const SubnetID &subnet_id)=0
Virtual method which removes specified leases.
virtual void updateLease4(const Lease4Ptr &lease4)=0
Updates IPv4 lease.
virtual void writeLeases4(const std::string &filename)=0
Write V4 leases to a file.
virtual Lease6Ptr getLease6(Lease::Type type, const isc::asiolink::IOAddress &addr) const =0
Returns existing IPv6 lease for a given IPv6 address.
virtual void updateLease6(const Lease6Ptr &lease6)=0
Updates IPv6 lease.
Wraps value holding size of the page with leases.
Definition lease_mgr.h:46
Attempt to update lease that was not there.
Resource race avoidance RAII handler for DHCPv4.
bool tryLock4(const asiolink::IOAddress &addr)
Tries to acquires a resource.
Resource race avoidance RAII handler.
bool tryLock(Lease::Type type, const asiolink::IOAddress &addr)
Tries to acquires a resource.
Per-packet callout handle.
void getArgument(const std::string &name, T &value) const
Get argument.
Parser for Lease4 structure.
virtual isc::dhcp::Lease4Ptr parse(isc::dhcp::ConstSrvConfigPtr &cfg, const isc::data::ConstElementPtr &lease_info, bool &force_create)
Parses Element tree and tries to convert to Lease4.
Parser for Lease6 structure.
virtual isc::dhcp::Lease6Ptr parse(isc::dhcp::ConstSrvConfigPtr &cfg, const isc::data::ConstElementPtr &lease_info, bool &force_create)
Parses Element tree and tries to convert to Lease4.
Parameters specified for lease commands.
Definition lease_cmds.cc:59
uint32_t iaid
IAID identifier used for v6 leases.
HWAddrPtr hwaddr
Specifies hardware address (used when query_type is TYPE_HWADDR)
Definition lease_cmds.cc:77
Lease::Type lease_type
Lease type (NA,TA or PD) used for v6 leases.
Type query_type
specifies parameter types
Type
specifies type of query (by IP addr, by hwaddr, by DUID)
Definition lease_cmds.cc:63
@ TYPE_CLIENT_ID
query by client identifier (v4 only).
Definition lease_cmds.cc:67
@ TYPE_HWADDR
query by hardware address (v4 only)
Definition lease_cmds.cc:65
@ TYPE_ADDR
query by IP address (either v4 or v6)
Definition lease_cmds.cc:64
isc::dhcp::ClientIdPtr client_id
Specifies identifier value (used when query_type is TYPE_CLIENT_ID)
Definition lease_cmds.cc:83
static Type txtToType(const std::string &txt)
Attempts to covert text to one of specified types.
Definition lease_cmds.cc:94
bool updateDDNS
Indicates whether or not DNS should be updated.
IOAddress addr
Specifies IPv4/v6 address (used when query_type is TYPE_ADDR)
Definition lease_cmds.cc:74
SubnetID subnet_id
Specifies subnet-id (always used)
Definition lease_cmds.cc:71
isc::dhcp::DuidPtr duid
Specifies identifier value (used when query_type is TYPE_DUID)
Definition lease_cmds.cc:80
Wrapper class around reservation command handlers.
Definition lease_cmds.cc:55
int lease4DelHandler(CalloutHandle &handle)
lease4-del command handler
IOAddress getAddressParam(ConstElementPtr params, const std::string name, short family=AF_INET) const
static void lease4Offer(CalloutHandle &callout_handle, BindingVariableMgrPtr mgr)
lease4_offer hookpoint handler.
static void updateStatsOnUpdate(const Lease4Ptr &existing, const Lease4Ptr &lease)
Update stats when updating lease.
ElementPtr createFailedLeaseMap(const Lease::Type &lease_type, const IOAddress &lease_address, const DuidPtr &duid, const int control_result, const std::string &error_message) const
Returns a map holding brief information about a lease which failed to be deleted, updated or added.
static bool addOrUpdate6(Lease6Ptr lease, bool force_create)
Add or update lease.
int lease6BulkApplyHandler(CalloutHandle &handle)
lease6-bulk-apply command handler
int leaseGetByDuidHandler(hooks::CalloutHandle &handle)
lease6-get-by-duid command handler
int lease6UpdateHandler(CalloutHandle &handle)
lease6-update handler
int leaseGetPageHandler(hooks::CalloutHandle &handle)
lease4-get-page, lease6-get-page commands handler
Lease6Ptr getIPv6LeaseForDelete(const Parameters &parameters) const
Convenience function fetching IPv6 address to be used to delete a lease.
int leaseGetByHostnameHandler(hooks::CalloutHandle &handle)
lease4-get-by-hostname and lease6-get-by-hostname commands handler
int lease6DelHandler(CalloutHandle &handle)
lease6-del command handler
int leaseGetByHwAddressHandler(hooks::CalloutHandle &handle)
lease4-get-by-hw-address command handler
static ConstElementPtr getExtendedInfo6(const Lease6Ptr &lease)
Get DHCPv6 extended info.
int leaseGetHandler(CalloutHandle &handle)
lease4-get, lease6-get command handler
static bool addOrUpdate4(Lease4Ptr lease, bool force_create)
Add or update lease.
static void leases4Committed(CalloutHandle &callout_handle, BindingVariableMgrPtr mgr)
leases4_committed hookpoint handler.
int lease6WipeHandler(CalloutHandle &handle)
lease6-wipe handler
int leaseGetByClientIdHandler(hooks::CalloutHandle &handle)
lease4-get-by-client-id command handler
int lease6ResendDdnsHandler(CalloutHandle &handle)
lease6-resend-ddns handler
int leaseAddHandler(CalloutHandle &handle)
lease4-add, lease6-add command handler
int lease4ResendDdnsHandler(CalloutHandle &handle)
lease4-resend-ddns handler
static void updateStatsOnAdd(const Lease4Ptr &lease)
Update stats when adding lease.
Parameters getParameters(bool v6, const ConstElementPtr &args)
Extracts parameters required for reservation-get and reservation-del.
static void leases6Committed(CalloutHandle &callout_handle, BindingVariableMgrPtr mgr)
leases6_committed hookpoint handler.
int lease4UpdateHandler(CalloutHandle &handle)
lease4-update handler
int lease4WipeHandler(CalloutHandle &handle)
lease4-wipe handler
int leaseGetAllHandler(CalloutHandle &handle)
lease4-get-all, lease6-get-all commands handler
int leaseWriteHandler(CalloutHandle &handle)
lease4-write handler, lease6-write handler
static void updateStatsOnDelete(const Lease4Ptr &lease)
Update stats when deleting lease.
int lease4ResendDdnsHandler(hooks::CalloutHandle &handle)
lease4-resend-ddns command handler
int lease6WipeHandler(hooks::CalloutHandle &handle)
lease6-wipe handler
int leaseGetPageHandler(hooks::CalloutHandle &handle)
lease4-get-page, lease6-get-page commands handler
int lease6DelHandler(hooks::CalloutHandle &handle)
lease6-del command handler
int leaseGetAllHandler(hooks::CalloutHandle &handle)
lease4-get-all, lease6-get-all commands handler
int leaseGetByHostnameHandler(hooks::CalloutHandle &handle)
lease4-get-by-hostname and lease6-get-by-hostname commands handler
void leases4Committed(hooks::CalloutHandle &callout_handle, BindingVariableMgrPtr mgr)
leases4_committed hookpoint handler.
int lease4DelHandler(hooks::CalloutHandle &handle)
lease4-del command handler
int leaseWriteHandler(hooks::CalloutHandle &handle)
lease4-write handler, lease6-write handler
int leaseAddHandler(hooks::CalloutHandle &handle)
lease4-add, lease6-add command handler
int leaseGetByClientIdHandler(hooks::CalloutHandle &handle)
lease4-get-by-client-id command handler
void lease4Offer(hooks::CalloutHandle &callout_handle, BindingVariableMgrPtr mgr)
lease4_offer hookpoint handler.
int lease4UpdateHandler(hooks::CalloutHandle &handle)
lease4-update handler
int leaseGetHandler(hooks::CalloutHandle &handle)
lease4-get, lease6-get command handler
int leaseGetByHwAddressHandler(hooks::CalloutHandle &handle)
lease4-get-by-hw-address command handler
int lease6UpdateHandler(hooks::CalloutHandle &handle)
lease6-update handler
void leases6Committed(hooks::CalloutHandle &callout_handle, BindingVariableMgrPtr mgr)
leases6_committed hookpoint handler.
int leaseGetByDuidHandler(hooks::CalloutHandle &handle)
lease6-get-by-duid command handler
int lease6BulkApplyHandler(hooks::CalloutHandle &handle)
lease6-bulk-apply command handler
int lease4WipeHandler(hooks::CalloutHandle &handle)
lease4-wipe handler
int lease6ResendDdnsHandler(hooks::CalloutHandle &handle)
lease6-resend-ddns command handler
ObservationPtr getObservation(const std::string &name) const
Returns an observation.
static StatsMgr & instance()
Statistics Manager accessor method.
static std::string generateName(const std::string &context, Type index, const std::string &stat_name)
Generates statistic name in a given context.
RAII class creating a critical section.
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
A generic exception that is thrown if a parameter given violates security check but enforcement is la...
Definition filesystem.h:21
This file contains several functions and constants that are used for handling commands and responses ...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
void setValue(const std::string &name, const int64_t value)
Records absolute integer observation.
void addValue(const std::string &name, const int64_t value)
Records incremental integer observation.
const isc::log::MessageID LEASE_CMDS_DEL4
const isc::log::MessageID LEASE_CMDS_WIPE4_FAILED
const isc::log::MessageID LEASE_CMDS_UPDATE6_FAILED
const isc::log::MessageID LEASE_CMDS_UPDATE4_FAILED
const isc::log::MessageID LEASE_CMDS_WIPE6_FAILED
const isc::log::MessageID LEASE_CMDS_UPDATE6_CONFLICT
const isc::log::MessageID LEASE_CMDS_UPDATE4_CONFLICT
const isc::log::MessageID LEASE_CMDS_RESEND_DDNS4_FAILED
const isc::log::MessageID LEASE_CMDS_DEL6
const isc::log::MessageID LEASE_CMDS_ADD4_FAILED
const isc::log::MessageID LEASE_CMDS_LEASES6_COMMITTED_LEASE_ERROR
const isc::log::MessageID LEASE_CMDS_PATH_SECURITY_WARNING
const isc::log::MessageID LEASE_CMDS_ADD6
const isc::log::MessageID LEASE_CMDS_ADD4
const isc::log::MessageID LEASE_CMDS_WIPE6
const isc::log::MessageID LEASE_CMDS_ADD6_CONFLICT
const isc::log::MessageID LEASE_CMDS_BULK_APPLY6_FAILED
const isc::log::MessageID LEASE_CMDS_UPDATE6
const isc::log::MessageID LEASE_CMDS_RESEND_DDNS4
const isc::log::MessageID LEASE_CMDS_GET6_FAILED
const isc::log::MessageID LEASE_CMDS_WIPE4
const isc::log::MessageID LEASE_CMDS_BULK_APPLY6
const isc::log::MessageID LEASE_CMDS_RESEND_DDNS6_FAILED
const isc::log::MessageID LEASE_CMDS_RESEND_DDNS6
const isc::log::MessageID LEASE_CMDS_GET4_FAILED
const isc::log::MessageID LEASE_CMDS_ADD4_CONFLICT
const isc::log::MessageID LEASE_CMDS_LEASES6_COMMITTED_CONFLICT
const isc::log::MessageID LEASE_CMDS_DEL4_FAILED
const isc::log::MessageID LEASE_CMDS_ADD6_FAILED
const isc::log::MessageID LEASE_CMDS_UPDATE4
const isc::log::MessageID LEASE_CMDS_DEL6_FAILED
An abstract API for lease database.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
Definition macros.h:32
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
Definition macros.h:20
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
Definition macros.h:26
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
Definition macros.h:14
const int CONTROL_RESULT_EMPTY
Status code indicating that the specified command was completed correctly, but failed to produce any ...
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
ConstElementPtr createAnswer()
Creates a standard config/command level success answer message (i.e.
const int CONTROL_RESULT_CONFLICT
Status code indicating that the command was unsuccessful due to a conflict between the command argume...
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
boost::shared_ptr< Lease4Collection > Lease4CollectionPtr
A shared pointer to the collection of IPv4 leases.
Definition lease.h:523
boost::shared_ptr< const SrvConfig > ConstSrvConfigPtr
Const pointer to the SrvConfig.
void queueNCR(const NameChangeType &chg_type, const Lease4Ptr &lease)
Creates name change request from the DHCPv4 lease.
boost::shared_ptr< const Subnet6 > ConstSubnet6Ptr
A const pointer to a Subnet6 object.
Definition subnet.h:623
boost::shared_ptr< const Subnet4 > ConstSubnet4Ptr
A const pointer to a Subnet4 object.
Definition subnet.h:458
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
Definition pkt4.h:555
boost::shared_ptr< DUID > DuidPtr
Definition duid.h:136
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
Definition lease.h:528
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
Definition lease.h:693
boost::multi_index_container< Subnet6Ptr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetSubnetIdIndexTag >, boost::multi_index::const_mem_fun< Subnet, SubnetID, &Subnet::getID > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetPrefixIndexTag >, boost::multi_index::const_mem_fun< Subnet, std::string, &Subnet::toText > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetModificationTimeIndexTag >, boost::multi_index::const_mem_fun< data::BaseStampedElement, boost::posix_time::ptime, &data::BaseStampedElement::getModificationTime > > > > Subnet6Collection
A collection of Subnet6 objects.
Definition subnet.h:937
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
Definition hwaddr.h:154
boost::shared_ptr< Pool > PoolPtr
a pointer to either IPv4 or IPv6 Pool
Definition pool.h:726
boost::multi_index_container< Subnet4Ptr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetSubnetIdIndexTag >, boost::multi_index::const_mem_fun< Subnet, SubnetID, &Subnet::getID > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetPrefixIndexTag >, boost::multi_index::const_mem_fun< Subnet, std::string, &Subnet::toText > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetServerIdIndexTag >, boost::multi_index::const_mem_fun< Network4, asiolink::IOAddress, &Network4::getServerId > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetModificationTimeIndexTag >, boost::multi_index::const_mem_fun< data::BaseStampedElement, boost::posix_time::ptime, &data::BaseStampedElement::getModificationTime > > > > Subnet4Collection
A collection of Subnet4 objects.
Definition subnet.h:866
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition subnet_id.h:25
boost::shared_ptr< ClientId > ClientIdPtr
Shared pointer to a Client ID.
Definition duid.h:216
@ DHCPACK
Definition dhcp4.h:239
boost::shared_ptr< const CfgSubnets4 > ConstCfgSubnets4Ptr
Const pointer.
boost::shared_ptr< const CfgSubnets6 > ConstCfgSubnets6Ptr
Const pointer.
boost::shared_ptr< Lease6Collection > Lease6CollectionPtr
A shared pointer to the collection of IPv6 leases.
Definition lease.h:696
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Definition pkt6.h:31
std::vector< Lease4Ptr > Lease4Collection
A collection of IPv4 leases.
Definition lease.h:520
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
Definition lease.h:315
const int LEASE_CMDS_DBG_COMMAND_DATA
Logging level used to log successful commands.
isc::log::Logger lease_cmds_logger("lease-cmds-hooks")
boost::shared_ptr< BindingVariableMgr > BindingVariableMgrPtr
Defines a shared pointer to a BindingVariableMgr.
Defines the logger used by the top-level component of kea-lfc.
Hardware type that represents information from DHCPv4 packet.
Definition hwaddr.h:20
static HWAddr fromText(const std::string &text, const uint16_t htype=HTYPE_ETHER)
Creates instance of the hardware address from textual format.
Definition hwaddr.cc:69
Structure that holds a lease for IPv6 address and/or prefix.
Definition lease.h:536
@ ACTION_UPDATE
update extended info tables.
Definition lease.h:576
a common structure for IPv4 and IPv6 leases
Definition lease.h:31
Type
Type of lease or pool.
Definition lease.h:46
@ TYPE_TA
the lease contains temporary IPv6 address
Definition lease.h:48
@ TYPE_PD
the lease contains IPv6 prefix (for prefix delegation)
Definition lease.h:49
@ TYPE_V4
IPv4 lease.
Definition lease.h:50
@ TYPE_NA
the lease contains non-temporary IPv6 address
Definition lease.h:47
static void syncCurrentExpirationTime(const Lease &from, Lease &to)
Sync lease current expiration time with new value from another lease, so that additional operations c...
Definition lease.cc:321
static std::string typeToText(Type type)
returns text representation of a lease type
Definition lease.cc:56