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