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