dhcp6_srv.cc 106 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696
  1. // Copyright (C) 2011-2014 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <config.h>
  15. #include <asiolink/io_address.h>
  16. #include <dhcp_ddns/ncr_msg.h>
  17. #include <dhcp/dhcp6.h>
  18. #include <dhcp/docsis3_option_defs.h>
  19. #include <dhcp/duid.h>
  20. #include <dhcp/iface_mgr.h>
  21. #include <dhcp/libdhcp++.h>
  22. #include <dhcp/option6_addrlst.h>
  23. #include <dhcp/option6_client_fqdn.h>
  24. #include <dhcp/option6_ia.h>
  25. #include <dhcp/option6_iaaddr.h>
  26. #include <dhcp/option6_iaprefix.h>
  27. #include <dhcp/option_custom.h>
  28. #include <dhcp/option_vendor.h>
  29. #include <dhcp/option_vendor_class.h>
  30. #include <dhcp/option_int_array.h>
  31. #include <dhcp/pkt6.h>
  32. #include <dhcp6/dhcp6_log.h>
  33. #include <dhcp6/dhcp6_srv.h>
  34. #include <dhcpsrv/callout_handle_store.h>
  35. #include <dhcpsrv/cfgmgr.h>
  36. #include <dhcpsrv/lease_mgr.h>
  37. #include <dhcpsrv/lease_mgr_factory.h>
  38. #include <dhcpsrv/subnet.h>
  39. #include <dhcpsrv/utils.h>
  40. #include <exceptions/exceptions.h>
  41. #include <hooks/callout_handle.h>
  42. #include <hooks/hooks_manager.h>
  43. #include <util/encode/hex.h>
  44. #include <util/io_utilities.h>
  45. #include <util/range_utilities.h>
  46. #include <boost/bind.hpp>
  47. #include <boost/foreach.hpp>
  48. #include <boost/tokenizer.hpp>
  49. #include <boost/algorithm/string/erase.hpp>
  50. #include <stdlib.h>
  51. #include <time.h>
  52. #include <iomanip>
  53. #include <fstream>
  54. #include <sstream>
  55. using namespace isc;
  56. using namespace isc::asiolink;
  57. using namespace isc::dhcp_ddns;
  58. using namespace isc::dhcp;
  59. using namespace isc::hooks;
  60. using namespace isc::util;
  61. using namespace std;
  62. namespace {
  63. /// Structure that holds registered hook indexes
  64. struct Dhcp6Hooks {
  65. int hook_index_buffer6_receive_;///< index for "buffer6_receive" hook point
  66. int hook_index_pkt6_receive_; ///< index for "pkt6_receive" hook point
  67. int hook_index_subnet6_select_; ///< index for "subnet6_select" hook point
  68. int hook_index_lease6_renew_; ///< index for "lease6_renew" hook point
  69. int hook_index_lease6_rebind_; ///< index for "lease6_rebind" hook point
  70. int hook_index_lease6_release_; ///< index for "lease6_release" hook point
  71. int hook_index_pkt6_send_; ///< index for "pkt6_send" hook point
  72. int hook_index_buffer6_send_; ///< index for "buffer6_send" hook point
  73. /// Constructor that registers hook points for DHCPv6 engine
  74. Dhcp6Hooks() {
  75. hook_index_buffer6_receive_= HooksManager::registerHook("buffer6_receive");
  76. hook_index_pkt6_receive_ = HooksManager::registerHook("pkt6_receive");
  77. hook_index_subnet6_select_ = HooksManager::registerHook("subnet6_select");
  78. hook_index_lease6_renew_ = HooksManager::registerHook("lease6_renew");
  79. hook_index_lease6_rebind_ = HooksManager::registerHook("lease6_rebind");
  80. hook_index_lease6_release_ = HooksManager::registerHook("lease6_release");
  81. hook_index_pkt6_send_ = HooksManager::registerHook("pkt6_send");
  82. hook_index_buffer6_send_ = HooksManager::registerHook("buffer6_send");
  83. }
  84. };
  85. // Declare a Hooks object. As this is outside any function or method, it
  86. // will be instantiated (and the constructor run) when the module is loaded.
  87. // As a result, the hook indexes will be defined before any method in this
  88. // module is called.
  89. Dhcp6Hooks Hooks;
  90. }; // anonymous namespace
  91. namespace isc {
  92. namespace dhcp {
  93. const std::string Dhcpv6Srv::VENDOR_CLASS_PREFIX("VENDOR_CLASS_");
  94. /// @brief file name of a server-id file
  95. ///
  96. /// Server must store its duid in persistent storage that must not change
  97. /// between restarts. This is name of the file that is created in dataDir
  98. /// (see isc::dhcp::CfgMgr::getDataDir()). It is a text file that uses
  99. /// double digit hex values separated by colons format, e.g.
  100. /// 01:ff:02:03:06:80:90:ab:cd:ef. Server will create it during first
  101. /// run and then use it afterwards.
  102. static const char* SERVER_DUID_FILE = "kea-dhcp6-serverid";
  103. Dhcpv6Srv::Dhcpv6Srv(uint16_t port)
  104. :alloc_engine_(), serverid_(), port_(port), shutdown_(true)
  105. {
  106. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_START, DHCP6_OPEN_SOCKET).arg(port);
  107. // Initialize objects required for DHCP server operation.
  108. try {
  109. // Port 0 is used for testing purposes where in most cases we don't
  110. // rely on the physical interfaces. Therefore, it should be possible
  111. // to create an object even when there are no usable interfaces.
  112. if ((port > 0) && (IfaceMgr::instance().countIfaces() == 0)) {
  113. LOG_ERROR(dhcp6_logger, DHCP6_NO_INTERFACES);
  114. return;
  115. }
  116. string duid_file = CfgMgr::instance().getDataDir() + "/" + string(SERVER_DUID_FILE);
  117. if (loadServerID(duid_file)) {
  118. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_START, DHCP6_SERVERID_LOADED)
  119. .arg(duidToString(getServerID()))
  120. .arg(duid_file);
  121. } else {
  122. generateServerID();
  123. LOG_INFO(dhcp6_logger, DHCP6_SERVERID_GENERATED)
  124. .arg(duidToString(getServerID()))
  125. .arg(duid_file);
  126. if (!writeServerID(duid_file)) {
  127. LOG_WARN(dhcp6_logger, DHCP6_SERVERID_WRITE_FAIL)
  128. .arg(duid_file);
  129. }
  130. }
  131. // Instantiate allocation engine
  132. alloc_engine_.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 100));
  133. /// @todo call loadLibraries() when handling configuration changes
  134. } catch (const std::exception &e) {
  135. LOG_ERROR(dhcp6_logger, DHCP6_SRV_CONSTRUCT_ERROR).arg(e.what());
  136. return;
  137. }
  138. // All done, so can proceed
  139. shutdown_ = false;
  140. }
  141. Dhcpv6Srv::~Dhcpv6Srv() {
  142. IfaceMgr::instance().closeSockets();
  143. LeaseMgrFactory::destroy();
  144. }
  145. void Dhcpv6Srv::shutdown() {
  146. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_SHUTDOWN_REQUEST);
  147. shutdown_ = true;
  148. }
  149. Pkt6Ptr Dhcpv6Srv::receivePacket(int timeout) {
  150. return (IfaceMgr::instance().receive6(timeout));
  151. }
  152. void Dhcpv6Srv::sendPacket(const Pkt6Ptr& packet) {
  153. IfaceMgr::instance().send(packet);
  154. }
  155. bool
  156. Dhcpv6Srv::testServerID(const Pkt6Ptr& pkt) {
  157. /// @todo Currently we always check server identifier regardless if
  158. /// it is allowed in the received message or not (per RFC3315).
  159. /// If the server identifier is not allowed in the message, the
  160. /// sanityCheck function should deal with it. We may rethink this
  161. /// design if we decide that it is appropriate to check at this stage
  162. /// of message processing that the server identifier must or must not
  163. /// be present. In such case however, the logic checking server id
  164. /// will have to be removed from sanityCheck and placed here instead,
  165. /// to avoid duplicate checks.
  166. OptionPtr server_id = pkt->getOption(D6O_SERVERID);
  167. if (server_id){
  168. // Let us test received ServerID if it is same as ServerID
  169. // which is beeing used by server
  170. if (getServerID()->getData() != server_id->getData()){
  171. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL_DATA, DHCP6_PACKET_MISMATCH_SERVERID_DROP)
  172. .arg(pkt->getName())
  173. .arg(pkt->getTransid())
  174. .arg(pkt->getIface());
  175. return (false);
  176. }
  177. }
  178. // retun True if: no serverid received or ServerIDs matching
  179. return (true);
  180. }
  181. bool
  182. Dhcpv6Srv::testUnicast(const Pkt6Ptr& pkt) const {
  183. switch (pkt->getType()) {
  184. case DHCPV6_SOLICIT:
  185. case DHCPV6_CONFIRM:
  186. case DHCPV6_REBIND:
  187. case DHCPV6_INFORMATION_REQUEST:
  188. if (pkt->relay_info_.empty() && !pkt->getLocalAddr().isV6Multicast()) {
  189. return (false);
  190. }
  191. break;
  192. default:
  193. // do nothing
  194. ;
  195. }
  196. return (true);
  197. }
  198. bool Dhcpv6Srv::run() {
  199. while (!shutdown_) {
  200. /// @todo Calculate actual timeout to the next event (e.g. lease
  201. /// expiration) once we have lease database. The idea here is that
  202. /// it is possible to do everything in a single process/thread.
  203. /// For now, we are just calling select for 1000 seconds. There
  204. /// were some issues reported on some systems when calling select()
  205. /// with too large values. Unfortunately, I don't recall the details.
  206. //cppcheck-suppress variableScope This is temporary anyway
  207. const int timeout = 1000;
  208. // client's message and server's response
  209. Pkt6Ptr query;
  210. Pkt6Ptr rsp;
  211. try {
  212. query = receivePacket(timeout);
  213. } catch (const std::exception& e) {
  214. LOG_ERROR(dhcp6_logger, DHCP6_PACKET_RECEIVE_FAIL).arg(e.what());
  215. }
  216. // Handle next signal received by the process. It must be called after
  217. // an attempt to receive a packet to properly handle server shut down.
  218. // The SIGTERM or SIGINT will be received prior to, or during execution
  219. // of select() (select is invoked by recivePacket()). When that happens,
  220. // select will be interrupted. The signal handler will be invoked
  221. // immediately after select(). The handler will set the shutdown flag
  222. // and cause the process to terminate before the next select() function
  223. // is called. If the function was called before receivePacket the
  224. // process could wait up to the duration of timeout of select() to
  225. // terminate.
  226. handleSignal();
  227. // Timeout may be reached or signal received, which breaks select()
  228. // with no packet received
  229. if (!query) {
  230. continue;
  231. }
  232. // In order to parse the DHCP options, the server needs to use some
  233. // configuration information such as: existing option spaces, option
  234. // definitions etc. This is the kind of information which is not
  235. // available in the libdhcp, so we need to supply our own implementation
  236. // of the option parsing function here, which would rely on the
  237. // configuration data.
  238. query->setCallback(boost::bind(&Dhcpv6Srv::unpackOptions, this, _1, _2,
  239. _3, _4, _5));
  240. bool skip_unpack = false;
  241. // The packet has just been received so contains the uninterpreted wire
  242. // data; execute callouts registered for buffer6_receive.
  243. if (HooksManager::calloutsPresent(Hooks.hook_index_buffer6_receive_)) {
  244. CalloutHandlePtr callout_handle = getCalloutHandle(query);
  245. // Delete previously set arguments
  246. callout_handle->deleteAllArguments();
  247. // Pass incoming packet as argument
  248. callout_handle->setArgument("query6", query);
  249. // Call callouts
  250. HooksManager::callCallouts(Hooks.hook_index_buffer6_receive_, *callout_handle);
  251. // Callouts decided to skip the next processing step. The next
  252. // processing step would to parse the packet, so skip at this
  253. // stage means that callouts did the parsing already, so server
  254. // should skip parsing.
  255. if (callout_handle->getSkip()) {
  256. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_HOOKS, DHCP6_HOOK_BUFFER_RCVD_SKIP);
  257. skip_unpack = true;
  258. }
  259. callout_handle->getArgument("query6", query);
  260. }
  261. // Unpack the packet information unless the buffer6_receive callouts
  262. // indicated they did it
  263. if (!skip_unpack) {
  264. if (!query->unpack()) {
  265. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL,
  266. DHCP6_PACKET_PARSE_FAIL);
  267. continue;
  268. }
  269. }
  270. // Check if received query carries server identifier matching
  271. // server identifier being used by the server.
  272. if (!testServerID(query)) {
  273. continue;
  274. }
  275. // Check if the received query has been sent to unicast or multicast.
  276. // The Solicit, Confirm, Rebind and Information Request will be
  277. // discarded if sent to unicast address.
  278. if (!testUnicast(query)) {
  279. continue;
  280. }
  281. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, DHCP6_PACKET_RECEIVED)
  282. .arg(query->getName());
  283. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL_DATA, DHCP6_QUERY_DATA)
  284. .arg(static_cast<int>(query->getType()))
  285. .arg(query->getBuffer().getLength())
  286. .arg(query->toText());
  287. // At this point the information in the packet has been unpacked into
  288. // the various packet fields and option objects has been cretated.
  289. // Execute callouts registered for packet6_receive.
  290. if (HooksManager::calloutsPresent(Hooks.hook_index_pkt6_receive_)) {
  291. CalloutHandlePtr callout_handle = getCalloutHandle(query);
  292. // Delete previously set arguments
  293. callout_handle->deleteAllArguments();
  294. // Pass incoming packet as argument
  295. callout_handle->setArgument("query6", query);
  296. // Call callouts
  297. HooksManager::callCallouts(Hooks.hook_index_pkt6_receive_, *callout_handle);
  298. // Callouts decided to skip the next processing step. The next
  299. // processing step would to process the packet, so skip at this
  300. // stage means drop.
  301. if (callout_handle->getSkip()) {
  302. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_HOOKS, DHCP6_HOOK_PACKET_RCVD_SKIP);
  303. continue;
  304. }
  305. callout_handle->getArgument("query6", query);
  306. }
  307. // Assign this packet to a class, if possible
  308. classifyPacket(query);
  309. try {
  310. NameChangeRequestPtr ncr;
  311. switch (query->getType()) {
  312. case DHCPV6_SOLICIT:
  313. rsp = processSolicit(query);
  314. break;
  315. case DHCPV6_REQUEST:
  316. rsp = processRequest(query);
  317. break;
  318. case DHCPV6_RENEW:
  319. rsp = processRenew(query);
  320. break;
  321. case DHCPV6_REBIND:
  322. rsp = processRebind(query);
  323. break;
  324. case DHCPV6_CONFIRM:
  325. rsp = processConfirm(query);
  326. break;
  327. case DHCPV6_RELEASE:
  328. rsp = processRelease(query);
  329. break;
  330. case DHCPV6_DECLINE:
  331. rsp = processDecline(query);
  332. break;
  333. case DHCPV6_INFORMATION_REQUEST:
  334. rsp = processInfRequest(query);
  335. break;
  336. default:
  337. // We received a packet type that we do not recognize.
  338. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_UNKNOWN_MSG_RECEIVED)
  339. .arg(static_cast<int>(query->getType()))
  340. .arg(query->getIface());
  341. // Only action is to output a message if debug is enabled,
  342. // and that will be covered by the debug statement before
  343. // the "switch" statement.
  344. ;
  345. }
  346. } catch (const RFCViolation& e) {
  347. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_REQUIRED_OPTIONS_CHECK_FAIL)
  348. .arg(query->getName())
  349. .arg(query->getRemoteAddr().toText())
  350. .arg(e.what());
  351. } catch (const isc::Exception& e) {
  352. // Catch-all exception (at least for ones based on the isc Exception
  353. // class, which covers more or less all that are explicitly raised
  354. // in the Kea code). Just log the problem and ignore the packet.
  355. // (The problem is logged as a debug message because debug is
  356. // disabled by default - it prevents a DDOS attack based on the
  357. // sending of problem packets.)
  358. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_PACKET_PROCESS_FAIL)
  359. .arg(query->getName())
  360. .arg(query->getRemoteAddr().toText())
  361. .arg(e.what());
  362. }
  363. if (rsp) {
  364. rsp->setRemoteAddr(query->getRemoteAddr());
  365. rsp->setLocalAddr(query->getLocalAddr());
  366. if (rsp->relay_info_.empty()) {
  367. // Direct traffic, send back to the client directly
  368. rsp->setRemotePort(DHCP6_CLIENT_PORT);
  369. } else {
  370. // Relayed traffic, send back to the relay agent
  371. rsp->setRemotePort(DHCP6_SERVER_PORT);
  372. }
  373. rsp->setLocalPort(DHCP6_SERVER_PORT);
  374. rsp->setIndex(query->getIndex());
  375. rsp->setIface(query->getIface());
  376. // Specifies if server should do the packing
  377. bool skip_pack = false;
  378. // Server's reply packet now has all options and fields set.
  379. // Options are represented by individual objects, but the
  380. // output wire data has not been prepared yet.
  381. // Execute all callouts registered for packet6_send
  382. if (HooksManager::calloutsPresent(Hooks.hook_index_pkt6_send_)) {
  383. CalloutHandlePtr callout_handle = getCalloutHandle(query);
  384. // Delete all previous arguments
  385. callout_handle->deleteAllArguments();
  386. // Set our response
  387. callout_handle->setArgument("response6", rsp);
  388. // Call all installed callouts
  389. HooksManager::callCallouts(Hooks.hook_index_pkt6_send_, *callout_handle);
  390. // Callouts decided to skip the next processing step. The next
  391. // processing step would to pack the packet (create wire data).
  392. // That step will be skipped if any callout sets skip flag.
  393. // It essentially means that the callout already did packing,
  394. // so the server does not have to do it again.
  395. if (callout_handle->getSkip()) {
  396. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_HOOKS, DHCP6_HOOK_PACKET_SEND_SKIP);
  397. skip_pack = true;
  398. }
  399. }
  400. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL_DATA,
  401. DHCP6_RESPONSE_DATA)
  402. .arg(static_cast<int>(rsp->getType())).arg(rsp->toText());
  403. if (!skip_pack) {
  404. try {
  405. rsp->pack();
  406. } catch (const std::exception& e) {
  407. LOG_ERROR(dhcp6_logger, DHCP6_PACK_FAIL)
  408. .arg(e.what());
  409. continue;
  410. }
  411. }
  412. try {
  413. // Now all fields and options are constructed into output wire buffer.
  414. // Option objects modification does not make sense anymore. Hooks
  415. // can only manipulate wire buffer at this stage.
  416. // Let's execute all callouts registered for buffer6_send
  417. if (HooksManager::calloutsPresent(Hooks.hook_index_buffer6_send_)) {
  418. CalloutHandlePtr callout_handle = getCalloutHandle(query);
  419. // Delete previously set arguments
  420. callout_handle->deleteAllArguments();
  421. // Pass incoming packet as argument
  422. callout_handle->setArgument("response6", rsp);
  423. // Call callouts
  424. HooksManager::callCallouts(Hooks.hook_index_buffer6_send_, *callout_handle);
  425. // Callouts decided to skip the next processing step. The next
  426. // processing step would to parse the packet, so skip at this
  427. // stage means drop.
  428. if (callout_handle->getSkip()) {
  429. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_HOOKS, DHCP6_HOOK_BUFFER_SEND_SKIP);
  430. continue;
  431. }
  432. callout_handle->getArgument("response6", rsp);
  433. }
  434. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL_DATA,
  435. DHCP6_RESPONSE_DATA)
  436. .arg(static_cast<int>(rsp->getType())).arg(rsp->toText());
  437. sendPacket(rsp);
  438. } catch (const std::exception& e) {
  439. LOG_ERROR(dhcp6_logger, DHCP6_PACKET_SEND_FAIL)
  440. .arg(e.what());
  441. }
  442. }
  443. }
  444. return (true);
  445. }
  446. bool Dhcpv6Srv::loadServerID(const std::string& file_name) {
  447. // load content of the file into a string
  448. fstream f(file_name.c_str(), ios::in);
  449. if (!f.is_open()) {
  450. return (false);
  451. }
  452. string hex_string;
  453. f >> hex_string;
  454. f.close();
  455. // remove any spaces
  456. boost::algorithm::erase_all(hex_string, " ");
  457. // now remove :
  458. /// @todo: We should check first if the format is sane.
  459. /// Otherwise 1:2:3:4 will be converted to 0x12, 0x34
  460. boost::algorithm::erase_all(hex_string, ":");
  461. std::vector<uint8_t> bin;
  462. // Decode the hex string and store it in bin (which happens
  463. // to be OptionBuffer format)
  464. isc::util::encode::decodeHex(hex_string, bin);
  465. // Now create server-id option
  466. serverid_.reset(new Option(Option::V6, D6O_SERVERID, bin));
  467. return (true);
  468. }
  469. std::string
  470. Dhcpv6Srv::duidToString(const OptionPtr& opt) {
  471. stringstream tmp;
  472. OptionBuffer data = opt->getData();
  473. bool colon = false;
  474. for (OptionBufferConstIter it = data.begin(); it != data.end(); ++it) {
  475. if (colon) {
  476. tmp << ":";
  477. }
  478. tmp << hex << setw(2) << setfill('0') << static_cast<uint16_t>(*it);
  479. if (!colon) {
  480. colon = true;
  481. }
  482. }
  483. return tmp.str();
  484. }
  485. bool
  486. Dhcpv6Srv::writeServerID(const std::string& file_name) {
  487. fstream f(file_name.c_str(), ios::out | ios::trunc);
  488. if (!f.good()) {
  489. return (false);
  490. }
  491. f << duidToString(getServerID());
  492. f.close();
  493. return (true);
  494. }
  495. void
  496. Dhcpv6Srv::generateServerID() {
  497. /// @todo: This code implements support for DUID-LLT (the recommended one).
  498. /// We should eventually add support for other DUID types: DUID-LL, DUID-EN
  499. /// and DUID-UUID
  500. const IfaceMgr::IfaceCollection& ifaces = IfaceMgr::instance().getIfaces();
  501. // Let's find suitable interface.
  502. for (IfaceMgr::IfaceCollection::const_iterator iface = ifaces.begin();
  503. iface != ifaces.end(); ++iface) {
  504. // All the following checks could be merged into one multi-condition
  505. // statement, but let's keep them separated as perhaps one day
  506. // we will grow knobs to selectively turn them on or off. Also,
  507. // this code is used only *once* during first start on a new machine
  508. // and then server-id is stored. (or at least it will be once
  509. // DUID storage is implemented)
  510. // I wish there was a this_is_a_real_physical_interface flag...
  511. // MAC address should be at least 6 bytes. Although there is no such
  512. // requirement in any RFC, all decent physical interfaces (Ethernet,
  513. // WiFi, Infiniband, etc.) have 6 bytes long MAC address. We want to
  514. // base our DUID on real hardware address, rather than virtual
  515. // interface that pretends that underlying IP address is its MAC.
  516. if (iface->getMacLen() < MIN_MAC_LEN) {
  517. continue;
  518. }
  519. // Let's don't use loopback.
  520. if (iface->flag_loopback_) {
  521. continue;
  522. }
  523. // Let's skip downed interfaces. It is better to use working ones.
  524. if (!iface->flag_up_) {
  525. continue;
  526. }
  527. // Some interfaces (like lo on Linux) report 6-bytes long
  528. // MAC address 00:00:00:00:00:00. Let's not use such weird interfaces
  529. // to generate DUID.
  530. if (isRangeZero(iface->getMac(), iface->getMac() + iface->getMacLen())) {
  531. continue;
  532. }
  533. // Ok, we have useful MAC. Let's generate DUID-LLT based on
  534. // it. See RFC3315, Section 9.2 for details.
  535. // DUID uses seconds since midnight of 01-01-2000, time() returns
  536. // seconds since 01-01-1970. DUID_TIME_EPOCH substution corrects that.
  537. time_t seconds = time(NULL);
  538. seconds -= DUID_TIME_EPOCH;
  539. OptionBuffer srvid(8 + iface->getMacLen());
  540. // We know that the buffer is more than 8 bytes long at this point.
  541. writeUint16(DUID::DUID_LLT, &srvid[0], 2);
  542. writeUint16(HWTYPE_ETHERNET, &srvid[2], 2);
  543. writeUint32(static_cast<uint32_t>(seconds), &srvid[4], 4);
  544. memcpy(&srvid[8], iface->getMac(), iface->getMacLen());
  545. serverid_ = OptionPtr(new Option(Option::V6, D6O_SERVERID,
  546. srvid.begin(), srvid.end()));
  547. return;
  548. }
  549. // If we reached here, there are no suitable interfaces found.
  550. // Either interface detection is not supported on this platform or
  551. // this is really weird box. Let's use DUID-EN instead.
  552. // See Section 9.3 of RFC3315 for details.
  553. OptionBuffer srvid(12);
  554. writeUint16(DUID::DUID_EN, &srvid[0], srvid.size());
  555. writeUint32(ENTERPRISE_ID_ISC, &srvid[2], srvid.size() - 2);
  556. // Length of the identifier is company specific. I hereby declare
  557. // ISC "standard" of 6 bytes long pseudo-random numbers.
  558. srandom(time(NULL));
  559. fillRandom(&srvid[6], &srvid[12]);
  560. serverid_ = OptionPtr(new Option(Option::V6, D6O_SERVERID,
  561. srvid.begin(), srvid.end()));
  562. }
  563. void
  564. Dhcpv6Srv::copyDefaultOptions(const Pkt6Ptr& question, Pkt6Ptr& answer) {
  565. // Add client-id.
  566. OptionPtr clientid = question->getOption(D6O_CLIENTID);
  567. if (clientid) {
  568. answer->addOption(clientid);
  569. }
  570. /// @todo: Should throw if there is no client-id (except anonymous INF-REQUEST)
  571. // If this is a relayed message, we need to copy relay information
  572. if (!question->relay_info_.empty()) {
  573. answer->copyRelayInfo(question);
  574. }
  575. }
  576. void
  577. Dhcpv6Srv::appendDefaultOptions(const Pkt6Ptr&, Pkt6Ptr& answer) {
  578. // add server-id
  579. answer->addOption(getServerID());
  580. }
  581. void
  582. Dhcpv6Srv::appendRequestedOptions(const Pkt6Ptr& question, Pkt6Ptr& answer) {
  583. // Get the configured subnet suitable for the incoming packet.
  584. Subnet6Ptr subnet = selectSubnet(question);
  585. // Leave if there is no subnet matching the incoming packet.
  586. // There is no need to log the error message here because
  587. // it will be logged in the assignLease() when it fails to
  588. // pick the suitable subnet. We don't want to duplicate
  589. // error messages in such case.
  590. if (!subnet) {
  591. return;
  592. }
  593. // Client requests some options using ORO option. Try to
  594. // get this option from client's message.
  595. boost::shared_ptr<OptionIntArray<uint16_t> > option_oro =
  596. boost::dynamic_pointer_cast<OptionIntArray<uint16_t> >(question->getOption(D6O_ORO));
  597. // Option ORO not found. Don't do anything then.
  598. if (!option_oro) {
  599. return;
  600. }
  601. // Get the list of options that client requested.
  602. const std::vector<uint16_t>& requested_opts = option_oro->getValues();
  603. BOOST_FOREACH(uint16_t opt, requested_opts) {
  604. Subnet::OptionDescriptor desc = subnet->getOptionDescriptor("dhcp6", opt);
  605. if (desc.option) {
  606. answer->addOption(desc.option);
  607. }
  608. }
  609. }
  610. void
  611. Dhcpv6Srv::appendRequestedVendorOptions(const Pkt6Ptr& question, Pkt6Ptr& answer) {
  612. // Get the configured subnet suitable for the incoming packet.
  613. Subnet6Ptr subnet = selectSubnet(question);
  614. // Leave if there is no subnet matching the incoming packet.
  615. // There is no need to log the error message here because
  616. // it will be logged in the assignLease() when it fails to
  617. // pick the suitable subnet. We don't want to duplicate
  618. // error messages in such case.
  619. if (!subnet) {
  620. return;
  621. }
  622. // Try to get the vendor option
  623. boost::shared_ptr<OptionVendor> vendor_req =
  624. boost::dynamic_pointer_cast<OptionVendor>(question->getOption(D6O_VENDOR_OPTS));
  625. if (!vendor_req) {
  626. return;
  627. }
  628. // Let's try to get ORO within that vendor-option
  629. /// @todo This is very specific to vendor-id=4491 (Cable Labs). Other vendors
  630. /// may have different policies.
  631. boost::shared_ptr<OptionUint16Array> oro =
  632. boost::dynamic_pointer_cast<OptionUint16Array>(vendor_req->getOption(DOCSIS3_V6_ORO));
  633. // Option ORO not found. Don't do anything then.
  634. if (!oro) {
  635. return;
  636. }
  637. uint32_t vendor_id = vendor_req->getVendorId();
  638. boost::shared_ptr<OptionVendor> vendor_rsp(new OptionVendor(Option::V6, vendor_id));
  639. // Get the list of options that client requested.
  640. bool added = false;
  641. const std::vector<uint16_t>& requested_opts = oro->getValues();
  642. BOOST_FOREACH(uint16_t opt, requested_opts) {
  643. Subnet::OptionDescriptor desc = subnet->getVendorOptionDescriptor(vendor_id, opt);
  644. if (desc.option) {
  645. vendor_rsp->addOption(desc.option);
  646. added = true;
  647. }
  648. }
  649. if (added) {
  650. answer->addOption(vendor_rsp);
  651. }
  652. }
  653. OptionPtr
  654. Dhcpv6Srv::createStatusCode(uint16_t code, const std::string& text) {
  655. // @todo This function uses OptionCustom class to manage contents
  656. // of the data fields. Since this this option is frequently used
  657. // it may be good to implement dedicated class to avoid performance
  658. // impact.
  659. // Get the definition of the option holding status code.
  660. OptionDefinitionPtr status_code_def =
  661. LibDHCP::getOptionDef(Option::V6, D6O_STATUS_CODE);
  662. // This definition is assumed to be initialized in LibDHCP.
  663. assert(status_code_def);
  664. // As there is no dedicated class to represent Status Code
  665. // the OptionCustom class is used here instead.
  666. OptionCustomPtr option_status =
  667. OptionCustomPtr(new OptionCustom(*status_code_def, Option::V6));
  668. assert(option_status);
  669. // Set status code to 'code' (0 - means data field #0).
  670. option_status->writeInteger(code, 0);
  671. // Set a message (1 - means data field #1).
  672. option_status->writeString(text, 1);
  673. return (option_status);
  674. }
  675. void
  676. Dhcpv6Srv::sanityCheck(const Pkt6Ptr& pkt, RequirementLevel clientid,
  677. RequirementLevel serverid) {
  678. OptionCollection client_ids = pkt->getOptions(D6O_CLIENTID);
  679. switch (clientid) {
  680. case MANDATORY:
  681. if (client_ids.size() != 1) {
  682. isc_throw(RFCViolation, "Exactly 1 client-id option expected in "
  683. << pkt->getName() << ", but " << client_ids.size()
  684. << " received");
  685. }
  686. break;
  687. case OPTIONAL:
  688. if (client_ids.size() > 1) {
  689. isc_throw(RFCViolation, "Too many (" << client_ids.size()
  690. << ") client-id options received in " << pkt->getName());
  691. }
  692. break;
  693. case FORBIDDEN:
  694. // doesn't make sense - client-id is always allowed
  695. break;
  696. }
  697. OptionCollection server_ids = pkt->getOptions(D6O_SERVERID);
  698. switch (serverid) {
  699. case FORBIDDEN:
  700. if (!server_ids.empty()) {
  701. isc_throw(RFCViolation, "Server-id option was not expected, but "
  702. << server_ids.size() << " received in " << pkt->getName());
  703. }
  704. break;
  705. case MANDATORY:
  706. if (server_ids.size() != 1) {
  707. isc_throw(RFCViolation, "Invalid number of server-id options received ("
  708. << server_ids.size() << "), exactly 1 expected in message "
  709. << pkt->getName());
  710. }
  711. break;
  712. case OPTIONAL:
  713. if (server_ids.size() > 1) {
  714. isc_throw(RFCViolation, "Too many (" << server_ids.size()
  715. << ") server-id options received in " << pkt->getName());
  716. }
  717. }
  718. }
  719. Subnet6Ptr
  720. Dhcpv6Srv::selectSubnet(const Pkt6Ptr& question) {
  721. Subnet6Ptr subnet;
  722. if (question->relay_info_.empty()) {
  723. // This is a direct (non-relayed) message
  724. // Try to find a subnet if received packet from a directly connected client
  725. subnet = CfgMgr::instance().getSubnet6(question->getIface(),
  726. question->classes_);
  727. if (!subnet) {
  728. // If no subnet was found, try to find it based on remote address
  729. subnet = CfgMgr::instance().getSubnet6(question->getRemoteAddr(),
  730. question->classes_);
  731. }
  732. } else {
  733. // This is a relayed message
  734. OptionPtr interface_id = question->getAnyRelayOption(D6O_INTERFACE_ID,
  735. Pkt6::RELAY_GET_FIRST);
  736. if (interface_id) {
  737. subnet = CfgMgr::instance().getSubnet6(interface_id,
  738. question->classes_);
  739. }
  740. if (!subnet) {
  741. // If no interface-id was specified (or not configured on server),
  742. // let's try address matching
  743. IOAddress link_addr = question->relay_info_.back().linkaddr_;
  744. // if relay filled in link_addr field, then let's use it
  745. if (link_addr != IOAddress("::")) {
  746. subnet = CfgMgr::instance().getSubnet6(link_addr,
  747. question->classes_, true);
  748. }
  749. }
  750. }
  751. // Let's execute all callouts registered for subnet6_receive
  752. if (HooksManager::calloutsPresent(Hooks.hook_index_subnet6_select_)) {
  753. CalloutHandlePtr callout_handle = getCalloutHandle(question);
  754. // We're reusing callout_handle from previous calls
  755. callout_handle->deleteAllArguments();
  756. // Set new arguments
  757. callout_handle->setArgument("query6", question);
  758. callout_handle->setArgument("subnet6", subnet);
  759. // We pass pointer to const collection for performance reasons.
  760. // Otherwise we would get a non-trivial performance penalty each
  761. // time subnet6_select is called.
  762. callout_handle->setArgument("subnet6collection", CfgMgr::instance().getSubnets6());
  763. // Call user (and server-side) callouts
  764. HooksManager::callCallouts(Hooks.hook_index_subnet6_select_, *callout_handle);
  765. // Callouts decided to skip this step. This means that no subnet will be
  766. // selected. Packet processing will continue, but it will be severly limited
  767. // (i.e. only global options will be assigned)
  768. if (callout_handle->getSkip()) {
  769. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_HOOKS, DHCP6_HOOK_SUBNET6_SELECT_SKIP);
  770. return (Subnet6Ptr());
  771. }
  772. // Use whatever subnet was specified by the callout
  773. callout_handle->getArgument("subnet6", subnet);
  774. }
  775. return (subnet);
  776. }
  777. void
  778. Dhcpv6Srv::assignLeases(const Pkt6Ptr& question, Pkt6Ptr& answer) {
  779. // We need to allocate addresses for all IA_NA options in the client's
  780. // question (i.e. SOLICIT or REQUEST) message.
  781. // @todo add support for IA_TA
  782. // We need to select a subnet the client is connected in.
  783. Subnet6Ptr subnet = selectSubnet(question);
  784. if (!subnet) {
  785. // This particular client is out of luck today. We do not have
  786. // information about the subnet he is connected to. This likely means
  787. // misconfiguration of the server (or some relays). We will continue to
  788. // process this message, but our response will be almost useless: no
  789. // addresses or prefixes, no subnet specific configuration etc. The only
  790. // thing this client can get is some global information (like DNS
  791. // servers).
  792. LOG_WARN(dhcp6_logger, DHCP6_SUBNET_SELECTION_FAILED)
  793. .arg(question->getRemoteAddr().toText())
  794. .arg(question->getName());
  795. } else {
  796. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL_DATA, DHCP6_SUBNET_SELECTED)
  797. .arg(subnet->toText());
  798. }
  799. // @todo: We should implement Option6Duid some day, but we can do without it
  800. // just fine for now
  801. // Let's find client's DUID. Client is supposed to include its client-id
  802. // option almost all the time (the only exception is an anonymous inf-request,
  803. // but that is mostly a theoretical case). Our allocation engine needs DUID
  804. // and will refuse to allocate anything to anonymous clients.
  805. DuidPtr duid;
  806. OptionPtr opt_duid = question->getOption(D6O_CLIENTID);
  807. if (opt_duid) {
  808. duid = DuidPtr(new DUID(opt_duid->getData()));
  809. } else {
  810. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_CLIENTID_MISSING);
  811. // Let's drop the message. This client is not sane.
  812. isc_throw(RFCViolation, "Mandatory client-id is missing in received message");
  813. }
  814. // Now that we have all information about the client, let's iterate over all
  815. // received options and handle IA_NA options one by one and store our
  816. // responses in answer message (ADVERTISE or REPLY).
  817. //
  818. // @todo: IA_TA once we implement support for temporary addresses.
  819. for (OptionCollection::iterator opt = question->options_.begin();
  820. opt != question->options_.end(); ++opt) {
  821. switch (opt->second->getType()) {
  822. case D6O_IA_NA: {
  823. OptionPtr answer_opt = assignIA_NA(subnet, duid, question, answer,
  824. boost::dynamic_pointer_cast<
  825. Option6IA>(opt->second));
  826. if (answer_opt) {
  827. answer->addOption(answer_opt);
  828. }
  829. break;
  830. }
  831. case D6O_IA_PD: {
  832. OptionPtr answer_opt = assignIA_PD(subnet, duid, question,
  833. boost::dynamic_pointer_cast<
  834. Option6IA>(opt->second));
  835. if (answer_opt) {
  836. answer->addOption(answer_opt);
  837. }
  838. }
  839. default:
  840. break;
  841. }
  842. }
  843. }
  844. void
  845. Dhcpv6Srv::processClientFqdn(const Pkt6Ptr& question, const Pkt6Ptr& answer) {
  846. // Get Client FQDN Option from the client's message. If this option hasn't
  847. // been included, do nothing.
  848. Option6ClientFqdnPtr fqdn = boost::dynamic_pointer_cast<
  849. Option6ClientFqdn>(question->getOption(D6O_CLIENT_FQDN));
  850. if (!fqdn) {
  851. return;
  852. }
  853. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL,
  854. DHCP6_DDNS_RECEIVE_FQDN).arg(fqdn->toText());
  855. // Create the DHCPv6 Client FQDN Option to be included in the server's
  856. // response to a client.
  857. Option6ClientFqdnPtr fqdn_resp(new Option6ClientFqdn(*fqdn));
  858. // Set the server S, N, and O flags based on client's flags and
  859. // current configuration.
  860. D2ClientMgr& d2_mgr = CfgMgr::instance().getD2ClientMgr();
  861. d2_mgr.adjustFqdnFlags<Option6ClientFqdn>(*fqdn, *fqdn_resp);
  862. // Adjust the domain name based on domain name value and type sent by the
  863. // client and current configuration.
  864. d2_mgr.adjustDomainName<Option6ClientFqdn>(*fqdn, *fqdn_resp);
  865. // The FQDN has been processed successfully. Let's append it to the
  866. // response to be sent to a client. Note that the Client FQDN option is
  867. // always sent back to the client if Client FQDN was included in the
  868. // client's message.
  869. answer->addOption(fqdn_resp);
  870. }
  871. void
  872. Dhcpv6Srv::createNameChangeRequests(const Pkt6Ptr& answer) {
  873. // Don't create NameChangeRequests if DNS updates are disabled.
  874. if (!CfgMgr::instance().ddnsEnabled()) {
  875. return;
  876. }
  877. // The response message instance is always required. For instance it
  878. // holds the Client Identifier. It is a programming error if supplied
  879. // message is NULL.
  880. if (!answer) {
  881. isc_throw(isc::Unexpected, "an instance of the object"
  882. << " encapsulating server's message must not be"
  883. << " NULL when creating DNS NameChangeRequest");
  884. }
  885. // It is likely that client haven't included the FQDN option. In such case,
  886. // FQDN option will be NULL. This is valid state, so we simply return.
  887. Option6ClientFqdnPtr opt_fqdn = boost::dynamic_pointer_cast<
  888. Option6ClientFqdn>(answer->getOption(D6O_CLIENT_FQDN));
  889. if (!opt_fqdn) {
  890. return;
  891. }
  892. // Get the update directions that should be performed based on our
  893. // response FQDN flags.
  894. bool do_fwd = false;
  895. bool do_rev = false;
  896. CfgMgr::instance().getD2ClientMgr().getUpdateDirections(*opt_fqdn,
  897. do_fwd, do_rev);
  898. if (!do_fwd && !do_rev) {
  899. // Flags indicate there is Nothing to do, get out now.
  900. // The Most likely scenario is that we are honoring the client's
  901. // request that no updates be done.
  902. return;
  903. }
  904. // Get the Client Id. It is mandatory and a function creating a response
  905. // would have thrown an exception if it was missing. Thus throwning
  906. // Unexpected if it is missing as it is a programming error.
  907. OptionPtr opt_duid = answer->getOption(D6O_CLIENTID);
  908. if (!opt_duid) {
  909. isc_throw(isc::Unexpected,
  910. "client identifier is required when creating a new"
  911. " DNS NameChangeRequest");
  912. }
  913. DuidPtr duid = DuidPtr(new DUID(opt_duid->getData()));
  914. // Get the FQDN in the on-wire format. It will be needed to compute
  915. // DHCID.
  916. OutputBuffer name_buf(1);
  917. opt_fqdn->packDomainName(name_buf);
  918. const uint8_t* name_data = static_cast<const uint8_t*>(name_buf.getData());
  919. // @todo currently D2Dhcid accepts a vector holding FQDN.
  920. // However, it will be faster if we used a pointer name_data.
  921. std::vector<uint8_t> buf_vec(name_data, name_data + name_buf.getLength());
  922. // Compute DHCID from Client Identifier and FQDN.
  923. isc::dhcp_ddns::D2Dhcid dhcid(*duid, buf_vec);
  924. // Get all IAs from the answer. For each IA, holding an address we will
  925. // create a corresponding NameChangeRequest.
  926. OptionCollection answer_ias = answer->getOptions(D6O_IA_NA);
  927. for (OptionCollection::const_iterator answer_ia =
  928. answer_ias.begin(); answer_ia != answer_ias.end(); ++answer_ia) {
  929. /// @todo IA_NA may contain multiple addresses. We should process
  930. /// each address individually. Currently we get only one.
  931. Option6IAAddrPtr iaaddr = boost::static_pointer_cast<
  932. Option6IAAddr>(answer_ia->second->getOption(D6O_IAADDR));
  933. // We need an address to create a name-to-address mapping.
  934. // If address is missing for any reason, go to the next IA.
  935. if (!iaaddr) {
  936. continue;
  937. }
  938. // Create new NameChangeRequest. Use the domain name from the FQDN.
  939. // This is an FQDN included in the response to the client, so it
  940. // holds a fully qualified domain-name already (not partial).
  941. // Get the IP address from the lease.
  942. NameChangeRequestPtr ncr;
  943. ncr.reset(new NameChangeRequest(isc::dhcp_ddns::CHG_ADD,
  944. do_fwd, do_rev,
  945. opt_fqdn->getDomainName(),
  946. iaaddr->getAddress().toText(),
  947. dhcid, 0, iaaddr->getValid()));
  948. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL,
  949. DHCP6_DDNS_CREATE_ADD_NAME_CHANGE_REQUEST).arg(ncr->toText());
  950. // Post the NCR to the D2ClientMgr.
  951. CfgMgr::instance().getD2ClientMgr().sendRequest(ncr);
  952. /// @todo Currently we create NCR with the first IPv6 address that
  953. /// is carried in one of the IA_NAs. In the future, the NCR API should
  954. /// be extended to map multiple IPv6 addresses to a single FQDN.
  955. /// In such case, this return statement will be removed.
  956. return;
  957. }
  958. }
  959. void
  960. Dhcpv6Srv::createRemovalNameChangeRequest(const Lease6Ptr& lease) {
  961. // Don't create NameChangeRequests if DNS updates are disabled.
  962. if (!CfgMgr::instance().ddnsEnabled()) {
  963. return;
  964. }
  965. // If we haven't performed a DNS Update when lease was acquired,
  966. // there is nothing to do here.
  967. if (!lease->fqdn_fwd_ && !lease->fqdn_rev_) {
  968. return;
  969. }
  970. // If hostname is non-empty, try to convert it to wire format so as
  971. // DHCID can be computed from it. This may throw an exception if hostname
  972. // has invalid format or is empty. Again, this should be only possible
  973. // in case of manual intervention in the database. Note that the last
  974. // parameter passed to the writeFqdn function forces conversion of the FQDN
  975. // to lower case. This is required by the RFC4701, section 3.5.
  976. // The DHCID computation is further in this function.
  977. std::vector<uint8_t> hostname_wire;
  978. try {
  979. OptionDataTypeUtil::writeFqdn(lease->hostname_, hostname_wire, true);
  980. } catch (const Exception& ex) {
  981. LOG_ERROR(dhcp6_logger, DHCP6_DDNS_REMOVE_INVALID_HOSTNAME)
  982. .arg(lease->hostname_.empty() ? "(empty)" : lease->hostname_)
  983. .arg(lease->addr_.toText());
  984. return;
  985. }
  986. // DUID must have been checked already by the caller of this function.
  987. // Let's be on the safe side and make sure it is non-NULL and throw
  988. // an exception if it is NULL.
  989. if (!lease->duid_) {
  990. isc_throw(isc::Unexpected, "DUID must be set when creating"
  991. << " NameChangeRequest for DNS records removal for "
  992. << lease->addr_);
  993. }
  994. isc::dhcp_ddns::D2Dhcid dhcid(*lease->duid_, hostname_wire);
  995. // Create a NameChangeRequest to remove the entry.
  996. NameChangeRequestPtr ncr;
  997. ncr.reset(new NameChangeRequest(isc::dhcp_ddns::CHG_REMOVE,
  998. lease->fqdn_fwd_, lease->fqdn_rev_,
  999. lease->hostname_,
  1000. lease->addr_.toText(),
  1001. dhcid, 0, lease->valid_lft_));
  1002. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL,
  1003. DHCP6_DDNS_CREATE_REMOVE_NAME_CHANGE_REQUEST).arg(ncr->toText());
  1004. // Post the NCR to the D2ClientMgr.
  1005. CfgMgr::instance().getD2ClientMgr().sendRequest(ncr);
  1006. }
  1007. OptionPtr
  1008. Dhcpv6Srv::assignIA_NA(const Subnet6Ptr& subnet, const DuidPtr& duid,
  1009. const Pkt6Ptr& query, const Pkt6Ptr& answer,
  1010. boost::shared_ptr<Option6IA> ia) {
  1011. // If there is no subnet selected for handling this IA_NA, the only thing to do left is
  1012. // to say that we are sorry, but the user won't get an address. As a convenience, we
  1013. // use a different status text to indicate that (compare to the same status code,
  1014. // but different wording below)
  1015. if (!subnet) {
  1016. // Creatasse empty IA_NA option with IAID matching the request.
  1017. // Note that we don't use OptionDefinition class to create this option.
  1018. // This is because we prefer using a constructor of Option6IA that
  1019. // initializes IAID. Otherwise we would have to use setIAID() after
  1020. // creation of the option which has some performance implications.
  1021. boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
  1022. // Insert status code NoAddrsAvail.
  1023. ia_rsp->addOption(createStatusCode(STATUS_NoAddrsAvail, "Sorry, no subnet available."));
  1024. return (ia_rsp);
  1025. }
  1026. // Check if the client sent us a hint in his IA_NA. Clients may send an
  1027. // address in their IA_NA options as a suggestion (e.g. the last address
  1028. // they used before).
  1029. boost::shared_ptr<Option6IAAddr> hint_opt =
  1030. boost::dynamic_pointer_cast<Option6IAAddr>(ia->getOption(D6O_IAADDR));
  1031. IOAddress hint("::");
  1032. if (hint_opt) {
  1033. hint = hint_opt->getAddress();
  1034. }
  1035. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, DHCP6_PROCESS_IA_NA_REQUEST)
  1036. .arg(duid ? duid->toText() : "(no-duid)").arg(ia->getIAID())
  1037. .arg(hint_opt ? hint.toText() : "(no hint)");
  1038. // "Fake" allocation is processing of SOLICIT message. We pretend to do an
  1039. // allocation, but we do not put the lease in the database. That is ok,
  1040. // because we do not guarantee that the user will get that exact lease. If
  1041. // the user selects this server to do actual allocation (i.e. sends REQUEST)
  1042. // it should include this hint. That will help us during the actual lease
  1043. // allocation.
  1044. bool fake_allocation = false;
  1045. if (query->getType() == DHCPV6_SOLICIT) {
  1046. /// @todo: Check if we support rapid commit
  1047. fake_allocation = true;
  1048. }
  1049. CalloutHandlePtr callout_handle = getCalloutHandle(query);
  1050. // At this point, we have to make make some decisions with respect to the
  1051. // FQDN option that we have generated as a result of receiving client's
  1052. // FQDN. In particular, we have to get to know if the DNS update will be
  1053. // performed or not. It is possible that option is NULL, which is valid
  1054. // condition if client didn't request DNS updates and server didn't force
  1055. // the update.
  1056. bool do_fwd = false;
  1057. bool do_rev = false;
  1058. Option6ClientFqdnPtr fqdn = boost::dynamic_pointer_cast<
  1059. Option6ClientFqdn>(answer->getOption(D6O_CLIENT_FQDN));
  1060. if (fqdn) {
  1061. CfgMgr::instance().getD2ClientMgr().getUpdateDirections(*fqdn,
  1062. do_fwd, do_rev);
  1063. }
  1064. // Set hostname only in case any of the updates is being performed.
  1065. std::string hostname;
  1066. if (do_fwd || do_rev) {
  1067. hostname = fqdn->getDomainName();
  1068. }
  1069. // Use allocation engine to pick a lease for this client. Allocation engine
  1070. // will try to honour the hint, but it is just a hint - some other address
  1071. // may be used instead. If fake_allocation is set to false, the lease will
  1072. // be inserted into the LeaseMgr as well.
  1073. Lease6Collection old_leases;
  1074. Lease6Collection leases = alloc_engine_->allocateLeases6(subnet, duid,
  1075. ia->getIAID(),
  1076. hint, Lease::TYPE_NA,
  1077. do_fwd, do_rev,
  1078. hostname,
  1079. fake_allocation,
  1080. callout_handle,
  1081. old_leases);
  1082. /// @todo: Handle more than one lease
  1083. Lease6Ptr lease;
  1084. if (!leases.empty()) {
  1085. lease = *leases.begin();
  1086. }
  1087. // Create IA_NA that we will put in the response.
  1088. // Do not use OptionDefinition to create option's instance so
  1089. // as we can initialize IAID using a constructor.
  1090. boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
  1091. if (lease) {
  1092. // We have a lease! Let's wrap its content into IA_NA option
  1093. // with IAADDR suboption.
  1094. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, fake_allocation?
  1095. DHCP6_LEASE_ADVERT:DHCP6_LEASE_ALLOC)
  1096. .arg(lease->addr_.toText())
  1097. .arg(duid?duid->toText():"(no-duid)")
  1098. .arg(ia->getIAID());
  1099. ia_rsp->setT1(subnet->getT1());
  1100. ia_rsp->setT2(subnet->getT2());
  1101. boost::shared_ptr<Option6IAAddr>
  1102. addr(new Option6IAAddr(D6O_IAADDR,
  1103. lease->addr_,
  1104. lease->preferred_lft_,
  1105. lease->valid_lft_));
  1106. ia_rsp->addOption(addr);
  1107. // It would be possible to insert status code=0(success) as well,
  1108. // but this is considered waste of bandwidth as absence of status
  1109. // code is considered a success.
  1110. Lease6Ptr old_lease;
  1111. if (!old_leases.empty()) {
  1112. old_lease = *old_leases.begin();
  1113. }
  1114. // Allocation engine may have returned an existing lease. If so, we
  1115. // have to check that the FQDN settings we provided are the same
  1116. // that were set. If they aren't, we will have to remove existing
  1117. // DNS records and update the lease with the new settings.
  1118. if (!fake_allocation && old_lease &&
  1119. !lease->hasIdenticalFqdn(*old_lease)) {
  1120. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL,
  1121. DHCP6_DDNS_LEASE_ASSIGN_FQDN_CHANGE)
  1122. .arg(old_lease->toText())
  1123. .arg(hostname)
  1124. .arg(do_rev ? "true" : "false")
  1125. .arg(do_fwd ? "true" : "false");
  1126. // Schedule removal of the existing lease.
  1127. createRemovalNameChangeRequest(old_lease);
  1128. }
  1129. } else {
  1130. // Allocation engine did not allocate a lease. The engine logged
  1131. // cause of that failure. The only thing left is to insert
  1132. // status code to pass the sad news to the client.
  1133. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, fake_allocation ?
  1134. DHCP6_LEASE_ADVERT_FAIL : DHCP6_LEASE_ALLOC_FAIL)
  1135. .arg(duid?duid->toText():"(no-duid)")
  1136. .arg(ia->getIAID());
  1137. ia_rsp->addOption(createStatusCode(STATUS_NoAddrsAvail,
  1138. "Sorry, no address could be allocated."));
  1139. }
  1140. return (ia_rsp);
  1141. }
  1142. OptionPtr
  1143. Dhcpv6Srv::assignIA_PD(const Subnet6Ptr& subnet, const DuidPtr& duid,
  1144. const Pkt6Ptr& query, boost::shared_ptr<Option6IA> ia) {
  1145. // Create IA_PD that we will put in the response.
  1146. // Do not use OptionDefinition to create option's instance so
  1147. // as we can initialize IAID using a constructor.
  1148. boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_PD, ia->getIAID()));
  1149. // If there is no subnet selected for handling this IA_PD, the only thing to
  1150. // do left is to say that we are sorry, but the user won't get an address.
  1151. // As a convenience, we use a different status text to indicate that
  1152. // (compare to the same status code, but different wording below)
  1153. if (!subnet) {
  1154. // Insert status code NoAddrsAvail.
  1155. ia_rsp->addOption(createStatusCode(STATUS_NoPrefixAvail,
  1156. "Sorry, no subnet available."));
  1157. return (ia_rsp);
  1158. }
  1159. // Check if the client sent us a hint in his IA_PD. Clients may send an
  1160. // address in their IA_NA options as a suggestion (e.g. the last address
  1161. // they used before).
  1162. boost::shared_ptr<Option6IAPrefix> hint_opt =
  1163. boost::dynamic_pointer_cast<Option6IAPrefix>(ia->getOption(D6O_IAPREFIX));
  1164. IOAddress hint("::");
  1165. if (hint_opt) {
  1166. hint = hint_opt->getAddress();
  1167. }
  1168. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, DHCP6_PROCESS_IA_PD_REQUEST)
  1169. .arg(duid ? duid->toText() : "(no-duid)").arg(ia->getIAID())
  1170. .arg(hint_opt ? hint.toText() : "(no hint)");
  1171. // "Fake" allocation is processing of SOLICIT message. We pretend to do an
  1172. // allocation, but we do not put the lease in the database. That is ok,
  1173. // because we do not guarantee that the user will get that exact lease. If
  1174. // the user selects this server to do actual allocation (i.e. sends REQUEST)
  1175. // it should include this hint. That will help us during the actual lease
  1176. // allocation.
  1177. bool fake_allocation = (query->getType() == DHCPV6_SOLICIT);
  1178. CalloutHandlePtr callout_handle = getCalloutHandle(query);
  1179. // Use allocation engine to pick a lease for this client. Allocation engine
  1180. // will try to honour the hint, but it is just a hint - some other address
  1181. // may be used instead. If fake_allocation is set to false, the lease will
  1182. // be inserted into the LeaseMgr as well.
  1183. Lease6Collection old_leases;
  1184. Lease6Collection leases = alloc_engine_->allocateLeases6(subnet, duid,
  1185. ia->getIAID(),
  1186. hint, Lease::TYPE_PD,
  1187. false, false,
  1188. string(),
  1189. fake_allocation,
  1190. callout_handle,
  1191. old_leases);
  1192. if (!leases.empty()) {
  1193. ia_rsp->setT1(subnet->getT1());
  1194. ia_rsp->setT2(subnet->getT2());
  1195. for (Lease6Collection::iterator l = leases.begin();
  1196. l != leases.end(); ++l) {
  1197. // We have a lease! Let's wrap its content into IA_PD option
  1198. // with IAADDR suboption.
  1199. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, fake_allocation ?
  1200. DHCP6_PD_LEASE_ADVERT : DHCP6_PD_LEASE_ALLOC)
  1201. .arg((*l)->addr_.toText())
  1202. .arg(static_cast<int>((*l)->prefixlen_))
  1203. .arg(duid ? duid->toText() : "(no-duid)")
  1204. .arg(ia->getIAID());
  1205. boost::shared_ptr<Option6IAPrefix>
  1206. addr(new Option6IAPrefix(D6O_IAPREFIX, (*l)->addr_,
  1207. (*l)->prefixlen_, (*l)->preferred_lft_,
  1208. (*l)->valid_lft_));
  1209. ia_rsp->addOption(addr);
  1210. }
  1211. // It would be possible to insert status code=0(success) as well,
  1212. // but this is considered waste of bandwidth as absence of status
  1213. // code is considered a success.
  1214. } else {
  1215. // Allocation engine did not allocate a lease. The engine logged
  1216. // cause of that failure. The only thing left is to insert
  1217. // status code to pass the sad news to the client.
  1218. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, fake_allocation ?
  1219. DHCP6_PD_LEASE_ADVERT_FAIL : DHCP6_PD_LEASE_ALLOC_FAIL)
  1220. .arg(duid ? duid->toText() : "(no-duid)")
  1221. .arg(ia->getIAID());
  1222. ia_rsp->addOption(createStatusCode(STATUS_NoPrefixAvail,
  1223. "Sorry, no prefixes could be allocated."));
  1224. }
  1225. return (ia_rsp);
  1226. }
  1227. OptionPtr
  1228. Dhcpv6Srv::extendIA_NA(const Subnet6Ptr& subnet, const DuidPtr& duid,
  1229. const Pkt6Ptr& query, const Pkt6Ptr& answer,
  1230. boost::shared_ptr<Option6IA> ia) {
  1231. // Create empty IA_NA option with IAID matching the request.
  1232. Option6IAPtr ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
  1233. if (!subnet) {
  1234. /// @todo For simpliclty and due to limitations of LeaseMgr we don't
  1235. /// get the binding for the client for which we don't get subnet id.
  1236. /// Subnet id is a required value when searching for the bindings.
  1237. /// The fact that we can't identify the subnet for the returning client
  1238. /// doesn't really mean that the client has no binding. It is possible
  1239. /// that due to server's reconfiguration the subnet has been removed
  1240. /// or modified since the client has got his lease. We may need to
  1241. /// rethink whether it is appropriate to send no binding if the subnet
  1242. // hasn't been found for the client.
  1243. ia_rsp->addOption(createStatusCode(STATUS_NoBinding,
  1244. "Sorry, no known leases for this duid/iaid."));
  1245. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL,
  1246. DHCP6_EXTEND_NA_UNKNOWN_SUBNET)
  1247. .arg(query->getName())
  1248. .arg(duid->toText())
  1249. .arg(ia->getIAID());
  1250. return (ia_rsp);
  1251. }
  1252. Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
  1253. *duid, ia->getIAID(),
  1254. subnet->getID());
  1255. // Client extending a lease that we don't know about.
  1256. if (!lease) {
  1257. // Insert status code NoBinding to indicate that the lease does not
  1258. // exist for this client.
  1259. ia_rsp->addOption(createStatusCode(STATUS_NoBinding,
  1260. "Sorry, no known leases for this duid/iaid/subnet."));
  1261. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, DHCP6_EXTEND_NA_UNKNOWN)
  1262. .arg(duid->toText())
  1263. .arg(ia->getIAID())
  1264. .arg(subnet->toText());
  1265. return (ia_rsp);
  1266. }
  1267. // Keep the old data in case the callout tells us to skip update.
  1268. Lease6 old_data = *lease;
  1269. bool invalid_addr = false;
  1270. // Check what address the client has sent. The address should match the one
  1271. // that we have associated with the IAID. If it doesn't match we have two
  1272. // options: allocate the address for the client, if the server's
  1273. // configuration allows to do so, or notify the client that his address is
  1274. // wrong. For now we will just notify the client that the address is wrong,
  1275. // but both solutions require that we check the contents of the IA_NA option
  1276. // sent by the client. Without this check we would extend the existing lease
  1277. // even if the address being carried in the IA_NA is different than the
  1278. // one we are extending.
  1279. Option6IAAddrPtr iaaddr = boost::dynamic_pointer_cast<
  1280. Option6IAAddr>(ia->getOption(D6O_IAADDR));
  1281. if (iaaddr && (iaaddr->getAddress() != lease->addr_)) {
  1282. Option6IAAddrPtr zero_lft_addr(new Option6IAAddr(D6O_IAADDR,
  1283. iaaddr->getAddress(),
  1284. 0, 0));
  1285. ia_rsp->addOption(zero_lft_addr);
  1286. // Mark that the client's notion of the address is invalid, so as
  1287. // we don't update the actual client's lease.
  1288. invalid_addr = true;
  1289. } else {
  1290. // At this point, we have to make make some decisions with respect to
  1291. // the FQDN option that we have generated as a result of receiving
  1292. // client's FQDN. In particular, we have to get to know if the DNS
  1293. // update will be performed or not. It is possible that option is NULL,
  1294. // which is valid condition if client didn't request DNS updates and
  1295. // server didn't force the update.
  1296. bool do_fwd = false;
  1297. bool do_rev = false;
  1298. Option6ClientFqdnPtr fqdn = boost::dynamic_pointer_cast<
  1299. Option6ClientFqdn>(answer->getOption(D6O_CLIENT_FQDN));
  1300. if (fqdn) {
  1301. CfgMgr::instance().getD2ClientMgr().getUpdateDirections(*fqdn,
  1302. do_fwd,
  1303. do_rev);
  1304. }
  1305. std::string hostname;
  1306. if (do_fwd || do_rev) {
  1307. hostname = fqdn->getDomainName();
  1308. }
  1309. // If the new FQDN settings have changed for the lease, we need to
  1310. // delete any existing FQDN records for this lease.
  1311. if ((lease->hostname_ != hostname) || (lease->fqdn_fwd_ != do_fwd) ||
  1312. (lease->fqdn_rev_ != do_rev)) {
  1313. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL,
  1314. DHCP6_DDNS_LEASE_RENEW_FQDN_CHANGE)
  1315. .arg(lease->toText())
  1316. .arg(hostname)
  1317. .arg(do_rev ? "true" : "false")
  1318. .arg(do_fwd ? "true" : "false");
  1319. createRemovalNameChangeRequest(lease);
  1320. }
  1321. lease->preferred_lft_ = subnet->getPreferred();
  1322. lease->valid_lft_ = subnet->getValid();
  1323. lease->t1_ = subnet->getT1();
  1324. lease->t2_ = subnet->getT2();
  1325. lease->cltt_ = time(NULL);
  1326. lease->hostname_ = hostname;
  1327. lease->fqdn_fwd_ = do_fwd;
  1328. lease->fqdn_rev_ = do_rev;
  1329. ia_rsp->setT1(subnet->getT1());
  1330. ia_rsp->setT2(subnet->getT2());
  1331. Option6IAAddrPtr addr(new Option6IAAddr(D6O_IAADDR, lease->addr_,
  1332. lease->preferred_lft_,
  1333. lease->valid_lft_));
  1334. ia_rsp->addOption(addr);
  1335. }
  1336. bool skip = false;
  1337. // Get the callouts specific for the processed message and execute them.
  1338. int hook_point = query->getType() == DHCPV6_RENEW ?
  1339. Hooks.hook_index_lease6_renew_ : Hooks.hook_index_lease6_rebind_;
  1340. if (HooksManager::calloutsPresent(hook_point)) {
  1341. CalloutHandlePtr callout_handle = getCalloutHandle(query);
  1342. // Delete all previous arguments
  1343. callout_handle->deleteAllArguments();
  1344. // Pass the original packet
  1345. callout_handle->setArgument("query6", query);
  1346. // Pass the lease to be updated
  1347. callout_handle->setArgument("lease6", lease);
  1348. // Pass the IA option to be sent in response
  1349. callout_handle->setArgument("ia_na", ia_rsp);
  1350. // Call all installed callouts
  1351. HooksManager::callCallouts(hook_point, *callout_handle);
  1352. // Callouts decided to skip the next processing step. The next
  1353. // processing step would to actually renew the lease, so skip at this
  1354. // stage means "keep the old lease as it is".
  1355. if (callout_handle->getSkip()) {
  1356. skip = true;
  1357. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_HOOKS,
  1358. DHCP6_HOOK_LEASE6_EXTEND_SKIP)
  1359. .arg(query->getName());
  1360. }
  1361. }
  1362. if (!skip) {
  1363. // If the client has sent an invalid address, it shouldn't affect the
  1364. // lease in our lease database.
  1365. if (!invalid_addr) {
  1366. LeaseMgrFactory::instance().updateLease6(lease);
  1367. }
  1368. } else {
  1369. // Copy back the original date to the lease. For MySQL it doesn't make
  1370. // much sense, but for memfile, the Lease6Ptr points to the actual lease
  1371. // in memfile, so the actual update is performed when we manipulate
  1372. // fields of returned Lease6Ptr, the actual updateLease6() is no-op.
  1373. *lease = old_data;
  1374. }
  1375. return (ia_rsp);
  1376. }
  1377. OptionPtr
  1378. Dhcpv6Srv::extendIA_PD(const Subnet6Ptr& subnet, const DuidPtr& duid,
  1379. const Pkt6Ptr& query, boost::shared_ptr<Option6IA> ia) {
  1380. // Let's create a IA_PD response and fill it in later
  1381. Option6IAPtr ia_rsp(new Option6IA(D6O_IA_PD, ia->getIAID()));
  1382. // If there is no subnet for the particular client, we can't retrieve
  1383. // information about client's leases from lease database. We treat this
  1384. // as no binding for the client.
  1385. if (!subnet) {
  1386. // Per RFC3633, section 12.2, if there is no binding and we are
  1387. // processing a Renew, the NoBinding status code should be returned.
  1388. if (query->getType() == DHCPV6_RENEW) {
  1389. // Insert status code NoBinding
  1390. ia_rsp->addOption(createStatusCode(STATUS_NoBinding,
  1391. "Sorry, no known PD leases"
  1392. " for this duid/iaid."));
  1393. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL,
  1394. DHCP6_EXTEND_PD_UNKNOWN_SUBNET)
  1395. .arg(duid->toText())
  1396. .arg(ia->getIAID());
  1397. return (ia_rsp);
  1398. // Per RFC3633, section 12.2, if there is no binding and we are
  1399. // processing Rebind, the message has to be discarded (assuming that
  1400. // the server doesn't know if the prefix in the IA_PD option is
  1401. // appropriate for the client's link). The exception being thrown
  1402. // here should propagate to the main loop and cause the message to
  1403. // be discarded.
  1404. } else {
  1405. isc_throw(DHCPv6DiscardMessageError, "no subnet found for the"
  1406. " client sending Rebind to extend lifetime of the"
  1407. " prefix (DUID=" << duid->toText() << ", IAID="
  1408. << ia->getIAID());
  1409. }
  1410. }
  1411. // There is a subnet selected. Let's pick the lease.
  1412. Lease6Ptr lease =
  1413. LeaseMgrFactory::instance().getLease6(Lease::TYPE_PD,
  1414. *duid, ia->getIAID(),
  1415. subnet->getID());
  1416. // There is no binding for the client.
  1417. if (!lease) {
  1418. // Per RFC3633, section 12.2, if there is no binding and we are
  1419. // processing a Renew, the NoBinding status code should be returned.
  1420. if (query->getType() == DHCPV6_RENEW) {
  1421. // Insert status code NoBinding.
  1422. ia_rsp->addOption(createStatusCode(STATUS_NoBinding,
  1423. "Sorry, no known PD"
  1424. " leases for this duid/iaid."));
  1425. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL,
  1426. DHCP6_EXTEND_PD_NO_BINDING)
  1427. .arg(query->getName())
  1428. .arg(duid->toText())
  1429. .arg(ia->getIAID())
  1430. .arg(subnet->toText());
  1431. // Per RFC3633, section 12.2, if there is no binding and we are
  1432. // processing Rebind, the message has to be discarded (assuming that
  1433. // the server doesn't know if the prefix in the IA_PD option is
  1434. // appropriate for the client's link). The exception being thrown
  1435. // here should propagate to the main loop and cause the message to
  1436. // be discarded.
  1437. } else {
  1438. isc_throw(DHCPv6DiscardMessageError, "no binding found for the"
  1439. " DUID=" << duid->toText() << ", IAID="
  1440. << ia->getIAID() << ", subnet="
  1441. << subnet->toText() << " when processing a Rebind"
  1442. " message with IA_PD option");
  1443. }
  1444. return (ia_rsp);
  1445. }
  1446. // Keep the old data in case the callout tells us to skip update.
  1447. Lease6 old_data = *lease;
  1448. bool invalid_prefix = false;
  1449. // Check what prefix the client has sent. The prefix should match the
  1450. // one that we have associated with the IAID. If it doesn't match we
  1451. // have to return the prefix with the lifetimes set to 0 (see section
  1452. // 12.2. of RFC3633).
  1453. Option6IAPrefixPtr ia_prefix = boost::dynamic_pointer_cast<
  1454. Option6IAPrefix>(ia->getOption(D6O_IAPREFIX));
  1455. if (ia_prefix && ((ia_prefix->getAddress() != lease->addr_) ||
  1456. (ia_prefix->getLength() != lease->prefixlen_))) {
  1457. Option6IAPrefixPtr prefix(new Option6IAPrefix(D6O_IAPREFIX,
  1458. ia_prefix->getAddress(),
  1459. ia_prefix->getLength(),
  1460. 0, 0));
  1461. ia_rsp->addOption(prefix);
  1462. invalid_prefix = true;
  1463. } else {
  1464. // The prefix sent by a client is correct. Let's extend the lease
  1465. // for the client.
  1466. lease->preferred_lft_ = subnet->getPreferred();
  1467. lease->valid_lft_ = subnet->getValid();
  1468. // Do the actual lease update
  1469. lease->t1_ = subnet->getT1();
  1470. lease->t2_ = subnet->getT2();
  1471. lease->cltt_ = time(NULL);
  1472. // Also update IA_PD container with proper T1, T2 values
  1473. ia_rsp->setT1(subnet->getT1());
  1474. ia_rsp->setT2(subnet->getT2());
  1475. Option6IAPrefixPtr prefix(new Option6IAPrefix(D6O_IAPREFIX,
  1476. lease->addr_,
  1477. lease->prefixlen_,
  1478. lease->preferred_lft_,
  1479. lease->valid_lft_));
  1480. ia_rsp->addOption(prefix);
  1481. }
  1482. bool skip = false;
  1483. // Execute all callouts registered for packet6_send
  1484. // Get the callouts specific for the processed message and execute them.
  1485. int hook_point = query->getType() == DHCPV6_RENEW ?
  1486. Hooks.hook_index_lease6_renew_ : Hooks.hook_index_lease6_rebind_;
  1487. if (HooksManager::calloutsPresent(hook_point)) {
  1488. CalloutHandlePtr callout_handle = getCalloutHandle(query);
  1489. // Delete all previous arguments
  1490. callout_handle->deleteAllArguments();
  1491. // Pass the original packet
  1492. callout_handle->setArgument("query6", query);
  1493. // Pass the lease to be updated
  1494. callout_handle->setArgument("lease6", lease);
  1495. // Pass the IA option to be sent in response
  1496. callout_handle->setArgument("ia_pd", ia_rsp);
  1497. // Call all installed callouts
  1498. HooksManager::callCallouts(hook_point,
  1499. *callout_handle);
  1500. // Remember hook's instruction whether we want to skip update or not
  1501. skip = callout_handle->getSkip();
  1502. }
  1503. if (!skip) {
  1504. // If the prefix specified by the client is wrong, we don't want to
  1505. // update client's lease.
  1506. if (!invalid_prefix) {
  1507. LeaseMgrFactory::instance().updateLease6(lease);
  1508. }
  1509. } else {
  1510. // Callouts decided to skip the next processing step. The next
  1511. // processing step would to actually renew/rebind the lease, so skip
  1512. // at this stage means "keep the old lease as it is".
  1513. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_HOOKS, DHCP6_HOOK_LEASE6_EXTEND_SKIP)
  1514. .arg(query->getName());
  1515. // Copy back the original date to the lease. For MySQL it doesn't make
  1516. // much sense, but for memfile, the Lease6Ptr points to the actual lease
  1517. // in memfile, so the actual update is performed when we manipulate
  1518. // fields of returned Lease6Ptr, the actual updateLease6() is no-op.
  1519. *lease = old_data;
  1520. }
  1521. return (ia_rsp);
  1522. }
  1523. void
  1524. Dhcpv6Srv::extendLeases(const Pkt6Ptr& query, Pkt6Ptr& reply) {
  1525. // We will try to extend lease lifetime for all IA options in the client's
  1526. // Renew or Rebind message.
  1527. /// @todo add support for IA_TA
  1528. // We need to select a subnet the client is connected in. This is needed
  1529. // to get the client's bindings from the lease database. The subnet id
  1530. // is one of the lease search parameters.
  1531. Subnet6Ptr subnet = selectSubnet(query);
  1532. if (!subnet) {
  1533. // This particular client is out of luck today. We do not have
  1534. // information about the subnet he is connected to. This likely means
  1535. // misconfiguration of the server (or some relays). We will continue to
  1536. // process this message, but our response will be almost useless: no
  1537. // addresses or prefixes, no subnet specific configuration etc. The only
  1538. // thing this client can get is some global information (like DNS
  1539. // servers).
  1540. LOG_WARN(dhcp6_logger, DHCP6_EXTEND_LEASE_SUBNET_SELECT_FAILED)
  1541. .arg(query->getName())
  1542. .arg(query->getRemoteAddr().toText())
  1543. .arg(query->getName());
  1544. } else {
  1545. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL_DATA,
  1546. DHCP6_EXTEND_LEASE_SUBNET_SELECTED)
  1547. .arg(subnet->toText());
  1548. }
  1549. // Let's find client's DUID. Client is supposed to include its client-id
  1550. // option almost all the time (the only exception is an anonymous
  1551. // inf-request, but that is mostly a theoretical case). Our allocation
  1552. // engine needs DUID and will refuse to allocate anything to anonymous
  1553. // clients.
  1554. /// @todo Consider removing this check from here and rely on what we have
  1555. /// checked on the earlier processing stage.
  1556. OptionPtr opt_duid = query->getOption(D6O_CLIENTID);
  1557. if (!opt_duid) {
  1558. // This should not happen. We have checked this before.
  1559. reply->addOption(createStatusCode(STATUS_UnspecFail,
  1560. "You did not include mandatory client-id"));
  1561. return;
  1562. }
  1563. DuidPtr duid(new DUID(opt_duid->getData()));
  1564. for (OptionCollection::iterator opt = query->options_.begin();
  1565. opt != query->options_.end(); ++opt) {
  1566. switch (opt->second->getType()) {
  1567. case D6O_IA_NA: {
  1568. OptionPtr answer_opt = extendIA_NA(subnet, duid, query, reply,
  1569. boost::dynamic_pointer_cast<
  1570. Option6IA>(opt->second));
  1571. if (answer_opt) {
  1572. reply->addOption(answer_opt);
  1573. }
  1574. break;
  1575. }
  1576. case D6O_IA_PD: {
  1577. OptionPtr answer_opt = extendIA_PD(subnet, duid, query,
  1578. boost::dynamic_pointer_cast<
  1579. Option6IA>(opt->second));
  1580. if (answer_opt) {
  1581. reply->addOption(answer_opt);
  1582. }
  1583. break;
  1584. }
  1585. default:
  1586. break;
  1587. }
  1588. }
  1589. }
  1590. void
  1591. Dhcpv6Srv::releaseLeases(const Pkt6Ptr& release, Pkt6Ptr& reply) {
  1592. // We need to release addresses for all IA_NA options in the client's
  1593. // RELEASE message.
  1594. // @todo Add support for IA_TA
  1595. // @todo Add support for IA_PD
  1596. // @todo Consider supporting more than one address in a single IA_NA.
  1597. // That was envisaged by RFC3315, but it never happened. The only
  1598. // software that supports that is Dibbler, but its author seriously doubts
  1599. // if anyone is really using it. Clients that want more than one address
  1600. // just include more instances of IA_NA options.
  1601. // Let's find client's DUID. Client is supposed to include its client-id
  1602. // option almost all the time (the only exception is an anonymous inf-request,
  1603. // but that is mostly a theoretical case). Our allocation engine needs DUID
  1604. // and will refuse to allocate anything to anonymous clients.
  1605. OptionPtr opt_duid = release->getOption(D6O_CLIENTID);
  1606. if (!opt_duid) {
  1607. // This should not happen. We have checked this before.
  1608. // see sanityCheck() called from processRelease()
  1609. LOG_WARN(dhcp6_logger, DHCP6_RELEASE_MISSING_CLIENTID)
  1610. .arg(release->getRemoteAddr().toText());
  1611. reply->addOption(createStatusCode(STATUS_UnspecFail,
  1612. "You did not include mandatory client-id"));
  1613. return;
  1614. }
  1615. DuidPtr duid(new DUID(opt_duid->getData()));
  1616. // Let's set the status to be success by default. We can override it with
  1617. // error status if needed. The important thing to understand here is that
  1618. // the global status code may be set to success only if all IA options were
  1619. // handled properly. Therefore the releaseIA_NA and releaseIA_PD options
  1620. // may turn the status code to some error, but can't turn it back to success.
  1621. int general_status = STATUS_Success;
  1622. for (OptionCollection::iterator opt = release->options_.begin();
  1623. opt != release->options_.end(); ++opt) {
  1624. switch (opt->second->getType()) {
  1625. case D6O_IA_NA: {
  1626. OptionPtr answer_opt = releaseIA_NA(duid, release, general_status,
  1627. boost::dynamic_pointer_cast<Option6IA>(opt->second));
  1628. if (answer_opt) {
  1629. reply->addOption(answer_opt);
  1630. }
  1631. break;
  1632. }
  1633. case D6O_IA_PD: {
  1634. OptionPtr answer_opt = releaseIA_PD(duid, release, general_status,
  1635. boost::dynamic_pointer_cast<Option6IA>(opt->second));
  1636. if (answer_opt) {
  1637. reply->addOption(answer_opt);
  1638. }
  1639. break;
  1640. }
  1641. // @todo: add support for IA_TA
  1642. default:
  1643. // remaining options are stateless and thus ignored in this context
  1644. ;
  1645. }
  1646. }
  1647. // To be pedantic, we should also include status code in the top-level
  1648. // scope, not just in each IA_NA. See RFC3315, section 18.2.6.
  1649. // This behavior will likely go away in RFC3315bis.
  1650. reply->addOption(createStatusCode(general_status,
  1651. "Summary status for all processed IA_NAs"));
  1652. }
  1653. OptionPtr
  1654. Dhcpv6Srv::releaseIA_NA(const DuidPtr& duid, const Pkt6Ptr& query,
  1655. int& general_status, boost::shared_ptr<Option6IA> ia) {
  1656. // Release can be done in one of two ways:
  1657. // Approach 1: extract address from client's IA_NA and see if it belongs
  1658. // to this particular client.
  1659. // Approach 2: find a subnet for this client, get a lease for
  1660. // this subnet/duid/iaid and check if its content matches to what the
  1661. // client is asking us to release.
  1662. //
  1663. // This method implements approach 1.
  1664. // That's our response
  1665. boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
  1666. boost::shared_ptr<Option6IAAddr> release_addr = boost::dynamic_pointer_cast<Option6IAAddr>
  1667. (ia->getOption(D6O_IAADDR));
  1668. if (!release_addr) {
  1669. ia_rsp->addOption(createStatusCode(STATUS_NoBinding,
  1670. "You did not include an address in your RELEASE"));
  1671. general_status = STATUS_NoBinding;
  1672. return (ia_rsp);
  1673. }
  1674. Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
  1675. release_addr->getAddress());
  1676. if (!lease) {
  1677. // client releasing a lease that we don't know about.
  1678. // Insert status code NoAddrsAvail.
  1679. ia_rsp->addOption(createStatusCode(STATUS_NoBinding,
  1680. "Sorry, no known leases for this duid/iaid, can't release."));
  1681. general_status = STATUS_NoBinding;
  1682. LOG_INFO(dhcp6_logger, DHCP6_UNKNOWN_RELEASE_NA)
  1683. .arg(duid->toText())
  1684. .arg(ia->getIAID());
  1685. return (ia_rsp);
  1686. }
  1687. if (!lease->duid_) {
  1688. // Something is gravely wrong here. We do have a lease, but it does not
  1689. // have mandatory DUID information attached. Someone was messing with our
  1690. // database.
  1691. LOG_ERROR(dhcp6_logger, DHCP6_LEASE_NA_WITHOUT_DUID)
  1692. .arg(release_addr->getAddress().toText());
  1693. general_status = STATUS_UnspecFail;
  1694. ia_rsp->addOption(createStatusCode(STATUS_UnspecFail,
  1695. "Database consistency check failed when trying to RELEASE"));
  1696. return (ia_rsp);
  1697. }
  1698. if (*duid != *(lease->duid_)) {
  1699. // Sorry, it's not your address. You can't release it.
  1700. LOG_INFO(dhcp6_logger, DHCP6_RELEASE_NA_FAIL_WRONG_DUID)
  1701. .arg(duid->toText())
  1702. .arg(release_addr->getAddress().toText())
  1703. .arg(lease->duid_->toText());
  1704. general_status = STATUS_NoBinding;
  1705. ia_rsp->addOption(createStatusCode(STATUS_NoBinding,
  1706. "This address does not belong to you, you can't release it"));
  1707. return (ia_rsp);
  1708. }
  1709. if (ia->getIAID() != lease->iaid_) {
  1710. // This address belongs to this client, but to a different IA
  1711. LOG_WARN(dhcp6_logger, DHCP6_RELEASE_PD_FAIL_WRONG_IAID)
  1712. .arg(duid->toText())
  1713. .arg(release_addr->getAddress().toText())
  1714. .arg(lease->iaid_)
  1715. .arg(ia->getIAID());
  1716. ia_rsp->addOption(createStatusCode(STATUS_NoBinding,
  1717. "This is your address, but you used wrong IAID"));
  1718. general_status = STATUS_NoBinding;
  1719. return (ia_rsp);
  1720. }
  1721. // It is not necessary to check if the address matches as we used
  1722. // getLease6(addr) method that is supposed to return a proper lease.
  1723. bool skip = false;
  1724. // Execute all callouts registered for packet6_send
  1725. if (HooksManager::calloutsPresent(Hooks.hook_index_lease6_release_)) {
  1726. CalloutHandlePtr callout_handle = getCalloutHandle(query);
  1727. // Delete all previous arguments
  1728. callout_handle->deleteAllArguments();
  1729. // Pass the original packet
  1730. callout_handle->setArgument("query6", query);
  1731. // Pass the lease to be updated
  1732. callout_handle->setArgument("lease6", lease);
  1733. // Call all installed callouts
  1734. HooksManager::callCallouts(Hooks.hook_index_lease6_release_, *callout_handle);
  1735. // Callouts decided to skip the next processing step. The next
  1736. // processing step would to send the packet, so skip at this
  1737. // stage means "drop response".
  1738. if (callout_handle->getSkip()) {
  1739. skip = true;
  1740. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_HOOKS, DHCP6_HOOK_LEASE6_RELEASE_NA_SKIP);
  1741. }
  1742. }
  1743. // Ok, we've passed all checks. Let's release this address.
  1744. bool success = false; // was the removal operation succeessful?
  1745. if (!skip) {
  1746. success = LeaseMgrFactory::instance().deleteLease(lease->addr_);
  1747. }
  1748. // Here the success should be true if we removed lease successfully
  1749. // and false if skip flag was set or the removal failed for whatever reason
  1750. if (!success) {
  1751. ia_rsp->addOption(createStatusCode(STATUS_UnspecFail,
  1752. "Server failed to release a lease"));
  1753. LOG_ERROR(dhcp6_logger, DHCP6_RELEASE_NA_FAIL)
  1754. .arg(lease->addr_.toText())
  1755. .arg(duid->toText())
  1756. .arg(lease->iaid_);
  1757. general_status = STATUS_UnspecFail;
  1758. return (ia_rsp);
  1759. } else {
  1760. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, DHCP6_RELEASE_NA)
  1761. .arg(lease->addr_.toText())
  1762. .arg(duid->toText())
  1763. .arg(lease->iaid_);
  1764. ia_rsp->addOption(createStatusCode(STATUS_Success,
  1765. "Lease released. Thank you, please come again."));
  1766. // Check if a lease has flags indicating that the FQDN update has
  1767. // been performed. If so, create NameChangeRequest which removes
  1768. // the entries.
  1769. createRemovalNameChangeRequest(lease);
  1770. return (ia_rsp);
  1771. }
  1772. }
  1773. OptionPtr
  1774. Dhcpv6Srv::releaseIA_PD(const DuidPtr& duid, const Pkt6Ptr& query,
  1775. int& general_status, boost::shared_ptr<Option6IA> ia) {
  1776. // Release can be done in one of two ways:
  1777. // Approach 1: extract address from client's IA_NA and see if it belongs
  1778. // to this particular client.
  1779. // Approach 2: find a subnet for this client, get a lease for
  1780. // this subnet/duid/iaid and check if its content matches to what the
  1781. // client is asking us to release.
  1782. //
  1783. // This method implements approach 1.
  1784. // That's our response. We will fill it in as we check the lease to be
  1785. // released.
  1786. boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_PD, ia->getIAID()));
  1787. boost::shared_ptr<Option6IAPrefix> release_prefix =
  1788. boost::dynamic_pointer_cast<Option6IAPrefix>(ia->getOption(D6O_IAPREFIX));
  1789. if (!release_prefix) {
  1790. ia_rsp->addOption(createStatusCode(STATUS_NoBinding,
  1791. "You did not include a prefix in your RELEASE"));
  1792. general_status = STATUS_NoBinding;
  1793. return (ia_rsp);
  1794. }
  1795. Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_PD,
  1796. release_prefix->getAddress());
  1797. if (!lease) {
  1798. // Client releasing a lease that we don't know about.
  1799. // Insert status code NoBinding.
  1800. ia_rsp->addOption(createStatusCode(STATUS_NoBinding,
  1801. "Sorry, no known leases for this duid/iaid, can't release."));
  1802. general_status = STATUS_NoBinding;
  1803. LOG_INFO(dhcp6_logger, DHCP6_UNKNOWN_RELEASE_PD)
  1804. .arg(duid->toText())
  1805. .arg(ia->getIAID());
  1806. return (ia_rsp);
  1807. }
  1808. if (!lease->duid_) {
  1809. // Something is gravely wrong here. We do have a lease, but it does not
  1810. // have mandatory DUID information attached. Someone was messing with our
  1811. // database.
  1812. LOG_ERROR(dhcp6_logger, DHCP6_LEASE_PD_WITHOUT_DUID)
  1813. .arg(release_prefix->getAddress().toText());
  1814. general_status = STATUS_UnspecFail;
  1815. ia_rsp->addOption(createStatusCode(STATUS_UnspecFail,
  1816. "Database consistency check failed when trying to RELEASE"));
  1817. return (ia_rsp);
  1818. }
  1819. if (*duid != *(lease->duid_)) {
  1820. // Sorry, it's not your address. You can't release it.
  1821. LOG_INFO(dhcp6_logger, DHCP6_RELEASE_PD_FAIL_WRONG_DUID)
  1822. .arg(duid->toText())
  1823. .arg(release_prefix->getAddress().toText())
  1824. .arg(lease->duid_->toText());
  1825. general_status = STATUS_NoBinding;
  1826. ia_rsp->addOption(createStatusCode(STATUS_NoBinding,
  1827. "This address does not belong to you, you can't release it"));
  1828. return (ia_rsp);
  1829. }
  1830. if (ia->getIAID() != lease->iaid_) {
  1831. // This address belongs to this client, but to a different IA
  1832. LOG_WARN(dhcp6_logger, DHCP6_RELEASE_PD_FAIL_WRONG_IAID)
  1833. .arg(duid->toText())
  1834. .arg(release_prefix->getAddress().toText())
  1835. .arg(lease->iaid_)
  1836. .arg(ia->getIAID());
  1837. ia_rsp->addOption(createStatusCode(STATUS_NoBinding,
  1838. "This is your address, but you used wrong IAID"));
  1839. general_status = STATUS_NoBinding;
  1840. return (ia_rsp);
  1841. }
  1842. // It is not necessary to check if the address matches as we used
  1843. // getLease6(addr) method that is supposed to return a proper lease.
  1844. bool skip = false;
  1845. // Execute all callouts registered for packet6_send
  1846. if (HooksManager::calloutsPresent(Hooks.hook_index_lease6_release_)) {
  1847. CalloutHandlePtr callout_handle = getCalloutHandle(query);
  1848. // Delete all previous arguments
  1849. callout_handle->deleteAllArguments();
  1850. // Pass the original packet
  1851. callout_handle->setArgument("query6", query);
  1852. // Pass the lease to be updated
  1853. callout_handle->setArgument("lease6", lease);
  1854. // Call all installed callouts
  1855. HooksManager::callCallouts(Hooks.hook_index_lease6_release_, *callout_handle);
  1856. skip = callout_handle->getSkip();
  1857. }
  1858. // Ok, we've passed all checks. Let's release this prefix.
  1859. bool success = false; // was the removal operation succeessful?
  1860. if (!skip) {
  1861. success = LeaseMgrFactory::instance().deleteLease(lease->addr_);
  1862. } else {
  1863. // Callouts decided to skip the next processing step. The next
  1864. // processing step would to send the packet, so skip at this
  1865. // stage means "drop response".
  1866. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_HOOKS, DHCP6_HOOK_LEASE6_RELEASE_PD_SKIP);
  1867. }
  1868. // Here the success should be true if we removed lease successfully
  1869. // and false if skip flag was set or the removal failed for whatever reason
  1870. if (!success) {
  1871. ia_rsp->addOption(createStatusCode(STATUS_UnspecFail,
  1872. "Server failed to release a lease"));
  1873. LOG_ERROR(dhcp6_logger, DHCP6_RELEASE_PD_FAIL)
  1874. .arg(lease->addr_.toText())
  1875. .arg(duid->toText())
  1876. .arg(lease->iaid_);
  1877. general_status = STATUS_UnspecFail;
  1878. } else {
  1879. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, DHCP6_RELEASE_PD)
  1880. .arg(lease->addr_.toText())
  1881. .arg(duid->toText())
  1882. .arg(lease->iaid_);
  1883. ia_rsp->addOption(createStatusCode(STATUS_Success,
  1884. "Lease released. Thank you, please come again."));
  1885. }
  1886. return (ia_rsp);
  1887. }
  1888. Pkt6Ptr
  1889. Dhcpv6Srv::processSolicit(const Pkt6Ptr& solicit) {
  1890. sanityCheck(solicit, MANDATORY, FORBIDDEN);
  1891. Pkt6Ptr advertise(new Pkt6(DHCPV6_ADVERTISE, solicit->getTransid()));
  1892. copyDefaultOptions(solicit, advertise);
  1893. appendDefaultOptions(solicit, advertise);
  1894. appendRequestedOptions(solicit, advertise);
  1895. appendRequestedVendorOptions(solicit, advertise);
  1896. processClientFqdn(solicit, advertise);
  1897. assignLeases(solicit, advertise);
  1898. // Note, that we don't create NameChangeRequests here because we don't
  1899. // perform DNS Updates for Solicit. Client must send Request to update
  1900. // DNS.
  1901. generateFqdn(advertise);
  1902. return (advertise);
  1903. }
  1904. Pkt6Ptr
  1905. Dhcpv6Srv::processRequest(const Pkt6Ptr& request) {
  1906. sanityCheck(request, MANDATORY, MANDATORY);
  1907. Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, request->getTransid()));
  1908. copyDefaultOptions(request, reply);
  1909. appendDefaultOptions(request, reply);
  1910. appendRequestedOptions(request, reply);
  1911. appendRequestedVendorOptions(request, reply);
  1912. processClientFqdn(request, reply);
  1913. assignLeases(request, reply);
  1914. generateFqdn(reply);
  1915. createNameChangeRequests(reply);
  1916. return (reply);
  1917. }
  1918. Pkt6Ptr
  1919. Dhcpv6Srv::processRenew(const Pkt6Ptr& renew) {
  1920. sanityCheck(renew, MANDATORY, MANDATORY);
  1921. Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, renew->getTransid()));
  1922. copyDefaultOptions(renew, reply);
  1923. appendDefaultOptions(renew, reply);
  1924. appendRequestedOptions(renew, reply);
  1925. processClientFqdn(renew, reply);
  1926. extendLeases(renew, reply);
  1927. generateFqdn(reply);
  1928. createNameChangeRequests(reply);
  1929. return (reply);
  1930. }
  1931. Pkt6Ptr
  1932. Dhcpv6Srv::processRebind(const Pkt6Ptr& rebind) {
  1933. Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, rebind->getTransid()));
  1934. copyDefaultOptions(rebind, reply);
  1935. appendDefaultOptions(rebind, reply);
  1936. appendRequestedOptions(rebind, reply);
  1937. processClientFqdn(rebind, reply);
  1938. extendLeases(rebind, reply);
  1939. generateFqdn(reply);
  1940. createNameChangeRequests(rebind);
  1941. return (reply);
  1942. }
  1943. Pkt6Ptr
  1944. Dhcpv6Srv::processConfirm(const Pkt6Ptr& confirm) {
  1945. // Get IA_NAs from the Confirm. If there are none, the message is
  1946. // invalid and must be discarded. There is nothing more to do.
  1947. OptionCollection ias = confirm->getOptions(D6O_IA_NA);
  1948. if (ias.empty()) {
  1949. return (Pkt6Ptr());
  1950. }
  1951. // The server sends Reply message in response to Confirm.
  1952. Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, confirm->getTransid()));
  1953. // Make sure that the necessary options are included.
  1954. copyDefaultOptions(confirm, reply);
  1955. appendDefaultOptions(confirm, reply);
  1956. // Indicates if at least one address has been verified. If no addresses
  1957. // are verified it means that the client has sent no IA_NA options
  1958. // or no IAAddr options and that client's message has to be discarded.
  1959. bool verified = false;
  1960. // Check if subnet can be selected for the message. If no subnet
  1961. // has been selected, the client is not on link.
  1962. SubnetPtr subnet = selectSubnet(confirm);
  1963. // Regardless if the subnet has been selected or not, we will iterate
  1964. // over the IA_NA options to check if they hold any addresses. If there
  1965. // are no, the Confirm is discarded.
  1966. // Check addresses in IA_NA options and make sure they are appropriate.
  1967. for (OptionCollection::const_iterator ia = ias.begin();
  1968. ia != ias.end(); ++ia) {
  1969. const OptionCollection& opts = ia->second->getOptions();
  1970. for (OptionCollection::const_iterator opt = opts.begin();
  1971. opt != opts.end(); ++opt) {
  1972. // Ignore options other than IAAddr.
  1973. if (opt->second->getType() == D6O_IAADDR) {
  1974. // Check that the address is in range in the subnet selected.
  1975. Option6IAAddrPtr iaaddr = boost::dynamic_pointer_cast<
  1976. Option6IAAddr>(opt->second);
  1977. // If there is subnet selected and the address has been included
  1978. // in IA_NA, mark it verified and verify that it belongs to the
  1979. // subnet.
  1980. if (iaaddr) {
  1981. // If at least one address is not in range, then return
  1982. // the NotOnLink status code.
  1983. if (subnet && !subnet->inRange(iaaddr->getAddress())) {
  1984. std::ostringstream status_msg;
  1985. status_msg << "Address " << iaaddr->getAddress()
  1986. << " is not on link.";
  1987. reply->addOption(createStatusCode(STATUS_NotOnLink,
  1988. status_msg.str()));
  1989. return (reply);
  1990. }
  1991. verified = true;
  1992. } else {
  1993. isc_throw(Unexpected, "failed to cast the IA Address option"
  1994. " to the Option6IAAddrPtr. This is programming"
  1995. " error and should be reported");
  1996. }
  1997. }
  1998. }
  1999. }
  2000. // It seems that the client hasn't included any addresses in which case
  2001. // the Confirm must be discarded.
  2002. if (!verified) {
  2003. return (Pkt6Ptr());
  2004. }
  2005. // If there is a subnet, there were addresses in IA_NA options and the
  2006. // addresses where consistent with the subnet then the client is on link.
  2007. if (subnet) {
  2008. // All addresses in range, so return success.
  2009. reply->addOption(createStatusCode(STATUS_Success,
  2010. "All addresses are on-link"));
  2011. } else {
  2012. reply->addOption(createStatusCode(STATUS_NotOnLink,
  2013. "No subnet selected"));
  2014. }
  2015. return (reply);
  2016. }
  2017. Pkt6Ptr
  2018. Dhcpv6Srv::processRelease(const Pkt6Ptr& release) {
  2019. sanityCheck(release, MANDATORY, MANDATORY);
  2020. Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, release->getTransid()));
  2021. copyDefaultOptions(release, reply);
  2022. appendDefaultOptions(release, reply);
  2023. releaseLeases(release, reply);
  2024. // @todo If client sent a release and we should remove outstanding
  2025. // DNS records.
  2026. return (reply);
  2027. }
  2028. Pkt6Ptr
  2029. Dhcpv6Srv::processDecline(const Pkt6Ptr& decline) {
  2030. /// @todo: Implement this
  2031. Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, decline->getTransid()));
  2032. return reply;
  2033. }
  2034. Pkt6Ptr
  2035. Dhcpv6Srv::processInfRequest(const Pkt6Ptr& infRequest) {
  2036. /// @todo: Implement this
  2037. Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, infRequest->getTransid()));
  2038. return reply;
  2039. }
  2040. void
  2041. Dhcpv6Srv::openActiveSockets(const uint16_t port) {
  2042. IfaceMgr::instance().closeSockets();
  2043. // Get the reference to the collection of interfaces. This reference should be
  2044. // valid as long as the program is run because IfaceMgr is a singleton.
  2045. // Therefore we can safely iterate over instances of all interfaces and modify
  2046. // their flags. Here we modify flags which indicate wheter socket should be
  2047. // open for a particular interface or not.
  2048. const IfaceMgr::IfaceCollection& ifaces = IfaceMgr::instance().getIfaces();
  2049. for (IfaceMgr::IfaceCollection::const_iterator iface = ifaces.begin();
  2050. iface != ifaces.end(); ++iface) {
  2051. Iface* iface_ptr = IfaceMgr::instance().getIface(iface->getName());
  2052. if (iface_ptr == NULL) {
  2053. isc_throw(isc::Unexpected, "Interface Manager returned NULL"
  2054. << " instance of the interface when DHCPv6 server was"
  2055. << " trying to reopen sockets after reconfiguration");
  2056. }
  2057. if (CfgMgr::instance().isActiveIface(iface->getName())) {
  2058. iface_ptr->inactive6_ = false;
  2059. LOG_INFO(dhcp6_logger, DHCP6_ACTIVATE_INTERFACE)
  2060. .arg(iface->getFullName());
  2061. } else {
  2062. // For deactivating interface, it should be sufficient to log it
  2063. // on the debug level because it is more useful to know what
  2064. // interface is activated which is logged on the info level.
  2065. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_BASIC,
  2066. DHCP6_DEACTIVATE_INTERFACE).arg(iface->getName());
  2067. iface_ptr->inactive6_ = true;
  2068. }
  2069. iface_ptr->clearUnicasts();
  2070. const IOAddress* unicast = CfgMgr::instance().getUnicast(iface->getName());
  2071. if (unicast) {
  2072. LOG_INFO(dhcp6_logger, DHCP6_SOCKET_UNICAST).arg(unicast->toText())
  2073. .arg(iface->getName());
  2074. iface_ptr->addUnicast(*unicast);
  2075. }
  2076. }
  2077. // Let's reopen active sockets. openSockets6 will check internally whether
  2078. // sockets are marked active or inactive.
  2079. // @todo Optimization: we should not reopen all sockets but rather select
  2080. // those that have been affected by the new configuration.
  2081. isc::dhcp::IfaceMgrErrorMsgCallback error_handler =
  2082. boost::bind(&Dhcpv6Srv::ifaceMgrSocket6ErrorHandler, _1);
  2083. if (!IfaceMgr::instance().openSockets6(port, error_handler)) {
  2084. LOG_WARN(dhcp6_logger, DHCP6_NO_SOCKETS_OPEN);
  2085. }
  2086. }
  2087. size_t
  2088. Dhcpv6Srv::unpackOptions(const OptionBuffer& buf,
  2089. const std::string& option_space,
  2090. isc::dhcp::OptionCollection& options,
  2091. size_t* relay_msg_offset,
  2092. size_t* relay_msg_len) {
  2093. size_t offset = 0;
  2094. size_t length = buf.size();
  2095. OptionDefContainer option_defs;
  2096. if (option_space == "dhcp6") {
  2097. // Get the list of stdandard option definitions.
  2098. option_defs = LibDHCP::getOptionDefs(Option::V6);
  2099. } else if (!option_space.empty()) {
  2100. OptionDefContainerPtr option_defs_ptr =
  2101. CfgMgr::instance().getOptionDefs(option_space);
  2102. if (option_defs_ptr != NULL) {
  2103. option_defs = *option_defs_ptr;
  2104. }
  2105. }
  2106. // Get the search index #1. It allows to search for option definitions
  2107. // using option code.
  2108. const OptionDefContainerTypeIndex& idx = option_defs.get<1>();
  2109. // The buffer being read comprises a set of options, each starting with
  2110. // a two-byte type code and a two-byte length field.
  2111. while (offset + 4 <= length) {
  2112. // At this point, from the while condition, we know that there
  2113. // are at least 4 bytes available following offset in the
  2114. // buffer.
  2115. uint16_t opt_type = isc::util::readUint16(&buf[offset], 2);
  2116. offset += 2;
  2117. uint16_t opt_len = isc::util::readUint16(&buf[offset], 2);
  2118. offset += 2;
  2119. if (offset + opt_len > length) {
  2120. // @todo: consider throwing exception here.
  2121. return (offset);
  2122. }
  2123. if (opt_type == D6O_RELAY_MSG && relay_msg_offset && relay_msg_len) {
  2124. // remember offset of the beginning of the relay-msg option
  2125. *relay_msg_offset = offset;
  2126. *relay_msg_len = opt_len;
  2127. // do not create that relay-msg option
  2128. offset += opt_len;
  2129. continue;
  2130. }
  2131. // Get all definitions with the particular option code. Note that option
  2132. // code is non-unique within this container however at this point we
  2133. // expect to get one option definition with the particular code. If more
  2134. // are returned we report an error.
  2135. const OptionDefContainerTypeRange& range = idx.equal_range(opt_type);
  2136. // Get the number of returned option definitions for the option code.
  2137. size_t num_defs = distance(range.first, range.second);
  2138. OptionPtr opt;
  2139. if (num_defs > 1) {
  2140. // Multiple options of the same code are not supported right now!
  2141. isc_throw(isc::Unexpected, "Internal error: multiple option definitions"
  2142. " for option type " << opt_type << " returned. Currently it is not"
  2143. " supported to initialize multiple option definitions"
  2144. " for the same option code. This will be supported once"
  2145. " support for option spaces is implemented");
  2146. } else if (num_defs == 0) {
  2147. // @todo Don't crash if definition does not exist because only a few
  2148. // option definitions are initialized right now. In the future
  2149. // we will initialize definitions for all options and we will
  2150. // remove this elseif. For now, return generic option.
  2151. opt = OptionPtr(new Option(Option::V6, opt_type,
  2152. buf.begin() + offset,
  2153. buf.begin() + offset + opt_len));
  2154. opt->setEncapsulatedSpace("dhcp6");
  2155. } else {
  2156. // The option definition has been found. Use it to create
  2157. // the option instance from the provided buffer chunk.
  2158. const OptionDefinitionPtr& def = *(range.first);
  2159. assert(def);
  2160. opt = def->optionFactory(Option::V6, opt_type,
  2161. buf.begin() + offset,
  2162. buf.begin() + offset + opt_len,
  2163. boost::bind(&Dhcpv6Srv::unpackOptions, this, _1, _2,
  2164. _3, _4, _5));
  2165. }
  2166. // add option to options
  2167. options.insert(std::make_pair(opt_type, opt));
  2168. offset += opt_len;
  2169. }
  2170. return (offset);
  2171. }
  2172. void
  2173. Dhcpv6Srv::ifaceMgrSocket6ErrorHandler(const std::string& errmsg) {
  2174. // Log the reason for socket opening failure and return.
  2175. LOG_WARN(dhcp6_logger, DHCP6_OPEN_SOCKET_FAIL).arg(errmsg);
  2176. }
  2177. void Dhcpv6Srv::classifyPacket(const Pkt6Ptr& pkt) {
  2178. OptionVendorClassPtr vclass = boost::dynamic_pointer_cast<
  2179. OptionVendorClass>(pkt->getOption(D6O_VENDOR_CLASS));
  2180. if (!vclass || vclass->getTuplesNum() == 0) {
  2181. return;
  2182. }
  2183. std::ostringstream classes;
  2184. if (vclass->hasTuple(DOCSIS3_CLASS_MODEM)) {
  2185. classes << VENDOR_CLASS_PREFIX << DOCSIS3_CLASS_MODEM;
  2186. } else if (vclass->hasTuple(DOCSIS3_CLASS_EROUTER)) {
  2187. classes << VENDOR_CLASS_PREFIX << DOCSIS3_CLASS_EROUTER;
  2188. } else {
  2189. classes << vclass->getTuple(0).getText();
  2190. }
  2191. // If there is no class identified, leave.
  2192. if (!classes.str().empty()) {
  2193. pkt->addClass(classes.str());
  2194. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_CLASS_ASSIGNED)
  2195. .arg(classes.str());
  2196. }
  2197. }
  2198. void
  2199. Dhcpv6Srv::generateFqdn(const Pkt6Ptr& answer) {
  2200. if (!answer) {
  2201. isc_throw(isc::Unexpected, "an instance of the object encapsulating"
  2202. " a message must not be NULL when generating FQDN");
  2203. }
  2204. // It is likely that client haven't included the FQDN option. In such case,
  2205. // FQDN option will be NULL. Also, there is nothing to do if the option
  2206. // is present and conveys the non-empty FQDN.
  2207. Option6ClientFqdnPtr fqdn = boost::dynamic_pointer_cast<
  2208. Option6ClientFqdn>(answer->getOption(D6O_CLIENT_FQDN));
  2209. if (!fqdn || !fqdn->getDomainName().empty()) {
  2210. return;
  2211. }
  2212. // Get the first IA_NA acquired for the client.
  2213. OptionPtr ia = answer->getOption(D6O_IA_NA);
  2214. if (!ia) {
  2215. return;
  2216. }
  2217. // If it has any IAAddr, use the first one to generate unique FQDN.
  2218. Option6IAAddrPtr iaaddr = boost::dynamic_pointer_cast<
  2219. Option6IAAddr>(ia->getOption(D6O_IAADDR));
  2220. if (!iaaddr) {
  2221. return;
  2222. }
  2223. // Get the IPv6 address acquired by the client.
  2224. IOAddress addr = iaaddr->getAddress();
  2225. std::string generated_name =
  2226. CfgMgr::instance().getD2ClientMgr().generateFqdn(addr);
  2227. try {
  2228. // The lease has been acquired but the FQDN for this lease hasn't
  2229. // been updated in the lease database. We now have new FQDN
  2230. // generated, so the lease database has to be updated here.
  2231. // However, never update lease database for Advertise, just send
  2232. // our notion of client's FQDN in the Client FQDN option.
  2233. if (answer->getType() != DHCPV6_ADVERTISE) {
  2234. Lease6Ptr lease =
  2235. LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr);
  2236. if (lease) {
  2237. lease->hostname_ = generated_name;
  2238. LeaseMgrFactory::instance().updateLease6(lease);
  2239. } else {
  2240. isc_throw(isc::Unexpected, "there is no lease in the database "
  2241. " for address " << addr << ", so as it is impossible"
  2242. " to update FQDN data. This is a programmatic error"
  2243. " as the given address is now being handed to the"
  2244. " client");
  2245. }
  2246. }
  2247. // Set the generated FQDN in the Client FQDN option.
  2248. fqdn->setDomainName(generated_name, Option6ClientFqdn::FULL);
  2249. } catch (const Exception& ex) {
  2250. LOG_ERROR(dhcp6_logger, DHCP6_NAME_GEN_UPDATE_FAIL)
  2251. .arg(addr.toText())
  2252. .arg(ex.what());
  2253. }
  2254. }
  2255. void
  2256. Dhcpv6Srv::startD2() {
  2257. D2ClientMgr& d2_mgr = CfgMgr::instance().getD2ClientMgr();
  2258. if (d2_mgr.ddnsEnabled()) {
  2259. // Updates are enabled, so lets start the sender, passing in
  2260. // our error handler.
  2261. // This may throw so wherever this is called needs to ready.
  2262. d2_mgr.startSender(boost::bind(&Dhcpv6Srv::d2ClientErrorHandler,
  2263. this, _1, _2));
  2264. }
  2265. }
  2266. void
  2267. Dhcpv6Srv::d2ClientErrorHandler(const
  2268. dhcp_ddns::NameChangeSender::Result result,
  2269. dhcp_ddns::NameChangeRequestPtr& ncr) {
  2270. LOG_ERROR(dhcp6_logger, DHCP6_DDNS_REQUEST_SEND_FAILED).
  2271. arg(result).arg((ncr ? ncr->toText() : " NULL "));
  2272. // We cannot communicate with kea-dhcp-ddns, suspend futher updates.
  2273. /// @todo We may wish to revisit this, but for now we will simpy turn
  2274. /// them off.
  2275. CfgMgr::instance().getD2ClientMgr().suspendUpdates();
  2276. }
  2277. };
  2278. };