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