Kea 2.0.1
dhcp6_srv.cc
Go to the documentation of this file.
1// Copyright (C) 2011-2021 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
982 // Use the RAII wrapper to make sure that the callout handle state is
983 // reset when this object goes out of scope. All hook points must do
984 // it to prevent possible circular dependency between the callout
985 // handle and its arguments.
986 ScopedCalloutHandleState callout_handle_state(callout_handle);
987
988 ScopedEnableOptionsCopy<Pkt6> query6_options_copy(query);
989
990 // Also pass the corresponding query packet as argument
991 callout_handle->setArgument("query6", query);
992
993 Lease6CollectionPtr new_leases(new Lease6Collection());
994 if (!ctx.new_leases_.empty()) {
995 // Filter out reused leases as they were not committed.
996 for (auto new_lease : ctx.new_leases_) {
997 if (new_lease->reuseable_valid_lft_ == 0) {
998 new_leases->push_back(new_lease);
999 }
1000 }
1001 }
1002 callout_handle->setArgument("leases6", new_leases);
1003
1004 Lease6CollectionPtr deleted_leases(new Lease6Collection());
1005
1006 // Do per IA lists
1007 for (auto const& iac : ctx.ias_) {
1008 if (!iac.old_leases_.empty()) {
1009 for (auto old_lease : iac.old_leases_) {
1010 if (ctx.new_leases_.empty()) {
1011 deleted_leases->push_back(old_lease);
1012 continue;
1013 }
1014 bool in_new = false;
1015 for (auto const& new_lease : ctx.new_leases_) {
1016 if ((new_lease->addr_ == old_lease->addr_) &&
1017 (new_lease->prefixlen_ == old_lease->prefixlen_)) {
1018 in_new = true;
1019 break;
1020 }
1021 }
1022 if (!in_new) {
1023 deleted_leases->push_back(old_lease);
1024 }
1025 }
1026 }
1027 }
1028 callout_handle->setArgument("deleted_leases6", deleted_leases);
1029
1030 // Get the parking limit. Parsing should ensure the value is present.
1031 uint32_t parked_packet_limit = 0;
1033 getCurrentCfg()->getConfiguredGlobal("parked-packet-limit");
1034 if (ppl) {
1035 parked_packet_limit = ppl->intValue();
1036 }
1037
1038 if (parked_packet_limit) {
1039 const auto& parking_lot = ServerHooks::getServerHooks().
1040 getParkingLotPtr("leases6_committed");
1041 if (parking_lot && (parking_lot->size() >= parked_packet_limit)) {
1042 // We can't park it so we're going to throw it on the floor.
1045 .arg(parked_packet_limit)
1046 .arg(query->getLabel());
1047 isc::stats::StatsMgr::instance().addValue("pkt6-receive-drop",
1048 static_cast<int64_t>(1));
1049 rsp.reset();
1050 return;
1051 }
1052 }
1053
1054 // We proactively park the packet. We'll unpark it without invoking
1055 // the callback (i.e. drop) unless the callout status is set to
1056 // NEXT_STEP_PARK. Otherwise the callback we bind here will be
1057 // executed when the hook library unparks the packet.
1058 HooksManager::park("leases6_committed", query,
1059 [this, callout_handle, query, rsp]() mutable {
1060 if (MultiThreadingMgr::instance().getMode()) {
1061 typedef function<void()> CallBack;
1062 boost::shared_ptr<CallBack> call_back =
1063 boost::make_shared<CallBack>(std::bind(&Dhcpv6Srv::sendResponseNoThrow,
1064 this, callout_handle, query, rsp));
1065 MultiThreadingMgr::instance().getThreadPool().add(call_back);
1066 } else {
1067 processPacketPktSend(callout_handle, query, rsp);
1068 processPacketBufferSend(callout_handle, rsp);
1069 }
1070 });
1071
1072 try {
1073 // Call all installed callouts
1074 HooksManager::callCallouts(Hooks.hook_index_leases6_committed_,
1075 *callout_handle);
1076 } catch (...) {
1077 // Make sure we don't orphan a parked packet.
1078 HooksManager::drop("leases4_committed", query);
1079 throw;
1080 }
1081
1082 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_PARK) {
1084 .arg(query->getLabel());
1085 // Since the hook library(ies) are going to do the unparking, then
1086 // reset the pointer to the response to indicate to the caller that
1087 // it should return, as the packet processing will continue via
1088 // the callback.
1089 rsp.reset();
1090 } else {
1091 // Drop the park job on the packet, it isn't needed.
1092 HooksManager::drop("leases6_committed", query);
1093 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP) {
1095 .arg(query->getLabel());
1096 rsp.reset();
1097 }
1098 }
1099 }
1100
1101 // If we have a response prep it for shipment.
1102 if (rsp) {
1103 processPacketPktSend(callout_handle, query, rsp);
1104 }
1105}
1106
1107void
1109 Pkt6Ptr& query, Pkt6Ptr& rsp) {
1110 try {
1111 processPacketPktSend(callout_handle, query, rsp);
1112 processPacketBufferSend(callout_handle, rsp);
1113 } catch (const std::exception& e) {
1115 .arg(e.what());
1116 } catch (...) {
1118 }
1119}
1120
1121void
1123 Pkt6Ptr& query, Pkt6Ptr& rsp) {
1124 if (!rsp) {
1125 return;
1126 }
1127
1128 // Specifies if server should do the packing
1129 bool skip_pack = false;
1130
1131 // Server's reply packet now has all options and fields set.
1132 // Options are represented by individual objects, but the
1133 // output wire data has not been prepared yet.
1134 // Execute all callouts registered for packet6_send
1135 if (HooksManager::calloutsPresent(Hooks.hook_index_pkt6_send_)) {
1136
1137 // Use the RAII wrapper to make sure that the callout handle state is
1138 // reset when this object goes out of scope. All hook points must do
1139 // it to prevent possible circular dependency between the callout
1140 // handle and its arguments.
1141 ScopedCalloutHandleState callout_handle_state(callout_handle);
1142
1143 // Enable copying options from the packets within hook library.
1144 ScopedEnableOptionsCopy<Pkt6> query_resp_options_copy(query, rsp);
1145
1146 // Pass incoming packet as argument
1147 callout_handle->setArgument("query6", query);
1148
1149 // Set our response
1150 callout_handle->setArgument("response6", rsp);
1151
1152 // Call all installed callouts
1153 HooksManager::callCallouts(Hooks.hook_index_pkt6_send_, *callout_handle);
1154
1155 // Callouts decided to skip the next processing step. The next
1156 // processing step would to pack the packet (create wire data).
1157 // That step will be skipped if any callout sets skip flag.
1158 // It essentially means that the callout already did packing,
1159 // so the server does not have to do it again.
1160 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) {
1162 .arg(rsp->getLabel());
1163 skip_pack = true;
1164 }
1165
1167 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP) {
1169 .arg(rsp->getLabel());
1170 rsp.reset();
1171 return;
1172 }
1173 }
1174
1175 if (!skip_pack) {
1176 try {
1177 rsp->pack();
1178 } catch (const std::exception& e) {
1180 return;
1181 }
1182
1183 }
1184}
1185
1186void
1188 Pkt6Ptr& rsp) {
1189 if (!rsp) {
1190 return;
1191 }
1192
1193 try {
1194 // Now all fields and options are constructed into output wire buffer.
1195 // Option objects modification does not make sense anymore. Hooks
1196 // can only manipulate wire buffer at this stage.
1197 // Let's execute all callouts registered for buffer6_send
1198 if (HooksManager::calloutsPresent(Hooks.hook_index_buffer6_send_)) {
1199
1200 // Use the RAII wrapper to make sure that the callout handle state is
1201 // reset when this object goes out of scope. All hook points must do
1202 // it to prevent possible circular dependency between the callout
1203 // handle and its arguments.
1204 ScopedCalloutHandleState callout_handle_state(callout_handle);
1205
1206 // Enable copying options from the packet within hook library.
1207 ScopedEnableOptionsCopy<Pkt6> response6_options_copy(rsp);
1208
1209 // Pass incoming packet as argument
1210 callout_handle->setArgument("response6", rsp);
1211
1212 // Call callouts
1213 HooksManager::callCallouts(Hooks.hook_index_buffer6_send_,
1214 *callout_handle);
1215
1216 // Callouts decided to skip the next processing step. The next
1217 // processing step would to parse the packet, so skip at this
1218 // stage means drop.
1219 if ((callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) ||
1220 (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP)) {
1223 .arg(rsp->getLabel());
1224 return;
1225 }
1226
1227 callout_handle->getArgument("response6", rsp);
1228 }
1229
1231 .arg(rsp->getLabel())
1232 .arg(rsp->getName())
1233 .arg(static_cast<int>(rsp->getType()))
1234 .arg(rsp->getLocalAddr().isV6Zero() ? "*" : rsp->getLocalAddr().toText())
1235 .arg(rsp->getLocalPort())
1236 .arg(rsp->getRemoteAddr())
1237 .arg(rsp->getRemotePort())
1238 .arg(rsp->getIface());
1239
1241 .arg(static_cast<int>(rsp->getType())).arg(rsp->toText());
1242
1243 sendPacket(rsp);
1244
1245 // Update statistics accordingly for sent packet.
1246 processStatsSent(rsp);
1247
1248 } catch (const std::exception& e) {
1250 }
1251}
1252
1253std::string
1255 stringstream tmp;
1256
1257 OptionBuffer data = opt->getData();
1258
1259 bool colon = false;
1260 for (OptionBufferConstIter it = data.begin(); it != data.end(); ++it) {
1261 if (colon) {
1262 tmp << ":";
1263 }
1264 tmp << hex << setw(2) << setfill('0') << static_cast<uint16_t>(*it);
1265 if (!colon) {
1266 colon = true;
1267 }
1268 }
1269
1270 return tmp.str();
1271}
1272
1273void
1275 // Add client-id.
1276 OptionPtr clientid = question->getOption(D6O_CLIENTID);
1277 if (clientid) {
1278 answer->addOption(clientid);
1279 }
1281
1282 // If this is a relayed message, we need to copy relay information
1283 if (!question->relay_info_.empty()) {
1284 answer->copyRelayInfo(question);
1285 }
1286
1287}
1288
1289void
1291 const CfgOptionList&) {
1292 // add server-id
1293 answer->addOption(getServerID());
1294}
1295
1296void
1299 CfgOptionList& co_list) {
1300 // Firstly, host specific options.
1301 if (ctx.currentHost() && !ctx.currentHost()->getCfgOption6()->empty()) {
1302 co_list.push_back(ctx.currentHost()->getCfgOption6());
1303 }
1304
1305 // Secondly, pool specific options. Pools are defined within a subnet, so
1306 // if there is no subnet, there is nothing to do.
1307 if (ctx.subnet_) {
1308 for (auto resource : ctx.allocated_resources_) {
1309 PoolPtr pool =
1310 ctx.subnet_->getPool(resource.getPrefixLength() == 128 ?
1312 resource.getAddress(),
1313 false);
1314 if (pool && !pool->getCfgOption()->empty()) {
1315 co_list.push_back(pool->getCfgOption());
1316 }
1317 }
1318 };
1319
1320 if (ctx.subnet_) {
1321 // Next, subnet configured options.
1322 if (!ctx.subnet_->getCfgOption()->empty()) {
1323 co_list.push_back(ctx.subnet_->getCfgOption());
1324 }
1325
1326 // Then, shared network specific options.
1327 SharedNetwork6Ptr network;
1328 ctx.subnet_->getSharedNetwork(network);
1329 if (network && !network->getCfgOption()->empty()) {
1330 co_list.push_back(network->getCfgOption());
1331 }
1332 }
1333
1334 // Each class in the incoming packet
1335 const ClientClasses& classes = question->getClasses();
1336 for (ClientClasses::const_iterator cclass = classes.cbegin();
1337 cclass != classes.cend(); ++cclass) {
1338 // Find the client class definition for this class
1340 getClientClassDictionary()->findClass(*cclass);
1341 if (!ccdef) {
1342 // Not found: the class is built-in or not configured
1343 if (!isClientClassBuiltIn(*cclass)) {
1345 .arg(question->getLabel())
1346 .arg(*cclass);
1347 }
1348 // Skip it
1349 continue;
1350 }
1351
1352 if (ccdef->getCfgOption()->empty()) {
1353 // Skip classes which don't configure options
1354 continue;
1355 }
1356
1357 co_list.push_back(ccdef->getCfgOption());
1358 }
1359
1360 // Last global options
1361 if (!CfgMgr::instance().getCurrentCfg()->getCfgOption()->empty()) {
1362 co_list.push_back(CfgMgr::instance().getCurrentCfg()->getCfgOption());
1363 }
1364}
1365
1366void
1368 const CfgOptionList& co_list) {
1369
1370 // Unlikely short cut
1371 if (co_list.empty()) {
1372 return;
1373 }
1374
1375 std::vector<uint16_t> requested_opts;
1376
1377 // Client requests some options using ORO option. Try to
1378 // get this option from client's message.
1379 boost::shared_ptr<OptionIntArray<uint16_t> > option_oro =
1380 boost::dynamic_pointer_cast<OptionIntArray<uint16_t> >
1381 (question->getOption(D6O_ORO));
1382
1383 // Get the list of options that client requested.
1384 if (option_oro) {
1385 requested_opts = option_oro->getValues();
1386 }
1387 // Iterate on the configured option list to add persistent options
1388 for (CfgOptionList::const_iterator copts = co_list.begin();
1389 copts != co_list.end(); ++copts) {
1390 const OptionContainerPtr& opts = (*copts)->getAll(DHCP6_OPTION_SPACE);
1391 if (!opts) {
1392 continue;
1393 }
1394 // Get persistent options
1395 const OptionContainerPersistIndex& idx = opts->get<2>();
1396 const OptionContainerPersistRange& range = idx.equal_range(true);
1397 for (OptionContainerPersistIndex::const_iterator desc = range.first;
1398 desc != range.second; ++desc) {
1399 // Add the persistent option code to requested options
1400 if (desc->option_) {
1401 requested_opts.push_back(desc->option_->getType());
1402 }
1403 }
1404 }
1405
1406 for (uint16_t opt : requested_opts) {
1407 // Add nothing when it is already there.
1408 if (!answer->getOption(opt)) {
1409 // Iterate on the configured option list
1410 for (CfgOptionList::const_iterator copts = co_list.begin();
1411 copts != co_list.end(); ++copts) {
1412 OptionDescriptor desc = (*copts)->get(DHCP6_OPTION_SPACE, opt);
1413 // Got it: add it and jump to the outer loop
1414 if (desc.option_) {
1415 answer->addOption(desc.option_);
1416 break;
1417 }
1418 }
1419 }
1420 }
1421}
1422
1423void
1425 Pkt6Ptr& answer,
1427 const CfgOptionList& co_list) {
1428
1429 // Leave if there is no subnet matching the incoming packet.
1430 // There is no need to log the error message here because
1431 // it will be logged in the assignLease() when it fails to
1432 // pick the suitable subnet. We don't want to duplicate
1433 // error messages in such case.
1434 //
1435 // Also, if there's no options to possibly assign, give up.
1436 if (!ctx.subnet_ || co_list.empty()) {
1437 return;
1438 }
1439
1440 uint32_t vendor_id = 0;
1441
1442 // The server could have provided the option using client classification or
1443 // hooks. If there's a vendor info option in the response already, use that.
1444 OptionVendorPtr vendor_rsp(boost::dynamic_pointer_cast<OptionVendor>(
1445 answer->getOption(D6O_VENDOR_OPTS)));
1446 if (vendor_rsp) {
1447 vendor_id = vendor_rsp->getVendorId();
1448 }
1449
1450 // Otherwise, try to get the vendor-id from the client packet's
1451 // vendor-specific information option (17).
1452 OptionVendorPtr vendor_req;
1453 if (vendor_id == 0) {
1454 vendor_req = boost::dynamic_pointer_cast<OptionVendor>(
1455 question->getOption(D6O_VENDOR_OPTS));
1456 if (vendor_req) {
1457 vendor_id = vendor_req->getVendorId();
1458 }
1459 }
1460
1461 // Finally, try to get the vendor-id from the client packet's vendor-class
1462 // option (16).
1463 if (vendor_id == 0) {
1464 OptionVendorClassPtr vendor_class(
1465 boost::dynamic_pointer_cast<OptionVendorClass>(
1466 question->getOption(D6O_VENDOR_CLASS)));
1467 if (vendor_class) {
1468 vendor_id = vendor_class->getVendorId();
1469 }
1470 }
1471
1472 // If there's no vendor option in either request or response, then there's no way
1473 // to figure out what the vendor-id value is and we give up.
1474 if (vendor_id == 0) {
1475 return;
1476 }
1477
1478 std::vector<uint16_t> requested_opts;
1479
1480 // Let's try to get ORO within that vendor-option.
1481 // This is specific to vendor-id=4491 (Cable Labs). Other vendors may have
1482 // different policies.
1484 if (vendor_id == VENDOR_ID_CABLE_LABS && vendor_req) {
1485 OptionPtr oro_generic = vendor_req->getOption(DOCSIS3_V6_ORO);
1486 if (oro_generic) {
1487 // Vendor ID 4491 makes Kea look at DOCSIS3_V6_OPTION_DEFINITIONS
1488 // when parsing options. Based on that, oro_generic will have been
1489 // created as an OptionUint16Array, but might not be for other
1490 // vendor IDs.
1491 oro = boost::dynamic_pointer_cast<OptionUint16Array>(oro_generic);
1492 if (oro) {
1493 requested_opts = oro->getValues();
1494 }
1495 }
1496 }
1497
1498 // Iterate on the configured option list to add persistent options
1499 for (CfgOptionList::const_iterator copts = co_list.begin();
1500 copts != co_list.end(); ++copts) {
1501 const OptionContainerPtr& opts = (*copts)->getAll(vendor_id);
1502 if (!opts) {
1503 continue;
1504 }
1505 // Get persistent options
1506 const OptionContainerPersistIndex& idx = opts->get<2>();
1507 const OptionContainerPersistRange& range = idx.equal_range(true);
1508 for (OptionContainerPersistIndex::const_iterator desc = range.first;
1509 desc != range.second; ++desc) {
1510 // Add the persistent option code to requested options
1511 if (desc->option_) {
1512 requested_opts.push_back(desc->option_->getType());
1513 }
1514 }
1515 }
1516
1517 // If there is nothing to add don't do anything then.
1518 if (requested_opts.empty()) {
1519 return;
1520 }
1521
1522 if (!vendor_rsp) {
1523 // It's possible that the vendor opts option was inserted already
1524 // by client class or a hook. If that is so, let's use it.
1525 vendor_rsp.reset(new OptionVendor(Option::V6, vendor_id));
1526 }
1527
1528 // Get the list of options that client requested.
1529 bool added = false;
1530
1531 for (uint16_t opt : requested_opts) {
1532 if (!vendor_rsp->getOption(opt)) {
1533 for (CfgOptionList::const_iterator copts = co_list.begin();
1534 copts != co_list.end(); ++copts) {
1535 OptionDescriptor desc = (*copts)->get(vendor_id, opt);
1536 if (desc.option_) {
1537 vendor_rsp->addOption(desc.option_);
1538 added = true;
1539 break;
1540 }
1541 }
1542 }
1543 }
1544
1545 // If we added some sub-options and the vendor opts option is not in
1546 // the response already, then add it.
1547 if (added && !answer->getOption(D6O_VENDOR_OPTS)) {
1548 answer->addOption(vendor_rsp);
1549 }
1550}
1551
1552bool
1554 try {
1555 switch (pkt->getType()) {
1556 case DHCPV6_SOLICIT:
1557 case DHCPV6_REBIND:
1558 case DHCPV6_CONFIRM:
1560 return (true);
1561
1562 case DHCPV6_REQUEST:
1563 case DHCPV6_RENEW:
1564 case DHCPV6_RELEASE:
1565 case DHCPV6_DECLINE:
1567 return (true);
1568
1572 return (true);
1573
1574 default:
1577 .arg(static_cast<int>(pkt->getType()))
1578 .arg(pkt->getIface());
1579 }
1580
1581 } catch (const RFCViolation& e) {
1583 .arg(pkt->getName())
1584 .arg(pkt->getRemoteAddr().toText())
1585 .arg(e.what());
1586
1587 }
1588
1589 // Increase the statistic of dropped packets.
1590 StatsMgr::instance().addValue("pkt6-receive-drop", static_cast<int64_t>(1));
1591 return (false);
1592}
1593
1594void
1596 RequirementLevel serverid) {
1597 OptionCollection client_ids = pkt->getOptions(D6O_CLIENTID);
1598 switch (clientid) {
1599 case MANDATORY: {
1600 if (client_ids.size() != 1) {
1601 isc_throw(RFCViolation, "Exactly 1 client-id option expected in "
1602 << pkt->getName() << ", but " << client_ids.size()
1603 << " received");
1604 }
1605 sanityCheckDUID(client_ids.begin()->second, "client-id");
1606 break;
1607 }
1608 case OPTIONAL:
1609 if (client_ids.size() > 1) {
1610 isc_throw(RFCViolation, "Too many (" << client_ids.size()
1611 << ") client-id options received in " << pkt->getName());
1612 }
1613 if (!client_ids.empty()) {
1614 sanityCheckDUID(client_ids.begin()->second, "client-id");
1615 }
1616 break;
1617
1618 case FORBIDDEN:
1619 // doesn't make sense - client-id is always allowed
1620 break;
1621 }
1622
1623 OptionCollection server_ids = pkt->getOptions(D6O_SERVERID);
1624 switch (serverid) {
1625 case FORBIDDEN:
1626 if (!server_ids.empty()) {
1627 isc_throw(RFCViolation, "Server-id option was not expected, but "
1628 << server_ids.size() << " received in " << pkt->getName());
1629 }
1630 break;
1631
1632 case MANDATORY:
1633 if (server_ids.size() != 1) {
1634 isc_throw(RFCViolation, "Invalid number of server-id options received ("
1635 << server_ids.size() << "), exactly 1 expected in message "
1636 << pkt->getName());
1637 }
1638 sanityCheckDUID(server_ids.begin()->second, "server-id");
1639 break;
1640
1641 case OPTIONAL:
1642 if (server_ids.size() > 1) {
1643 isc_throw(RFCViolation, "Too many (" << server_ids.size()
1644 << ") server-id options received in " << pkt->getName());
1645 }
1646 if (!server_ids.empty()) {
1647 sanityCheckDUID(server_ids.begin()->second, "server-id");
1648 }
1649 }
1650}
1651
1652void Dhcpv6Srv::sanityCheckDUID(const OptionPtr& opt, const std::string& opt_name) {
1653 if (!opt) {
1654 isc_throw(RFCViolation, "Unable to find expected option " << opt_name);
1655 }
1656
1657 // The client-id or server-id has to have at least 3 bytes of useful data:
1658 // two for duid type and one more for actual duid value.
1659 uint16_t len = opt->len() - opt->getHeaderLen();
1660 if (len < 3 || len > DUID::MAX_DUID_LEN || opt->getData().empty()) {
1661 isc_throw(RFCViolation, "Received invalid DUID for " << opt_name << ", received "
1662 << len << " byte(s). It must be at least 3 and no more than "
1664 }
1665}
1666
1668Dhcpv6Srv::selectSubnet(const Pkt6Ptr& question, bool& drop) {
1669 const SubnetSelector& selector = CfgSubnets6::initSelector(question);
1670
1672 getCfgSubnets6()->selectSubnet(selector);
1673
1674 // Let's execute all callouts registered for subnet6_receive
1675 if (HooksManager::calloutsPresent(Hooks.hook_index_subnet6_select_)) {
1676 CalloutHandlePtr callout_handle = getCalloutHandle(question);
1677
1678 // Use the RAII wrapper to make sure that the callout handle state is
1679 // reset when this object goes out of scope. All hook points must do
1680 // it to prevent possible circular dependency between the callout
1681 // handle and its arguments.
1682 ScopedCalloutHandleState callout_handle_state(callout_handle);
1683
1684 // Enable copying options from the packet within hook library.
1685 ScopedEnableOptionsCopy<Pkt6> query6_options_copy(question);
1686
1687 // Set new arguments
1688 callout_handle->setArgument("query6", question);
1689 callout_handle->setArgument("subnet6", subnet);
1690
1691 // We pass pointer to const collection for performance reasons.
1692 // Otherwise we would get a non-trivial performance penalty each
1693 // time subnet6_select is called.
1694 callout_handle->setArgument("subnet6collection",
1695 CfgMgr::instance().getCurrentCfg()->
1696 getCfgSubnets6()->getAll());
1697
1698 // Call user (and server-side) callouts
1699 HooksManager::callCallouts(Hooks.hook_index_subnet6_select_, *callout_handle);
1700
1701 // Callouts decided to skip this step. This means that no
1702 // subnet will be selected. Packet processing will continue,
1703 // but it will be severely limited (i.e. only global options
1704 // will be assigned)
1705 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) {
1707 .arg(question->getLabel());
1708 return (Subnet6Ptr());
1709 }
1710
1711 // Callouts decided to drop the packet. It is a superset of the
1712 // skip case so no subnet will be selected.
1713 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP) {
1715 .arg(question->getLabel());
1716 drop = true;
1717 return (Subnet6Ptr());
1718 }
1719
1720 // Use whatever subnet was specified by the callout
1721 callout_handle->getArgument("subnet6", subnet);
1722 }
1723
1724 if (subnet) {
1725 // Log at higher debug level that subnet has been found.
1727 .arg(question->getLabel())
1728 .arg(subnet->getID());
1729 // Log detailed information about the selected subnet at the
1730 // lower debug level.
1732 .arg(question->getLabel())
1733 .arg(subnet->toText());
1734
1735 } else {
1737 .arg(question->getLabel());
1738 }
1739
1740 return (subnet);
1741}
1742
1743void
1744Dhcpv6Srv::assignLeases(const Pkt6Ptr& question, Pkt6Ptr& answer,
1746 // Save the originally selected subnet.
1747 Subnet6Ptr orig_subnet = ctx.subnet_;
1748
1749 // We need to allocate addresses for all IA_NA options in the client's
1750 // question (i.e. SOLICIT or REQUEST) message.
1751 // @todo add support for IA_TA
1752
1753 // For the lease allocation it is critical that the client has sent
1754 // DUID. There is no need to check for the presence of the DUID here
1755 // because we have already checked it in the sanityCheck().
1756
1757 // Now that we have all information about the client, let's iterate over all
1758 // received options and handle IA_NA options one by one and store our
1759 // responses in answer message (ADVERTISE or REPLY).
1760 //
1761 // @todo: IA_TA once we implement support for temporary addresses.
1762 for (OptionCollection::iterator opt = question->options_.begin();
1763 opt != question->options_.end(); ++opt) {
1764 switch (opt->second->getType()) {
1765 case D6O_IA_NA: {
1766 OptionPtr answer_opt = assignIA_NA(question, ctx,
1767 boost::dynamic_pointer_cast<
1768 Option6IA>(opt->second));
1769 if (answer_opt) {
1770 answer->addOption(answer_opt);
1771 }
1772 break;
1773 }
1774 case D6O_IA_PD: {
1775 OptionPtr answer_opt = assignIA_PD(question, ctx,
1776 boost::dynamic_pointer_cast<
1777 Option6IA>(opt->second));
1778 if (answer_opt) {
1779 answer->addOption(answer_opt);
1780 }
1781 break;
1782 }
1783 default:
1784 break;
1785 }
1786 }
1787
1788 // Subnet may be modified by the allocation engine, there are things
1789 // we need to do when that happens.
1790 checkDynamicSubnetChange(question, answer, ctx, orig_subnet);
1791}
1792
1793void
1794Dhcpv6Srv::processClientFqdn(const Pkt6Ptr& question, const Pkt6Ptr& answer,
1797 DdnsParamsPtr ddns_params = ctx.getDdnsParams();
1798
1799 // Get Client FQDN Option from the client's message. If this option hasn't
1800 // been included, do nothing.
1801 Option6ClientFqdnPtr fqdn = boost::dynamic_pointer_cast<
1802 Option6ClientFqdn>(question->getOption(D6O_CLIENT_FQDN));
1803 if (!fqdn) {
1804 if (ddns_params->getEnableUpdates() &&
1805 (ddns_params->getReplaceClientNameMode() == D2ClientConfig::RCM_ALWAYS ||
1806 ddns_params->getReplaceClientNameMode() == D2ClientConfig::RCM_WHEN_NOT_PRESENT)) {
1807 // Fabricate an empty "client" FQDN with flags requesting
1808 // the server do all the updates. The flags will get modified
1809 // below according the configuration options, the name will
1810 // be supplied later on.
1814 .arg(question->getLabel());
1815 } else {
1816 // No FQDN so get the lease hostname from the host reservation if
1817 // there is one.
1818 if (ctx.currentHost()) {
1819 ctx.hostname_ = ctx.currentHost()->getHostname();
1820 }
1821
1822 return;
1823 }
1824 }
1825
1827 .arg(question->getLabel())
1828 .arg(fqdn->toText());
1829
1830 // Create the DHCPv6 Client FQDN Option to be included in the server's
1831 // response to a client.
1832 Option6ClientFqdnPtr fqdn_resp(new Option6ClientFqdn(*fqdn));
1833
1834 // Set the server S, N, and O flags based on client's flags and
1835 // current configuration.
1836 d2_mgr.adjustFqdnFlags<Option6ClientFqdn>(*fqdn, *fqdn_resp, *ddns_params);
1837
1838 // Get DDNS update direction flags
1840 ctx.rev_dns_update_);
1841
1842 // If there's a reservation and it has a hostname specified, use it!
1843 if (ctx.currentHost() && !ctx.currentHost()->getHostname().empty()) {
1844 // Add the qualifying suffix.
1845 // After #3765, this will only occur if the suffix is not empty.
1846 fqdn_resp->setDomainName(d2_mgr.qualifyName(ctx.currentHost()->getHostname(),
1847 *ddns_params, true),
1849 } else {
1850 // Adjust the domain name based on domain name value and type sent by
1851 // the client and current configuration.
1852 d2_mgr.adjustDomainName<Option6ClientFqdn>(*fqdn, *fqdn_resp, *ddns_params);
1853 }
1854
1855 // Once we have the FQDN setup to use it for the lease hostname. This
1856 // only gets replaced later if the FQDN is to be generated from the address.
1857 ctx.hostname_ = fqdn_resp->getDomainName();
1858
1859 // The FQDN has been processed successfully. Let's append it to the
1860 // response to be sent to a client. Note that the Client FQDN option is
1861 // always sent back to the client if Client FQDN was included in the
1862 // client's message.
1864 .arg(question->getLabel())
1865 .arg(fqdn_resp->toText());
1866 answer->addOption(fqdn_resp);
1867}
1868
1869void
1872 // Don't create NameChangeRequests if DNS updates are disabled.
1873 if (!(ctx.getDdnsParams()->getEnableUpdates())) {
1874 return;
1875 }
1876
1877 // The response message instance is always required. For instance it
1878 // holds the Client Identifier. It is a programming error if supplied
1879 // message is NULL.
1880 if (!answer) {
1881 isc_throw(isc::Unexpected, "an instance of the object"
1882 << " encapsulating server's message must not be"
1883 << " NULL when creating DNS NameChangeRequest");
1884 }
1885
1886 // It is likely that client haven't included the FQDN option. In such case,
1887 // FQDN option will be NULL. This is valid state, so we simply return.
1888 Option6ClientFqdnPtr opt_fqdn = boost::dynamic_pointer_cast<
1889 Option6ClientFqdn>(answer->getOption(D6O_CLIENT_FQDN));
1890 if (!opt_fqdn) {
1891 return;
1892 }
1893
1894 // Get the update directions that should be performed based on our
1895 // response FQDN flags.
1896 bool do_fwd = false;
1897 bool do_rev = false;
1899 do_fwd, do_rev);
1900
1901 // Get the Client Id. It is mandatory and a function creating a response
1902 // would have thrown an exception if it was missing. Thus throwing
1903 // Unexpected if it is missing as it is a programming error.
1904 OptionPtr opt_duid = answer->getOption(D6O_CLIENTID);
1905 if (!opt_duid) {
1907 "client identifier is required when creating a new"
1908 " DNS NameChangeRequest");
1909 }
1910 DuidPtr duid = DuidPtr(new DUID(opt_duid->getData()));
1911
1912 // Get the FQDN in the on-wire format. It will be needed to compute
1913 // DHCID.
1914 OutputBuffer name_buf(1);
1915 opt_fqdn->packDomainName(name_buf);
1916 const uint8_t* name_data = static_cast<const uint8_t*>(name_buf.getData());
1917 // @todo currently D2Dhcid accepts a vector holding FQDN.
1918 // However, it will be faster if we used a pointer name_data.
1919 std::vector<uint8_t> buf_vec(name_data, name_data + name_buf.getLength());
1920 // Compute DHCID from Client Identifier and FQDN.
1921 isc::dhcp_ddns::D2Dhcid dhcid(*duid, buf_vec);
1922
1923 // Get all IAs from the answer. For each IA, holding an address we will
1924 // create a corresponding NameChangeRequest.
1925 for (auto answer_ia : answer->getOptions(D6O_IA_NA)) {
1928 Option6IAAddrPtr iaaddr = boost::static_pointer_cast<
1929 Option6IAAddr>(answer_ia.second->getOption(D6O_IAADDR));
1930
1931 // We need an address to create a name-to-address mapping.
1932 // If address is missing for any reason, go to the next IA.
1933 if (!iaaddr) {
1934 continue;
1935 }
1936
1937 // If the lease for iaaddr is in the list of changed leases, we need
1938 // to determine if the changes included changes to the FQDN. If so
1939 // then we may need to do a CHG_REMOVE.
1940 bool extended_only = false;
1941 for (Lease6Collection::const_iterator l = ctx.currentIA().changed_leases_.begin();
1942 l != ctx.currentIA().changed_leases_.end(); ++l) {
1943
1944 if ((*l)->addr_ == iaaddr->getAddress()) {
1945 // The address is the same so this must be renewal. If we're not
1946 // always updating on renew, then we only renew if DNS info has
1947 // changed.
1948 if (!ctx.getDdnsParams()->getUpdateOnRenew() &&
1949 ((*l)->hostname_ == opt_fqdn->getDomainName() &&
1950 (*l)->fqdn_fwd_ == do_fwd && (*l)->fqdn_rev_ == do_rev)) {
1951 extended_only = true;
1952 } else {
1953 // Queue a CHG_REMOVE of the old data.
1954 // NCR will only be created if the lease hostname is not
1955 // empty and at least one of the direction flags is true
1956 queueNCR(CHG_REMOVE, *l);
1957 }
1958
1959 break;
1960 }
1961 }
1962
1963 if (!(do_fwd || do_rev) || (extended_only)) {
1964 // Flags indicate no updates needed or it was an extension of
1965 // an existing lease with no FQDN changes. In the case of the
1966 // former, the most likely scenario is that we are honoring the
1967 // client's request that no updates be done.
1968 continue;
1969 }
1970
1971 // Create new NameChangeRequest. Use the domain name from the FQDN.
1972 // This is an FQDN included in the response to the client, so it
1973 // holds a fully qualified domain-name already (not partial).
1974 // Get the IP address from the lease.
1977 do_fwd, do_rev,
1978 opt_fqdn->getDomainName(),
1979 iaaddr->getAddress().toText(),
1980 dhcid, 0, calculateDdnsTtl(iaaddr->getValid()),
1981 ctx.getDdnsParams()->getUseConflictResolution()));
1984
1985 // Post the NCR to the D2ClientMgr.
1987
1992 return;
1993 }
1994}
1995
1998 CfgMACSources mac_sources = CfgMgr::instance().getCurrentCfg()->
1999 getMACSources().get();
2000 HWAddrPtr hwaddr;
2001 for (CfgMACSources::const_iterator it = mac_sources.begin();
2002 it != mac_sources.end(); ++it) {
2003 hwaddr = pkt->getMAC(*it);
2004 if (hwaddr) {
2005 return (hwaddr);
2006 }
2007 }
2008 return (hwaddr);
2009}
2010
2014 boost::shared_ptr<Option6IA> ia) {
2015
2016 // Check if the client sent us a hint in his IA_NA. Clients may send an
2017 // address in their IA_NA options as a suggestion (e.g. the last address
2018 // they used before).
2019 Option6IAAddrPtr hint_opt =
2020 boost::dynamic_pointer_cast<Option6IAAddr>(ia->getOption(D6O_IAADDR));
2022 if (hint_opt) {
2023 hint = hint_opt->getAddress();
2024 }
2025
2027 .arg(query->getLabel())
2028 .arg(ia->getIAID())
2029 .arg(hint_opt ? hint.toText() : "(no hint)");
2030
2031 // convenience values
2032 const Subnet6Ptr& subnet = ctx.subnet_;
2033
2034 // If there is no subnet selected for handling this IA_NA, the only thing left to do is
2035 // to say that we are sorry, but the user won't get an address. As a convenience, we
2036 // use a different status text to indicate that (compare to the same status code,
2037 // but different wording below)
2038 if (!subnet) {
2039 // Create an empty IA_NA option with IAID matching the request.
2040 // Note that we don't use OptionDefinition class to create this option.
2041 // This is because we prefer using a constructor of Option6IA that
2042 // initializes IAID. Otherwise we would have to use setIAID() after
2043 // creation of the option which has some performance implications.
2044 boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
2045
2046 // Insert status code NoAddrsAvail.
2047 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoAddrsAvail,
2048 "Server could not select subnet for"
2049 " this client"));
2050 return (ia_rsp);
2051 }
2052
2053 // Set per-IA context values.
2054 ctx.createIAContext();
2055 ctx.currentIA().iaid_ = ia->getIAID();
2056 if (hint_opt) {
2057 ctx.currentIA().addHint(hint_opt);
2058 } else {
2059 ctx.currentIA().addHint(hint);
2060 }
2062
2063 // Use allocation engine to pick a lease for this client. Allocation engine
2064 // will try to honor the hint, but it is just a hint - some other address
2065 // may be used instead. If fake_allocation is set to false, the lease will
2066 // be inserted into the LeaseMgr as well.
2067 Lease6Collection leases = alloc_engine_->allocateLeases6(ctx);
2068
2070 Lease6Ptr lease;
2071 if (!leases.empty()) {
2072 lease = *leases.begin();
2073 }
2074
2075 // Create IA_NA that we will put in the response.
2076 // Do not use OptionDefinition to create option's instance so
2077 // as we can initialize IAID using a constructor.
2078 Option6IAPtr ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
2079
2080 if (lease) {
2081 // We have a lease! Let's wrap its content into IA_NA option
2082 // with IAADDR suboption.
2083 if (ctx.fake_allocation_) {
2085 .arg(query->getLabel())
2086 .arg(lease->addr_.toText())
2087 .arg(ia->getIAID());
2088 } else if (lease->reuseable_valid_lft_ == 0) {
2090 .arg(query->getLabel())
2091 .arg(lease->addr_.toText())
2092 .arg(ia->getIAID())
2093 .arg(Lease::lifetimeToText(lease->valid_lft_));
2094 } else {
2095 lease->valid_lft_ = lease->reuseable_valid_lft_;
2096 lease->preferred_lft_ = lease->reuseable_preferred_lft_;
2098 .arg(query->getLabel())
2099 .arg(lease->addr_.toText())
2100 .arg(ia->getIAID())
2101 .arg(Lease::lifetimeToText(lease->valid_lft_));
2102 }
2104 .arg(query->getLabel())
2105 .arg(ia->getIAID())
2106 .arg(lease->toText());
2107
2108 // Set the values for T1 and T2.
2109 setTeeTimes(lease->preferred_lft_, subnet, ia_rsp);
2110
2111 Option6IAAddrPtr addr(new Option6IAAddr(D6O_IAADDR, lease->addr_,
2112 lease->preferred_lft_,
2113 lease->valid_lft_));
2114 ia_rsp->addOption(addr);
2115
2116 // It would be possible to insert status code=0(success) as well,
2117 // but this is considered waste of bandwidth as absence of status
2118 // code is considered a success.
2119
2120 } else {
2121 // Allocation engine did not allocate a lease. The engine logged
2122 // cause of that failure. The only thing left is to insert
2123 // status code to pass the sad news to the client.
2124
2127 .arg(query->getLabel())
2128 .arg(ia->getIAID());
2129
2130 ia_rsp->addOption(createStatusCode(*query, *ia_rsp,
2132 "Sorry, no address could be"
2133 " allocated."));
2134 }
2135 return (ia_rsp);
2136}
2137
2141 boost::shared_ptr<Option6IA> ia) {
2142
2143 // Check if the client sent us a hint in his IA_PD. Clients may send an
2144 // address in their IA_PD options as a suggestion (e.g. the last address
2145 // they used before). While the hint consists of a full prefix (prefix +
2146 // length), getting just the prefix is sufficient to identify a lease.
2147 Option6IAPrefixPtr hint_opt =
2148 boost::dynamic_pointer_cast<Option6IAPrefix>(ia->getOption(D6O_IAPREFIX));
2150 if (hint_opt) {
2151 hint = hint_opt->getAddress();
2152 }
2153
2155 .arg(query->getLabel())
2156 .arg(ia->getIAID())
2157 .arg(hint_opt ? hint.toText() : "(no hint)");
2158
2159 const Subnet6Ptr& subnet = ctx.subnet_;
2160
2161 // Create IA_PD that we will put in the response.
2162 // Do not use OptionDefinition to create option's instance so
2163 // as we can initialize IAID using a constructor.
2164 boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_PD, ia->getIAID()));
2165
2166 // If there is no subnet selected for handling this IA_PD, the only thing
2167 // left to do is to say that we are sorry, but the user won't get an address.
2168 // As a convenience, we use a different status text to indicate that
2169 // (compare to the same status code, but different wording below)
2170 if (!subnet) {
2171
2172 // Insert status code NoAddrsAvail.
2173 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoPrefixAvail,
2174 "Sorry, no subnet available."));
2175 return (ia_rsp);
2176 }
2177
2178 // Set per-IA context values.
2179 ctx.createIAContext();
2180 ctx.currentIA().iaid_ = ia->getIAID();
2181 if (hint_opt) {
2182 ctx.currentIA().addHint(hint_opt);
2183 } else {
2184 ctx.currentIA().addHint(hint);
2185 }
2187
2188 // Use allocation engine to pick a lease for this client. Allocation engine
2189 // will try to honor the hint, but it is just a hint - some other address
2190 // may be used instead. If fake_allocation is set to false, the lease will
2191 // be inserted into the LeaseMgr as well.
2192 Lease6Collection leases = alloc_engine_->allocateLeases6(ctx);
2193
2194 if (!leases.empty()) {
2195
2196 // Need to retain the shortest preferred lease time to use
2197 // for calculating T1 and T2.
2198 uint32_t min_preferred_lft = (*leases.begin())->preferred_lft_;
2199
2200 const bool pd_exclude_requested = requestedInORO(query, D6O_PD_EXCLUDE);
2201 for (Lease6Collection::iterator l = leases.begin();
2202 l != leases.end(); ++l) {
2203
2204 // We have a lease! Let's wrap its content into IA_PD option
2205 // with IAADDR suboption.
2206 if (ctx.fake_allocation_) {
2208 .arg(query->getLabel())
2209 .arg((*l)->addr_.toText())
2210 .arg(static_cast<int>((*l)->prefixlen_))
2211 .arg(ia->getIAID());
2212 } else if ((*l)->reuseable_valid_lft_ == 0) {
2214 .arg(query->getLabel())
2215 .arg((*l)->addr_.toText())
2216 .arg(static_cast<int>((*l)->prefixlen_))
2217 .arg(ia->getIAID())
2218 .arg(Lease::lifetimeToText((*l)->valid_lft_));
2219 } else {
2220 (*l)->valid_lft_ = (*l)->reuseable_valid_lft_;
2221 (*l)->preferred_lft_ = (*l)->reuseable_preferred_lft_;
2223 .arg(query->getLabel())
2224 .arg((*l)->addr_.toText())
2225 .arg(static_cast<int>((*l)->prefixlen_))
2226 .arg(ia->getIAID())
2227 .arg(Lease::lifetimeToText((*l)->valid_lft_));
2228 }
2229
2230 // Check for new minimum lease time
2231 if (((*l)->preferred_lft_ > 0) && (min_preferred_lft > (*l)->preferred_lft_)) {
2232 min_preferred_lft = (*l)->preferred_lft_;
2233 }
2234
2235 boost::shared_ptr<Option6IAPrefix>
2236 addr(new Option6IAPrefix(D6O_IAPREFIX, (*l)->addr_,
2237 (*l)->prefixlen_, (*l)->preferred_lft_,
2238 (*l)->valid_lft_));
2239 ia_rsp->addOption(addr);
2240
2241 if (pd_exclude_requested) {
2242 // PD exclude option has been requested via ORO, thus we need to
2243 // include it if the pool configuration specifies this option.
2244 Pool6Ptr pool = boost::dynamic_pointer_cast<
2245 Pool6>(subnet->getPool(Lease::TYPE_PD, (*l)->addr_));
2246 if (pool) {
2247 Option6PDExcludePtr pd_exclude_option = pool->getPrefixExcludeOption();
2248 if (pd_exclude_option) {
2249 addr->addOption(pd_exclude_option);
2250 }
2251 }
2252 }
2253 }
2254
2255 // Set T1 and T2, using the shortest preferred lifetime among the leases.
2256 setTeeTimes(min_preferred_lft, subnet, ia_rsp);
2257
2258 // It would be possible to insert status code=0(success) as well,
2259 // but this is considered waste of bandwidth as absence of status
2260 // code is considered a success.
2261
2262 } else {
2263 // Allocation engine did not allocate a lease. The engine logged
2264 // cause of that failure. The only thing left is to insert
2265 // status code to pass the sad news to the client.
2266
2269 .arg(query->getLabel())
2270 .arg(ia->getIAID());
2271
2272 ia_rsp->addOption(createStatusCode(*query, *ia_rsp,
2274 "Sorry, no prefixes could"
2275 " be allocated."));
2276 }
2277 return (ia_rsp);
2278}
2279
2283 boost::shared_ptr<Option6IA> ia) {
2284
2286 .arg(query->getLabel())
2287 .arg(ia->getIAID());
2288
2289 // convenience values
2290 const Subnet6Ptr& subnet = ctx.subnet_;
2291
2292 // Create empty IA_NA option with IAID matching the request.
2293 Option6IAPtr ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
2294
2295 if (!subnet) {
2305 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
2306 "Sorry, no known leases for this duid/iaid."));
2307 return (ia_rsp);
2308 }
2309
2310 // Set per-IA context values.
2311 ctx.createIAContext();
2312 ctx.currentIA().iaid_ = ia->getIAID();
2314 ctx.currentIA().ia_rsp_ = ia_rsp;
2315
2316 // Extract the addresses that the client is trying to obtain.
2317 OptionCollection addrs = ia->getOptions();
2318 for (OptionCollection::const_iterator it = addrs.begin();
2319 it != addrs.end(); ++it) {
2320 if (it->second->getType() != D6O_IAADDR) {
2321 continue;
2322 }
2323 Option6IAAddrPtr iaaddr = boost::dynamic_pointer_cast<Option6IAAddr>(it->second);
2324 if (!iaaddr) {
2325 // That's weird. Option code was ok, but the object type was not.
2326 // This should never happen. The only case would be with badly
2327 // mis-implemented hook libraries that insert invalid option objects.
2328 // There's no way to protect against this.
2329 continue;
2330 }
2331 ctx.currentIA().addHint(iaaddr);
2332 }
2333
2334 Lease6Collection leases = alloc_engine_->renewLeases6(ctx);
2335
2336 // Ok, now we have the leases extended. We have:
2337 // - what the client tried to renew in ctx.hints_
2338 // - what we actually assigned in leases
2339 // - old leases that are no longer valid in ctx.old_leases_
2340
2341 // For each IA inserted by the client we have to determine what to do
2342 // about included addresses and notify the client. We will iterate over
2343 // those prefixes and remove those that we have already processed. We
2344 // don't want to remove them from the context, so we need to copy them
2345 // into temporary container.
2347
2348 // Retains the shortest valid lease time to use
2349 // for calculating T1 and T2.
2350 uint32_t min_preferred_lft = std::numeric_limits<uint32_t>::max();
2351
2352 // For all leases we have now, add the IAADDR with non-zero lifetimes.
2353 for (Lease6Collection::iterator l = leases.begin(); l != leases.end(); ++l) {
2354 if ((*l)->reuseable_valid_lft_ == 0) {
2356 .arg(query->getLabel())
2357 .arg((*l)->addr_.toText())
2358 .arg(ia->getIAID());
2359 } else {
2360 (*l)->valid_lft_ = (*l)->reuseable_valid_lft_;
2361 (*l)->preferred_lft_ = (*l)->reuseable_preferred_lft_;
2363 .arg(query->getLabel())
2364 .arg((*l)->addr_.toText())
2365 .arg(ia->getIAID())
2366 .arg(Lease::lifetimeToText((*l)->valid_lft_));
2367 }
2368
2370 (*l)->addr_, (*l)->preferred_lft_, (*l)->valid_lft_));
2371 ia_rsp->addOption(iaaddr);
2372
2373 // Check for new minimum lease time
2374 if (((*l)->preferred_lft_ > 0) && (min_preferred_lft > (*l)->preferred_lft_)) {
2375 min_preferred_lft = (*l)->preferred_lft_;
2376 }
2377
2378 // Now remove this prefix from the hints list.
2379 AllocEngine::Resource hint_type((*l)->addr_, (*l)->prefixlen_);
2380 hints.erase(std::remove(hints.begin(), hints.end(), hint_type),
2381 hints.end());
2382 }
2383
2384 // For the leases that we just retired, send the addresses with 0 lifetimes.
2385 for (Lease6Collection::iterator l = ctx.currentIA().old_leases_.begin();
2386 l != ctx.currentIA().old_leases_.end(); ++l) {
2387
2388 // Send an address with zero lifetimes only when this lease belonged to
2389 // this client. Do not send it when we're reusing an old lease that belonged
2390 // to someone else.
2391 if (equalValues(query->getClientId(), (*l)->duid_)) {
2393 (*l)->addr_, 0, 0));
2394 ia_rsp->addOption(iaaddr);
2395 }
2396
2397 // Now remove this address from the hints list.
2398 AllocEngine::Resource hint_type((*l)->addr_, 128);
2399 hints.erase(std::remove(hints.begin(), hints.end(), hint_type), hints.end());
2400
2401 // If the new FQDN settings have changed for the lease, we need to
2402 // delete any existing FQDN records for this lease.
2403 if (((*l)->hostname_ != ctx.hostname_) || ((*l)->fqdn_fwd_ != ctx.fwd_dns_update_) ||
2404 ((*l)->fqdn_rev_ != ctx.rev_dns_update_)) {
2407 .arg(query->getLabel())
2408 .arg((*l)->toText())
2409 .arg(ctx.hostname_)
2410 .arg(ctx.rev_dns_update_ ? "true" : "false")
2411 .arg(ctx.fwd_dns_update_ ? "true" : "false");
2412
2413 queueNCR(CHG_REMOVE, *l);
2414 }
2415 }
2416
2417 // Finally, if there are any addresses requested that we haven't dealt with
2418 // already, inform the client that he can't have them.
2419 for (AllocEngine::HintContainer::const_iterator hint = hints.begin();
2420 hint != hints.end(); ++hint) {
2422 hint->getAddress(), 0, 0));
2423 ia_rsp->addOption(iaaddr);
2424 }
2425
2426 if (!leases.empty()) {
2427 // We allocated leases so we need to update T1 and T2.
2428 setTeeTimes(min_preferred_lft, subnet, ia_rsp);
2429 } else {
2430 // The server wasn't able allocate new lease and renew an existing
2431 // lease. In that case, the server sends NoAddrsAvail per RFC 8415.
2432 ia_rsp->addOption(createStatusCode(*query, *ia_rsp,
2434 "Sorry, no addresses could be"
2435 " assigned at this time."));
2436 }
2437
2438 return (ia_rsp);
2439}
2440
2444 boost::shared_ptr<Option6IA> ia) {
2445
2447 .arg(query->getLabel())
2448 .arg(ia->getIAID());
2449
2450 const Subnet6Ptr& subnet = ctx.subnet_;
2451 const DuidPtr& duid = ctx.duid_;
2452
2453 // Let's create a IA_PD response and fill it in later
2454 Option6IAPtr ia_rsp(new Option6IA(D6O_IA_PD, ia->getIAID()));
2455
2456 // If there is no subnet for the particular client, we can't retrieve
2457 // information about client's leases from lease database. We treat this
2458 // as no binding for the client.
2459 if (!subnet) {
2460 // Per RFC 8415, section 18.3.4, if there is no binding and we are
2461 // processing a Renew, the NoBinding status code should be returned.
2462 if (query->getType() == DHCPV6_RENEW) {
2463 // Insert status code NoBinding
2464 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
2465 "Sorry, no known PD leases"
2466 " for this duid/iaid."));
2467 return (ia_rsp);
2468
2469 // Per RFC 8415, section 18.3.5, if there is no binding and we are
2470 // processing Rebind, the message has to be discarded (assuming that
2471 // the server doesn't know if the prefix in the IA_PD option is
2472 // appropriate for the client's link). The exception being thrown
2473 // here should propagate to the main loop and cause the message to
2474 // be discarded.
2475 } else {
2476
2485 isc_throw(DHCPv6DiscardMessageError, "no subnet found for the"
2486 " client sending Rebind to extend lifetime of the"
2487 " prefix (DUID=" << duid->toText() << ", IAID="
2488 << ia->getIAID() << ")");
2489 }
2490 }
2491
2492 // Set per-IA context values.
2493 ctx.createIAContext();
2494 ctx.currentIA().iaid_ = ia->getIAID();
2496 ctx.currentIA().ia_rsp_ = ia_rsp;
2497
2498 // Extract prefixes that the client is trying to renew.
2499 OptionCollection addrs = ia->getOptions();
2500 for (OptionCollection::const_iterator it = addrs.begin();
2501 it != addrs.end(); ++it) {
2502 if (it->second->getType() != D6O_IAPREFIX) {
2503 continue;
2504 }
2505 Option6IAPrefixPtr prf = boost::dynamic_pointer_cast<Option6IAPrefix>(it->second);
2506 if (!prf) {
2507 // That's weird. Option code was ok, but the object type was not.
2508 // This should never happen. The only case would be with badly
2509 // mis-implemented hook libraries that insert invalid option objects.
2510 // There's no way to protect against this.
2511 continue;
2512 }
2513
2514 // Put the client's prefix into the hints list.
2515 ctx.currentIA().addHint(prf);
2516 }
2517
2518 // Call Allocation Engine and attempt to renew leases. Number of things
2519 // may happen. Leases may be extended, revoked (if the lease is no longer
2520 // valid or reserved for someone else), or new leases may be added.
2521 // Important parameters are:
2522 // - returned container - current valid leases
2523 // - old_leases - leases that used to be, but are no longer valid
2524 // - changed_leases - leases that have FQDN changed (not really important
2525 // in PD context)
2526 Lease6Collection leases = alloc_engine_->renewLeases6(ctx);
2527
2528 // For each IA inserted by the client we have to determine what to do
2529 // about included prefixes and notify the client. We will iterate over
2530 // those prefixes and remove those that we have already processed. We
2531 // don't want to remove them from the context, so we need to copy them
2532 // into temporary container.
2534
2535 const bool pd_exclude_requested = requestedInORO(query, D6O_PD_EXCLUDE);
2536
2537 // Retains the shortest valid lease time to use
2538 // for calculating T1 and T2.
2539 uint32_t min_preferred_lft = std::numeric_limits<uint32_t>::max();
2540
2541 for (Lease6Collection::iterator l = leases.begin(); l != leases.end(); ++l) {
2542 if ((*l)->reuseable_valid_lft_ == 0) {
2544 .arg(query->getLabel())
2545 .arg((*l)->addr_.toText())
2546 .arg(static_cast<int>((*l)->prefixlen_))
2547 .arg(ia->getIAID());
2548 } else {
2549 (*l)->valid_lft_ = (*l)->reuseable_valid_lft_;
2550 (*l)->preferred_lft_ = (*l)->reuseable_preferred_lft_;
2552 .arg(query->getLabel())
2553 .arg((*l)->addr_.toText())
2554 .arg(static_cast<int>((*l)->prefixlen_))
2555 .arg(ia->getIAID())
2556 .arg(Lease::lifetimeToText((*l)->valid_lft_));
2557 }
2558
2560 (*l)->addr_, (*l)->prefixlen_,
2561 (*l)->preferred_lft_, (*l)->valid_lft_));
2562 ia_rsp->addOption(prf);
2563
2564 if (pd_exclude_requested) {
2565 // PD exclude option has been requested via ORO, thus we need to
2566 // include it if the pool configuration specifies this option.
2567 Pool6Ptr pool = boost::dynamic_pointer_cast<
2568 Pool6>(subnet->getPool(Lease::TYPE_PD, (*l)->addr_));
2569
2570 if (pool) {
2571 Option6PDExcludePtr pd_exclude_option = pool->getPrefixExcludeOption();
2572 if (pd_exclude_option) {
2573 prf->addOption(pd_exclude_option);
2574 }
2575 }
2576 }
2577
2578 // Check for new minimum lease time
2579 if (((*l)->preferred_lft_ > 0) && ((*l)->preferred_lft_ < min_preferred_lft)) {
2580 min_preferred_lft = (*l)->preferred_lft_;
2581 }
2582
2583 // Now remove this prefix from the hints list.
2584 AllocEngine::Resource hint_type((*l)->addr_, (*l)->prefixlen_);
2585 hints.erase(std::remove(hints.begin(), hints.end(), hint_type),
2586 hints.end());
2587 }
2588
2590 for (Lease6Collection::iterator l = ctx.currentIA().old_leases_.begin();
2591 l != ctx.currentIA().old_leases_.end(); ++l) {
2592
2593 // Send a prefix with zero lifetimes only when this lease belonged to
2594 // this client. Do not send it when we're reusing an old lease that belonged
2595 // to someone else.
2596 if (equalValues(query->getClientId(), (*l)->duid_)) {
2597 Option6IAPrefixPtr prefix(new Option6IAPrefix(D6O_IAPREFIX, (*l)->addr_,
2598 (*l)->prefixlen_, 0, 0));
2599 ia_rsp->addOption(prefix);
2600 }
2601
2602 // Now remove this prefix from the hints list.
2603 AllocEngine::Resource hint_type((*l)->addr_, (*l)->prefixlen_);
2604 hints.erase(std::remove(hints.begin(), hints.end(), hint_type), hints.end());
2605 }
2606
2607 // Finally, if there are any prefixes requested that we haven't dealt with
2608 // already, inform the client that he can't have them.
2609 for (AllocEngine::HintContainer::const_iterator prefix = hints.begin();
2610 prefix != hints.end(); ++prefix) {
2611
2612 // Send the prefix with the zero lifetimes only if the prefix
2613 // contains non-zero value. A zero value indicates that the hint was
2614 // for the prefix length.
2615 if (!prefix->getAddress().isV6Zero()) {
2616 OptionPtr prefix_opt(new Option6IAPrefix(D6O_IAPREFIX,
2617 prefix->getAddress(),
2618 prefix->getPrefixLength(),
2619 0, 0));
2620 ia_rsp->addOption(prefix_opt);
2621 }
2622 }
2623
2624 if (!leases.empty()) {
2625 // We allocated leases so we need to update T1 and T2.
2626 setTeeTimes(min_preferred_lft, subnet, ia_rsp);
2627 } else {
2628 // All is left is to insert the status code.
2629 // The server wasn't able allocate new lease and renew an existing
2630 // lease. In that case, the server sends NoPrefixAvail per RFC 8415.
2631 ia_rsp->addOption(createStatusCode(*query, *ia_rsp,
2633 "Sorry, no prefixes could be"
2634 " assigned at this time."));
2635 }
2636
2637 return (ia_rsp);
2638}
2639
2640void
2643
2644 // We will try to extend lease lifetime for all IA options in the client's
2645 // Renew or Rebind message.
2647
2648 // For the lease extension it is critical that the client has sent
2649 // DUID. There is no need to check for the presence of the DUID here
2650 // because we have already checked it in the sanityCheck().
2651
2652 // Save the originally selected subnet.
2653 Subnet6Ptr orig_subnet = ctx.subnet_;
2654
2655 for (OptionCollection::iterator opt = query->options_.begin();
2656 opt != query->options_.end(); ++opt) {
2657 switch (opt->second->getType()) {
2658 case D6O_IA_NA: {
2659 OptionPtr answer_opt = extendIA_NA(query, ctx,
2660 boost::dynamic_pointer_cast<
2661 Option6IA>(opt->second));
2662 if (answer_opt) {
2663 reply->addOption(answer_opt);
2664 }
2665 break;
2666 }
2667
2668 case D6O_IA_PD: {
2669 OptionPtr answer_opt = extendIA_PD(query, ctx,
2670 boost::dynamic_pointer_cast<
2671 Option6IA>(opt->second));
2672 if (answer_opt) {
2673 reply->addOption(answer_opt);
2674 }
2675 break;
2676 }
2677
2678 default:
2679 break;
2680 }
2681 }
2682
2683 // Subnet may be modified by the allocation engine, there are things
2684 // we need to do when that happens.
2685 checkDynamicSubnetChange(query, reply, ctx, orig_subnet);
2686}
2687
2688void
2691
2692 // We need to release addresses for all IA options in the client's
2693 // RELEASE message.
2694
2701
2702 // Let's set the status to be success by default. We can override it with
2703 // error status if needed. The important thing to understand here is that
2704 // the global status code may be set to success only if all IA options were
2705 // handled properly. Therefore the releaseIA_NA and releaseIA_PD options
2706 // may turn the status code to some error, but can't turn it back to success.
2707 int general_status = STATUS_Success;
2708 for (OptionCollection::iterator opt = release->options_.begin();
2709 opt != release->options_.end(); ++opt) {
2710 Lease6Ptr old_lease;
2711 switch (opt->second->getType()) {
2712 case D6O_IA_NA: {
2713 OptionPtr answer_opt = releaseIA_NA(ctx.duid_, release, general_status,
2714 boost::dynamic_pointer_cast<Option6IA>(opt->second),
2715 old_lease);
2716 if (answer_opt) {
2717 reply->addOption(answer_opt);
2718 }
2719 break;
2720 }
2721 case D6O_IA_PD: {
2722 OptionPtr answer_opt = releaseIA_PD(ctx.duid_, release, general_status,
2723 boost::dynamic_pointer_cast<Option6IA>(opt->second),
2724 old_lease);
2725 if (answer_opt) {
2726 reply->addOption(answer_opt);
2727 }
2728 break;
2729 }
2730 // @todo: add support for IA_TA
2731 default:
2732 // remaining options are stateless and thus ignored in this context
2733 ;
2734 }
2735
2736 // Store the old lease.
2737 if (old_lease) {
2738 ctx.currentIA().old_leases_.push_back(old_lease);
2739 }
2740 }
2741
2742 // Include top-level status code as well.
2743 reply->addOption(createStatusCode(*release, general_status,
2744 "Summary status for all processed IA_NAs"));
2745}
2746
2748Dhcpv6Srv::releaseIA_NA(const DuidPtr& duid, const Pkt6Ptr& query,
2749 int& general_status, boost::shared_ptr<Option6IA> ia,
2750 Lease6Ptr& old_lease) {
2751
2753 .arg(query->getLabel())
2754 .arg(ia->getIAID());
2755
2756 // Release can be done in one of two ways:
2757 // Approach 1: extract address from client's IA_NA and see if it belongs
2758 // to this particular client.
2759 // Approach 2: find a subnet for this client, get a lease for
2760 // this subnet/duid/iaid and check if its content matches to what the
2761 // client is asking us to release.
2762 //
2763 // This method implements approach 1.
2764
2765 // That's our response
2766 boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
2767
2768 Option6IAAddrPtr release_addr = boost::dynamic_pointer_cast<Option6IAAddr>
2769 (ia->getOption(D6O_IAADDR));
2770 if (!release_addr) {
2771 ia_rsp->addOption(createStatusCode(*query, STATUS_NoBinding,
2772 "You did not include an address in your RELEASE"));
2773 general_status = STATUS_NoBinding;
2774 return (ia_rsp);
2775 }
2776
2778 release_addr->getAddress());
2779
2780 if (!lease) {
2781 // client releasing a lease that we don't know about.
2782
2783 // Insert status code NoBinding.
2784 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
2785 "Sorry, no known leases for this duid/iaid, can't release."));
2786 general_status = STATUS_NoBinding;
2787
2788 return (ia_rsp);
2789 }
2790
2791 if (!lease->duid_) {
2792 // Something is gravely wrong here. We do have a lease, but it does not
2793 // have mandatory DUID information attached. Someone was messing with our
2794 // database.
2795
2797 .arg(query->getLabel())
2798 .arg(release_addr->getAddress().toText());
2799
2800 general_status = STATUS_UnspecFail;
2801 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_UnspecFail,
2802 "Database consistency check failed when trying to RELEASE"));
2803 return (ia_rsp);
2804 }
2805
2806 if (*duid != *(lease->duid_)) {
2807
2808 // Sorry, it's not your address. You can't release it.
2810 .arg(query->getLabel())
2811 .arg(release_addr->getAddress().toText())
2812 .arg(lease->duid_->toText());
2813
2814 general_status = STATUS_NoBinding;
2815 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
2816 "This address does not belong to you, you can't release it"));
2817 return (ia_rsp);
2818 }
2819
2820 if (ia->getIAID() != lease->iaid_) {
2821 // This address belongs to this client, but to a different IA
2823 .arg(query->getLabel())
2824 .arg(release_addr->getAddress().toText())
2825 .arg(lease->iaid_)
2826 .arg(ia->getIAID());
2827 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
2828 "This is your address, but you used wrong IAID"));
2829 general_status = STATUS_NoBinding;
2830 return (ia_rsp);
2831 }
2832
2833 // It is not necessary to check if the address matches as we used
2834 // getLease6(addr) method that is supposed to return a proper lease.
2835
2836 bool skip = false;
2837 // Execute all callouts registered for packet6_send
2838 if (HooksManager::calloutsPresent(Hooks.hook_index_lease6_release_)) {
2839 CalloutHandlePtr callout_handle = getCalloutHandle(query);
2840
2841 // Use the RAII wrapper to make sure that the callout handle state is
2842 // reset when this object goes out of scope. All hook points must do
2843 // it to prevent possible circular dependency between the callout
2844 // handle and its arguments.
2845 ScopedCalloutHandleState callout_handle_state(callout_handle);
2846
2847 // Enable copying options from the packet within hook library.
2848 ScopedEnableOptionsCopy<Pkt6> query6_options_copy(query);
2849
2850 // Delete all previous arguments
2851 callout_handle->deleteAllArguments();
2852
2853 // Pass the original packet
2854 callout_handle->setArgument("query6", query);
2855
2856 // Pass the lease to be updated
2857 callout_handle->setArgument("lease6", lease);
2858
2859 // Call all installed callouts
2860 HooksManager::callCallouts(Hooks.hook_index_lease6_release_, *callout_handle);
2861
2862 // Callouts decided to skip the next processing step. The next
2863 // processing step would to send the packet, so skip at this
2864 // stage means "drop response".
2865 if ((callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) ||
2866 (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP)) {
2867 skip = true;
2869 .arg(query->getLabel());
2870 }
2871 }
2872
2873 // Ok, we've passed all checks. Let's release this address.
2874 bool success = false; // was the removal operation successful?
2875
2876 if (!skip) {
2877 success = LeaseMgrFactory::instance().deleteLease(lease);
2878 }
2879
2880 // Here the success should be true if we removed lease successfully
2881 // and false if skip flag was set or the removal failed for whatever reason
2882
2883 if (!success) {
2884 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_UnspecFail,
2885 "Server failed to release a lease"));
2886
2888 .arg(query->getLabel())
2889 .arg(lease->addr_.toText())
2890 .arg(lease->iaid_);
2891 general_status = STATUS_UnspecFail;
2892
2893 return (ia_rsp);
2894 } else {
2895 old_lease = lease;
2896
2898 .arg(query->getLabel())
2899 .arg(lease->addr_.toText())
2900 .arg(lease->iaid_);
2901
2902 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_Success,
2903 "Lease released. Thank you, please come again."));
2904
2905 // Need to decrease statistic for assigned addresses.
2906 StatsMgr::instance().addValue(
2907 StatsMgr::generateName("subnet", lease->subnet_id_, "assigned-nas"),
2908 static_cast<int64_t>(-1));
2909
2910 // Check if a lease has flags indicating that the FQDN update has
2911 // been performed. If so, create NameChangeRequest which removes
2912 // the entries.
2913 queueNCR(CHG_REMOVE, lease);
2914
2915 return (ia_rsp);
2916 }
2917}
2918
2920Dhcpv6Srv::releaseIA_PD(const DuidPtr& duid, const Pkt6Ptr& query,
2921 int& general_status, boost::shared_ptr<Option6IA> ia,
2922 Lease6Ptr& old_lease) {
2923 // Release can be done in one of two ways:
2924 // Approach 1: extract address from client's IA_NA and see if it belongs
2925 // to this particular client.
2926 // Approach 2: find a subnet for this client, get a lease for
2927 // this subnet/duid/iaid and check if its content matches to what the
2928 // client is asking us to release.
2929 //
2930 // This method implements approach 1.
2931
2932 // That's our response. We will fill it in as we check the lease to be
2933 // released.
2934 boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_PD, ia->getIAID()));
2935
2936 boost::shared_ptr<Option6IAPrefix> release_prefix =
2937 boost::dynamic_pointer_cast<Option6IAPrefix>(ia->getOption(D6O_IAPREFIX));
2938 if (!release_prefix) {
2939 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
2940 "You did not include a prefix in your RELEASE"));
2941 general_status = STATUS_NoBinding;
2942 return (ia_rsp);
2943 }
2944
2946 release_prefix->getAddress());
2947
2948 if (!lease) {
2949 // Client releasing a lease that we don't know about.
2950
2951 // Insert status code NoBinding.
2952 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
2953 "Sorry, no known leases for this duid/iaid, can't release."));
2954 general_status = STATUS_NoBinding;
2955
2956 return (ia_rsp);
2957 }
2958
2959 if (!lease->duid_) {
2960 // Something is gravely wrong here. We do have a lease, but it does not
2961 // have mandatory DUID information attached. Someone was messing with our
2962 // database.
2964 .arg(query->getLabel())
2965 .arg(release_prefix->getAddress().toText())
2966 .arg(static_cast<int>(release_prefix->getLength()));
2967
2968 general_status = STATUS_UnspecFail;
2969 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_UnspecFail,
2970 "Database consistency check failed when trying to RELEASE"));
2971 return (ia_rsp);
2972 }
2973
2974 if (*duid != *(lease->duid_)) {
2975 // Sorry, it's not your address. You can't release it.
2977 .arg(query->getLabel())
2978 .arg(release_prefix->getAddress().toText())
2979 .arg(static_cast<int>(release_prefix->getLength()))
2980 .arg(lease->duid_->toText());
2981
2982 general_status = STATUS_NoBinding;
2983 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
2984 "This address does not belong to you, you can't release it"));
2985 return (ia_rsp);
2986 }
2987
2988 if (ia->getIAID() != lease->iaid_) {
2989 // This address belongs to this client, but to a different IA
2991 .arg(query->getLabel())
2992 .arg(release_prefix->getAddress().toText())
2993 .arg(static_cast<int>(release_prefix->getLength()))
2994 .arg(lease->iaid_)
2995 .arg(ia->getIAID());
2996 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
2997 "This is your address, but you used wrong IAID"));
2998 general_status = STATUS_NoBinding;
2999 return (ia_rsp);
3000 }
3001
3002 // It is not necessary to check if the address matches as we used
3003 // getLease6(addr) method that is supposed to return a proper lease.
3004
3005 bool skip = false;
3006 // Execute all callouts registered for packet6_send
3007 if (HooksManager::calloutsPresent(Hooks.hook_index_lease6_release_)) {
3008 CalloutHandlePtr callout_handle = getCalloutHandle(query);
3009
3010 // Use the RAII wrapper to make sure that the callout handle state is
3011 // reset when this object goes out of scope. All hook points must do
3012 // it to prevent possible circular dependency between the callout
3013 // handle and its arguments.
3014 ScopedCalloutHandleState callout_handle_state(callout_handle);
3015
3016 // Enable copying options from the packet within hook library.
3017 ScopedEnableOptionsCopy<Pkt6> query6_options_copy(query);
3018
3019 // Pass the original packet
3020 callout_handle->setArgument("query6", query);
3021
3022 // Pass the lease to be updated
3023 callout_handle->setArgument("lease6", lease);
3024
3025 // Call all installed callouts
3026 HooksManager::callCallouts(Hooks.hook_index_lease6_release_, *callout_handle);
3027
3028 skip = callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP;
3029 }
3030
3031 // Ok, we've passed all checks. Let's release this prefix.
3032 bool success = false; // was the removal operation successful?
3033
3034 if (!skip) {
3035 success = LeaseMgrFactory::instance().deleteLease(lease);
3036 } else {
3037 // Callouts decided to skip the next processing step. The next
3038 // processing step would to send the packet, so skip at this
3039 // stage means "drop response".
3041 .arg(query->getLabel());
3042 }
3043
3044 // Here the success should be true if we removed lease successfully
3045 // and false if skip flag was set or the removal failed for whatever reason
3046
3047 if (!success) {
3048 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_UnspecFail,
3049 "Server failed to release a lease"));
3050
3052 .arg(query->getLabel())
3053 .arg(lease->addr_.toText())
3054 .arg(static_cast<int>(lease->prefixlen_))
3055 .arg(lease->iaid_);
3056 general_status = STATUS_UnspecFail;
3057
3058 } else {
3059 old_lease = lease;
3060
3062 .arg(query->getLabel())
3063 .arg(lease->addr_.toText())
3064 .arg(static_cast<int>(lease->prefixlen_))
3065 .arg(lease->iaid_);
3066
3067 ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_Success,
3068 "Lease released. Thank you, please come again."));
3069
3070 // Need to decrease statistic for assigned prefixes.
3071 StatsMgr::instance().addValue(
3072 StatsMgr::generateName("subnet", lease->subnet_id_, "assigned-pds"),
3073 static_cast<int64_t>(-1));
3074 }
3075
3076 return (ia_rsp);
3077}
3078
3079Pkt6Ptr
3081
3082 Pkt6Ptr solicit = ctx.query_;
3083 Pkt6Ptr response(new Pkt6(DHCPV6_ADVERTISE, solicit->getTransid()));
3084
3085 // Handle Rapid Commit option, if present.
3086 if (ctx.subnet_ && ctx.subnet_->getRapidCommit()) {
3087 OptionPtr opt_rapid_commit = solicit->getOption(D6O_RAPID_COMMIT);
3088 if (opt_rapid_commit) {
3089
3091 .arg(solicit->getLabel());
3092
3093 // If Rapid Commit has been sent by the client, change the
3094 // response type to Reply and include Rapid Commit option.
3095 response->setType(DHCPV6_REPLY);
3096 response->addOption(opt_rapid_commit);
3097 }
3098 }
3099
3100 // "Fake" allocation is the case when the server is processing the Solicit
3101 // message without the Rapid Commit option and advertises a lease to
3102 // the client, but doesn't commit this lease to the lease database. If
3103 // the Solicit contains the Rapid Commit option and the server is
3104 // configured to honor the Rapid Commit option, or the client has sent
3105 // the Request message, the lease will be committed to the lease
3106 // database. The type of the server's response may be used to determine
3107 // if this is the fake allocation case or not. When the server sends
3108 // Reply message it means that it is committing leases. Other message
3109 // type (Advertise) means that server is not committing leases (fake
3110 // allocation).
3111 ctx.fake_allocation_ = (response->getType() != DHCPV6_REPLY);
3112
3113 processClientFqdn(solicit, response, ctx);
3114
3115 if (MultiThreadingMgr::instance().getMode()) {
3116 // The lease reclamation cannot run at the same time.
3117 ReadLockGuard share(alloc_engine_->getReadWriteMutex());
3118
3119 assignLeases(solicit, response, ctx);
3120 } else {
3121 assignLeases(solicit, response, ctx);
3122 }
3123
3125 requiredClassify(solicit, ctx);
3126
3127 copyClientOptions(solicit, response);
3128 CfgOptionList co_list;
3129 buildCfgOptionList(solicit, ctx, co_list);
3130 appendDefaultOptions(solicit, response, co_list);
3131 appendRequestedOptions(solicit, response, co_list);
3132 appendRequestedVendorOptions(solicit, response, ctx, co_list);
3133
3134 updateReservedFqdn(ctx, response);
3135
3136 // Only generate name change requests if sending a Reply as a result
3137 // of receiving Rapid Commit option.
3138 if (response->getType() == DHCPV6_REPLY) {
3139 createNameChangeRequests(response, ctx);
3140 }
3141
3142 return (response);
3143}
3144
3145Pkt6Ptr
3147
3148 Pkt6Ptr request = ctx.query_;
3149 Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, request->getTransid()));
3150
3151 processClientFqdn(request, reply, ctx);
3152
3153 if (MultiThreadingMgr::instance().getMode()) {
3154 // The lease reclamation cannot run at the same time.
3155 ReadLockGuard share(alloc_engine_->getReadWriteMutex());
3156
3157 assignLeases(request, reply, ctx);
3158 } else {
3159 assignLeases(request, reply, ctx);
3160 }
3161
3163 requiredClassify(request, ctx);
3164
3165 copyClientOptions(request, reply);
3166 CfgOptionList co_list;
3167 buildCfgOptionList(request, ctx, co_list);
3168 appendDefaultOptions(request, reply, co_list);
3169 appendRequestedOptions(request, reply, co_list);
3170 appendRequestedVendorOptions(request, reply, ctx, co_list);
3171
3172 updateReservedFqdn(ctx, reply);
3173 generateFqdn(reply, ctx);
3174 createNameChangeRequests(reply, ctx);
3175
3176 return (reply);
3177}
3178
3179Pkt6Ptr
3181
3182 Pkt6Ptr renew = ctx.query_;
3183 Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, renew->getTransid()));
3184
3185 processClientFqdn(renew, reply, ctx);
3186
3187 if (MultiThreadingMgr::instance().getMode()) {
3188 // The lease reclamation cannot run at the same time.
3189 ReadLockGuard share(alloc_engine_->getReadWriteMutex());
3190
3191 extendLeases(renew, reply, ctx);
3192 } else {
3193 extendLeases(renew, reply, ctx);
3194 }
3195
3197 requiredClassify(renew, ctx);
3198
3199 copyClientOptions(renew, reply);
3200 CfgOptionList co_list;
3201 buildCfgOptionList(renew, ctx, co_list);
3202 appendDefaultOptions(renew, reply, co_list);
3203 appendRequestedOptions(renew, reply, co_list);
3204 appendRequestedVendorOptions(renew, reply, ctx, co_list);
3205
3206 updateReservedFqdn(ctx, reply);
3207 generateFqdn(reply, ctx);
3208 createNameChangeRequests(reply, ctx);
3209
3210 return (reply);
3211}
3212
3213Pkt6Ptr
3215
3216 Pkt6Ptr rebind = ctx.query_;
3217 Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, rebind->getTransid()));
3218
3219 processClientFqdn(rebind, reply, ctx);
3220
3221 if (MultiThreadingMgr::instance().getMode()) {
3222 // The lease reclamation cannot run at the same time.
3223 ReadLockGuard share(alloc_engine_->getReadWriteMutex());
3224
3225 extendLeases(rebind, reply, ctx);
3226 } else {
3227 extendLeases(rebind, reply, ctx);
3228 }
3229
3231 requiredClassify(rebind, ctx);
3232
3233 copyClientOptions(rebind, reply);
3234 CfgOptionList co_list;
3235 buildCfgOptionList(rebind, ctx, co_list);
3236 appendDefaultOptions(rebind, reply, co_list);
3237 appendRequestedOptions(rebind, reply, co_list);
3238 appendRequestedVendorOptions(rebind, reply, ctx, co_list);
3239
3240 updateReservedFqdn(ctx, reply);
3241 generateFqdn(reply, ctx);
3242 createNameChangeRequests(reply, ctx);
3243
3244 return (reply);
3245}
3246
3247Pkt6Ptr
3249
3250 Pkt6Ptr confirm = ctx.query_;
3252 requiredClassify(confirm, ctx);
3253
3254 // Get IA_NAs from the Confirm. If there are none, the message is
3255 // invalid and must be discarded. There is nothing more to do.
3256 OptionCollection ias = confirm->getOptions(D6O_IA_NA);
3257 if (ias.empty()) {
3258 return (Pkt6Ptr());
3259 }
3260
3261 // The server sends Reply message in response to Confirm.
3262 Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, confirm->getTransid()));
3263 // Make sure that the necessary options are included.
3264 copyClientOptions(confirm, reply);
3265 CfgOptionList co_list;
3266 buildCfgOptionList(confirm, ctx, co_list);
3267 appendDefaultOptions(confirm, reply, co_list);
3268 appendRequestedOptions(confirm, reply, co_list);
3269 appendRequestedVendorOptions(confirm, reply, ctx, co_list);
3270 // Indicates if at least one address has been verified. If no addresses
3271 // are verified it means that the client has sent no IA_NA options
3272 // or no IAAddr options and that client's message has to be discarded.
3273 bool verified = false;
3274 // Check if subnet was selected for the message. If no subnet
3275 // has been selected, the client is not on link.
3276 SubnetPtr subnet = ctx.subnet_;
3277
3278 // Regardless if the subnet has been selected or not, we will iterate
3279 // over the IA_NA options to check if they hold any addresses. If there
3280 // are no, the Confirm is discarded.
3281 // Check addresses in IA_NA options and make sure they are appropriate.
3282 for (OptionCollection::const_iterator ia = ias.begin();
3283 ia != ias.end(); ++ia) {
3284 const OptionCollection& opts = ia->second->getOptions();
3285 for (OptionCollection::const_iterator opt = opts.begin();
3286 opt != opts.end(); ++opt) {
3287 // Ignore options other than IAAddr.
3288 if (opt->second->getType() == D6O_IAADDR) {
3289 // Check that the address is in range in the subnet selected.
3290 Option6IAAddrPtr iaaddr = boost::dynamic_pointer_cast<
3291 Option6IAAddr>(opt->second);
3292 // If there is subnet selected and the address has been included
3293 // in IA_NA, mark it verified and verify that it belongs to the
3294 // subnet.
3295 if (iaaddr) {
3296 // If at least one address is not in range, then return
3297 // the NotOnLink status code.
3298 if (subnet && !subnet->inRange(iaaddr->getAddress())) {
3299 std::ostringstream status_msg;
3300 status_msg << "Address " << iaaddr->getAddress()
3301 << " is not on link.";
3302 reply->addOption(createStatusCode(*confirm,
3304 status_msg.str()));
3305 return (reply);
3306 }
3307 verified = true;
3308 } else {
3309 isc_throw(Unexpected, "failed to cast the IA Address option"
3310 " to the Option6IAAddrPtr. This is programming"
3311 " error and should be reported");
3312 }
3313 }
3314 }
3315 }
3316
3317 // It seems that the client hasn't included any addresses in which case
3318 // the Confirm must be discarded.
3319 if (!verified) {
3320 return (Pkt6Ptr());
3321 }
3322
3323 // If there is a subnet, there were addresses in IA_NA options and the
3324 // addresses where consistent with the subnet then the client is on link.
3325 if (subnet) {
3326 // All addresses in range, so return success.
3327 reply->addOption(createStatusCode(*confirm, STATUS_Success,
3328 "All addresses are on-link"));
3329 } else {
3330 reply->addOption(createStatusCode(*confirm, STATUS_NotOnLink,
3331 "No subnet selected"));
3332 }
3333
3334 return (reply);
3335}
3336
3337Pkt6Ptr
3339
3340 Pkt6Ptr release = ctx.query_;
3342 requiredClassify(release, ctx);
3343
3344 // Create an empty Reply message.
3345 Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, release->getTransid()));
3346
3347 // Copy client options (client-id, also relay information if present)
3348 copyClientOptions(release, reply);
3349
3350 // Get the configured option list
3351 CfgOptionList co_list;
3352 // buildCfgOptionList(release, ctx, co_list);
3353 appendDefaultOptions(release, reply, co_list);
3354
3355 releaseLeases(release, reply, ctx);
3356
3359
3360 return (reply);
3361}
3362
3363Pkt6Ptr
3365
3366 Pkt6Ptr decline = ctx.query_;
3368 requiredClassify(decline, ctx);
3369
3370 // Create an empty Reply message.
3371 Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, decline->getTransid()));
3372
3373 // Copy client options (client-id, also relay information if present)
3374 copyClientOptions(decline, reply);
3375
3376 // Get the configured option list
3377 CfgOptionList co_list;
3378 buildCfgOptionList(decline, ctx, co_list);
3379
3380 // Include server-id
3381 appendDefaultOptions(decline, reply, co_list);
3382
3383 if (declineLeases(decline, reply, ctx)) {
3384 return (reply);
3385 } else {
3386
3387 // declineLeases returns false only if the hooks set the next step
3388 // status to DROP. We'll just doing as requested.
3389 return (Pkt6Ptr());
3390 }
3391}
3392
3393bool
3396
3397 // We need to decline addresses for all IA_NA options in the client's
3398 // DECLINE message.
3399
3400 // Let's set the status to be success by default. We can override it with
3401 // error status if needed. The important thing to understand here is that
3402 // the global status code may be set to success only if all IA options were
3403 // handled properly. Therefore the declineIA options
3404 // may turn the status code to some error, but can't turn it back to success.
3405 int general_status = STATUS_Success;
3406
3407 for (OptionCollection::iterator opt = decline->options_.begin();
3408 opt != decline->options_.end(); ++opt) {
3409 switch (opt->second->getType()) {
3410 case D6O_IA_NA: {
3411 OptionPtr answer_opt = declineIA(decline, ctx.duid_, general_status,
3412 boost::dynamic_pointer_cast<Option6IA>(opt->second),
3413 ctx.new_leases_);
3414 if (answer_opt) {
3415
3416 // We have an answer, let's use it.
3417 reply->addOption(answer_opt);
3418 } else {
3419
3420 // The only case when declineIA could return NULL is if one of the
3421 // hook callouts set next step status to DROP. We just need to drop
3422 // this packet.
3423 return (false);
3424 }
3425 break;
3426 }
3427 default:
3428 // We don't care for the remaining options
3429 ;
3430 }
3431 }
3432
3433 return (true);
3434}
3435
3437Dhcpv6Srv::declineIA(const Pkt6Ptr& decline, const DuidPtr& duid,
3438 int& general_status, boost::shared_ptr<Option6IA> ia,
3439 Lease6Collection& new_leases) {
3440
3442 .arg(decline->getLabel())
3443 .arg(ia->getIAID());
3444
3445 // Decline can be done in one of two ways:
3446 // Approach 1: extract address from client's IA_NA and see if it belongs
3447 // to this particular client.
3448 // Approach 2: find a subnet for this client, get a lease for
3449 // this subnet/duid/iaid and check if its content matches to what the
3450 // client is asking us to decline.
3451 //
3452 // This method implements approach 1.
3453
3454 // That's our response
3455 boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
3456
3457 const OptionCollection& opts = ia->getOptions();
3458 int total_addrs = 0; // Let's count the total number of addresses.
3459 for (OptionCollection::const_iterator opt = opts.begin(); opt != opts.end();
3460 ++opt) {
3461
3462 // Let's ignore nested options other than IAADDR (there shouldn't be anything
3463 // else in IA_NA in Decline message, but let's be on the safe side).
3464 if (opt->second->getType() != D6O_IAADDR) {
3465 continue;
3466 }
3467 Option6IAAddrPtr decline_addr = boost::dynamic_pointer_cast<Option6IAAddr>
3468 (opt->second);
3469 if (!decline_addr) {
3470 continue;
3471 }
3472
3473 total_addrs++;
3474
3476 decline_addr->getAddress());
3477
3478 if (!lease) {
3479 // Client trying to decline a lease that we don't know about.
3481 .arg(decline->getLabel()).arg(decline_addr->getAddress().toText());
3482
3483 // According to RFC 8415, section 18.3.8:
3484 // "For each IA in the Decline message for which the server has no
3485 // binding information, the server adds an IA option using the IAID
3486 // from the Decline message and includes a Status Code option with
3487 // the value NoBinding in the IA option".
3488 setStatusCode(ia_rsp, createStatusCode(*decline, *ia_rsp, STATUS_NoBinding,
3489 "Server does not know about such an address."));
3490
3491 // In the same section of RFC 8415:
3492 // "The server ignores addresses not assigned to the IAs (though it may"
3493 // choose to log an error if it finds such addresses)."
3494 continue; // There may be other addresses.
3495 }
3496
3497 if (!lease->duid_) {
3498 // Something is gravely wrong here. We do have a lease, but it does not
3499 // have mandatory DUID information attached. Someone was messing with our
3500 // database.
3501
3503 .arg(decline->getLabel())
3504 .arg(decline_addr->getAddress().toText());
3505
3506 ia_rsp->addOption(createStatusCode(*decline, *ia_rsp, STATUS_UnspecFail,
3507 "Database consistency check failed when attempting Decline."));
3508
3509 continue;
3510 }
3511
3512 // Ok, there's a sane lease with an address. Let's check if DUID matches first.
3513 if (*duid != *(lease->duid_)) {
3514
3515 // Sorry, it's not your address. You can't release it.
3517 .arg(decline->getLabel())
3518 .arg(decline_addr->getAddress().toText())
3519 .arg(lease->duid_->toText());
3520
3521 ia_rsp->addOption(createStatusCode(*decline, *ia_rsp, STATUS_NoBinding,
3522 "This address does not belong to you, you can't decline it"));
3523
3524 continue;
3525 }
3526
3527 // Let's check if IAID matches.
3528 if (ia->getIAID() != lease->iaid_) {
3529 // This address belongs to this client, but to a different IA
3531 .arg(decline->getLabel())
3532 .arg(lease->addr_.toText())
3533 .arg(ia->getIAID())
3534 .arg(lease->iaid_);
3535 setStatusCode(ia_rsp, createStatusCode(*decline, *ia_rsp, STATUS_NoBinding,
3536 "This is your address, but you used wrong IAID"));
3537
3538 continue;
3539 }
3540
3541 // Ok, all is good. Decline this lease.
3542 if (!declineLease(decline, lease, ia_rsp)) {
3543 // declineLease returns false only when hook callouts set the next
3544 // step status to drop. We just propagate the bad news here.
3545 return (OptionPtr());
3546
3547 } else {
3548 new_leases.push_back(lease);
3549 }
3550 }
3551
3552 if (total_addrs == 0) {
3553 setStatusCode(ia_rsp, createStatusCode(*decline, *ia_rsp, STATUS_NoBinding,
3554 "No addresses sent in IA_NA"));
3555 general_status = STATUS_NoBinding;
3556 }
3557
3558 return (ia_rsp);
3559}
3560
3561void
3562Dhcpv6Srv::setStatusCode(boost::shared_ptr<isc::dhcp::Option6IA>& container,
3563 const OptionPtr& status) {
3564 // Let's delete any old status code we may have.
3565 container->delOption(D6O_STATUS_CODE);
3566
3567 container->addOption(status);
3568}
3569
3570bool
3571Dhcpv6Srv::declineLease(const Pkt6Ptr& decline, const Lease6Ptr lease,
3572 boost::shared_ptr<Option6IA> ia_rsp) {
3573 // We do not want to decrease the assigned-nas at this time. While
3574 // technically a declined address is no longer allocated, the
3575 // primary usage of the assigned-nas statistic is to monitor pool
3576 // utilization. Most people would forget to include declined-nas
3577 // in the calculation, and simply do assigned-nas/total-nas. This
3578 // would have a bias towards under-representing pool utilization,
3579 // if we decreased allocated immediately after receiving DHCPDECLINE,
3580 // rather than later when we recover the address.
3581
3582 // Let's call lease6_decline hooks if necessary.
3583 if (HooksManager::calloutsPresent(Hooks.hook_index_lease6_decline_)) {
3584 CalloutHandlePtr callout_handle = getCalloutHandle(decline);
3585
3586 // Use the RAII wrapper to make sure that the callout handle state is
3587 // reset when this object goes out of scope. All hook points must do
3588 // it to prevent possible circular dependency between the callout
3589 // handle and its arguments.
3590 ScopedCalloutHandleState callout_handle_state(callout_handle);
3591
3592 // Enable copying options from the packet within hook library.
3593 ScopedEnableOptionsCopy<Pkt6> query6_options_copy(decline);
3594
3595 // Pass the original packet
3596 callout_handle->setArgument("query6", decline);
3597
3598 // Pass the lease to be updated
3599 callout_handle->setArgument("lease6", lease);
3600
3601 // Call callouts
3602 HooksManager::callCallouts(Hooks.hook_index_lease6_decline_,
3603 *callout_handle);
3604
3605 // Callouts decided to SKIP the next processing step. The next
3606 // processing step would to actually decline the lease, so we'll
3607 // keep the lease as is.
3608 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) {
3610 .arg(decline->getLabel())
3611 .arg(decline->getIface())
3612 .arg(lease->addr_.toText());
3613 return (true);
3614 }
3615
3616 // Callouts decided to DROP the packet. Let's simply log it and
3617 // return false, so callers will act accordingly.
3618 if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP) {
3620 .arg(decline->getLabel())
3621 .arg(decline->getIface())
3622 .arg(lease->addr_.toText());
3623 return (false);
3624 }
3625 }
3626
3627 Lease6Ptr old_values = boost::make_shared<Lease6>(*lease);
3628
3629 // @todo: Call hooks.
3630
3631 // We need to disassociate the lease from the client. Once we move a lease
3632 // to declined state, it is no longer associated with the client in any
3633 // way.
3634 lease->decline(CfgMgr::instance().getCurrentCfg()->getDeclinePeriod());
3635
3636 try {
3638 } catch (const Exception& ex) {
3639 // Update failed.
3641 .arg(decline->getLabel())
3642 .arg(lease->addr_.toText())
3643 .arg(ex.what());
3644 return (false);
3645 }
3646
3647 // Check if a lease has flags indicating that the FQDN update has
3648 // been performed. If so, create NameChangeRequest which removes
3649 // the entries. This method does all necessary checks.
3650 queueNCR(CHG_REMOVE, old_values);
3651
3652 // Bump up the subnet-specific statistic.
3653 StatsMgr::instance().addValue(
3654 StatsMgr::generateName("subnet", lease->subnet_id_, "declined-addresses"),
3655 static_cast<int64_t>(1));
3656
3657 // Global declined addresses counter.
3658 StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(1));
3659
3660 LOG_INFO(lease6_logger, DHCP6_DECLINE_LEASE).arg(decline->getLabel())
3661 .arg(lease->addr_.toText()).arg(lease->valid_lft_);
3662
3663 ia_rsp->addOption(createStatusCode(*decline, *ia_rsp, STATUS_Success,
3664 "Lease declined. Hopefully the next one will be better."));
3665
3666 return (true);
3667}
3668
3669Pkt6Ptr
3671
3672 Pkt6Ptr inf_request = ctx.query_;
3673 conditionallySetReservedClientClasses(inf_request, ctx);
3674 requiredClassify(inf_request, ctx);
3675
3676 // Create a Reply packet, with the same trans-id as the client's.
3677 Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, inf_request->getTransid()));
3678
3679 // Copy client options (client-id, also relay information if present)
3680 copyClientOptions(inf_request, reply);
3681
3682 // Build the configured option list for append methods
3683 CfgOptionList co_list;
3684 buildCfgOptionList(inf_request, ctx, co_list);
3685
3686 // Append default options, i.e. options that the server is supposed
3687 // to put in all messages it sends (server-id for now, but possibly other
3688 // options once we start supporting authentication)
3689 appendDefaultOptions(inf_request, reply, co_list);
3690
3691 // Try to assign options that were requested by the client.
3692 appendRequestedOptions(inf_request, reply, co_list);
3693
3694 // Try to assign vendor options that were requested by the client.
3695 appendRequestedVendorOptions(inf_request, reply, ctx, co_list);
3696
3697 return (reply);
3698}
3699
3700void
3702
3703 // flags are in transid
3704 // uint32_t flags = dhcp4_query->getTransid();
3705 // do nothing with DHCPV4_QUERY_FLAGS_UNICAST
3706
3707 // Get the DHCPv4 message option
3708 OptionPtr dhcp4_msg = dhcp4_query->getOption(D6O_DHCPV4_MSG);
3709 if (dhcp4_msg) {
3710 try {
3711 // Forward the whole message to the DHCPv4 server via IPC
3712 Dhcp6to4Ipc::instance().send(dhcp4_query);
3713 } catch (...) {
3714 // Assume the error was already logged
3715 return;
3716 }
3717 }
3718
3719 // This method does not return anything as we always sent back
3720 // the response via Dhcp6To4Ipc.
3721}
3722
3723void Dhcpv6Srv::classifyByVendor(const Pkt6Ptr& pkt, std::string& classes) {
3724 OptionVendorClassPtr vclass = boost::dynamic_pointer_cast<
3725 OptionVendorClass>(pkt->getOption(D6O_VENDOR_CLASS));
3726
3727 if (!vclass || vclass->getTuplesNum() == 0) {
3728 return;
3729 }
3730
3731 if (vclass->hasTuple(DOCSIS3_CLASS_MODEM)) {
3733 classes += VENDOR_CLASS_PREFIX + DOCSIS3_CLASS_MODEM + " ";
3734
3735 } else if (vclass->hasTuple(DOCSIS3_CLASS_EROUTER)) {
3737 classes += VENDOR_CLASS_PREFIX + DOCSIS3_CLASS_EROUTER + " ";
3738
3739 } else {
3740 pkt->addClass(VENDOR_CLASS_PREFIX + vclass->getTuple(0).getText());
3741 classes + VENDOR_CLASS_PREFIX + vclass->getTuple(0).getText() + " ";
3742 }
3743}
3744
3746 // All packets belongs to ALL
3747 pkt->addClass("ALL");
3748 string classes = "ALL ";
3749
3750 // First: built-in vendor class processing
3751 classifyByVendor(pkt, classes);
3752
3753 // Run match expressions on classes not depending on KNOWN/UNKNOWN.
3754 evaluateClasses(pkt, false);
3755}
3756
3757void Dhcpv6Srv::evaluateClasses(const Pkt6Ptr& pkt, bool depend_on_known) {
3758 // Note getClientClassDictionary() cannot be null
3759 const ClientClassDictionaryPtr& dict =
3760 CfgMgr::instance().getCurrentCfg()->getClientClassDictionary();
3761 const ClientClassDefListPtr& defs_ptr = dict->getClasses();
3762 for (ClientClassDefList::const_iterator it = defs_ptr->cbegin();
3763 it != defs_ptr->cend(); ++it) {
3764 // Note second cannot be null
3765 const ExpressionPtr& expr_ptr = (*it)->getMatchExpr();
3766 // Nothing to do without an expression to evaluate
3767 if (!expr_ptr) {
3768 continue;
3769 }
3770 // Not the right time if only when required
3771 if ((*it)->getRequired()) {
3772 continue;
3773 }
3774 // Not the right pass.
3775 if ((*it)->getDependOnKnown() != depend_on_known) {
3776 continue;
3777 }
3778 // Evaluate the expression which can return false (no match),
3779 // true (match) or raise an exception (error)
3780 try {
3781 bool status = evaluateBool(*expr_ptr, *pkt);
3782 if (status) {
3784 .arg((*it)->getName())
3785 .arg(status);
3786 // Matching: add the class
3787 pkt->addClass((*it)->getName());
3788 } else {
3790 .arg((*it)->getName())
3791 .arg(status);
3792 }
3793 } catch (const Exception& ex) {
3795 .arg((*it)->getName())
3796 .arg(ex.what());
3797 } catch (...) {
3799 .arg((*it)->getName())
3800 .arg("get exception?");
3801 }
3802 }
3803}
3804
3805void
3807 const AllocEngine::ClientContext6& ctx) {
3808 if (ctx.currentHost() && pkt) {
3809 const ClientClasses& classes = ctx.currentHost()->getClientClasses6();
3810 for (ClientClasses::const_iterator cclass = classes.cbegin();
3811 cclass != classes.cend(); ++cclass) {
3812 pkt->addClass(*cclass);
3813 }
3814 }
3815
3816 const ClientClasses& classes = pkt->getClasses();
3817 if (!classes.empty()) {
3819 .arg(pkt->getLabel())
3820 .arg(classes.toText());
3821 }
3822}
3823
3824void
3826 const AllocEngine::ClientContext6& ctx) {
3827 if (ctx.subnet_) {
3828 SharedNetwork6Ptr shared_network;
3829 ctx.subnet_->getSharedNetwork(shared_network);
3830 if (shared_network) {
3831 ConstHostPtr host = ctx.currentHost();
3832 if (host && (host->getIPv6SubnetID() != SUBNET_ID_GLOBAL)) {
3833 setReservedClientClasses(pkt, ctx);
3834 }
3835 }
3836 }
3837}
3838
3839void
3841 // First collect required classes
3842 ClientClasses classes = pkt->getClasses(true);
3843 Subnet6Ptr subnet = ctx.subnet_;
3844
3845 if (subnet) {
3846 // Begin by the shared-network
3847 SharedNetwork6Ptr network;
3848 subnet->getSharedNetwork(network);
3849 if (network) {
3850 const ClientClasses& to_add = network->getRequiredClasses();
3851 for (ClientClasses::const_iterator cclass = to_add.cbegin();
3852 cclass != to_add.cend(); ++cclass) {
3853 classes.insert(*cclass);
3854 }
3855 }
3856
3857 // Followed by the subnet
3858 const ClientClasses& to_add = subnet->getRequiredClasses();
3859 for (ClientClasses::const_iterator cclass = to_add.cbegin();
3860 cclass != to_add.cend(); ++cclass) {
3861 classes.insert(*cclass);
3862 }
3863
3864 // And finish by pools
3865 for (auto resource : ctx.allocated_resources_) {
3866 PoolPtr pool =
3867 ctx.subnet_->getPool(resource.getPrefixLength() == 128 ?
3869 resource.getAddress(),
3870 false);
3871 if (pool) {
3872 const ClientClasses& to_add = pool->getRequiredClasses();
3873 for (ClientClasses::const_iterator cclass = to_add.cbegin();
3874 cclass != to_add.cend(); ++cclass) {
3875 classes.insert(*cclass);
3876 }
3877 }
3878 }
3879
3880 // host reservation???
3881 }
3882
3883 // Run match expressions
3884 // Note getClientClassDictionary() cannot be null
3885 const ClientClassDictionaryPtr& dict =
3886 CfgMgr::instance().getCurrentCfg()->getClientClassDictionary();
3887 for (ClientClasses::const_iterator cclass = classes.cbegin();
3888 cclass != classes.cend(); ++cclass) {
3889 const ClientClassDefPtr class_def = dict->findClass(*cclass);
3890 if (!class_def) {
3892 .arg(*cclass);
3893 continue;
3894 }
3895 const ExpressionPtr& expr_ptr = class_def->getMatchExpr();
3896 // Nothing to do without an expression to evaluate
3897 if (!expr_ptr) {
3899 .arg(*cclass);
3900 continue;
3901 }
3902 // Evaluate the expression which can return false (no match),
3903 // true (match) or raise an exception (error)
3904 try {
3905 bool status = evaluateBool(*expr_ptr, *pkt);
3906 if (status) {
3908 .arg(*cclass)
3909 .arg(status);
3910 // Matching: add the class
3911 pkt->addClass(*cclass);
3912 } else {
3914 .arg(*cclass)
3915 .arg(status);
3916 }
3917 } catch (const Exception& ex) {
3919 .arg(*cclass)
3920 .arg(ex.what());
3921 } catch (...) {
3923 .arg(*cclass)
3924 .arg("get exception?");
3925 }
3926 }
3927}
3928
3929void
3930Dhcpv6Srv::updateReservedFqdn(AllocEngine::ClientContext6& ctx,
3931 const Pkt6Ptr& answer) {
3932 if (!answer) {
3933 isc_throw(isc::Unexpected, "an instance of the object encapsulating"
3934 " a message must not be NULL when updating reserved FQDN");
3935 }
3936
3937 Option6ClientFqdnPtr fqdn = boost::dynamic_pointer_cast<Option6ClientFqdn>
3938 (answer->getOption(D6O_CLIENT_FQDN));
3939
3940 // If Client FQDN option is not included, there is nothing to do.
3941 if (!fqdn) {
3942 return;
3943 }
3944
3945 std::string name = fqdn->getDomainName();
3946
3947 // If there is a host reservation for this client we have to check whether
3948 // this reservation has the same hostname as the hostname currently
3949 // present in the FQDN option. If not, it indicates that the allocation
3950 // engine picked a different subnet (from within a shared network) for
3951 // reservations and we have to send this new value to the client.
3952 if (ctx.currentHost() &&
3953 !ctx.currentHost()->getHostname().empty()) {
3954 std::string new_name = CfgMgr::instance().getD2ClientMgr().
3955 qualifyName(ctx.currentHost()->getHostname(), *ctx.getDdnsParams(), true);
3956
3957 if (new_name != name) {
3958 fqdn->setDomainName(new_name, Option6ClientFqdn::FULL);
3959
3960 // Replace previous instance of Client FQDN option.
3961 answer->delOption(D6O_CLIENT_FQDN);
3962 answer->addOption(fqdn);
3963 }
3964 }
3965}
3966
3967void
3968Dhcpv6Srv::generateFqdn(const Pkt6Ptr& answer,
3970 if (!answer) {
3971 isc_throw(isc::Unexpected, "an instance of the object encapsulating"
3972 " a message must not be NULL when generating FQDN");
3973 }
3974
3977
3978 // It is likely that client hasn't included the FQDN option. In such case,
3979 // FQDN option will be NULL. Also, there is nothing to do if the option
3980 // is present and conveys the non-empty FQDN.
3981 Option6ClientFqdnPtr fqdn = boost::dynamic_pointer_cast<
3982 Option6ClientFqdn>(answer->getOption(D6O_CLIENT_FQDN));
3983 if (!fqdn || !fqdn->getDomainName().empty()) {
3984 return;
3985 }
3986
3987 // Get the first IA_NA acquired for the client.
3988 OptionPtr ia = answer->getOption(D6O_IA_NA);
3989 if (!ia) {
3990 return;
3991 }
3992
3993 // If it has any IAAddr, use the first one to generate unique FQDN.
3994 Option6IAAddrPtr iaaddr = boost::dynamic_pointer_cast<
3995 Option6IAAddr>(ia->getOption(D6O_IAADDR));
3996 if (!iaaddr) {
3997 return;
3998 }
3999 // Get the IPv6 address acquired by the client.
4000 IOAddress addr = iaaddr->getAddress();
4001 std::string generated_name =
4003
4005 .arg(answer->getLabel())
4006 .arg(generated_name);
4007
4008 try {
4009 // The lease has been acquired but the FQDN for this lease hasn't
4010 // been updated in the lease database. We now have new FQDN
4011 // generated, so the lease database has to be updated here.
4012 // However, never update lease database for Advertise, just send
4013 // our notion of client's FQDN in the Client FQDN option.
4014 if (answer->getType() != DHCPV6_ADVERTISE) {
4015 Lease6Ptr lease;
4016 for (auto l : ctx.new_leases_) {
4017 if ((l->type_ == Lease::TYPE_NA) && (l->addr_ == addr)) {
4018 lease = l;
4019 break;
4020 }
4021 }
4022 if (lease) {
4023 lease->hostname_ = generated_name;
4024 lease->reuseable_valid_lft_ = 0;
4026
4027 } else {
4028 isc_throw(isc::Unexpected, "there is no lease in the database "
4029 " for address " << addr << ", so as it is impossible"
4030 " to update FQDN data. This is a programmatic error"
4031 " as the given address is now being handed to the"
4032 " client");
4033 }
4034 }
4035 // Set the generated FQDN in the Client FQDN option.
4036 fqdn->setDomainName(generated_name, Option6ClientFqdn::FULL);
4037
4038 answer->delOption(D6O_CLIENT_FQDN);
4039 answer->addOption(fqdn);
4040 ctx.hostname_ = generated_name;
4041 } catch (const Exception& ex) {
4043 .arg(answer->getLabel())
4044 .arg(addr.toText())
4045 .arg(ex.what());
4046 }
4047}
4048
4049void
4052 if (d2_mgr.ddnsEnabled()) {
4053 // Updates are enabled, so lets start the sender, passing in
4054 // our error handler.
4055 // This may throw so wherever this is called needs to ready.
4057 this, ph::_1, ph::_2));
4058 }
4059}
4060
4061void
4064 if (d2_mgr.ddnsEnabled()) {
4065 // Updates are enabled, so lets stop the sender
4066 d2_mgr.stopSender();
4067 }
4068}
4069
4070void
4075 arg(result).arg((ncr ? ncr->toText() : " NULL "));
4076 // We cannot communicate with kea-dhcp-ddns, suspend further updates.
4080}
4081
4082// Refer to config_report so it will be embedded in the binary
4084
4085std::string
4087 std::stringstream tmp;
4088
4089 tmp << VERSION;
4090 if (extended) {
4091 tmp << endl << EXTENDED_VERSION << endl;
4092 tmp << "linked with:" << endl;
4093 tmp << Logger::getVersion() << endl;
4094 tmp << CryptoLink::getVersion() << endl;
4095 tmp << "database:" << endl;
4096#ifdef HAVE_MYSQL
4097 tmp << MySqlLeaseMgr::getDBVersion() << endl;
4098#endif
4099#ifdef HAVE_PGSQL
4100 tmp << PgSqlLeaseMgr::getDBVersion() << endl;
4101#endif
4102#ifdef HAVE_CQL
4103 tmp << CqlLeaseMgr::getDBVersion() << endl;
4104#endif
4106
4107 // @todo: more details about database runtime
4108 }
4109
4110 return (tmp.str());
4111}
4112
4113void Dhcpv6Srv::processRSOO(const Pkt6Ptr& query, const Pkt6Ptr& rsp) {
4114
4115 if (query->relay_info_.empty()) {
4116 // RSOO is inserted by relay agents, nothing to do here if it's
4117 // a direct message.
4118 return;
4119 }
4120
4121 // Get RSOO configuration.
4122 ConstCfgRSOOPtr cfg_rsoo = CfgMgr::instance().getCurrentCfg()->getCfgRSOO();
4123
4124 // Let's get over all relays (encapsulation levels). We need to do
4125 // it in the same order as the client packet traversed the relays.
4126 for (int i = query->relay_info_.size(); i > 0 ; --i) {
4127 OptionPtr rsoo_container = query->getRelayOption(D6O_RSOO, i - 1);
4128 if (rsoo_container) {
4129 // There are RSOO options. Let's get through them one by one
4130 // and if it's RSOO-enabled and there's no such option provided yet,
4131 // copy it to the server's response
4132 const OptionCollection& rsoo = rsoo_container->getOptions();
4133 for (OptionCollection::const_iterator opt = rsoo.begin();
4134 opt != rsoo.end(); ++opt) {
4135
4136 // Echo option if it is RSOO enabled option and there is no such
4137 // option added yet.
4138 if (cfg_rsoo->enabled(opt->second->getType()) &&
4139 !rsp->getOption(opt->second->getType())) {
4140 rsp->addOption(opt->second);
4141 }
4142 }
4143 }
4144 }
4145}
4146
4148
4149 if (query->relay_info_.empty()) {
4150 // No relay agent
4151 return (0);
4152 }
4153
4154 // Did the last relay agent add a relay-source-port?
4155 if (query->getRelayOption(D6O_RELAY_SOURCE_PORT, 0)) {
4156 // RFC 8357 section 5.2
4157 return (query->getRemotePort());
4158 }
4159
4160 return (0);
4161}
4162
4163void Dhcpv6Srv::processStatsReceived(const Pkt6Ptr& query) {
4164 // Note that we're not bumping pkt6-received statistic as it was
4165 // increased early in the packet reception code.
4166
4167 string stat_name = "pkt6-unknown-received";
4168 switch (query->getType()) {
4169 case DHCPV6_SOLICIT:
4170 stat_name = "pkt6-solicit-received";
4171 break;
4172 case DHCPV6_ADVERTISE:
4173 // Should not happen, but let's keep a counter for it
4174 stat_name = "pkt6-advertise-received";
4175 break;
4176 case DHCPV6_REQUEST:
4177 stat_name = "pkt6-request-received";
4178 break;
4179 case DHCPV6_CONFIRM:
4180 stat_name = "pkt6-confirm-received";
4181 break;
4182 case DHCPV6_RENEW:
4183 stat_name = "pkt6-renew-received";
4184 break;
4185 case DHCPV6_REBIND:
4186 stat_name = "pkt6-rebind-received";
4187 break;
4188 case DHCPV6_REPLY:
4189 // Should not happen, but let's keep a counter for it
4190 stat_name = "pkt6-reply-received";
4191 break;
4192 case DHCPV6_RELEASE:
4193 stat_name = "pkt6-release-received";
4194 break;
4195 case DHCPV6_DECLINE:
4196 stat_name = "pkt6-decline-received";
4197 break;
4198 case DHCPV6_RECONFIGURE:
4199 stat_name = "pkt6-reconfigure-received";
4200 break;
4202 stat_name = "pkt6-infrequest-received";
4203 break;
4205 stat_name = "pkt6-dhcpv4-query-received";
4206 break;
4208 // Should not happen, but let's keep a counter for it
4209 stat_name = "pkt6-dhcpv4-response-received";
4210 break;
4211 default:
4212 ; // do nothing
4213 }
4214
4215 StatsMgr::instance().addValue(stat_name, static_cast<int64_t>(1));
4216}
4217
4219 // Increase generic counter for sent packets.
4220 StatsMgr::instance().addValue("pkt6-sent", static_cast<int64_t>(1));
4221
4222 // Increase packet type specific counter for packets sent.
4223 string stat_name;
4224 switch (response->getType()) {
4225 case DHCPV6_ADVERTISE:
4226 stat_name = "pkt6-advertise-sent";
4227 break;
4228 case DHCPV6_REPLY:
4229 stat_name = "pkt6-reply-sent";
4230 break;
4232 stat_name = "pkt6-dhcpv4-response-sent";
4233 break;
4234 default:
4235 // That should never happen
4236 return;
4237 }
4238
4239 StatsMgr::instance().addValue(stat_name, static_cast<int64_t>(1));
4240}
4241
4243 return (Hooks.hook_index_buffer6_send_);
4244}
4245
4246bool
4247Dhcpv6Srv::requestedInORO(const Pkt6Ptr& query, const uint16_t code) const {
4249 boost::dynamic_pointer_cast<OptionUint16Array>(query->getOption(D6O_ORO));
4250
4251 if (oro) {
4252 const std::vector<uint16_t>& codes = oro->getValues();
4253 return (std::find(codes.begin(), codes.end(), code) != codes.end());
4254 }
4255
4256 return (false);
4257}
4258
4260 // Dump all of our current packets, anything that is mid-stream
4261 HooksManager::clearParkingLots();
4262}
4263
4265void
4266Dhcpv6Srv::setTeeTimes(uint32_t preferred_lft, const Subnet6Ptr& subnet, Option6IAPtr& resp) {
4267 // Default T2 time to zero.
4268 uint32_t t2_time = 0;
4269
4270 // If T2 is explicitly configured we'll use that value.
4271 if (!subnet->getT2().unspecified()) {
4272 t2_time = subnet->getT2();
4273 } else if (subnet->getCalculateTeeTimes()) {
4274 // Calculating tee times is enabled, so calculate it.
4275 t2_time = static_cast<uint32_t>(round(subnet->getT2Percent() * preferred_lft));
4276 }
4277
4278 // We allow T2 to be any value.
4279 resp->setT2(t2_time);
4280
4281 // Default T1 time to zero.
4282 uint32_t t1_time = 0;
4283
4284 // If T1 is explicitly configured we'll use try value.
4285 if (!subnet->getT1().unspecified()) {
4286 t1_time = subnet->getT1();
4287 } else if (subnet->getCalculateTeeTimes()) {
4288 // Calculating tee times is enabled, so calculate it.
4289 t1_time = static_cast<uint32_t>(round(subnet->getT1Percent() * preferred_lft));
4290 }
4291
4292 // T1 is sane if it is less than or equal to T2.
4293 if (t1_time < t2_time) {
4294 resp->setT1(t1_time);
4295 } else {
4296 // It's either explicitly 0 or insane, leave it to the client
4297 resp->setT1(0);
4298 }
4299}
4300
4301void
4304 const Subnet6Ptr orig_subnet) {
4305 // If the subnet's are the same there's nothing to do.
4306 if ((!ctx.subnet_) || (!orig_subnet) || (orig_subnet->getID() == ctx.subnet_->getID())) {
4307 return;
4308 }
4309
4310 // We get the network for logging only. It should always be set as this a dynamic
4311 // change should only happen within shared-networks. Not having one might not be
4312 // an error if a hook changed the subnet?
4313 SharedNetwork6Ptr network;
4314 orig_subnet->getSharedNetwork(network);
4316 .arg(question->getLabel())
4317 .arg(orig_subnet->toText())
4318 .arg(ctx.subnet_->toText())
4319 .arg(network ? network->getName() : "<no network?>");
4320
4321 // The DDNS parameters may have changed with the subnet, so we need to
4322 // recalculate the client name.
4323
4324 // Save the current DNS values on the context.
4325 std::string prev_hostname = ctx.hostname_;
4326 bool prev_fwd_dns_update = ctx.fwd_dns_update_;
4327 bool prev_rev_dns_update = ctx.rev_dns_update_;
4328
4329 // Remove the current FQDN option from the answer.
4330 answer->delOption(D6O_CLIENT_FQDN);
4331
4332 // Recalculate the client's FQDN. This will replace the FQDN option and
4333 // update the context values for hostname_ and DNS directions.
4334 processClientFqdn(question, answer, ctx);
4335
4336 // If this is a real allocation and the DNS values changed we need to
4337 // update the leases.
4338 if (!ctx.fake_allocation_ &&
4339 ((prev_hostname != ctx.hostname_) ||
4340 (prev_fwd_dns_update != ctx.fwd_dns_update_) ||
4341 (prev_rev_dns_update != ctx.rev_dns_update_))) {
4342 for (Lease6Collection::const_iterator l = ctx.new_leases_.begin();
4343 l != ctx.new_leases_.end(); ++l) {
4344 (*l)->hostname_ = ctx.hostname_;
4345 (*l)->fqdn_fwd_ = ctx.fwd_dns_update_;
4346 (*l)->fqdn_rev_ = ctx.rev_dns_update_;
4347 (*l)->reuseable_valid_lft_ = 0;
4349 }
4350 }
4351}
4352
4353std::list<std::list<std::string>> Dhcpv6Srv::jsonPathsToRedact() const{
4354 static std::list<std::list<std::string>> const list({
4355 {"config-control", "config-databases", "[]"},
4356 {"hooks-libraries", "[]", "parameters", "*"},
4357 {"hosts-database"},
4358 {"hosts-databases", "[]"},
4359 {"lease-database"},
4360 });
4361 return list;
4362}
4363
4364} // namespace dhcp
4365} // 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:2442
void setReservedClientClasses(const Pkt6Ptr &pkt, const AllocEngine::ClientContext6 &ctx)
Assigns classes retrieved from host reservation database.
Definition: dhcp6_srv.cc:3806
Pkt6Ptr processDecline(AllocEngine::ClientContext6 &ctx)
Process incoming Decline message.
Definition: dhcp6_srv.cc:3364
void evaluateClasses(const Pkt6Ptr &pkt, bool depend_on_known)
Evaluate classes.
Definition: dhcp6_srv.cc:3757
Pkt6Ptr processRenew(AllocEngine::ClientContext6 &ctx)
Processes incoming Renew message.
Definition: dhcp6_srv.cc:3180
static void processStatsSent(const Pkt6Ptr &response)
Updates statistics for transmitted packets.
Definition: dhcp6_srv.cc:4218
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:1553
static uint16_t checkRelaySourcePort(const Pkt6Ptr &query)
Used for DHCPv4-over-DHCPv6 too.
Definition: dhcp6_srv.cc:4147
void assignLeases(const Pkt6Ptr &question, Pkt6Ptr &answer, AllocEngine::ClientContext6 &ctx)
Assigns leases.
Definition: dhcp6_srv.cc:1744
void stopD2()
Stops DHCP_DDNS client IO if DDNS updates are enabled.
Definition: dhcp6_srv.cc:4062
void copyClientOptions(const Pkt6Ptr &question, Pkt6Ptr &answer)
Copies required options from client message to server answer.
Definition: dhcp6_srv.cc:1274
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:1122
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:4071
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:3437
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:1187
void requiredClassify(const Pkt6Ptr &pkt, AllocEngine::ClientContext6 &ctx)
Assigns incoming packet to zero or more classes (required pass).
Definition: dhcp6_srv.cc:3840
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:2748
void buildCfgOptionList(const Pkt6Ptr &question, AllocEngine::ClientContext6 &ctx, CfgOptionList &co_list)
Build the configured option list.
Definition: dhcp6_srv.cc:1297
void appendDefaultOptions(const Pkt6Ptr &question, Pkt6Ptr &answer, const CfgOptionList &co_list)
Appends default options to server's answer.
Definition: dhcp6_srv.cc:1290
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:2012
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:4302
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:3825
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:2920
void processDhcp4Query(const Pkt6Ptr &dhcp4_query)
Processes incoming DHCPv4-query message.
Definition: dhcp6_srv.cc:3701
Pkt6Ptr processRebind(AllocEngine::ClientContext6 &ctx)
Processes incoming Rebind message.
Definition: dhcp6_srv.cc:3214
void classifyByVendor(const Pkt6Ptr &pkt, std::string &classes)
Assign class using vendor-class-identifier option.
Definition: dhcp6_srv.cc:3723
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:4266
Pkt6Ptr processRequest(AllocEngine::ClientContext6 &ctx)
Processes incoming Request and returns Reply response.
Definition: dhcp6_srv.cc:3146
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:4353
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:2139
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:3338
void processClientFqdn(const Pkt6Ptr &question, const Pkt6Ptr &answer, AllocEngine::ClientContext6 &ctx)
Processes Client FQDN Option.
Definition: dhcp6_srv.cc:1794
void setStatusCode(boost::shared_ptr< Option6IA > &container, const OptionPtr &status)
A simple utility method that sets the status code.
Definition: dhcp6_srv.cc:3562
static int getHookIndexBuffer6Send()
Returns the index of the buffer6_send hook.
Definition: dhcp6_srv.cc:4242
void sendResponseNoThrow(hooks::CalloutHandlePtr &callout_handle, Pkt6Ptr &query, Pkt6Ptr &rsp)
Process an unparked DHCPv6 packet and sends the response.
Definition: dhcp6_srv.cc:1108
void classifyPacket(const Pkt6Ptr &pkt)
Assigns incoming packet to zero or more classes.
Definition: dhcp6_srv.cc:3745
static HWAddrPtr getMAC(const Pkt6Ptr &pkt)
Attempts to get a MAC/hardware address using configured sources.
Definition: dhcp6_srv.cc:1997
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:3394
void releaseLeases(const Pkt6Ptr &release, Pkt6Ptr &reply, AllocEngine::ClientContext6 &ctx)
Attempts to release received addresses.
Definition: dhcp6_srv.cc:2689
void extendLeases(const Pkt6Ptr &query, Pkt6Ptr &reply, AllocEngine::ClientContext6 &ctx)
Attempts to extend the lifetime of IAs.
Definition: dhcp6_srv.cc:2641
void processRSOO(const Pkt6Ptr &query, const Pkt6Ptr &rsp)
Processes Relay-supplied options, if present.
Definition: dhcp6_srv.cc:4113
static std::string getVersion(bool extended)
returns Kea version on stdout and exit.
Definition: dhcp6_srv.cc:4086
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:2281
Pkt6Ptr processConfirm(AllocEngine::ClientContext6 &ctx)
Processes incoming Confirm message and returns Reply.
Definition: dhcp6_srv.cc:3248
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:1652
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:1367
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:3080
void startD2()
Starts DHCP_DDNS client IO if DDNS updates are enabled.
Definition: dhcp6_srv.cc:4050
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:1254
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:1870
Pkt6Ptr processInfRequest(AllocEngine::ClientContext6 &ctx)
Processes incoming Information-request message.
Definition: dhcp6_srv.cc:3670
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:1668
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:1424
bool declineLease(const Pkt6Ptr &decline, const Lease6Ptr lease, boost::shared_ptr< Option6IA > ia_rsp)
Declines specific IPv6 lease.
Definition: dhcp6_srv.cc:3571
void discardPackets()
Discards parked packets Clears the packet parking lots of all packets.
Definition: dhcp6_srv.cc:4259
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:4083
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.