Kea 3.3.2
dhcp6_srv.cc
Go to the documentation of this file.
1// Copyright (C) 2011-2026 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>
8#include <kea_version.h>
9
10#include <asiolink/io_address.h>
11#include <asiolink/io_service.h>
13#include <cc/data.h>
16#include <dhcp/classify.h>
17#include <dhcp/dhcp6.h>
19#include <dhcp/duid.h>
20#include <dhcp/duid_factory.h>
21#include <dhcp/hwaddr.h>
22#include <dhcp/iface_mgr.h>
23#include <dhcp/libdhcp++.h>
25#include <dhcp/option.h>
27#include <dhcp/option6_ia.h>
28#include <dhcp/option6_iaaddr.h>
32#include <dhcp/option_vendor.h>
34#include <dhcp/pkt.h>
35#include <dhcp/pkt6.h>
38#include <dhcp6/dhcp6_log.h>
39#include <dhcp6/dhcp6_srv.h>
40#include <dhcp6/dhcp6to4_ipc.h>
41#include <dhcp_ddns/ncr_io.h>
42#include <dhcp_ddns/ncr_msg.h>
48#include <dhcpsrv/cfg_globals.h>
51#include <dhcpsrv/cfg_option.h>
53#include <dhcpsrv/cfg_rsoo.h>
55#include <dhcpsrv/cfgmgr.h>
59#include <dhcpsrv/host.h>
61#include <dhcpsrv/host_mgr.h>
62#include <dhcpsrv/lease.h>
67#include <dhcpsrv/pool.h>
70#include <dhcpsrv/srv_config.h>
71#include <dhcpsrv/subnet.h>
72#include <dhcpsrv/subnet_id.h>
74#include <dhcpsrv/utils.h>
75#include <eval/evaluate.h>
76#include <eval/token.h>
79#include <hooks/hooks_log.h>
80#include <hooks/hooks_manager.h>
81#include <hooks/parking_lots.h>
82#include <hooks/server_hooks.h>
84#include <log/log_dbglevels.h>
85#include <log/log_formatter.h>
86#include <log/logger.h>
87#include <log/macros.h>
88#include <stats/stats_mgr.h>
89#include <util/buffer.h>
91#include <util/optional.h>
92#include <util/pointer_util.h>
94#include <util/thread_pool.h>
95#include <util/triplet.h>
96#include <util/str.h>
97
98#include <algorithm>
99#include <cmath>
100#include <cstdint>
101#include <cstdlib>
102#include <exception>
103#include <functional>
104#include <iomanip>
105#include <limits>
106#include <list>
107#include <map>
108#include <memory>
109#include <set>
110#include <sstream>
111#include <string>
112#include <tuple>
113#include <utility>
114#include <vector>
115
116#include <boost/algorithm/string/erase.hpp>
117#include <boost/algorithm/string/join.hpp>
118#include <boost/algorithm/string/split.hpp>
119#include <boost/foreach.hpp>
120#include <boost/tokenizer.hpp>
121
122using namespace isc;
123using namespace isc::asiolink;
124using namespace isc::cryptolink;
125using namespace isc::data;
126using namespace isc::dhcp;
127using namespace isc::dhcp_ddns;
128using namespace isc::hooks;
129using namespace isc::log;
130using namespace isc::log::interprocess;
131using namespace isc::stats;
132using namespace isc::util;
133using namespace isc::util::str;
134using namespace std;
135namespace ph = std::placeholders;
136
137namespace {
138
140struct Dhcp6Hooks {
141 int hook_index_buffer6_receive_;
142 int hook_index_pkt6_receive_;
143 int hook_index_subnet6_select_;
144 int hook_index_leases6_committed_;
145 int hook_index_lease6_release_;
146 int hook_index_pkt6_send_;
147 int hook_index_buffer6_send_;
148 int hook_index_lease6_decline_;
149 int hook_index_host6_identifier_;
150 int hook_index_ddns6_update_;
151 int hook_index_addr6_register_;
152
154 Dhcp6Hooks() {
155 hook_index_buffer6_receive_ = HooksManager::registerHook("buffer6_receive");
156 hook_index_pkt6_receive_ = HooksManager::registerHook("pkt6_receive");
157 hook_index_subnet6_select_ = HooksManager::registerHook("subnet6_select");
158 hook_index_leases6_committed_ = HooksManager::registerHook("leases6_committed");
159 hook_index_lease6_release_ = HooksManager::registerHook("lease6_release");
160 hook_index_pkt6_send_ = HooksManager::registerHook("pkt6_send");
161 hook_index_buffer6_send_ = HooksManager::registerHook("buffer6_send");
162 hook_index_lease6_decline_ = HooksManager::registerHook("lease6_decline");
163 hook_index_host6_identifier_ = HooksManager::registerHook("host6_identifier");
164 hook_index_ddns6_update_ = HooksManager::registerHook("ddns6_update");
165 hook_index_addr6_register_ = HooksManager::registerHook("addr6_register");
166 }
167};
168
169// Declare a Hooks object. As this is outside any function or method, it
170// will be instantiated (and the constructor run) when the module is loaded.
171// As a result, the hook indexes will be defined before any method in this
172// module is called.
173Dhcp6Hooks Hooks;
174
187createStatusCode(const Pkt6& pkt, const uint16_t status_code,
188 const std::string& status_message) {
189 Option6StatusCodePtr option_status(new Option6StatusCode(status_code,
190 status_message));
192 .arg(pkt.getLabel())
193 .arg(option_status->dataToText());
194 return (option_status);
195}
196
212createStatusCode(const Pkt6& pkt, const Option6IA& ia, const uint16_t status_code,
213 const std::string& status_message) {
214 Option6StatusCodePtr option_status(new Option6StatusCode(status_code,
215 status_message));
217 .arg(pkt.getLabel())
218 .arg(ia.getIAID())
219 .arg(option_status->dataToText());
220 return (option_status);
221}
222
225std::set<std::string> dhcp6_statistics = {
226 "pkt6-received",
227 "pkt6-solicit-received",
228 "pkt6-advertise-received",
229 "pkt6-request-received",
230 "pkt6-reply-received",
231 "pkt6-renew-received",
232 "pkt6-rebind-received",
233 "pkt6-decline-received",
234 "pkt6-release-received",
235 "pkt6-infrequest-received",
236 "pkt6-lease-query-received",
237 "pkt6-dhcpv4-query-received",
238 "pkt6-dhcpv4-response-received",
239 "pkt6-addr-reg-inform-received",
240 "pkt6-addr-reg-reply-received",
241 "pkt6-unknown-received",
242 "pkt6-sent",
243 "pkt6-advertise-sent",
244 "pkt6-reply-sent",
245 "pkt6-lease-query-reply-sent",
246 "pkt6-dhcpv4-response-sent",
247 "pkt6-addr-reg-reply-sent",
248 "pkt6-service-disabled",
249 "pkt6-parse-failed",
250 "pkt6-queue-full",
251 "pkt6-duplicate",
252 "pkt6-rfc-violation",
253 "pkt6-admin-filtered",
254 "pkt6-not-for-us",
255 "pkt6-processing-failed",
256 "pkt6-limit-exceeded",
257 "pkt6-receive-drop",
258 "v6-allocation-fail",
259 "v6-allocation-fail-shared-network",
260 "v6-allocation-fail-subnet",
261 "v6-allocation-fail-no-pools",
262 "v6-allocation-fail-classes",
263 "v6-ia-na-lease-reuses",
264 "v6-ia-pd-lease-reuses",
265};
266
267} // namespace
268
269namespace isc {
270namespace dhcp {
271
272const std::string Dhcpv6Srv::VENDOR_CLASS_PREFIX("VENDOR_CLASS_");
273
274Dhcpv6Srv::Dhcpv6Srv(uint16_t server_port, uint16_t client_port)
275 : io_service_(new IOService()), server_port_(server_port),
276 client_port_(client_port), serverid_(), shutdown_(true),
281 .arg(server_port);
282
283 Dhcp6to4Ipc::instance().client_port = client_port;
284
285 // Initialize objects required for DHCP server operation.
286 try {
287 // Port 0 is used for testing purposes where in most cases we don't
288 // rely on the physical interfaces. Therefore, it should be possible
289 // to create an object even when there are no usable interfaces.
290 if ((server_port > 0) && (IfaceMgr::instance().countIfaces() == 0)) {
292 return;
293 }
294
295 // Create a DUID instance but do not store it into a file.
296 DUIDFactory duid_factory;
297 DuidPtr duid = duid_factory.get();
298 serverid_.reset(new Option(Option::V6, D6O_SERVERID, duid->getDuid()));
299
300 // Instantiate allocation engine. The number of allocation attempts equal
301 // to zero indicates that the allocation engine will use the number of
302 // attempts depending on the pool size.
303 alloc_engine_.reset(new AllocEngine(0));
304
306
307 } catch (const std::exception &e) {
309 return;
310 }
311
312 // Initializing all observations with default value
314
315 // All done, so can proceed
316 shutdown_ = false;
317}
318
320 StatsMgr& stats_mgr = StatsMgr::instance();
321
322 // Iterate over set of observed statistics
323 for (auto const& it : dhcp6_statistics) {
324 // Initialize them with default value 0
325 stats_mgr.setValue(it, static_cast<int64_t>(0));
326 }
327}
328
330 // Discard any parked packets
332
333 try {
334 stopD2();
335 } catch (const std::exception& ex) {
336 // Highly unlikely, but lets Report it but go on
338 }
339
340 try {
342 } catch (const std::exception& ex) {
343 // Highly unlikely, but lets Report it but go on
344 // LOG_ERROR(dhcp6_logger, DHCP6_SRV_DHCP4O6_ERROR).arg(ex.what());
345 }
346
348
349 // The lease manager was instantiated during DHCPv6Srv configuration,
350 // so we should clean up after ourselves.
352
353 // Destroy the host manager before hooks unload.
355
356 // Explicitly unload hooks
359 auto names = HooksManager::getLibraryNames();
360 std::string msg;
361 if (!names.empty()) {
362 msg = names[0];
363 for (size_t i = 1; i < names.size(); ++i) {
364 msg += std::string(", ") + names[i];
365 }
366 }
368 }
370 io_service_->stopAndPoll();
371}
372
377
379 return (IfaceMgr::instance().receive6(timeout));
380}
381
382void Dhcpv6Srv::sendPacket(const Pkt6Ptr& packet) {
383 IfaceMgr::instance().send(packet);
384}
385
386bool
392 OptionPtr server_id = pkt->getOption(D6O_SERVERID);
393 if (server_id){
394 // Let us test received ServerID if it is same as ServerID
395 // which is being used by server
396 if (getServerID()->getData() != server_id->getData()){
398 .arg(pkt->getLabel())
399 .arg(duidToString(server_id))
400 .arg(duidToString(getServerID()));
401 StatsMgr::instance().addValue("pkt6-not-for-us",
402 static_cast<int64_t>(1));
403 return (false);
404 }
405 }
406 // return True if: no serverid received or ServerIDs matching
407 return (true);
408}
409
410bool
412 if (pkt->relay_info_.empty() && !pkt->getLocalAddr().isV6Multicast()) {
414 .arg(pkt->getLabel())
415 .arg(pkt->getName());
416 StatsMgr::instance().addValue("pkt6-rfc-violation",
417 static_cast<int64_t>(1));
418 return (false);
419 }
420 return (true);
421}
422
423void
425 const ConstCfgHostOperationsPtr cfg =
426 CfgMgr::instance().getCurrentCfg()->getCfgHostOperations6();
427 for (auto const& id_type : cfg->getIdentifierTypes()) {
428 switch (id_type) {
429 case Host::IDENT_DUID:
430 if (ctx.duid_) {
431 ctx.addHostIdentifier(id_type, ctx.duid_->getDuid());
432 }
433 break;
434
436 if (ctx.hwaddr_ && !ctx.hwaddr_->hwaddr_.empty()) {
437 ctx.addHostIdentifier(id_type, ctx.hwaddr_->hwaddr_);
438 }
439 break;
440 case Host::IDENT_FLEX:
441 // At this point the information in the packet has been unpacked into
442 // the various packet fields and option objects has been created.
443 // Execute callouts registered for host6_identifier.
444 if (HooksManager::calloutsPresent(Hooks.hook_index_host6_identifier_)) {
445 CalloutHandlePtr callout_handle = getCalloutHandle(ctx.query_);
446
448 std::vector<uint8_t> id;
449
450 // Use the RAII wrapper to make sure that the callout handle state is
451 // reset when this object goes out of scope. All hook points must do
452 // it to prevent possible circular dependency between the callout
453 // handle and its arguments.
454 ScopedCalloutHandleState callout_handle_state(callout_handle);
455
456 // Pass incoming packet as argument
457 callout_handle->setArgument("query6", ctx.query_);
458 callout_handle->setArgument("id_type", type);
459 callout_handle->setArgument("id_value", id);
460
461 // Call callouts
462 HooksManager::callCallouts(Hooks.hook_index_host6_identifier_,
463 *callout_handle);
464
465 callout_handle->getArgument("id_type", type);
466 callout_handle->getArgument("id_value", id);
467
468 if ((callout_handle->getStatus() == CalloutHandle::NEXT_STEP_CONTINUE) &&
469 !id.empty()) {
470
472 .arg(ctx.query_->getLabel())
473 .arg(Host::getIdentifierAsText(type, &id[0], id.size()));
474
475 ctx.addHostIdentifier(type, id);
476 }
477 }
478 break;
479 default:
480 ;
481 }
482 }
483}
484
485void
488 // Pointer to client's query.
489 ctx.query_ = query;
490
491 // DUID.
492 ctx.duid_ = query->getClientId();
493
494 // Hardware address.
495 ctx.hwaddr_ = getMAC(query);
496}
497
498bool
501 // First part of context initialization.
502 initContext0(query, ctx);
503
504 // Get the early-global-reservations-lookup flag value.
507 if (egrl) {
508 ctx.early_global_reservations_lookup_ = egrl->boolValue();
509 }
510
511 // Perform early global reservations lookup when wanted.
513 // Get the host identifiers.
515
516 // Check for global host reservations.
517 ConstHostPtr global_host = alloc_engine_->findGlobalReservation(ctx);
518
519 if (global_host && !global_host->getClientClasses6().empty()) {
520 // Remove dependent evaluated classes.
522
523 // Add classes from the global reservations.
524 const ClientClasses& classes = global_host->getClientClasses6();
525 for (auto const& cclass : classes) {
526 query->addClass(cclass);
527 }
528
529 // Evaluate classes before KNOWN.
530 evaluateClasses(query, false);
531 }
532
533 if (global_host) {
534 // Add the KNOWN class;
535 query->addClass("KNOWN");
537 .arg(query->getLabel())
538 .arg("KNOWN");
539
540 // Evaluate classes after KNOWN.
541 evaluateClasses(query, true);
542
543 // Check the DROP special class.
544 if (query->inClass("DROP")) {
547 .arg(query->makeLabel(query->getClientId(), nullptr))
548 .arg(query->toText());
549 StatsMgr::instance().addValue("pkt6-admin-filtered",
550 static_cast<int64_t>(1));
551 StatsMgr::instance().addValue("pkt6-receive-drop",
552 static_cast<int64_t>(1));
553 return (false);
554 }
555
556 // Store the reservation.
557 ctx.hosts_[SUBNET_ID_GLOBAL] = global_host;
558 }
559 }
560
561 return (true);
562}
563
564void
566 // Sanity check.
567 if (!ctx.query_) {
568 drop = true;
569 return;
570 }
571 ctx.fwd_dns_update_ = false;
572 ctx.rev_dns_update_ = false;
573 ctx.hostname_ = "";
575
576 // Collect host identifiers if host reservations enabled. The identifiers
577 // are stored in order of preference. The server will use them in that
578 // order to search for host reservations.
580 if (ctx.subnet_) {
581 // Before we can check for static reservations, we need to prepare
582 // a set of identifiers to be used for this.
585 }
586
587 // Find host reservations using specified identifiers.
588 alloc_engine_->findReservation(ctx);
589
590 // Get shared network to see if it is set for a subnet.
591 ctx.subnet_->getSharedNetwork(sn);
592 }
593
594 // Global host reservations are independent of a selected subnet. If the
595 // global reservations contain client classes we should use them in case
596 // they are meant to affect pool selection. Also, if the subnet does not
597 // belong to a shared network we can use the reserved client classes
598 // because there is no way our subnet could change. Such classes may
599 // affect selection of a pool within the selected subnet.
600 auto global_host = ctx.globalHost();
601 auto current_host = ctx.currentHost();
603 global_host && !global_host->getClientClasses6().empty()) ||
604 (!sn && current_host && !current_host->getClientClasses6().empty())) {
605 // We have already evaluated client classes and some of them may
606 // be in conflict with the reserved classes. Suppose there are
607 // two classes defined in the server configuration: first_class
608 // and second_class and the test for the second_class it looks
609 // like this: "not member('first_class')". If the first_class
610 // initially evaluates to false, the second_class evaluates to
611 // true. If the first_class is now set within the hosts reservations
612 // and we don't remove the previously evaluated second_class we'd
613 // end up with both first_class and second_class evaluated to
614 // true. In order to avoid that, we have to remove the classes
615 // evaluated in the first pass and evaluate them again. As
616 // a result, the first_class set via the host reservation will
617 // replace the second_class because the second_class will this
618 // time evaluate to false as desired.
621 evaluateClasses(ctx.query_, false);
622 }
623
624 // Set KNOWN builtin class if something was found, UNKNOWN if not.
625 if (!ctx.hosts_.empty()) {
626 ctx.query_->addClass("KNOWN");
628 .arg(ctx.query_->getLabel())
629 .arg("KNOWN");
630 } else {
631 ctx.query_->addClass("UNKNOWN");
633 .arg(ctx.query_->getLabel())
634 .arg("UNKNOWN");
635 }
636
637 // Perform second pass of classification.
638 evaluateClasses(ctx.query_, true);
639
640 const ClientClasses& classes = ctx.query_->getClasses();
642 .arg(ctx.query_->getLabel())
643 .arg(classes.toText());
644
645 // Check the DROP special class.
646 if (ctx.query_->inClass("DROP")) {
648 .arg(ctx.query_->makeLabel(ctx.query_->getClientId(), 0))
649 .arg(ctx.query_->toText());
650 StatsMgr::instance().addValue("pkt6-admin-filtered",
651 static_cast<int64_t>(1));
652 StatsMgr::instance().addValue("pkt6-receive-drop",
653 static_cast<int64_t>(1));
654 drop = true;
655 }
656}
657
658int
660#ifdef HAVE_AFL
661 // Get the values of the environment variables used to control the
662 // fuzzing.
663
664 // Specfies the interface to be used to pass packets from AFL to Kea.
665 const char* interface = getenv("KEA_AFL_INTERFACE");
666 if (!interface) {
667 isc_throw(FuzzInitFail, "no fuzzing interface has been set");
668 }
669
670 // The address on the interface to be used.
671 const char* address = getenv("KEA_AFL_ADDRESS");
672 if (!address) {
673 isc_throw(FuzzInitFail, "no fuzzing address has been set");
674 }
675
676 // Set up structures needed for fuzzing.
677 PacketFuzzer fuzzer(server_port_, interface, address);
678
679 // The next line is needed as a signature for AFL to recognize that we are
680 // running persistent fuzzing. This has to be in the main image file.
681 while (__AFL_LOOP(fuzzer.maxLoopCount())) {
682 // Read from stdin and put the data read into an address/port on which
683 // Kea is listening, read for Kea to read it via asynchronous I/O.
684 fuzzer.transfer();
685#else
686 while (!shutdown_) {
687#endif // HAVE_AFL
688 try {
689 runOne();
690 // Handle events registered by hooks using external IOService objects.
692 getIOService()->poll();
693 } catch (const std::exception& e) {
694 // General catch-all standard exceptions that are not caught by more
695 // specific catches.
697 .arg(e.what());
698
699 } catch (...) {
700 // General catch-all non-standard exception that are not caught
701 // by more specific catches.
703 }
704 }
705
706 // Stop everything before we change into single-threaded mode.
708
709 // destroying the thread pool
710 MultiThreadingMgr::instance().apply(false, 0, 0);
711
712 return (getExitValue());
713}
714
715void
717 // client's message and server's response
718 Pkt6Ptr query;
719
720 try {
721 // Set select() timeout to 1s. This value should not be modified
722 // because it is important that the select() returns control
723 // frequently so as the IOService can be polled for ready handlers.
724 uint32_t timeout = 1;
725 query = receivePacket(timeout);
726
727 // Log if packet has arrived. We can't log the detailed information
728 // about the DHCP message because it hasn't been unpacked/parsed
729 // yet, and it can't be parsed at this point because hooks will
730 // have to process it first. The only information available at this
731 // point are: the interface, source address and destination addresses
732 // and ports.
733 if (query) {
735 .arg(query->getRemoteAddr().toText())
736 .arg(query->getRemotePort())
737 .arg(query->getLocalAddr().toText())
738 .arg(query->getLocalPort())
739 .arg(query->getIface());
740
741 // Log reception of the packet. We need to increase it early, as
742 // any failures in unpacking will cause the packet to be dropped.
743 // we will increase type specific packets further down the road.
744 // See processStatsReceived().
745 StatsMgr::instance().addValue("pkt6-received", static_cast<int64_t>(1));
746 }
747
748 // We used to log that the wait was interrupted, but this is no longer
749 // the case. Our wait time is 1s now, so the lack of query packet more
750 // likely means that nothing new appeared within a second, rather than
751 // we were interrupted. And we don't want to print a message every
752 // second.
753
754 } catch (const SignalInterruptOnSelect&) {
755 // Packet reception interrupted because a signal has been received.
756 // This is not an error because we might have received a SIGTERM,
757 // SIGINT, SIGHUP or SIGCHLD which are handled by the server. For
758 // signals that are not handled by the server we rely on the default
759 // behavior of the system.
761 } catch (const std::exception& e) {
763 .arg(e.what());
764 }
765
766 // Timeout may be reached or signal received, which breaks select()
767 // with no packet received
768 if (!query) {
769 return;
770 }
771
772 // If the DHCP service has been globally disabled, drop the packet.
773 if (!network_state_->isServiceEnabled()) {
775 .arg(query->getLabel());
776 // Increase the statistics of service disabled and dropped packets.
777 StatsMgr::instance().addValue("pkt6-service-disabled",
778 static_cast<int64_t>(1));
779 StatsMgr::instance().addValue("pkt6-receive-drop",
780 static_cast<int64_t>(1));
781 return;
782 } else {
783 if (MultiThreadingMgr::instance().getMode()) {
784 query->addPktEvent("mt_queued");
785 typedef function<void()> CallBack;
786 boost::shared_ptr<CallBack> call_back =
787 boost::make_shared<CallBack>(std::bind(&Dhcpv6Srv::processPacketAndSendResponseNoThrow,
788 this, query));
789 if (!MultiThreadingMgr::instance().getThreadPool().add(call_back)) {
791 StatsMgr::instance().addValue("pkt6-queue-full",
792 static_cast<int64_t>(1));
793 StatsMgr::instance().addValue("pkt6-receive-drop",
794 static_cast<int64_t>(1));
795 }
796 } else {
798 }
799 }
800}
801
802void
804 try {
806 } catch (const std::exception& e) {
808 .arg(query->getLabel())
809 .arg(e.what());
810 StatsMgr::instance().addValue("pkt6-processing-failed",
811 static_cast<int64_t>(1));
812 StatsMgr::instance().addValue("pkt6-receive-drop",
813 static_cast<int64_t>(1));
814 } catch (...) {
816 .arg(query->getLabel());
817 StatsMgr::instance().addValue("pkt6-processing-failed",
818 static_cast<int64_t>(1));
819 StatsMgr::instance().addValue("pkt6-receive-drop",
820 static_cast<int64_t>(1));
821 }
822}
823
824void
826 Pkt6Ptr rsp = processPacket(query);
827 if (!rsp) {
828 return;
829 }
830
831 CalloutHandlePtr callout_handle = getCalloutHandle(query);
832 processPacketBufferSend(callout_handle, rsp);
833}
834
837 query->addPktEvent("process_started");
838
839 // All packets belong to ALL.
840 query->addClass("ALL");
841
842 bool skip_unpack = false;
843
844 // The packet has just been received so contains the uninterpreted wire
845 // data; execute callouts registered for buffer6_receive.
846 if (HooksManager::calloutsPresent(Hooks.hook_index_buffer6_receive_)) {
847 CalloutHandlePtr callout_handle = getCalloutHandle(query);
848
849 // Use the RAII wrapper to make sure that the callout handle state is
850 // reset when this object goes out of scope. All hook points must do
851 // it to prevent possible circular dependency between the callout
852 // handle and its arguments.
853 ScopedCalloutHandleState callout_handle_state(callout_handle);
854
855 // Enable copying options from the packet within hook library.
856 ScopedEnableOptionsCopy<Pkt6> query6_options_copy(query);
857
858 // Pass incoming packet as argument
859 callout_handle->setArgument("query6", query);
860
861 // Call callouts
862 HooksManager::callCallouts(Hooks.hook_index_buffer6_receive_, *callout_handle);
863
864 // Callouts decided to skip the next processing step. The next
865 // processing step would be to parse the packet, so skip at this
866 // stage means that callouts did the parsing already, so server
867 // should skip parsing.
868 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) {
870 .arg(query->getRemoteAddr().toText())
871 .arg(query->getLocalAddr().toText())
872 .arg(query->getIface());
873 skip_unpack = true;
874 }
875
876 // Callouts decided to drop the received packet
877 // The response (rsp) is null so the caller (runOne) will
878 // immediately return too.
879 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP) {
881 .arg(query->getRemoteAddr().toText())
882 .arg(query->getLocalAddr().toText())
883 .arg(query->getIface());
884
885 // Not increasing the statistics of the dropped packets because it
886 // is the callouts' responsibility to increase it.
887 return (Pkt6Ptr());
888 }
889
890 callout_handle->getArgument("query6", query);
891 if (!query) {
892 // Please use the status instead of resetting query!
893 return (Pkt6Ptr());
894 }
895 }
896
897 // Unpack the packet information unless the buffer6_receive callouts
898 // indicated they did it
899 if (!skip_unpack) {
900 try {
902 .arg(query->getRemoteAddr().toText())
903 .arg(query->getLocalAddr().toText())
904 .arg(query->getIface());
905 query->unpack();
906 } catch (const SkipRemainingOptionsError& e) {
907 // An option failed to unpack but we are to attempt to process it
908 // anyway. Log it and let's hope for the best.
911 .arg(query->getLabel())
912 .arg(e.what());
913 } catch (const std::exception &e) {
914 // Failed to parse the packet.
916 .arg(query->getLabel())
917 .arg(query->getRemoteAddr().toText())
918 .arg(query->getLocalAddr().toText())
919 .arg(query->getIface())
920 .arg(e.what())
921 .arg(query->makeLabel(query->getClientId(), nullptr));
922
923 // Increase the statistics of parse failures and dropped packets.
924 StatsMgr::instance().addValue("pkt6-parse-failed",
925 static_cast<int64_t>(1));
926 StatsMgr::instance().addValue("pkt6-receive-drop",
927 static_cast<int64_t>(1));
928 return (Pkt6Ptr());
929 }
930 }
931
932 // Classify can emit INFO logs so help to track the query.
934 .arg(query->getLabel());
935
936 // Update statistics accordingly for received packet.
937 processStatsReceived(query);
938
939 // Check if received query carries server identifier matching
940 // server identifier being used by the server.
941 if (!testServerID(query)) {
942
943 // Increase the statistic of dropped packets.
944 // The drop cause statistic was increased by testServerID.
945 StatsMgr::instance().addValue("pkt6-receive-drop",
946 static_cast<int64_t>(1));
947 return (Pkt6Ptr());
948 }
949
950 // Check if the received query has been sent to unicast or multicast.
951 // All queries per RFC 9915 will be discarded if sent to unicast address.
952 if (!testUnicast(query)) {
953
954 // Increase the statistic of dropped packets.
955 StatsMgr::instance().addValue("pkt6-receive-drop",
956 static_cast<int64_t>(1));
957 return (Pkt6Ptr());
958 }
959
960 // Assign this packet to a class, if possible
961 classifyPacket(query);
962
964 .arg(query->getLabel())
965 .arg(query->getName())
966 .arg(static_cast<int>(query->getType()))
967 .arg(query->getRemoteAddr())
968 .arg(query->getLocalAddr())
969 .arg(query->getIface());
971 .arg(query->getLabel())
972 .arg(query->toText());
973
974 // At this point the information in the packet has been unpacked into
975 // the various packet fields and option objects has been created.
976 // Execute callouts registered for packet6_receive.
977 if (HooksManager::calloutsPresent(Hooks.hook_index_pkt6_receive_)) {
978 CalloutHandlePtr callout_handle = getCalloutHandle(query);
979
980 // Use the RAII wrapper to make sure that the callout handle state is
981 // reset when this object goes out of scope. All hook points must do
982 // it to prevent possible circular dependency between the callout
983 // handle and its arguments.
984 ScopedCalloutHandleState callout_handle_state(callout_handle);
985
986 // Enable copying options from the packet within hook library.
987 ScopedEnableOptionsCopy<Pkt6> query6_options_copy(query);
988
989 // Pass incoming packet as argument
990 callout_handle->setArgument("query6", query);
991
992 // Call callouts
993 HooksManager::callCallouts(Hooks.hook_index_pkt6_receive_, *callout_handle);
994
995 // Callouts decided to skip the next processing step. The next
996 // processing step would be to process the packet, so skip at this
997 // stage means drop.
998 if ((callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) ||
999 (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP)) {
1001 .arg(query->getLabel());
1002 // Not increasing the statistics of the dropped packets because it
1003 // is the callouts' responsibility to increase it.
1004 return (Pkt6Ptr());
1005 }
1006
1007 callout_handle->getArgument("query6", query);
1008 if (!query) {
1009 // Please use the status instead of resetting query!
1010 return (Pkt6Ptr());
1011 }
1012 }
1013
1014 // Reject the message if it doesn't pass the sanity check.
1015 // Statistics were updated by sanityCheck.
1016 if (!sanityCheck(query)) {
1017 return (Pkt6Ptr());
1018 }
1019
1020 // Check the DROP special class.
1021 if (query->inClass("DROP")) {
1023 .arg(query->makeLabel(query->getClientId(), nullptr))
1024 .arg(query->toText());
1025 StatsMgr::instance().addValue("pkt6-admin-filtered",
1026 static_cast<int64_t>(1));
1027 StatsMgr::instance().addValue("pkt6-receive-drop",
1028 static_cast<int64_t>(1));
1029 return (Pkt6Ptr());
1030 }
1031
1032 return (processDhcp6Query(query));
1033}
1034
1035void
1037 try {
1038 Pkt6Ptr rsp = processDhcp6Query(query);
1039 if (!rsp) {
1040 return;
1041 }
1042
1043 CalloutHandlePtr callout_handle = getCalloutHandle(query);
1044 processPacketBufferSend(callout_handle, rsp);
1045 } catch (const std::exception& e) {
1047 .arg(query->getLabel())
1048 .arg(e.what());
1049 StatsMgr::instance().addValue("pkt6-processing-failed",
1050 static_cast<int64_t>(1));
1051 StatsMgr::instance().addValue("pkt6-receive-drop",
1052 static_cast<int64_t>(1));
1053 } catch (...) {
1055 .arg(query->getLabel());
1056 StatsMgr::instance().addValue("pkt6-processing-failed",
1057 static_cast<int64_t>(1));
1058 StatsMgr::instance().addValue("pkt6-receive-drop",
1059 static_cast<int64_t>(1));
1060 }
1061}
1062
1063Pkt6Ptr
1065 // Create a client race avoidance RAII handler.
1066 ClientHandler client_handler;
1067
1068 // Check for lease modifier queries from the same client being processed.
1069 if (MultiThreadingMgr::instance().getMode() &&
1070 ((query->getType() == DHCPV6_SOLICIT) ||
1071 (query->getType() == DHCPV6_REQUEST) ||
1072 (query->getType() == DHCPV6_RENEW) ||
1073 (query->getType() == DHCPV6_REBIND) ||
1074 (query->getType() == DHCPV6_RELEASE) ||
1075 (query->getType() == DHCPV6_DECLINE) ||
1076 (query->getType() == DHCPV6_ADDR_REG_INFORM))) {
1077 ContinuationPtr cont =
1079 this, query));
1080 if (!client_handler.tryLock(query, cont)) {
1081 return (Pkt6Ptr());
1082 }
1083 }
1084
1085 // Let's create a simplified client context here.
1087 if (!earlyGHRLookup(query, ctx)) {
1088 return (Pkt6Ptr());
1089 }
1090
1091 if (query->getType() == DHCPV6_DHCPV4_QUERY) {
1092 // This call never throws. Should this change, this section must be
1093 // enclosed in try-catch.
1094 processDhcp4Query(query);
1095 return (Pkt6Ptr());
1096 }
1097
1098 // Complete the client context initialization.
1099 bool drop = false;
1100 ctx.subnet_ = selectSubnet(query, drop);
1101 if (drop) {
1102 // Caller will immediately drop the packet so simply return now.
1103 return (Pkt6Ptr());
1104 }
1105
1106 return (processLocalizedQuery6(ctx));
1107}
1108
1109void
1112 try {
1114 if (!rsp) {
1115 return;
1116 }
1117
1118 CalloutHandlePtr callout_handle = getCalloutHandle(query);
1119 processPacketBufferSend(callout_handle, rsp);
1120 } catch (const std::exception& e) {
1122 .arg(query->getLabel())
1123 .arg(e.what());
1124 StatsMgr::instance().addValue("pkt6-processing-failed",
1125 static_cast<int64_t>(1));
1126 StatsMgr::instance().addValue("pkt6-receive-drop",
1127 static_cast<int64_t>(1));
1128 } catch (...) {
1130 .arg(query->getLabel());
1131 StatsMgr::instance().addValue("pkt6-processing-failed",
1132 static_cast<int64_t>(1));
1133 StatsMgr::instance().addValue("pkt6-receive-drop",
1134 static_cast<int64_t>(1));
1135 }
1136}
1137
1138void
1140 // Initialize context.
1142 initContext0(query, ctx);
1143
1144 // Subnet is cached in the callout context associated to the query.
1145 try {
1146 CalloutHandlePtr callout_handle = getCalloutHandle(query);
1147 callout_handle->getContext("subnet6", ctx.subnet_);
1148 } catch (const Exception&) {
1149 // No subnet, leave it to null...
1150 }
1151
1153}
1154
1155Pkt6Ptr
1157 Pkt6Ptr query = ctx.query_;
1158 bool drop = false;
1159 initContext(ctx, drop);
1160 // Stop here if initContext decided to drop the packet.
1161 if (drop) {
1162 return (Pkt6Ptr());
1163 }
1164
1165 Pkt6Ptr rsp;
1166 // The only expected exception is RFCViolation.
1167 bool rfc_violation = false;
1168 try {
1169 try {
1170 switch (query->getType()) {
1171 case DHCPV6_SOLICIT:
1172 rsp = processSolicit(ctx);
1173 break;
1174
1175 case DHCPV6_REQUEST:
1176 rsp = processRequest(ctx);
1177 break;
1178
1179 case DHCPV6_RENEW:
1180 rsp = processRenew(ctx);
1181 break;
1182
1183 case DHCPV6_REBIND:
1184 rsp = processRebind(ctx);
1185 break;
1186
1187 case DHCPV6_CONFIRM:
1188 rsp = processConfirm(ctx);
1189 break;
1190
1191 case DHCPV6_RELEASE:
1192 rsp = processRelease(ctx);
1193 break;
1194
1195 case DHCPV6_DECLINE:
1196 rsp = processDecline(ctx);
1197 break;
1198
1200 rsp = processInfRequest(ctx);
1201 break;
1202
1204 rsp = processAddrRegInform(ctx);
1205 break;
1206
1207 default:
1208 return (rsp);
1209 }
1210 } catch (const RFCViolation&) {
1211 rfc_violation = true;
1212 throw;
1213 }
1214 } catch (const std::exception& e) {
1215
1216 // Catch-all exception (at least for ones based on the isc Exception
1217 // class, which covers more or less all that are explicitly raised
1218 // in the Kea code), but also the standard one, which may possibly be
1219 // thrown from boost code. Just log the problem and ignore the packet.
1220 // (The problem is logged as a debug message because debug is
1221 // disabled by default - it prevents a DDOS attack based on the
1222 // sending of problem packets.)
1224 .arg(query->getLabel())
1225 .arg(query->getName())
1226 .arg(query->getRemoteAddr().toText())
1227 .arg(e.what());
1228
1229 // Increase the statistic of dropped packets.
1230 // The RFCViolation thrower updated the drop cause statistic.
1231 if (!rfc_violation) {
1232 StatsMgr::instance().addValue("pkt6-processing-failed",
1233 static_cast<int64_t>(1));
1234 }
1235 StatsMgr::instance().addValue("pkt6-receive-drop",
1236 static_cast<int64_t>(1));
1237 return (Pkt6Ptr());
1238 }
1239
1240 if (!rsp) {
1241 return (rsp);
1242 }
1243
1244 // Process relay-supplied options. It is important to call this very
1245 // late in the process, because we now have all the options the
1246 // server wanted to send already set. This is important, because
1247 // RFC6422, section 6 states:
1248 //
1249 // The server SHOULD discard any options that appear in the RSOO
1250 // for which it already has one or more candidates.
1251 //
1252 // So we ignore any RSOO options if there's an option with the same
1253 // code already present.
1254 processRSOO(query, rsp);
1255
1256 rsp->setRemoteAddr(query->getRemoteAddr());
1257 rsp->setLocalAddr(query->getLocalAddr());
1258
1259 if (client_port_) {
1260 // A command line option enforces a specific client port
1261 rsp->setRemotePort(client_port_);
1262 } else if (rsp->relay_info_.empty()) {
1263 // Direct traffic, send back to the client directly
1264 rsp->setRemotePort(DHCP6_CLIENT_PORT);
1265 } else {
1266 // Relayed traffic, send back to the relay agent
1267 uint16_t relay_port = checkRelaySourcePort(query);
1268 rsp->setRemotePort(relay_port ? relay_port : DHCP6_SERVER_PORT);
1269 }
1270
1271 if (server_port_) {
1272 rsp->setLocalPort(server_port_);
1273 } else {
1274 rsp->setLocalPort(DHCP6_SERVER_PORT);
1275 }
1276 rsp->setIndex(query->getIndex());
1277 rsp->setIface(query->getIface());
1278
1279 CalloutHandlePtr callout_handle = getCalloutHandle(query);
1280 if (!ctx.fake_allocation_ && (ctx.query_->getType() != DHCPV6_CONFIRM) &&
1281 (ctx.query_->getType() != DHCPV6_INFORMATION_REQUEST) &&
1282 HooksManager::calloutsPresent(Hooks.hook_index_leases6_committed_)) {
1283 // The ScopedCalloutHandleState class which guarantees that the task
1284 // is added to the thread pool after the response is reset (if needed)
1285 // and CalloutHandle state is reset. In ST it does nothing.
1286 // A smart pointer is used to store the ScopedCalloutHandleState so that
1287 // a copy of the pointer is created by the lambda and only on the
1288 // destruction of the last reference the task is added.
1289 // In MT there are 2 cases:
1290 // 1. packet is unparked before current thread smart pointer to
1291 // ScopedCalloutHandleState is destroyed:
1292 // - the lambda uses the smart pointer to set the callout which adds the
1293 // task, but the task is added after ScopedCalloutHandleState is
1294 // destroyed, on the destruction of the last reference which is held
1295 // by the current thread.
1296 // 2. packet is unparked after the current thread smart pointer to
1297 // ScopedCalloutHandleState is destroyed:
1298 // - the current thread reference to ScopedCalloutHandleState is
1299 // destroyed, but the reference in the lambda keeps it alive until
1300 // the lambda is called and the last reference is released, at which
1301 // time the task is actually added.
1302 // Use the RAII wrapper to make sure that the callout handle state is
1303 // reset when this object goes out of scope. All hook points must do
1304 // it to prevent possible circular dependency between the callout
1305 // handle and its arguments.
1306 std::shared_ptr<ScopedCalloutHandleState> callout_handle_state =
1307 std::make_shared<ScopedCalloutHandleState>(callout_handle);
1308
1309 ScopedEnableOptionsCopy<Pkt6> query6_options_copy(query);
1310
1311 // Also pass the corresponding query packet as argument
1312 callout_handle->setArgument("query6", query);
1313
1314 // Pass the response packet as an argument.
1315 ScopedEnableOptionsCopy<Pkt6> rsp6_options_copy(rsp);
1316 callout_handle->setArgument("response6", rsp);
1317
1318 Lease6CollectionPtr new_leases(new Lease6Collection());
1319 if (!ctx.new_leases_.empty()) {
1320 // Filter out reused leases as they were not committed.
1321 for (auto const& new_lease : ctx.new_leases_) {
1322 if (new_lease->reuseable_valid_lft_ == 0) {
1323 new_leases->push_back(new_lease);
1324 }
1325 }
1326 }
1327 callout_handle->setArgument("leases6", new_leases);
1328
1329 Lease6CollectionPtr deleted_leases(new Lease6Collection());
1330
1331 // Do per IA lists
1332 for (auto const& iac : ctx.ias_) {
1333 if (!iac.old_leases_.empty()) {
1334 for (auto const& old_lease : iac.old_leases_) {
1335 if (ctx.new_leases_.empty()) {
1336 deleted_leases->push_back(old_lease);
1337 continue;
1338 }
1339 bool in_new = false;
1340 for (auto const& new_lease : ctx.new_leases_) {
1341 if ((new_lease->addr_ == old_lease->addr_) &&
1342 ((new_lease->type_ != Lease::TYPE_PD) ||
1343 (new_lease->prefixlen_ == old_lease->prefixlen_))) {
1344 in_new = true;
1345 break;
1346 }
1347 }
1348 if (!in_new) {
1349 deleted_leases->push_back(old_lease);
1350 }
1351 }
1352 }
1353 }
1354 callout_handle->setArgument("deleted_leases6", deleted_leases);
1355
1356 // Get the parking limit. Parsing should ensure the value is present.
1357 uint32_t parked_packet_limit = 0;
1359 getConfiguredGlobal(CfgGlobals::PARKED_PACKET_LIMIT);
1360 if (ppl) {
1361 parked_packet_limit = ppl->intValue();
1362 }
1363
1364 if (parked_packet_limit) {
1365 auto const& parking_lot = ServerHooks::getServerHooks().
1366 getParkingLotPtr("leases6_committed");
1367 if (parking_lot && (parking_lot->size() >= parked_packet_limit)) {
1368 // We can't park it so we're going to throw it on the floor.
1371 .arg(parked_packet_limit)
1372 .arg(query->getLabel());
1373 StatsMgr::instance().addValue("pkt6-queue-full",
1374 static_cast<int64_t>(1));
1375 StatsMgr::instance().addValue("pkt6-receive-drop",
1376 static_cast<int64_t>(1));
1377 rsp.reset();
1378 return (rsp);
1379 }
1380 }
1381
1382 // We proactively park the packet. We'll unpark it without invoking
1383 // the callback (i.e. drop) unless the callout status is set to
1384 // NEXT_STEP_PARK. Otherwise the callback we bind here will be
1385 // executed when the hook library unparks the packet.
1386 ConstSubnet6Ptr subnet = ctx.subnet_;
1387 HooksManager::park("leases6_committed", query,
1388 [this, callout_handle, query, rsp, callout_handle_state, subnet]() mutable {
1389 if (MultiThreadingMgr::instance().getMode()) {
1390 typedef function<void()> CallBack;
1391 boost::shared_ptr<CallBack> call_back =
1392 boost::make_shared<CallBack>(std::bind(&Dhcpv6Srv::sendResponseNoThrow,
1393 this, callout_handle, query, rsp, subnet));
1394 callout_handle_state->on_completion_ = [call_back]() {
1396 };
1397 } else {
1398 processPacketPktSend(callout_handle, query, rsp, subnet);
1399 processPacketBufferSend(callout_handle, rsp);
1400 }
1401 });
1402
1403 try {
1404 // Call all installed callouts
1405 HooksManager::callCallouts(Hooks.hook_index_leases6_committed_,
1406 *callout_handle);
1407 } catch (...) {
1408 // Make sure we don't orphan a parked packet.
1409 HooksManager::drop("leases6_committed", query);
1410 throw;
1411 }
1412
1413 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_PARK) {
1415 .arg(query->getLabel());
1416 // Since the hook library(ies) are going to do the unparking, then
1417 // reset the pointer to the response to indicate to the caller that
1418 // it should return, as the packet processing will continue via
1419 // the callback.
1420 rsp.reset();
1421 } else {
1422 // Drop the park job on the packet, it isn't needed.
1423 HooksManager::drop("leases6_committed", query);
1424 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP) {
1426 .arg(query->getLabel());
1427 rsp.reset();
1428 }
1429 }
1430 }
1431
1432 // If we have a response prep it for shipment.
1433 if (rsp) {
1434 processPacketPktSend(callout_handle, query, rsp, ctx.subnet_);
1435 }
1436
1437 return (rsp);
1438}
1439
1440void
1442 Pkt6Ptr query, Pkt6Ptr& rsp,
1443 ConstSubnet6Ptr& subnet) {
1444 try {
1445 processPacketPktSend(callout_handle, query, rsp, subnet);
1446 processPacketBufferSend(callout_handle, rsp);
1447 } catch (const std::exception& e) {
1449 .arg(query->getLabel())
1450 .arg(e.what());
1451 } catch (...) {
1453 .arg(query->getLabel());
1454 }
1455}
1456
1457void
1459 Pkt6Ptr& query, Pkt6Ptr& rsp,
1460 ConstSubnet6Ptr& subnet) {
1461 query->addPktEvent("process_completed");
1462 if (!rsp) {
1463 return;
1464 }
1465
1466 // Specifies if server should do the packing
1467 bool skip_pack = false;
1468
1469 // Server's reply packet now has all options and fields set.
1470 // Options are represented by individual objects, but the
1471 // output wire data has not been prepared yet.
1472 // Execute all callouts registered for packet6_send
1473 if (HooksManager::calloutsPresent(Hooks.hook_index_pkt6_send_)) {
1474
1475 // Use the RAII wrapper to make sure that the callout handle state is
1476 // reset when this object goes out of scope. All hook points must do
1477 // it to prevent possible circular dependency between the callout
1478 // handle and its arguments.
1479 ScopedCalloutHandleState callout_handle_state(callout_handle);
1480
1481 // Enable copying options from the packets within hook library.
1482 ScopedEnableOptionsCopy<Pkt6> query_resp_options_copy(query, rsp);
1483
1484 // Pass incoming packet as argument
1485 callout_handle->setArgument("query6", query);
1486
1487 // Set our response
1488 callout_handle->setArgument("response6", rsp);
1489
1490 // Pass the selected subnet as an argument.
1491 callout_handle->setArgument("subnet6", subnet);
1492
1493 // Call all installed callouts
1494 HooksManager::callCallouts(Hooks.hook_index_pkt6_send_, *callout_handle);
1495
1496 // Callouts decided to skip the next processing step. The next
1497 // processing step would be to pack the packet (create wire data).
1498 // That step will be skipped if any callout sets skip flag.
1499 // It essentially means that the callout already did packing,
1500 // so the server does not have to do it again.
1501 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) {
1503 .arg(rsp->getLabel());
1504 skip_pack = true;
1505 }
1506
1508 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP) {
1510 .arg(rsp->getLabel());
1511 rsp.reset();
1512 return;
1513 }
1514 }
1515
1516 if (!skip_pack) {
1517 try {
1518 LibDHCP::splitNtpServerOptions6(rsp->options_);
1519 rsp->pack();
1520 } catch (const std::exception& e) {
1522 .arg(query->getLabel())
1523 .arg(e.what());
1524 return;
1525 }
1526
1527 }
1528}
1529
1530void
1532 Pkt6Ptr& rsp) {
1533 if (!rsp) {
1534 return;
1535 }
1536
1537 try {
1538 // Now all fields and options are constructed into output wire buffer.
1539 // Option objects modification does not make sense anymore. Hooks
1540 // can only manipulate wire buffer at this stage.
1541 // Let's execute all callouts registered for buffer6_send
1542 if (HooksManager::calloutsPresent(Hooks.hook_index_buffer6_send_)) {
1543
1544 // Use the RAII wrapper to make sure that the callout handle state is
1545 // reset when this object goes out of scope. All hook points must do
1546 // it to prevent possible circular dependency between the callout
1547 // handle and its arguments.
1548 ScopedCalloutHandleState callout_handle_state(callout_handle);
1549
1550 // Enable copying options from the packet within hook library.
1551 ScopedEnableOptionsCopy<Pkt6> response6_options_copy(rsp);
1552
1553 // Pass incoming packet as argument
1554 callout_handle->setArgument("response6", rsp);
1555
1556 // Call callouts
1557 HooksManager::callCallouts(Hooks.hook_index_buffer6_send_,
1558 *callout_handle);
1559
1560 // Callouts decided to skip the next processing step. The next
1561 // processing step would be to parse the packet, so skip at this
1562 // stage means drop.
1563 if ((callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) ||
1564 (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP)) {
1567 .arg(rsp->getLabel());
1568 return;
1569 }
1570
1571 callout_handle->getArgument("response6", rsp);
1572 }
1573
1575 .arg(rsp->getLabel())
1576 .arg(rsp->getName())
1577 .arg(static_cast<int>(rsp->getType()))
1578 .arg(rsp->getLocalAddr().isV6Zero() ? "*" : rsp->getLocalAddr().toText())
1579 .arg(rsp->getLocalPort())
1580 .arg(rsp->getRemoteAddr())
1581 .arg(rsp->getRemotePort())
1582 .arg(rsp->getIface());
1583
1585 .arg(rsp->getLabel())
1586 .arg(rsp->getName())
1587 .arg(static_cast<int>(rsp->getType()))
1588 .arg(rsp->toText());
1589 sendPacket(rsp);
1590
1591 // Update statistics accordingly for sent packet.
1592 processStatsSent(rsp);
1593
1594 } catch (const std::exception& e) {
1596 .arg(rsp->getLabel())
1597 .arg(e.what());
1598 }
1599}
1600
1601std::string
1603 if (!opt) {
1604 return ("<NULL>");
1605 }
1606 return (dumpAsHex(opt->getData()));
1607}
1608
1609void
1611 // Add client-id.
1612 OptionPtr clientid = question->getOption(D6O_CLIENTID);
1613 if (clientid) {
1614 answer->addOption(clientid);
1615 }
1617
1618 // If this is a relayed message, we need to copy relay information
1619 if (!question->relay_info_.empty()) {
1620 answer->copyRelayInfo(question);
1621 }
1622
1623}
1624
1625void
1627 const CfgOptionList&) {
1628 // add server-id
1629 answer->addOption(getServerID());
1630}
1631
1632void
1635 CfgOptionList& co_list) {
1636 // Firstly, host specific options.
1637 if (ctx.currentHost() && !ctx.currentHost()->getCfgOption6()->empty()) {
1638 co_list.push_back(ctx.currentHost()->getCfgOption6());
1639 }
1640
1641 // Secondly, pool specific options. Pools are defined within a subnet, so
1642 // if there is no subnet, there is nothing to do.
1643 if (ctx.subnet_) {
1644 for (auto const& resource : ctx.allocated_resources_) {
1645 PoolPtr pool =
1646 ctx.subnet_->getPool(resource.getPrefixLength() == 128 ?
1648 resource.getAddress(),
1649 false);
1650 if (pool && !pool->getCfgOption()->empty()) {
1651 co_list.push_back(pool->getCfgOption());
1652 }
1653 }
1654
1655 // Thirdly, subnet configured options.
1656 if (!ctx.subnet_->getCfgOption()->empty()) {
1657 co_list.push_back(ctx.subnet_->getCfgOption());
1658 }
1659
1660 // Fourthly, shared network specific options.
1661 SharedNetwork6Ptr network;
1662 ctx.subnet_->getSharedNetwork(network);
1663 if (network && !network->getCfgOption()->empty()) {
1664 co_list.push_back(network->getCfgOption());
1665 }
1666 }
1667
1668 // Each class in the incoming packet
1669 const ClientClasses& classes = question->getClasses();
1670 for (auto const& cclass : classes) {
1671 // Find the client class definition for this class
1673 getClientClassDictionary()->findClass(cclass);
1674 if (!ccdef) {
1675 // Not found: the class is built-in or not configured
1676 if (!isClientClassBuiltIn(cclass)) {
1678 .arg(question->getLabel())
1679 .arg(cclass);
1680 }
1681 // Skip it
1682 continue;
1683 }
1684
1685 if (ccdef->getCfgOption()->empty()) {
1686 // Skip classes which don't configure options
1687 continue;
1688 }
1689
1690 co_list.push_back(ccdef->getCfgOption());
1691 }
1692
1693 // Last global options
1694 if (!CfgMgr::instance().getCurrentCfg()->getCfgOption()->empty()) {
1695 co_list.push_back(CfgMgr::instance().getCurrentCfg()->getCfgOption());
1696 }
1697}
1698
1699void
1701 const CfgOptionList& co_list) {
1702 // Unlikely short cut
1703 if (co_list.empty()) {
1704 return;
1705 }
1706
1707 set<uint16_t> requested_opts;
1708
1709 // Client requests some options using ORO option. Try to
1710 // get this option from client's message.
1711 OptionUint16ArrayPtr option_oro = boost::dynamic_pointer_cast<
1712 OptionUint16Array>(question->getOption(D6O_ORO));
1713
1714 // Get the list of options that client requested.
1715 if (option_oro) {
1716 for (uint16_t code : option_oro->getValues()) {
1717 static_cast<void>(requested_opts.insert(code));
1718 }
1719 }
1720
1721 set<uint16_t> cancelled_opts;
1722
1723 // Iterate on the configured option list to add persistent and
1724 // cancelled options.
1725 for (auto const& copts : co_list) {
1726 const OptionContainerPtr& opts = copts->getAll(DHCP6_OPTION_SPACE);
1727 if (!opts) {
1728 continue;
1729 }
1730 // Get persistent options.
1731 const OptionContainerPersistIndex& pidx = opts->get<2>();
1732 const OptionContainerPersistRange& prange = pidx.equal_range(true);
1733 BOOST_FOREACH(auto const& desc, prange) {
1734 // Add the persistent option code to requested options.
1735 if (desc.option_) {
1736 uint16_t code = desc.option_->getType();
1737 static_cast<void>(requested_opts.insert(code));
1738 }
1739 }
1740 // Get cancelled options.
1741 const OptionContainerCancelIndex& cidx = opts->get<5>();
1742 const OptionContainerCancelRange& crange = cidx.equal_range(true);
1743 BOOST_FOREACH(auto const& desc, crange) {
1744 // Add the cancelled option code to the cancelled options.
1745 if (desc.option_) {
1746 uint16_t code = desc.option_->getType();
1747 static_cast<void>(cancelled_opts.insert(code));
1748 }
1749 }
1750 }
1751
1752 const auto& cclasses = question->getClasses();
1753 // For each requested option code get the first instance of the option
1754 // to be returned to the client.
1755 for (uint16_t opt : requested_opts) {
1756 // Skip if cancelled.
1757 if (cancelled_opts.count(opt) > 0) {
1758 continue;
1759 }
1760 // Add nothing when it is already there.
1761 // Skip special cases: D6O_VENDOR_OPTS
1762 if (opt == D6O_VENDOR_OPTS) {
1763 continue;
1764 }
1765 if (!answer->getOption(opt)) {
1766 // Iterate on the configured option list
1767 for (auto const& copts : co_list) {
1769 opt, cclasses);
1770 // Got it: add it and jump to the outer loop.
1771 if (desc.option_) {
1772 if (opt == D6O_UNICAST) {
1774 .arg(answer->getLabel());
1775 }
1776 answer->addOption(desc.option_);
1777 break;
1778 }
1779 }
1780 }
1781 }
1782
1783 // Special cases for vendor class and options which are identified
1784 // by the code/type and the vendor/enterprise id vs. the code/type only.
1785 if ((requested_opts.count(D6O_VENDOR_CLASS) > 0) &&
1786 (cancelled_opts.count(D6O_VENDOR_CLASS) == 0)) {
1787 // Keep vendor ids which are already in the response to insert
1788 // D6O_VENDOR_CLASS options at most once per vendor.
1789 set<uint32_t> vendor_ids;
1790 // Get what already exists in the response.
1791 for (auto const& opt : answer->getOptions(D6O_VENDOR_CLASS)) {
1792 OptionVendorClassPtr vendor_class;
1793 vendor_class = boost::dynamic_pointer_cast<OptionVendorClass>(opt.second);
1794 if (vendor_class) {
1795 uint32_t vendor_id = vendor_class->getVendorId();
1796 static_cast<void>(vendor_ids.insert(vendor_id));
1797 }
1798 }
1799 // Iterate on the configured option list.
1800 for (auto const& copts : co_list) {
1801 for (auto const& desc : copts->getList(DHCP6_OPTION_SPACE, D6O_VENDOR_CLASS)) {
1802 // Empty or not allowed, skip i.
1803 if (!desc.option_ || !desc.allowedForClientClasses(cclasses)) {
1804 continue;
1805 }
1806 OptionVendorClassPtr vendor_class =
1807 boost::dynamic_pointer_cast<OptionVendorClass>(desc.option_);
1808 if (!vendor_class) {
1809 continue;
1810 }
1811 // Is the vendor id already in the response?
1812 uint32_t vendor_id = vendor_class->getVendorId();
1813 if (vendor_ids.count(vendor_id) > 0) {
1814 continue;
1815 }
1816 // Got it: add it.
1817 answer->addOption(desc.option_);
1818 static_cast<void>(vendor_ids.insert(vendor_id));
1819 }
1820 }
1821 }
1822
1823 if ((requested_opts.count(D6O_VENDOR_OPTS) > 0) &&
1824 (cancelled_opts.count(D6O_VENDOR_OPTS) == 0)) {
1825 // Keep vendor ids which are already in the response to insert
1826 // D6O_VENDOR_OPTS options at most once per vendor.
1827 set<uint32_t> vendor_ids;
1828 // Get what already exists in the response.
1829 for (auto const& opt : answer->getOptions(D6O_VENDOR_OPTS)) {
1830 OptionVendorPtr vendor_opts;
1831 vendor_opts = boost::dynamic_pointer_cast<OptionVendor>(opt.second);
1832 if (vendor_opts) {
1833 uint32_t vendor_id = vendor_opts->getVendorId();
1834 static_cast<void>(vendor_ids.insert(vendor_id));
1835 }
1836 }
1837 // Iterate on the configured option list
1838 for (auto const& copts : co_list) {
1839 for (auto const& desc : copts->getList(DHCP6_OPTION_SPACE, D6O_VENDOR_OPTS)) {
1840 // Empty or not allowed, skip it.
1841 if (!desc.option_ || !desc.allowedForClientClasses(cclasses)) {
1842 continue;
1843 }
1844 OptionVendorPtr vendor_opts =
1845 boost::dynamic_pointer_cast<OptionVendor>(desc.option_);
1846 if (!vendor_opts) {
1847 continue;
1848 }
1849 // Is the vendor id already in the response?
1850 uint32_t vendor_id = vendor_opts->getVendorId();
1851 if (vendor_ids.count(vendor_id) > 0) {
1852 continue;
1853 }
1854 // Append a fresh vendor option as the next method should
1855 // add suboptions to it.
1856 vendor_opts.reset(new OptionVendor(Option::V6, vendor_id));
1857 answer->addOption(vendor_opts);
1858 static_cast<void>(vendor_ids.insert(vendor_id));
1859 }
1860 }
1861 }
1862}
1863
1864void
1866 Pkt6Ptr& answer,
1868 const CfgOptionList& co_list) {
1869
1870 // Leave if there is no subnet matching the incoming packet.
1871 // There is no need to log the error message here because
1872 // it will be logged in the assignLease() when it fails to
1873 // pick the suitable subnet. We don't want to duplicate
1874 // error messages in such case.
1875 //
1876 // Also, if there's no options to possibly assign, give up.
1877 if (!ctx.subnet_ || co_list.empty()) {
1878 return;
1879 }
1880
1881 set<uint32_t> vendor_ids;
1882
1883 // The server could have provided the option using client classification or
1884 // hooks. If there're vendor info options in the response already, use them.
1885 map<uint32_t, OptionVendorPtr> vendor_rsps;
1886 for (auto const& opt : answer->getOptions(D6O_VENDOR_OPTS)) {
1887 OptionVendorPtr vendor_rsp;
1888 vendor_rsp = boost::dynamic_pointer_cast<OptionVendor>(opt.second);
1889 if (vendor_rsp) {
1890 uint32_t vendor_id = vendor_rsp->getVendorId();
1891 vendor_rsps[vendor_id] = vendor_rsp;
1892 static_cast<void>(vendor_ids.insert(vendor_id));
1893 }
1894 }
1895
1896 // Next, try to get the vendor-id from the client packet's
1897 // vendor-specific information option (17).
1898 map<uint32_t, OptionVendorPtr> vendor_reqs;
1899 for (auto const& opt : question->getOptions(D6O_VENDOR_OPTS)) {
1900 OptionVendorPtr vendor_req;
1901 vendor_req = boost::dynamic_pointer_cast<OptionVendor>(opt.second);
1902 if (vendor_req) {
1903 uint32_t vendor_id = vendor_req->getVendorId();
1904 vendor_reqs[vendor_id] = vendor_req;
1905 static_cast<void>(vendor_ids.insert(vendor_id));
1906 }
1907 }
1908
1909 // Finally, try to get the vendor-id from the client packet's vendor-class
1910 // option (16).
1911 for (auto const& opt : question->getOptions(D6O_VENDOR_CLASS)) {
1912 OptionVendorClassPtr vendor_class;
1913 vendor_class = boost::dynamic_pointer_cast<OptionVendorClass>(opt.second);
1914 if (vendor_class) {
1915 uint32_t vendor_id = vendor_class->getVendorId();
1916 static_cast<void>(vendor_ids.insert(vendor_id));
1917 }
1918 }
1919
1920 // If there's no vendor option in either request or response, then there's no way
1921 // to figure out what the vendor-id values are and we give up.
1922 if (vendor_ids.empty()) {
1923 return;
1924 }
1925
1926 map<uint32_t, set<uint16_t> > requested_opts;
1927
1928 // Let's try to get ORO within that vendor-option.
1929 // This is specific to vendor-id=4491 (Cable Labs). Other vendors may have
1930 // different policies.
1932 if (vendor_reqs.count(VENDOR_ID_CABLE_LABS) > 0) {
1933 OptionVendorPtr vendor_req = vendor_reqs[VENDOR_ID_CABLE_LABS];
1934 OptionPtr oro_generic = vendor_req->getOption(DOCSIS3_V6_ORO);
1935 if (oro_generic) {
1936 // Vendor ID 4491 makes Kea look at DOCSIS3_V6_OPTION_DEFINITIONS
1937 // when parsing options. Based on that, oro_generic will have been
1938 // created as an OptionUint16Array, but might not be for other
1939 // vendor IDs.
1940 oro = boost::dynamic_pointer_cast<OptionUint16Array>(oro_generic);
1941 }
1942 if (oro) {
1943 set<uint16_t> oro_req_opts;
1944 for (uint16_t code : oro->getValues()) {
1945 static_cast<void>(oro_req_opts.insert(code));
1946 }
1947 requested_opts[VENDOR_ID_CABLE_LABS] = oro_req_opts;
1948 }
1949 }
1950
1951 map<uint32_t, set<uint16_t> > cancelled_opts;
1952 const auto& cclasses = question->getClasses();
1953
1954 // Iterate on the configured option list to add persistent and
1955 // cancelled options.
1956 for (uint32_t vendor_id : vendor_ids) {
1957 for (auto const& copts : co_list) {
1958 const OptionContainerPtr& opts = copts->getAll(vendor_id);
1959 if (!opts) {
1960 continue;
1961 }
1962 // Get persistent options.
1963 const OptionContainerPersistIndex& pidx = opts->get<2>();
1964 const OptionContainerPersistRange& prange = pidx.equal_range(true);
1965 BOOST_FOREACH(auto const& desc, prange) {
1966 if (!desc.option_) {
1967 continue;
1968 }
1969 // Add the persistent option code to requested options
1970 uint16_t code = desc.option_->getType();
1971 static_cast<void>(requested_opts[vendor_id].insert(code));
1972 }
1973 // Get cancelled options.
1974 const OptionContainerCancelIndex& cidx = opts->get<5>();
1975 const OptionContainerCancelRange& crange = cidx.equal_range(true);
1976 BOOST_FOREACH(auto const& desc, crange) {
1977 if (!desc.option_) {
1978 continue;
1979 }
1980 // Add the cancelled option code to cancelled options
1981 uint16_t code = desc.option_->getType();
1982 static_cast<void>(cancelled_opts[vendor_id].insert(code));
1983 }
1984 }
1985
1986 // If there is nothing to add don't do anything with this vendor.
1987 // This will explicitly not echo back vendor options from the request
1988 // that either correspond to a vendor not known to Kea even if the
1989 // option encapsulates data or there are no persistent options
1990 // configured for this vendor so Kea does not send any option back.
1991 if (requested_opts[vendor_id].empty()) {
1992 continue;
1993 }
1994
1995 // It's possible that the vendor opts option was inserted already
1996 // by client class or a hook. If that is so, let's use it.
1997 OptionVendorPtr vendor_rsp;
1998 if (vendor_rsps.count(vendor_id) > 0) {
1999 vendor_rsp = vendor_rsps[vendor_id];
2000 } else {
2001 vendor_rsp.reset(new OptionVendor(Option::V6, vendor_id));
2002 }
2003
2004 // Get the list of options that client requested.
2005 bool added = false;
2006
2007 for (uint16_t opt : requested_opts[vendor_id]) {
2008 if (cancelled_opts[vendor_id].count(opt) > 0) {
2009 continue;
2010 }
2011 if (!vendor_rsp->getOption(opt)) {
2012 for (auto const& copts : co_list) {
2013 OptionDescriptor desc = copts->allowedForClientClasses(vendor_id,
2014 opt, cclasses);
2015 // Got it: add it and jump to outer loop.
2016 if (desc.option_) {
2017 vendor_rsp->addOption(desc.option_);
2018 added = true;
2019 break;
2020 }
2021 }
2022 }
2023 }
2024
2025 // If we added some sub-options and the vendor opts option is not in
2026 // the response already, then add it.
2027 if (added && (vendor_rsps.count(vendor_id) == 0)) {
2028 answer->addOption(vendor_rsp);
2029 }
2030 }
2031}
2032
2033bool
2035 try {
2036 switch (pkt->getType()) {
2037 case DHCPV6_SOLICIT:
2038 case DHCPV6_REBIND:
2039 case DHCPV6_CONFIRM:
2042 return (true);
2043
2044 case DHCPV6_REQUEST:
2045 case DHCPV6_RENEW:
2046 case DHCPV6_RELEASE:
2047 case DHCPV6_DECLINE:
2049 return (true);
2050
2054 return (true);
2055
2056 default:
2059 .arg(pkt->getLabel())
2060 .arg(static_cast<int>(pkt->getType()))
2061 .arg(pkt->getIface());
2062 }
2063
2064 } catch (const RFCViolation& e) {
2066 .arg(pkt->getLabel())
2067 .arg(pkt->getName())
2068 .arg(pkt->getRemoteAddr().toText())
2069 .arg(e.what());
2070 StatsMgr::instance().addValue("pkt6-rfc-violation",
2071 static_cast<int64_t>(1));
2072 }
2073
2074 // Increase the statistic of dropped packets.
2075 StatsMgr::instance().addValue("pkt6-receive-drop", static_cast<int64_t>(1));
2076 return (false);
2077}
2078
2079void
2081 RequirementLevel serverid) {
2082 OptionCollection client_ids = pkt->getOptions(D6O_CLIENTID);
2083 switch (clientid) {
2084 case MANDATORY: {
2085 if (client_ids.size() != 1) {
2086 isc_throw(RFCViolation, "Exactly 1 client-id option expected in "
2087 << pkt->getName() << ", but " << client_ids.size()
2088 << " received");
2089 }
2090 sanityCheckDUID(client_ids.begin()->second, "client-id");
2091 break;
2092 }
2093 case OPTIONAL:
2094 if (client_ids.size() > 1) {
2095 isc_throw(RFCViolation, "Too many (" << client_ids.size()
2096 << ") client-id options received in " << pkt->getName());
2097 }
2098 if (!client_ids.empty()) {
2099 sanityCheckDUID(client_ids.begin()->second, "client-id");
2100 }
2101 break;
2102
2103 case FORBIDDEN:
2104 // doesn't make sense - client-id is always allowed
2105 break;
2106 }
2107
2108 OptionCollection server_ids = pkt->getOptions(D6O_SERVERID);
2109 switch (serverid) {
2110 case FORBIDDEN:
2111 if (!server_ids.empty()) {
2112 isc_throw(RFCViolation, "Server-id option was not expected, but "
2113 << server_ids.size() << " received in " << pkt->getName());
2114 }
2115 break;
2116
2117 case MANDATORY:
2118 if (server_ids.size() != 1) {
2119 isc_throw(RFCViolation, "Invalid number of server-id options received ("
2120 << server_ids.size() << "), exactly 1 expected in message "
2121 << pkt->getName());
2122 }
2123 sanityCheckDUID(server_ids.begin()->second, "server-id");
2124 break;
2125
2126 case OPTIONAL:
2127 if (server_ids.size() > 1) {
2128 isc_throw(RFCViolation, "Too many (" << server_ids.size()
2129 << ") server-id options received in " << pkt->getName());
2130 }
2131 if (!server_ids.empty()) {
2132 sanityCheckDUID(server_ids.begin()->second, "server-id");
2133 }
2134 }
2135}
2136
2137void Dhcpv6Srv::sanityCheckDUID(const OptionPtr& opt, const std::string& opt_name) {
2138 if (!opt) {
2139 isc_throw(RFCViolation, "Unable to find expected option " << opt_name);
2140 }
2141
2142 // The client-id or server-id has to have at least 3 bytes of useful data:
2143 // two for duid type and one more for actual duid value.
2144 uint16_t len = opt->len() - opt->getHeaderLen();
2145 if (len < DUID::MIN_DUID_LEN || len > DUID::MAX_DUID_LEN) {
2146 isc_throw(RFCViolation, "Received invalid DUID for " << opt_name << ", received "
2147 << len << " byte(s). It must be at least " << DUID::MIN_DUID_LEN
2148 << " and no more than " << DUID::MAX_DUID_LEN);
2149 }
2150 auto const& empty_duid = DUID::EMPTY().getDuid();
2151 if (len == DUID::MIN_DUID_LEN && opt->getData() == empty_duid) {
2152 isc_throw(RFCViolation, "Received invalid DUID for " << opt_name
2153 << ". It matches the reserved empty-DUID sentinel 00:00:00");
2154 }
2155}
2156
2158Dhcpv6Srv::selectSubnet(const Pkt6Ptr& question, bool& drop) {
2159 const SubnetSelector& selector = CfgSubnets6::initSelector(question);
2160
2162 getCfgSubnets6()->selectSubnet(selector);
2163
2164 // Let's execute all callouts registered for subnet6_receive
2165 if (HooksManager::calloutsPresent(Hooks.hook_index_subnet6_select_)) {
2166 CalloutHandlePtr callout_handle = getCalloutHandle(question);
2167
2168 // Use the RAII wrapper to make sure that the callout handle state is
2169 // reset when this object goes out of scope. All hook points must do
2170 // it to prevent possible circular dependency between the callout
2171 // handle and its arguments.
2172 shared_ptr<ScopedCalloutHandleState> callout_handle_state(
2173 std::make_shared<ScopedCalloutHandleState>(callout_handle));
2174
2175 // Enable copying options from the packet within hook library.
2176 ScopedEnableOptionsCopy<Pkt6> query6_options_copy(question);
2177
2178 // Set new arguments
2179 callout_handle->setArgument("query6", question);
2180 callout_handle->setArgument("subnet6", subnet);
2181
2182 // We pass pointer to const collection for performance reasons.
2183 // Otherwise we would get a non-trivial performance penalty each
2184 // time subnet6_select is called.
2185 callout_handle->setArgument("subnet6collection",
2186 CfgMgr::instance().getCurrentCfg()->
2187 getCfgSubnets6()->getAll());
2188
2189 auto const tpl(parkingLimitExceeded("subnet6_select"));
2190 bool const exceeded(get<0>(tpl));
2191 if (exceeded) {
2192 uint32_t const limit(get<1>(tpl));
2193 // We can't park it so we're going to throw it on the floor.
2196 .arg(limit)
2197 .arg(question->getLabel());
2198 StatsMgr::instance().addValue("pkt6-queue-full",
2199 static_cast<int64_t>(1));
2200 StatsMgr::instance().addValue("pkt6-receive-drop",
2201 static_cast<int64_t>(1));
2202 return (ConstSubnet6Ptr());
2203 }
2204
2205 // We proactively park the packet.
2206 // Not MT compatible because the unparking callback can be called
2207 // before the current thread exists from this block.
2208 HooksManager::park("subnet6_select", question, [this, question, callout_handle_state]() {
2209 if (MultiThreadingMgr::instance().getMode()) {
2210 boost::shared_ptr<function<void()>> callback(
2211 boost::make_shared<function<void()>>([this, question]() mutable {
2213 }));
2214 callout_handle_state->on_completion_ = [callback]() {
2216 };
2217 } else {
2219 }
2220 });
2221
2222 // Call user (and server-side) callouts
2223 try {
2224 HooksManager::callCallouts(Hooks.hook_index_subnet6_select_,
2225 *callout_handle);
2226 } catch (...) {
2227 // Make sure we don't orphan a parked packet.
2228 HooksManager::drop("subnet6_select", question);
2229 throw;
2230 }
2231
2232 // Callouts parked the packet. Same as drop but callouts will resume
2233 // processing or drop the packet later.
2234 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_PARK) {
2236 .arg(question->getLabel());
2237 drop = true;
2238 return (ConstSubnet6Ptr());
2239 } else {
2240 HooksManager::drop("subnet6_select", question);
2241 }
2242
2243 // Callouts decided to skip this step. This means that no
2244 // subnet will be selected. Packet processing will continue,
2245 // but it will be severely limited (i.e. only global options
2246 // will be assigned)
2247 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) {
2249 .arg(question->getLabel());
2250 return (ConstSubnet6Ptr());
2251 }
2252
2253 // Callouts decided to drop the packet. It is a superset of the
2254 // skip case so no subnet will be selected.
2255 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP) {
2257 .arg(question->getLabel());
2258 drop = true;
2259 return (ConstSubnet6Ptr());
2260 }
2261
2262 // Use whatever subnet was specified by the callout
2263 callout_handle->getArgument("subnet6", subnet);
2264 }
2265
2266 if (subnet) {
2267 // Log at higher debug level that subnet has been found.
2269 .arg(question->getLabel())
2270 .arg(subnet->getID());
2271 // Log detailed information about the selected subnet at the
2272 // lower debug level.
2274 .arg(question->getLabel())
2275 .arg(subnet->toText());
2276
2277 } else {
2279 .arg(question->getLabel());
2280 }
2281
2282 return (subnet);
2283}
2284
2285void
2286Dhcpv6Srv::assignLeases(const Pkt6Ptr& question, Pkt6Ptr& answer,
2288 // Save the originally selected subnet.
2289 ConstSubnet6Ptr orig_subnet = ctx.subnet_;
2290
2291 // We need to allocate addresses for all IA_NA options in the client's
2292 // question (i.e. SOLICIT or REQUEST) message. IA_TA options are ignored.
2293
2294 // For the lease allocation it is critical that the client has sent
2295 // DUID. There is no need to check for the presence of the DUID here
2296 // because we have already checked it in the sanityCheck().
2297
2298 // Now that we have all information about the client, let's iterate over all
2299 // received options and handle IA_NA options one by one and store our
2300 // responses in answer message (ADVERTISE or REPLY).
2301 for (auto const& opt : question->options_) {
2302 switch (opt.second->getType()) {
2303 case D6O_IA_NA: {
2304 OptionPtr answer_opt = assignIA_NA(question, ctx,
2305 boost::dynamic_pointer_cast<
2306 Option6IA>(opt.second));
2307 if (answer_opt) {
2308 answer->addOption(answer_opt);
2309 }
2310 break;
2311 }
2312 case D6O_IA_PD: {
2313 OptionPtr answer_opt = assignIA_PD(question, ctx,
2314 boost::dynamic_pointer_cast<
2315 Option6IA>(opt.second));
2316 if (answer_opt) {
2317 answer->addOption(answer_opt);
2318 }
2319 break;
2320 }
2321 default:
2322 break;
2323 }
2324 }
2325
2326 // Need to check for pool-level DDNS parameters and if the
2327 // subnet was modified by the allocation engine, there are things
2328 // we need to do either case.
2329 checkPostAssignmentChanges(question, answer, ctx, orig_subnet);
2330}
2331
2332void
2333Dhcpv6Srv::processClientFqdn(const Pkt6Ptr& question, const Pkt6Ptr& answer,
2336 DdnsParamsPtr ddns_params = ctx.getDdnsParams();
2337
2338 // Get Client FQDN Option from the client's message. If this option hasn't
2339 // been included, do nothing.
2340 Option6ClientFqdnPtr fqdn = boost::dynamic_pointer_cast<
2341 Option6ClientFqdn>(question->getOption(D6O_CLIENT_FQDN));
2342 if (!fqdn) {
2343 if (ddns_params->getEnableUpdates() &&
2344 (ddns_params->getReplaceClientNameMode() == D2ClientConfig::RCM_ALWAYS ||
2345 ddns_params->getReplaceClientNameMode() == D2ClientConfig::RCM_WHEN_NOT_PRESENT)) {
2346 // Fabricate an empty "client" FQDN with flags requesting
2347 // the server do all the updates. The flags will get modified
2348 // below according the configuration options, the name will
2349 // be supplied later on.
2353 .arg(question->getLabel());
2354 } else {
2355 // No FQDN so get the lease hostname from the host reservation if
2356 // there is one.
2357 if (ctx.currentHost()) {
2358 ctx.hostname_ = ctx.currentHost()->getHostname();
2359 }
2360
2361 return;
2362 }
2363 }
2364
2366 .arg(question->getLabel())
2367 .arg(fqdn->toText());
2368
2369 // Create the DHCPv6 Client FQDN Option to be included in the server's
2370 // response to a client.
2371 Option6ClientFqdnPtr fqdn_resp(new Option6ClientFqdn(*fqdn));
2372
2373 // Set the server S, N, and O flags based on client's flags and
2374 // current configuration.
2375 d2_mgr.adjustFqdnFlags<Option6ClientFqdn>(*fqdn, *fqdn_resp, *ddns_params);
2376
2377 // Get DDNS update direction flags
2379 ctx.rev_dns_update_);
2380
2381 // If there's a reservation and it has a hostname specified, use it!
2382 if (ctx.currentHost() && !ctx.currentHost()->getHostname().empty()) {
2383 // Add the qualifying suffix.
2384 // After #3765, this will only occur if the suffix is not empty.
2385 fqdn_resp->setDomainName(d2_mgr.qualifyName(ctx.currentHost()->getHostname(),
2386 *ddns_params, true),
2388 } else {
2389 // Adjust the domain name based on domain name value and type sent by
2390 // the client and current configuration.
2391 try {
2392 d2_mgr.adjustDomainName<Option6ClientFqdn>(*fqdn, *fqdn_resp, *ddns_params);
2393 } catch(const FQDNScrubbedEmpty& scrubbed) {
2395 .arg(question->getLabel())
2396 .arg(scrubbed.what());
2397 return;
2398 }
2399 }
2400
2401 // Once we have the FQDN setup to use it for the lease hostname. This
2402 // only gets replaced later if the FQDN is to be generated from the address.
2403 ctx.hostname_ = fqdn_resp->getDomainName();
2404
2405 // The FQDN has been processed successfully. Let's append it to the
2406 // response to be sent to a client. Note that the Client FQDN option is
2407 // always sent back to the client if Client FQDN was included in the
2408 // client's message.
2410 .arg(question->getLabel())
2411 .arg(fqdn_resp->toText());
2412 answer->addOption(fqdn_resp);
2413
2414 // Optionally, call a hook that may override the decisions made
2415 // earlier.
2416 if (HooksManager::calloutsPresent(Hooks.hook_index_ddns6_update_)) {
2417 CalloutHandlePtr callout_handle = getCalloutHandle(question);
2418
2419 // Use the RAII wrapper to make sure that the callout handle state is
2420 // reset when this object goes out of scope. All hook points must do
2421 // it to prevent possible circular dependency between the callout
2422 // handle and its arguments.
2423 ScopedCalloutHandleState callout_handle_state(callout_handle);
2424
2425 // Setup the callout arguments.
2426 ConstSubnet6Ptr subnet = ctx.subnet_;
2427 callout_handle->setArgument("query6", question);
2428 callout_handle->setArgument("response6", answer);
2429 callout_handle->setArgument("subnet6", subnet);
2430 callout_handle->setArgument("hostname", ctx.hostname_);
2431 callout_handle->setArgument("fwd-update", ctx.fwd_dns_update_);
2432 callout_handle->setArgument("rev-update", ctx.rev_dns_update_);
2433 callout_handle->setArgument("ddns-params", ddns_params);
2434
2435 // Call callouts
2436 HooksManager::callCallouts(Hooks.hook_index_ddns6_update_, *callout_handle);
2437
2438 // Let's get the parameters returned by hook.
2439 string hook_hostname;
2440 bool hook_fwd_dns_update;
2441 bool hook_rev_dns_update;
2442 callout_handle->getArgument("hostname", hook_hostname);
2443 callout_handle->getArgument("fwd-update", hook_fwd_dns_update);
2444 callout_handle->getArgument("rev-update", hook_rev_dns_update);
2445
2446 // If there's anything changed by the hook, log it and then update the parameters
2447 if ((ctx.hostname_ != hook_hostname) || (ctx.fwd_dns_update_!= hook_fwd_dns_update) ||
2448 (ctx.rev_dns_update_ != hook_rev_dns_update)) {
2450 .arg(ctx.hostname_).arg(hook_hostname)
2451 .arg(ctx.fwd_dns_update_).arg(hook_fwd_dns_update)
2452 .arg(ctx.rev_dns_update_).arg(hook_rev_dns_update);
2453
2454 // Update the FQDN option in the response.
2455 fqdn_resp = boost::dynamic_pointer_cast<Option6ClientFqdn>(answer->getOption(D6O_CLIENT_FQDN));
2456 if (fqdn) {
2457 fqdn_resp->setDomainName(hook_hostname, Option6ClientFqdn::FULL);
2458 if (!(hook_fwd_dns_update || hook_rev_dns_update)) {
2459 // Hook disabled updates, Set flags back to client accordingly.
2460 fqdn_resp->setFlag(Option6ClientFqdn::FLAG_S, 0);
2461 fqdn_resp->setFlag(Option6ClientFqdn::FLAG_N, 1);
2462 }
2463 }
2464
2465 ctx.hostname_ = hook_hostname;
2466 ctx.fwd_dns_update_ = hook_fwd_dns_update;
2467 ctx.rev_dns_update_ = hook_rev_dns_update;
2468 }
2469 }
2470}
2471
2472void
2475 // Don't create NameChangeRequests if DNS updates are disabled.
2476 if (!(ctx.getDdnsParams()->getEnableUpdates())) {
2477 return;
2478 }
2479
2480 // The response message instance is always required. For instance it
2481 // holds the Client Identifier. It is a programming error if supplied
2482 // message is NULL.
2483 if (!answer) {
2484 isc_throw(Unexpected, "an instance of the object"
2485 << " encapsulating server's message must not be"
2486 << " NULL when creating DNS NameChangeRequest");
2487 }
2488
2489 // It is likely that client haven't included the FQDN option. In such case,
2490 // FQDN option will be NULL. This is valid state, so we simply return.
2491 Option6ClientFqdnPtr opt_fqdn = boost::dynamic_pointer_cast<
2492 Option6ClientFqdn>(answer->getOption(D6O_CLIENT_FQDN));
2493 if (!opt_fqdn) {
2494 return;
2495 }
2496
2497 // Get the update directions that should be performed based on our
2498 // response FQDN flags.
2499 bool do_fwd = false;
2500 bool do_rev = false;
2502 do_fwd, do_rev);
2503
2504 // Get the Client Id. It is mandatory and a function creating a response
2505 // would have thrown an exception if it was missing. Thus throwing
2506 // Unexpected if it is missing as it is a programming error.
2507 OptionPtr opt_duid = answer->getOption(D6O_CLIENTID);
2508 if (!opt_duid) {
2510 "client identifier is required when creating a new"
2511 " DNS NameChangeRequest");
2512 }
2513 DuidPtr duid = DuidPtr(new DUID(opt_duid->getData()));
2514
2515 // Get the FQDN in the on-wire format. It will be needed to compute
2516 // DHCID.
2517 OutputBuffer name_buf(1);
2518 opt_fqdn->packDomainName(name_buf);
2519 const std::vector<uint8_t>& buf_vec = name_buf.getVector();
2520 // Compute DHCID from Client Identifier and FQDN.
2521 isc::dhcp_ddns::D2Dhcid dhcid(*duid, buf_vec);
2522
2523 // Iterate over the IAContexts (there should be one per client IA processed).
2524 // For the first address in each IA_NA, create the appropriate NCR(s).
2527 for (auto& ia_ctx : ctx.getIAContexts()) {
2528 if ((ia_ctx.type_ != Lease::TYPE_NA) || !ia_ctx.ia_rsp_) {
2529 continue;
2530 }
2531
2534 Option6IAAddrPtr iaaddr = boost::static_pointer_cast<
2535 Option6IAAddr>(ia_ctx.ia_rsp_->getOption(D6O_IAADDR));
2536
2537 // We need an address to create a name-to-address mapping.
2538 // If address is missing for any reason, go to the next IA.
2539 if (!iaaddr) {
2540 continue;
2541 }
2542
2543 bool extended_only = false;
2544 // If the lease is being reused (i.e. lease caching in effect) skip it.
2545 IOAddress ia_address = iaaddr->getAddress();
2546 for (auto const& l : ia_ctx.reused_leases_) {
2547 if (l->addr_ == ia_address) {
2548 extended_only = true;
2549 break;
2550 }
2551 }
2552
2553 if (extended_only) {
2554 continue;
2555 }
2556
2557 // If the lease for iaaddr is in the list of changed leases, we need
2558 // to determine if the changes included changes to the FQDN. If so
2559 // then we may need to do a CHG_REMOVE.
2560 for (auto const& l : ia_ctx.changed_leases_) {
2561 if (l->addr_ == ia_address) {
2562 // The address is the same so this must be renewal. If we're not
2563 // always updating on renew, then we only renew if DNS info has
2564 // changed.
2565 bool ddns_changed = ((*(ctx.duid_) != *(l->duid_)) ||
2566 (l->hostname_ != opt_fqdn->getDomainName()) ||
2567 (l->fqdn_fwd_ != do_fwd) || (l->fqdn_rev_ != do_rev));
2568
2569 if ((l->reuseable_valid_lft_ > 0) ||
2570 (!ctx.getDdnsParams()->getUpdateOnRenew() && !ddns_changed)) {
2571 extended_only = true;
2572 } else {
2573 // Queue a CHG_REMOVE of the old data if it's different.
2574 // NCR will only be created if the lease hostname is not
2575 // empty and at least one of the direction flags is true
2576 if (ddns_changed) {
2577 queueNCR(CHG_REMOVE, l);
2578 }
2579 }
2580
2581 break;
2582 }
2583 }
2584
2585 if (!(do_fwd || do_rev) || (extended_only)) {
2586 // Flags indicate no updates needed or it was an extension of
2587 // an existing lease with no FQDN changes. In the case of the
2588 // former, the most likely scenario is that we are honoring the
2589 // client's request that no updates be done.
2590 continue;
2591 }
2592
2593 // Create new NameChangeRequest. Use the domain name from the FQDN.
2594 // This is an FQDN included in the response to the client, so it
2595 // holds a fully qualified domain-name already (not partial).
2596 // Get the IP address from the lease.
2598 auto cr_mode = StringToConflictResolutionMode(ctx.getDdnsParams()->getConflictResolutionMode());
2599 ncr.reset(new NameChangeRequest(isc::dhcp_ddns::CHG_ADD, do_fwd, do_rev, opt_fqdn->getDomainName(),
2600 iaaddr->getAddress().toText(), dhcid,
2601 calculateDdnsTtl(iaaddr->getValid(),
2602 ctx.getDdnsParams()->getTtlPercent(),
2603 ctx.getDdnsParams()->getTtl(),
2604 ctx.getDdnsParams()->getTtlMin(),
2605 ctx.getDdnsParams()->getTtlMax()),
2606 cr_mode));
2608 .arg(answer->getLabel())
2609 .arg(ncr->toText());
2610
2611 // Post the NCR to the D2ClientMgr.
2613
2618 return;
2619 }
2620}
2621
2624 CfgMACSources mac_sources = CfgMgr::instance().getCurrentCfg()->
2625 getMACSources().get();
2626 HWAddrPtr hwaddr;
2627 for (auto const& it : mac_sources) {
2628 hwaddr = pkt->getMAC(it);
2629 if (hwaddr) {
2630 return (hwaddr);
2631 }
2632 }
2633 return (hwaddr);
2634}
2635
2638 const Lease6Ptr& lease) {
2639
2640 // Search the reservation the prefix is from.
2641 ConstHostPtr host = ctx.currentHost();
2642 if (host) {
2643 IPv6ResrvRange resvs = host->getIPv6Reservations(IPv6Resrv::TYPE_PD);
2644 BOOST_FOREACH(auto const& resv, resvs) {
2645 if ((resv.second.getPrefix() == lease->addr_) &&
2646 (resv.second.getPrefixLen() == lease->prefixlen_)) {
2647 return (resv.second.getPDExclude());
2648 }
2649 }
2650 }
2651
2652 // Search the pool the address is from.
2653 const ConstSubnet6Ptr& subnet = ctx.subnet_;
2654 Pool6Ptr pool = boost::dynamic_pointer_cast<Pool6>(
2655 subnet->getPool(Lease::TYPE_PD, lease->addr_));
2656 if (pool) {
2657 return (pool->getPrefixExcludeOption());
2658 }
2659 return (OptionPtr());
2660}
2661
2665 boost::shared_ptr<Option6IA> ia) {
2666
2667 // Check if the client sent us a hint in his IA_NA. Clients may send an
2668 // address in their IA_NA options as a suggestion (e.g. the last address
2669 // they used before).
2670 Option6IAAddrPtr hint_opt =
2671 boost::dynamic_pointer_cast<Option6IAAddr>(ia->getOption(D6O_IAADDR));
2673 if (hint_opt) {
2674 hint = hint_opt->getAddress();
2675 }
2676
2677 if (ctx.fake_allocation_) {
2679 .arg(query->getLabel())
2680 .arg(ia->getIAID())
2681 .arg(hint_opt ? hint.toText() : "(no hint)");
2682 } else {
2684 .arg(query->getLabel())
2685 .arg(ia->getIAID())
2686 .arg(hint_opt ? hint.toText() : "(no hint)");
2687 }
2688
2689 // convenience values
2690 const ConstSubnet6Ptr& subnet = ctx.subnet_;
2691
2692 // If there is no subnet selected for handling this IA_NA, the only thing left to do is
2693 // to say that we are sorry, but the user won't get an address. As a convenience, we
2694 // use a different status text to indicate that (compare to the same status code,
2695 // but different wording below)
2696 if (!subnet) {
2697 // Create an empty IA_NA option with IAID matching the request.
2698 // Note that we don't use OptionDefinition class to create this option.
2699 // This is because we prefer using a constructor of Option6IA that
2700 // initializes IAID. Otherwise we would have to use setIAID() after
2701 // creation of the option which has some performance implications.
2702 boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
2703
2704 // Insert status code NoAddrsAvail.
2705 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoAddrsAvail,
2706 "Server could not select subnet for"
2707 " this client"));
2708 return (ia_rsp);
2709 }
2710
2711 // Set per-IA context values.
2712 ctx.createIAContext();
2713 ctx.currentIA().iaid_ = ia->getIAID();
2714 if (hint_opt) {
2715 ctx.currentIA().addHint(hint_opt);
2716 } else {
2717 ctx.currentIA().addHint(hint);
2718 }
2720
2721 // Use allocation engine to pick a lease for this client. Allocation engine
2722 // will try to honor the hint, but it is just a hint - some other address
2723 // may be used instead. If fake_allocation is set to false, the lease will
2724 // be inserted into the LeaseMgr as well.
2725 Lease6Collection leases = alloc_engine_->allocateLeases6(ctx);
2726
2728 Lease6Ptr lease;
2729 if (!leases.empty()) {
2730 lease = *leases.begin();
2731 }
2732
2733 // Create IA_NA that we will put in the response.
2734 // Do not use OptionDefinition to create option's instance so
2735 // as we can initialize IAID using a constructor.
2736 Option6IAPtr ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
2737 ctx.currentIA().ia_rsp_ = ia_rsp;
2738
2739 if (lease) {
2740 // We have a lease! Let's wrap its content into IA_NA option
2741 // with IAADDR suboption.
2742 if (ctx.fake_allocation_) {
2744 .arg(query->getLabel())
2745 .arg(lease->addr_.toText())
2746 .arg(ia->getIAID());
2747 } else if (lease->reuseable_valid_lft_ == 0) {
2749 .arg(query->getLabel())
2750 .arg(lease->addr_.toText())
2751 .arg(ia->getIAID())
2752 .arg(Lease::lifetimeToText(lease->valid_lft_));
2753 } else {
2754 lease->valid_lft_ = lease->reuseable_valid_lft_;
2755 lease->preferred_lft_ = lease->reuseable_preferred_lft_;
2756 ctx.currentIA().reused_leases_.push_back(lease);
2758 .arg(query->getLabel())
2759 .arg(lease->addr_.toText())
2760 .arg(ia->getIAID())
2761 .arg(Lease::lifetimeToText(lease->valid_lft_));
2762
2763 // Increment the reuse statistics.
2764 StatsMgr::instance().addValue("v6-ia-na-lease-reuses", int64_t(1));
2765 StatsMgr::instance().addValue(StatsMgr::generateName("subnet", lease->subnet_id_,
2766 "v6-ia-na-lease-reuses"),
2767 int64_t(1));
2768 }
2770 .arg(query->getLabel())
2771 .arg(ia->getIAID())
2772 .arg(lease->toText());
2773
2774 // Set the values for T1 and T2.
2775 setTeeTimes(lease->preferred_lft_, subnet, ia_rsp);
2776
2777 Option6IAAddrPtr addr(new Option6IAAddr(D6O_IAADDR, lease->addr_,
2778 lease->preferred_lft_,
2779 lease->valid_lft_));
2780 ia_rsp->addOption(addr);
2781
2782 // It would be possible to insert status code=0(success) as well,
2783 // but this is considered waste of bandwidth as absence of status
2784 // code is considered a success.
2785
2786 } else {
2787 // Allocation engine did not allocate a lease. The engine logged
2788 // cause of that failure. The only thing left is to insert
2789 // status code to pass the sad news to the client.
2790
2793 .arg(query->getLabel())
2794 .arg(ia->getIAID());
2795
2796 ia_rsp->addOption(createStatusCode(*query, *ia_rsp,
2798 "Sorry, no address could be"
2799 " allocated."));
2800 }
2801 return (ia_rsp);
2802}
2803
2807 boost::shared_ptr<Option6IA> ia) {
2808
2809 // Check if the client sent us a hint in his IA_PD. Clients may send an
2810 // address in their IA_PD options as a suggestion (e.g. the last address
2811 // they used before). While the hint consists of a full prefix (prefix +
2812 // length), getting just the prefix is sufficient to identify a lease.
2813 Option6IAPrefixPtr hint_opt =
2814 boost::dynamic_pointer_cast<Option6IAPrefix>(ia->getOption(D6O_IAPREFIX));
2816 if (hint_opt) {
2817 hint = hint_opt->getAddress();
2818 }
2819
2820 if (ctx.fake_allocation_) {
2822 .arg(query->getLabel())
2823 .arg(ia->getIAID())
2824 .arg(hint_opt ? hint.toText() : "(no hint)");
2825 } else {
2827 .arg(query->getLabel())
2828 .arg(ia->getIAID())
2829 .arg(hint_opt ? hint.toText() : "(no hint)");
2830 }
2831
2832 const ConstSubnet6Ptr& subnet = ctx.subnet_;
2833
2834 // Create IA_PD that we will put in the response.
2835 // Do not use OptionDefinition to create option's instance so
2836 // as we can initialize IAID using a constructor.
2837 boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_PD, ia->getIAID()));
2838
2839 // If there is no subnet selected for handling this IA_PD, the only thing
2840 // left to do is to say that we are sorry, but the user won't get an address.
2841 // As a convenience, we use a different status text to indicate that
2842 // (compare to the same status code, but different wording below)
2843 if (!subnet) {
2844
2845 // Insert status code NoPrefixAvail.
2846 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoPrefixAvail,
2847 "Sorry, no subnet available."));
2848 return (ia_rsp);
2849 }
2850
2851 // Set per-IA context values.
2852 ctx.createIAContext();
2853 ctx.currentIA().iaid_ = ia->getIAID();
2854 if (hint_opt) {
2855 ctx.currentIA().addHint(hint_opt);
2856 } else {
2857 ctx.currentIA().addHint(hint, 0);
2858 }
2860 ctx.currentIA().ia_rsp_ = ia_rsp;
2861
2862 // Use allocation engine to pick a lease for this client. Allocation engine
2863 // will try to honor the hint, but it is just a hint - some other address
2864 // may be used instead. If fake_allocation is set to false, the lease will
2865 // be inserted into the LeaseMgr as well.
2866 Lease6Collection leases = alloc_engine_->allocateLeases6(ctx);
2867
2868 if (!leases.empty()) {
2869
2870 // Need to retain the shortest preferred lease time to use
2871 // for calculating T1 and T2.
2872 uint32_t min_preferred_lft = (*leases.begin())->preferred_lft_;
2873
2874 const bool pd_exclude_requested = requestedInORO(query, D6O_PD_EXCLUDE);
2875 for (auto const& l : leases) {
2876
2877 // We have a lease! Let's wrap its content into IA_PD option
2878 // with IAADDR suboption.
2879 if (ctx.fake_allocation_) {
2881 .arg(query->getLabel())
2882 .arg(l->addr_.toText())
2883 .arg(static_cast<int>(l->prefixlen_))
2884 .arg(ia->getIAID());
2885 } else if (l->reuseable_valid_lft_ == 0) {
2887 .arg(query->getLabel())
2888 .arg(l->addr_.toText())
2889 .arg(static_cast<int>(l->prefixlen_))
2890 .arg(ia->getIAID())
2891 .arg(Lease::lifetimeToText(l->valid_lft_));
2892 } else {
2893 l->valid_lft_ = l->reuseable_valid_lft_;
2894 l->preferred_lft_ = l->reuseable_preferred_lft_;
2896 .arg(query->getLabel())
2897 .arg(l->addr_.toText())
2898 .arg(static_cast<int>(l->prefixlen_))
2899 .arg(ia->getIAID())
2900 .arg(Lease::lifetimeToText(l->valid_lft_));
2901
2902 // Increment the reuse statistics.
2903 StatsMgr::instance().addValue("v6-ia-pd-lease-reuses", int64_t(1));
2904 StatsMgr::instance().addValue(StatsMgr::generateName("subnet", l->subnet_id_,
2905 "v6-ia-pd-lease-reuses"),
2906 int64_t(1));
2907 }
2908
2909 // Check for new minimum lease time
2910 if ((l->preferred_lft_ > 0) && (min_preferred_lft > l->preferred_lft_)) {
2911 min_preferred_lft = l->preferred_lft_;
2912 }
2913
2914 boost::shared_ptr<Option6IAPrefix>
2915 addr(new Option6IAPrefix(D6O_IAPREFIX, l->addr_,
2916 l->prefixlen_, l->preferred_lft_,
2917 l->valid_lft_));
2918 ia_rsp->addOption(addr);
2919
2920 if (pd_exclude_requested) {
2921 OptionPtr pd_exclude_option = getPDExclude(ctx, l);
2922 if (pd_exclude_option) {
2923 addr->addOption(pd_exclude_option);
2924 }
2925 }
2926 }
2927
2928 // Set T1 and T2, using the shortest preferred lifetime among the leases.
2929 setTeeTimes(min_preferred_lft, subnet, ia_rsp);
2930
2931 // It would be possible to insert status code=0(success) as well,
2932 // but this is considered waste of bandwidth as absence of status
2933 // code is considered a success.
2934
2935 } else {
2936 // Allocation engine did not allocate a lease. The engine logged
2937 // cause of that failure. The only thing left is to insert
2938 // status code to pass the sad news to the client.
2939
2942 .arg(query->getLabel())
2943 .arg(ia->getIAID());
2944
2945 ia_rsp->addOption(createStatusCode(*query, *ia_rsp,
2947 "Sorry, no prefixes could"
2948 " be allocated."));
2949 }
2950 return (ia_rsp);
2951}
2952
2956 boost::shared_ptr<Option6IA> ia) {
2957
2959 .arg(query->getLabel())
2960 .arg(ia->getIAID());
2961
2962 // convenience values
2963 const ConstSubnet6Ptr& subnet = ctx.subnet_;
2964
2965 // Create empty IA_NA option with IAID matching the request.
2966 Option6IAPtr ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
2967
2968 if (!subnet) {
2978 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
2979 "Sorry, no known leases for this duid/iaid."));
2980 return (ia_rsp);
2981 }
2982
2983 // Set per-IA context values.
2984 ctx.createIAContext();
2985 ctx.currentIA().iaid_ = ia->getIAID();
2987 ctx.currentIA().ia_rsp_ = ia_rsp;
2988
2989 // Extract the addresses that the client is trying to obtain.
2990 OptionCollection addrs = ia->getOptions();
2991 for (auto const& it : addrs) {
2992 if (it.second->getType() != D6O_IAADDR) {
2993 continue;
2994 }
2995 Option6IAAddrPtr iaaddr = boost::dynamic_pointer_cast<Option6IAAddr>(it.second);
2996 if (!iaaddr) {
2997 // That's weird. Option code was ok, but the object type was not.
2998 // This should never happen. The only case would be with badly
2999 // mis-implemented hook libraries that insert invalid option objects.
3000 // There's no way to protect against this.
3001 continue;
3002 }
3003 ctx.currentIA().addHint(iaaddr);
3004 }
3005
3006 Lease6Collection leases = alloc_engine_->renewLeases6(ctx);
3007
3008 // Ok, now we have the leases extended. We have:
3009 // - what the client tried to renew in ctx.hints_
3010 // - what we actually assigned in leases
3011 // - old leases that are no longer valid in ctx.old_leases_
3012
3013 // For each IA inserted by the client we have to determine what to do
3014 // about included addresses and notify the client. We will iterate over
3015 // those prefixes and remove those that we have already processed. We
3016 // don't want to remove them from the context, so we need to copy them
3017 // into temporary container.
3019
3020 // Retains the shortest valid lease time to use
3021 // for calculating T1 and T2.
3022 uint32_t min_preferred_lft = std::numeric_limits<uint32_t>::max();
3023
3024 // For all leases we have now, add the IAADDR with non-zero lifetimes.
3025 for (auto const& l : leases) {
3026 if (l->reuseable_valid_lft_ == 0) {
3028 .arg(query->getLabel())
3029 .arg(l->addr_.toText())
3030 .arg(ia->getIAID());
3031 } else {
3032 l->valid_lft_ = l->reuseable_valid_lft_;
3033 l->preferred_lft_ = l->reuseable_preferred_lft_;
3035 .arg(query->getLabel())
3036 .arg(l->addr_.toText())
3037 .arg(ia->getIAID())
3038 .arg(Lease::lifetimeToText(l->valid_lft_));
3039
3040 // Increment the reuse statistics.
3041 StatsMgr::instance().addValue("v6-ia-na-lease-reuses", int64_t(1));
3042 StatsMgr::instance().addValue(StatsMgr::generateName("subnet", l->subnet_id_,
3043 "v6-ia-na-lease-reuses"),
3044 int64_t(1));
3045 }
3046
3048 l->addr_, l->preferred_lft_, l->valid_lft_));
3049 ia_rsp->addOption(iaaddr);
3050
3051 // Check for new minimum lease time
3052 if ((l->preferred_lft_ > 0) && (min_preferred_lft > l->preferred_lft_)) {
3053 min_preferred_lft = l->preferred_lft_;
3054 }
3055
3056 // Now remove this address from the hints list.
3057 AllocEngine::Resource hint_type(l->addr_);
3058 hints.erase(std::remove(hints.begin(), hints.end(), hint_type),
3059 hints.end());
3060 }
3061
3062 // For the leases that we just retired, send the addresses with 0 lifetimes.
3063 for (auto const& l : ctx.currentIA().old_leases_) {
3064
3065 // Send an address with zero lifetimes only when this lease belonged to
3066 // this client. Do not send it when we're reusing an old lease that belonged
3067 // to someone else.
3068 if (equalValues(query->getClientId(), l->duid_)) {
3070 l->addr_, 0, 0));
3071 ia_rsp->addOption(iaaddr);
3072 }
3073
3074 // Now remove this address from the hints list.
3075 AllocEngine::Resource hint_type(l->addr_);
3076 hints.erase(std::remove(hints.begin(), hints.end(), hint_type), hints.end());
3077
3078 // If the new FQDN settings have changed for the lease, we need to
3079 // delete any existing FQDN records for this lease.
3080 if ((l->hostname_ != ctx.hostname_) || (l->fqdn_fwd_ != ctx.fwd_dns_update_) ||
3081 (l->fqdn_rev_ != ctx.rev_dns_update_)) {
3084 .arg(query->getLabel())
3085 .arg(l->toText())
3086 .arg(ctx.hostname_)
3087 .arg(ctx.rev_dns_update_ ? "true" : "false")
3088 .arg(ctx.fwd_dns_update_ ? "true" : "false");
3089
3090 queueNCR(CHG_REMOVE, l);
3091 }
3092 }
3093
3094 // Finally, if there are any addresses requested that we haven't dealt with
3095 // already, inform the client that he can't have them.
3096 for (auto const& hint : hints) {
3098 hint.getAddress(), 0, 0));
3099 ia_rsp->addOption(iaaddr);
3100 }
3101
3102 if (!leases.empty()) {
3103 // We allocated leases so we need to update T1 and T2.
3104 setTeeTimes(min_preferred_lft, subnet, ia_rsp);
3105 } else {
3106 // The server wasn't able allocate new lease and renew an existing
3107 // lease. In that case, the server sends NoAddrsAvail per RFC 9915.
3108 ia_rsp->addOption(createStatusCode(*query, *ia_rsp,
3110 "Sorry, no addresses could be"
3111 " assigned at this time."));
3112 }
3113
3114 return (ia_rsp);
3115}
3116
3120 boost::shared_ptr<Option6IA> ia) {
3121
3123 .arg(query->getLabel())
3124 .arg(ia->getIAID());
3125
3126 const ConstSubnet6Ptr& subnet = ctx.subnet_;
3127 const DuidPtr& duid = ctx.duid_;
3128
3129 // Let's create a IA_PD response and fill it in later
3130 Option6IAPtr ia_rsp(new Option6IA(D6O_IA_PD, ia->getIAID()));
3131
3132 // If there is no subnet for the particular client, we can't retrieve
3133 // information about client's leases from lease database. We treat this
3134 // as no binding for the client.
3135 if (!subnet) {
3136 // Per RFC 9915, section 18.3.4, if there is no binding and we are
3137 // processing a Renew, the NoBinding status code should be returned.
3138 if (query->getType() == DHCPV6_RENEW) {
3139 // Insert status code NoBinding
3140 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
3141 "Sorry, no known PD leases"
3142 " for this duid/iaid."));
3143 return (ia_rsp);
3144
3145 // Per RFC 9915, section 18.3.5, if there is no binding and we are
3146 // processing Rebind, the message has to be discarded (assuming that
3147 // the server doesn't know if the prefix in the IA_PD option is
3148 // appropriate for the client's link). The exception being thrown
3149 // here should propagate to the main loop and cause the message to
3150 // be discarded.
3151 } else {
3152
3161 isc_throw(DHCPv6DiscardMessageError, "no subnet found for the"
3162 " client sending Rebind to extend lifetime of the"
3163 " prefix (DUID=" << duid->toText() << ", IAID="
3164 << ia->getIAID() << ")");
3165 }
3166 }
3167
3168 // Set per-IA context values.
3169 ctx.createIAContext();
3170 ctx.currentIA().iaid_ = ia->getIAID();
3172 ctx.currentIA().ia_rsp_ = ia_rsp;
3173
3174 // Extract prefixes that the client is trying to renew.
3175 OptionCollection addrs = ia->getOptions();
3176 for (auto const& it : addrs) {
3177 if (it.second->getType() != D6O_IAPREFIX) {
3178 continue;
3179 }
3180 Option6IAPrefixPtr prf = boost::dynamic_pointer_cast<Option6IAPrefix>(it.second);
3181 if (!prf) {
3182 // That's weird. Option code was ok, but the object type was not.
3183 // This should never happen. The only case would be with badly
3184 // mis-implemented hook libraries that insert invalid option objects.
3185 // There's no way to protect against this.
3186 continue;
3187 }
3188
3189 // Put the client's prefix into the hints list.
3190 ctx.currentIA().addHint(prf);
3191 }
3192
3193 // Call Allocation Engine and attempt to renew leases. Number of things
3194 // may happen. Leases may be extended, revoked (if the lease is no longer
3195 // valid or reserved for someone else), or new leases may be added.
3196 // Important parameters are:
3197 // - returned container - current valid leases
3198 // - old_leases - leases that used to be, but are no longer valid
3199 // - changed_leases - leases that have FQDN changed (not really important
3200 // in PD context)
3201 Lease6Collection leases = alloc_engine_->renewLeases6(ctx);
3202
3203 // For each IA inserted by the client we have to determine what to do
3204 // about included prefixes and notify the client. We will iterate over
3205 // those prefixes and remove those that we have already processed. We
3206 // don't want to remove them from the context, so we need to copy them
3207 // into temporary container.
3209
3210 const bool pd_exclude_requested = requestedInORO(query, D6O_PD_EXCLUDE);
3211
3212 // Retains the shortest valid lease time to use
3213 // for calculating T1 and T2.
3214 uint32_t min_preferred_lft = std::numeric_limits<uint32_t>::max();
3215
3216 for (auto const& l : leases) {
3217 if (l->reuseable_valid_lft_ == 0) {
3219 .arg(query->getLabel())
3220 .arg(l->addr_.toText())
3221 .arg(static_cast<int>(l->prefixlen_))
3222 .arg(ia->getIAID());
3223 } else {
3224 l->valid_lft_ = l->reuseable_valid_lft_;
3225 l->preferred_lft_ = l->reuseable_preferred_lft_;
3227 .arg(query->getLabel())
3228 .arg(l->addr_.toText())
3229 .arg(static_cast<int>(l->prefixlen_))
3230 .arg(ia->getIAID())
3231 .arg(Lease::lifetimeToText(l->valid_lft_));
3232
3233 // Increment the reuse statistics.
3234 StatsMgr::instance().addValue("v6-ia-pd-lease-reuses", int64_t(1));
3235 StatsMgr::instance().addValue(StatsMgr::generateName("subnet", l->subnet_id_,
3236 "v6-ia-pd-lease-reuses"),
3237 int64_t(1));
3238 }
3239
3241 l->addr_, l->prefixlen_,
3242 l->preferred_lft_, l->valid_lft_));
3243 ia_rsp->addOption(prf);
3244
3245 if (pd_exclude_requested) {
3246 OptionPtr pd_exclude_option = getPDExclude(ctx, l);
3247 if (pd_exclude_option) {
3248 prf->addOption(pd_exclude_option);
3249 }
3250 }
3251
3252 // Check for new minimum lease time
3253 if ((l->preferred_lft_ > 0) && (l->preferred_lft_ < min_preferred_lft)) {
3254 min_preferred_lft = l->preferred_lft_;
3255 }
3256
3257 // Now remove this prefix from the hints list.
3258 AllocEngine::Resource hint_type(l->addr_, l->prefixlen_);
3259 hints.erase(std::remove(hints.begin(), hints.end(), hint_type),
3260 hints.end());
3261 }
3262
3264 for (auto const& l : ctx.currentIA().old_leases_) {
3265
3266 // Send a prefix with zero lifetimes only when this lease belonged to
3267 // this client. Do not send it when we're reusing an old lease that belonged
3268 // to someone else.
3269 if (equalValues(query->getClientId(), l->duid_)) {
3270 Option6IAPrefixPtr prefix(new Option6IAPrefix(D6O_IAPREFIX, l->addr_,
3271 l->prefixlen_, 0, 0));
3272 ia_rsp->addOption(prefix);
3273 }
3274
3275 // Now remove this prefix from the hints list.
3276 AllocEngine::Resource hint_type(l->addr_, l->prefixlen_);
3277 hints.erase(std::remove(hints.begin(), hints.end(), hint_type), hints.end());
3278 }
3279
3280 // Finally, if there are any prefixes requested that we haven't dealt with
3281 // already, inform the client that he can't have them.
3282 for (auto const& prefix : hints) {
3283
3284 // Send the prefix with the zero lifetimes only if the prefix
3285 // contains non-zero value. A zero value indicates that the hint was
3286 // for the prefix length.
3287 if (!prefix.getAddress().isV6Zero()) {
3288 OptionPtr prefix_opt(new Option6IAPrefix(D6O_IAPREFIX,
3289 prefix.getAddress(),
3290 prefix.getPrefixLength(),
3291 0, 0));
3292 ia_rsp->addOption(prefix_opt);
3293 }
3294 }
3295
3296 if (!leases.empty()) {
3297 // We allocated leases so we need to update T1 and T2.
3298 setTeeTimes(min_preferred_lft, subnet, ia_rsp);
3299 } else {
3300 // All is left is to insert the status code.
3301 // The server wasn't able allocate new lease and renew an existing
3302 // lease. In that case, the server sends NoPrefixAvail per RFC 9915.
3303 ia_rsp->addOption(createStatusCode(*query, *ia_rsp,
3305 "Sorry, no prefixes could be"
3306 " assigned at this time."));
3307 }
3308
3309 return (ia_rsp);
3310}
3311
3312void
3315
3316 // We will try to extend lease lifetime for all IA options in the client's
3317 // Renew or Rebind message. IA_TA options are ignored.
3318
3319 // For the lease extension it is critical that the client has sent
3320 // DUID. There is no need to check for the presence of the DUID here
3321 // because we have already checked it in the sanityCheck().
3322
3323 // Save the originally selected subnet.
3324 ConstSubnet6Ptr orig_subnet = ctx.subnet_;
3325
3326 for (auto const& opt : query->options_) {
3327 switch (opt.second->getType()) {
3328 case D6O_IA_NA: {
3329 OptionPtr answer_opt = extendIA_NA(query, ctx,
3330 boost::dynamic_pointer_cast<
3331 Option6IA>(opt.second));
3332 if (answer_opt) {
3333 reply->addOption(answer_opt);
3334 }
3335 break;
3336 }
3337
3338 case D6O_IA_PD: {
3339 OptionPtr answer_opt = extendIA_PD(query, ctx,
3340 boost::dynamic_pointer_cast<
3341 Option6IA>(opt.second));
3342 if (answer_opt) {
3343 reply->addOption(answer_opt);
3344 }
3345 break;
3346 }
3347
3348 default:
3349 break;
3350 }
3351 }
3352
3353 // Need to check for pool-level DDNS parameters and if the
3354 // subnet was modified by the allocation engine, there are things
3355 // we need to do either case.
3356 checkPostAssignmentChanges(query, reply, ctx, orig_subnet);
3357}
3358
3359void
3362
3363 // We need to release addresses for all IA options in the client's
3364 // RELEASE message. IA_TA options are ignored.
3365
3371
3372 // Let's set the status to be success by default. We can override it with
3373 // error status if needed. The important thing to understand here is that
3374 // the global status code may be set to success only if all IA options were
3375 // handled properly. Therefore the releaseIA_NA and releaseIA_PD options
3376 // may turn the status code to some error, but can't turn it back to success.
3377 int general_status = STATUS_Success;
3378 for (auto const& opt : release->options_) {
3379 Lease6Ptr old_lease;
3380 switch (opt.second->getType()) {
3381 case D6O_IA_NA: {
3382 OptionPtr answer_opt = releaseIA_NA(ctx.duid_, release, general_status,
3383 boost::dynamic_pointer_cast<Option6IA>(opt.second),
3384 old_lease);
3385 if (answer_opt) {
3386 reply->addOption(answer_opt);
3387 }
3388 break;
3389 }
3390 case D6O_IA_PD: {
3391 OptionPtr answer_opt = releaseIA_PD(ctx.duid_, release, general_status,
3392 boost::dynamic_pointer_cast<Option6IA>(opt.second),
3393 old_lease);
3394 if (answer_opt) {
3395 reply->addOption(answer_opt);
3396 }
3397 break;
3398 }
3399 case D6O_IA_TA:
3400 default:
3401 // remaining options are stateless and thus ignored in this context
3402 ;
3403 }
3404
3405 // Store the old lease.
3406 if (old_lease) {
3407 ctx.currentIA().old_leases_.push_back(old_lease);
3408 }
3409 }
3410
3411 // Include top-level status code as well.
3412 reply->addOption(createStatusCode(*release, general_status,
3413 "Summary status for all processed IA_NAs"));
3414}
3415
3417Dhcpv6Srv::releaseIA_NA(const DuidPtr& duid, const Pkt6Ptr& query,
3418 int& general_status, boost::shared_ptr<Option6IA> ia,
3419 Lease6Ptr& old_lease) {
3420
3422 .arg(query->getLabel())
3423 .arg(ia->getIAID());
3424
3425 // Release can be done in one of two ways:
3426 // Approach 1: extract address from client's IA_NA and see if it belongs
3427 // to this particular client.
3428 // Approach 2: find a subnet for this client, get a lease for
3429 // this subnet/duid/iaid and check if its content matches to what the
3430 // client is asking us to release.
3431 //
3432 // This method implements approach 1.
3433
3434 // That's our response
3435 boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
3436
3437 Option6IAAddrPtr release_addr = boost::dynamic_pointer_cast<Option6IAAddr>
3438 (ia->getOption(D6O_IAADDR));
3439 if (!release_addr) {
3440 ia_rsp->addOption(createStatusCode(*query, STATUS_NoBinding,
3441 "You did not include an address in your RELEASE"));
3442 general_status = STATUS_NoBinding;
3443 return (ia_rsp);
3444 }
3445
3447 release_addr->getAddress());
3448
3449 if (!lease || (lease->state_ != Lease::STATE_DEFAULT)) {
3450 // client releasing an address which is not assigned.
3451
3454 .arg(query->getLabel())
3455 .arg(release_addr->getAddress().toText());
3456
3457 // Insert status code NoBinding.
3458 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
3459 "Sorry, this address isn't assigned, can't release."));
3460 general_status = STATUS_NoBinding;
3461
3462 return (ia_rsp);
3463 }
3464
3465 if (!lease->duid_) {
3466 // Something is gravely wrong here. We do have a lease, but it does not
3467 // have mandatory DUID information attached. Someone was messing with our
3468 // database.
3469
3471 .arg(query->getLabel())
3472 .arg(release_addr->getAddress().toText());
3473
3474 general_status = STATUS_UnspecFail;
3475 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_UnspecFail,
3476 "Database consistency check failed when trying to RELEASE"));
3477 return (ia_rsp);
3478 }
3479
3480 if (*duid != *(lease->duid_)) {
3481
3482 // Sorry, it's not your address. You can't release it.
3484 .arg(query->getLabel())
3485 .arg(release_addr->getAddress().toText())
3486 .arg(lease->duid_->toText());
3487
3488 general_status = STATUS_NoBinding;
3489 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
3490 "This address does not belong to you, you can't release it"));
3491 return (ia_rsp);
3492 }
3493
3494 if (ia->getIAID() != lease->iaid_) {
3495 // This address belongs to this client, but to a different IA
3497 .arg(query->getLabel())
3498 .arg(release_addr->getAddress().toText())
3499 .arg(lease->iaid_)
3500 .arg(ia->getIAID());
3501 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
3502 "This is your address, but you used wrong IAID"));
3503 general_status = STATUS_NoBinding;
3504 return (ia_rsp);
3505 }
3506
3507 // It is not necessary to check if the address matches as we used
3508 // getLease6(addr) method that is supposed to return a proper lease.
3509
3510 bool skip = false;
3511 // Execute all callouts registered for packet6_send
3512 if (HooksManager::calloutsPresent(Hooks.hook_index_lease6_release_)) {
3513 CalloutHandlePtr callout_handle = getCalloutHandle(query);
3514
3515 // Use the RAII wrapper to make sure that the callout handle state is
3516 // reset when this object goes out of scope. All hook points must do
3517 // it to prevent possible circular dependency between the callout
3518 // handle and its arguments.
3519 ScopedCalloutHandleState callout_handle_state(callout_handle);
3520
3521 // Enable copying options from the packet within hook library.
3522 ScopedEnableOptionsCopy<Pkt6> query6_options_copy(query);
3523
3524 // Delete all previous arguments
3525 callout_handle->deleteAllArguments();
3526
3527 // Pass the original packet
3528 callout_handle->setArgument("query6", query);
3529
3530 // Pass the lease to be updated
3531 callout_handle->setArgument("lease6", lease);
3532
3533 // Call all installed callouts
3534 HooksManager::callCallouts(Hooks.hook_index_lease6_release_, *callout_handle);
3535
3536 // Callouts decided to skip the next processing step. The next
3537 // processing step would be to send the packet, so skip at this
3538 // stage means "drop response".
3539 if ((callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) ||
3540 (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP)) {
3541 skip = true;
3543 .arg(query->getLabel());
3544 }
3545 }
3546
3547 // Ok, we've passed all checks. Let's release this address.
3548 bool success = false; // was the removal operation successful?
3549 bool expired = false; // explicitly expired instead of removed?
3550 auto expiration_cfg = CfgMgr::instance().getCurrentCfg()->getCfgExpiration();
3551
3552 // Callout didn't indicate to skip the release process. Let's release
3553 // the lease.
3554 if (!skip) {
3555 // Delete lease only if affinity is disabled.
3556 if (expiration_cfg->getFlushReclaimedTimerWaitTime() &&
3557 expiration_cfg->getHoldReclaimedTime() &&
3558 lease->valid_lft_ != Lease::INFINITY_LFT) {
3559 // Expire the lease.
3560 lease->valid_lft_ = 0;
3561 lease->preferred_lft_ = 0;
3562 // Set the lease state to released to indicate that this lease
3563 // must be preserved in the database. It is particularly useful
3564 // in HA to differentiate between the leases that should be
3565 // updated in the partner's database and deleted from the partner's
3566 // database.
3567 lease->state_ = Lease6::STATE_RELEASED;
3569 expired = true;
3570 success = true;
3571 } else {
3572 success = LeaseMgrFactory::instance().deleteLease(lease);
3573 }
3574 }
3575
3576 // Here the success should be true if we removed lease successfully
3577 // and false if skip flag was set or the removal failed for whatever reason
3578
3579 if (!success) {
3580 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_UnspecFail,
3581 "Server failed to release a lease"));
3582
3584 .arg(query->getLabel())
3585 .arg(lease->addr_.toText())
3586 .arg(lease->iaid_);
3587 general_status = STATUS_UnspecFail;
3588
3589 return (ia_rsp);
3590 } else {
3591 old_lease = lease;
3592
3594 .arg(query->getLabel())
3595 .arg(lease->addr_.toText())
3596 .arg(lease->iaid_);
3597
3598 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_Success,
3599 "Lease released. Thank you, please come again."));
3600
3601 if (expired) {
3603 .arg(query->getLabel())
3604 .arg(lease->addr_.toText())
3605 .arg(lease->iaid_);
3606 } else {
3608 .arg(query->getLabel())
3609 .arg(lease->addr_.toText())
3610 .arg(lease->iaid_);
3611
3612 // Check if a lease has flags indicating that the FQDN update has
3613 // been performed. If so, create NameChangeRequest which removes
3614 // the entries.
3615 queueNCR(CHG_REMOVE, lease);
3616 }
3617
3618 // Need to decrease statistic for assigned addresses.
3619 StatsMgr::instance().addValue("assigned-nas", static_cast<int64_t>(-1));
3620
3622 StatsMgr::generateName("subnet", lease->subnet_id_, "assigned-nas"),
3623 static_cast<int64_t>(-1));
3624
3625 auto const& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(lease->subnet_id_);
3626 if (subnet) {
3627 auto const& pool = subnet->getPool(Lease::TYPE_NA, lease->addr_, false);
3628 if (pool) {
3630 StatsMgr::generateName("subnet", subnet->getID(),
3631 StatsMgr::generateName("pool", pool->getID(), "assigned-nas")),
3632 static_cast<int64_t>(-1));
3633 }
3634 }
3635
3636 return (ia_rsp);
3637 }
3638}
3639
3641Dhcpv6Srv::releaseIA_PD(const DuidPtr& duid, const Pkt6Ptr& query,
3642 int& general_status, boost::shared_ptr<Option6IA> ia,
3643 Lease6Ptr& old_lease) {
3644 // Release can be done in one of two ways:
3645 // Approach 1: extract address from client's IA_NA and see if it belongs
3646 // to this particular client.
3647 // Approach 2: find a subnet for this client, get a lease for
3648 // this subnet/duid/iaid and check if its content matches to what the
3649 // client is asking us to release.
3650 //
3651 // This method implements approach 1.
3652
3653 // That's our response. We will fill it in as we check the lease to be
3654 // released.
3655 boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_PD, ia->getIAID()));
3656
3657 boost::shared_ptr<Option6IAPrefix> release_prefix =
3658 boost::dynamic_pointer_cast<Option6IAPrefix>(ia->getOption(D6O_IAPREFIX));
3659 if (!release_prefix) {
3660 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
3661 "You did not include a prefix in your RELEASE"));
3662 general_status = STATUS_NoBinding;
3663 return (ia_rsp);
3664 }
3665
3667 release_prefix->getAddress());
3668
3669 if (!lease || (lease->state_ != Lease::STATE_DEFAULT)) {
3670 // Client releasing a prefix which is not assigned.
3671
3674 .arg(query->getLabel())
3675 .arg(release_prefix->getAddress().toText())
3676 .arg(static_cast<int>(release_prefix->getLength()));
3677
3678 // Insert status code NoBinding.
3679 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
3680 "Sorry, this prefix isn't assigned, can't release."));
3681 general_status = STATUS_NoBinding;
3682
3683 return (ia_rsp);
3684 }
3685
3686 if (!lease->duid_) {
3687 // Something is gravely wrong here. We do have a lease, but it does not
3688 // have mandatory DUID information attached. Someone was messing with our
3689 // database.
3691 .arg(query->getLabel())
3692 .arg(release_prefix->getAddress().toText())
3693 .arg(static_cast<int>(release_prefix->getLength()));
3694
3695 general_status = STATUS_UnspecFail;
3696 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_UnspecFail,
3697 "Database consistency check failed when trying to RELEASE"));
3698 return (ia_rsp);
3699 }
3700
3701 if (*duid != *(lease->duid_)) {
3702 // Sorry, it's not your address. You can't release it.
3704 .arg(query->getLabel())
3705 .arg(release_prefix->getAddress().toText())
3706 .arg(static_cast<int>(release_prefix->getLength()))
3707 .arg(lease->duid_->toText());
3708
3709 general_status = STATUS_NoBinding;
3710 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
3711 "This address does not belong to you, you can't release it"));
3712 return (ia_rsp);
3713 }
3714
3715 if (ia->getIAID() != lease->iaid_) {
3716 // This address belongs to this client, but to a different IA
3718 .arg(query->getLabel())
3719 .arg(release_prefix->getAddress().toText())
3720 .arg(static_cast<int>(release_prefix->getLength()))
3721 .arg(lease->iaid_)
3722 .arg(ia->getIAID());
3723 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
3724 "This is your address, but you used wrong IAID"));
3725 general_status = STATUS_NoBinding;
3726 return (ia_rsp);
3727 }
3728
3729 // It is not necessary to check if the address matches as we used
3730 // getLease6(addr) method that is supposed to return a proper lease.
3731
3732 bool skip = false;
3733 // Execute all callouts registered for packet6_send
3734 if (HooksManager::calloutsPresent(Hooks.hook_index_lease6_release_)) {
3735 CalloutHandlePtr callout_handle = getCalloutHandle(query);
3736
3737 // Use the RAII wrapper to make sure that the callout handle state is
3738 // reset when this object goes out of scope. All hook points must do
3739 // it to prevent possible circular dependency between the callout
3740 // handle and its arguments.
3741 ScopedCalloutHandleState callout_handle_state(callout_handle);
3742
3743 // Enable copying options from the packet within hook library.
3744 ScopedEnableOptionsCopy<Pkt6> query6_options_copy(query);
3745
3746 // Pass the original packet
3747 callout_handle->setArgument("query6", query);
3748
3749 // Pass the lease to be updated
3750 callout_handle->setArgument("lease6", lease);
3751
3752 // Call all installed callouts
3753 HooksManager::callCallouts(Hooks.hook_index_lease6_release_, *callout_handle);
3754
3755 // Callouts decided to skip the next processing step. The next
3756 // processing step would be to send the packet, so skip at this
3757 // stage means "drop response".
3758 if ((callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) ||
3759 (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP)) {
3760 skip = true;
3762 .arg(query->getLabel());
3763 }
3764 }
3765
3766 // Ok, we've passed all checks. Let's release this prefix.
3767 bool success = false; // was the removal operation successful?
3768 bool expired = false; // explicitly expired instead of removed?
3769 auto expiration_cfg = CfgMgr::instance().getCurrentCfg()->getCfgExpiration();
3770
3771 // Callout didn't indicate to skip the release process. Let's release
3772 // the lease.
3773 if (!skip) {
3774 // Delete lease only if affinity is disabled.
3775 if (expiration_cfg->getFlushReclaimedTimerWaitTime() &&
3776 expiration_cfg->getHoldReclaimedTime() &&
3777 lease->valid_lft_ != Lease::INFINITY_LFT) {
3778 // Expire the lease.
3779 lease->valid_lft_ = 0;
3780 lease->preferred_lft_ = 0;
3781 // Set the lease state to released to indicate that this lease
3782 // must be preserved in the database. It is particularly useful
3783 // in HA to differentiate between the leases that should be
3784 // updated in the partner's database and deleted from the partner's
3785 // database.
3786 lease->state_ = Lease6::STATE_RELEASED;
3788 expired = true;
3789 success = true;
3790 } else {
3791 success = LeaseMgrFactory::instance().deleteLease(lease);
3792 }
3793 }
3794
3795 // Here the success should be true if we removed lease successfully
3796 // and false if skip flag was set or the removal failed for whatever reason
3797
3798 if (!success) {
3799 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_UnspecFail,
3800 "Server failed to release a lease"));
3801
3803 .arg(query->getLabel())
3804 .arg(lease->addr_.toText())
3805 .arg(static_cast<int>(lease->prefixlen_))
3806 .arg(lease->iaid_);
3807 general_status = STATUS_UnspecFail;
3808
3809 } else {
3810 old_lease = lease;
3811
3813 .arg(query->getLabel())
3814 .arg(lease->addr_.toText())
3815 .arg(static_cast<int>(lease->prefixlen_))
3816 .arg(lease->iaid_);
3817
3818 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_Success,
3819 "Lease released. Thank you, please come again."));
3820
3821 if (expired) {
3823 .arg(query->getLabel())
3824 .arg(lease->addr_.toText())
3825 .arg(static_cast<int>(lease->prefixlen_))
3826 .arg(lease->iaid_);
3827 } else {
3829 .arg(query->getLabel())
3830 .arg(lease->addr_.toText())
3831 .arg(static_cast<int>(lease->prefixlen_))
3832 .arg(lease->iaid_);
3833 }
3834
3835 // Need to decrease statistic for assigned prefixes.
3836 StatsMgr::instance().addValue("assigned-pds", static_cast<int64_t>(-1));
3837
3839 StatsMgr::generateName("subnet", lease->subnet_id_, "assigned-pds"),
3840 static_cast<int64_t>(-1));
3841
3842 auto const& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(lease->subnet_id_);
3843 if (subnet) {
3844 auto const& pool = subnet->getPool(Lease::TYPE_PD, lease->addr_, false);
3845 if (pool) {
3847 StatsMgr::generateName("subnet", subnet->getID(),
3848 StatsMgr::generateName("pd-pool", pool->getID(), "assigned-pds")),
3849 static_cast<int64_t>(-1));
3850 }
3851 }
3852 }
3853
3854 return (ia_rsp);
3855}
3856
3857void
3858Dhcpv6Srv::reject(const Pkt6Ptr& query, Pkt6Ptr& answer) {
3860 .arg(query->makeLabel(query->getClientId(), 0))
3861 .arg(query->toText());
3862 // Handle IAs.
3863 for (auto const& opt : query->options_) {
3864 switch (opt.second->getType()) {
3865 case D6O_IA_NA: {
3866 OptionPtr answer_opt = rejectIA_NA(query,
3867 boost::dynamic_pointer_cast<
3868 Option6IA>(opt.second));
3869 if (answer_opt) {
3870 answer->addOption(answer_opt);
3871 }
3872 break;
3873 }
3874 case D6O_IA_PD: {
3875 OptionPtr answer_opt = rejectIA_PD(query,
3876 boost::dynamic_pointer_cast<
3877 Option6IA>(opt.second));
3878 if (answer_opt) {
3879 answer->addOption(answer_opt);
3880 }
3881 break;
3882 }
3883 default:
3884 break;
3885 }
3886 }
3887}
3888
3891 Option6IAPtr ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
3892 // Insert status code NoAddrsAvail.
3893 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoAddrsAvail,
3894 "Server rejected this request"));
3895 return (ia_rsp);
3896}
3897
3900 Option6IAPtr ia_rsp(new Option6IA(D6O_IA_PD, ia->getIAID()));
3901 // Insert status code NoPrefixAvail.
3902 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoPrefixAvail,
3903 "Server rejected this request"));
3904 return (ia_rsp);
3905}
3906
3907Pkt6Ptr
3909
3910 Pkt6Ptr solicit = ctx.query_;
3911 Pkt6Ptr response(new Pkt6(DHCPV6_ADVERTISE, solicit->getTransid()));
3912
3913 // Handle Rapid Commit option, if present.
3914 if (ctx.subnet_ && ctx.subnet_->getRapidCommit()) {
3915 OptionPtr opt_rapid_commit = solicit->getOption(D6O_RAPID_COMMIT);
3916 if (opt_rapid_commit) {
3917
3919 .arg(solicit->getLabel());
3920
3921 // If Rapid Commit has been sent by the client, change the
3922 // response type to Reply and include Rapid Commit option.
3923 response->setType(DHCPV6_REPLY);
3924 response->addOption(opt_rapid_commit);
3925 }
3926 }
3927
3928 // "Fake" allocation is the case when the server is processing the Solicit
3929 // message without the Rapid Commit option and advertises a lease to
3930 // the client, but doesn't commit this lease to the lease database. If
3931 // the Solicit contains the Rapid Commit option and the server is
3932 // configured to honor the Rapid Commit option, or the client has sent
3933 // the Request message, the lease will be committed to the lease
3934 // database. The type of the server's response may be used to determine
3935 // if this is the fake allocation case or not. When the server sends
3936 // Reply message it means that it is committing leases. Other message
3937 // type (Advertise) means that server is not committing leases (fake
3938 // allocation).
3939 ctx.fake_allocation_ = (response->getType() != DHCPV6_REPLY);
3940
3941 processClientFqdn(solicit, response, ctx);
3942
3943 if (solicit->inClass("REJECT")) {
3944 reject(solicit, response);
3945 } else if (MultiThreadingMgr::instance().getMode()) {
3946 // The lease reclamation cannot run at the same time.
3947 ReadLockGuard share(alloc_engine_->getReadWriteMutex());
3948 assignLeases(solicit, response, ctx);
3949 } else {
3950 assignLeases(solicit, response, ctx);
3951 }
3952
3954 // Evaluate additional classes.
3955 evaluateAdditionalClasses(solicit, ctx);
3956
3958 .arg(solicit->getLabel())
3959 .arg(solicit->getName())
3960 .arg(solicit->getClasses().toText());
3961
3962 copyClientOptions(solicit, response);
3963 CfgOptionList co_list;
3964 buildCfgOptionList(solicit, ctx, co_list);
3965 appendDefaultOptions(solicit, response, co_list);
3966 appendRequestedOptions(solicit, response, co_list);
3967 appendRequestedVendorOptions(solicit, response, ctx, co_list);
3968
3969 updateReservedFqdn(ctx, response);
3970
3971 // Only generate name change requests if sending a Reply as a result
3972 // of receiving Rapid Commit option.
3973 if (response->getType() == DHCPV6_REPLY) {
3974 createNameChangeRequests(response, ctx);
3975 }
3976
3977 return (response);
3978}
3979
3980Pkt6Ptr
3982
3983 Pkt6Ptr request = ctx.query_;
3984 Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, request->getTransid()));
3985
3986 processClientFqdn(request, reply, ctx);
3987
3988 if (request->inClass("REJECT")) {
3989 reject(request, reply);
3990 } else if (MultiThreadingMgr::instance().getMode()) {
3991 // The lease reclamation cannot run at the same time.
3992 ReadLockGuard share(alloc_engine_->getReadWriteMutex());
3993 assignLeases(request, reply, ctx);
3994 } else {
3995 assignLeases(request, reply, ctx);
3996 }
3997
3999 // Evaluate additional classes.
4000 evaluateAdditionalClasses(request, ctx);
4001
4003 .arg(request->getLabel())
4004 .arg(request->getName())
4005 .arg(request->getClasses().toText());
4006
4007 copyClientOptions(request, reply);
4008 CfgOptionList co_list;
4009 buildCfgOptionList(request, ctx, co_list);
4010 appendDefaultOptions(request, reply, co_list);
4011 appendRequestedOptions(request, reply, co_list);
4012 appendRequestedVendorOptions(request, reply, ctx, co_list);
4013
4014 updateReservedFqdn(ctx, reply);
4015 generateFqdn(reply, ctx);
4016 createNameChangeRequests(reply, ctx);
4017
4018 return (reply);
4019}
4020
4021Pkt6Ptr
4023
4024 Pkt6Ptr renew = ctx.query_;
4025 Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, renew->getTransid()));
4026
4027 processClientFqdn(renew, reply, ctx);
4028
4029 if (renew->inClass("REJECT")) {
4030 reject(renew, reply);
4031 } else if (MultiThreadingMgr::instance().getMode()) {
4032 // The lease reclamation cannot run at the same time.
4033 ReadLockGuard share(alloc_engine_->getReadWriteMutex());
4034
4035 extendLeases(renew, reply, ctx);
4036 } else {
4037 extendLeases(renew, reply, ctx);
4038 }
4039
4041 // Evaluate additional classes.
4042 evaluateAdditionalClasses(renew, ctx);
4043
4045 .arg(renew->getLabel())
4046 .arg(renew->getName())
4047 .arg(renew->getClasses().toText());
4048
4049 copyClientOptions(renew, reply);
4050 CfgOptionList co_list;
4051 buildCfgOptionList(renew, ctx, co_list);
4052 appendDefaultOptions(renew, reply, co_list);
4053 appendRequestedOptions(renew, reply, co_list);
4054 appendRequestedVendorOptions(renew, reply, ctx, co_list);
4055
4056 updateReservedFqdn(ctx, reply);
4057 generateFqdn(reply, ctx);
4058 createNameChangeRequests(reply, ctx);
4059
4060 return (reply);
4061}
4062
4063Pkt6Ptr
4065
4066 Pkt6Ptr rebind = ctx.query_;
4067 Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, rebind->getTransid()));
4068
4069 processClientFqdn(rebind, reply, ctx);
4070
4071 if (rebind->inClass("REJECT")) {
4072 reject(rebind, reply);
4073 } else if (MultiThreadingMgr::instance().getMode()) {
4074 // The lease reclamation cannot run at the same time.
4075 ReadLockGuard share(alloc_engine_->getReadWriteMutex());
4076
4077 extendLeases(rebind, reply, ctx);
4078 } else {
4079 extendLeases(rebind, reply, ctx);
4080 }
4081
4083 // Evaluate additional classes.
4084 evaluateAdditionalClasses(rebind, ctx);
4085
4087 .arg(rebind->getLabel())
4088 .arg(rebind->getName())
4089 .arg(rebind->getClasses().toText());
4090
4091 copyClientOptions(rebind, reply);
4092 CfgOptionList co_list;
4093 buildCfgOptionList(rebind, ctx, co_list);
4094 appendDefaultOptions(rebind, reply, co_list);
4095 appendRequestedOptions(rebind, reply, co_list);
4096 appendRequestedVendorOptions(rebind, reply, ctx, co_list);
4097
4098 updateReservedFqdn(ctx, reply);
4099 generateFqdn(reply, ctx);
4100 createNameChangeRequests(reply, ctx);
4101
4102 return (reply);
4103}
4104
4105Pkt6Ptr
4107
4108 Pkt6Ptr confirm = ctx.query_;
4110 // Evaluate additional classes.
4111 evaluateAdditionalClasses(confirm, ctx);
4112
4114 .arg(confirm->getLabel())
4115 .arg(confirm->getName())
4116 .arg(confirm->getClasses().toText());
4117
4118 // Get IA_NAs from the Confirm. If there are none, the message is
4119 // invalid and must be discarded. There is nothing more to do.
4120 OptionCollection ias = confirm->getOptions(D6O_IA_NA);
4121 if (ias.empty()) {
4122 return (Pkt6Ptr());
4123 }
4124
4125 // The server sends Reply message in response to Confirm.
4126 Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, confirm->getTransid()));
4127 // Make sure that the necessary options are included.
4128 copyClientOptions(confirm, reply);
4129 CfgOptionList co_list;
4130 buildCfgOptionList(confirm, ctx, co_list);
4131 appendDefaultOptions(confirm, reply, co_list);
4132 appendRequestedOptions(confirm, reply, co_list);
4133 appendRequestedVendorOptions(confirm, reply, ctx, co_list);
4134 // Indicates if at least one address has been verified. If no addresses
4135 // are verified it means that the client has sent no IA_NA options
4136 // or no IAAddr options and that client's message has to be discarded.
4137 bool verified = false;
4138 // Check if subnet was selected for the message. If no subnet
4139 // has been selected, the client is not on link.
4140 ConstSubnetPtr subnet = ctx.subnet_;
4141
4142 // Regardless if the subnet has been selected or not, we will iterate
4143 // over the IA_NA options to check if they hold any addresses. If there
4144 // are no, the Confirm is discarded.
4145 // Check addresses in IA_NA options and make sure they are appropriate.
4146 for (auto const& ia : ias) {
4147 const OptionCollection& opts = ia.second->getOptions();
4148 for (auto const& opt : opts) {
4149 // Ignore options other than IAAddr.
4150 if (opt.second->getType() == D6O_IAADDR) {
4151 // Check that the address is in range in the subnet selected.
4152 Option6IAAddrPtr iaaddr = boost::dynamic_pointer_cast<
4153 Option6IAAddr>(opt.second);
4154 // If there is subnet selected and the address has been included
4155 // in IA_NA, mark it verified and verify that it belongs to the
4156 // subnet.
4157 if (iaaddr) {
4158 // If at least one address is not in range, then return
4159 // the NotOnLink status code.
4160 if (subnet && !subnet->inRange(iaaddr->getAddress())) {
4161 std::ostringstream status_msg;
4162 status_msg << "Address " << iaaddr->getAddress()
4163 << " is not on link.";
4164 reply->addOption(createStatusCode(*confirm,
4166 status_msg.str()));
4167 return (reply);
4168 }
4169 verified = true;
4170 } else {
4171 isc_throw(Unexpected, "failed to cast the IA Address option"
4172 " to the Option6IAAddrPtr. This is programming"
4173 " error and should be reported");
4174 }
4175 }
4176 }
4177 }
4178
4179 // It seems that the client hasn't included any addresses in which case
4180 // the Confirm must be discarded.
4181 if (!verified) {
4182 return (Pkt6Ptr());
4183 }
4184
4185 // If there is a subnet, there were addresses in IA_NA options and the
4186 // addresses where consistent with the subnet then the client is on link.
4187 if (subnet) {
4188 // All addresses in range, so return success.
4189 reply->addOption(createStatusCode(*confirm, STATUS_Success,
4190 "All addresses are on-link"));
4191 } else {
4192 reply->addOption(createStatusCode(*confirm, STATUS_NotOnLink,
4193 "No subnet selected"));
4194 }
4195
4196 return (reply);
4197}
4198
4199Pkt6Ptr
4201
4202 Pkt6Ptr release = ctx.query_;
4204 // Evaluate additional classes.
4205 evaluateAdditionalClasses(release, ctx);
4206
4208 .arg(release->getLabel())
4209 .arg(release->getName())
4210 .arg(release->getClasses().toText());
4211
4212 // Create an empty Reply message.
4213 Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, release->getTransid()));
4214
4215 // Copy client options (client-id, also relay information if present)
4216 copyClientOptions(release, reply);
4217
4218 // Get the configured option list
4219 CfgOptionList co_list;
4220 // buildCfgOptionList(release, ctx, co_list);
4221 appendDefaultOptions(release, reply, co_list);
4222
4223 releaseLeases(release, reply, ctx);
4224
4227
4228 return (reply);
4229}
4230
4231Pkt6Ptr
4233
4234 Pkt6Ptr decline = ctx.query_;
4236 // Evaluate additional classes.
4237 evaluateAdditionalClasses(decline, ctx);
4238
4240 .arg(decline->getLabel())
4241 .arg(decline->getName())
4242 .arg(decline->getClasses().toText());
4243
4244 // Create an empty Reply message.
4245 Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, decline->getTransid()));
4246
4247 // Copy client options (client-id, also relay information if present)
4248 copyClientOptions(decline, reply);
4249
4250 // Get the configured option list
4251 CfgOptionList co_list;
4252 buildCfgOptionList(decline, ctx, co_list);
4253
4254 // Include server-id
4255 appendDefaultOptions(decline, reply, co_list);
4256
4257 if (declineLeases(decline, reply, ctx)) {
4258 return (reply);
4259 } else {
4260
4261 // declineLeases returns false only if the hooks set the next step
4262 // status to DROP. We'll just doing as requested.
4263 return (Pkt6Ptr());
4264 }
4265}
4266
4267bool
4270
4271 // We need to decline addresses for all IA_NA options in the client's
4272 // DECLINE message.
4273
4274 // Let's set the status to be success by default. We can override it with
4275 // error status if needed. The important thing to understand here is that
4276 // the global status code may be set to success only if all IA options were
4277 // handled properly. Therefore the declineIA options
4278 // may turn the status code to some error, but can't turn it back to success.
4279 int general_status = STATUS_Success;
4280
4281 for (auto const& opt : decline->options_) {
4282 switch (opt.second->getType()) {
4283 case D6O_IA_NA: {
4284 OptionPtr answer_opt = declineIA(decline, ctx.duid_, general_status,
4285 boost::dynamic_pointer_cast<Option6IA>(opt.second),
4286 ctx.new_leases_);
4287 if (answer_opt) {
4288
4289 // We have an answer, let's use it.
4290 reply->addOption(answer_opt);
4291 } else {
4292
4293 // The only case when declineIA could return NULL is if one of the
4294 // hook callouts set next step status to DROP. We just need to drop
4295 // this packet.
4296 return (false);
4297 }
4298 break;
4299 }
4300 default:
4301 // We don't care for the remaining options
4302 ;
4303 }
4304 }
4305
4306 return (true);
4307}
4308
4310Dhcpv6Srv::declineIA(const Pkt6Ptr& decline, const DuidPtr& duid,
4311 int& general_status, boost::shared_ptr<Option6IA> ia,
4312 Lease6Collection& new_leases) {
4313
4315 .arg(decline->getLabel())
4316 .arg(ia->getIAID());
4317
4318 // Decline can be done in one of two ways:
4319 // Approach 1: extract address from client's IA_NA and see if it belongs
4320 // to this particular client.
4321 // Approach 2: find a subnet for this client, get a lease for
4322 // this subnet/duid/iaid and check if its content matches to what the
4323 // client is asking us to decline.
4324 //
4325 // This method implements approach 1.
4326
4327 // That's our response
4328 boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
4329
4330 const OptionCollection& opts = ia->getOptions();
4331 int total_addrs = 0; // Let's count the total number of addresses.
4332 for (auto const& opt : opts) {
4333
4334 // Let's ignore nested options other than IAADDR (there shouldn't be anything
4335 // else in IA_NA in Decline message, but let's be on the safe side).
4336 if (opt.second->getType() != D6O_IAADDR) {
4337 continue;
4338 }
4339 Option6IAAddrPtr decline_addr = boost::dynamic_pointer_cast<Option6IAAddr>
4340 (opt.second);
4341 if (!decline_addr) {
4342 continue;
4343 }
4344
4345 total_addrs++;
4346
4348 decline_addr->getAddress());
4349
4350 if (!lease || lease->expired() || lease->state_ != Lease::STATE_DEFAULT) {
4351 // Client trying to decline a lease that we don't know about.
4353 .arg(decline->getLabel()).arg(decline_addr->getAddress().toText());
4354
4355 // According to RFC 9915, section 18.3.8:
4356 // "For each IA in the Decline message for which the server has no
4357 // binding information, the server adds an IA option using the IAID
4358 // from the Decline message and includes a Status Code option with
4359 // the value NoBinding in the IA option".
4360 setStatusCode(ia_rsp, createStatusCode(*decline, *ia_rsp, STATUS_NoBinding,
4361 "Server does not know about such an address."));
4362
4363 // In the same section of RFC 9915:
4364 // "The server ignores addresses not assigned to the IAs (though it may"
4365 // choose to log an error if it finds such addresses)."
4366 continue; // There may be other addresses.
4367 }
4368
4369 if (!lease->duid_) {
4370 // Something is gravely wrong here. We do have a lease, but it does not
4371 // have mandatory DUID information attached. Someone was messing with our
4372 // database.
4373
4375 .arg(decline->getLabel())
4376 .arg(decline_addr->getAddress().toText());
4377
4378 ia_rsp->addOption(createStatusCode(*decline, *ia_rsp, STATUS_UnspecFail,
4379 "Database consistency check failed when attempting Decline."));
4380
4381 continue;
4382 }
4383
4384 // Ok, there's a sane lease with an address. Let's check if DUID matches first.
4385 if (*duid != *(lease->duid_)) {
4386
4387 // Sorry, it's not your address. You can't release it.
4389 .arg(decline->getLabel())
4390 .arg(decline_addr->getAddress().toText())
4391 .arg(lease->duid_->toText());
4392
4393 ia_rsp->addOption(createStatusCode(*decline, *ia_rsp, STATUS_NoBinding,
4394 "This address does not belong to you, you can't decline it"));
4395
4396 continue;
4397 }
4398
4399 // Let's check if IAID matches.
4400 if (ia->getIAID() != lease->iaid_) {
4401 // This address belongs to this client, but to a different IA
4403 .arg(decline->getLabel())
4404 .arg(lease->addr_.toText())
4405 .arg(ia->getIAID())
4406 .arg(lease->iaid_);
4407 setStatusCode(ia_rsp, createStatusCode(*decline, *ia_rsp, STATUS_NoBinding,
4408 "This is your address, but you used wrong IAID"));
4409
4410 continue;
4411 }
4412
4413 // Ok, all is good. Decline this lease.
4414 if (!declineLease(decline, lease, ia_rsp)) {
4415 // declineLease returns false only when hook callouts set the next
4416 // step status to drop. We just propagate the bad news here.
4417 return (OptionPtr());
4418
4419 } else {
4420 new_leases.push_back(lease);
4421 }
4422 }
4423
4424 if (total_addrs == 0) {
4425 setStatusCode(ia_rsp, createStatusCode(*decline, *ia_rsp, STATUS_NoBinding,
4426 "No addresses sent in IA_NA"));
4427 general_status = STATUS_NoBinding;
4428 }
4429
4430 return (ia_rsp);
4431}
4432
4433void
4434Dhcpv6Srv::setStatusCode(boost::shared_ptr<isc::dhcp::Option6IA>& container,
4435 const OptionPtr& status) {
4436 // Let's delete any old status code we may have.
4437 container->delOption(D6O_STATUS_CODE);
4438
4439 container->addOption(status);
4440}
4441
4442bool
4443Dhcpv6Srv::declineLease(const Pkt6Ptr& decline, const Lease6Ptr lease,
4444 boost::shared_ptr<Option6IA> ia_rsp) {
4445 // We do not want to decrease the assigned-nas at this time. While
4446 // technically a declined address is no longer allocated, the
4447 // primary usage of the assigned-nas statistic is to monitor pool
4448 // utilization. Most people would forget to include declined-addresses
4449 // in the calculation, and simply do assigned-nas/total-nas. This
4450 // would have a bias towards under-representing pool utilization,
4451 // if we decreased allocated immediately after receiving DHCPDECLINE,
4452 // rather than later when we recover the address.
4453
4454 // Let's call lease6_decline hooks if necessary.
4455 if (HooksManager::calloutsPresent(Hooks.hook_index_lease6_decline_)) {
4456 CalloutHandlePtr callout_handle = getCalloutHandle(decline);
4457
4458 // Use the RAII wrapper to make sure that the callout handle state is
4459 // reset when this object goes out of scope. All hook points must do
4460 // it to prevent possible circular dependency between the callout
4461 // handle and its arguments.
4462 ScopedCalloutHandleState callout_handle_state(callout_handle);
4463
4464 // Enable copying options from the packet within hook library.
4465 ScopedEnableOptionsCopy<Pkt6> query6_options_copy(decline);
4466
4467 // Pass the original packet
4468 callout_handle->setArgument("query6", decline);
4469
4470 // Pass the lease to be updated
4471 callout_handle->setArgument("lease6", lease);
4472
4473 // Call callouts
4474 HooksManager::callCallouts(Hooks.hook_index_lease6_decline_,
4475 *callout_handle);
4476
4477 // Callouts decided to SKIP the next processing step. The next
4478 // processing step would be to actually decline the lease, so we'll
4479 // keep the lease as is.
4480 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) {
4482 .arg(decline->getLabel())
4483 .arg(decline->getIface())
4484 .arg(lease->addr_.toText());
4485 return (true);
4486 }
4487
4488 // Callouts decided to DROP the packet. Let's simply log it and
4489 // return false, so callers will act accordingly.
4490 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP) {
4492 .arg(decline->getLabel())
4493 .arg(decline->getIface())
4494 .arg(lease->addr_.toText());
4495 return (false);
4496 }
4497 }
4498
4499 Lease6Ptr old_values = boost::make_shared<Lease6>(*lease);
4500
4501 // @todo: Call hooks.
4502
4503 // We need to disassociate the lease from the client. Once we move a lease
4504 // to declined state, it is no longer associated with the client in any
4505 // way.
4506 lease->decline(CfgMgr::instance().getCurrentCfg()->getDeclinePeriod());
4507
4508 try {
4510 } catch (const Exception& ex) {
4511 // Update failed.
4513 .arg(decline->getLabel())
4514 .arg(lease->addr_.toText())
4515 .arg(ex.what());
4516 return (false);
4517 }
4518
4519 // Check if a lease has flags indicating that the FQDN update has
4520 // been performed. If so, create NameChangeRequest which removes
4521 // the entries. This method does all necessary checks.
4522 queueNCR(CHG_REMOVE, old_values);
4523
4524 // Bump up the subnet-specific statistic.
4526 StatsMgr::generateName("subnet", lease->subnet_id_, "declined-addresses"),
4527 static_cast<int64_t>(1));
4528
4529 auto const& subnet = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getBySubnetId(lease->subnet_id_);
4530 if (subnet) {
4531 auto const& pool = subnet->getPool(Lease::TYPE_NA, lease->addr_, false);
4532 if (pool) {
4534 StatsMgr::generateName("subnet", subnet->getID(),
4535 StatsMgr::generateName("pool", pool->getID(), "declined-addresses")),
4536 static_cast<int64_t>(1));
4537 }
4538 }
4539
4540 // Global declined addresses counter.
4541 StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(1));
4542
4543 LOG_INFO(lease6_logger, DHCP6_DECLINE_LEASE).arg(decline->getLabel())
4544 .arg(lease->addr_.toText()).arg(lease->valid_lft_);
4545
4546 ia_rsp->addOption(createStatusCode(*decline, *ia_rsp, STATUS_Success,
4547 "Lease declined. Hopefully the next one will be better."));
4548
4549 return (true);
4550}
4551
4552Pkt6Ptr
4554
4555 Pkt6Ptr inf_request = ctx.query_;
4556 conditionallySetReservedClientClasses(inf_request, ctx);
4557 // Evaluate additional classes.
4558 evaluateAdditionalClasses(inf_request, ctx);
4559
4561 .arg(inf_request->getLabel())
4562 .arg(inf_request->getName())
4563 .arg(inf_request->getClasses().toText());
4564
4565 // Create a Reply packet, with the same trans-id as the client's.
4566 Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, inf_request->getTransid()));
4567
4568 // Copy client options (client-id, also relay information if present)
4569 copyClientOptions(inf_request, reply);
4570
4571 // Build the configured option list for append methods
4572 CfgOptionList co_list;
4573 buildCfgOptionList(inf_request, ctx, co_list);
4574
4575 // Append default options, i.e. options that the server is supposed
4576 // to put in all messages it sends (server-id for now, but possibly other
4577 // options once we start supporting authentication)
4578 appendDefaultOptions(inf_request, reply, co_list);
4579
4580 // Try to assign options that were requested by the client.
4581 appendRequestedOptions(inf_request, reply, co_list);
4582
4583 // Try to assign vendor options that were requested by the client.
4584 appendRequestedVendorOptions(inf_request, reply, ctx, co_list);
4585
4586 return (reply);
4587}
4588
4589void
4591
4592 // flags are in transid
4593 // uint32_t flags = dhcp4_query->getTransid();
4594 // do nothing with DHCPV4_QUERY_FLAGS_UNICAST
4595
4596 // Get the DHCPv4 message option
4597 OptionPtr dhcp4_msg = dhcp4_query->getOption(D6O_DHCPV4_MSG);
4598 if (dhcp4_msg) {
4599 try {
4600 // Forward the whole message to the DHCPv4 server via IPC
4601 Dhcp6to4Ipc::instance().send(dhcp4_query);
4602 } catch (...) {
4603 // Assume the error was already logged
4604 return;
4605 }
4606 }
4607
4608 // This method does not return anything as we always sent back
4609 // the response via Dhcp6To4Ipc.
4610}
4611
4612Pkt6Ptr
4614 // Get the allow-address-registration flag value.
4615 // If it's false, punt.
4616 auto allow_address_registration = CfgMgr::instance().getCurrentCfg()->
4617 getConfiguredGlobal(CfgGlobals::ALLOW_ADDRESS_REGISTRATION);
4618
4619 if (allow_address_registration && !allow_address_registration->boolValue()) {
4621 .arg(ctx.query_->getLabel());
4622 StatsMgr::instance().addValue("pkt6-admin-filtered",
4623 static_cast<int64_t>(1));
4624 StatsMgr::instance().addValue("pkt6-receive-drop",
4625 static_cast<int64_t>(1));
4626 return(Pkt6Ptr());
4627 }
4628
4629 ConstSubnetPtr subnet = ctx.subnet_;
4630 // Silently ignore message which can't be localized
4631 if (!subnet) {
4632 return (Pkt6Ptr());
4633 }
4634
4635 Pkt6Ptr addr_reg_inf = ctx.query_;
4636
4637 // Get the client source address.
4638 IOAddress addr = addr_reg_inf->getRemoteAddr();
4639 // If there are some relays get the peer address of the closest relay
4640 // to the client.
4641 size_t relay_level = addr_reg_inf->relay_info_.size();
4642 if (relay_level > 0) {
4643 addr = addr_reg_inf->getRelay6PeerAddress(relay_level - 1);
4644 }
4645
4646 Option6IAAddrPtr iaaddr;
4647 Lease6Ptr old_lease;
4648 const uint32_t no_iaid = 0; /* there's no IAID in the ADDR-REG-INFORM */
4649
4650 // Check if the message is bad and shout be dropped.
4651 bool invalid = false;
4652 try {
4653 // Check there is no IA_NA option.
4654 if (addr_reg_inf->getOption(D6O_IA_NA)) {
4655 invalid = true;
4656 StatsMgr::instance().addValue("pkt6-rfc-violation",
4657 static_cast<int64_t>(1));
4658 isc_throw(RFCViolation, "unexpected IA_NA option");
4659 }
4660
4661 // Check there is no IA_TA option.
4662 if (addr_reg_inf->getOption(D6O_IA_TA)) {
4663 invalid = true;
4664 StatsMgr::instance().addValue("pkt6-rfc-violation",
4665 static_cast<int64_t>(1));
4666 isc_throw(RFCViolation, "unexpected IA_TA option");
4667 }
4668
4669 // Check there is no IA_PD option.
4670 if (addr_reg_inf->getOption(D6O_IA_PD)) {
4671 invalid = true;
4672 StatsMgr::instance().addValue("pkt6-rfc-violation",
4673 static_cast<int64_t>(1));
4674 isc_throw(RFCViolation, "unexpected IA_PD option");
4675 }
4676
4677 // Get IAADDR from the Address registration inform.
4678 // There must be one.
4679 OptionCollection addrs = addr_reg_inf->getOptions(D6O_IAADDR);
4680 if (addrs.size() != 1) {
4681 invalid = true;
4682 StatsMgr::instance().addValue("pkt6-rfc-violation",
4683 static_cast<int64_t>(1));
4684 isc_throw(RFCViolation, "Exactly 1 IAADDR option expected, but "
4685 << addrs.size() << " received");
4686 }
4687 iaaddr = boost::dynamic_pointer_cast<Option6IAAddr>(addrs.begin()->second);
4688 if (!iaaddr) {
4689 invalid = true;
4690 StatsMgr::instance().addValue("pkt6-rfc-violation",
4691 static_cast<int64_t>(1));
4692 isc_throw(Unexpected, "can't convert the IAADDR option");
4693 }
4694
4695 // Client and IADDR addresses must match.
4696 if (addr != iaaddr->getAddress()) {
4697 invalid = true;
4698 StatsMgr::instance().addValue("pkt6-rfc-violation",
4699 static_cast<int64_t>(1));
4700 isc_throw(RFCViolation, "Address mismatch: client at " << addr
4701 << " wants to register " << iaaddr->getAddress());
4702 }
4703
4704 // Should be in the subnet.
4705 if (!subnet->inRange(addr)) {
4706 StatsMgr::instance().addValue("pkt6-rfc-violation",
4707 static_cast<int64_t>(1));
4708 isc_throw(RFCViolation, "Address " << addr << " is not in subnet "
4709 << subnet->toText() << " (id " << subnet->getID() << ")");
4710 }
4711
4712 // Check if there is a lease for the address.
4714 addr);
4715
4716 // Address registration can't be mixed with standard allocation.
4717 if (old_lease && (old_lease->state_ != Lease6::STATE_REGISTERED)) {
4718 invalid = true;
4719 StatsMgr::instance().addValue("pkt6-rfc-violation",
4720 static_cast<int64_t>(1));
4721 isc_throw(RFCViolation, "Address " << addr << " already in use "
4722 << *old_lease);
4723 }
4724
4725 // Address must not be reserved.
4726 auto hosts = HostMgr::instance().getAll6(addr);
4727 if (!hosts.empty()) {
4728 invalid = true;
4729 StatsMgr::instance().addValue("pkt6-rfc-violation",
4730 static_cast<int64_t>(1));
4731 isc_throw(RFCViolation, "Address " << addr << " is reserved");
4732 }
4733 } catch (const std::exception &ex) {
4734 // Incoming processing failed.
4736 .arg(addr)
4737 .arg(ex.what());
4738 if (!invalid) {
4739 StatsMgr::instance().addValue("pkt6-processing-failed",
4740 static_cast<int64_t>(1));
4741 }
4742 StatsMgr::instance().addValue("pkt6-receive-drop",
4743 static_cast<int64_t>(1));
4744 return (Pkt6Ptr());
4745 }
4746
4747 // Check if the client is the same.
4748 if (old_lease) {
4749 if (old_lease->duid_ && (*ctx.duid_ != *(old_lease->duid_))) {
4751 .arg(addr)
4752 .arg(ctx.duid_->toText())
4753 .arg(old_lease->duid_->toText());
4754 }
4755 }
4756
4757 // Build response.
4758 Pkt6Ptr addr_reg_rep(new Pkt6(DHCPV6_ADDR_REG_REPLY,
4759 addr_reg_inf->getTransid()));
4760 addr_reg_rep->addOption(iaaddr);
4761
4762 // Set per-IA context values for DDNS.
4763 // Note the address is considered as not-temporary address.
4764 ctx.createIAContext();
4766 ctx.currentIA().iaid_ = no_iaid;
4767 Option6IAPtr ia(new Option6IA(D6O_IA_NA, no_iaid));
4768 ia->addOption(iaaddr);
4769 ctx.currentIA().ia_rsp_ = ia;
4770
4771 // Process FQDN.
4772 processClientFqdn(addr_reg_inf, addr_reg_rep, ctx);
4773
4774 Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, ctx.duid_,
4775 no_iaid, iaaddr->getPreferred(),
4776 iaaddr->getValid(), subnet->getID(),
4777 ctx.hwaddr_));
4778 lease->state_ = Lease6::STATE_REGISTERED;
4779 lease->fqdn_fwd_ = ctx.fwd_dns_update_;
4780 lease->fqdn_rev_ = ctx.rev_dns_update_;
4781 lease->hostname_ = ctx.hostname_;
4782
4783 conditionallySetReservedClientClasses(addr_reg_inf, ctx);
4784 // Evaluate additional classes.
4785 evaluateAdditionalClasses(addr_reg_inf, ctx);
4786
4788 .arg(addr_reg_inf->getLabel())
4789 .arg(addr_reg_inf->getName())
4790 .arg(addr_reg_inf->getClasses().toText());
4791
4792 copyClientOptions(addr_reg_inf, addr_reg_rep);
4793 CfgOptionList co_list;
4794 buildCfgOptionList(addr_reg_inf, ctx, co_list);
4795 // The RFC says to not do that...
4796 appendDefaultOptions(addr_reg_inf, addr_reg_rep, co_list);
4797 appendRequestedOptions(addr_reg_inf, addr_reg_rep, co_list);
4798 appendRequestedVendorOptions(addr_reg_inf, addr_reg_rep, ctx, co_list);
4799
4800 // Handle the "addr6_register" callout point.
4801 bool skip = false;
4802 if (HooksManager::calloutsPresent(Hooks.hook_index_addr6_register_)) {
4803 CalloutHandlePtr callout_handle = getCalloutHandle(addr_reg_inf);
4804 ScopedCalloutHandleState callout_handle_state(callout_handle);
4805
4806 // Pass the query6 argument.
4807 ScopedEnableOptionsCopy<Pkt6> query6_options_copy(addr_reg_inf);
4808 callout_handle->setArgument("query6", addr_reg_inf);
4809
4810 // Pass the response6 argument.
4811 ScopedEnableOptionsCopy<Pkt6> rsp6_options_copy(addr_reg_rep);
4812 callout_handle->setArgument("response6", addr_reg_rep);
4813
4814 // Pass the address6 argument.
4815 callout_handle->setArgument("address6", addr);
4816
4817 // Pass the old_lease argument.
4818 callout_handle->setArgument("old_lease6", old_lease);
4819
4820 // Pass the new_lease argument.
4821 callout_handle->setArgument("new_lease6", lease);
4822
4823 // Call callouts
4824 HooksManager::callCallouts(Hooks.hook_index_addr6_register_, *callout_handle);
4825
4826 // Callouts decided to skip the next processing step. This means
4827 // to not perform the lease operation.
4828 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) {
4831 .arg(addr_reg_inf->getLabel())
4832 .arg(old_lease ? "update" : "add")
4833 .arg(addr);
4834 skip = true;
4835 } else
4836 // Callouts decided to drop the next processing step. This means
4837 // cancel processing so drop the query.
4838 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP) {
4841 .arg(addr_reg_inf->getLabel())
4842 .arg(addr);
4843 return (Pkt6Ptr());
4844 }
4845 }
4846
4847 if (!skip) {
4848 // Statefull registration.
4849 if (old_lease) {
4850 try {
4852 } catch (const std::exception& ex) {
4853 // Assume that stats and DNS were handled by someone else.
4855 .arg(addr)
4856 .arg(ex.what());
4857 return (Pkt6Ptr());
4858 }
4859 // Save the old lease for the DNS update.
4860 ctx.currentIA().changed_leases_.push_back(old_lease);
4861 // Update stats when the subnet changed.
4862 if (old_lease->subnet_id_ != lease->subnet_id_) {
4864 StatsMgr::generateName("subnet", old_lease->subnet_id_,
4865 "registered-nas"),
4866 static_cast<int64_t>(-1));
4868 StatsMgr::generateName("subnet", lease->subnet_id_,
4869 "registered-nas"),
4870 static_cast<int64_t>(1));
4872 StatsMgr::generateName("subnet", lease->subnet_id_,
4873 "cumulative-registered-nas"),
4874 static_cast<int64_t>(1));
4875 }
4876 } else {
4877 if (!LeaseMgrFactory::instance().addLease(lease)) {
4878 // Assume that stats and DNS were handled by someone else.
4880 .arg(addr);
4881 return (Pkt6Ptr());
4882 }
4883 // Update stats.
4885 StatsMgr::generateName("subnet", lease->subnet_id_,
4886 "registered-nas"),
4887 static_cast<int64_t>(1));
4889 StatsMgr::generateName("subnet", lease->subnet_id_,
4890 "cumulative-registered-nas"),
4891 static_cast<int64_t>(1));
4892 StatsMgr::instance().addValue("cumulative-registered-nas",
4893 static_cast<int64_t>(1));
4894 }
4895 // Save the new lease for the leases6_committed callout.
4896 ctx.new_leases_.push_back(lease);
4897 }
4898
4899 // Deal with FQDN.
4900 updateReservedFqdn(ctx, addr_reg_rep);
4901 generateFqdn(addr_reg_rep, ctx);
4902 createNameChangeRequests(addr_reg_rep, ctx);
4903
4904 return (addr_reg_rep);
4905}
4906
4907void Dhcpv6Srv::classifyByVendor(const Pkt6Ptr& pkt) {
4908 OptionVendorClassPtr vclass;
4909 for (auto const& opt : pkt->getOptions(D6O_VENDOR_CLASS)) {
4910 vclass = boost::dynamic_pointer_cast<OptionVendorClass>(opt.second);
4911 if (!vclass || vclass->getTuplesNum() == 0) {
4912 continue;
4913 }
4914
4915 if (vclass->hasTuple(DOCSIS3_CLASS_MODEM)) {
4917
4918 } else if (vclass->hasTuple(DOCSIS3_CLASS_EROUTER)) {
4920
4921 } else {
4922 string escaped = ClientClasses::escape(vclass->getTuple(0).getText());
4923 pkt->addClass(VENDOR_CLASS_PREFIX + escaped);
4924 }
4925 }
4926}
4927
4929 // All packets belong to ALL.
4930 pkt->addClass("ALL");
4931
4932 // First: built-in vendor class processing
4933 classifyByVendor(pkt);
4934
4935 // Run match expressions on classes not depending on KNOWN/UNKNOWN.
4936 evaluateClasses(pkt, false);
4937}
4938
4939void Dhcpv6Srv::evaluateClasses(const Pkt6Ptr& pkt, bool depend_on_known) {
4940 // Note getClientClassDictionary() cannot be null
4941 const ClientClassDictionaryPtr& dict =
4942 CfgMgr::instance().getCurrentCfg()->getClientClassDictionary();
4943 const ClientClassDefListPtr& defs_ptr = dict->getClasses();
4944 for (auto const& it : *defs_ptr) {
4945 // Note second cannot be null
4946 const ExpressionPtr& expr_ptr = it->getMatchExpr();
4947 // Nothing to do without an expression to evaluate
4948 if (!expr_ptr) {
4949 continue;
4950 }
4951 // Not the right time if only when required
4952 if (it->getAdditional()) {
4953 continue;
4954 }
4955 // Not the right pass.
4956 if (it->getDependOnKnown() != depend_on_known) {
4957 continue;
4958 }
4959 it->test(pkt, expr_ptr);
4960 }
4961}
4962
4963void
4965 const ClientClassDictionaryPtr& dict =
4966 CfgMgr::instance().getCurrentCfg()->getClientClassDictionary();
4967 const ClientClassDefListPtr& defs_ptr = dict->getClasses();
4968 for (auto const& def : *defs_ptr) {
4969 // Only remove evaluated classes. Other classes can be
4970 // assigned via hooks libraries and we should not remove
4971 // them because there is no way they can be added back.
4972 if (def->getMatchExpr()) {
4973 pkt->classes_.erase(def->getName());
4974 }
4975 }
4976}
4977
4978void
4980 const AllocEngine::ClientContext6& ctx) {
4981 if (ctx.currentHost() && pkt) {
4982 const ClientClasses& classes = ctx.currentHost()->getClientClasses6();
4983 for (auto const& cclass : classes) {
4984 pkt->addClass(cclass);
4985 }
4986 }
4987}
4988
4989void
4991 const AllocEngine::ClientContext6& ctx) {
4992 if (ctx.subnet_) {
4993 SharedNetwork6Ptr shared_network;
4994 ctx.subnet_->getSharedNetwork(shared_network);
4995 if (shared_network) {
4996 ConstHostPtr host = ctx.currentHost();
4997 if (host && (host->getIPv6SubnetID() != SUBNET_ID_GLOBAL)) {
4998 setReservedClientClasses(pkt, ctx);
4999 }
5000 }
5001 }
5002}
5003
5004void
5006 // Get additional classes to evaluate added elsewhere, possibly by hooks.
5007 ClientClasses classes = pkt->getAdditionalClasses();
5008 ConstSubnet6Ptr subnet = ctx.subnet_;
5009
5010 if (subnet) {
5011 // host reservation???
5012
5013 // Begin by pools
5014 for (auto const& resource : ctx.allocated_resources_) {
5015 PoolPtr pool =
5016 ctx.subnet_->getPool(resource.getPrefixLength() == 128 ?
5018 resource.getAddress(),
5019 false);
5020 if (pool) {
5021 const ClientClasses& pool_to_add = pool->getAdditionalClasses();
5022 for (auto const& cclass : pool_to_add) {
5023 classes.insert(cclass);
5024 }
5025 }
5026 }
5027
5028 // Followed by the subnet
5029 const ClientClasses& to_add = subnet->getAdditionalClasses();
5030 for (auto const& cclass : to_add) {
5031 classes.insert(cclass);
5032 }
5033
5034 // And finish by the shared-network
5035 SharedNetwork6Ptr network;
5036 subnet->getSharedNetwork(network);
5037 if (network) {
5038 const ClientClasses& net_to_add = network->getAdditionalClasses();
5039 for (auto const& cclass : net_to_add) {
5040 classes.insert(cclass);
5041 }
5042 }
5043 }
5044
5045 // Run match expressions
5046 // Note getClientClassDictionary() cannot be null
5047 const ClientClassDictionaryPtr& dict =
5048 CfgMgr::instance().getCurrentCfg()->getClientClassDictionary();
5049 for (auto const& cclass : classes) {
5050 const ClientClassDefPtr class_def = dict->findClass(cclass);
5051 if (!class_def) {
5054 .arg(cclass);
5055 // Ignore it as it can't have an attached action
5056 continue;
5057 }
5058 const ExpressionPtr& expr_ptr = class_def->getMatchExpr();
5059 // Add a class without an expression to evaluate
5060 if (!expr_ptr) {
5063 .arg(cclass);
5064 pkt->addClass(cclass);
5065 continue;
5066 }
5067 // Evaluate the expression which can return false (no match),
5068 // true (match) or raise an exception (error)
5069 try {
5070 bool status = evaluateBool(*expr_ptr, *pkt);
5072 .arg(pkt->getLabel())
5073 .arg(cclass)
5074 .arg(status ? "true" : "false");
5075 if (status) {
5076 // Matching: add the class
5077 pkt->addClass(cclass);
5078 }
5079 } catch (const Exception& ex) {
5081 .arg(pkt->getLabel())
5082 .arg(cclass)
5083 .arg(ex.what());
5084 }
5085 }
5086}
5087
5088void
5089Dhcpv6Srv::updateReservedFqdn(AllocEngine::ClientContext6& ctx,
5090 const Pkt6Ptr& answer) {
5091 if (!answer) {
5092 isc_throw(isc::Unexpected, "an instance of the object encapsulating"
5093 " a message must not be NULL when updating reserved FQDN");
5094 }
5095
5096 Option6ClientFqdnPtr fqdn = boost::dynamic_pointer_cast<Option6ClientFqdn>
5097 (answer->getOption(D6O_CLIENT_FQDN));
5098
5099 // If Client FQDN option is not included, there is nothing to do.
5100 if (!fqdn) {
5101 return;
5102 }
5103
5104 std::string name = fqdn->getDomainName();
5105
5106 // If there is a host reservation for this client we have to check whether
5107 // this reservation has the same hostname as the hostname currently
5108 // present in the FQDN option. If not, it indicates that the allocation
5109 // engine picked a different subnet (from within a shared network) for
5110 // reservations and we have to send this new value to the client.
5111 if (ctx.currentHost() &&
5112 !ctx.currentHost()->getHostname().empty()) {
5113 std::string new_name = CfgMgr::instance().getD2ClientMgr().
5114 qualifyName(ctx.currentHost()->getHostname(), *ctx.getDdnsParams(), true);
5115
5116 if (new_name != name) {
5117 fqdn->setDomainName(new_name, Option6ClientFqdn::FULL);
5118
5119 // Replace previous instance of Client FQDN option.
5120 answer->delOption(D6O_CLIENT_FQDN);
5121 answer->addOption(fqdn);
5122 }
5123 }
5124}
5125
5126void
5127Dhcpv6Srv::generateFqdn(const Pkt6Ptr& answer,
5128 AllocEngine::ClientContext6& ctx) {
5129 if (!answer) {
5130 isc_throw(isc::Unexpected, "an instance of the object encapsulating"
5131 " a message must not be NULL when generating FQDN");
5132 }
5133
5136
5137 // It is likely that client hasn't included the FQDN option. In such case,
5138 // FQDN option will be NULL. Also, there is nothing to do if the option
5139 // is present and conveys the non-empty FQDN.
5140 Option6ClientFqdnPtr fqdn = boost::dynamic_pointer_cast<
5141 Option6ClientFqdn>(answer->getOption(D6O_CLIENT_FQDN));
5142 if (!fqdn || !fqdn->getDomainName().empty()) {
5143 return;
5144 }
5145
5146 // Get the first IA_NA acquired for the client.
5147 OptionPtr ia = answer->getOption(D6O_IA_NA);
5148 if (!ia) {
5149 return;
5150 }
5151
5152 // If it has any IAAddr with a valid lifetime > 0, use it to
5153 // generate unique FQDN.
5154 Option6IAAddrPtr iaaddr = boost::dynamic_pointer_cast<
5155 Option6IAAddr>(ia->getOption(D6O_IAADDR));
5156 if (!iaaddr || iaaddr->getValid() == 0) {
5157 return;
5158 }
5159
5160 // Get the IPv6 address acquired by the client.
5161 IOAddress addr = iaaddr->getAddress();
5162 std::string generated_name =
5164
5166 .arg(answer->getLabel())
5167 .arg(generated_name);
5168
5169 try {
5170 // The lease has been acquired but the FQDN for this lease hasn't
5171 // been updated in the lease database. We now have new FQDN
5172 // generated, so the lease database has to be updated here.
5173 // However, never update lease database for Advertise, just send
5174 // our notion of client's FQDN in the Client FQDN option.
5175 if (answer->getType() != DHCPV6_ADVERTISE) {
5176 Lease6Ptr lease;
5177 for (auto const& l : ctx.new_leases_) {
5178 if ((l->type_ == Lease::TYPE_NA) && (l->addr_ == addr)) {
5179 lease = l;
5180 break;
5181 }
5182 }
5183 if (lease) {
5184 lease->hostname_ = generated_name;
5185 lease->reuseable_valid_lft_ = 0;
5187
5188 } else {
5189 isc_throw(isc::Unexpected, "there is no lease in the database "
5190 " for address " << addr << ", so as it is impossible"
5191 " to update FQDN data. This is a programmatic error"
5192 " as the given address is now being handed to the"
5193 " client");
5194 }
5195 }
5196 // Set the generated FQDN in the Client FQDN option.
5197 fqdn->setDomainName(generated_name, Option6ClientFqdn::FULL);
5198
5199 answer->delOption(D6O_CLIENT_FQDN);
5200 answer->addOption(fqdn);
5201 ctx.hostname_ = generated_name;
5202 } catch (const Exception& ex) {
5204 .arg(answer->getLabel())
5205 .arg(addr.toText())
5206 .arg(ex.what());
5207 }
5208}
5209
5210void
5213 if (d2_mgr.ddnsEnabled()) {
5214 // Updates are enabled, so lets start the sender, passing in
5215 // our error handler.
5216 // This may throw so wherever this is called needs to ready.
5218 this, ph::_1, ph::_2));
5219 }
5220}
5221
5222void
5225 if (d2_mgr.ddnsEnabled()) {
5226 // Updates are enabled, so lets stop the sender
5227 d2_mgr.stop();
5228 d2_mgr.stopSender();
5229 }
5230}
5231
5232void
5236 .arg(NameChangeSender::resultToText(result))
5237 .arg((ncr ? ncr->toText() : " NULL "));
5238 // We cannot communicate with kea-dhcp-ddns, suspend further updates.
5242}
5243
5244std::string
5246 std::stringstream tmp;
5247
5248 tmp << VERSION;
5249 if (extended) {
5250 tmp << " (" << SOURCE_OF_INSTALLATION << ")" << endl;
5251 tmp << "premium: " << PREMIUM_EXTENDED_VERSION << endl;
5252 tmp << "linked with:" << endl;
5253 tmp << "- " << Logger::getVersion() << endl;
5254 tmp << "- " << CryptoLink::getVersion();
5256 if (info.size()) {
5257 tmp << endl << "lease backends:";
5258 for (auto const& version : info) {
5259 tmp << endl << "- " << version;
5260 }
5261 }
5263 if (info.size()) {
5264 tmp << endl << "host backends:";
5265 for (auto const& version : info) {
5266 tmp << endl << "- " << version;
5267 }
5268 }
5270 if (info.size()) {
5271 tmp << endl << "forensic backends:";
5272 for (auto const& version : info) {
5273 tmp << endl << "- " << version;
5274 }
5275 }
5276 // @todo: more details about database runtime
5277 }
5278
5279 return (tmp.str());
5280}
5281
5282void Dhcpv6Srv::processRSOO(const Pkt6Ptr& query, const Pkt6Ptr& rsp) {
5283
5284 if (query->relay_info_.empty()) {
5285 // RSOO is inserted by relay agents, nothing to do here if it's
5286 // a direct message.
5287 return;
5288 }
5289
5290 // Get RSOO configuration.
5291 ConstCfgRSOOPtr cfg_rsoo = CfgMgr::instance().getCurrentCfg()->getCfgRSOO();
5292
5293 // Let's get over all relays (encapsulation levels). We need to do
5294 // it in the same order as the client packet traversed the relays.
5295 for (int i = query->relay_info_.size(); i > 0 ; --i) {
5296 OptionPtr rsoo_container = query->getRelayOption(D6O_RSOO, i - 1);
5297 if (rsoo_container) {
5298 // There are RSOO options. Let's get through them one by one
5299 // and if it's RSOO-enabled and there's no such option provided yet,
5300 // copy it to the server's response
5301 const OptionCollection& rsoo = rsoo_container->getOptions();
5302 for (auto const& opt : rsoo) {
5303
5304 // Echo option if it is RSOO enabled option and there is no such
5305 // option added yet.
5306 if (cfg_rsoo->enabled(opt.second->getType()) &&
5307 !rsp->getOption(opt.second->getType())) {
5308 rsp->addOption(opt.second);
5309 }
5310 }
5311 }
5312 }
5313}
5314
5316
5317 if (query->relay_info_.empty()) {
5318 // No relay agent
5319 return (0);
5320 }
5321
5322 // Did the last relay agent add a relay-source-port?
5323 if (query->getRelayOption(D6O_RELAY_SOURCE_PORT, 0)) {
5324 // RFC 8357 section 5.2
5325 return (query->getRemotePort());
5326 }
5327
5328 return (0);
5329}
5330
5331void Dhcpv6Srv::processStatsReceived(const Pkt6Ptr& query) {
5332 // Note that we're not bumping pkt6-received statistic as it was
5333 // increased early in the packet reception code.
5334
5335 string stat_name = "pkt6-unknown-received";
5336 switch (query->getType()) {
5337 case DHCPV6_SOLICIT:
5338 stat_name = "pkt6-solicit-received";
5339 break;
5340 case DHCPV6_ADVERTISE:
5341 // Should not happen, but let's keep a counter for it
5342 stat_name = "pkt6-advertise-received";
5343 break;
5344 case DHCPV6_REQUEST:
5345 stat_name = "pkt6-request-received";
5346 break;
5347 case DHCPV6_CONFIRM:
5348 stat_name = "pkt6-confirm-received";
5349 break;
5350 case DHCPV6_RENEW:
5351 stat_name = "pkt6-renew-received";
5352 break;
5353 case DHCPV6_REBIND:
5354 stat_name = "pkt6-rebind-received";
5355 break;
5356 case DHCPV6_REPLY:
5357 // Should not happen, but let's keep a counter for it
5358 stat_name = "pkt6-reply-received";
5359 break;
5360 case DHCPV6_RELEASE:
5361 stat_name = "pkt6-release-received";
5362 break;
5363 case DHCPV6_DECLINE:
5364 stat_name = "pkt6-decline-received";
5365 break;
5366 case DHCPV6_RECONFIGURE:
5367 stat_name = "pkt6-reconfigure-received";
5368 break;
5370 stat_name = "pkt6-infrequest-received";
5371 break;
5373 stat_name = "pkt6-dhcpv4-query-received";
5374 break;
5376 // Should not happen, but let's keep a counter for it
5377 stat_name = "pkt6-dhcpv4-response-received";
5378 break;
5380 stat_name = "pkt6-addr-reg-inform-received";
5381 break;
5383 // Should not happen, but let's keep a counter for it
5384 stat_name = "pkt6-addr-reg-reply-received";
5385 break;
5386 default:
5387 ; // do nothing
5388 }
5389
5390 StatsMgr::instance().addValue(stat_name, static_cast<int64_t>(1));
5391}
5392
5394 // Increase generic counter for sent packets.
5395 StatsMgr::instance().addValue("pkt6-sent", static_cast<int64_t>(1));
5396
5397 // Increase packet type specific counter for packets sent.
5398 string stat_name;
5399 switch (response->getType()) {
5400 case DHCPV6_ADVERTISE:
5401 stat_name = "pkt6-advertise-sent";
5402 break;
5403 case DHCPV6_REPLY:
5404 stat_name = "pkt6-reply-sent";
5405 break;
5407 stat_name = "pkt6-dhcpv4-response-sent";
5408 break;
5410 stat_name = "pkt6-addr-reg-reply-sent";
5411 break;
5412 default:
5413 // That should never happen
5414 return;
5415 }
5416
5417 StatsMgr::instance().addValue(stat_name, static_cast<int64_t>(1));
5418}
5419
5421 return (Hooks.hook_index_buffer6_send_);
5422}
5423
5424bool
5425Dhcpv6Srv::requestedInORO(const Pkt6Ptr& query, const uint16_t code) const {
5427 boost::dynamic_pointer_cast<OptionUint16Array>(query->getOption(D6O_ORO));
5428
5429 if (oro) {
5430 const std::vector<uint16_t>& codes = oro->getValues();
5431 return (std::find(codes.begin(), codes.end(), code) != codes.end());
5432 }
5433
5434 return (false);
5435}
5436
5437tuple<bool, uint32_t>
5438Dhcpv6Srv::parkingLimitExceeded(string const& hook_label) {
5439 // Get the parking limit. Parsing should ensure the value is present.
5440 uint32_t parked_packet_limit(0);
5441 ConstElementPtr const& ppl(
5442 CfgMgr::instance().getCurrentCfg()->getConfiguredGlobal(CfgGlobals::PARKED_PACKET_LIMIT));
5443 if (ppl) {
5444 parked_packet_limit = ppl->intValue();
5445 }
5446
5447 if (parked_packet_limit) {
5448 ParkingLotPtr const& parking_lot(
5449 ServerHooks::getServerHooks().getParkingLotPtr(hook_label));
5450
5451 if (parking_lot && parked_packet_limit <= parking_lot->size()) {
5452 return make_tuple(true, parked_packet_limit);
5453 }
5454 }
5455 return make_tuple(false, parked_packet_limit);
5456}
5457
5458
5460 // Dump all of our current packets, anything that is mid-stream
5462}
5463
5465#ifdef FUZZING
5466 char const* const rotate(getenv("KEA_DHCP6_FUZZING_ROTATE_PORT"));
5467 if (rotate) {
5468 InterprocessSyncFile file("kea-dhcp6-fuzzing-rotate-port");
5470 while (!locker.lock()) {
5471 this_thread::sleep_for(1s);
5472 }
5473 fstream port_file;
5474 port_file.open("/tmp/port6.txt", ios::in);
5475 string line;
5476 int port;
5477 getline(port_file, line);
5478 port_file.close();
5479 if (line.empty()) {
5480 port = 2000;
5481 } else {
5482 port = stoi(line);
5483 if (port < 3000) {
5484 ++port;
5485 } else {
5486 port = 2000;
5487 }
5488 }
5489 port_file.open("/tmp/port6.txt", ios::out | ios::trunc);
5490 port_file << to_string(port) << endl;
5491 port_file.close();
5492 locker.unlock();
5493 return port;
5494 }
5495#endif // FUZZING
5496 return server_port_;
5497}
5498
5500void
5501Dhcpv6Srv::setTeeTimes(uint32_t preferred_lft,
5502 const ConstSubnet6Ptr& subnet,
5503 Option6IAPtr& resp) {
5504 // Default T2 time to zero.
5505 uint32_t t2_time = 0;
5506
5507 // If T2 is explicitly configured we'll use that value.
5508 if (!subnet->getT2().unspecified()) {
5509 t2_time = subnet->getT2();
5510 } else if (subnet->getCalculateTeeTimes()) {
5511 // Calculating tee times is enabled, so calculate it.
5512 t2_time = static_cast<uint32_t>(round(subnet->getT2Percent() * preferred_lft));
5513 }
5514
5515 // We allow T2 to be any value.
5516 resp->setT2(t2_time);
5517
5518 // Default T1 time to zero.
5519 uint32_t t1_time = 0;
5520
5521 // If T1 is explicitly configured we'll use try value.
5522 if (!subnet->getT1().unspecified()) {
5523 t1_time = subnet->getT1();
5524 } else if (subnet->getCalculateTeeTimes()) {
5525 // Calculating tee times is enabled, so calculate it.
5526 t1_time = static_cast<uint32_t>(round(subnet->getT1Percent() * preferred_lft));
5527 }
5528
5529 // T1 is sane if it is less than or equal to T2.
5530 if (t1_time < t2_time) {
5531 resp->setT1(t1_time);
5532 } else {
5533 // It's either explicitly 0 or insane, leave it to the client
5534 resp->setT1(0);
5535 }
5536}
5537
5538void
5541 const ConstSubnet6Ptr orig_subnet) {
5542 bool reprocess_client_name = false;
5543
5544 // Find the pool to which the first active lease address belongs and use it
5545 // to update DDNS parameters to include those from the pool.
5546 OptionPtr ia = answer->getOption(D6O_IA_NA);
5547 if (ia) {
5548 Option6IAAddrPtr iaaddr = boost::dynamic_pointer_cast<Option6IAAddr>(ia->getOption(D6O_IAADDR));
5549 if (iaaddr && (iaaddr->getValid() > 0)) {
5550 auto ddns_params = ctx.getDdnsParams();
5551 auto pool = ddns_params->setPoolFromAddress(iaaddr->getAddress());
5552 if (pool) {
5553 // If the pool has any DDNS parameters we need to recalculate the FQDN.
5554 reprocess_client_name = pool->hasDdnsParameters();
5555 }
5556 }
5557 }
5558
5559 // Check if the subnet was dynamically changed by the allocation engine.
5560 if (ctx.subnet_ && orig_subnet && (orig_subnet->getID() != ctx.subnet_->getID())) {
5561 // We get the network for logging only. It should always be set as
5562 // this a dynamic change should only happen within shared-networks.
5563 // Not having one might not be an error if a hook changed the subnet?
5564 SharedNetwork6Ptr network;
5565 orig_subnet->getSharedNetwork(network);
5567 .arg(question->getLabel())
5568 .arg(orig_subnet->toText())
5569 .arg(ctx.subnet_->toText())
5570 .arg(network ? network->getName() : "<no network?>");
5571
5572 // The subnet changed so we need to recalculate the FQDN.
5573 reprocess_client_name = true;
5574 }
5575
5576 // Recalulate the FQDN if either the pool has DDNS parameters or the
5577 // selected subnet was changed.
5578 if (reprocess_client_name) {
5579 // Save the current DNS values on the context.
5580 std::string prev_hostname = ctx.hostname_;
5581 bool prev_fwd_dns_update = ctx.fwd_dns_update_;
5582 bool prev_rev_dns_update = ctx.rev_dns_update_;
5583
5584 // Remove the current FQDN option from the answer.
5585 answer->delOption(D6O_CLIENT_FQDN);
5586
5587 // Recalculate the client's FQDN. This will replace the FQDN option and
5588 // update the context values for hostname_ and DNS directions.
5589 processClientFqdn(question, answer, ctx);
5590
5591 // If this is a real allocation and the DNS values changed we need to
5592 // update the leases.
5593 if (!ctx.fake_allocation_ &&
5594 ((prev_hostname != ctx.hostname_) ||
5595 (prev_fwd_dns_update != ctx.fwd_dns_update_) ||
5596 (prev_rev_dns_update != ctx.rev_dns_update_))) {
5597 for (auto const& l : ctx.new_leases_) {
5598 l->hostname_ = ctx.hostname_;
5599 l->fqdn_fwd_ = ctx.fwd_dns_update_;
5600 l->fqdn_rev_ = ctx.rev_dns_update_;
5601 l->reuseable_valid_lft_ = 0;
5603 }
5604 }
5605 }
5606}
5607
5608std::list<std::list<std::string>> Dhcpv6Srv::jsonPathsToRedact() const{
5609 static std::list<std::list<std::string>> const list({
5610 {"config-control", "config-databases", "[]"},
5611 {"hooks-libraries", "[]", "parameters", "*"},
5612 {"hosts-database"},
5613 {"hosts-databases", "[]"},
5614 {"lease-database"},
5615 });
5616 return list;
5617}
5618
5619} // namespace dhcp
5620} // namespace isc
Defines elements for storing the names of client classes.
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown when an unexpected error condition occurs.
Defines a single hint.
DHCPv4 and DHCPv6 allocation engine.
std::vector< Resource > HintContainer
Container for client's hints.
Implementation of the mechanisms to control the use of the Configuration Backends by the DHCPv6 serve...
D2ClientMgr & getD2ClientMgr()
Fetches the DHCP-DDNS manager.
Definition cfgmgr.cc:69
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 SubnetSelector initSelector(const Pkt6Ptr &query)
Build selector from a client's message.
Container for storing client class names.
Definition classify.h:111
void insert(const ClientClass &class_name)
Insert an element.
Definition classify.h:161
static std::string escape(const std::string &name, bool escape_escape=true)
Escape a client class name.
Definition classify.cc:164
std::string toText(const std::string &separator=", ") const
Returns all class names as text.
Definition classify.cc:77
Client race avoidance RAII handler.
bool tryLock(Pkt4Ptr query, ContinuationPtr cont=ContinuationPtr())
Tries to acquires a client.
D2ClientMgr isolates Kea from the details of being a D2 client.
std::string generateFqdn(const asiolink::IOAddress &address, const DdnsParams &ddns_params, const bool trailing_dot=true) const
Builds a FQDN based on the configuration and given IP address.
bool ddnsEnabled()
Convenience method for checking if DHCP-DDNS is enabled.
void getUpdateDirections(const T &fqdn_resp, bool &forward, bool &reverse)
Get directional update flags based on server FQDN flags.
void stop()
Stop the sender.
void suspendUpdates()
Suspends sending requests.
void adjustDomainName(const T &fqdn, T &fqdn_resp, const DdnsParams &ddns_params)
Set server FQDN name based on configuration and a given FQDN.
void sendRequest(dhcp_ddns::NameChangeRequestPtr &ncr)
Send the given NameChangeRequests to kea-dhcp-ddns.
void stopSender()
Disables sending NameChangeRequests to kea-dhcp-ddns.
void adjustFqdnFlags(const T &fqdn, T &fqdn_resp, const DdnsParams &ddns_params)
Set server FQDN flags based on configuration and a given FQDN.
std::string qualifyName(const std::string &partial_name, const DdnsParams &ddns_params, const bool trailing_dot) const
Adds a qualifying suffix to a given domain name.
void startSender(D2ClientErrorHandler error_handler, const isc::asiolink::IOServicePtr &io_service)
Enables sending NameChangeRequests to kea-dhcp-ddns.
This exception is thrown when DHCP server hits the error which should result in discarding the messag...
Definition dhcp6_srv.h:48
Factory for generating DUIDs (DHCP Unique Identifiers).
DuidPtr get()
Returns current DUID.
Holds DUID (DHCPv6 Unique Identifier).
Definition duid.h:142
static constexpr size_t MIN_DUID_LEN
minimum duid size
Definition duid.h:149
static const DUID & EMPTY()
Defines the constant "empty" DUID.
Definition duid.cc:55
static constexpr size_t MAX_DUID_LEN
maximum duid size
Definition duid.h:155
const std::vector< uint8_t > & getDuid() const
Returns a const reference to the actual DUID value.
Definition duid.cc:33
void send(const Pkt6Ptr &pkt)
Send message over IPC.
void close()
Close communication socket.
static Dhcp6to4Ipc & instance()
Returns pointer to the sole instance of Dhcp6to4Ipc.
static uint16_t client_port
std::queue< isc::dhcp_ddns::NameChangeRequest > name_change_reqs_
Holds a list of isc::dhcp_ddns::NameChangeRequest objects, which are waiting for sending to kea-dhcp-...
Definition dhcp6_srv.h:1269
void shutdown() override
Instructs the server to shut down.
Definition dhcp6_srv.cc:373
RequirementLevel
defines if certain option may, must or must not appear
Definition dhcp6_srv.h:74
OptionPtr getServerID()
Returns server-identifier option.
Definition dhcp6_srv.h:135
OptionPtr rejectIA_PD(const isc::dhcp::Pkt6Ptr &query, Option6IAPtr ia)
Reject IA_PD.
Pkt6Ptr processPacket(Pkt6Ptr query)
Process a single incoming DHCPv6 packet.
Definition dhcp6_srv.cc:836
Pkt6Ptr processLocalizedQuery6(AllocEngine::ClientContext6 &ctx)
Process a localized incoming DHCPv6 query.
void processPacketAndSendResponseNoThrow(Pkt6Ptr query)
Process a single incoming DHCPv6 packet and sends the response.
Definition dhcp6_srv.cc:803
OptionPtr extendIA_PD(const Pkt6Ptr &query, AllocEngine::ClientContext6 &ctx, Option6IAPtr ia)
Extends lifetime of the prefix.
void setReservedClientClasses(const Pkt6Ptr &pkt, const AllocEngine::ClientContext6 &ctx)
Assigns classes retrieved from host reservation database.
Pkt6Ptr processDecline(AllocEngine::ClientContext6 &ctx)
Process incoming Decline message.
void evaluateClasses(const Pkt6Ptr &pkt, bool depend_on_known)
Evaluate classes.
Pkt6Ptr processRenew(AllocEngine::ClientContext6 &ctx)
Processes incoming Renew message.
static void processStatsSent(const Pkt6Ptr &response)
Updates statistics for transmitted packets.
void reject(const Pkt6Ptr &query, Pkt6Ptr &answer)
Reject query.
void evaluateAdditionalClasses(const Pkt6Ptr &pkt, AllocEngine::ClientContext6 &ctx)
Evaluates classes in the additional classes lists.
void processLocalizedQuery6AndSendResponse(Pkt6Ptr query, AllocEngine::ClientContext6 &ctx)
Process a localized incoming DHCPv6 query.
int run()
Main server processing loop.
Definition dhcp6_srv.cc:659
void setPacketStatisticsDefaults()
This function sets statistics related to DHCPv6 packets processing to their initial values.
Definition dhcp6_srv.cc:319
bool sanityCheck(const Pkt6Ptr &pkt)
Verifies if specified packet meets RFC requirements.
static uint16_t checkRelaySourcePort(const Pkt6Ptr &query)
Used for DHCPv4-over-DHCPv6 too.
void assignLeases(const Pkt6Ptr &question, Pkt6Ptr &answer, AllocEngine::ClientContext6 &ctx)
Assigns leases.
void stopD2()
Stops DHCP_DDNS client IO if DDNS updates are enabled.
void copyClientOptions(const Pkt6Ptr &question, Pkt6Ptr &answer)
Copies required options from client message to server answer.
boost::shared_ptr< AllocEngine > alloc_engine_
Allocation Engine.
Definition dhcp6_srv.h:1265
virtual void sendPacket(const Pkt6Ptr &pkt)
dummy wrapper around IfaceMgr::send()
Definition dhcp6_srv.cc:382
bool testServerID(const Pkt6Ptr &pkt)
Compare received server id with our server id.
Definition dhcp6_srv.cc:387
virtual void d2ClientErrorHandler(const dhcp_ddns::NameChangeSender::Result result, dhcp_ddns::NameChangeRequestPtr &ncr)
Implements the error handler for DHCP_DDNS IO errors.
OptionPtr declineIA(const Pkt6Ptr &decline, const DuidPtr &duid, int &general_status, boost::shared_ptr< Option6IA > ia, Lease6Collection &new_leases)
Declines leases in a single IA_NA option.
OptionPtr rejectIA_NA(const isc::dhcp::Pkt6Ptr &query, Option6IAPtr ia)
Reject IA_NA.
uint16_t getServerPort() const
Get UDP port on which server should listen.
void runOne()
Main server processing step.
Definition dhcp6_srv.cc:716
virtual Pkt6Ptr receivePacket(int timeout)
dummy wrapper around IfaceMgr::receive6
Definition dhcp6_srv.cc:378
void processPacketBufferSend(hooks::CalloutHandlePtr &callout_handle, Pkt6Ptr &rsp)
Executes buffer6_send callout and sends the response.
OptionPtr releaseIA_NA(const DuidPtr &duid, const Pkt6Ptr &query, int &general_status, boost::shared_ptr< Option6IA > ia, Lease6Ptr &old_lease)
Releases specific IA_NA option.
void buildCfgOptionList(const Pkt6Ptr &question, AllocEngine::ClientContext6 &ctx, CfgOptionList &co_list)
Build the configured option list.
void appendDefaultOptions(const Pkt6Ptr &question, Pkt6Ptr &answer, const CfgOptionList &co_list)
Appends default options to server's answer.
OptionPtr assignIA_NA(const isc::dhcp::Pkt6Ptr &query, AllocEngine::ClientContext6 &ctx, Option6IAPtr ia)
Processes IA_NA option (and assigns addresses if necessary).
static const std::string VENDOR_CLASS_PREFIX
this is a prefix added to the content of vendor-class option
Definition dhcp6_srv.h:999
OptionPtr serverid_
Server DUID (to be sent in server-identifier option).
Definition dhcp6_srv.h:1245
void setTeeTimes(uint32_t preferred_lft, const ConstSubnet6Ptr &subnet, Option6IAPtr &resp)
Sets the T1 and T2 timers in the outbound IA.
void conditionallySetReservedClientClasses(const Pkt6Ptr &pkt, const AllocEngine::ClientContext6 &ctx)
Assigns classes retrieved from host reservation database if they haven't been yet set.
void processPacketAndSendResponse(Pkt6Ptr query)
Process a single incoming DHCPv6 packet and sends the response.
Definition dhcp6_srv.cc:825
OptionPtr releaseIA_PD(const DuidPtr &duid, const Pkt6Ptr &query, int &general_status, boost::shared_ptr< Option6IA > ia, Lease6Ptr &old_lease)
Releases specific IA_PD option.
void processDhcp4Query(const Pkt6Ptr &dhcp4_query)
Processes incoming DHCPv4-query message.
Pkt6Ptr processRebind(AllocEngine::ClientContext6 &ctx)
Processes incoming Rebind message.
bool earlyGHRLookup(const Pkt6Ptr &query, AllocEngine::ClientContext6 &ctx)
Initialize client context and perform early global reservations lookup.
Definition dhcp6_srv.cc:499
void initContext0(const Pkt6Ptr &query, AllocEngine::ClientContext6 &ctx)
Initialize client context (first part).
Definition dhcp6_srv.cc:486
virtual ~Dhcpv6Srv()
Destructor. Used during DHCPv6 service shutdown.
Definition dhcp6_srv.cc:329
void initContext(AllocEngine::ClientContext6 &ctx, bool &drop)
Initializes client context for specified packet.
Definition dhcp6_srv.cc:565
Pkt6Ptr processRequest(AllocEngine::ClientContext6 &ctx)
Processes incoming Request and returns Reply response.
void sendResponseNoThrow(hooks::CalloutHandlePtr &callout_handle, Pkt6Ptr query, Pkt6Ptr &rsp, ConstSubnet6Ptr &subnet)
Process an unparked DHCPv6 packet and sends the response.
NetworkStatePtr network_state_
Holds information about disabled DHCP service and/or disabled subnet/network scopes.
Definition dhcp6_srv.h:1273
std::list< std::list< std::string > > jsonPathsToRedact() const final override
Return a list of all paths that contain passwords or secrets for kea-dhcp6.
OptionPtr assignIA_PD(const Pkt6Ptr &query, AllocEngine::ClientContext6 &ctx, boost::shared_ptr< Option6IA > ia)
Processes IA_PD option (and assigns prefixes if necessary).
bool testUnicast(const Pkt6Ptr &pkt) const
Check if the message can be sent to unicast.
Definition dhcp6_srv.cc:411
Pkt6Ptr processRelease(AllocEngine::ClientContext6 &ctx)
Process incoming Release message.
void processClientFqdn(const Pkt6Ptr &question, const Pkt6Ptr &answer, AllocEngine::ClientContext6 &ctx)
Processes Client FQDN Option.
void setStatusCode(boost::shared_ptr< Option6IA > &container, const OptionPtr &status)
A simple utility method that sets the status code.
static int getHookIndexBuffer6Send()
Returns the index of the buffer6_send hook.
void classifyPacket(const Pkt6Ptr &pkt)
Assigns incoming packet to zero or more classes.
static HWAddrPtr getMAC(const Pkt6Ptr &pkt)
Attempts to get a MAC/hardware address using configured sources.
Dhcpv6Srv(uint16_t server_port=DHCP6_SERVER_PORT, uint16_t client_port=0)
Default constructor.
Definition dhcp6_srv.cc:274
bool declineLeases(const Pkt6Ptr &decline, Pkt6Ptr &reply, AllocEngine::ClientContext6 &ctx)
Attempts to decline all leases in specified Decline message.
void releaseLeases(const Pkt6Ptr &release, Pkt6Ptr &reply, AllocEngine::ClientContext6 &ctx)
Attempts to release received addresses.
void extendLeases(const Pkt6Ptr &query, Pkt6Ptr &reply, AllocEngine::ClientContext6 &ctx)
Attempts to extend the lifetime of IAs.
void processRSOO(const Pkt6Ptr &query, const Pkt6Ptr &rsp)
Processes Relay-supplied options, if present.
static std::string getVersion(bool extended)
returns Kea version on stdout and exit.
Pkt6Ptr processAddrRegInform(AllocEngine::ClientContext6 &ctx)
Processes incoming Addr-reg-inform message.
OptionPtr extendIA_NA(const Pkt6Ptr &query, AllocEngine::ClientContext6 &ctx, Option6IAPtr ia)
Extends lifetime of the specific IA_NA option.
Pkt6Ptr processConfirm(AllocEngine::ClientContext6 &ctx)
Processes incoming Confirm message and returns Reply.
void sanityCheckDUID(const OptionPtr &opt, const std::string &opt_name)
verifies if received DUID option (client-id or server-id) is sane
static void setHostIdentifiers(AllocEngine::ClientContext6 &ctx)
Set host identifiers within a context.
Definition dhcp6_srv.cc:424
void processPacketPktSend(hooks::CalloutHandlePtr &callout_handle, Pkt6Ptr &query, Pkt6Ptr &rsp, ConstSubnet6Ptr &subnet)
Executes pkt6_send callout.
Pkt6Ptr processDhcp6Query(Pkt6Ptr query)
Process a single incoming DHCPv6 query.
void processDhcp6QueryAndSendResponse(Pkt6Ptr query)
Process a single incoming DHCPv6 query.
asiolink::IOServicePtr & getIOService()
Returns pointer to the IO service used by the server.
Definition dhcp6_srv.h:110
void appendRequestedOptions(const Pkt6Ptr &question, Pkt6Ptr &answer, const CfgOptionList &co_list)
Appends requested options to server's answer.
uint16_t client_port_
UDP port number to which server sends all responses.
Definition dhcp6_srv.h:1214
CBControlDHCPv6Ptr cb_control_
Controls access to the configuration backends.
Definition dhcp6_srv.h:1276
isc::dhcp::ConstSubnet6Ptr selectSubnet(const Pkt6Ptr &question, bool &drop)
Selects a subnet for a given client's packet.
volatile bool shutdown_
Indicates if shutdown is in progress.
Definition dhcp6_srv.h:1249
void checkPostAssignmentChanges(const Pkt6Ptr &question, Pkt6Ptr &answer, AllocEngine::ClientContext6 &ctx, const ConstSubnet6Ptr orig_subnet)
Iterates over new leases, update stale DNS entries.
Pkt6Ptr processSolicit(AllocEngine::ClientContext6 &ctx)
Processes incoming Solicit and returns response.
void startD2()
Starts DHCP_DDNS client IO if DDNS updates are enabled.
static std::string duidToString(const OptionPtr &opt)
converts DUID to text Converts content of DUID option to a text representation, e....
OptionPtr getPDExclude(const AllocEngine::ClientContext6 &ctx, const Lease6Ptr &lease)
Return the PD exclude option to include.
static void removeDependentEvaluatedClasses(const Pkt6Ptr &pkt)
Removed evaluated client classes.
void createNameChangeRequests(const Pkt6Ptr &answer, AllocEngine::ClientContext6 &ctx)
Creates a number of isc::dhcp_ddns::NameChangeRequest objects based on the DHCPv6 Client FQDN Option.
Pkt6Ptr processInfRequest(AllocEngine::ClientContext6 &ctx)
Processes incoming Information-request message.
uint16_t server_port_
UDP port number on which server listens.
Definition dhcp6_srv.h:1211
void appendRequestedVendorOptions(const Pkt6Ptr &question, Pkt6Ptr &answer, AllocEngine::ClientContext6 &ctx, const CfgOptionList &co_list)
Appends requested vendor options to server's answer.
bool declineLease(const Pkt6Ptr &decline, const Lease6Ptr lease, boost::shared_ptr< Option6IA > ia_rsp)
Declines specific IPv6 lease.
void discardPackets()
Discards parked packets Clears the packet parking lots of all packets.
Exception thrown when host name sanitizing reduces the domain name to an empty string.
static std::list< std::string > getDBVersions()
Return extended version info for registered backends.
ConstHostCollection getAll6(const SubnetID &subnet_id, const HostMgrOperationTarget target) const
Return all hosts in a DHCPv6 subnet.
Definition host_mgr.cc:171
static void create()
Creates new instance of the HostMgr.
Definition host_mgr.cc:52
static HostMgr & instance()
Returns a sole instance of the HostMgr.
Definition host_mgr.cc:114
std::string getIdentifierAsText() const
Returns host identifier in a textual form.
Definition host.cc:319
IdentifierType
Type of the host identifier.
Definition host.h:337
@ IDENT_FLEX
Flexible host identifier.
Definition host.h:342
static IfaceMgr & instance()
IfaceMgr is a singleton class.
Definition iface_mgr.cc:52
bool send(const Pkt6Ptr &pkt)
Sends an IPv6 packet.
void closeSockets()
Closes all open sockets.
Definition iface_mgr.cc:313
static TrackingLeaseMgr & instance()
Return current lease manager.
static std::list< std::string > getDBVersions()
Return extended version info for registered backends.
static void destroy()
Destroy lease manager.
virtual bool deleteLease(const Lease4Ptr &lease)=0
Deletes an IPv4 lease.
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.
static std::list< std::string > getDBVersions()
Return extended version info for registered backends.
static void splitNtpServerOptions6(isc::dhcp::OptionCollection &options)
Split NTP server option to one suboption per instance.
Controls the DHCP service enabling status.
Represents DHCPv6 Client FQDN Option (code 39).
static const uint8_t FLAG_S
S bit.
static const uint8_t FLAG_N
N bit.
Class that represents IAPREFIX option in DHCPv6.
uint32_t getIAID() const
Returns IA identifier.
Definition option6_ia.h:96
Option descriptor.
Definition cfg_option.h:50
OptionPtr option_
Option instance.
Definition cfg_option.h:53
bool allowedForClientClasses(const ClientClasses &cclasses) const
Validates an OptionDescriptor's client-classes against a list of classes.
Definition cfg_option.cc:72
This class represents vendor-specific information option.
const OptionCollection & getOptions() const
Returns all encapsulated options.
Definition option.h:354
OptionPtr getOption(uint16_t type) const
Returns shared_ptr to suboption of specific type.
Definition option.cc:200
Represents a DHCPv6 packet.
Definition pkt6.h:43
virtual std::string getLabel() const
Returns text representation of the primary packet identifiers.
Definition pkt6.cc:730
An exception that is thrown if a DHCPv6 protocol violation occurs while processing a message (e....
Definition utils.h:17
RAII object enabling copying options retrieved from the packet.
Definition pkt.h:47
Exception thrown when a call to select is interrupted by a signal.
Definition iface_mgr.h:58
Exception thrown during option unpacking This exception is thrown when an error has occurred,...
Definition option.h:52
Container class for handling the DHCID value within a NameChangeRequest.
Definition ncr_msg.h:114
Represents a DHCP-DDNS client request.
Definition ncr_msg.h:255
static std::string const & resultToText(Result const &result)
Convert enum to string.
Definition ncr_io.h:500
Result
Defines the outcome of an asynchronous NCR send.
Definition ncr_io.h:488
@ NEXT_STEP_PARK
park the packet
@ NEXT_STEP_CONTINUE
continue normally
@ NEXT_STEP_DROP
drop the packet
@ NEXT_STEP_SKIP
skip the next processing step
static int registerHook(const std::string &name)
Register Hook.
static bool calloutsPresent(int index)
Are callouts present?
static std::vector< std::string > getLibraryNames()
Return list of loaded libraries.
static bool unloadLibraries()
Unload libraries.
static void park(const std::string &hook_name, T parked_object, std::function< void()> unpark_callback)
Park an object (packet).
static void callCallouts(int index, CalloutHandle &handle)
Calls the callouts for a given hook.
static void prepareUnloadLibraries()
Prepare the unloading of libraries.
static bool drop(const std::string &hook_name, T parked_object)
Removes parked object without calling a callback.
static void clearParkingLots()
Clears any parking packets.
Wrapper class around callout handle which automatically resets handle's state.
static ServerHooks & getServerHooks()
Return ServerHooks object.
static std::string getVersion()
Version.
Definition log/logger.cc:60
bool lock()
Acquire the lock (blocks if something else has acquired a lock on the same task name).
int getExitValue()
Fetches the exit value.
Definition daemon.h:235
Statistics Manager class.
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.
ThreadPool< std::function< void()> > & getThreadPool()
Get the dhcp thread pool.
void apply(bool enabled, uint32_t thread_count, uint32_t queue_size)
Apply the multi-threading related settings.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition buffer.h:355
const std::vector< uint8_t > & getVector() const
Return the buffer.
Definition buffer.h:445
Read mutex RAII handler.
Defines classes for storing client class definitions.
int version()
returns Kea hooks version.
Defines the D2ClientConfig class.
Defines the D2ClientMgr class.
Dhcp4Hooks Hooks
Definition dhcp4_srv.cc:213
@ STATUS_NoAddrsAvail
Definition dhcp6.h:178
@ STATUS_NoPrefixAvail
Definition dhcp6.h:182
@ STATUS_NotOnLink
Definition dhcp6.h:180
@ STATUS_Success
Definition dhcp6.h:176
@ STATUS_NoBinding
Definition dhcp6.h:179
@ STATUS_UnspecFail
Definition dhcp6.h:177
@ D6O_CLIENT_FQDN
Definition dhcp6.h:59
@ D6O_UNICAST
Definition dhcp6.h:32
@ D6O_RSOO
Definition dhcp6.h:86
@ D6O_SERVERID
Definition dhcp6.h:22
@ D6O_CLIENTID
Definition dhcp6.h:21
@ D6O_VENDOR_OPTS
Definition dhcp6.h:37
@ D6O_IA_TA
Definition dhcp6.h:24
@ D6O_RELAY_SOURCE_PORT
Definition dhcp6.h:155
@ D6O_RAPID_COMMIT
Definition dhcp6.h:34
@ D6O_IA_NA
Definition dhcp6.h:23
@ D6O_ORO
Definition dhcp6.h:26
@ D6O_PD_EXCLUDE
Definition dhcp6.h:87
@ D6O_IA_PD
Definition dhcp6.h:45
@ D6O_DHCPV4_MSG
Definition dhcp6.h:107
@ D6O_IAADDR
Definition dhcp6.h:25
@ D6O_VENDOR_CLASS
Definition dhcp6.h:36
@ D6O_STATUS_CODE
Definition dhcp6.h:33
@ D6O_IAPREFIX
Definition dhcp6.h:46
@ DHCPV6_ADVERTISE
Definition dhcp6.h:209
@ DHCPV6_REQUEST
Definition dhcp6.h:210
@ DHCPV6_RENEW
Definition dhcp6.h:212
@ DHCPV6_DHCPV4_QUERY
Definition dhcp6.h:231
@ DHCPV6_DHCPV4_RESPONSE
Definition dhcp6.h:232
@ DHCPV6_RECONFIGURE
Definition dhcp6.h:217
@ DHCPV6_REBIND
Definition dhcp6.h:213
@ DHCPV6_REPLY
Definition dhcp6.h:214
@ DHCPV6_ADDR_REG_REPLY
Definition dhcp6.h:250
@ DHCPV6_ADDR_REG_INFORM
Definition dhcp6.h:249
@ DHCPV6_SOLICIT
Definition dhcp6.h:208
@ DHCPV6_RELEASE
Definition dhcp6.h:215
@ DHCPV6_INFORMATION_REQUEST
Definition dhcp6.h:218
@ DHCPV6_CONFIRM
Definition dhcp6.h:211
@ DHCPV6_DECLINE
Definition dhcp6.h:216
Defines the Dhcp6to4Ipc class.
#define DOCSIS3_V6_ORO
#define VENDOR_ID_CABLE_LABS
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< OptionUint16Array > OptionUint16ArrayPtr
OptionIntArray< uint16_t > OptionUint16Array
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.
int get(CalloutHandle &handle)
The gss-tsig-get command.
When a message is logged with DEBUG severity, the debug level associated with the message is also spe...
#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
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
@ info
Definition db_log.h:128
ConflictResolutionMode StringToConflictResolutionMode(const std::string &mode_str)
Function which converts string to ConflictResolutionMode enum values.
Definition ncr_msg.cc:42
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
Definition ncr_msg.h:242
const isc::log::MessageID DHCP6_DDNS_REQUEST_SEND_FAILED
boost::shared_ptr< OptionVendor > OptionVendorPtr
Pointer to a vendor option.
const isc::log::MessageID DHCP6_PD_LEASE_ADVERT
const isc::log::MessageID DHCP6_BUFFER_RECEIVED
const isc::log::MessageID DHCP6_RELEASE_NA_DELETED
isc::log::Logger bad_packet6_logger(DHCP6_BAD_PACKET_LOGGER_NAME)
Logger for rejected packets.
Definition dhcp6_log.h:94
const isc::log::MessageID DHCP6_PACKET_DROP_PARSE_FAIL
const isc::log::MessageID DHCP6_ADDITIONAL_CLASS_NO_TEST
const isc::log::MessageID DHCP6_ADDITIONAL_CLASS_EVAL_RESULT
const isc::log::MessageID DHCP6_RELEASE_PD_DELETED
const isc::log::MessageID DHCP6_PACKET_REJECT_CLASS
const isc::log::MessageID DHCP6_LEASE_ALLOC
const isc::log::MessageID DHCP6_FLEX_ID
const isc::log::MessageID DHCP6_REGISTERED_LEASE_ADD_FAIL
uint32_t calculateDdnsTtl(uint32_t lease_lft, const util::Optional< double > &ddns_ttl_percent, const util::Optional< uint32_t > &ddns_ttl, const util::Optional< uint32_t > &ddns_ttl_min, const util::Optional< uint32_t > &ddns_ttl_max)
Calculates TTL for a DNS resource record based on lease life time.
const isc::log::MessageID DHCP6_PACKET_PROCESS_EXCEPTION_MAIN
const isc::log::MessageID DHCP6_HOOK_PACKET_SEND_SKIP
const isc::log::MessageID DHCP6_ADDR_REG_INFORM_CLIENT_CHANGE
const isc::log::MessageID DHCP6_SUBNET_SELECTION_FAILED
const isc::log::MessageID DHCP6_PACKET_DROP_SERVERID_MISMATCH
const isc::log::MessageID DHCP6_HOOK_DECLINE_SKIP
const isc::log::MessageID DHCP6_PD_LEASE_REUSE
const isc::log::MessageID DHCP6_PACKET_DROP_UNICAST
const isc::log::MessageID DHCP6_LEASE_PD_WITHOUT_DUID
const isc::log::MessageID DHCP6_LEASE_ALLOC_FAIL
const isc::log::MessageID DHCP6_ADDITIONAL_CLASS_UNDEFINED
const isc::log::MessageID DHCP6_PACKET_SEND_FAIL
const isc::log::MessageID DHCP6_PACKET_PROCESS_EXCEPTION
void queueNCR(const NameChangeType &chg_type, const Lease4Ptr &lease)
Creates name change request from the DHCPv4 lease.
const isc::log::MessageID DHCP6_CLIENT_FQDN_SCRUBBED_EMPTY
const isc::log::MessageID DHCP6_QUERY_LABEL
const isc::log::MessageID DHCP6_BUFFER_UNPACK
boost::shared_ptr< const Subnet6 > ConstSubnet6Ptr
A const pointer to a Subnet6 object.
Definition subnet.h:620
std::vector< uint32_t > CfgMACSources
Container for defined MAC/hardware address sources.
const isc::log::MessageID DHCP6_SRV_D2STOP_ERROR
const isc::log::MessageID DHCP6_REGISTERED_LEASE_UPDATE_FAIL
const isc::log::MessageID DHCP6_PACKET_SEND
const isc::log::MessageID DHCP6_DECLINE_FAIL_LEASE_WITHOUT_DUID
const int DBG_DHCP6_BASIC_DATA
Debug level used to log the traces with some basic data.
Definition dhcp6_log.h:43
const isc::log::MessageID DHCP6_HOOK_PACKET_RCVD_SKIP
const isc::log::MessageID DHCP6_ADDR6_REGISTER_DISABLED_DROP
const isc::log::MessageID DHCP6_ADDITIONAL_CLASS_EVAL_ERROR
boost::shared_ptr< DUID > DuidPtr
Definition duid.h:136
const isc::log::MessageID DHCP6_OPEN_SOCKET
const isc::log::MessageID DHCP6_PACK_FAIL
const isc::log::MessageID DHCP6_RELEASE_PD_FAIL_WRONG_IAID
const isc::log::MessageID DHCP6_HOOK_DDNS_UPDATE
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
const int DBG_DHCP6_HOOKS
Debug level used to trace hook related operations.
Definition dhcp6_log.h:34
const isc::log::MessageID DHCP6_HOOK_LEASE6_RELEASE_NA_SKIP
ContinuationPtr makeContinuation(Continuation &&cont)
Continuation factory.
const int DBG_DHCP6_START
Debug level used to log information during server startup.
Definition dhcp6_log.h:22
const isc::log::MessageID DHCP6_PD_LEASE_ALLOC
const isc::log::MessageID DHCP6_DDNS_GENERATE_FQDN
const isc::log::MessageID DHCP6_RELEASE_PD_EXPIRED
boost::shared_ptr< Option6IA > Option6IAPtr
A pointer to the Option6IA object.
Definition option6_ia.h:20
const isc::log::MessageID DHCP6_DDNS_REMOVE_OLD_LEASE_FQDN
boost::shared_ptr< const CfgRSOO > ConstCfgRSOOPtr
Pointer to the const object.
Definition cfg_rsoo.h:74
boost::shared_ptr< const CfgHostOperations > ConstCfgHostOperationsPtr
Pointer to the const object.
std::multimap< unsigned int, OptionPtr > OptionCollection
A collection of DHCP (v4 or v6) options.
Definition option.h:40
const isc::log::MessageID DHCP6_SUBNET_DATA
const isc::log::MessageID DHCP6_UNKNOWN_MSG_RECEIVED
boost::shared_ptr< ClientClassDef > ClientClassDefPtr
a pointer to an ClientClassDef
boost::shared_ptr< DdnsParams > DdnsParamsPtr
Defines a pointer for DdnsParams instances.
const isc::log::MessageID DHCP6_HOOK_SUBNET6_SELECT_DROP
const isc::log::MessageID DHCP6_ADD_GLOBAL_STATUS_CODE
boost::shared_ptr< Option6IAPrefix > Option6IAPrefixPtr
Pointer to the Option6IAPrefix object.
const isc::log::MessageID DHCP6_DDNS_RESPONSE_FQDN_DATA
const isc::log::MessageID DHCP6_RELEASE_NA
const isc::log::MessageID DHCP6_CLASSES_ASSIGNED
const isc::log::MessageID DHCP6_REQUIRED_OPTIONS_CHECK_FAIL
const isc::log::MessageID DHCP6_PROCESS_IA_NA_EXTEND
std::pair< IPv6ResrvIterator, IPv6ResrvIterator > IPv6ResrvRange
Definition host.h:273
const isc::log::MessageID DHCP6_RELEASE_PD_FAIL
const isc::log::MessageID DHCP6_SRV_CONSTRUCT_ERROR
const isc::log::MessageID DHCP6_LEASE_RENEW
const char * DOCSIS3_CLASS_EROUTER
The class as specified in vendor-class option by the devices.
Definition libdhcp++.cc:94
const isc::log::MessageID DHCP6_RELEASE_NA_FAIL
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
Definition hwaddr.h:166
const isc::log::MessageID DHCP6_PACKET_PROCESS_STD_EXCEPTION
const isc::log::MessageID DHCP6_PACKET_RECEIVE_FAIL
const isc::log::MessageID DHCP6_PROCESS_IA_NA_SOLICIT
const isc::log::MessageID DHCP6_ADDR_REG_INFORM_FAIL
const isc::log::MessageID DHCP6_DECLINE_FAIL_IAID_MISMATCH
const isc::log::MessageID DHCP6_HOOK_SUBNET6_SELECT_PARK
OptionContainer::nth_index< 5 >::type OptionContainerCancelIndex
Type of the index #5 - option cancellation flag.
Definition cfg_option.h:367
boost::shared_ptr< Option6StatusCode > Option6StatusCodePtr
Pointer to the isc::dhcp::Option6StatusCode.
std::pair< OptionContainerPersistIndex::const_iterator, OptionContainerPersistIndex::const_iterator > OptionContainerPersistRange
Pair of iterators to represent the range of options having the same persistency flag.
Definition cfg_option.h:365
boost::shared_ptr< SharedNetwork6 > SharedNetwork6Ptr
Pointer to SharedNetwork6 object.
const isc::log::MessageID DHCP4_HOOK_SUBNET6_SELECT_PARKING_LOT_FULL
isc::log::Logger packet6_logger(DHCP6_PACKET_LOGGER_NAME)
Logger for processed packets.
Definition dhcp6_log.h:100
const isc::log::MessageID DHCP6_DECLINE_LEASE
boost::shared_ptr< Expression > ExpressionPtr
Definition token.h:31
const isc::log::MessageID DHCP6_LEASE_ADVERT_FAIL
const isc::log::MessageID DHCP6_HOOK_LEASES6_PARKING_LOT_FULL
const isc::log::MessageID DHCP6_PD_LEASE_ADVERT_FAIL
boost::shared_ptr< Pool > PoolPtr
a pointer to either IPv4 or IPv6 Pool
Definition pool.h:726
isc::hooks::CalloutHandlePtr getCalloutHandle(const T &pktptr)
CalloutHandle Store.
const isc::log::MessageID DHCP6_PACKET_PROCESS_FAIL
const isc::log::MessageID DHCP6_RELEASE_NA_EXPIRED
boost::shared_ptr< ClientClassDictionary > ClientClassDictionaryPtr
Defines a pointer to a ClientClassDictionary.
const isc::log::MessageID DHCP6_PACKET_RECEIVED
const isc::log::MessageID DHCP6_RESPONSE_DATA
const isc::log::MessageID DHCP6_DDNS_RECEIVE_FQDN
const isc::log::MessageID DHCP6_PACKET_OPTIONS_SKIPPED
const isc::log::MessageID DHCP6_NO_INTERFACES
const isc::log::MessageID DHCP6_RELEASE_PD_FAIL_WRONG_DUID
const isc::log::MessageID DHCP6_LEASE_REUSE
isc::log::Logger ddns6_logger(DHCP6_DDNS_LOGGER_NAME)
Logger for Hostname or FQDN processing.
Definition dhcp6_log.h:112
const isc::log::MessageID DHCP6_HOOK_ADDR6_REGISTER_SKIP
boost::shared_ptr< Continuation > ContinuationPtr
Define the type of shared pointers to continuations.
boost::shared_ptr< OptionContainer > OptionContainerPtr
Pointer to the OptionContainer object.
Definition cfg_option.h:351
boost::shared_ptr< ClientClassDefList > ClientClassDefListPtr
Defines a pointer to a ClientClassDefList.
const isc::log::MessageID DHCP6_HOOK_LEASES6_COMMITTED_DROP
const isc::log::MessageID DHCP6_HOOK_PACKET_SEND_DROP
const isc::log::MessageID DHCP6_DDNS_GENERATED_FQDN_UPDATE_FAIL
const isc::log::MessageID DHCP6_PACKET_DROP_DROP_CLASS2
boost::shared_ptr< Option6IAAddr > Option6IAAddrPtr
A pointer to the isc::dhcp::Option6IAAddr object.
const char * DOCSIS3_CLASS_MODEM
DOCSIS3.0 compatible cable modem.
Definition libdhcp++.cc:91
const isc::log::MessageID DHCP6_SHUTDOWN_REQUEST
const isc::log::MessageID DHCP6_HOOK_BUFFER_RCVD_SKIP
const isc::log::MessageID DHCP6_DECLINE_FAIL
bool evaluateBool(const Expression &expr, Pkt &pkt)
Evaluate a RPN expression for a v4 or v6 packet and return a true or false decision.
Definition evaluate.cc:34
const isc::log::MessageID DHCP6_QUERY_DATA
const int DBG_DHCP6_DETAIL_DATA
This level is used to log the contents of packets received and sent.
Definition dhcp6_log.h:54
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
Definition host.h:840
const isc::log::MessageID DHCP6_PROCESS_IA_PD_SOLICIT
const isc::log::MessageID DHCP6_PACKET_DROP_DROP_CLASS
boost::shared_ptr< Lease6Collection > Lease6CollectionPtr
A shared pointer to the collection of IPv6 leases.
Definition lease.h:696
const isc::log::MessageID DHCP6_DECLINE_PROCESS_IA
const isc::log::MessageID DHCP6_PROCESS_IA_NA_REQUEST
OptionContainer::nth_index< 2 >::type OptionContainerPersistIndex
Type of the index #2 - option persistency flag.
Definition cfg_option.h:360
isc::log::Logger lease6_logger(DHCP6_LEASE_LOGGER_NAME)
Logger for lease allocation logic.
Definition dhcp6_log.h:117
const isc::log::MessageID DHCP6_CLASS_UNCONFIGURED
boost::shared_ptr< OptionVendorClass > OptionVendorClassPtr
Defines a pointer to the OptionVendorClass.
const isc::log::MessageID DHCP6_LEASE_NA_WITHOUT_DUID
const isc::log::MessageID DHCP6_HOOK_DECLINE_DROP
const isc::log::MessageID DHCP6_PROCESS_IA_PD_REQUEST
const isc::log::MessageID DHCP6_HOOK_SUBNET6_SELECT_SKIP
const isc::log::MessageID DHCP6_PD_LEASE_RENEW
const isc::log::MessageID DHCP6_CLASS_ASSIGNED
boost::shared_ptr< const Subnet > ConstSubnetPtr
A generic pointer to either const Subnet4 or const Subnet6 object.
Definition subnet.h:449
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Definition pkt6.h:30
const isc::log::MessageID DHCP6_RELEASE_PD_FAIL_NOT_ASSIGNED
const isc::log::MessageID DHCP6_PROCESS_IA_NA_RELEASE
const isc::log::MessageID DHCP6_PACKET_DROP_DROP_CLASS_EARLY
const isc::log::MessageID DHCP6_LEASE_ADVERT
const isc::log::MessageID DHCP6_DECLINE_FAIL_DUID_MISMATCH
const isc::log::MessageID DHCP6_SRV_UNLOAD_LIBRARIES_ERROR
const isc::log::MessageID DHCP6_HOOK_LEASES6_COMMITTED_PARK
const isc::log::MessageID DHCP6_DECLINE_FAIL_NO_LEASE
const isc::log::MessageID DHCP6_RAPID_COMMIT
const isc::log::MessageID DHCP6_BUFFER_WAIT_SIGNAL
bool isClientClassBuiltIn(const ClientClass &client_class)
Check if a client class name is builtin.
boost::shared_ptr< Option6ClientFqdn > Option6ClientFqdnPtr
A pointer to the Option6ClientFqdn object.
const isc::log::MessageID DHCP6_PROCESS_IA_PD_EXTEND
std::pair< OptionContainerCancelIndex::const_iterator, OptionContainerCancelIndex::const_iterator > OptionContainerCancelRange
Pair of iterators to represent the range of options having the same cancellation flag.
Definition cfg_option.h:372
const isc::log::MessageID DHCP6_CLASSES_ASSIGNED_AFTER_SUBNET_SELECTION
const isc::log::MessageID DHCP6_PACKET_PROCESS_STD_EXCEPTION_MAIN
const int DBG_DHCP6_BASIC
Debug level used to trace basic operations within the code.
Definition dhcp6_log.h:31
const isc::log::MessageID DHCP6_HOOK_ADDR6_REGISTER_DROP
isc::log::Logger dhcp6_logger(DHCP6_APP_LOGGER_NAME)
Base logger for DHCPv6 server.
Definition dhcp6_log.h:88
const isc::log::MessageID DHCP6_SUBNET_SELECTED
const isc::log::MessageID DHCP6_RELEASE_NA_FAIL_WRONG_IAID
const isc::log::MessageID DHCP6_RELEASE_NA_FAIL_NOT_ASSIGNED
const isc::log::MessageID DHCP6_HOOK_BUFFER_RCVD_DROP
const isc::log::MessageID DHCP6_ADD_DEPRECATED_UNICAST
boost::shared_ptr< Option > OptionPtr
Definition option.h:37
const isc::log::MessageID DHCP6_DDNS_CREATE_ADD_NAME_CHANGE_REQUEST
const isc::log::MessageID DHCP6_RELEASE_NA_FAIL_WRONG_DUID
const isc::log::MessageID DHCP6_ADD_STATUS_CODE_FOR_IA
isc::log::Logger options6_logger(DHCP6_OPTIONS_LOGGER_NAME)
Logger for options parser.
Definition dhcp6_log.h:106
const isc::log::MessageID DHCP6_LEASE_DATA
const isc::log::MessageID DHCP6_HOOK_BUFFER_SEND_SKIP
const int DBG_DHCP6_DETAIL
Debug level used to trace detailed errors.
Definition dhcp6_log.h:51
const isc::log::MessageID DHCP6_SUBNET_DYNAMICALLY_CHANGED
const isc::log::MessageID DHCP6_PACKET_QUEUE_FULL
const isc::log::MessageID DHCP6_PD_LEASE_ALLOC_FAIL
const isc::log::MessageID DHCP6_HOOK_LEASE6_RELEASE_PD_SKIP
const isc::log::MessageID DHCP6_RELEASE_PD
std::list< ConstCfgOptionPtr > CfgOptionList
Const pointer list.
Definition cfg_option.h:989
const isc::log::MessageID DHCP6_DDNS_FQDN_GENERATED
const isc::log::MessageID DHCP6_PACKET_DROP_DHCP_DISABLED
boost::shared_ptr< Pool6 > Pool6Ptr
a pointer an IPv6 Pool
Definition pool.h:536
isc::log::Logger hooks_logger("hooks")
Hooks Logger.
Definition hooks_log.h:37
boost::shared_ptr< CalloutHandle > CalloutHandlePtr
A shared pointer to a CalloutHandle object.
boost::shared_ptr< ParkingLot > ParkingLotPtr
Type of the pointer to the parking lot.
const int DBGLVL_TRACE_BASIC
Trace basic operations.
const int DBGLVL_PKT_HANDLING
This debug level is reserved for logging the details of packet handling, such as dropping the packet ...
string dumpAsHex(const uint8_t *data, size_t length)
Dumps a buffer of bytes as a string of hexadecimal digits.
Definition str.cc:330
bool equalValues(const T &ptr1, const T &ptr2)
This function checks if two pointers are non-null and values are equal.
Defines the logger used by the top-level component of kea-lfc.
This file defines abstract classes for exchanging NameChangeRequests.
This file provides the classes needed to embody, compose, and decompose DNS update requests that are ...
Standard implementation of read-write mutexes with writer preference using C++11 mutex and condition ...
#define DHCP6_OPTION_SPACE
Lease6Collection old_leases_
A pointer to any old leases that the client had before update but are no longer valid after the updat...
Option6IAPtr ia_rsp_
A pointer to the IA_NA/IA_PD option to be sent in response.
Lease::Type type_
Lease type (IA or PD).
Lease6Collection changed_leases_
A pointer to any leases that have changed FQDN information.
void addHint(const asiolink::IOAddress &prefix, const uint8_t prefix_len=128, const uint32_t preferred=0, const uint32_t valid=0)
Convenience method adding new hint.
Lease6Collection reused_leases_
Set of leases marked for reuse by lease caching.
uint32_t iaid_
The IAID field from IA_NA or IA_PD that is being processed.
Context information for the DHCPv6 leases allocation.
IAContext & currentIA()
Returns IA specific context for the currently processed IA.
std::vector< IAContext > ias_
Container holding IA specific contexts.
void addHostIdentifier(const Host::IdentifierType &id_type, const std::vector< uint8_t > &identifier)
Convenience function adding host identifier into host_identifiers_ list.
bool fake_allocation_
Indicates if this is a real or fake allocation.
ConstHostPtr currentHost() const
Returns host from the most preferred subnet.
DuidPtr duid_
Client identifier.
Lease6Collection new_leases_
A collection of newly allocated leases.
std::vector< IAContext > & getIAContexts()
HWAddrPtr hwaddr_
Hardware/MAC address (if available, may be NULL).
hooks::CalloutHandlePtr callout_handle_
Callout handle associated with the client's message.
ResourceContainer allocated_resources_
Holds addresses and prefixes allocated for all IAs.
bool rev_dns_update_
A boolean value which indicates that server takes responsibility for the reverse DNS Update for this ...
DdnsParamsPtr getDdnsParams()
Returns the set of DDNS behavioral parameters based on the selected subnet.
ConstHostPtr globalHost() const
Returns global host reservation if there is one.
Pkt6Ptr query_
A pointer to the client's message.
bool early_global_reservations_lookup_
Indicates if early global reservation is enabled.
void createIAContext()
Creates new IA context.
ConstSubnet6Ptr subnet_
Subnet selected for the client by the server.
std::map< SubnetID, ConstHostPtr > hosts_
Holds a map of hosts belonging to the client within different subnets.
bool fwd_dns_update_
A boolean value which indicates that server takes responsibility for the forward DNS Update for this ...
Structure that holds a lease for IPv6 address and/or prefix.
Definition lease.h:536
static const uint32_t INFINITY_LFT
Infinity (means static, i.e. never expire).
Definition lease.h:34
static constexpr uint32_t STATE_DEFAULT
A lease in the default state.
Definition lease.h:69
static std::string lifetimeToText(uint32_t lifetime)
Print lifetime.
Definition lease.cc:34
static constexpr uint32_t STATE_REGISTERED
Registered self-generated lease.
Definition lease.h:81
static constexpr uint32_t STATE_RELEASED
Released lease held in the database for lease affinity.
Definition lease.h:78
@ TYPE_PD
the lease contains IPv6 prefix (for prefix delegation)
Definition lease.h:49
@ TYPE_NA
the lease contains non-temporary IPv6 address
Definition lease.h:47
Subnet selector used to specify parameters used to select a subnet.
bool add(const WorkItemPtr &item)
add a work item to the thread pool