dhcp6_srv.cc 105 KB

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