Kea 2.0.3
dhcp6_srv.cc
Go to the documentation of this file.
1// Copyright (C) 2011-2022 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 <dhcp_ddns/ncr_msg.h>
12#include <dhcp/dhcp6.h>
14#include <dhcp/duid.h>
15#include <dhcp/duid_factory.h>
16#include <dhcpsrv/fuzz.h>
17#include <dhcp/iface_mgr.h>
18#include <dhcp/libdhcp++.h>
21#include <dhcp/option6_ia.h>
22#include <dhcp/option6_iaaddr.h>
26#include <dhcp/option_custom.h>
27#include <dhcp/option_vendor.h>
30#include <dhcp/pkt6.h>
32#include <dhcp6/dhcp6to4_ipc.h>
33#include <dhcp6/dhcp6_log.h>
34#include <dhcp6/dhcp6_srv.h>
36#include <dhcpsrv/cfgmgr.h>
37#include <dhcpsrv/lease_mgr.h>
40#include <dhcpsrv/subnet.h>
42#include <dhcpsrv/utils.h>
43#include <eval/evaluate.h>
44#include <eval/eval_messages.h>
47#include <hooks/hooks_log.h>
48#include <hooks/hooks_manager.h>
49#include <stats/stats_mgr.h>
50#include <util/encode/hex.h>
51#include <util/io_utilities.h>
52#include <util/pointer_util.h>
54#include <log/logger.h>
57
58#ifdef HAVE_MYSQL
60#endif
61#ifdef HAVE_PGSQL
63#endif
64#ifdef HAVE_CQL
66#endif
68
69#include <boost/foreach.hpp>
70#include <boost/tokenizer.hpp>
71#include <boost/algorithm/string/erase.hpp>
72#include <boost/algorithm/string/join.hpp>
73#include <boost/algorithm/string/split.hpp>
74
75#include <algorithm>
76#include <functional>
77#include <stdlib.h>
78#include <time.h>
79#include <iomanip>
80#include <fstream>
81#include <sstream>
82#include <set>
83
84using namespace isc;
85using namespace isc::asiolink;
86using namespace isc::cryptolink;
87using namespace isc::dhcp;
88using namespace isc::dhcp_ddns;
89using namespace isc::hooks;
90using namespace isc::log;
91using namespace isc::stats;
92using namespace isc::util;
93using namespace std;
94namespace ph = std::placeholders;
95
96namespace {
97
99struct Dhcp6Hooks {
100 int hook_index_buffer6_receive_;
101 int hook_index_pkt6_receive_;
102 int hook_index_subnet6_select_;
103 int hook_index_leases6_committed_;
104 int hook_index_lease6_release_;
105 int hook_index_pkt6_send_;
106 int hook_index_buffer6_send_;
107 int hook_index_lease6_decline_;
108 int hook_index_host6_identifier_;
109
111 Dhcp6Hooks() {
112 hook_index_buffer6_receive_ = HooksManager::registerHook("buffer6_receive");
113 hook_index_pkt6_receive_ = HooksManager::registerHook("pkt6_receive");
114 hook_index_subnet6_select_ = HooksManager::registerHook("subnet6_select");
115 hook_index_leases6_committed_ = HooksManager::registerHook("leases6_committed");
116 hook_index_lease6_release_ = HooksManager::registerHook("lease6_release");
117 hook_index_pkt6_send_ = HooksManager::registerHook("pkt6_send");
118 hook_index_buffer6_send_ = HooksManager::registerHook("buffer6_send");
119 hook_index_lease6_decline_ = HooksManager::registerHook("lease6_decline");
120 hook_index_host6_identifier_ = HooksManager::registerHook("host6_identifier");
121 }
122};
123
124// Declare a Hooks object. As this is outside any function or method, it
125// will be instantiated (and the constructor run) when the module is loaded.
126// As a result, the hook indexes will be defined before any method in this
127// module is called.
128Dhcp6Hooks Hooks;
129
142createStatusCode(const Pkt6& pkt, const uint16_t status_code,
143 const std::string& status_message) {
144 Option6StatusCodePtr option_status(new Option6StatusCode(status_code,
145 status_message));
147 .arg(pkt.getLabel())
148 .arg(option_status->dataToText());
149 return (option_status);
150}
151
167createStatusCode(const Pkt6& pkt, const Option6IA& ia, const uint16_t status_code,
168 const std::string& status_message) {
169 Option6StatusCodePtr option_status(new Option6StatusCode(status_code,
170 status_message));
172 .arg(pkt.getLabel())
173 .arg(ia.getIAID())
174 .arg(option_status->dataToText());
175 return (option_status);
176}
177
180std::set<std::string> dhcp6_statistics = {
181 "pkt6-received",
182 "pkt6-solicit-received",
183 "pkt6-advertise-received",
184 "pkt6-request-received",
185 "pkt6-reply-received",
186 "pkt6-renew-received",
187 "pkt6-rebind-received",
188 "pkt6-decline-received",
189 "pkt6-release-received",
190 "pkt6-infrequest-received",
191 "pkt6-dhcpv4-query-received",
192 "pkt6-dhcpv4-response-received",
193 "pkt6-unknown-received",
194 "pkt6-sent",
195 "pkt6-advertise-sent",
196 "pkt6-reply-sent",
197 "pkt6-dhcpv4-response-sent",
198 "pkt6-parse-failed",
199 "pkt6-receive-drop"
200};
201
202} // namespace
203
204namespace isc {
205namespace dhcp {
206
207const std::string Dhcpv6Srv::VENDOR_CLASS_PREFIX("VENDOR_CLASS_");
208
209Dhcpv6Srv::Dhcpv6Srv(uint16_t server_port, uint16_t client_port)
210 : io_service_(new IOService()), server_port_(server_port),
211 client_port_(client_port), serverid_(), shutdown_(true),
212 alloc_engine_(), name_change_reqs_(),
213 network_state_(new NetworkState(NetworkState::DHCPv6)),
214 cb_control_(new CBControlDHCPv6()) {
216 .arg(server_port);
217
218 Dhcp6to4Ipc::instance().client_port = client_port;
219
220 // Initialize objects required for DHCP server operation.
221 try {
222 // Port 0 is used for testing purposes where in most cases we don't
223 // rely on the physical interfaces. Therefore, it should be possible
224 // to create an object even when there are no usable interfaces.
225 if ((server_port > 0) && (IfaceMgr::instance().countIfaces() == 0)) {
227 return;
228 }
229
230 // Create a DUID instance but do not store it into a file.
231 DUIDFactory duid_factory;
232 DuidPtr duid = duid_factory.get();
233 serverid_.reset(new Option(Option::V6, D6O_SERVERID, duid->getDuid()));
234
235 // Instantiate allocation engine. The number of allocation attempts equal
236 // to zero indicates that the allocation engine will use the number of
237 // attempts depending on the pool size.
239
241
242 } catch (const std::exception &e) {
244 return;
245 }
246 // Initializing all observations with default value
248
249 // All done, so can proceed
250 shutdown_ = false;
251}
252
255
256 // Iterate over set of observed statistics
257 for (auto it = dhcp6_statistics.begin(); it != dhcp6_statistics.end(); ++it) {
258 // Initialize them with default value 0
259 stats_mgr.setValue((*it), static_cast<int64_t>(0));
260 }
261}
262
264 // Discard any parked packets
266
267 try {
268 stopD2();
269 } catch (const std::exception& ex) {
270 // Highly unlikely, but lets Report it but go on
272 }
273
274 try {
276 } catch (const std::exception& ex) {
277 // Highly unlikely, but lets Report it but go on
278 // LOG_ERROR(dhcp6_logger, DHCP6_SRV_DHCP4O6_ERROR).arg(ex.what());
279 }
280
282
284
285 // Explicitly unload hooks
286 HooksManager::prepareUnloadLibraries();
287 if (!HooksManager::unloadLibraries()) {
288 auto names = HooksManager::getLibraryNames();
289 std::string msg;
290 if (!names.empty()) {
291 msg = names[0];
292 for (size_t i = 1; i < names.size(); ++i) {
293 msg += std::string(", ") + names[i];
294 }
295 }
297 }
298}
299
302 shutdown_ = true;
303}
304
306 return (IfaceMgr::instance().receive6(timeout));
307}
308
309void Dhcpv6Srv::sendPacket(const Pkt6Ptr& packet) {
310 IfaceMgr::instance().send(packet);
311}
312
313bool
319 OptionPtr server_id = pkt->getOption(D6O_SERVERID);
320 if (server_id){
321 // Let us test received ServerID if it is same as ServerID
322 // which is being used by server
323 if (getServerID()->getData() != server_id->getData()){
325 .arg(pkt->getLabel())
326 .arg(duidToString(server_id))
327 .arg(duidToString(getServerID()));
328 return (false);
329 }
330 }
331 // return True if: no serverid received or ServerIDs matching
332 return (true);
333}
334
335bool
337 switch (pkt->getType()) {
338 case DHCPV6_SOLICIT:
339 case DHCPV6_CONFIRM:
340 case DHCPV6_REBIND:
342 if (pkt->relay_info_.empty() && !pkt->getLocalAddr().isV6Multicast()) {
344 .arg(pkt->getLabel())
345 .arg(pkt->getName());
346 return (false);
347 }
348 break;
349 default:
350 // do nothing
351 ;
352 }
353 return (true);
354}
355
356void
359 bool& drop) {
360 ctx.subnet_ = selectSubnet(pkt, drop);
361 ctx.duid_ = pkt->getClientId(),
362 ctx.fwd_dns_update_ = false;
363 ctx.rev_dns_update_ = false;
364 ctx.hostname_ = "";
365 ctx.query_ = pkt;
367 ctx.hwaddr_ = getMAC(pkt);
368
369 if (drop) {
370 // Caller will immediately drop the packet so simply return now.
371 return;
372 }
373
374 // Collect host identifiers if host reservations enabled. The identifiers
375 // are stored in order of preference. The server will use them in that
376 // order to search for host reservations.
378 if (ctx.subnet_) {
379 const ConstCfgHostOperationsPtr cfg =
380 CfgMgr::instance().getCurrentCfg()->getCfgHostOperations6();
381 BOOST_FOREACH(const Host::IdentifierType& id_type,
382 cfg->getIdentifierTypes()) {
383 switch (id_type) {
384 case Host::IDENT_DUID:
385 if (ctx.duid_) {
386 ctx.addHostIdentifier(id_type, ctx.duid_->getDuid());
387 }
388 break;
389
391 if (ctx.hwaddr_) {
392 ctx.addHostIdentifier(id_type, ctx.hwaddr_->hwaddr_);
393 }
394 break;
395 case Host::IDENT_FLEX:
396 // At this point the information in the packet has been unpacked into
397 // the various packet fields and option objects has been created.
398 // Execute callouts registered for host6_identifier.
399 if (HooksManager::calloutsPresent(Hooks.hook_index_host6_identifier_)) {
400 CalloutHandlePtr callout_handle = getCalloutHandle(pkt);
401
403 std::vector<uint8_t> id;
404
405 // Use the RAII wrapper to make sure that the callout handle state is
406 // reset when this object goes out of scope. All hook points must do
407 // it to prevent possible circular dependency between the callout
408 // handle and its arguments.
409 ScopedCalloutHandleState callout_handle_state(callout_handle);
410
411 // Pass incoming packet as argument
412 callout_handle->setArgument("query6", pkt);
413 callout_handle->setArgument("id_type", type);
414 callout_handle->setArgument("id_value", id);
415
416 // Call callouts
417 HooksManager::callCallouts(Hooks.hook_index_host6_identifier_,
418 *callout_handle);
419
420 callout_handle->getArgument("id_type", type);
421 callout_handle->getArgument("id_value", id);
422
423 if ((callout_handle->getStatus() == CalloutHandle::NEXT_STEP_CONTINUE) &&
424 !id.empty()) {
425
427 .arg(Host::getIdentifierAsText(type, &id[0], id.size()));
428
429 ctx.addHostIdentifier(type, id);
430 }
431 }
432 break;
433 default:
434 ;
435 }
436 }
437
438 // Find host reservations using specified identifiers.
439 alloc_engine_->findReservation(ctx);
440
441 // Get shared network to see if it is set for a subnet.
442 ctx.subnet_->getSharedNetwork(sn);
443 }
444
445 // Global host reservations are independent of a selected subnet. If the
446 // global reservations contain client classes we should use them in case
447 // they are meant to affect pool selection. Also, if the subnet does not
448 // belong to a shared network we can use the reserved client classes
449 // because there is no way our subnet could change. Such classes may
450 // affect selection of a pool within the selected subnet.
451 auto global_host = ctx.globalHost();
452 auto current_host = ctx.currentHost();
453 if ((global_host && !global_host->getClientClasses6().empty()) ||
454 (!sn && current_host && !current_host->getClientClasses6().empty())) {
455 // We have already evaluated client classes and some of them may
456 // be in conflict with the reserved classes. Suppose there are
457 // two classes defined in the server configuration: first_class
458 // and second_class and the test for the second_class it looks
459 // like this: "not member('first_class')". If the first_class
460 // initially evaluates to false, the second_class evaluates to
461 // true. If the first_class is now set within the hosts reservations
462 // and we don't remove the previously evaluated second_class we'd
463 // end up with both first_class and second_class evaluated to
464 // true. In order to avoid that, we have to remove the classes
465 // evaluated in the first pass and evaluate them again. As
466 // a result, the first_class set via the host reservation will
467 // replace the second_class because the second_class will this
468 // time evaluate to false as desired.
469 const ClientClassDictionaryPtr& dict =
470 CfgMgr::instance().getCurrentCfg()->getClientClassDictionary();
471 const ClientClassDefListPtr& defs_ptr = dict->getClasses();
472 for (auto def : *defs_ptr) {
473 // Only remove evaluated classes. Other classes can be
474 // assigned via hooks libraries and we should not remove
475 // them because there is no way they can be added back.
476 if (def->getMatchExpr()) {
477 ctx.query_->classes_.erase(def->getName());
478 }
479 }
480 setReservedClientClasses(pkt, ctx);
481 evaluateClasses(pkt, false);
482 }
483
484 // Set KNOWN builtin class if something was found, UNKNOWN if not.
485 if (!ctx.hosts_.empty()) {
486 pkt->addClass("KNOWN");
488 .arg(pkt->getLabel())
489 .arg("KNOWN");
490 } else {
491 pkt->addClass("UNKNOWN");
493 .arg(pkt->getLabel())
494 .arg("UNKNOWN");
495 }
496
497 // Perform second pass of classification.
498 evaluateClasses(pkt, true);
499
500 // Check the DROP special class.
501 if (pkt->inClass("DROP")) {
503 .arg(pkt->toText());
504 StatsMgr::instance().addValue("pkt6-receive-drop",
505 static_cast<int64_t>(1));
506 drop = true;
507 }
508}
509
511#ifdef ENABLE_AFL
512 // Set up structures needed for fuzzing.
513 Fuzz fuzzer(6, server_port_);
514 //
515 // The next line is needed as a signature for AFL to recognize that we are
516 // running persistent fuzzing. This has to be in the main image file.
517 while (__AFL_LOOP(fuzzer.maxLoopCount())) {
518 // Read from stdin and put the data read into an address/port on which
519 // Kea is listening, read for Kea to read it via asynchronous I/O.
520 fuzzer.transfer();
521#else
522 while (!shutdown_) {
523#endif // ENABLE_AFL
524 try {
525 run_one();
526 getIOService()->poll();
527 } catch (const std::exception& e) {
528 // General catch-all standard exceptions that are not caught by more
529 // specific catches.
531 .arg(e.what());
532
533 } catch (...) {
534 // General catch-all non-standard exception that are not caught
535 // by more specific catches.
537 }
538 }
539
540 // Stop everything before we change into single-threaded mode.
542
543 // destroying the thread pool
544 MultiThreadingMgr::instance().apply(false, 0, 0);
545
546 return (getExitValue());
547}
548
550 // client's message and server's response
551 Pkt6Ptr query;
552
553 try {
554 // Set select() timeout to 1s. This value should not be modified
555 // because it is important that the select() returns control
556 // frequently so as the IOService can be polled for ready handlers.
557 uint32_t timeout = 1;
558 query = receivePacket(timeout);
559
560 // Log if packet has arrived. We can't log the detailed information
561 // about the DHCP message because it hasn't been unpacked/parsed
562 // yet, and it can't be parsed at this point because hooks will
563 // have to process it first. The only information available at this
564 // point are: the interface, source address and destination addresses
565 // and ports.
566 if (query) {
568 .arg(query->getRemoteAddr().toText())
569 .arg(query->getRemotePort())
570 .arg(query->getLocalAddr().toText())
571 .arg(query->getLocalPort())
572 .arg(query->getIface());
573
574 // Log reception of the packet. We need to increase it early, as
575 // any failures in unpacking will cause the packet to be dropped.
576 // we will increase type specific packets further down the road.
577 // See processStatsReceived().
578 StatsMgr::instance().addValue("pkt6-received", static_cast<int64_t>(1));
579 }
580
581 // We used to log that the wait was interrupted, but this is no longer
582 // the case. Our wait time is 1s now, so the lack of query packet more
583 // likely means that nothing new appeared within a second, rather than
584 // we were interrupted. And we don't want to print a message every
585 // second.
586
587 } catch (const SignalInterruptOnSelect&) {
588 // Packet reception interrupted because a signal has been received.
589 // This is not an error because we might have received a SIGTERM,
590 // SIGINT, SIGHUP or SIGCHLD which are handled by the server. For
591 // signals that are not handled by the server we rely on the default
592 // behavior of the system.
594 } catch (const std::exception& e) {
596 }
597
598 // Timeout may be reached or signal received, which breaks select()
599 // with no packet received
600 if (!query) {
601 return;
602 }
603
604 // If the DHCP service has been globally disabled, drop the packet.
605 if (!network_state_->isServiceEnabled()) {
607 .arg(query->getLabel());
608 return;
609 } else {
610 if (MultiThreadingMgr::instance().getMode()) {
611 typedef function<void()> CallBack;
612 boost::shared_ptr<CallBack> call_back =
613 boost::make_shared<CallBack>(std::bind(&Dhcpv6Srv::processPacketAndSendResponseNoThrow,
614 this, query));
615 if (!MultiThreadingMgr::instance().getThreadPool().add(call_back)) {
617 }
618 } else {
620 }
621 }
622}
623
624void
626 try {
628 } catch (const std::exception& e) {
630 .arg(e.what());
631 } catch (...) {
633 }
634}
635
636void
638 Pkt6Ptr rsp;
639 processPacket(query, rsp);
640 if (!rsp) {
641 return;
642 }
643
644 CalloutHandlePtr callout_handle = getCalloutHandle(query);
645 processPacketBufferSend(callout_handle, rsp);
646}
647
648void
650 bool skip_unpack = false;
651
652 // The packet has just been received so contains the uninterpreted wire
653 // data; execute callouts registered for buffer6_receive.
654 if (HooksManager::calloutsPresent(Hooks.hook_index_buffer6_receive_)) {
655 CalloutHandlePtr callout_handle = getCalloutHandle(query);
656
657 // Use the RAII wrapper to make sure that the callout handle state is
658 // reset when this object goes out of scope. All hook points must do
659 // it to prevent possible circular dependency between the callout
660 // handle and its arguments.
661 ScopedCalloutHandleState callout_handle_state(callout_handle);
662
663 // Enable copying options from the packet within hook library.
664 ScopedEnableOptionsCopy<Pkt6> query6_options_copy(query);
665
666 // Pass incoming packet as argument
667 callout_handle->setArgument("query6", query);
668
669 // Call callouts
670 HooksManager::callCallouts(Hooks.hook_index_buffer6_receive_, *callout_handle);
671
672 // Callouts decided to skip the next processing step. The next
673 // processing step would to parse the packet, so skip at this
674 // stage means that callouts did the parsing already, so server
675 // should skip parsing.
676 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) {
678 .arg(query->getRemoteAddr().toText())
679 .arg(query->getLocalAddr().toText())
680 .arg(query->getIface());
681 skip_unpack = true;
682 }
683
684 // Callouts decided to drop the received packet
685 // The response (rsp) is null so the caller (run_one) will
686 // immediately return too.
687 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP) {
689 .arg(query->getRemoteAddr().toText())
690 .arg(query->getLocalAddr().toText())
691 .arg(query->getIface());
692
693 // Increase the statistic of dropped packets.
694 StatsMgr::instance().addValue("pkt6-receive-drop",
695 static_cast<int64_t>(1));
696 return;
697 }
698
699 callout_handle->getArgument("query6", query);
700 }
701
702 // Unpack the packet information unless the buffer6_receive callouts
703 // indicated they did it
704 if (!skip_unpack) {
705 try {
707 .arg(query->getRemoteAddr().toText())
708 .arg(query->getLocalAddr().toText())
709 .arg(query->getIface());
710 query->unpack();
711 } catch (const SkipRemainingOptionsError& e) {
712 // An option failed to unpack but we are to attempt to process it
713 // anyway. Log it and let's hope for the best.
716 .arg(e.what());
717 } catch (const std::exception &e) {
718 // Failed to parse the packet.
720 .arg(query->getRemoteAddr().toText())
721 .arg(query->getLocalAddr().toText())
722 .arg(query->getIface())
723 .arg(e.what());
724
725 // Increase the statistics of parse failures and dropped packets.
726 StatsMgr::instance().addValue("pkt6-parse-failed",
727 static_cast<int64_t>(1));
728 StatsMgr::instance().addValue("pkt6-receive-drop",
729 static_cast<int64_t>(1));
730 return;
731 }
732 }
733
734 // Update statistics accordingly for received packet.
735 processStatsReceived(query);
736
737 // Check if received query carries server identifier matching
738 // server identifier being used by the server.
739 if (!testServerID(query)) {
740
741 // Increase the statistic of dropped packets.
742 StatsMgr::instance().addValue("pkt6-receive-drop", static_cast<int64_t>(1));
743 return;
744 }
745
746 // Check if the received query has been sent to unicast or multicast.
747 // The Solicit, Confirm, Rebind and Information Request will be
748 // discarded if sent to unicast address.
749 if (!testUnicast(query)) {
750
751 // Increase the statistic of dropped packets.
752 StatsMgr::instance().addValue("pkt6-receive-drop", static_cast<int64_t>(1));
753 return;
754 }
755
756 // Assign this packet to a class, if possible
757 classifyPacket(query);
758
760 .arg(query->getLabel())
761 .arg(query->getName())
762 .arg(static_cast<int>(query->getType()))
763 .arg(query->getRemoteAddr())
764 .arg(query->getLocalAddr())
765 .arg(query->getIface());
767 .arg(query->getLabel())
768 .arg(query->toText());
769
770 // At this point the information in the packet has been unpacked into
771 // the various packet fields and option objects has been created.
772 // Execute callouts registered for packet6_receive.
773 if (HooksManager::calloutsPresent(Hooks.hook_index_pkt6_receive_)) {
774 CalloutHandlePtr callout_handle = getCalloutHandle(query);
775
776 // Use the RAII wrapper to make sure that the callout handle state is
777 // reset when this object goes out of scope. All hook points must do
778 // it to prevent possible circular dependency between the callout
779 // handle and its arguments.
780 ScopedCalloutHandleState callout_handle_state(callout_handle);
781
782 // Enable copying options from the packet within hook library.
783 ScopedEnableOptionsCopy<Pkt6> query6_options_copy(query);
784
785 // Pass incoming packet as argument
786 callout_handle->setArgument("query6", query);
787
788 // Call callouts
789 HooksManager::callCallouts(Hooks.hook_index_pkt6_receive_, *callout_handle);
790
791 // Callouts decided to skip the next processing step. The next
792 // processing step would to process the packet, so skip at this
793 // stage means drop.
794 if ((callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) ||
795 (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP)) {
797 .arg(query->getLabel());
798 // Increase the statistic of dropped packets.
799 StatsMgr::instance().addValue("pkt6-receive-drop",
800 static_cast<int64_t>(1));
801 return;
802 }
803
804 callout_handle->getArgument("query6", query);
805 }
806
807 // Reject the message if it doesn't pass the sanity check.
808 if (!sanityCheck(query)) {
809 return;
810 }
811
812 // Check the DROP special class.
813 if (query->inClass("DROP")) {
815 .arg(query->toText());
816 StatsMgr::instance().addValue("pkt6-receive-drop",
817 static_cast<int64_t>(1));
818 return;
819 }
820
821 if (query->getType() == DHCPV6_DHCPV4_QUERY) {
822 // This call never throws. Should this change, this section must be
823 // enclosed in try-catch.
824 processDhcp4Query(query);
825 return;
826 }
827
828 processDhcp6Query(query, rsp);
829}
830
831void
833 try {
834 processDhcp6Query(query, rsp);
835 if (!rsp) {
836 return;
837 }
838
839 CalloutHandlePtr callout_handle = getCalloutHandle(query);
840 processPacketBufferSend(callout_handle, rsp);
841 } catch (const std::exception& e) {
843 .arg(e.what());
844 } catch (...) {
846 }
847}
848
849void
851 // Create a client race avoidance RAII handler.
852 ClientHandler client_handler;
853
854 // Check for lease modifier queries from the same client being processed.
855 if (MultiThreadingMgr::instance().getMode() &&
856 ((query->getType() == DHCPV6_SOLICIT) ||
857 (query->getType() == DHCPV6_REQUEST) ||
858 (query->getType() == DHCPV6_RENEW) ||
859 (query->getType() == DHCPV6_REBIND) ||
860 (query->getType() == DHCPV6_RELEASE) ||
861 (query->getType() == DHCPV6_DECLINE))) {
862 ContinuationPtr cont =
864 this, query, rsp));
865 if (!client_handler.tryLock(query, cont)) {
866 return;
867 }
868 }
869
870 // Let's create a simplified client context here.
872 bool drop = false;
873 initContext(query, ctx, drop);
874
875 // Stop here if initContext decided to drop the packet.
876 if (drop) {
877 return;
878 }
879
880 // Park point here.
881
882 try {
883 switch (query->getType()) {
884 case DHCPV6_SOLICIT:
885 rsp = processSolicit(ctx);
886 break;
887
888 case DHCPV6_REQUEST:
889 rsp = processRequest(ctx);
890 break;
891
892 case DHCPV6_RENEW:
893 rsp = processRenew(ctx);
894 break;
895
896 case DHCPV6_REBIND:
897 rsp = processRebind(ctx);
898 break;
899
900 case DHCPV6_CONFIRM:
901 rsp = processConfirm(ctx);
902 break;
903
904 case DHCPV6_RELEASE:
905 rsp = processRelease(ctx);
906 break;
907
908 case DHCPV6_DECLINE:
909 rsp = processDecline(ctx);
910 break;
911
913 rsp = processInfRequest(ctx);
914 break;
915
916 default:
917 return;
918 }
919
920 } catch (const std::exception& e) {
921
922 // Catch-all exception (at least for ones based on the isc Exception
923 // class, which covers more or less all that are explicitly raised
924 // in the Kea code), but also the standard one, which may possibly be
925 // thrown from boost code. Just log the problem and ignore the packet.
926 // (The problem is logged as a debug message because debug is
927 // disabled by default - it prevents a DDOS attack based on the
928 // sending of problem packets.)
930 .arg(query->getName())
931 .arg(query->getRemoteAddr().toText())
932 .arg(e.what());
933
934 // Increase the statistic of dropped packets.
935 StatsMgr::instance().addValue("pkt6-receive-drop", static_cast<int64_t>(1));
936 }
937
938 if (!rsp) {
939 return;
940 }
941
942 // Process relay-supplied options. It is important to call this very
943 // late in the process, because we now have all the options the
944 // server wanted to send already set. This is important, because
945 // RFC6422, section 6 states:
946 //
947 // The server SHOULD discard any options that appear in the RSOO
948 // for which it already has one or more candidates.
949 //
950 // So we ignore any RSOO options if there's an option with the same
951 // code already present.
952 processRSOO(query, rsp);
953
954 rsp->setRemoteAddr(query->getRemoteAddr());
955 rsp->setLocalAddr(query->getLocalAddr());
956
957 if (client_port_) {
958 // A command line option enforces a specific client port
959 rsp->setRemotePort(client_port_);
960 } else if (rsp->relay_info_.empty()) {
961 // Direct traffic, send back to the client directly
962 rsp->setRemotePort(DHCP6_CLIENT_PORT);
963 } else {
964 // Relayed traffic, send back to the relay agent
965 uint16_t relay_port = checkRelaySourcePort(query);
966 rsp->setRemotePort(relay_port ? relay_port : DHCP6_SERVER_PORT);
967 }
968
969 if (server_port_) {
970 rsp->setLocalPort(server_port_);
971 } else {
972 rsp->setLocalPort(DHCP6_SERVER_PORT);
973 }
974 rsp->setIndex(query->getIndex());
975 rsp->setIface(query->getIface());
976
977 CalloutHandlePtr callout_handle = getCalloutHandle(query);
978 if (!ctx.fake_allocation_ && (ctx.query_->getType() != DHCPV6_CONFIRM) &&
979 (ctx.query_->getType() != DHCPV6_INFORMATION_REQUEST) &&
980 HooksManager::calloutsPresent(Hooks.hook_index_leases6_committed_)) {
981 // The ScopedCalloutHandleState class which guarantees that the task
982 // is added to the thread pool after the response is reset (if needed)
983 // and CalloutHandle state is reset. In ST it does nothing.
984 // A smart pointer is used to store the ScopedCalloutHandleState so that
985 // a copy of the pointer is created by the lambda and only on the
986 // destruction of the last reference the task is added.
987 // In MT there are 2 cases:
988 // 1. packet is unparked before current thread smart pointer to
989 // ScopedCalloutHandleState is destroyed:
990 // - the lamba uses the smart pointer to set the callout which adds the
991 // task, but the task is added after ScopedCalloutHandleState is
992 // destroyed, on the destruction of the last reference which is held
993 // by the current thread.
994 // 2. packet is unparked after the current thread smart pointer to
995 // ScopedCalloutHandleState is destroyed:
996 // - the current thread reference to ScopedCalloutHandleState is
997 // destroyed, but the reference in the lambda keeps it alive until
998 // the lamba is called and the last reference is released, at which
999 // time the task is actually added.
1000 // Use the RAII wrapper to make sure that the callout handle state is
1001 // reset when this object goes out of scope. All hook points must do
1002 // it to prevent possible circular dependency between the callout
1003 // handle and its arguments.
1004 std::shared_ptr<ScopedCalloutHandleState> callout_handle_state =
1005 std::make_shared<ScopedCalloutHandleState>(callout_handle);
1006
1007 ScopedEnableOptionsCopy<Pkt6> query6_options_copy(query);
1008
1009 // Also pass the corresponding query packet as argument
1010 callout_handle->setArgument("query6", query);
1011
1012 Lease6CollectionPtr new_leases(new Lease6Collection());
1013 if (!ctx.new_leases_.empty()) {
1014 // Filter out reused leases as they were not committed.
1015 for (auto new_lease : ctx.new_leases_) {
1016 if (new_lease->reuseable_valid_lft_ == 0) {
1017 new_leases->push_back(new_lease);
1018 }
1019 }
1020 }
1021 callout_handle->setArgument("leases6", new_leases);
1022
1023 Lease6CollectionPtr deleted_leases(new Lease6Collection());
1024
1025 // Do per IA lists
1026 for (auto const& iac : ctx.ias_) {
1027 if (!iac.old_leases_.empty()) {
1028 for (auto old_lease : iac.old_leases_) {
1029 if (ctx.new_leases_.empty()) {
1030 deleted_leases->push_back(old_lease);
1031 continue;
1032 }
1033 bool in_new = false;
1034 for (auto const& new_lease : ctx.new_leases_) {
1035 if ((new_lease->addr_ == old_lease->addr_) &&
1036 (new_lease->prefixlen_ == old_lease->prefixlen_)) {
1037 in_new = true;
1038 break;
1039 }
1040 }
1041 if (!in_new) {
1042 deleted_leases->push_back(old_lease);
1043 }
1044 }
1045 }
1046 }
1047 callout_handle->setArgument("deleted_leases6", deleted_leases);
1048
1049 // Get the parking limit. Parsing should ensure the value is present.
1050 uint32_t parked_packet_limit = 0;
1052 getCurrentCfg()->getConfiguredGlobal("parked-packet-limit");
1053 if (ppl) {
1054 parked_packet_limit = ppl->intValue();
1055 }
1056
1057 if (parked_packet_limit) {
1058 const auto& parking_lot = ServerHooks::getServerHooks().
1059 getParkingLotPtr("leases6_committed");
1060 if (parking_lot && (parking_lot->size() >= parked_packet_limit)) {
1061 // We can't park it so we're going to throw it on the floor.
1064 .arg(parked_packet_limit)
1065 .arg(query->getLabel());
1066 isc::stats::StatsMgr::instance().addValue("pkt6-receive-drop",
1067 static_cast<int64_t>(1));
1068 rsp.reset();
1069 return;
1070 }
1071 }
1072
1073 // We proactively park the packet. We'll unpark it without invoking
1074 // the callback (i.e. drop) unless the callout status is set to
1075 // NEXT_STEP_PARK. Otherwise the callback we bind here will be
1076 // executed when the hook library unparks the packet.
1077 HooksManager::park("leases6_committed", query,
1078 [this, callout_handle, query, rsp, callout_handle_state]() mutable {
1079 if (MultiThreadingMgr::instance().getMode()) {
1080 typedef function<void()> CallBack;
1081 boost::shared_ptr<CallBack> call_back =
1082 boost::make_shared<CallBack>(std::bind(&Dhcpv6Srv::sendResponseNoThrow,
1083 this, callout_handle, query, rsp));
1084 callout_handle_state->on_completion_ = [call_back]() {
1085 MultiThreadingMgr::instance().getThreadPool().add(call_back);
1086 };
1087 } else {
1088 processPacketPktSend(callout_handle, query, rsp);
1089 processPacketBufferSend(callout_handle, rsp);
1090 }
1091 });
1092
1093 try {
1094 // Call all installed callouts
1095 HooksManager::callCallouts(Hooks.hook_index_leases6_committed_,
1096 *callout_handle);
1097 } catch (...) {
1098 // Make sure we don't orphan a parked packet.
1099 HooksManager::drop("leases4_committed", query);
1100 throw;
1101 }
1102
1103 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_PARK) {
1105 .arg(query->getLabel());
1106 // Since the hook library(ies) are going to do the unparking, then
1107 // reset the pointer to the response to indicate to the caller that
1108 // it should return, as the packet processing will continue via
1109 // the callback.
1110 rsp.reset();
1111 } else {
1112 // Drop the park job on the packet, it isn't needed.
1113 HooksManager::drop("leases6_committed", query);
1114 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP) {
1116 .arg(query->getLabel());
1117 rsp.reset();
1118 }
1119 }
1120 }
1121
1122 // If we have a response prep it for shipment.
1123 if (rsp) {
1124 processPacketPktSend(callout_handle, query, rsp);
1125 }
1126}
1127
1128void
1130 Pkt6Ptr& query, Pkt6Ptr& rsp) {
1131 try {
1132 processPacketPktSend(callout_handle, query, rsp);
1133 processPacketBufferSend(callout_handle, rsp);
1134 } catch (const std::exception& e) {
1136 .arg(e.what());
1137 } catch (...) {
1139 }
1140}
1141
1142void
1144 Pkt6Ptr& query, Pkt6Ptr& rsp) {
1145 if (!rsp) {
1146 return;
1147 }
1148
1149 // Specifies if server should do the packing
1150 bool skip_pack = false;
1151
1152 // Server's reply packet now has all options and fields set.
1153 // Options are represented by individual objects, but the
1154 // output wire data has not been prepared yet.
1155 // Execute all callouts registered for packet6_send
1156 if (HooksManager::calloutsPresent(Hooks.hook_index_pkt6_send_)) {
1157
1158 // Use the RAII wrapper to make sure that the callout handle state is
1159 // reset when this object goes out of scope. All hook points must do
1160 // it to prevent possible circular dependency between the callout
1161 // handle and its arguments.
1162 ScopedCalloutHandleState callout_handle_state(callout_handle);
1163
1164 // Enable copying options from the packets within hook library.
1165 ScopedEnableOptionsCopy<Pkt6> query_resp_options_copy(query, rsp);
1166
1167 // Pass incoming packet as argument
1168 callout_handle->setArgument("query6", query);
1169
1170 // Set our response
1171 callout_handle->setArgument("response6", rsp);
1172
1173 // Call all installed callouts
1174 HooksManager::callCallouts(Hooks.hook_index_pkt6_send_, *callout_handle);
1175
1176 // Callouts decided to skip the next processing step. The next
1177 // processing step would to pack the packet (create wire data).
1178 // That step will be skipped if any callout sets skip flag.
1179 // It essentially means that the callout already did packing,
1180 // so the server does not have to do it again.
1181 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) {
1183 .arg(rsp->getLabel());
1184 skip_pack = true;
1185 }
1186
1188 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP) {
1190 .arg(rsp->getLabel());
1191 rsp.reset();
1192 return;
1193 }
1194 }
1195
1196 if (!skip_pack) {
1197 try {
1198 rsp->pack();
1199 } catch (const std::exception& e) {
1201 return;
1202 }
1203
1204 }
1205}
1206
1207void
1209 Pkt6Ptr& rsp) {
1210 if (!rsp) {
1211 return;
1212 }
1213
1214 try {
1215 // Now all fields and options are constructed into output wire buffer.
1216 // Option objects modification does not make sense anymore. Hooks
1217 // can only manipulate wire buffer at this stage.
1218 // Let's execute all callouts registered for buffer6_send
1219 if (HooksManager::calloutsPresent(Hooks.hook_index_buffer6_send_)) {
1220
1221 // Use the RAII wrapper to make sure that the callout handle state is
1222 // reset when this object goes out of scope. All hook points must do
1223 // it to prevent possible circular dependency between the callout
1224 // handle and its arguments.
1225 ScopedCalloutHandleState callout_handle_state(callout_handle);
1226
1227 // Enable copying options from the packet within hook library.
1228 ScopedEnableOptionsCopy<Pkt6> response6_options_copy(rsp);
1229
1230 // Pass incoming packet as argument
1231 callout_handle->setArgument("response6", rsp);
1232
1233 // Call callouts
1234 HooksManager::callCallouts(Hooks.hook_index_buffer6_send_,
1235 *callout_handle);
1236
1237 // Callouts decided to skip the next processing step. The next
1238 // processing step would to parse the packet, so skip at this
1239 // stage means drop.
1240 if ((callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) ||
1241 (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP)) {
1244 .arg(rsp->getLabel());
1245 return;
1246 }
1247
1248 callout_handle->getArgument("response6", rsp);
1249 }
1250
1252 .arg(rsp->getLabel())
1253 .arg(rsp->getName())
1254 .arg(static_cast<int>(rsp->getType()))
1255 .arg(rsp->getLocalAddr().isV6Zero() ? "*" : rsp->getLocalAddr().toText())
1256 .arg(rsp->getLocalPort())
1257 .arg(rsp->getRemoteAddr())
1258 .arg(rsp->getRemotePort())
1259 .arg(rsp->getIface());
1260
1262 .arg(static_cast<int>(rsp->getType())).arg(rsp->toText());
1263
1264 sendPacket(rsp);
1265
1266 // Update statistics accordingly for sent packet.
1267 processStatsSent(rsp);
1268
1269 } catch (const std::exception& e) {
1271 }
1272}
1273
1274std::string
1276 stringstream tmp;
1277
1278 OptionBuffer data = opt->getData();
1279
1280 bool colon = false;
1281 for (OptionBufferConstIter it = data.begin(); it != data.end(); ++it) {
1282 if (colon) {
1283 tmp << ":";
1284 }
1285 tmp << hex << setw(2) << setfill('0') << static_cast<uint16_t>(*it);
1286 if (!colon) {
1287 colon = true;
1288 }
1289 }
1290
1291 return tmp.str();
1292}
1293
1294void
1296 // Add client-id.
1297 OptionPtr clientid = question->getOption(D6O_CLIENTID);
1298 if (clientid) {
1299 answer->addOption(clientid);
1300 }
1302
1303 // If this is a relayed message, we need to copy relay information
1304 if (!question->relay_info_.empty()) {
1305 answer->copyRelayInfo(question);
1306 }
1307
1308}
1309
1310void
1312 const CfgOptionList&) {
1313 // add server-id
1314 answer->addOption(getServerID());
1315}
1316
1317void
1320 CfgOptionList& co_list) {
1321 // Firstly, host specific options.
1322 if (ctx.currentHost() && !ctx.currentHost()->getCfgOption6()->empty()) {
1323 co_list.push_back(ctx.currentHost()->getCfgOption6());
1324 }
1325
1326 // Secondly, pool specific options. Pools are defined within a subnet, so
1327 // if there is no subnet, there is nothing to do.
1328 if (ctx.subnet_) {
1329 for (auto resource : ctx.allocated_resources_) {
1330 PoolPtr pool =
1331 ctx.subnet_->getPool(resource.getPrefixLength() == 128 ?
1333 resource.getAddress(),
1334 false);
1335 if (pool && !pool->getCfgOption()->empty()) {
1336 co_list.push_back(pool->getCfgOption());
1337 }
1338 }
1339 };
1340
1341 if (ctx.subnet_) {
1342 // Next, subnet configured options.
1343 if (!ctx.subnet_->getCfgOption()->empty()) {
1344 co_list.push_back(ctx.subnet_->getCfgOption());
1345 }
1346
1347 // Then, shared network specific options.
1348 SharedNetwork6Ptr network;
1349 ctx.subnet_->getSharedNetwork(network);
1350 if (network && !network->getCfgOption()->empty()) {
1351 co_list.push_back(network->getCfgOption());
1352 }
1353 }
1354
1355 // Each class in the incoming packet
1356 const ClientClasses& classes = question->getClasses();
1357 for (ClientClasses::const_iterator cclass = classes.cbegin();
1358 cclass != classes.cend(); ++cclass) {
1359 // Find the client class definition for this class
1361 getClientClassDictionary()->findClass(*cclass);
1362 if (!ccdef) {
1363 // Not found: the class is built-in or not configured
1364 if (!isClientClassBuiltIn(*cclass)) {
1366 .arg(question->getLabel())
1367 .arg(*cclass);
1368 }
1369 // Skip it
1370 continue;
1371 }
1372
1373 if (ccdef->getCfgOption()->empty()) {
1374 // Skip classes which don't configure options
1375 continue;
1376 }
1377
1378 co_list.push_back(ccdef->getCfgOption());
1379 }
1380
1381 // Last global options
1382 if (!CfgMgr::instance().getCurrentCfg()->getCfgOption()->empty()) {
1383 co_list.push_back(CfgMgr::instance().getCurrentCfg()->getCfgOption());
1384 }
1385}
1386
1387void
1389 const CfgOptionList& co_list) {
1390
1391 // Unlikely short cut
1392 if (co_list.empty()) {
1393 return;
1394 }
1395
1396 std::vector<uint16_t> requested_opts;
1397
1398 // Client requests some options using ORO option. Try to
1399 // get this option from client's message.
1400 boost::shared_ptr<OptionIntArray<uint16_t> > option_oro =
1401 boost::dynamic_pointer_cast<OptionIntArray<uint16_t> >
1402 (question->getOption(D6O_ORO));
1403
1404 // Get the list of options that client requested.
1405 if (option_oro) {
1406 requested_opts = option_oro->getValues();
1407 }
1408 // Iterate on the configured option list to add persistent options
1409 for (CfgOptionList::const_iterator copts = co_list.begin();
1410 copts != co_list.end(); ++copts) {
1411 const OptionContainerPtr& opts = (*copts)->getAll(DHCP6_OPTION_SPACE);
1412 if (!opts) {
1413 continue;
1414 }
1415 // Get persistent options
1416 const OptionContainerPersistIndex& idx = opts->get<2>();
1417 const OptionContainerPersistRange& range = idx.equal_range(true);
1418 for (OptionContainerPersistIndex::const_iterator desc = range.first;
1419 desc != range.second; ++desc) {
1420 // Add the persistent option code to requested options
1421 if (desc->option_) {
1422 requested_opts.push_back(desc->option_->getType());
1423 }
1424 }
1425 }
1426
1427 for (uint16_t opt : requested_opts) {
1428 // Add nothing when it is already there.
1429 if (!answer->getOption(opt)) {
1430 // Iterate on the configured option list
1431 for (CfgOptionList::const_iterator copts = co_list.begin();
1432 copts != co_list.end(); ++copts) {
1433 OptionDescriptor desc = (*copts)->get(DHCP6_OPTION_SPACE, opt);
1434 // Got it: add it and jump to the outer loop
1435 if (desc.option_) {
1436 answer->addOption(desc.option_);
1437 break;
1438 }
1439 }
1440 }
1441 }
1442}
1443
1444void
1446 Pkt6Ptr& answer,
1448 const CfgOptionList& co_list) {
1449
1450 // Leave if there is no subnet matching the incoming packet.
1451 // There is no need to log the error message here because
1452 // it will be logged in the assignLease() when it fails to
1453 // pick the suitable subnet. We don't want to duplicate
1454 // error messages in such case.
1455 //
1456 // Also, if there's no options to possibly assign, give up.
1457 if (!ctx.subnet_ || co_list.empty()) {
1458 return;
1459 }
1460
1461 uint32_t vendor_id = 0;
1462
1463 // The server could have provided the option using client classification or
1464 // hooks. If there's a vendor info option in the response already, use that.
1465 OptionVendorPtr vendor_rsp(boost::dynamic_pointer_cast<OptionVendor>(
1466 answer->getOption(D6O_VENDOR_OPTS)));
1467 if (vendor_rsp) {
1468 vendor_id = vendor_rsp->getVendorId();
1469 }
1470
1471 // Otherwise, try to get the vendor-id from the client packet's
1472 // vendor-specific information option (17).
1473 OptionVendorPtr vendor_req;
1474 if (vendor_id == 0) {
1475 vendor_req = boost::dynamic_pointer_cast<OptionVendor>(
1476 question->getOption(D6O_VENDOR_OPTS));
1477 if (vendor_req) {
1478 vendor_id = vendor_req->getVendorId();
1479 }
1480 }
1481
1482 // Finally, try to get the vendor-id from the client packet's vendor-class
1483 // option (16).
1484 if (vendor_id == 0) {
1485 OptionVendorClassPtr vendor_class(
1486 boost::dynamic_pointer_cast<OptionVendorClass>(
1487 question->getOption(D6O_VENDOR_CLASS)));
1488 if (vendor_class) {
1489 vendor_id = vendor_class->getVendorId();
1490 }
1491 }
1492
1493 // If there's no vendor option in either request or response, then there's no way
1494 // to figure out what the vendor-id value is and we give up.
1495 if (vendor_id == 0) {
1496 return;
1497 }
1498
1499 std::vector<uint16_t> requested_opts;
1500
1501 // Let's try to get ORO within that vendor-option.
1502 // This is specific to vendor-id=4491 (Cable Labs). Other vendors may have
1503 // different policies.
1505 if (vendor_id == VENDOR_ID_CABLE_LABS && vendor_req) {
1506 OptionPtr oro_generic = vendor_req->getOption(DOCSIS3_V6_ORO);
1507 if (oro_generic) {
1508 // Vendor ID 4491 makes Kea look at DOCSIS3_V6_OPTION_DEFINITIONS
1509 // when parsing options. Based on that, oro_generic will have been
1510 // created as an OptionUint16Array, but might not be for other
1511 // vendor IDs.
1512 oro = boost::dynamic_pointer_cast<OptionUint16Array>(oro_generic);
1513 if (oro) {
1514 requested_opts = oro->getValues();
1515 }
1516 }
1517 }
1518
1519 // Iterate on the configured option list to add persistent options
1520 for (CfgOptionList::const_iterator copts = co_list.begin();
1521 copts != co_list.end(); ++copts) {
1522 const OptionContainerPtr& opts = (*copts)->getAll(vendor_id);
1523 if (!opts) {
1524 continue;
1525 }
1526 // Get persistent options
1527 const OptionContainerPersistIndex& idx = opts->get<2>();
1528 const OptionContainerPersistRange& range = idx.equal_range(true);
1529 for (OptionContainerPersistIndex::const_iterator desc = range.first;
1530 desc != range.second; ++desc) {
1531 // Add the persistent option code to requested options
1532 if (desc->option_) {
1533 requested_opts.push_back(desc->option_->getType());
1534 }
1535 }
1536 }
1537
1538 // If there is nothing to add don't do anything then.
1539 if (requested_opts.empty()) {
1540 return;
1541 }
1542
1543 if (!vendor_rsp) {
1544 // It's possible that the vendor opts option was inserted already
1545 // by client class or a hook. If that is so, let's use it.
1546 vendor_rsp.reset(new OptionVendor(Option::V6, vendor_id));
1547 }
1548
1549 // Get the list of options that client requested.
1550 bool added = false;
1551
1552 for (uint16_t opt : requested_opts) {
1553 if (!vendor_rsp->getOption(opt)) {
1554 for (CfgOptionList::const_iterator copts = co_list.begin();
1555 copts != co_list.end(); ++copts) {
1556 OptionDescriptor desc = (*copts)->get(vendor_id, opt);
1557 if (desc.option_) {
1558 vendor_rsp->addOption(desc.option_);
1559 added = true;
1560 break;
1561 }
1562 }
1563 }
1564 }
1565
1566 // If we added some sub-options and the vendor opts option is not in
1567 // the response already, then add it.
1568 if (added && !answer->getOption(D6O_VENDOR_OPTS)) {
1569 answer->addOption(vendor_rsp);
1570 }
1571}
1572
1573bool
1575 try {
1576 switch (pkt->getType()) {
1577 case DHCPV6_SOLICIT:
1578 case DHCPV6_REBIND:
1579 case DHCPV6_CONFIRM:
1581 return (true);
1582
1583 case DHCPV6_REQUEST:
1584 case DHCPV6_RENEW:
1585 case DHCPV6_RELEASE:
1586 case DHCPV6_DECLINE:
1588 return (true);
1589
1593 return (true);
1594
1595 default:
1598 .arg(static_cast<int>(pkt->getType()))
1599 .arg(pkt->getIface());
1600 }
1601
1602 } catch (const RFCViolation& e) {
1604 .arg(pkt->getName())
1605 .arg(pkt->getRemoteAddr().toText())
1606 .arg(e.what());
1607
1608 }
1609
1610 // Increase the statistic of dropped packets.
1611 StatsMgr::instance().addValue("pkt6-receive-drop", static_cast<int64_t>(1));
1612 return (false);
1613}
1614
1615void
1617 RequirementLevel serverid) {
1618 OptionCollection client_ids = pkt->getOptions(D6O_CLIENTID);
1619 switch (clientid) {
1620 case MANDATORY: {
1621 if (client_ids.size() != 1) {
1622 isc_throw(RFCViolation, "Exactly 1 client-id option expected in "
1623 << pkt->getName() << ", but " << client_ids.size()
1624 << " received");
1625 }
1626 sanityCheckDUID(client_ids.begin()->second, "client-id");
1627 break;
1628 }
1629 case OPTIONAL:
1630 if (client_ids.size() > 1) {
1631 isc_throw(RFCViolation, "Too many (" << client_ids.size()
1632 << ") client-id options received in " << pkt->getName());
1633 }
1634 if (!client_ids.empty()) {
1635 sanityCheckDUID(client_ids.begin()->second, "client-id");
1636 }
1637 break;
1638
1639 case FORBIDDEN:
1640 // doesn't make sense - client-id is always allowed
1641 break;
1642 }
1643
1644 OptionCollection server_ids = pkt->getOptions(D6O_SERVERID);
1645 switch (serverid) {
1646 case FORBIDDEN:
1647 if (!server_ids.empty()) {
1648 isc_throw(RFCViolation, "Server-id option was not expected, but "
1649 << server_ids.size() << " received in " << pkt->getName());
1650 }
1651 break;
1652
1653 case MANDATORY:
1654 if (server_ids.size() != 1) {
1655 isc_throw(RFCViolation, "Invalid number of server-id options received ("
1656 << server_ids.size() << "), exactly 1 expected in message "
1657 << pkt->getName());
1658 }
1659 sanityCheckDUID(server_ids.begin()->second, "server-id");
1660 break;
1661
1662 case OPTIONAL:
1663 if (server_ids.size() > 1) {
1664 isc_throw(RFCViolation, "Too many (" << server_ids.size()
1665 << ") server-id options received in " << pkt->getName());
1666 }
1667 if (!server_ids.empty()) {
1668 sanityCheckDUID(server_ids.begin()->second, "server-id");
1669 }
1670 }
1671}
1672
1673void Dhcpv6Srv::sanityCheckDUID(const OptionPtr& opt, const std::string& opt_name) {
1674 if (!opt) {
1675 isc_throw(RFCViolation, "Unable to find expected option " << opt_name);
1676 }
1677
1678 // The client-id or server-id has to have at least 3 bytes of useful data:
1679 // two for duid type and one more for actual duid value.
1680 uint16_t len = opt->len() - opt->getHeaderLen();
1681 if (len < 3 || len > DUID::MAX_DUID_LEN || opt->getData().empty()) {
1682 isc_throw(RFCViolation, "Received invalid DUID for " << opt_name << ", received "
1683 << len << " byte(s). It must be at least 3 and no more than "
1685 }
1686}
1687
1689Dhcpv6Srv::selectSubnet(const Pkt6Ptr& question, bool& drop) {
1690 const SubnetSelector& selector = CfgSubnets6::initSelector(question);
1691
1693 getCfgSubnets6()->selectSubnet(selector);
1694
1695 // Let's execute all callouts registered for subnet6_receive
1696 if (HooksManager::calloutsPresent(Hooks.hook_index_subnet6_select_)) {
1697 CalloutHandlePtr callout_handle = getCalloutHandle(question);
1698
1699 // Use the RAII wrapper to make sure that the callout handle state is
1700 // reset when this object goes out of scope. All hook points must do
1701 // it to prevent possible circular dependency between the callout
1702 // handle and its arguments.
1703 ScopedCalloutHandleState callout_handle_state(callout_handle);
1704
1705 // Enable copying options from the packet within hook library.
1706 ScopedEnableOptionsCopy<Pkt6> query6_options_copy(question);
1707
1708 // Set new arguments
1709 callout_handle->setArgument("query6", question);
1710 callout_handle->setArgument("subnet6", subnet);
1711
1712 // We pass pointer to const collection for performance reasons.
1713 // Otherwise we would get a non-trivial performance penalty each
1714 // time subnet6_select is called.
1715 callout_handle->setArgument("subnet6collection",
1716 CfgMgr::instance().getCurrentCfg()->
1717 getCfgSubnets6()->getAll());
1718
1719 // Call user (and server-side) callouts
1720 HooksManager::callCallouts(Hooks.hook_index_subnet6_select_, *callout_handle);
1721
1722 // Callouts decided to skip this step. This means that no
1723 // subnet will be selected. Packet processing will continue,
1724 // but it will be severely limited (i.e. only global options
1725 // will be assigned)
1726 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) {
1728 .arg(question->getLabel());
1729 return (Subnet6Ptr());
1730 }
1731
1732 // Callouts decided to drop the packet. It is a superset of the
1733 // skip case so no subnet will be selected.
1734 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP) {
1736 .arg(question->getLabel());
1737 drop = true;
1738 return (Subnet6Ptr());
1739 }
1740
1741 // Use whatever subnet was specified by the callout
1742 callout_handle->getArgument("subnet6", subnet);
1743 }
1744
1745 if (subnet) {
1746 // Log at higher debug level that subnet has been found.
1748 .arg(question->getLabel())
1749 .arg(subnet->getID());
1750 // Log detailed information about the selected subnet at the
1751 // lower debug level.
1753 .arg(question->getLabel())
1754 .arg(subnet->toText());
1755
1756 } else {
1758 .arg(question->getLabel());
1759 }
1760
1761 return (subnet);
1762}
1763
1764void
1765Dhcpv6Srv::assignLeases(const Pkt6Ptr& question, Pkt6Ptr& answer,
1767 // Save the originally selected subnet.
1768 Subnet6Ptr orig_subnet = ctx.subnet_;
1769
1770 // We need to allocate addresses for all IA_NA options in the client's
1771 // question (i.e. SOLICIT or REQUEST) message.
1772 // @todo add support for IA_TA
1773
1774 // For the lease allocation it is critical that the client has sent
1775 // DUID. There is no need to check for the presence of the DUID here
1776 // because we have already checked it in the sanityCheck().
1777
1778 // Now that we have all information about the client, let's iterate over all
1779 // received options and handle IA_NA options one by one and store our
1780 // responses in answer message (ADVERTISE or REPLY).
1781 //
1782 // @todo: IA_TA once we implement support for temporary addresses.
1783 for (OptionCollection::iterator opt = question->options_.begin();
1784 opt != question->options_.end(); ++opt) {
1785 switch (opt->second->getType()) {
1786 case D6O_IA_NA: {
1787 OptionPtr answer_opt = assignIA_NA(question, ctx,
1788 boost::dynamic_pointer_cast<
1789 Option6IA>(opt->second));
1790 if (answer_opt) {
1791 answer->addOption(answer_opt);
1792 }
1793 break;
1794 }
1795 case D6O_IA_PD: {
1796 OptionPtr answer_opt = assignIA_PD(question, ctx,
1797 boost::dynamic_pointer_cast<
1798 Option6IA>(opt->second));
1799 if (answer_opt) {
1800 answer->addOption(answer_opt);
1801 }
1802 break;
1803 }
1804 default:
1805 break;
1806 }
1807 }
1808
1809 // Subnet may be modified by the allocation engine, there are things
1810 // we need to do when that happens.
1811 checkDynamicSubnetChange(question, answer, ctx, orig_subnet);
1812}
1813
1814void
1815Dhcpv6Srv::processClientFqdn(const Pkt6Ptr& question, const Pkt6Ptr& answer,
1818 DdnsParamsPtr ddns_params = ctx.getDdnsParams();
1819
1820 // Get Client FQDN Option from the client's message. If this option hasn't
1821 // been included, do nothing.
1822 Option6ClientFqdnPtr fqdn = boost::dynamic_pointer_cast<
1823 Option6ClientFqdn>(question->getOption(D6O_CLIENT_FQDN));
1824 if (!fqdn) {
1825 if (ddns_params->getEnableUpdates() &&
1826 (ddns_params->getReplaceClientNameMode() == D2ClientConfig::RCM_ALWAYS ||
1827 ddns_params->getReplaceClientNameMode() == D2ClientConfig::RCM_WHEN_NOT_PRESENT)) {
1828 // Fabricate an empty "client" FQDN with flags requesting
1829 // the server do all the updates. The flags will get modified
1830 // below according the configuration options, the name will
1831 // be supplied later on.
1835 .arg(question->getLabel());
1836 } else {
1837 // No FQDN so get the lease hostname from the host reservation if
1838 // there is one.
1839 if (ctx.currentHost()) {
1840 ctx.hostname_ = ctx.currentHost()->getHostname();
1841 }
1842
1843 return;
1844 }
1845 }
1846
1848 .arg(question->getLabel())
1849 .arg(fqdn->toText());
1850
1851 // Create the DHCPv6 Client FQDN Option to be included in the server's
1852 // response to a client.
1853 Option6ClientFqdnPtr fqdn_resp(new Option6ClientFqdn(*fqdn));
1854
1855 // Set the server S, N, and O flags based on client's flags and
1856 // current configuration.
1857 d2_mgr.adjustFqdnFlags<Option6ClientFqdn>(*fqdn, *fqdn_resp, *ddns_params);
1858
1859 // Get DDNS update direction flags
1861 ctx.rev_dns_update_);
1862
1863 // If there's a reservation and it has a hostname specified, use it!
1864 if (ctx.currentHost() && !ctx.currentHost()->getHostname().empty()) {
1865 // Add the qualifying suffix.
1866 // After #3765, this will only occur if the suffix is not empty.
1867 fqdn_resp->setDomainName(d2_mgr.qualifyName(ctx.currentHost()->getHostname(),
1868 *ddns_params, true),
1870 } else {
1871 // Adjust the domain name based on domain name value and type sent by
1872 // the client and current configuration.
1873 d2_mgr.adjustDomainName<Option6ClientFqdn>(*fqdn, *fqdn_resp, *ddns_params);
1874 }
1875
1876 // Once we have the FQDN setup to use it for the lease hostname. This
1877 // only gets replaced later if the FQDN is to be generated from the address.
1878 ctx.hostname_ = fqdn_resp->getDomainName();
1879
1880 // The FQDN has been processed successfully. Let's append it to the
1881 // response to be sent to a client. Note that the Client FQDN option is
1882 // always sent back to the client if Client FQDN was included in the
1883 // client's message.
1885 .arg(question->getLabel())
1886 .arg(fqdn_resp->toText());
1887 answer->addOption(fqdn_resp);
1888}
1889
1890void
1893 // Don't create NameChangeRequests if DNS updates are disabled.
1894 if (!(ctx.getDdnsParams()->getEnableUpdates())) {
1895 return;
1896 }
1897
1898 // The response message instance is always required. For instance it
1899 // holds the Client Identifier. It is a programming error if supplied
1900 // message is NULL.
1901 if (!answer) {
1902 isc_throw(isc::Unexpected, "an instance of the object"
1903 << " encapsulating server's message must not be"
1904 << " NULL when creating DNS NameChangeRequest");
1905 }
1906
1907 // It is likely that client haven't included the FQDN option. In such case,
1908 // FQDN option will be NULL. This is valid state, so we simply return.
1909 Option6ClientFqdnPtr opt_fqdn = boost::dynamic_pointer_cast<
1910 Option6ClientFqdn>(answer->getOption(D6O_CLIENT_FQDN));
1911 if (!opt_fqdn) {
1912 return;
1913 }
1914
1915 // Get the update directions that should be performed based on our
1916 // response FQDN flags.
1917 bool do_fwd = false;
1918 bool do_rev = false;
1920 do_fwd, do_rev);
1921
1922 // Get the Client Id. It is mandatory and a function creating a response
1923 // would have thrown an exception if it was missing. Thus throwing
1924 // Unexpected if it is missing as it is a programming error.
1925 OptionPtr opt_duid = answer->getOption(D6O_CLIENTID);
1926 if (!opt_duid) {
1928 "client identifier is required when creating a new"
1929 " DNS NameChangeRequest");
1930 }
1931 DuidPtr duid = DuidPtr(new DUID(opt_duid->getData()));
1932
1933 // Get the FQDN in the on-wire format. It will be needed to compute
1934 // DHCID.
1935 OutputBuffer name_buf(1);
1936 opt_fqdn->packDomainName(name_buf);
1937 const uint8_t* name_data = static_cast<const uint8_t*>(name_buf.getData());
1938 // @todo currently D2Dhcid accepts a vector holding FQDN.
1939 // However, it will be faster if we used a pointer name_data.
1940 std::vector<uint8_t> buf_vec(name_data, name_data + name_buf.getLength());
1941 // Compute DHCID from Client Identifier and FQDN.
1942 isc::dhcp_ddns::D2Dhcid dhcid(*duid, buf_vec);
1943
1944 // Get all IAs from the answer. For each IA, holding an address we will
1945 // create a corresponding NameChangeRequest.
1946 for (auto answer_ia : answer->getOptions(D6O_IA_NA)) {
1949 Option6IAAddrPtr iaaddr = boost::static_pointer_cast<
1950 Option6IAAddr>(answer_ia.second->getOption(D6O_IAADDR));
1951
1952 // We need an address to create a name-to-address mapping.
1953 // If address is missing for any reason, go to the next IA.
1954 if (!iaaddr) {
1955 continue;
1956 }
1957
1958 // If the lease for iaaddr is in the list of changed leases, we need
1959 // to determine if the changes included changes to the FQDN. If so
1960 // then we may need to do a CHG_REMOVE.
1961 bool extended_only = false;
1962 for (Lease6Collection::const_iterator l = ctx.currentIA().changed_leases_.begin();
1963 l != ctx.currentIA().changed_leases_.end(); ++l) {
1964
1965 if ((*l)->addr_ == iaaddr->getAddress()) {
1966 // The address is the same so this must be renewal. If we're not
1967 // always updating on renew, then we only renew if DNS info has
1968 // changed.
1969 if (!ctx.getDdnsParams()->getUpdateOnRenew() &&
1970 ((*l)->hostname_ == opt_fqdn->getDomainName() &&
1971 (*l)->fqdn_fwd_ == do_fwd && (*l)->fqdn_rev_ == do_rev)) {
1972 extended_only = true;
1973 } else {
1974 // Queue a CHG_REMOVE of the old data.
1975 // NCR will only be created if the lease hostname is not
1976 // empty and at least one of the direction flags is true
1977 queueNCR(CHG_REMOVE, *l);
1978 }
1979
1980 break;
1981 }
1982 }
1983
1984 if (!(do_fwd || do_rev) || (extended_only)) {
1985 // Flags indicate no updates needed or it was an extension of
1986 // an existing lease with no FQDN changes. In the case of the
1987 // former, the most likely scenario is that we are honoring the
1988 // client's request that no updates be done.
1989 continue;
1990 }
1991
1992 // Create new NameChangeRequest. Use the domain name from the FQDN.
1993 // This is an FQDN included in the response to the client, so it
1994 // holds a fully qualified domain-name already (not partial).
1995 // Get the IP address from the lease.
1998 do_fwd, do_rev,
1999 opt_fqdn->getDomainName(),
2000 iaaddr->getAddress().toText(),
2001 dhcid, 0, calculateDdnsTtl(iaaddr->getValid()),
2002 ctx.getDdnsParams()->getUseConflictResolution()));
2005
2006 // Post the NCR to the D2ClientMgr.
2008
2013 return;
2014 }
2015}
2016
2019 CfgMACSources mac_sources = CfgMgr::instance().getCurrentCfg()->
2020 getMACSources().get();
2021 HWAddrPtr hwaddr;
2022 for (CfgMACSources::const_iterator it = mac_sources.begin();
2023 it != mac_sources.end(); ++it) {
2024 hwaddr = pkt->getMAC(*it);
2025 if (hwaddr) {
2026 return (hwaddr);
2027 }
2028 }
2029 return (hwaddr);
2030}
2031
2035 boost::shared_ptr<Option6IA> ia) {
2036
2037 // Check if the client sent us a hint in his IA_NA. Clients may send an
2038 // address in their IA_NA options as a suggestion (e.g. the last address
2039 // they used before).
2040 Option6IAAddrPtr hint_opt =
2041 boost::dynamic_pointer_cast<Option6IAAddr>(ia->getOption(D6O_IAADDR));
2043 if (hint_opt) {
2044 hint = hint_opt->getAddress();
2045 }
2046
2048 .arg(query->getLabel())
2049 .arg(ia->getIAID())
2050 .arg(hint_opt ? hint.toText() : "(no hint)");
2051
2052 // convenience values
2053 const Subnet6Ptr& subnet = ctx.subnet_;
2054
2055 // If there is no subnet selected for handling this IA_NA, the only thing left to do is
2056 // to say that we are sorry, but the user won't get an address. As a convenience, we
2057 // use a different status text to indicate that (compare to the same status code,
2058 // but different wording below)
2059 if (!subnet) {
2060 // Create an empty IA_NA option with IAID matching the request.
2061 // Note that we don't use OptionDefinition class to create this option.
2062 // This is because we prefer using a constructor of Option6IA that
2063 // initializes IAID. Otherwise we would have to use setIAID() after
2064 // creation of the option which has some performance implications.
2065 boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
2066
2067 // Insert status code NoAddrsAvail.
2068 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoAddrsAvail,
2069 "Server could not select subnet for"
2070 " this client"));
2071 return (ia_rsp);
2072 }
2073
2074 // Set per-IA context values.
2075 ctx.createIAContext();
2076 ctx.currentIA().iaid_ = ia->getIAID();
2077 if (hint_opt) {
2078 ctx.currentIA().addHint(hint_opt);
2079 } else {
2080 ctx.currentIA().addHint(hint);
2081 }
2083
2084 // Use allocation engine to pick a lease for this client. Allocation engine
2085 // will try to honor the hint, but it is just a hint - some other address
2086 // may be used instead. If fake_allocation is set to false, the lease will
2087 // be inserted into the LeaseMgr as well.
2088 Lease6Collection leases = alloc_engine_->allocateLeases6(ctx);
2089
2091 Lease6Ptr lease;
2092 if (!leases.empty()) {
2093 lease = *leases.begin();
2094 }
2095
2096 // Create IA_NA that we will put in the response.
2097 // Do not use OptionDefinition to create option's instance so
2098 // as we can initialize IAID using a constructor.
2099 Option6IAPtr ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
2100
2101 if (lease) {
2102 // We have a lease! Let's wrap its content into IA_NA option
2103 // with IAADDR suboption.
2104 if (ctx.fake_allocation_) {
2106 .arg(query->getLabel())
2107 .arg(lease->addr_.toText())
2108 .arg(ia->getIAID());
2109 } else if (lease->reuseable_valid_lft_ == 0) {
2111 .arg(query->getLabel())
2112 .arg(lease->addr_.toText())
2113 .arg(ia->getIAID())
2114 .arg(Lease::lifetimeToText(lease->valid_lft_));
2115 } else {
2116 lease->valid_lft_ = lease->reuseable_valid_lft_;
2117 lease->preferred_lft_ = lease->reuseable_preferred_lft_;
2119 .arg(query->getLabel())
2120 .arg(lease->addr_.toText())
2121 .arg(ia->getIAID())
2122 .arg(Lease::lifetimeToText(lease->valid_lft_));
2123 }
2125 .arg(query->getLabel())
2126 .arg(ia->getIAID())
2127 .arg(lease->toText());
2128
2129 // Set the values for T1 and T2.
2130 setTeeTimes(lease->preferred_lft_, subnet, ia_rsp);
2131
2132 Option6IAAddrPtr addr(new Option6IAAddr(D6O_IAADDR, lease->addr_,
2133 lease->preferred_lft_,
2134 lease->valid_lft_));
2135 ia_rsp->addOption(addr);
2136
2137 // It would be possible to insert status code=0(success) as well,
2138 // but this is considered waste of bandwidth as absence of status
2139 // code is considered a success.
2140
2141 } else {
2142 // Allocation engine did not allocate a lease. The engine logged
2143 // cause of that failure. The only thing left is to insert
2144 // status code to pass the sad news to the client.
2145
2148 .arg(query->getLabel())
2149 .arg(ia->getIAID());
2150
2151 ia_rsp->addOption(createStatusCode(*query, *ia_rsp,
2153 "Sorry, no address could be"
2154 " allocated."));
2155 }
2156 return (ia_rsp);
2157}
2158
2162 boost::shared_ptr<Option6IA> ia) {
2163
2164 // Check if the client sent us a hint in his IA_PD. Clients may send an
2165 // address in their IA_PD options as a suggestion (e.g. the last address
2166 // they used before). While the hint consists of a full prefix (prefix +
2167 // length), getting just the prefix is sufficient to identify a lease.
2168 Option6IAPrefixPtr hint_opt =
2169 boost::dynamic_pointer_cast<Option6IAPrefix>(ia->getOption(D6O_IAPREFIX));
2171 if (hint_opt) {
2172 hint = hint_opt->getAddress();
2173 }
2174
2176 .arg(query->getLabel())
2177 .arg(ia->getIAID())
2178 .arg(hint_opt ? hint.toText() : "(no hint)");
2179
2180 const Subnet6Ptr& subnet = ctx.subnet_;
2181
2182 // Create IA_PD that we will put in the response.
2183 // Do not use OptionDefinition to create option's instance so
2184 // as we can initialize IAID using a constructor.
2185 boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_PD, ia->getIAID()));
2186
2187 // If there is no subnet selected for handling this IA_PD, the only thing
2188 // left to do is to say that we are sorry, but the user won't get an address.
2189 // As a convenience, we use a different status text to indicate that
2190 // (compare to the same status code, but different wording below)
2191 if (!subnet) {
2192
2193 // Insert status code NoAddrsAvail.
2194 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoPrefixAvail,
2195 "Sorry, no subnet available."));
2196 return (ia_rsp);
2197 }
2198
2199 // Set per-IA context values.
2200 ctx.createIAContext();
2201 ctx.currentIA().iaid_ = ia->getIAID();
2202 if (hint_opt) {
2203 ctx.currentIA().addHint(hint_opt);
2204 } else {
2205 ctx.currentIA().addHint(hint);
2206 }
2208
2209 // Use allocation engine to pick a lease for this client. Allocation engine
2210 // will try to honor the hint, but it is just a hint - some other address
2211 // may be used instead. If fake_allocation is set to false, the lease will
2212 // be inserted into the LeaseMgr as well.
2213 Lease6Collection leases = alloc_engine_->allocateLeases6(ctx);
2214
2215 if (!leases.empty()) {
2216
2217 // Need to retain the shortest preferred lease time to use
2218 // for calculating T1 and T2.
2219 uint32_t min_preferred_lft = (*leases.begin())->preferred_lft_;
2220
2221 const bool pd_exclude_requested = requestedInORO(query, D6O_PD_EXCLUDE);
2222 for (Lease6Collection::iterator l = leases.begin();
2223 l != leases.end(); ++l) {
2224
2225 // We have a lease! Let's wrap its content into IA_PD option
2226 // with IAADDR suboption.
2227 if (ctx.fake_allocation_) {
2229 .arg(query->getLabel())
2230 .arg((*l)->addr_.toText())
2231 .arg(static_cast<int>((*l)->prefixlen_))
2232 .arg(ia->getIAID());
2233 } else if ((*l)->reuseable_valid_lft_ == 0) {
2235 .arg(query->getLabel())
2236 .arg((*l)->addr_.toText())
2237 .arg(static_cast<int>((*l)->prefixlen_))
2238 .arg(ia->getIAID())
2239 .arg(Lease::lifetimeToText((*l)->valid_lft_));
2240 } else {
2241 (*l)->valid_lft_ = (*l)->reuseable_valid_lft_;
2242 (*l)->preferred_lft_ = (*l)->reuseable_preferred_lft_;
2244 .arg(query->getLabel())
2245 .arg((*l)->addr_.toText())
2246 .arg(static_cast<int>((*l)->prefixlen_))
2247 .arg(ia->getIAID())
2248 .arg(Lease::lifetimeToText((*l)->valid_lft_));
2249 }
2250
2251 // Check for new minimum lease time
2252 if (((*l)->preferred_lft_ > 0) && (min_preferred_lft > (*l)->preferred_lft_)) {
2253 min_preferred_lft = (*l)->preferred_lft_;
2254 }
2255
2256 boost::shared_ptr<Option6IAPrefix>
2257 addr(new Option6IAPrefix(D6O_IAPREFIX, (*l)->addr_,
2258 (*l)->prefixlen_, (*l)->preferred_lft_,
2259 (*l)->valid_lft_));
2260 ia_rsp->addOption(addr);
2261
2262 if (pd_exclude_requested) {
2263 // PD exclude option has been requested via ORO, thus we need to
2264 // include it if the pool configuration specifies this option.
2265 Pool6Ptr pool = boost::dynamic_pointer_cast<
2266 Pool6>(subnet->getPool(Lease::TYPE_PD, (*l)->addr_));
2267 if (pool) {
2268 Option6PDExcludePtr pd_exclude_option = pool->getPrefixExcludeOption();
2269 if (pd_exclude_option) {
2270 addr->addOption(pd_exclude_option);
2271 }
2272 }
2273 }
2274 }
2275
2276 // Set T1 and T2, using the shortest preferred lifetime among the leases.
2277 setTeeTimes(min_preferred_lft, subnet, ia_rsp);
2278
2279 // It would be possible to insert status code=0(success) as well,
2280 // but this is considered waste of bandwidth as absence of status
2281 // code is considered a success.
2282
2283 } else {
2284 // Allocation engine did not allocate a lease. The engine logged
2285 // cause of that failure. The only thing left is to insert
2286 // status code to pass the sad news to the client.
2287
2290 .arg(query->getLabel())
2291 .arg(ia->getIAID());
2292
2293 ia_rsp->addOption(createStatusCode(*query, *ia_rsp,
2295 "Sorry, no prefixes could"
2296 " be allocated."));
2297 }
2298 return (ia_rsp);
2299}
2300
2304 boost::shared_ptr<Option6IA> ia) {
2305
2307 .arg(query->getLabel())
2308 .arg(ia->getIAID());
2309
2310 // convenience values
2311 const Subnet6Ptr& subnet = ctx.subnet_;
2312
2313 // Create empty IA_NA option with IAID matching the request.
2314 Option6IAPtr ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
2315
2316 if (!subnet) {
2326 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
2327 "Sorry, no known leases for this duid/iaid."));
2328 return (ia_rsp);
2329 }
2330
2331 // Set per-IA context values.
2332 ctx.createIAContext();
2333 ctx.currentIA().iaid_ = ia->getIAID();
2335 ctx.currentIA().ia_rsp_ = ia_rsp;
2336
2337 // Extract the addresses that the client is trying to obtain.
2338 OptionCollection addrs = ia->getOptions();
2339 for (OptionCollection::const_iterator it = addrs.begin();
2340 it != addrs.end(); ++it) {
2341 if (it->second->getType() != D6O_IAADDR) {
2342 continue;
2343 }
2344 Option6IAAddrPtr iaaddr = boost::dynamic_pointer_cast<Option6IAAddr>(it->second);
2345 if (!iaaddr) {
2346 // That's weird. Option code was ok, but the object type was not.
2347 // This should never happen. The only case would be with badly
2348 // mis-implemented hook libraries that insert invalid option objects.
2349 // There's no way to protect against this.
2350 continue;
2351 }
2352 ctx.currentIA().addHint(iaaddr);
2353 }
2354
2355 Lease6Collection leases = alloc_engine_->renewLeases6(ctx);
2356
2357 // Ok, now we have the leases extended. We have:
2358 // - what the client tried to renew in ctx.hints_
2359 // - what we actually assigned in leases
2360 // - old leases that are no longer valid in ctx.old_leases_
2361
2362 // For each IA inserted by the client we have to determine what to do
2363 // about included addresses and notify the client. We will iterate over
2364 // those prefixes and remove those that we have already processed. We
2365 // don't want to remove them from the context, so we need to copy them
2366 // into temporary container.
2368
2369 // Retains the shortest valid lease time to use
2370 // for calculating T1 and T2.
2371 uint32_t min_preferred_lft = std::numeric_limits<uint32_t>::max();
2372
2373 // For all leases we have now, add the IAADDR with non-zero lifetimes.
2374 for (Lease6Collection::iterator l = leases.begin(); l != leases.end(); ++l) {
2375 if ((*l)->reuseable_valid_lft_ == 0) {
2377 .arg(query->getLabel())
2378 .arg((*l)->addr_.toText())
2379 .arg(ia->getIAID());
2380 } else {
2381 (*l)->valid_lft_ = (*l)->reuseable_valid_lft_;
2382 (*l)->preferred_lft_ = (*l)->reuseable_preferred_lft_;
2384 .arg(query->getLabel())
2385 .arg((*l)->addr_.toText())
2386 .arg(ia->getIAID())
2387 .arg(Lease::lifetimeToText((*l)->valid_lft_));
2388 }
2389
2391 (*l)->addr_, (*l)->preferred_lft_, (*l)->valid_lft_));
2392 ia_rsp->addOption(iaaddr);
2393
2394 // Check for new minimum lease time
2395 if (((*l)->preferred_lft_ > 0) && (min_preferred_lft > (*l)->preferred_lft_)) {
2396 min_preferred_lft = (*l)->preferred_lft_;
2397 }
2398
2399 // Now remove this prefix from the hints list.
2400 AllocEngine::Resource hint_type((*l)->addr_, (*l)->prefixlen_);
2401 hints.erase(std::remove(hints.begin(), hints.end(), hint_type),
2402 hints.end());
2403 }
2404
2405 // For the leases that we just retired, send the addresses with 0 lifetimes.
2406 for (Lease6Collection::iterator l = ctx.currentIA().old_leases_.begin();
2407 l != ctx.currentIA().old_leases_.end(); ++l) {
2408
2409 // Send an address with zero lifetimes only when this lease belonged to
2410 // this client. Do not send it when we're reusing an old lease that belonged
2411 // to someone else.
2412 if (equalValues(query->getClientId(), (*l)->duid_)) {
2414 (*l)->addr_, 0, 0));
2415 ia_rsp->addOption(iaaddr);
2416 }
2417
2418 // Now remove this address from the hints list.
2419 AllocEngine::Resource hint_type((*l)->addr_, 128);
2420 hints.erase(std::remove(hints.begin(), hints.end(), hint_type), hints.end());
2421
2422 // If the new FQDN settings have changed for the lease, we need to
2423 // delete any existing FQDN records for this lease.
2424 if (((*l)->hostname_ != ctx.hostname_) || ((*l)->fqdn_fwd_ != ctx.fwd_dns_update_) ||
2425 ((*l)->fqdn_rev_ != ctx.rev_dns_update_)) {
2428 .arg(query->getLabel())
2429 .arg((*l)->toText())
2430 .arg(ctx.hostname_)
2431 .arg(ctx.rev_dns_update_ ? "true" : "false")
2432 .arg(ctx.fwd_dns_update_ ? "true" : "false");
2433
2434 queueNCR(CHG_REMOVE, *l);
2435 }
2436 }
2437
2438 // Finally, if there are any addresses requested that we haven't dealt with
2439 // already, inform the client that he can't have them.
2440 for (AllocEngine::HintContainer::const_iterator hint = hints.begin();
2441 hint != hints.end(); ++hint) {
2443 hint->getAddress(), 0, 0));
2444 ia_rsp->addOption(iaaddr);
2445 }
2446
2447 if (!leases.empty()) {
2448 // We allocated leases so we need to update T1 and T2.
2449 setTeeTimes(min_preferred_lft, subnet, ia_rsp);
2450 } else {
2451 // The server wasn't able allocate new lease and renew an existing
2452 // lease. In that case, the server sends NoAddrsAvail per RFC 8415.
2453 ia_rsp->addOption(createStatusCode(*query, *ia_rsp,
2455 "Sorry, no addresses could be"
2456 " assigned at this time."));
2457 }
2458
2459 return (ia_rsp);
2460}
2461
2465 boost::shared_ptr<Option6IA> ia) {
2466
2468 .arg(query->getLabel())
2469 .arg(ia->getIAID());
2470
2471 const Subnet6Ptr& subnet = ctx.subnet_;
2472 const DuidPtr& duid = ctx.duid_;
2473
2474 // Let's create a IA_PD response and fill it in later
2475 Option6IAPtr ia_rsp(new Option6IA(D6O_IA_PD, ia->getIAID()));
2476
2477 // If there is no subnet for the particular client, we can't retrieve
2478 // information about client's leases from lease database. We treat this
2479 // as no binding for the client.
2480 if (!subnet) {
2481 // Per RFC 8415, section 18.3.4, if there is no binding and we are
2482 // processing a Renew, the NoBinding status code should be returned.
2483 if (query->getType() == DHCPV6_RENEW) {
2484 // Insert status code NoBinding
2485 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
2486 "Sorry, no known PD leases"
2487 " for this duid/iaid."));
2488 return (ia_rsp);
2489
2490 // Per RFC 8415, section 18.3.5, if there is no binding and we are
2491 // processing Rebind, the message has to be discarded (assuming that
2492 // the server doesn't know if the prefix in the IA_PD option is
2493 // appropriate for the client's link). The exception being thrown
2494 // here should propagate to the main loop and cause the message to
2495 // be discarded.
2496 } else {
2497
2506 isc_throw(DHCPv6DiscardMessageError, "no subnet found for the"
2507 " client sending Rebind to extend lifetime of the"
2508 " prefix (DUID=" << duid->toText() << ", IAID="
2509 << ia->getIAID() << ")");
2510 }
2511 }
2512
2513 // Set per-IA context values.
2514 ctx.createIAContext();
2515 ctx.currentIA().iaid_ = ia->getIAID();
2517 ctx.currentIA().ia_rsp_ = ia_rsp;
2518
2519 // Extract prefixes that the client is trying to renew.
2520 OptionCollection addrs = ia->getOptions();
2521 for (OptionCollection::const_iterator it = addrs.begin();
2522 it != addrs.end(); ++it) {
2523 if (it->second->getType() != D6O_IAPREFIX) {
2524 continue;
2525 }
2526 Option6IAPrefixPtr prf = boost::dynamic_pointer_cast<Option6IAPrefix>(it->second);
2527 if (!prf) {
2528 // That's weird. Option code was ok, but the object type was not.
2529 // This should never happen. The only case would be with badly
2530 // mis-implemented hook libraries that insert invalid option objects.
2531 // There's no way to protect against this.
2532 continue;
2533 }
2534
2535 // Put the client's prefix into the hints list.
2536 ctx.currentIA().addHint(prf);
2537 }
2538
2539 // Call Allocation Engine and attempt to renew leases. Number of things
2540 // may happen. Leases may be extended, revoked (if the lease is no longer
2541 // valid or reserved for someone else), or new leases may be added.
2542 // Important parameters are:
2543 // - returned container - current valid leases
2544 // - old_leases - leases that used to be, but are no longer valid
2545 // - changed_leases - leases that have FQDN changed (not really important
2546 // in PD context)
2547 Lease6Collection leases = alloc_engine_->renewLeases6(ctx);
2548
2549 // For each IA inserted by the client we have to determine what to do
2550 // about included prefixes and notify the client. We will iterate over
2551 // those prefixes and remove those that we have already processed. We
2552 // don't want to remove them from the context, so we need to copy them
2553 // into temporary container.
2555
2556 const bool pd_exclude_requested = requestedInORO(query, D6O_PD_EXCLUDE);
2557
2558 // Retains the shortest valid lease time to use
2559 // for calculating T1 and T2.
2560 uint32_t min_preferred_lft = std::numeric_limits<uint32_t>::max();
2561
2562 for (Lease6Collection::iterator l = leases.begin(); l != leases.end(); ++l) {
2563 if ((*l)->reuseable_valid_lft_ == 0) {
2565 .arg(query->getLabel())
2566 .arg((*l)->addr_.toText())
2567 .arg(static_cast<int>((*l)->prefixlen_))
2568 .arg(ia->getIAID());
2569 } else {
2570 (*l)->valid_lft_ = (*l)->reuseable_valid_lft_;
2571 (*l)->preferred_lft_ = (*l)->reuseable_preferred_lft_;
2573 .arg(query->getLabel())
2574 .arg((*l)->addr_.toText())
2575 .arg(static_cast<int>((*l)->prefixlen_))
2576 .arg(ia->getIAID())
2577 .arg(Lease::lifetimeToText((*l)->valid_lft_));
2578 }
2579
2581 (*l)->addr_, (*l)->prefixlen_,
2582 (*l)->preferred_lft_, (*l)->valid_lft_));
2583 ia_rsp->addOption(prf);
2584
2585 if (pd_exclude_requested) {
2586 // PD exclude option has been requested via ORO, thus we need to
2587 // include it if the pool configuration specifies this option.
2588 Pool6Ptr pool = boost::dynamic_pointer_cast<
2589 Pool6>(subnet->getPool(Lease::TYPE_PD, (*l)->addr_));
2590
2591 if (pool) {
2592 Option6PDExcludePtr pd_exclude_option = pool->getPrefixExcludeOption();
2593 if (pd_exclude_option) {
2594 prf->addOption(pd_exclude_option);
2595 }
2596 }
2597 }
2598
2599 // Check for new minimum lease time
2600 if (((*l)->preferred_lft_ > 0) && ((*l)->preferred_lft_ < min_preferred_lft)) {
2601 min_preferred_lft = (*l)->preferred_lft_;
2602 }
2603
2604 // Now remove this prefix from the hints list.
2605 AllocEngine::Resource hint_type((*l)->addr_, (*l)->prefixlen_);
2606 hints.erase(std::remove(hints.begin(), hints.end(), hint_type),
2607 hints.end());
2608 }
2609
2611 for (Lease6Collection::iterator l = ctx.currentIA().old_leases_.begin();
2612 l != ctx.currentIA().old_leases_.end(); ++l) {
2613
2614 // Send a prefix with zero lifetimes only when this lease belonged to
2615 // this client. Do not send it when we're reusing an old lease that belonged
2616 // to someone else.
2617 if (equalValues(query->getClientId(), (*l)->duid_)) {
2618 Option6IAPrefixPtr prefix(new Option6IAPrefix(D6O_IAPREFIX, (*l)->addr_,
2619 (*l)->prefixlen_, 0, 0));
2620 ia_rsp->addOption(prefix);
2621 }
2622
2623 // Now remove this prefix from the hints list.
2624 AllocEngine::Resource hint_type((*l)->addr_, (*l)->prefixlen_);
2625 hints.erase(std::remove(hints.begin(), hints.end(), hint_type), hints.end());
2626 }
2627
2628 // Finally, if there are any prefixes requested that we haven't dealt with
2629 // already, inform the client that he can't have them.
2630 for (AllocEngine::HintContainer::const_iterator prefix = hints.begin();
2631 prefix != hints.end(); ++prefix) {
2632
2633 // Send the prefix with the zero lifetimes only if the prefix
2634 // contains non-zero value. A zero value indicates that the hint was
2635 // for the prefix length.
2636 if (!prefix->getAddress().isV6Zero()) {
2637 OptionPtr prefix_opt(new Option6IAPrefix(D6O_IAPREFIX,
2638 prefix->getAddress(),
2639 prefix->getPrefixLength(),
2640 0, 0));
2641 ia_rsp->addOption(prefix_opt);
2642 }
2643 }
2644
2645 if (!leases.empty()) {
2646 // We allocated leases so we need to update T1 and T2.
2647 setTeeTimes(min_preferred_lft, subnet, ia_rsp);
2648 } else {
2649 // All is left is to insert the status code.
2650 // The server wasn't able allocate new lease and renew an existing
2651 // lease. In that case, the server sends NoPrefixAvail per RFC 8415.
2652 ia_rsp->addOption(createStatusCode(*query, *ia_rsp,
2654 "Sorry, no prefixes could be"
2655 " assigned at this time."));
2656 }
2657
2658 return (ia_rsp);
2659}
2660
2661void
2664
2665 // We will try to extend lease lifetime for all IA options in the client's
2666 // Renew or Rebind message.
2668
2669 // For the lease extension it is critical that the client has sent
2670 // DUID. There is no need to check for the presence of the DUID here
2671 // because we have already checked it in the sanityCheck().
2672
2673 // Save the originally selected subnet.
2674 Subnet6Ptr orig_subnet = ctx.subnet_;
2675
2676 for (OptionCollection::iterator opt = query->options_.begin();
2677 opt != query->options_.end(); ++opt) {
2678 switch (opt->second->getType()) {
2679 case D6O_IA_NA: {
2680 OptionPtr answer_opt = extendIA_NA(query, ctx,
2681 boost::dynamic_pointer_cast<
2682 Option6IA>(opt->second));
2683 if (answer_opt) {
2684 reply->addOption(answer_opt);
2685 }
2686 break;
2687 }
2688
2689 case D6O_IA_PD: {
2690 OptionPtr answer_opt = extendIA_PD(query, ctx,
2691 boost::dynamic_pointer_cast<
2692 Option6IA>(opt->second));
2693 if (answer_opt) {
2694 reply->addOption(answer_opt);
2695 }
2696 break;
2697 }
2698
2699 default:
2700 break;
2701 }
2702 }
2703
2704 // Subnet may be modified by the allocation engine, there are things
2705 // we need to do when that happens.
2706 checkDynamicSubnetChange(query, reply, ctx, orig_subnet);
2707}
2708
2709void
2712
2713 // We need to release addresses for all IA options in the client's
2714 // RELEASE message.
2715
2722
2723 // Let's set the status to be success by default. We can override it with
2724 // error status if needed. The important thing to understand here is that
2725 // the global status code may be set to success only if all IA options were
2726 // handled properly. Therefore the releaseIA_NA and releaseIA_PD options
2727 // may turn the status code to some error, but can't turn it back to success.
2728 int general_status = STATUS_Success;
2729 for (OptionCollection::iterator opt = release->options_.begin();
2730 opt != release->options_.end(); ++opt) {
2731 Lease6Ptr old_lease;
2732 switch (opt->second->getType()) {
2733 case D6O_IA_NA: {
2734 OptionPtr answer_opt = releaseIA_NA(ctx.duid_, release, general_status,
2735 boost::dynamic_pointer_cast<Option6IA>(opt->second),
2736 old_lease);
2737 if (answer_opt) {
2738 reply->addOption(answer_opt);
2739 }
2740 break;
2741 }
2742 case D6O_IA_PD: {
2743 OptionPtr answer_opt = releaseIA_PD(ctx.duid_, release, general_status,
2744 boost::dynamic_pointer_cast<Option6IA>(opt->second),
2745 old_lease);
2746 if (answer_opt) {
2747 reply->addOption(answer_opt);
2748 }
2749 break;
2750 }
2751 // @todo: add support for IA_TA
2752 default:
2753 // remaining options are stateless and thus ignored in this context
2754 ;
2755 }
2756
2757 // Store the old lease.
2758 if (old_lease) {
2759 ctx.currentIA().old_leases_.push_back(old_lease);
2760 }
2761 }
2762
2763 // Include top-level status code as well.
2764 reply->addOption(createStatusCode(*release, general_status,
2765 "Summary status for all processed IA_NAs"));
2766}
2767
2769Dhcpv6Srv::releaseIA_NA(const DuidPtr& duid, const Pkt6Ptr& query,
2770 int& general_status, boost::shared_ptr<Option6IA> ia,
2771 Lease6Ptr& old_lease) {
2772
2774 .arg(query->getLabel())
2775 .arg(ia->getIAID());
2776
2777 // Release can be done in one of two ways:
2778 // Approach 1: extract address from client's IA_NA and see if it belongs
2779 // to this particular client.
2780 // Approach 2: find a subnet for this client, get a lease for
2781 // this subnet/duid/iaid and check if its content matches to what the
2782 // client is asking us to release.
2783 //
2784 // This method implements approach 1.
2785
2786 // That's our response
2787 boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
2788
2789 Option6IAAddrPtr release_addr = boost::dynamic_pointer_cast<Option6IAAddr>
2790 (ia->getOption(D6O_IAADDR));
2791 if (!release_addr) {
2792 ia_rsp->addOption(createStatusCode(*query, STATUS_NoBinding,
2793 "You did not include an address in your RELEASE"));
2794 general_status = STATUS_NoBinding;
2795 return (ia_rsp);
2796 }
2797
2799 release_addr->getAddress());
2800
2801 if (!lease) {
2802 // client releasing a lease that we don't know about.
2803
2804 // Insert status code NoBinding.
2805 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
2806 "Sorry, no known leases for this duid/iaid, can't release."));
2807 general_status = STATUS_NoBinding;
2808
2809 return (ia_rsp);
2810 }
2811
2812 if (!lease->duid_) {
2813 // Something is gravely wrong here. We do have a lease, but it does not
2814 // have mandatory DUID information attached. Someone was messing with our
2815 // database.
2816
2818 .arg(query->getLabel())
2819 .arg(release_addr->getAddress().toText());
2820
2821 general_status = STATUS_UnspecFail;
2822 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_UnspecFail,
2823 "Database consistency check failed when trying to RELEASE"));
2824 return (ia_rsp);
2825 }
2826
2827 if (*duid != *(lease->duid_)) {
2828
2829 // Sorry, it's not your address. You can't release it.
2831 .arg(query->getLabel())
2832 .arg(release_addr->getAddress().toText())
2833 .arg(lease->duid_->toText());
2834
2835 general_status = STATUS_NoBinding;
2836 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
2837 "This address does not belong to you, you can't release it"));
2838 return (ia_rsp);
2839 }
2840
2841 if (ia->getIAID() != lease->iaid_) {
2842 // This address belongs to this client, but to a different IA
2844 .arg(query->getLabel())
2845 .arg(release_addr->getAddress().toText())
2846 .arg(lease->iaid_)
2847 .arg(ia->getIAID());
2848 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
2849 "This is your address, but you used wrong IAID"));
2850 general_status = STATUS_NoBinding;
2851 return (ia_rsp);
2852 }
2853
2854 // It is not necessary to check if the address matches as we used
2855 // getLease6(addr) method that is supposed to return a proper lease.
2856
2857 bool skip = false;
2858 // Execute all callouts registered for packet6_send
2859 if (HooksManager::calloutsPresent(Hooks.hook_index_lease6_release_)) {
2860 CalloutHandlePtr callout_handle = getCalloutHandle(query);
2861
2862 // Use the RAII wrapper to make sure that the callout handle state is
2863 // reset when this object goes out of scope. All hook points must do
2864 // it to prevent possible circular dependency between the callout
2865 // handle and its arguments.
2866 ScopedCalloutHandleState callout_handle_state(callout_handle);
2867
2868 // Enable copying options from the packet within hook library.
2869 ScopedEnableOptionsCopy<Pkt6> query6_options_copy(query);
2870
2871 // Delete all previous arguments
2872 callout_handle->deleteAllArguments();
2873
2874 // Pass the original packet
2875 callout_handle->setArgument("query6", query);
2876
2877 // Pass the lease to be updated
2878 callout_handle->setArgument("lease6", lease);
2879
2880 // Call all installed callouts
2881 HooksManager::callCallouts(Hooks.hook_index_lease6_release_, *callout_handle);
2882
2883 // Callouts decided to skip the next processing step. The next
2884 // processing step would to send the packet, so skip at this
2885 // stage means "drop response".
2886 if ((callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) ||
2887 (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP)) {
2888 skip = true;
2890 .arg(query->getLabel());
2891 }
2892 }
2893
2894 // Ok, we've passed all checks. Let's release this address.
2895 bool success = false; // was the removal operation successful?
2896
2897 if (!skip) {
2898 success = LeaseMgrFactory::instance().deleteLease(lease);
2899 }
2900
2901 // Here the success should be true if we removed lease successfully
2902 // and false if skip flag was set or the removal failed for whatever reason
2903
2904 if (!success) {
2905 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_UnspecFail,
2906 "Server failed to release a lease"));
2907
2909 .arg(query->getLabel())
2910 .arg(lease->addr_.toText())
2911 .arg(lease->iaid_);
2912 general_status = STATUS_UnspecFail;
2913
2914 return (ia_rsp);
2915 } else {
2916 old_lease = lease;
2917
2919 .arg(query->getLabel())
2920 .arg(lease->addr_.toText())
2921 .arg(lease->iaid_);
2922
2923 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_Success,
2924 "Lease released. Thank you, please come again."));
2925
2926 // Need to decrease statistic for assigned addresses.
2927 StatsMgr::instance().addValue(
2928 StatsMgr::generateName("subnet", lease->subnet_id_, "assigned-nas"),
2929 static_cast<int64_t>(-1));
2930
2931 // Check if a lease has flags indicating that the FQDN update has
2932 // been performed. If so, create NameChangeRequest which removes
2933 // the entries.
2934 queueNCR(CHG_REMOVE, lease);
2935
2936 return (ia_rsp);
2937 }
2938}
2939
2941Dhcpv6Srv::releaseIA_PD(const DuidPtr& duid, const Pkt6Ptr& query,
2942 int& general_status, boost::shared_ptr<Option6IA> ia,
2943 Lease6Ptr& old_lease) {
2944 // Release can be done in one of two ways:
2945 // Approach 1: extract address from client's IA_NA and see if it belongs
2946 // to this particular client.
2947 // Approach 2: find a subnet for this client, get a lease for
2948 // this subnet/duid/iaid and check if its content matches to what the
2949 // client is asking us to release.
2950 //
2951 // This method implements approach 1.
2952
2953 // That's our response. We will fill it in as we check the lease to be
2954 // released.
2955 boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_PD, ia->getIAID()));
2956
2957 boost::shared_ptr<Option6IAPrefix> release_prefix =
2958 boost::dynamic_pointer_cast<Option6IAPrefix>(ia->getOption(D6O_IAPREFIX));
2959 if (!release_prefix) {
2960 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
2961 "You did not include a prefix in your RELEASE"));
2962 general_status = STATUS_NoBinding;
2963 return (ia_rsp);
2964 }
2965
2967 release_prefix->getAddress());
2968
2969 if (!lease) {
2970 // Client releasing a lease that we don't know about.
2971
2972 // Insert status code NoBinding.
2973 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
2974 "Sorry, no known leases for this duid/iaid, can't release."));
2975 general_status = STATUS_NoBinding;
2976
2977 return (ia_rsp);
2978 }
2979
2980 if (!lease->duid_) {
2981 // Something is gravely wrong here. We do have a lease, but it does not
2982 // have mandatory DUID information attached. Someone was messing with our
2983 // database.
2985 .arg(query->getLabel())
2986 .arg(release_prefix->getAddress().toText())
2987 .arg(static_cast<int>(release_prefix->getLength()));
2988
2989 general_status = STATUS_UnspecFail;
2990 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_UnspecFail,
2991 "Database consistency check failed when trying to RELEASE"));
2992 return (ia_rsp);
2993 }
2994
2995 if (*duid != *(lease->duid_)) {
2996 // Sorry, it's not your address. You can't release it.
2998 .arg(query->getLabel())
2999 .arg(release_prefix->getAddress().toText())
3000 .arg(static_cast<int>(release_prefix->getLength()))
3001 .arg(lease->duid_->toText());
3002
3003 general_status = STATUS_NoBinding;
3004 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
3005 "This address does not belong to you, you can't release it"));
3006 return (ia_rsp);
3007 }
3008
3009 if (ia->getIAID() != lease->iaid_) {
3010 // This address belongs to this client, but to a different IA
3012 .arg(query->getLabel())
3013 .arg(release_prefix->getAddress().toText())
3014 .arg(static_cast<int>(release_prefix->getLength()))
3015 .arg(lease->iaid_)
3016 .arg(ia->getIAID());
3017 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
3018 "This is your address, but you used wrong IAID"));
3019 general_status = STATUS_NoBinding;
3020 return (ia_rsp);
3021 }
3022
3023 // It is not necessary to check if the address matches as we used
3024 // getLease6(addr) method that is supposed to return a proper lease.
3025
3026 bool skip = false;
3027 // Execute all callouts registered for packet6_send
3028 if (HooksManager::calloutsPresent(Hooks.hook_index_lease6_release_)) {
3029 CalloutHandlePtr callout_handle = getCalloutHandle(query);
3030
3031 // Use the RAII wrapper to make sure that the callout handle state is
3032 // reset when this object goes out of scope. All hook points must do
3033 // it to prevent possible circular dependency between the callout
3034 // handle and its arguments.
3035 ScopedCalloutHandleState callout_handle_state(callout_handle);
3036
3037 // Enable copying options from the packet within hook library.
3038 ScopedEnableOptionsCopy<Pkt6> query6_options_copy(query);
3039
3040 // Pass the original packet
3041 callout_handle->setArgument("query6", query);
3042
3043 // Pass the lease to be updated
3044 callout_handle->setArgument("lease6", lease);
3045
3046 // Call all installed callouts
3047 HooksManager::callCallouts(Hooks.hook_index_lease6_release_, *callout_handle);
3048
3049 skip = callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP;
3050 }
3051
3052 // Ok, we've passed all checks. Let's release this prefix.
3053 bool success = false; // was the removal operation successful?
3054
3055 if (!skip) {
3056 success = LeaseMgrFactory::instance().deleteLease(lease);
3057 } else {
3058 // Callouts decided to skip the next processing step. The next
3059 // processing step would to send the packet, so skip at this
3060 // stage means "drop response".
3062 .arg(query->getLabel());
3063 }
3064
3065 // Here the success should be true if we removed lease successfully
3066 // and false if skip flag was set or the removal failed for whatever reason
3067
3068 if (!success) {
3069 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_UnspecFail,
3070 "Server failed to release a lease"));
3071
3073 .arg(query->getLabel())
3074 .arg(lease->addr_.toText())
3075 .arg(static_cast<int>(lease->prefixlen_))
3076 .arg(lease->iaid_);
3077 general_status = STATUS_UnspecFail;
3078
3079 } else {
3080 old_lease = lease;
3081
3083 .arg(query->getLabel())
3084 .arg(lease->addr_.toText())
3085 .arg(static_cast<int>(lease->prefixlen_))
3086 .arg(lease->iaid_);
3087
3088 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_Success,
3089 "Lease released. Thank you, please come again."));
3090
3091 // Need to decrease statistic for assigned prefixes.
3092 StatsMgr::instance().addValue(
3093 StatsMgr::generateName("subnet", lease->subnet_id_, "assigned-pds"),
3094 static_cast<int64_t>(-1));
3095 }
3096
3097 return (ia_rsp);
3098}
3099
3100Pkt6Ptr
3102
3103 Pkt6Ptr solicit = ctx.query_;
3104 Pkt6Ptr response(new Pkt6(DHCPV6_ADVERTISE, solicit->getTransid()));
3105
3106 // Handle Rapid Commit option, if present.
3107 if (ctx.subnet_ && ctx.subnet_->getRapidCommit()) {
3108 OptionPtr opt_rapid_commit = solicit->getOption(D6O_RAPID_COMMIT);
3109 if (opt_rapid_commit) {
3110
3112 .arg(solicit->getLabel());
3113
3114 // If Rapid Commit has been sent by the client, change the
3115 // response type to Reply and include Rapid Commit option.
3116 response->setType(DHCPV6_REPLY);
3117 response->addOption(opt_rapid_commit);
3118 }
3119 }
3120
3121 // "Fake" allocation is the case when the server is processing the Solicit
3122 // message without the Rapid Commit option and advertises a lease to
3123 // the client, but doesn't commit this lease to the lease database. If
3124 // the Solicit contains the Rapid Commit option and the server is
3125 // configured to honor the Rapid Commit option, or the client has sent
3126 // the Request message, the lease will be committed to the lease
3127 // database. The type of the server's response may be used to determine
3128 // if this is the fake allocation case or not. When the server sends
3129 // Reply message it means that it is committing leases. Other message
3130 // type (Advertise) means that server is not committing leases (fake
3131 // allocation).
3132 ctx.fake_allocation_ = (response->getType() != DHCPV6_REPLY);
3133
3134 processClientFqdn(solicit, response, ctx);
3135
3136 if (MultiThreadingMgr::instance().getMode()) {
3137 // The lease reclamation cannot run at the same time.
3138 ReadLockGuard share(alloc_engine_->getReadWriteMutex());
3139
3140 assignLeases(solicit, response, ctx);
3141 } else {
3142 assignLeases(solicit, response, ctx);
3143 }
3144
3146 requiredClassify(solicit, ctx);
3147
3148 copyClientOptions(solicit, response);
3149 CfgOptionList co_list;
3150 buildCfgOptionList(solicit, ctx, co_list);
3151 appendDefaultOptions(solicit, response, co_list);
3152 appendRequestedOptions(solicit, response, co_list);
3153 appendRequestedVendorOptions(solicit, response, ctx, co_list);
3154
3155 updateReservedFqdn(ctx, response);
3156
3157 // Only generate name change requests if sending a Reply as a result
3158 // of receiving Rapid Commit option.
3159 if (response->getType() == DHCPV6_REPLY) {
3160 createNameChangeRequests(response, ctx);
3161 }
3162
3163 return (response);
3164}
3165
3166Pkt6Ptr
3168
3169 Pkt6Ptr request = ctx.query_;
3170 Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, request->getTransid()));
3171
3172 processClientFqdn(request, reply, ctx);
3173
3174 if (MultiThreadingMgr::instance().getMode()) {
3175 // The lease reclamation cannot run at the same time.
3176 ReadLockGuard share(alloc_engine_->getReadWriteMutex());
3177
3178 assignLeases(request, reply, ctx);
3179 } else {
3180 assignLeases(request, reply, ctx);
3181 }
3182
3184 requiredClassify(request, ctx);
3185
3186 copyClientOptions(request, reply);
3187 CfgOptionList co_list;
3188 buildCfgOptionList(request, ctx, co_list);
3189 appendDefaultOptions(request, reply, co_list);
3190 appendRequestedOptions(request, reply, co_list);
3191 appendRequestedVendorOptions(request, reply, ctx, co_list);
3192
3193 updateReservedFqdn(ctx, reply);
3194 generateFqdn(reply, ctx);
3195 createNameChangeRequests(reply, ctx);
3196
3197 return (reply);
3198}
3199
3200Pkt6Ptr
3202
3203 Pkt6Ptr renew = ctx.query_;
3204 Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, renew->getTransid()));
3205
3206 processClientFqdn(renew, reply, ctx);
3207
3208 if (MultiThreadingMgr::instance().getMode()) {
3209 // The lease reclamation cannot run at the same time.
3210 ReadLockGuard share(alloc_engine_->getReadWriteMutex());
3211
3212 extendLeases(renew, reply, ctx);
3213 } else {
3214 extendLeases(renew, reply, ctx);
3215 }
3216
3218 requiredClassify(renew, ctx);
3219
3220 copyClientOptions(renew, reply);
3221 CfgOptionList co_list;
3222 buildCfgOptionList(renew, ctx, co_list);
3223 appendDefaultOptions(renew, reply, co_list);
3224 appendRequestedOptions(renew, reply, co_list);
3225 appendRequestedVendorOptions(renew, reply, ctx, co_list);
3226
3227 updateReservedFqdn(ctx, reply);
3228 generateFqdn(reply, ctx);
3229 createNameChangeRequests(reply, ctx);
3230
3231 return (reply);
3232}
3233
3234Pkt6Ptr
3236
3237 Pkt6Ptr rebind = ctx.query_;
3238 Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, rebind->getTransid()));
3239
3240 processClientFqdn(rebind, reply, ctx);
3241
3242 if (MultiThreadingMgr::instance().getMode()) {
3243 // The lease reclamation cannot run at the same time.
3244 ReadLockGuard share(alloc_engine_->getReadWriteMutex());
3245
3246 extendLeases(rebind, reply, ctx);
3247 } else {
3248 extendLeases(rebind, reply, ctx);
3249 }
3250
3252 requiredClassify(rebind, ctx);
3253
3254 copyClientOptions(rebind, reply);
3255 CfgOptionList co_list;
3256 buildCfgOptionList(rebind, ctx, co_list);
3257 appendDefaultOptions(rebind, reply, co_list);
3258 appendRequestedOptions(rebind, reply, co_list);
3259 appendRequestedVendorOptions(rebind, reply, ctx, co_list);
3260
3261 updateReservedFqdn(ctx, reply);
3262 generateFqdn(reply, ctx);
3263 createNameChangeRequests(reply, ctx);
3264
3265 return (reply);
3266}
3267
3268Pkt6Ptr
3270
3271 Pkt6Ptr confirm = ctx.query_;
3273 requiredClassify(confirm, ctx);
3274
3275 // Get IA_NAs from the Confirm. If there are none, the message is
3276 // invalid and must be discarded. There is nothing more to do.
3277 OptionCollection ias = confirm->getOptions(D6O_IA_NA);
3278 if (ias.empty()) {
3279 return (Pkt6Ptr());
3280 }
3281
3282 // The server sends Reply message in response to Confirm.
3283 Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, confirm->getTransid()));
3284 // Make sure that the necessary options are included.
3285 copyClientOptions(confirm, reply);
3286 CfgOptionList co_list;
3287 buildCfgOptionList(confirm, ctx, co_list);
3288 appendDefaultOptions(confirm, reply, co_list);
3289 appendRequestedOptions(confirm, reply, co_list);
3290 appendRequestedVendorOptions(confirm, reply, ctx, co_list);
3291 // Indicates if at least one address has been verified. If no addresses
3292 // are verified it means that the client has sent no IA_NA options
3293 // or no IAAddr options and that client's message has to be discarded.
3294 bool verified = false;
3295 // Check if subnet was selected for the message. If no subnet
3296 // has been selected, the client is not on link.
3297 SubnetPtr subnet = ctx.subnet_;
3298
3299 // Regardless if the subnet has been selected or not, we will iterate
3300 // over the IA_NA options to check if they hold any addresses. If there
3301 // are no, the Confirm is discarded.
3302 // Check addresses in IA_NA options and make sure they are appropriate.
3303 for (OptionCollection::const_iterator ia = ias.begin();
3304 ia != ias.end(); ++ia) {
3305 const OptionCollection& opts = ia->second->getOptions();
3306 for (OptionCollection::const_iterator opt = opts.begin();
3307 opt != opts.end(); ++opt) {
3308 // Ignore options other than IAAddr.
3309 if (opt->second->getType() == D6O_IAADDR) {
3310 // Check that the address is in range in the subnet selected.
3311 Option6IAAddrPtr iaaddr = boost::dynamic_pointer_cast<
3312 Option6IAAddr>(opt->second);
3313 // If there is subnet selected and the address has been included
3314 // in IA_NA, mark it verified and verify that it belongs to the
3315 // subnet.
3316 if (iaaddr) {
3317 // If at least one address is not in range, then return
3318 // the NotOnLink status code.
3319 if (subnet && !subnet->inRange(iaaddr->getAddress())) {
3320 std::ostringstream status_msg;
3321 status_msg << "Address " << iaaddr->getAddress()
3322 << " is not on link.";
3323 reply->addOption(createStatusCode(*confirm,
3325 status_msg.str()));
3326 return (reply);
3327 }
3328 verified = true;
3329 } else {
3330 isc_throw(Unexpected, "failed to cast the IA Address option"
3331 " to the Option6IAAddrPtr. This is programming"
3332 " error and should be reported");
3333 }
3334 }
3335 }
3336 }
3337
3338 // It seems that the client hasn't included any addresses in which case
3339 // the Confirm must be discarded.
3340 if (!verified) {
3341 return (Pkt6Ptr());
3342 }
3343
3344 // If there is a subnet, there were addresses in IA_NA options and the
3345 // addresses where consistent with the subnet then the client is on link.
3346 if (subnet) {
3347 // All addresses in range, so return success.
3348 reply->addOption(createStatusCode(*confirm, STATUS_Success,
3349 "All addresses are on-link"));
3350 } else {
3351 reply->addOption(createStatusCode(*confirm, STATUS_NotOnLink,
3352 "No subnet selected"));
3353 }
3354
3355 return (reply);
3356}
3357
3358Pkt6Ptr
3360
3361 Pkt6Ptr release = ctx.query_;
3363 requiredClassify(release, ctx);
3364
3365 // Create an empty Reply message.
3366 Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, release->getTransid()));
3367
3368 // Copy client options (client-id, also relay information if present)
3369 copyClientOptions(release, reply);
3370
3371 // Get the configured option list
3372 CfgOptionList co_list;
3373 // buildCfgOptionList(release, ctx, co_list);
3374 appendDefaultOptions(release, reply, co_list);
3375
3376 releaseLeases(release, reply, ctx);
3377
3380
3381 return (reply);
3382}
3383
3384Pkt6Ptr
3386
3387 Pkt6Ptr decline = ctx.query_;
3389 requiredClassify(decline, ctx);
3390
3391 // Create an empty Reply message.
3392 Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, decline->getTransid()));
3393
3394 // Copy client options (client-id, also relay information if present)
3395 copyClientOptions(decline, reply);
3396
3397 // Get the configured option list
3398 CfgOptionList co_list;
3399 buildCfgOptionList(decline, ctx, co_list);
3400
3401 // Include server-id
3402 appendDefaultOptions(decline, reply, co_list);
3403
3404 if (declineLeases(decline, reply, ctx)) {
3405 return (reply);
3406 } else {
3407
3408 // declineLeases returns false only if the hooks set the next step
3409 // status to DROP. We'll just doing as requested.
3410 return (Pkt6Ptr());
3411 }
3412}
3413
3414bool
3417
3418 // We need to decline addresses for all IA_NA options in the client's
3419 // DECLINE message.
3420
3421 // Let's set the status to be success by default. We can override it with
3422 // error status if needed. The important thing to understand here is that
3423 // the global status code may be set to success only if all IA options were
3424 // handled properly. Therefore the declineIA options
3425 // may turn the status code to some error, but can't turn it back to success.
3426 int general_status = STATUS_Success;
3427
3428 for (OptionCollection::iterator opt = decline->options_.begin();
3429 opt != decline->options_.end(); ++opt) {
3430 switch (opt->second->getType()) {
3431 case D6O_IA_NA: {
3432 OptionPtr answer_opt = declineIA(decline, ctx.duid_, general_status,
3433 boost::dynamic_pointer_cast<Option6IA>(opt->second),
3434 ctx.new_leases_);
3435 if (answer_opt) {
3436
3437 // We have an answer, let's use it.
3438 reply->addOption(answer_opt);
3439 } else {
3440
3441 // The only case when declineIA could return NULL is if one of the
3442 // hook callouts set next step status to DROP. We just need to drop
3443 // this packet.
3444 return (false);
3445 }
3446 break;
3447 }
3448 default:
3449 // We don't care for the remaining options
3450 ;
3451 }
3452 }
3453
3454 return (true);
3455}
3456
3458Dhcpv6Srv::declineIA(const Pkt6Ptr& decline, const DuidPtr& duid,
3459 int& general_status, boost::shared_ptr<Option6IA> ia,
3460 Lease6Collection& new_leases) {
3461
3463 .arg(decline->getLabel())
3464 .arg(ia->getIAID());
3465
3466 // Decline can be done in one of two ways:
3467 // Approach 1: extract address from client's IA_NA and see if it belongs
3468 // to this particular client.
3469 // Approach 2: find a subnet for this client, get a lease for
3470 // this subnet/duid/iaid and check if its content matches to what the
3471 // client is asking us to decline.
3472 //
3473 // This method implements approach 1.
3474
3475 // That's our response
3476 boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
3477
3478 const OptionCollection& opts = ia->getOptions();
3479 int total_addrs = 0; // Let's count the total number of addresses.
3480 for (OptionCollection::const_iterator opt = opts.begin(); opt != opts.end();
3481 ++opt) {
3482
3483 // Let's ignore nested options other than IAADDR (there shouldn't be anything
3484 // else in IA_NA in Decline message, but let's be on the safe side).
3485 if (opt->second->getType() != D6O_IAADDR) {
3486 continue;
3487 }
3488 Option6IAAddrPtr decline_addr = boost::dynamic_pointer_cast<Option6IAAddr>
3489 (opt->second);
3490 if (!decline_addr) {
3491 continue;
3492 }
3493
3494 total_addrs++;
3495
3497 decline_addr->getAddress());
3498
3499 if (!lease) {
3500 // Client trying to decline a lease that we don't know about.
3502 .arg(decline->getLabel()).arg(decline_addr->getAddress().toText());
3503
3504 // According to RFC 8415, section 18.3.8:
3505 // "For each IA in the Decline message for which the server has no
3506 // binding information, the server adds an IA option using the IAID
3507 // from the Decline message and includes a Status Code option with
3508 // the value NoBinding in the IA option".
3509 setStatusCode(ia_rsp, createStatusCode(*decline, *ia_rsp, STATUS_NoBinding,
3510 "Server does not know about such an address."));
3511
3512 // In the same section of RFC 8415:
3513 // "The server ignores addresses not assigned to the IAs (though it may"
3514 // choose to log an error if it finds such addresses)."
3515 continue; // There may be other addresses.
3516 }
3517
3518 if (!lease->duid_) {
3519 // Something is gravely wrong here. We do have a lease, but it does not
3520 // have mandatory DUID information attached. Someone was messing with our
3521 // database.
3522
3524 .arg(decline->getLabel())
3525 .arg(decline_addr->getAddress().toText());
3526
3527 ia_rsp->addOption(createStatusCode(*decline, *ia_rsp, STATUS_UnspecFail,
3528 "Database consistency check failed when attempting Decline."));
3529
3530 continue;
3531 }
3532
3533 // Ok, there's a sane lease with an address. Let's check if DUID matches first.
3534 if (*duid != *(lease->duid_)) {
3535
3536 // Sorry, it's not your address. You can't release it.
3538 .arg(decline->getLabel())
3539 .arg(decline_addr->getAddress().toText())
3540 .arg(lease->duid_->toText());
3541
3542 ia_rsp->addOption(createStatusCode(*decline, *ia_rsp, STATUS_NoBinding,
3543 "This address does not belong to you, you can't decline it"));
3544
3545 continue;
3546 }
3547
3548 // Let's check if IAID matches.
3549 if (ia->getIAID() != lease->iaid_) {
3550 // This address belongs to this client, but to a different IA
3552 .arg(decline->getLabel())
3553 .arg(lease->addr_.toText())
3554 .arg(ia->getIAID())
3555 .arg(lease->iaid_);
3556 setStatusCode(ia_rsp, createStatusCode(*decline, *ia_rsp, STATUS_NoBinding,
3557 "This is your address, but you used wrong IAID"));
3558
3559 continue;
3560 }
3561
3562 // Ok, all is good. Decline this lease.
3563 if (!declineLease(decline, lease, ia_rsp)) {
3564 // declineLease returns false only when hook callouts set the next
3565 // step status to drop. We just propagate the bad news here.
3566 return (OptionPtr());
3567
3568 } else {
3569 new_leases.push_back(lease);
3570 }
3571 }
3572
3573 if (total_addrs == 0) {
3574 setStatusCode(ia_rsp, createStatusCode(*decline, *ia_rsp, STATUS_NoBinding,
3575 "No addresses sent in IA_NA"));
3576 general_status = STATUS_NoBinding;
3577 }
3578
3579 return (ia_rsp);
3580}
3581
3582void
3583Dhcpv6Srv::setStatusCode(boost::shared_ptr<isc::dhcp::Option6IA>& container,
3584 const OptionPtr& status) {
3585 // Let's delete any old status code we may have.
3586 container->delOption(D6O_STATUS_CODE);
3587
3588 container->addOption(status);
3589}
3590
3591bool
3592Dhcpv6Srv::declineLease(const Pkt6Ptr& decline, const Lease6Ptr lease,
3593 boost::shared_ptr<Option6IA> ia_rsp) {
3594 // We do not want to decrease the assigned-nas at this time. While
3595 // technically a declined address is no longer allocated, the
3596 // primary usage of the assigned-nas statistic is to monitor pool
3597 // utilization. Most people would forget to include declined-nas
3598 // in the calculation, and simply do assigned-nas/total-nas. This
3599 // would have a bias towards under-representing pool utilization,
3600 // if we decreased allocated immediately after receiving DHCPDECLINE,
3601 // rather than later when we recover the address.
3602
3603 // Let's call lease6_decline hooks if necessary.
3604 if (HooksManager::calloutsPresent(Hooks.hook_index_lease6_decline_)) {
3605 CalloutHandlePtr callout_handle = getCalloutHandle(decline);
3606
3607 // Use the RAII wrapper to make sure that the callout handle state is
3608 // reset when this object goes out of scope. All hook points must do
3609 // it to prevent possible circular dependency between the callout
3610 // handle and its arguments.
3611 ScopedCalloutHandleState callout_handle_state(callout_handle);
3612
3613 // Enable copying options from the packet within hook library.
3614 ScopedEnableOptionsCopy<Pkt6> query6_options_copy(decline);
3615
3616 // Pass the original packet
3617 callout_handle->setArgument("query6", decline);
3618
3619 // Pass the lease to be updated
3620 callout_handle->setArgument("lease6", lease);
3621
3622 // Call callouts
3623 HooksManager::callCallouts(Hooks.hook_index_lease6_decline_,
3624 *callout_handle);
3625
3626 // Callouts decided to SKIP the next processing step. The next
3627 // processing step would to actually decline the lease, so we'll
3628 // keep the lease as is.
3629 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) {
3631 .arg(decline->getLabel())
3632 .arg(decline->getIface())
3633 .arg(lease->addr_.toText());
3634 return (true);
3635 }
3636
3637 // Callouts decided to DROP the packet. Let's simply log it and
3638 // return false, so callers will act accordingly.
3639 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP) {
3641 .arg(decline->getLabel())
3642 .arg(decline->getIface())
3643 .arg(lease->addr_.toText());
3644 return (false);
3645 }
3646 }
3647
3648 Lease6Ptr old_values = boost::make_shared<Lease6>(*lease);
3649
3650 // @todo: Call hooks.
3651
3652 // We need to disassociate the lease from the client. Once we move a lease
3653 // to declined state, it is no longer associated with the client in any
3654 // way.
3655 lease->decline(CfgMgr::instance().getCurrentCfg()->getDeclinePeriod());
3656
3657 try {
3659 } catch (const Exception& ex) {
3660 // Update failed.
3662 .arg(decline->getLabel())
3663 .arg(lease->addr_.toText())
3664 .arg(ex.what());
3665 return (false);
3666 }
3667
3668 // Check if a lease has flags indicating that the FQDN update has
3669 // been performed. If so, create NameChangeRequest which removes
3670 // the entries. This method does all necessary checks.
3671 queueNCR(CHG_REMOVE, old_values);
3672
3673 // Bump up the subnet-specific statistic.
3674 StatsMgr::instance().addValue(
3675 StatsMgr::generateName("subnet", lease->subnet_id_, "declined-addresses"),
3676 static_cast<int64_t>(1));
3677
3678 // Global declined addresses counter.
3679 StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(1));
3680
3681 LOG_INFO(lease6_logger, DHCP6_DECLINE_LEASE).arg(decline->getLabel())
3682 .arg(lease->addr_.toText()).arg(lease->valid_lft_);
3683
3684 ia_rsp->addOption(createStatusCode(*decline, *ia_rsp, STATUS_Success,
3685 "Lease declined. Hopefully the next one will be better."));
3686
3687 return (true);
3688}
3689
3690Pkt6Ptr
3692
3693 Pkt6Ptr inf_request = ctx.query_;
3694 conditionallySetReservedClientClasses(inf_request, ctx);
3695 requiredClassify(inf_request, ctx);
3696
3697 // Create a Reply packet, with the same trans-id as the client's.
3698 Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, inf_request->getTransid()));
3699
3700 // Copy client options (client-id, also relay information if present)
3701 copyClientOptions(inf_request, reply);
3702
3703 // Build the configured option list for append methods
3704 CfgOptionList co_list;
3705 buildCfgOptionList(inf_request, ctx, co_list);
3706
3707 // Append default options, i.e. options that the server is supposed
3708 // to put in all messages it sends (server-id for now, but possibly other
3709 // options once we start supporting authentication)
3710 appendDefaultOptions(inf_request, reply, co_list);
3711
3712 // Try to assign options that were requested by the client.
3713 appendRequestedOptions(inf_request, reply, co_list);
3714
3715 // Try to assign vendor options that were requested by the client.
3716 appendRequestedVendorOptions(inf_request, reply, ctx, co_list);
3717
3718 return (reply);
3719}
3720
3721void
3723
3724 // flags are in transid
3725 // uint32_t flags = dhcp4_query->getTransid();
3726 // do nothing with DHCPV4_QUERY_FLAGS_UNICAST
3727
3728 // Get the DHCPv4 message option
3729 OptionPtr dhcp4_msg = dhcp4_query->getOption(D6O_DHCPV4_MSG);
3730 if (dhcp4_msg) {
3731 try {
3732 // Forward the whole message to the DHCPv4 server via IPC
3733 Dhcp6to4Ipc::instance().send(dhcp4_query);
3734 } catch (...) {
3735 // Assume the error was already logged
3736 return;
3737 }
3738 }
3739
3740 // This method does not return anything as we always sent back
3741 // the response via Dhcp6To4Ipc.
3742}
3743
3744void Dhcpv6Srv::classifyByVendor(const Pkt6Ptr& pkt, std::string& classes) {
3745 OptionVendorClassPtr vclass = boost::dynamic_pointer_cast<
3746 OptionVendorClass>(pkt->getOption(D6O_VENDOR_CLASS));
3747
3748 if (!vclass || vclass->getTuplesNum() == 0) {
3749 return;
3750 }
3751
3752 if (vclass->hasTuple(DOCSIS3_CLASS_MODEM)) {
3754 classes += VENDOR_CLASS_PREFIX + DOCSIS3_CLASS_MODEM + " ";
3755
3756 } else if (vclass->hasTuple(DOCSIS3_CLASS_EROUTER)) {
3758 classes += VENDOR_CLASS_PREFIX + DOCSIS3_CLASS_EROUTER + " ";
3759
3760 } else {
3761 pkt->addClass(VENDOR_CLASS_PREFIX + vclass->getTuple(0).getText());
3762 classes + VENDOR_CLASS_PREFIX + vclass->getTuple(0).getText() + " ";
3763 }
3764}
3765
3767 // All packets belongs to ALL
3768 pkt->addClass("ALL");
3769 string classes = "ALL ";
3770
3771 // First: built-in vendor class processing
3772 classifyByVendor(pkt, classes);
3773
3774 // Run match expressions on classes not depending on KNOWN/UNKNOWN.
3775 evaluateClasses(pkt, false);
3776}
3777
3778void Dhcpv6Srv::evaluateClasses(const Pkt6Ptr& pkt, bool depend_on_known) {
3779 // Note getClientClassDictionary() cannot be null
3780 const ClientClassDictionaryPtr& dict =
3781 CfgMgr::instance().getCurrentCfg()->getClientClassDictionary();
3782 const ClientClassDefListPtr& defs_ptr = dict->getClasses();
3783 for (ClientClassDefList::const_iterator it = defs_ptr->cbegin();
3784 it != defs_ptr->cend(); ++it) {
3785 // Note second cannot be null
3786 const ExpressionPtr& expr_ptr = (*it)->getMatchExpr();
3787 // Nothing to do without an expression to evaluate
3788 if (!expr_ptr) {
3789 continue;
3790 }
3791 // Not the right time if only when required
3792 if ((*it)->getRequired()) {
3793 continue;
3794 }
3795 // Not the right pass.
3796 if ((*it)->getDependOnKnown() != depend_on_known) {
3797 continue;
3798 }
3799 // Evaluate the expression which can return false (no match),
3800 // true (match) or raise an exception (error)
3801 try {
3802 bool status = evaluateBool(*expr_ptr, *pkt);
3803 if (status) {
3805 .arg((*it)->getName())
3806 .arg(status);
3807 // Matching: add the class
3808 pkt->addClass((*it)->getName());
3809 } else {
3811 .arg((*it)->getName())
3812 .arg(status);
3813 }
3814 } catch (const Exception& ex) {
3816 .arg((*it)->getName())
3817 .arg(ex.what());
3818 } catch (...) {
3820 .arg((*it)->getName())
3821 .arg("get exception?");
3822 }
3823 }
3824}
3825
3826void
3828 const AllocEngine::ClientContext6& ctx) {
3829 if (ctx.currentHost() && pkt) {
3830 const ClientClasses& classes = ctx.currentHost()->getClientClasses6();
3831 for (ClientClasses::const_iterator cclass = classes.cbegin();
3832 cclass != classes.cend(); ++cclass) {
3833 pkt->addClass(*cclass);
3834 }
3835 }
3836
3837 const ClientClasses& classes = pkt->getClasses();
3838 if (!classes.empty()) {
3840 .arg(pkt->getLabel())
3841 .arg(classes.toText());
3842 }
3843}
3844
3845void
3847 const AllocEngine::ClientContext6& ctx) {
3848 if (ctx.subnet_) {
3849 SharedNetwork6Ptr shared_network;
3850 ctx.subnet_->getSharedNetwork(shared_network);
3851 if (shared_network) {
3852 ConstHostPtr host = ctx.currentHost();
3853 if (host && (host->getIPv6SubnetID() != SUBNET_ID_GLOBAL)) {
3854 setReservedClientClasses(pkt, ctx);
3855 }
3856 }
3857 }
3858}
3859
3860void
3862 // First collect required classes
3863 ClientClasses classes = pkt->getClasses(true);
3864 Subnet6Ptr subnet = ctx.subnet_;
3865
3866 if (subnet) {
3867 // Begin by the shared-network
3868 SharedNetwork6Ptr network;
3869 subnet->getSharedNetwork(network);
3870 if (network) {
3871 const ClientClasses& to_add = network->getRequiredClasses();
3872 for (ClientClasses::const_iterator cclass = to_add.cbegin();
3873 cclass != to_add.cend(); ++cclass) {
3874 classes.insert(*cclass);
3875 }
3876 }
3877
3878 // Followed by the subnet
3879 const ClientClasses& to_add = subnet->getRequiredClasses();
3880 for (ClientClasses::const_iterator cclass = to_add.cbegin();
3881 cclass != to_add.cend(); ++cclass) {
3882 classes.insert(*cclass);
3883 }
3884
3885 // And finish by pools
3886 for (auto resource : ctx.allocated_resources_) {
3887 PoolPtr pool =
3888 ctx.subnet_->getPool(resource.getPrefixLength() == 128 ?
3890 resource.getAddress(),
3891 false);
3892 if (pool) {
3893 const ClientClasses& to_add = pool->getRequiredClasses();
3894 for (ClientClasses::const_iterator cclass = to_add.cbegin();
3895 cclass != to_add.cend(); ++cclass) {
3896 classes.insert(*cclass);
3897 }
3898 }
3899 }
3900
3901 // host reservation???
3902 }
3903
3904 // Run match expressions
3905 // Note getClientClassDictionary() cannot be null
3906 const ClientClassDictionaryPtr& dict =
3907 CfgMgr::instance().getCurrentCfg()->getClientClassDictionary();
3908 for (ClientClasses::const_iterator cclass = classes.cbegin();
3909 cclass != classes.cend(); ++cclass) {
3910 const ClientClassDefPtr class_def = dict->findClass(*cclass);
3911 if (!class_def) {
3913 .arg(*cclass);
3914 continue;
3915 }
3916 const ExpressionPtr& expr_ptr = class_def->getMatchExpr();
3917 // Nothing to do without an expression to evaluate
3918 if (!expr_ptr) {
3920 .arg(*cclass);
3921 continue;
3922 }
3923 // Evaluate the expression which can return false (no match),
3924 // true (match) or raise an exception (error)
3925 try {
3926 bool status = evaluateBool(*expr_ptr, *pkt);
3927 if (status) {
3929 .arg(*cclass)
3930 .arg(status);
3931 // Matching: add the class
3932 pkt->addClass(*cclass);
3933 } else {
3935 .arg(*cclass)
3936 .arg(status);
3937 }
3938 } catch (const Exception& ex) {
3940 .arg(*cclass)
3941 .arg(ex.what());
3942 } catch (...) {
3944 .arg(*cclass)
3945 .arg("get exception?");
3946 }
3947 }
3948}
3949
3950void
3951Dhcpv6Srv::updateReservedFqdn(AllocEngine::ClientContext6& ctx,
3952 const Pkt6Ptr& answer) {
3953 if (!answer) {
3954 isc_throw(isc::Unexpected, "an instance of the object encapsulating"
3955 " a message must not be NULL when updating reserved FQDN");
3956 }
3957
3958 Option6ClientFqdnPtr fqdn = boost::dynamic_pointer_cast<Option6ClientFqdn>
3959 (answer->getOption(D6O_CLIENT_FQDN));
3960
3961 // If Client FQDN option is not included, there is nothing to do.
3962 if (!fqdn) {
3963 return;
3964 }
3965
3966 std::string name = fqdn->getDomainName();
3967
3968 // If there is a host reservation for this client we have to check whether
3969 // this reservation has the same hostname as the hostname currently
3970 // present in the FQDN option. If not, it indicates that the allocation
3971 // engine picked a different subnet (from within a shared network) for
3972 // reservations and we have to send this new value to the client.
3973 if (ctx.currentHost() &&
3974 !ctx.currentHost()->getHostname().empty()) {
3975 std::string new_name = CfgMgr::instance().getD2ClientMgr().
3976 qualifyName(ctx.currentHost()->getHostname(), *ctx.getDdnsParams(), true);
3977
3978 if (new_name != name) {
3979 fqdn->setDomainName(new_name, Option6ClientFqdn::FULL);
3980
3981 // Replace previous instance of Client FQDN option.
3982 answer->delOption(D6O_CLIENT_FQDN);
3983 answer->addOption(fqdn);
3984 }
3985 }
3986}
3987
3988void
3989Dhcpv6Srv::generateFqdn(const Pkt6Ptr& answer,
3991 if (!answer) {
3992 isc_throw(isc::Unexpected, "an instance of the object encapsulating"
3993 " a message must not be NULL when generating FQDN");
3994 }
3995
3998
3999 // It is likely that client hasn't included the FQDN option. In such case,
4000 // FQDN option will be NULL. Also, there is nothing to do if the option
4001 // is present and conveys the non-empty FQDN.
4002 Option6ClientFqdnPtr fqdn = boost::dynamic_pointer_cast<
4003 Option6ClientFqdn>(answer->getOption(D6O_CLIENT_FQDN));
4004 if (!fqdn || !fqdn->getDomainName().empty()) {
4005 return;
4006 }
4007
4008 // Get the first IA_NA acquired for the client.
4009 OptionPtr ia = answer->getOption(D6O_IA_NA);
4010 if (!ia) {
4011 return;
4012 }
4013
4014 // If it has any IAAddr, use the first one to generate unique FQDN.
4015 Option6IAAddrPtr iaaddr = boost::dynamic_pointer_cast<
4016 Option6IAAddr>(ia->getOption(D6O_IAADDR));
4017 if (!iaaddr) {
4018 return;
4019 }
4020 // Get the IPv6 address acquired by the client.
4021 IOAddress addr = iaaddr->getAddress();
4022 std::string generated_name =
4024
4026 .arg(answer->getLabel())
4027 .arg(generated_name);
4028
4029 try {
4030 // The lease has been acquired but the FQDN for this lease hasn't
4031 // been updated in the lease database. We now have new FQDN
4032 // generated, so the lease database has to be updated here.
4033 // However, never update lease database for Advertise, just send
4034 // our notion of client's FQDN in the Client FQDN option.
4035 if (answer->getType() != DHCPV6_ADVERTISE) {
4036 Lease6Ptr lease;
4037 for (auto l : ctx.new_leases_) {
4038 if ((l->type_ == Lease::TYPE_NA) && (l->addr_ == addr)) {
4039 lease = l;
4040 break;
4041 }
4042 }
4043 if (lease) {
4044 lease->hostname_ = generated_name;
4045 lease->reuseable_valid_lft_ = 0;
4047
4048 } else {
4049 isc_throw(isc::Unexpected, "there is no lease in the database "
4050 " for address " << addr << ", so as it is impossible"
4051 " to update FQDN data. This is a programmatic error"
4052 " as the given address is now being handed to the"
4053 " client");
4054 }
4055 }
4056 // Set the generated FQDN in the Client FQDN option.
4057 fqdn->setDomainName(generated_name, Option6ClientFqdn::FULL);
4058
4059 answer->delOption(D6O_CLIENT_FQDN);
4060 answer->addOption(fqdn);
4061 ctx.hostname_ = generated_name;
4062 } catch (const Exception& ex) {
4064 .arg(answer->getLabel())
4065 .arg(addr.toText())
4066 .arg(ex.what());
4067 }
4068}
4069
4070void
4073 if (d2_mgr.ddnsEnabled()) {
4074 // Updates are enabled, so lets start the sender, passing in
4075 // our error handler.
4076 // This may throw so wherever this is called needs to ready.
4078 this, ph::_1, ph::_2));
4079 }
4080}
4081
4082void
4085 if (d2_mgr.ddnsEnabled()) {
4086 // Updates are enabled, so lets stop the sender
4087 d2_mgr.stopSender();
4088 }
4089}
4090
4091void
4096 arg(result).arg((ncr ? ncr->toText() : " NULL "));
4097 // We cannot communicate with kea-dhcp-ddns, suspend further updates.
4101}
4102
4103// Refer to config_report so it will be embedded in the binary
4105
4106std::string
4108 std::stringstream tmp;
4109
4110 tmp << VERSION;
4111 if (extended) {
4112 tmp << endl << EXTENDED_VERSION << endl;
4113 tmp << "linked with:" << endl;
4114 tmp << Logger::getVersion() << endl;
4115 tmp << CryptoLink::getVersion() << endl;
4116 tmp << "database:" << endl;
4117#ifdef HAVE_MYSQL
4118 tmp << MySqlLeaseMgr::getDBVersion() << endl;
4119#endif
4120#ifdef HAVE_PGSQL
4121 tmp << PgSqlLeaseMgr::getDBVersion() << endl;
4122#endif
4123#ifdef HAVE_CQL
4124 tmp << CqlLeaseMgr::getDBVersion() << endl;
4125#endif
4127
4128 // @todo: more details about database runtime
4129 }
4130
4131 return (tmp.str());
4132}
4133
4134void Dhcpv6Srv::processRSOO(const Pkt6Ptr& query, const Pkt6Ptr& rsp) {
4135
4136 if (query->relay_info_.empty()) {
4137 // RSOO is inserted by relay agents, nothing to do here if it's
4138 // a direct message.
4139 return;
4140 }
4141
4142 // Get RSOO configuration.
4143 ConstCfgRSOOPtr cfg_rsoo = CfgMgr::instance().getCurrentCfg()->getCfgRSOO();
4144
4145 // Let's get over all relays (encapsulation levels). We need to do
4146 // it in the same order as the client packet traversed the relays.
4147 for (int i = query->relay_info_.size(); i > 0 ; --i) {
4148 OptionPtr rsoo_container = query->getRelayOption(D6O_RSOO, i - 1);
4149 if (rsoo_container) {
4150 // There are RSOO options. Let's get through them one by one
4151 // and if it's RSOO-enabled and there's no such option provided yet,
4152 // copy it to the server's response
4153 const OptionCollection& rsoo = rsoo_container->getOptions();
4154 for (OptionCollection::const_iterator opt = rsoo.begin();
4155 opt != rsoo.end(); ++opt) {
4156
4157 // Echo option if it is RSOO enabled option and there is no such
4158 // option added yet.
4159 if (cfg_rsoo->enabled(opt->second->getType()) &&
4160 !rsp->getOption(opt->second->getType())) {
4161 rsp->addOption(opt->second);
4162 }
4163 }
4164 }
4165 }
4166}
4167
4169
4170 if (query->relay_info_.empty()) {
4171 // No relay agent
4172 return (0);
4173 }
4174
4175 // Did the last relay agent add a relay-source-port?
4176 if (query->getRelayOption(D6O_RELAY_SOURCE_PORT, 0)) {
4177 // RFC 8357 section 5.2
4178 return (query->getRemotePort());
4179 }
4180
4181 return (0);
4182}
4183
4184void Dhcpv6Srv::processStatsReceived(const Pkt6Ptr& query) {
4185 // Note that we're not bumping pkt6-received statistic as it was
4186 // increased early in the packet reception code.
4187
4188 string stat_name = "pkt6-unknown-received";
4189 switch (query->getType()) {
4190 case DHCPV6_SOLICIT:
4191 stat_name = "pkt6-solicit-received";
4192 break;
4193 case DHCPV6_ADVERTISE:
4194 // Should not happen, but let's keep a counter for it
4195 stat_name = "pkt6-advertise-received";
4196 break;
4197 case DHCPV6_REQUEST:
4198 stat_name = "pkt6-request-received";
4199 break;
4200 case DHCPV6_CONFIRM:
4201 stat_name = "pkt6-confirm-received";
4202 break;
4203 case DHCPV6_RENEW:
4204 stat_name = "pkt6-renew-received";
4205 break;
4206 case DHCPV6_REBIND:
4207 stat_name = "pkt6-rebind-received";
4208 break;
4209 case DHCPV6_REPLY:
4210 // Should not happen, but let's keep a counter for it
4211 stat_name = "pkt6-reply-received";
4212 break;
4213 case DHCPV6_RELEASE:
4214 stat_name = "pkt6-release-received";
4215 break;
4216 case DHCPV6_DECLINE:
4217 stat_name = "pkt6-decline-received";
4218 break;
4219 case DHCPV6_RECONFIGURE:
4220 stat_name = "pkt6-reconfigure-received";
4221 break;
4223 stat_name = "pkt6-infrequest-received";
4224 break;
4226 stat_name = "pkt6-dhcpv4-query-received";
4227 break;
4229 // Should not happen, but let's keep a counter for it
4230 stat_name = "pkt6-dhcpv4-response-received";
4231 break;
4232 default:
4233 ; // do nothing
4234 }
4235
4236 StatsMgr::instance().addValue(stat_name, static_cast<int64_t>(1));
4237}
4238
4240 // Increase generic counter for sent packets.
4241 StatsMgr::instance().addValue("pkt6-sent", static_cast<int64_t>(1));
4242
4243 // Increase packet type specific counter for packets sent.
4244 string stat_name;
4245 switch (response->getType()) {
4246 case DHCPV6_ADVERTISE:
4247 stat_name = "pkt6-advertise-sent";
4248 break;
4249 case DHCPV6_REPLY:
4250 stat_name = "pkt6-reply-sent";
4251 break;
4253 stat_name = "pkt6-dhcpv4-response-sent";
4254 break;
4255 default:
4256 // That should never happen
4257 return;
4258 }
4259
4260 StatsMgr::instance().addValue(stat_name, static_cast<int64_t>(1));
4261}
4262
4264 return (Hooks.hook_index_buffer6_send_);
4265}
4266
4267bool
4268Dhcpv6Srv::requestedInORO(const Pkt6Ptr& query, const uint16_t code) const {
4270 boost::dynamic_pointer_cast<OptionUint16Array>(query->getOption(D6O_ORO));
4271
4272 if (oro) {
4273 const std::vector<uint16_t>& codes = oro->getValues();
4274 return (std::find(codes.begin(), codes.end(), code) != codes.end());
4275 }
4276
4277 return (false);
4278}
4279
4281 // Dump all of our current packets, anything that is mid-stream
4282 HooksManager::clearParkingLots();
4283}
4284
4286void
4287Dhcpv6Srv::setTeeTimes(uint32_t preferred_lft, const Subnet6Ptr& subnet, Option6IAPtr& resp) {
4288 // Default T2 time to zero.
4289 uint32_t t2_time = 0;
4290
4291 // If T2 is explicitly configured we'll use that value.
4292 if (!subnet->getT2().unspecified()) {
4293 t2_time = subnet->getT2();
4294 } else if (subnet->getCalculateTeeTimes()) {
4295 // Calculating tee times is enabled, so calculate it.
4296 t2_time = static_cast<uint32_t>(round(subnet->getT2Percent() * preferred_lft));
4297 }
4298
4299 // We allow T2 to be any value.
4300 resp->setT2(t2_time);
4301
4302 // Default T1 time to zero.
4303 uint32_t t1_time = 0;
4304
4305 // If T1 is explicitly configured we'll use try value.
4306 if (!subnet->getT1().unspecified()) {
4307 t1_time = subnet->getT1();
4308 } else if (subnet->getCalculateTeeTimes()) {
4309 // Calculating tee times is enabled, so calculate it.
4310 t1_time = static_cast<uint32_t>(round(subnet->getT1Percent() * preferred_lft));
4311 }
4312
4313 // T1 is sane if it is less than or equal to T2.
4314 if (t1_time < t2_time) {
4315 resp->setT1(t1_time);
4316 } else {
4317 // It's either explicitly 0 or insane, leave it to the client
4318 resp->setT1(0);
4319 }
4320}
4321
4322void
4325 const Subnet6Ptr orig_subnet) {
4326 // If the subnet's are the same there's nothing to do.
4327 if ((!ctx.subnet_) || (!orig_subnet) || (orig_subnet->getID() == ctx.subnet_->getID())) {
4328 return;
4329 }
4330
4331 // We get the network for logging only. It should always be set as this a dynamic
4332 // change should only happen within shared-networks. Not having one might not be
4333 // an error if a hook changed the subnet?
4334 SharedNetwork6Ptr network;
4335 orig_subnet->getSharedNetwork(network);
4337 .arg(question->getLabel())
4338 .arg(orig_subnet->toText())
4339 .arg(ctx.subnet_->toText())
4340 .arg(network ? network->getName() : "<no network?>");
4341
4342 // The DDNS parameters may have changed with the subnet, so we need to
4343 // recalculate the client name.
4344
4345 // Save the current DNS values on the context.
4346 std::string prev_hostname = ctx.hostname_;
4347 bool prev_fwd_dns_update = ctx.fwd_dns_update_;
4348 bool prev_rev_dns_update = ctx.rev_dns_update_;
4349
4350 // Remove the current FQDN option from the answer.
4351 answer->delOption(D6O_CLIENT_FQDN);
4352
4353 // Recalculate the client's FQDN. This will replace the FQDN option and
4354 // update the context values for hostname_ and DNS directions.
4355 processClientFqdn(question, answer, ctx);
4356
4357 // If this is a real allocation and the DNS values changed we need to
4358 // update the leases.
4359 if (!ctx.fake_allocation_ &&
4360 ((prev_hostname != ctx.hostname_) ||
4361 (prev_fwd_dns_update != ctx.fwd_dns_update_) ||
4362 (prev_rev_dns_update != ctx.rev_dns_update_))) {
4363 for (Lease6Collection::const_iterator l = ctx.new_leases_.begin();
4364 l != ctx.new_leases_.end(); ++l) {
4365 (*l)->hostname_ = ctx.hostname_;
4366 (*l)->fqdn_fwd_ = ctx.fwd_dns_update_;
4367 (*l)->fqdn_rev_ = ctx.rev_dns_update_;
4368 (*l)->reuseable_valid_lft_ = 0;
4370 }
4371 }
4372}
4373
4374std::list<std::list<std::string>> Dhcpv6Srv::jsonPathsToRedact() const{
4375 static std::list<std::list<std::string>> const list({
4376 {"config-control", "config-databases", "[]"},
4377 {"hooks-libraries", "[]", "parameters", "*"},
4378 {"hosts-database"},
4379 {"hosts-databases", "[]"},
4380 {"lease-database"},
4381 });
4382 return list;
4383}
4384
4385} // namespace dhcp
4386} // namespace isc
CtrlAgentHooks Hooks
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.
Definition: alloc_engine.h:324
DHCPv4 and DHCPv6 allocation engine.
Definition: alloc_engine.h:63
std::vector< Resource > HintContainer
Container for client's hints.
Definition: alloc_engine.h:426
Implementation of the mechanisms to control the use of the Configuration Backends by the DHCPv6 serve...
Definition: cb_ctl_dhcp6.h:26
D2ClientMgr & getD2ClientMgr()
Fetches the DHCP-DDNS manager.
Definition: cfgmgr.cc:66
static CfgMgr & instance()
returns a single instance of Configuration Manager
Definition: cfgmgr.cc:25
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
Definition: cfgmgr.cc:161
static SubnetSelector initSelector(const Pkt6Ptr &query)
Build selector from a client's message.
Container for storing client class names.
Definition: classify.h:43
void insert(const ClientClass &class_name)
Insert an element.
Definition: classify.h:62
std::list< ClientClass >::const_iterator const_iterator
Type of iterators.
Definition: classify.h:47
bool empty() const
Check if classes is empty.
Definition: classify.h:73
std::string toText(const std::string &separator=", ") const
Returns all class names as text.
Definition: classify.cc:40
const_iterator cbegin() const
Iterator to the first element.
Definition: classify.h:86
const_iterator cend() const
Iterator to the past the end element.
Definition: classify.h:91
Client race avoidance RAII handler.
bool tryLock(Pkt4Ptr query, ContinuationPtr cont=ContinuationPtr())
Tries to acquires a client.
static std::string getDBVersion()
Local version of getDBVersion() class method.
D2ClientMgr isolates Kea from the details of being a D2 client.
Definition: d2_client_mgr.h:80
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 startSender(D2ClientErrorHandler error_handler, isc::asiolink::IOService &io_service)
Enables sending NameChangeRequests to kea-dhcp-ddns.
void getUpdateDirections(const T &fqdn_resp, bool &forward, bool &reverse)
Get directional update flags based on server FQDN flags.
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.
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).
Definition: duid_factory.h:63
DuidPtr get()
Returns current DUID.
Holds DUID (DHCPv6 Unique Identifier)
Definition: duid.h:27
static const size_t MAX_DUID_LEN
maximum duid size As defined in RFC 8415, section 11.1
Definition: duid.h:31
void send(const Pkt6Ptr &pkt)
Send message over IPC.
Definition: dhcp4o6_ipc.cc:226
void close()
Close communication socket.
Definition: dhcp4o6_ipc.cc:118
static Dhcp6to4Ipc & instance()
Returns pointer to the sole instance of Dhcp6to4Ipc.
Definition: dhcp6to4_ipc.cc:34
static uint16_t client_port
Definition: dhcp6to4_ipc.h:51
void run_one()
Main server processing step.
Definition: dhcp6_srv.cc:549
void shutdown() override
Instructs the server to shut down.
Definition: dhcp6_srv.cc:300
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 extendIA_PD(const Pkt6Ptr &query, AllocEngine::ClientContext6 &ctx, Option6IAPtr ia)
Extends lifetime of the prefix.
Definition: dhcp6_srv.cc:2463
void setReservedClientClasses(const Pkt6Ptr &pkt, const AllocEngine::ClientContext6 &ctx)
Assigns classes retrieved from host reservation database.
Definition: dhcp6_srv.cc:3827
Pkt6Ptr processDecline(AllocEngine::ClientContext6 &ctx)
Process incoming Decline message.
Definition: dhcp6_srv.cc:3385
void evaluateClasses(const Pkt6Ptr &pkt, bool depend_on_known)
Evaluate classes.
Definition: dhcp6_srv.cc:3778
Pkt6Ptr processRenew(AllocEngine::ClientContext6 &ctx)
Processes incoming Renew message.
Definition: dhcp6_srv.cc:3201
static void processStatsSent(const Pkt6Ptr &response)
Updates statistics for transmitted packets.
Definition: dhcp6_srv.cc:4239
int run()
Main server processing loop.
Definition: dhcp6_srv.cc:510
void setPacketStatisticsDefaults()
This function sets statistics related to DHCPv6 packets processing to their initial values.
Definition: dhcp6_srv.cc:253
bool sanityCheck(const Pkt6Ptr &pkt)
Verifies if specified packet meets RFC requirements.
Definition: dhcp6_srv.cc:1574
static uint16_t checkRelaySourcePort(const Pkt6Ptr &query)
Used for DHCPv4-over-DHCPv6 too.
Definition: dhcp6_srv.cc:4168
void assignLeases(const Pkt6Ptr &question, Pkt6Ptr &answer, AllocEngine::ClientContext6 &ctx)
Assigns leases.
Definition: dhcp6_srv.cc:1765
void stopD2()
Stops DHCP_DDNS client IO if DDNS updates are enabled.
Definition: dhcp6_srv.cc:4083
void copyClientOptions(const Pkt6Ptr &question, Pkt6Ptr &answer)
Copies required options from client message to server answer.
Definition: dhcp6_srv.cc:1295
boost::shared_ptr< AllocEngine > alloc_engine_
Allocation Engine.
Definition: dhcp6_srv.h:1156
virtual void sendPacket(const Pkt6Ptr &pkt)
dummy wrapper around IfaceMgr::send()
Definition: dhcp6_srv.cc:309
bool testServerID(const Pkt6Ptr &pkt)
Compare received server id with our server id.
Definition: dhcp6_srv.cc:314
void processPacketPktSend(hooks::CalloutHandlePtr &callout_handle, Pkt6Ptr &query, Pkt6Ptr &rsp)
Executes pkt6_send callout.
Definition: dhcp6_srv.cc:1143
virtual void d2ClientErrorHandler(const dhcp_ddns::NameChangeSender::Result result, dhcp_ddns::NameChangeRequestPtr &ncr)
Implements the error handler for DHCP_DDNS IO errors.
Definition: dhcp6_srv.cc:4092
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.
Definition: dhcp6_srv.cc:3458
virtual Pkt6Ptr receivePacket(int timeout)
dummy wrapper around IfaceMgr::receive6
Definition: dhcp6_srv.cc:305
void processPacketBufferSend(hooks::CalloutHandlePtr &callout_handle, Pkt6Ptr &rsp)
Executes buffer6_send callout and sends the response.
Definition: dhcp6_srv.cc:1208
void requiredClassify(const Pkt6Ptr &pkt, AllocEngine::ClientContext6 &ctx)
Assigns incoming packet to zero or more classes (required pass).
Definition: dhcp6_srv.cc:3861
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.
Definition: dhcp6_srv.cc:2769
void buildCfgOptionList(const Pkt6Ptr &question, AllocEngine::ClientContext6 &ctx, CfgOptionList &co_list)
Build the configured option list.
Definition: dhcp6_srv.cc:1318
void appendDefaultOptions(const Pkt6Ptr &question, Pkt6Ptr &answer, const CfgOptionList &co_list)
Appends default options to server's answer.
Definition: dhcp6_srv.cc:1311
OptionPtr assignIA_NA(const isc::dhcp::Pkt6Ptr &query, AllocEngine::ClientContext6 &ctx, Option6IAPtr ia)
Processes IA_NA option (and assigns addresses if necessary).
Definition: dhcp6_srv.cc:2033
static const std::string VENDOR_CLASS_PREFIX
this is a prefix added to the content of vendor-class option
Definition: dhcp6_srv.h:907
OptionPtr serverid_
Server DUID (to be sent in server-identifier option)
Definition: dhcp6_srv.h:1138
void initContext(const Pkt6Ptr &pkt, AllocEngine::ClientContext6 &ctx, bool &drop)
Initializes client context for specified packet.
Definition: dhcp6_srv.cc:357
void checkDynamicSubnetChange(const Pkt6Ptr &question, Pkt6Ptr &answer, AllocEngine::ClientContext6 &ctx, const Subnet6Ptr orig_subnet)
Iterates over new leases, update stale DNS entries.
Definition: dhcp6_srv.cc:4323
void conditionallySetReservedClientClasses(const Pkt6Ptr &pkt, const AllocEngine::ClientContext6 &ctx)
Assigns classes retrieved from host reservation database if they haven't been yet set.
Definition: dhcp6_srv.cc:3846
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.
Definition: dhcp6_srv.cc:2941
void processDhcp4Query(const Pkt6Ptr &dhcp4_query)
Processes incoming DHCPv4-query message.
Definition: dhcp6_srv.cc:3722
Pkt6Ptr processRebind(AllocEngine::ClientContext6 &ctx)
Processes incoming Rebind message.
Definition: dhcp6_srv.cc:3235
void classifyByVendor(const Pkt6Ptr &pkt, std::string &classes)
Assign class using vendor-class-identifier option.
Definition: dhcp6_srv.cc:3744
void processPacketAndSendResponseNoThrow(Pkt6Ptr &query)
Process a single incoming DHCPv6 packet and sends the response.
Definition: dhcp6_srv.cc:625
void processDhcp6Query(Pkt6Ptr &query, Pkt6Ptr &rsp)
Process a single incoming DHCPv6 query.
Definition: dhcp6_srv.cc:850
virtual ~Dhcpv6Srv()
Destructor. Used during DHCPv6 service shutdown.
Definition: dhcp6_srv.cc:263
void setTeeTimes(uint32_t preferred_lft, const Subnet6Ptr &subnet, Option6IAPtr &resp)
Sets the T1 and T2 timers in the outbound IA.
Definition: dhcp6_srv.cc:4287
Pkt6Ptr processRequest(AllocEngine::ClientContext6 &ctx)
Processes incoming Request and returns Reply response.
Definition: dhcp6_srv.cc:3167
NetworkStatePtr network_state_
Holds information about disabled DHCP service and/or disabled subnet/network scopes.
Definition: dhcp6_srv.h:1164
std::list< std::list< std::string > > jsonPathsToRedact() const final override
Return a list of all paths that contain passwords or secrets for kea-dhcp6.
Definition: dhcp6_srv.cc:4374
void processPacket(Pkt6Ptr &query, Pkt6Ptr &rsp)
Process a single incoming DHCPv6 packet.
Definition: dhcp6_srv.cc:649
OptionPtr assignIA_PD(const Pkt6Ptr &query, AllocEngine::ClientContext6 &ctx, boost::shared_ptr< Option6IA > ia)
Processes IA_PD option (and assigns prefixes if necessary).
Definition: dhcp6_srv.cc:2160
bool testUnicast(const Pkt6Ptr &pkt) const
Check if the message can be sent to unicast.
Definition: dhcp6_srv.cc:336
Pkt6Ptr processRelease(AllocEngine::ClientContext6 &ctx)
Process incoming Release message.
Definition: dhcp6_srv.cc:3359
void processClientFqdn(const Pkt6Ptr &question, const Pkt6Ptr &answer, AllocEngine::ClientContext6 &ctx)
Processes Client FQDN Option.
Definition: dhcp6_srv.cc:1815
void setStatusCode(boost::shared_ptr< Option6IA > &container, const OptionPtr &status)
A simple utility method that sets the status code.
Definition: dhcp6_srv.cc:3583
static int getHookIndexBuffer6Send()
Returns the index of the buffer6_send hook.
Definition: dhcp6_srv.cc:4263
void sendResponseNoThrow(hooks::CalloutHandlePtr &callout_handle, Pkt6Ptr &query, Pkt6Ptr &rsp)
Process an unparked DHCPv6 packet and sends the response.
Definition: dhcp6_srv.cc:1129
void classifyPacket(const Pkt6Ptr &pkt)
Assigns incoming packet to zero or more classes.
Definition: dhcp6_srv.cc:3766
static HWAddrPtr getMAC(const Pkt6Ptr &pkt)
Attempts to get a MAC/hardware address using configured sources.
Definition: dhcp6_srv.cc:2018
Dhcpv6Srv(uint16_t server_port=DHCP6_SERVER_PORT, uint16_t client_port=0)
Default constructor.
Definition: dhcp6_srv.cc:209
bool declineLeases(const Pkt6Ptr &decline, Pkt6Ptr &reply, AllocEngine::ClientContext6 &ctx)
Attempts to decline all leases in specified Decline message.
Definition: dhcp6_srv.cc:3415
void releaseLeases(const Pkt6Ptr &release, Pkt6Ptr &reply, AllocEngine::ClientContext6 &ctx)
Attempts to release received addresses.
Definition: dhcp6_srv.cc:2710
void extendLeases(const Pkt6Ptr &query, Pkt6Ptr &reply, AllocEngine::ClientContext6 &ctx)
Attempts to extend the lifetime of IAs.
Definition: dhcp6_srv.cc:2662
void processRSOO(const Pkt6Ptr &query, const Pkt6Ptr &rsp)
Processes Relay-supplied options, if present.
Definition: dhcp6_srv.cc:4134
static std::string getVersion(bool extended)
returns Kea version on stdout and exit.
Definition: dhcp6_srv.cc:4107
void processPacketAndSendResponse(Pkt6Ptr &query)
Process a single incoming DHCPv6 packet and sends the response.
Definition: dhcp6_srv.cc:637
OptionPtr extendIA_NA(const Pkt6Ptr &query, AllocEngine::ClientContext6 &ctx, Option6IAPtr ia)
Extends lifetime of the specific IA_NA option.
Definition: dhcp6_srv.cc:2302
Pkt6Ptr processConfirm(AllocEngine::ClientContext6 &ctx)
Processes incoming Confirm message and returns Reply.
Definition: dhcp6_srv.cc:3269
void sanityCheckDUID(const OptionPtr &opt, const std::string &opt_name)
verifies if received DUID option (client-id or server-id) is sane
Definition: dhcp6_srv.cc:1673
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.
Definition: dhcp6_srv.cc:1388
uint16_t client_port_
UDP port number to which server sends all responses.
Definition: dhcp6_srv.h:1107
volatile bool shutdown_
Indicates if shutdown is in progress.
Definition: dhcp6_srv.h:1142
Pkt6Ptr processSolicit(AllocEngine::ClientContext6 &ctx)
Processes incoming Solicit and returns response.
Definition: dhcp6_srv.cc:3101
void startD2()
Starts DHCP_DDNS client IO if DDNS updates are enabled.
Definition: dhcp6_srv.cc:4071
static std::string duidToString(const OptionPtr &opt)
converts DUID to text Converts content of DUID option to a text representation, e....
Definition: dhcp6_srv.cc:1275
void createNameChangeRequests(const Pkt6Ptr &answer, AllocEngine::ClientContext6 &ctx)
Creates a number of isc::dhcp_ddns::NameChangeRequest objects based on the DHCPv6 Client FQDN Option.
Definition: dhcp6_srv.cc:1891
Pkt6Ptr processInfRequest(AllocEngine::ClientContext6 &ctx)
Processes incoming Information-request message.
Definition: dhcp6_srv.cc:3691
void processDhcp6QueryAndSendResponse(Pkt6Ptr &query, Pkt6Ptr &rsp)
Process a single incoming DHCPv6 query.
Definition: dhcp6_srv.cc:832
uint16_t server_port_
UDP port number on which server listens.
Definition: dhcp6_srv.h:1104
isc::dhcp::Subnet6Ptr selectSubnet(const Pkt6Ptr &question, bool &drop)
Selects a subnet for a given client's packet.
Definition: dhcp6_srv.cc:1689
void appendRequestedVendorOptions(const Pkt6Ptr &question, Pkt6Ptr &answer, AllocEngine::ClientContext6 &ctx, const CfgOptionList &co_list)
Appends requested vendor options to server's answer.
Definition: dhcp6_srv.cc:1445
bool declineLease(const Pkt6Ptr &decline, const Lease6Ptr lease, boost::shared_ptr< Option6IA > ia_rsp)
Declines specific IPv6 lease.
Definition: dhcp6_srv.cc:3592
void discardPackets()
Discards parked packets Clears the packet parking lots of all packets.
Definition: dhcp6_srv.cc:4280
IdentifierType
Type of the host identifier.
Definition: host.h:307
@ IDENT_HWADDR
Definition: host.h:308
@ IDENT_FLEX
Flexible host identifier.
Definition: host.h:312
std::string getIdentifierAsText() const
Returns host identifier in a textual form.
Definition: host.cc:256
static IfaceMgr & instance()
IfaceMgr is a singleton class.
Definition: iface_mgr.cc:53
bool send(const Pkt6Ptr &pkt)
Sends an IPv6 packet.
Definition: iface_mgr.cc:1101
void closeSockets()
Closes all open sockets.
Definition: iface_mgr.cc:286
static void destroy()
Destroy lease manager.
static LeaseMgr & instance()
Return current 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::string getDBVersion()
Local version of getDBVersion() class method.
static std::string getDBVersion()
Local version of getDBVersion() class method.
Holds information about DHCP service enabling status.
Definition: network_state.h:70
Represents DHCPv6 Client FQDN Option (code 39).
static const uint8_t FLAG_S
S bit.
isc::asiolink::IOAddress getAddress() const
Returns address contained within this option.
Class that represents IAPREFIX option in DHCPv6.
uint32_t getIAID() const
Returns IA identifier.
Definition: option6_ia.h:86
This class represents Status Code option (13) from RFC 8415.
Option descriptor.
Definition: cfg_option.h:42
OptionPtr option_
Option instance.
Definition: cfg_option.h:45
This class encapsulates DHCPv6 Vendor Class and DHCPv4 V-I Vendor Class options.
This class represents vendor-specific information option.
Definition: option_vendor.h:30
const OptionCollection & getOptions() const
Returns all encapsulated options.
Definition: option.h:338
OptionPtr getOption(uint16_t type) const
Returns shared_ptr to suboption of specific type.
Definition: option.cc:211
static std::string getDBVersion()
Local version of getDBVersion() class method.
Represents a DHCPv6 packet.
Definition: pkt6.h:44
virtual std::string getLabel() const
Returns text representation of the primary packet identifiers.
Definition: pkt6.cc:616
Pool information for IPv6 addresses and prefixes.
Definition: pool.h:321
Option6PDExcludePtr getPrefixExcludeOption() const
Returns instance of the pool specific Prefix Exclude option.
Definition: pool.h:455
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:40
Exception thrown when a call to select is interrupted by a signal.
Definition: iface_mgr.h:55
Exception thrown during option unpacking This exception is thrown when an error has occurred,...
Definition: option.h:51
Container class for handling the DHCID value within a NameChangeRequest.
Definition: ncr_msg.h:86
Represents a DHCP-DDNS client request.
Definition: ncr_msg.h:227
Result
Defines the outcome of an asynchronous NCR send.
Definition: ncr_io.h:476
Wrapper class around callout handle which automatically resets handle's state.
int getExitValue()
Fetches the exit value.
Definition: daemon.h:220
Statistics Manager class.
static StatsMgr & instance()
Statistics Manager accessor method.
RAII class creating a critical section.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition: buffer.h:294
size_t getLength() const
Return the length of data written in the buffer.
Definition: buffer.h:403
const void * getData() const
Return a pointer to the head of the data stored in the buffer.
Definition: buffer.h:401
Read mutex RAII handler.
@ STATUS_NoAddrsAvail
Definition: dhcp6.h:166
@ STATUS_NoPrefixAvail
Definition: dhcp6.h:170
@ STATUS_NotOnLink
Definition: dhcp6.h:168
@ STATUS_Success
Definition: dhcp6.h:164
@ STATUS_NoBinding
Definition: dhcp6.h:167
@ STATUS_UnspecFail
Definition: dhcp6.h:165
@ D6O_CLIENT_FQDN
Definition: dhcp6.h:59
@ 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_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:205
@ DHCPV6_REQUEST
Definition: dhcp6.h:206
@ DHCPV6_RENEW
Definition: dhcp6.h:208
@ DHCPV6_DHCPV4_QUERY
Definition: dhcp6.h:227
@ DHCPV6_DHCPV4_RESPONSE
Definition: dhcp6.h:228
@ DHCPV6_RECONFIGURE
Definition: dhcp6.h:213
@ DHCPV6_REBIND
Definition: dhcp6.h:209
@ DHCPV6_REPLY
Definition: dhcp6.h:210
@ DHCPV6_SOLICIT
Definition: dhcp6.h:204
@ DHCPV6_RELEASE
Definition: dhcp6.h:211
@ DHCPV6_INFORMATION_REQUEST
Definition: dhcp6.h:214
@ DHCPV6_CONFIRM
Definition: dhcp6.h:207
@ DHCPV6_DECLINE
Definition: dhcp6.h:212
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
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.
An abstract API for lease database.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
Definition: macros.h:32
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
Definition: macros.h:20
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
Definition: macros.h:26
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
Definition: macros.h:14
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
const char *const config_report[]
Definition: config_report.h:15
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
Definition: ncr_msg.h:212
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
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_LEASE_ALLOC
const isc::log::MessageID DHCP6_FLEX_ID
boost::shared_ptr< Subnet > SubnetPtr
A generic pointer to either Subnet4 or Subnet6 object.
Definition: subnet.h:513
const isc::log::MessageID DHCP6_HOOK_PACKET_SEND_SKIP
const isc::log::MessageID DHCP6_SUBNET_SELECTION_FAILED
const isc::log::MessageID DHCP6_CLASS_UNDEFINED
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_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.
boost::shared_ptr< Option6PDExclude > Option6PDExcludePtr
Pointer to the Option6PDExclude object.
const isc::log::MessageID EVAL_RESULT
Definition: eval_messages.h:51
const isc::log::MessageID DHCP6_BUFFER_UNPACK
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_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
boost::shared_ptr< DUID > DuidPtr
Definition: duid.h:20
const isc::log::MessageID DHCP6_OPEN_SOCKET
const isc::log::MessageID DHCP6_PACK_FAIL
const isc::log::MessageID DHCP6_RELEASE_PD_FAIL_WRONG_IAID
OptionBuffer::const_iterator OptionBufferConstIter
const_iterator for walking over OptionBuffer
Definition: option.h:30
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
Definition: lease.h:492
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
Definition: lease.h:640
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
boost::shared_ptr< Option6IA > Option6IAPtr
A pointer to the Option6IA object.
Definition: option6_ia.h:17
boost::shared_ptr< Subnet6 > Subnet6Ptr
A pointer to a Subnet6 object.
Definition: subnet.h:670
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.
Definition: srv_config.h:162
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_REQUIRED_OPTIONS_CHECK_FAIL
const isc::log::MessageID DHCP6_PROCESS_IA_NA_EXTEND
const isc::log::MessageID DHCP6_RELEASE_PD_FAIL
const char *const * dhcp6_config_report
Definition: dhcp6_srv.cc:4104
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:84
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_DECLINE_FAIL_IAID_MISMATCH
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:286
boost::shared_ptr< SharedNetwork6 > SharedNetwork6Ptr
Pointer to SharedNetwork6 object.
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:30
const isc::log::MessageID DHCP6_LEASE_ADVERT_FAIL
const isc::log::MessageID DHCP6_HOOK_LEASES6_PARKING_LOT_FULL
uint32_t calculateDdnsTtl(uint32_t lease_lft)
Calculates TTL for a DNS resource record based on lease life time.
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:505
isc::hooks::CalloutHandlePtr getCalloutHandle(const T &pktptr)
CalloutHandle Store.
const isc::log::MessageID DHCP6_PACKET_PROCESS_FAIL
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
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:272
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:81
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:14
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:788
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:644
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:281
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< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Definition: pkt6.h:28
const isc::log::MessageID DHCP6_PROCESS_IA_NA_RELEASE
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
const int DBG_DHCP6_BASIC
Debug level used to trace basic operations within the code.
Definition: dhcp6_log.h:31
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_CLASS_UNTESTABLE
const isc::log::MessageID DHCP6_RELEASE_NA_FAIL_WRONG_IAID
const isc::log::MessageID DHCP6_HOOK_BUFFER_RCVD_DROP
boost::shared_ptr< Option > OptionPtr
Definition: option.h:36
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:712
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:312
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.
const int DBGLVL_TRACE_BASIC
Trace basic operations.
Definition: log_dbglevels.h:69
const int DBGLVL_PKT_HANDLING
This debug level is reserved for logging the details of packet handling, such as dropping the packet ...
Definition: log_dbglevels.h:58
Definition: edns.h:19
bool equalValues(const T &ptr1, const T &ptr2)
This function checks if two pointers are non-null and values are equal.
Definition: pointer_util.h:27
Defines the logger used by the top-level component of kea-lfc.
This file provides the classes needed to embody, compose, and decompose DNS update requests that are ...
#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...
Definition: alloc_engine.h:551
Option6IAPtr ia_rsp_
A pointer to the IA_NA/IA_PD option to be sent in response.
Definition: alloc_engine.h:568
Lease::Type type_
Lease type (IA or PD)
Definition: alloc_engine.h:536
Lease6Collection changed_leases_
A pointer to any leases that have changed FQDN information.
Definition: alloc_engine.h:559
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.
uint32_t iaid_
The IAID field from IA_NA or IA_PD that is being processed.
Definition: alloc_engine.h:533
Context information for the DHCPv6 leases allocation.
Definition: alloc_engine.h:459
IAContext & currentIA()
Returns IA specific context for the currently processed IA.
Definition: alloc_engine.h:656
std::vector< IAContext > ias_
Container holding IA specific contexts.
Definition: alloc_engine.h:616
void addHostIdentifier(const Host::IdentifierType &id_type, const std::vector< uint8_t > &identifier)
Convenience function adding host identifier into host_identifiers_ list.
Definition: alloc_engine.h:646
bool fake_allocation_
Indicates if this is a real or fake allocation.
Definition: alloc_engine.h:474
ConstHostPtr currentHost() const
Returns host from the most preferred subnet.
DuidPtr duid_
Client identifier.
Definition: alloc_engine.h:485
Lease6Collection new_leases_
A collection of newly allocated leases.
Definition: alloc_engine.h:524
HWAddrPtr hwaddr_
Hardware/MAC address (if available, may be NULL)
Definition: alloc_engine.h:488
hooks::CalloutHandlePtr callout_handle_
Callout handle associated with the client's message.
Definition: alloc_engine.h:518
Subnet6Ptr subnet_
Subnet selected for the client by the server.
Definition: alloc_engine.h:477
ResourceContainer allocated_resources_
Holds addresses and prefixes allocated for all IAs.
Definition: alloc_engine.h:521
bool rev_dns_update_
A boolean value which indicates that server takes responsibility for the reverse DNS Update for this ...
Definition: alloc_engine.h:509
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.
Definition: alloc_engine.h:467
void createIAContext()
Creates new IA context.
Definition: alloc_engine.h:667
std::map< SubnetID, ConstHostPtr > hosts_
Holds a map of hosts belonging to the client within different subnets.
Definition: alloc_engine.h:499
bool fwd_dns_update_
A boolean value which indicates that server takes responsibility for the forward DNS Update for this ...
Definition: alloc_engine.h:504
static std::string lifetimeToText(uint32_t lifetime)
Print lifetime.
Definition: lease.cc:29
@ TYPE_PD
the lease contains IPv6 prefix (for prefix delegation)
Definition: lease.h:53
@ TYPE_NA
the lease contains non-temporary IPv6 address
Definition: lease.h:51
Subnet selector used to specify parameters used to select a subnet.