dhcp6_srv.cc 122 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234
  1. // Copyright (C) 2011-2016 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. #include <config.h>
  7. #include <asiolink/io_address.h>
  8. #include <dhcp_ddns/ncr_msg.h>
  9. #include <dhcp/dhcp6.h>
  10. #include <dhcp/docsis3_option_defs.h>
  11. #include <dhcp/duid.h>
  12. #include <dhcp/duid_factory.h>
  13. #include <dhcp/iface_mgr.h>
  14. #include <dhcp/libdhcp++.h>
  15. #include <dhcp/option6_addrlst.h>
  16. #include <dhcp/option6_client_fqdn.h>
  17. #include <dhcp/option6_ia.h>
  18. #include <dhcp/option6_iaaddr.h>
  19. #include <dhcp/option6_iaprefix.h>
  20. #include <dhcp/option6_status_code.h>
  21. #include <dhcp/option_custom.h>
  22. #include <dhcp/option_vendor.h>
  23. #include <dhcp/option_vendor_class.h>
  24. #include <dhcp/option_int_array.h>
  25. #include <dhcp/pkt6.h>
  26. #include <dhcp6/dhcp6to4_ipc.h>
  27. #include <dhcp6/dhcp6_log.h>
  28. #include <dhcp6/dhcp6_srv.h>
  29. #include <dhcpsrv/callout_handle_store.h>
  30. #include <dhcpsrv/cfg_host_operations.h>
  31. #include <dhcpsrv/cfgmgr.h>
  32. #include <dhcpsrv/lease_mgr.h>
  33. #include <dhcpsrv/lease_mgr_factory.h>
  34. #include <dhcpsrv/ncr_generator.h>
  35. #include <dhcpsrv/subnet.h>
  36. #include <dhcpsrv/subnet_selector.h>
  37. #include <dhcpsrv/utils.h>
  38. #include <eval/evaluate.h>
  39. #include <eval/eval_messages.h>
  40. #include <exceptions/exceptions.h>
  41. #include <hooks/callout_handle.h>
  42. #include <hooks/hooks_log.h>
  43. #include <hooks/hooks_manager.h>
  44. #include <stats/stats_mgr.h>
  45. #include <util/encode/hex.h>
  46. #include <util/io_utilities.h>
  47. #include <util/range_utilities.h>
  48. #include <log/logger.h>
  49. #include <cryptolink/cryptolink.h>
  50. #include <cfgrpt/config_report.h>
  51. #ifdef HAVE_MYSQL
  52. #include <dhcpsrv/mysql_lease_mgr.h>
  53. #endif
  54. #ifdef HAVE_PGSQL
  55. #include <dhcpsrv/pgsql_lease_mgr.h>
  56. #endif
  57. #ifdef HAVE_CQL
  58. #include <dhcpsrv/cql_lease_mgr.h>
  59. #endif
  60. #include <dhcpsrv/memfile_lease_mgr.h>
  61. #include <boost/bind.hpp>
  62. #include <boost/foreach.hpp>
  63. #include <boost/tokenizer.hpp>
  64. #include <boost/algorithm/string/erase.hpp>
  65. #include <boost/algorithm/string/join.hpp>
  66. #include <boost/algorithm/string/split.hpp>
  67. #include <stdlib.h>
  68. #include <time.h>
  69. #include <iomanip>
  70. #include <fstream>
  71. #include <sstream>
  72. using namespace isc;
  73. using namespace isc::asiolink;
  74. using namespace isc::cryptolink;
  75. using namespace isc::dhcp;
  76. using namespace isc::dhcp_ddns;
  77. using namespace isc::hooks;
  78. using namespace isc::log;
  79. using namespace isc::stats;
  80. using namespace isc::util;
  81. using namespace std;
  82. namespace {
  83. /// Structure that holds registered hook indexes
  84. struct Dhcp6Hooks {
  85. int hook_index_buffer6_receive_;///< index for "buffer6_receive" hook point
  86. int hook_index_pkt6_receive_; ///< index for "pkt6_receive" hook point
  87. int hook_index_subnet6_select_; ///< index for "subnet6_select" hook point
  88. int hook_index_lease6_release_; ///< index for "lease6_release" hook point
  89. int hook_index_pkt6_send_; ///< index for "pkt6_send" hook point
  90. int hook_index_buffer6_send_; ///< index for "buffer6_send" hook point
  91. int hook_index_lease6_decline_; ///< index for "lease6_decline" hook point
  92. /// Constructor that registers hook points for DHCPv6 engine
  93. Dhcp6Hooks() {
  94. hook_index_buffer6_receive_= HooksManager::registerHook("buffer6_receive");
  95. hook_index_pkt6_receive_ = HooksManager::registerHook("pkt6_receive");
  96. hook_index_subnet6_select_ = HooksManager::registerHook("subnet6_select");
  97. hook_index_lease6_release_ = HooksManager::registerHook("lease6_release");
  98. hook_index_pkt6_send_ = HooksManager::registerHook("pkt6_send");
  99. hook_index_buffer6_send_ = HooksManager::registerHook("buffer6_send");
  100. hook_index_lease6_decline_ = HooksManager::registerHook("lease6_decline");
  101. }
  102. };
  103. // Declare a Hooks object. As this is outside any function or method, it
  104. // will be instantiated (and the constructor run) when the module is loaded.
  105. // As a result, the hook indexes will be defined before any method in this
  106. // module is called.
  107. Dhcp6Hooks Hooks;
  108. /// @brief Creates instance of the Status Code option.
  109. ///
  110. /// This variant of the function is used when the Status Code option
  111. /// is added as a top-level option. It logs the debug message and
  112. /// includes the information about the client and transaction.
  113. ///
  114. /// @param pkt Reference to the client's message.
  115. /// @param status_code Numeric status code.
  116. /// @param status_message Status message.
  117. ///
  118. /// @return Pointer to the Status Code option.
  119. OptionPtr
  120. createStatusCode(const Pkt6& pkt, const uint16_t status_code,
  121. const std::string& status_message) {
  122. Option6StatusCodePtr option_status(new Option6StatusCode(status_code,
  123. status_message));
  124. LOG_DEBUG(options6_logger, DBG_DHCP6_DETAIL, DHCP6_ADD_GLOBAL_STATUS_CODE)
  125. .arg(pkt.getLabel())
  126. .arg(option_status->dataToText());
  127. return (option_status);
  128. }
  129. /// @brief Creates instance of the Status Code option.
  130. ///
  131. /// This variant of the function is used when the Status Code option
  132. /// is added to one of the IA options. It logs the debug message and
  133. /// includes the information about the client and transaction as well
  134. /// as IAID of the IA option.
  135. ///
  136. /// @param pkt Reference to the client's message.
  137. /// param ia Reference to the IA option to which the Status Code is
  138. /// being added.
  139. /// @param status_code Numeric status code.
  140. /// @param status_message Status message.
  141. ///
  142. /// @return Pointer to the Status Code option.
  143. OptionPtr
  144. createStatusCode(const Pkt6& pkt, const Option6IA& ia, const uint16_t status_code,
  145. const std::string& status_message) {
  146. Option6StatusCodePtr option_status(new Option6StatusCode(status_code,
  147. status_message));
  148. LOG_DEBUG(options6_logger, DBG_DHCP6_DETAIL, DHCP6_ADD_STATUS_CODE_FOR_IA)
  149. .arg(pkt.getLabel())
  150. .arg(ia.getIAID())
  151. .arg(option_status->dataToText());
  152. return (option_status);
  153. }
  154. }; // anonymous namespace
  155. namespace isc {
  156. namespace dhcp {
  157. const std::string Dhcpv6Srv::VENDOR_CLASS_PREFIX("VENDOR_CLASS_");
  158. Dhcpv6Srv::Dhcpv6Srv(uint16_t port)
  159. : port_(port), serverid_(), shutdown_(true), alloc_engine_()
  160. {
  161. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_START, DHCP6_OPEN_SOCKET).arg(port);
  162. // Initialize objects required for DHCP server operation.
  163. try {
  164. // Port 0 is used for testing purposes where in most cases we don't
  165. // rely on the physical interfaces. Therefore, it should be possible
  166. // to create an object even when there are no usable interfaces.
  167. if ((port > 0) && (IfaceMgr::instance().countIfaces() == 0)) {
  168. LOG_ERROR(dhcp6_logger, DHCP6_NO_INTERFACES);
  169. return;
  170. }
  171. // Create a DUID instance but do not store it into a file.
  172. DUIDFactory duid_factory;
  173. DuidPtr duid = duid_factory.get();
  174. serverid_.reset(new Option(Option::V6, D6O_SERVERID, duid->getDuid()));
  175. // Instantiate allocation engine. The number of allocation attempts equal
  176. // to zero indicates that the allocation engine will use the number of
  177. // attempts depending on the pool size.
  178. alloc_engine_.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0));
  179. /// @todo call loadLibraries() when handling configuration changes
  180. } catch (const std::exception &e) {
  181. LOG_ERROR(dhcp6_logger, DHCP6_SRV_CONSTRUCT_ERROR).arg(e.what());
  182. return;
  183. }
  184. // All done, so can proceed
  185. shutdown_ = false;
  186. }
  187. Dhcpv6Srv::~Dhcpv6Srv() {
  188. try {
  189. stopD2();
  190. } catch(const std::exception& ex) {
  191. // Highly unlikely, but lets Report it but go on
  192. LOG_ERROR(dhcp6_logger, DHCP6_SRV_D2STOP_ERROR).arg(ex.what());
  193. }
  194. try {
  195. Dhcp6to4Ipc::instance().close();
  196. } catch(const std::exception& ex) {
  197. // Highly unlikely, but lets Report it but go on
  198. // LOG_ERROR(dhcp6_logger, DHCP6_SRV_DHCP4O6_ERROR).arg(ex.what());
  199. }
  200. IfaceMgr::instance().closeSockets();
  201. LeaseMgrFactory::destroy();
  202. // Explicitly unload hooks
  203. HooksManager::getHooksManager().unloadLibraries();
  204. }
  205. void Dhcpv6Srv::shutdown() {
  206. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_SHUTDOWN_REQUEST);
  207. shutdown_ = true;
  208. }
  209. Pkt6Ptr Dhcpv6Srv::receivePacket(int timeout) {
  210. return (IfaceMgr::instance().receive6(timeout));
  211. }
  212. void Dhcpv6Srv::sendPacket(const Pkt6Ptr& packet) {
  213. IfaceMgr::instance().send(packet);
  214. }
  215. bool
  216. Dhcpv6Srv::testServerID(const Pkt6Ptr& pkt) {
  217. /// @todo Currently we always check server identifier regardless if
  218. /// it is allowed in the received message or not (per RFC3315).
  219. /// If the server identifier is not allowed in the message, the
  220. /// sanityCheck function should deal with it.
  221. OptionPtr server_id = pkt->getOption(D6O_SERVERID);
  222. if (server_id){
  223. // Let us test received ServerID if it is same as ServerID
  224. // which is being used by server
  225. if (getServerID()->getData() != server_id->getData()){
  226. LOG_DEBUG(bad_packet6_logger, DBG_DHCP6_DETAIL_DATA,
  227. DHCP6_PACKET_DROP_SERVERID_MISMATCH)
  228. .arg(pkt->getLabel())
  229. .arg(duidToString(server_id))
  230. .arg(duidToString(getServerID()));
  231. return (false);
  232. }
  233. }
  234. // return True if: no serverid received or ServerIDs matching
  235. return (true);
  236. }
  237. bool
  238. Dhcpv6Srv::testUnicast(const Pkt6Ptr& pkt) const {
  239. switch (pkt->getType()) {
  240. case DHCPV6_SOLICIT:
  241. case DHCPV6_CONFIRM:
  242. case DHCPV6_REBIND:
  243. case DHCPV6_INFORMATION_REQUEST:
  244. if (pkt->relay_info_.empty() && !pkt->getLocalAddr().isV6Multicast()) {
  245. LOG_DEBUG(bad_packet6_logger, DBG_DHCP6_DETAIL, DHCP6_PACKET_DROP_UNICAST)
  246. .arg(pkt->getLabel())
  247. .arg(pkt->getName());
  248. return (false);
  249. }
  250. break;
  251. default:
  252. // do nothing
  253. ;
  254. }
  255. return (true);
  256. }
  257. void
  258. Dhcpv6Srv::initContext(const Pkt6Ptr& pkt, AllocEngine::ClientContext6& ctx) {
  259. ctx.subnet_ = selectSubnet(pkt);
  260. ctx.duid_ = pkt->getClientId(),
  261. ctx.fwd_dns_update_ = false;
  262. ctx.rev_dns_update_ = false;
  263. ctx.hostname_ = "";
  264. ctx.query_ = pkt;
  265. ctx.callout_handle_ = getCalloutHandle(pkt);
  266. ctx.hwaddr_ = getMAC(pkt);
  267. // Collect host identifiers if host reservations enabled. The identifiers
  268. // are stored in order of preference. The server will use them in that
  269. // order to search for host reservations.
  270. if (ctx.subnet_ &&
  271. (ctx.subnet_->getHostReservationMode() != Subnet::HR_DISABLED)) {
  272. const ConstCfgHostOperationsPtr cfg =
  273. CfgMgr::instance().getCurrentCfg()->getCfgHostOperations6();
  274. BOOST_FOREACH(const Host::IdentifierType& id_type,
  275. cfg->getIdentifierTypes()) {
  276. switch (id_type) {
  277. case Host::IDENT_DUID:
  278. if (ctx.duid_) {
  279. ctx.addHostIdentifier(id_type, ctx.duid_->getDuid());
  280. }
  281. break;
  282. case Host::IDENT_HWADDR:
  283. if (ctx.hwaddr_) {
  284. ctx.addHostIdentifier(id_type, ctx.hwaddr_->hwaddr_);
  285. }
  286. break;
  287. default:
  288. ;
  289. }
  290. }
  291. // Find host reservations using specified identifiers.
  292. alloc_engine_->findReservation(ctx);
  293. }
  294. }
  295. bool Dhcpv6Srv::run() {
  296. while (!shutdown_) {
  297. try {
  298. run_one();
  299. } catch (const std::exception& e) {
  300. // General catch-all standard exceptions that are not caught by more
  301. // specific catches.
  302. LOG_ERROR(packet6_logger, DHCP6_PACKET_PROCESS_STD_EXCEPTION)
  303. .arg(e.what());
  304. } catch (...) {
  305. // General catch-all non-standard exception that are not caught
  306. // by more specific catches.
  307. LOG_ERROR(packet6_logger, DHCP6_PACKET_PROCESS_EXCEPTION);
  308. }
  309. }
  310. return (true);
  311. }
  312. void Dhcpv6Srv::run_one() {
  313. // client's message and server's response
  314. Pkt6Ptr query;
  315. Pkt6Ptr rsp;
  316. try {
  317. uint32_t timeout = 1000;
  318. LOG_DEBUG(packet6_logger, DBG_DHCP6_DETAIL, DHCP6_BUFFER_WAIT).arg(timeout);
  319. query = receivePacket(timeout);
  320. // Log if packet has arrived. We can't log the detailed information
  321. // about the DHCP message because it hasn't been unpacked/parsed
  322. // yet, and it can't be parsed at this point because hooks will
  323. // have to process it first. The only information available at this
  324. // point are: the interface, source address and destination addresses
  325. // and ports.
  326. if (query) {
  327. LOG_DEBUG(packet6_logger, DBG_DHCP6_BASIC, DHCP6_BUFFER_RECEIVED)
  328. .arg(query->getRemoteAddr().toText())
  329. .arg(query->getRemotePort())
  330. .arg(query->getLocalAddr().toText())
  331. .arg(query->getLocalPort())
  332. .arg(query->getIface());
  333. // Log reception of the packet. We need to increase it early, as
  334. // any failures in unpacking will cause the packet to be dropped.
  335. // we will increase type specific packets further down the road.
  336. // See processStatsReceived().
  337. StatsMgr::instance().addValue("pkt6-received", static_cast<int64_t>(1));
  338. } else {
  339. LOG_DEBUG(packet6_logger, DBG_DHCP6_DETAIL, DHCP6_BUFFER_WAIT_INTERRUPTED)
  340. .arg(timeout);
  341. }
  342. } catch (const SignalInterruptOnSelect) {
  343. // Packet reception interrupted because a signal has been received.
  344. // This is not an error because we might have received a SIGTERM,
  345. // SIGINT or SIGHUP which are handled by the server. For signals
  346. // that are not handled by the server we rely on the default
  347. // behavior of the system.
  348. LOG_DEBUG(packet6_logger, DBG_DHCP6_DETAIL, DHCP6_BUFFER_WAIT_SIGNAL)
  349. .arg(signal_set_->getNext());
  350. } catch (const std::exception& e) {
  351. LOG_ERROR(packet6_logger, DHCP6_PACKET_RECEIVE_FAIL).arg(e.what());
  352. }
  353. // Handle next signal received by the process. It must be called after
  354. // an attempt to receive a packet to properly handle server shut down.
  355. // The SIGTERM or SIGINT will be received prior to, or during execution
  356. // of select() (select is invoked by receivePacket()). When that happens,
  357. // select will be interrupted. The signal handler will be invoked
  358. // immediately after select(). The handler will set the shutdown flag
  359. // and cause the process to terminate before the next select() function
  360. // is called. If the function was called before receivePacket the
  361. // process could wait up to the duration of timeout of select() to
  362. // terminate.
  363. try {
  364. handleSignal();
  365. } catch (const std::exception& e) {
  366. // An (a standard or ISC) exception occurred.
  367. LOG_ERROR(dhcp6_logger, DHCP6_HANDLE_SIGNAL_EXCEPTION)
  368. .arg(e.what());
  369. }
  370. // Timeout may be reached or signal received, which breaks select()
  371. // with no packet received
  372. if (!query) {
  373. return;
  374. }
  375. processPacket(query, rsp);
  376. if (!rsp) {
  377. return;
  378. }
  379. try {
  380. // Now all fields and options are constructed into output wire buffer.
  381. // Option objects modification does not make sense anymore. Hooks
  382. // can only manipulate wire buffer at this stage.
  383. // Let's execute all callouts registered for buffer6_send
  384. if (HooksManager::calloutsPresent(Hooks.hook_index_buffer6_send_)) {
  385. CalloutHandlePtr callout_handle = getCalloutHandle(query);
  386. // Delete previously set arguments
  387. callout_handle->deleteAllArguments();
  388. // Enable copying options from the packet within hook library.
  389. ScopedEnableOptionsCopy<Pkt6> response6_options_copy(rsp);
  390. // Pass incoming packet as argument
  391. callout_handle->setArgument("response6", rsp);
  392. // Call callouts
  393. HooksManager::callCallouts(Hooks.hook_index_buffer6_send_, *callout_handle);
  394. // Callouts decided to skip the next processing step. The next
  395. // processing step would to parse the packet, so skip at this
  396. // stage means drop.
  397. if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) {
  398. LOG_DEBUG(hooks_logger, DBG_DHCP6_HOOKS, DHCP6_HOOK_BUFFER_SEND_SKIP)
  399. .arg(rsp->getLabel());
  400. return;
  401. }
  402. /// @todo: Add support for DROP status
  403. callout_handle->getArgument("response6", rsp);
  404. }
  405. LOG_DEBUG(packet6_logger, DBG_DHCP6_DETAIL_DATA, DHCP6_RESPONSE_DATA)
  406. .arg(static_cast<int>(rsp->getType())).arg(rsp->toText());
  407. sendPacket(rsp);
  408. // Update statistics accordingly for sent packet.
  409. processStatsSent(rsp);
  410. } catch (const std::exception& e) {
  411. LOG_ERROR(packet6_logger, DHCP6_PACKET_SEND_FAIL).arg(e.what());
  412. }
  413. }
  414. void
  415. Dhcpv6Srv::processPacket(Pkt6Ptr& query, Pkt6Ptr& rsp) {
  416. bool skip_unpack = false;
  417. // The packet has just been received so contains the uninterpreted wire
  418. // data; execute callouts registered for buffer6_receive.
  419. if (HooksManager::calloutsPresent(Hooks.hook_index_buffer6_receive_)) {
  420. CalloutHandlePtr callout_handle = getCalloutHandle(query);
  421. // Enable copying options from the packet within hook library.
  422. ScopedEnableOptionsCopy<Pkt6> query6_options_copy(query);
  423. // Delete previously set arguments
  424. callout_handle->deleteAllArguments();
  425. // Pass incoming packet as argument
  426. callout_handle->setArgument("query6", query);
  427. // Call callouts
  428. HooksManager::callCallouts(Hooks.hook_index_buffer6_receive_, *callout_handle);
  429. // Callouts decided to skip the next processing step. The next
  430. // processing step would to parse the packet, so skip at this
  431. // stage means that callouts did the parsing already, so server
  432. // should skip parsing.
  433. if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) {
  434. LOG_DEBUG(hooks_logger, DBG_DHCP6_DETAIL, DHCP6_HOOK_BUFFER_RCVD_SKIP)
  435. .arg(query->getRemoteAddr().toText())
  436. .arg(query->getLocalAddr().toText())
  437. .arg(query->getIface());
  438. skip_unpack = true;
  439. }
  440. /// @todo: Add support for DROP status.
  441. callout_handle->getArgument("query6", query);
  442. }
  443. // Unpack the packet information unless the buffer6_receive callouts
  444. // indicated they did it
  445. if (!skip_unpack) {
  446. try {
  447. LOG_DEBUG(options6_logger, DBG_DHCP6_DETAIL, DHCP6_BUFFER_UNPACK)
  448. .arg(query->getRemoteAddr().toText())
  449. .arg(query->getLocalAddr().toText())
  450. .arg(query->getIface());
  451. query->unpack();
  452. } catch (const std::exception &e) {
  453. // Failed to parse the packet.
  454. LOG_DEBUG(bad_packet6_logger, DBG_DHCP6_DETAIL,
  455. DHCP6_PACKET_DROP_PARSE_FAIL)
  456. .arg(query->getRemoteAddr().toText())
  457. .arg(query->getLocalAddr().toText())
  458. .arg(query->getIface())
  459. .arg(e.what());
  460. // Increase the statistics of parse failures and dropped packets.
  461. StatsMgr::instance().addValue("pkt6-parse-failed",
  462. static_cast<int64_t>(1));
  463. StatsMgr::instance().addValue("pkt6-receive-drop",
  464. static_cast<int64_t>(1));
  465. return;
  466. }
  467. }
  468. // Update statistics accordingly for received packet.
  469. processStatsReceived(query);
  470. // Check if received query carries server identifier matching
  471. // server identifier being used by the server.
  472. if (!testServerID(query)) {
  473. // Increase the statistic of dropped packets.
  474. StatsMgr::instance().addValue("pkt6-receive-drop", static_cast<int64_t>(1));
  475. return;
  476. }
  477. // Check if the received query has been sent to unicast or multicast.
  478. // The Solicit, Confirm, Rebind and Information Request will be
  479. // discarded if sent to unicast address.
  480. if (!testUnicast(query)) {
  481. // Increase the statistic of dropped packets.
  482. StatsMgr::instance().addValue("pkt6-receive-drop", static_cast<int64_t>(1));
  483. return;
  484. }
  485. LOG_DEBUG(packet6_logger, DBG_DHCP6_BASIC_DATA, DHCP6_PACKET_RECEIVED)
  486. .arg(query->getLabel())
  487. .arg(query->getName())
  488. .arg(static_cast<int>(query->getType()))
  489. .arg(query->getRemoteAddr())
  490. .arg(query->getLocalAddr())
  491. .arg(query->getIface());
  492. LOG_DEBUG(packet6_logger, DBG_DHCP6_DETAIL_DATA, DHCP6_QUERY_DATA)
  493. .arg(query->getLabel())
  494. .arg(query->toText());
  495. // At this point the information in the packet has been unpacked into
  496. // the various packet fields and option objects has been created.
  497. // Execute callouts registered for packet6_receive.
  498. if (HooksManager::calloutsPresent(Hooks.hook_index_pkt6_receive_)) {
  499. CalloutHandlePtr callout_handle = getCalloutHandle(query);
  500. // Delete previously set arguments
  501. callout_handle->deleteAllArguments();
  502. // Enable copying options from the packet within hook library.
  503. ScopedEnableOptionsCopy<Pkt6> query6_options_copy(query);
  504. // Pass incoming packet as argument
  505. callout_handle->setArgument("query6", query);
  506. // Call callouts
  507. HooksManager::callCallouts(Hooks.hook_index_pkt6_receive_, *callout_handle);
  508. // Callouts decided to skip the next processing step. The next
  509. // processing step would to process the packet, so skip at this
  510. // stage means drop.
  511. if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) {
  512. LOG_DEBUG(hooks_logger, DBG_DHCP6_HOOKS, DHCP6_HOOK_PACKET_RCVD_SKIP)
  513. .arg(query->getLabel());
  514. return;
  515. }
  516. /// @todo: Add support for DROP status.
  517. callout_handle->getArgument("query6", query);
  518. }
  519. // Assign this packet to a class, if possible
  520. classifyPacket(query);
  521. try {
  522. NameChangeRequestPtr ncr;
  523. switch (query->getType()) {
  524. case DHCPV6_SOLICIT:
  525. rsp = processSolicit(query);
  526. break;
  527. case DHCPV6_REQUEST:
  528. rsp = processRequest(query);
  529. break;
  530. case DHCPV6_RENEW:
  531. rsp = processRenew(query);
  532. break;
  533. case DHCPV6_REBIND:
  534. rsp = processRebind(query);
  535. break;
  536. case DHCPV6_CONFIRM:
  537. rsp = processConfirm(query);
  538. break;
  539. case DHCPV6_RELEASE:
  540. rsp = processRelease(query);
  541. break;
  542. case DHCPV6_DECLINE:
  543. rsp = processDecline(query);
  544. break;
  545. case DHCPV6_INFORMATION_REQUEST:
  546. rsp = processInfRequest(query);
  547. break;
  548. case DHCPV6_DHCPV4_QUERY:
  549. processDhcp4Query(query);
  550. break;
  551. default:
  552. // We received a packet type that we do not recognize.
  553. LOG_DEBUG(bad_packet6_logger, DBG_DHCP6_BASIC, DHCP6_UNKNOWN_MSG_RECEIVED)
  554. .arg(static_cast<int>(query->getType()))
  555. .arg(query->getIface());
  556. // Only action is to output a message if debug is enabled,
  557. // and that will be covered by the debug statement before
  558. // the "switch" statement.
  559. ;
  560. }
  561. } catch (const RFCViolation& e) {
  562. LOG_DEBUG(bad_packet6_logger, DBG_DHCP6_BASIC, DHCP6_REQUIRED_OPTIONS_CHECK_FAIL)
  563. .arg(query->getName())
  564. .arg(query->getRemoteAddr().toText())
  565. .arg(e.what());
  566. // Increase the statistic of dropped packets.
  567. StatsMgr::instance().addValue("pkt6-receive-drop", static_cast<int64_t>(1));
  568. } catch (const std::exception& e) {
  569. // Catch-all exception (at least for ones based on the isc Exception
  570. // class, which covers more or less all that are explicitly raised
  571. // in the Kea code), but also the standard one, which may possibly be
  572. // thrown from boost code. Just log the problem and ignore the packet.
  573. // (The problem is logged as a debug message because debug is
  574. // disabled by default - it prevents a DDOS attack based on the
  575. // sending of problem packets.)
  576. LOG_DEBUG(bad_packet6_logger, DBG_DHCP6_BASIC, DHCP6_PACKET_PROCESS_FAIL)
  577. .arg(query->getName())
  578. .arg(query->getRemoteAddr().toText())
  579. .arg(e.what());
  580. // Increase the statistic of dropped packets.
  581. StatsMgr::instance().addValue("pkt6-receive-drop", static_cast<int64_t>(1));
  582. }
  583. if (!rsp) {
  584. return;
  585. }
  586. // Process relay-supplied options. It is important to call this very
  587. // late in the process, because we now have all the options the
  588. // server wanted to send already set. This is important, because
  589. // RFC6422, section 6 states:
  590. //
  591. // The server SHOULD discard any options that appear in the RSOO
  592. // for which it already has one or more candidates.
  593. //
  594. // So we ignore any RSOO options if there's an option with the same
  595. // code already present.
  596. processRSOO(query, rsp);
  597. rsp->setRemoteAddr(query->getRemoteAddr());
  598. rsp->setLocalAddr(query->getLocalAddr());
  599. if (rsp->relay_info_.empty()) {
  600. // Direct traffic, send back to the client directly
  601. rsp->setRemotePort(DHCP6_CLIENT_PORT);
  602. } else {
  603. // Relayed traffic, send back to the relay agent
  604. rsp->setRemotePort(DHCP6_SERVER_PORT);
  605. }
  606. rsp->setLocalPort(DHCP6_SERVER_PORT);
  607. rsp->setIndex(query->getIndex());
  608. rsp->setIface(query->getIface());
  609. // Specifies if server should do the packing
  610. bool skip_pack = false;
  611. // Server's reply packet now has all options and fields set.
  612. // Options are represented by individual objects, but the
  613. // output wire data has not been prepared yet.
  614. // Execute all callouts registered for packet6_send
  615. if (HooksManager::calloutsPresent(Hooks.hook_index_pkt6_send_)) {
  616. CalloutHandlePtr callout_handle = getCalloutHandle(query);
  617. // Enable copying options from the packets within hook library.
  618. ScopedEnableOptionsCopy<Pkt6> query_resp_options_copy(query, rsp);
  619. // Delete all previous arguments
  620. callout_handle->deleteAllArguments();
  621. // Pass incoming packet as argument
  622. callout_handle->setArgument("query6", query);
  623. // Set our response
  624. callout_handle->setArgument("response6", rsp);
  625. // Call all installed callouts
  626. HooksManager::callCallouts(Hooks.hook_index_pkt6_send_, *callout_handle);
  627. // Callouts decided to skip the next processing step. The next
  628. // processing step would to pack the packet (create wire data).
  629. // That step will be skipped if any callout sets skip flag.
  630. // It essentially means that the callout already did packing,
  631. // so the server does not have to do it again.
  632. if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) {
  633. LOG_DEBUG(hooks_logger, DBG_DHCP6_HOOKS, DHCP6_HOOK_PACKET_SEND_SKIP)
  634. .arg(rsp->getLabel());
  635. skip_pack = true;
  636. }
  637. /// @todo: Add support for DROP status
  638. }
  639. if (!skip_pack) {
  640. try {
  641. rsp->pack();
  642. } catch (const std::exception& e) {
  643. LOG_ERROR(options6_logger, DHCP6_PACK_FAIL).arg(e.what());
  644. return;
  645. }
  646. }
  647. }
  648. std::string
  649. Dhcpv6Srv::duidToString(const OptionPtr& opt) {
  650. stringstream tmp;
  651. OptionBuffer data = opt->getData();
  652. bool colon = false;
  653. for (OptionBufferConstIter it = data.begin(); it != data.end(); ++it) {
  654. if (colon) {
  655. tmp << ":";
  656. }
  657. tmp << hex << setw(2) << setfill('0') << static_cast<uint16_t>(*it);
  658. if (!colon) {
  659. colon = true;
  660. }
  661. }
  662. return tmp.str();
  663. }
  664. void
  665. Dhcpv6Srv::copyClientOptions(const Pkt6Ptr& question, Pkt6Ptr& answer) {
  666. // Add client-id.
  667. OptionPtr clientid = question->getOption(D6O_CLIENTID);
  668. if (clientid) {
  669. answer->addOption(clientid);
  670. }
  671. /// @todo: Should throw if there is no client-id (except anonymous INF-REQUEST)
  672. // If this is a relayed message, we need to copy relay information
  673. if (!question->relay_info_.empty()) {
  674. answer->copyRelayInfo(question);
  675. }
  676. }
  677. void
  678. Dhcpv6Srv::appendDefaultOptions(const Pkt6Ptr&, Pkt6Ptr& answer,
  679. const CfgOptionList&) {
  680. // add server-id
  681. answer->addOption(getServerID());
  682. }
  683. void
  684. Dhcpv6Srv::buildCfgOptionList(const Pkt6Ptr& question,
  685. AllocEngine::ClientContext6& ctx,
  686. CfgOptionList& co_list) {
  687. // Firstly, host specific options.
  688. if (ctx.host_ && !ctx.host_->getCfgOption6()->empty()) {
  689. co_list.push_back(ctx.host_->getCfgOption6());
  690. }
  691. // Secondly, pool specific options. Pools are defined within a subnet, so
  692. // if there is no subnet, there is nothing to do.
  693. if (ctx.subnet_) {
  694. BOOST_FOREACH(const AllocEngine::ResourceType& resource,
  695. ctx.allocated_resources_) {
  696. PoolPtr pool = ctx.subnet_->getPool(resource.second == 128 ?
  697. Lease::TYPE_NA : Lease::TYPE_PD,
  698. resource.first, false);
  699. if (pool && !pool->getCfgOption()->empty()) {
  700. co_list.push_back(pool->getCfgOption());
  701. }
  702. }
  703. };
  704. // Next, subnet configured options.
  705. if (ctx.subnet_ && !ctx.subnet_->getCfgOption()->empty()) {
  706. co_list.push_back(ctx.subnet_->getCfgOption());
  707. }
  708. // Each class in the incoming packet
  709. const ClientClasses& classes = question->getClasses();
  710. for (ClientClasses::const_iterator cclass = classes.begin();
  711. cclass != classes.end(); ++cclass) {
  712. // Find the client class definition for this class
  713. const ClientClassDefPtr& ccdef = CfgMgr::instance().getCurrentCfg()->
  714. getClientClassDictionary()->findClass(*cclass);
  715. if (!ccdef) {
  716. // Not found: the class is not configured
  717. if (((*cclass).size() <= VENDOR_CLASS_PREFIX.size()) ||
  718. ((*cclass).compare(0, VENDOR_CLASS_PREFIX.size(), VENDOR_CLASS_PREFIX) != 0)) {
  719. // Not a VENDOR_CLASS_* so should be configured
  720. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_CLASS_UNCONFIGURED)
  721. .arg(question->getLabel())
  722. .arg(*cclass);
  723. }
  724. // Skip it
  725. continue;
  726. }
  727. if (ccdef->getCfgOption()->empty()) {
  728. // Skip classes which don't configure options
  729. continue;
  730. }
  731. co_list.push_back(ccdef->getCfgOption());
  732. }
  733. // Last global options
  734. if (!CfgMgr::instance().getCurrentCfg()->getCfgOption()->empty()) {
  735. co_list.push_back(CfgMgr::instance().getCurrentCfg()->getCfgOption());
  736. }
  737. }
  738. void
  739. Dhcpv6Srv::appendRequestedOptions(const Pkt6Ptr& question, Pkt6Ptr& answer,
  740. const CfgOptionList& co_list) {
  741. // Client requests some options using ORO option. Try to
  742. // get this option from client's message.
  743. boost::shared_ptr<OptionIntArray<uint16_t> > option_oro =
  744. boost::dynamic_pointer_cast<OptionIntArray<uint16_t> >
  745. (question->getOption(D6O_ORO));
  746. // Option ORO not found? We're done here then.
  747. if (!option_oro || co_list.empty()) {
  748. return;
  749. }
  750. // Get the list of options that client requested.
  751. const std::vector<uint16_t>& requested_opts = option_oro->getValues();
  752. BOOST_FOREACH(uint16_t opt, requested_opts) {
  753. // Iterate on the configured option list
  754. for (CfgOptionList::const_iterator copts = co_list.begin();
  755. copts != co_list.end(); ++copts) {
  756. OptionDescriptor desc = (*copts)->get("dhcp6", opt);
  757. // Got it: add it and jump to the outer loop
  758. if (desc.option_) {
  759. answer->addOption(desc.option_);
  760. break;
  761. }
  762. }
  763. }
  764. }
  765. void
  766. Dhcpv6Srv::appendRequestedVendorOptions(const Pkt6Ptr& question,
  767. Pkt6Ptr& answer,
  768. AllocEngine::ClientContext6& ctx,
  769. const CfgOptionList& co_list) {
  770. // Leave if there is no subnet matching the incoming packet.
  771. // There is no need to log the error message here because
  772. // it will be logged in the assignLease() when it fails to
  773. // pick the suitable subnet. We don't want to duplicate
  774. // error messages in such case.
  775. if (!ctx.subnet_) {
  776. return;
  777. }
  778. // Try to get the vendor option
  779. boost::shared_ptr<OptionVendor> vendor_req =
  780. boost::dynamic_pointer_cast<OptionVendor>(question->getOption(D6O_VENDOR_OPTS));
  781. if (!vendor_req || co_list.empty()) {
  782. return;
  783. }
  784. // Let's try to get ORO within that vendor-option
  785. /// @todo This is very specific to vendor-id=4491 (Cable Labs). Other vendors
  786. /// may have different policies.
  787. boost::shared_ptr<OptionUint16Array> oro =
  788. boost::dynamic_pointer_cast<OptionUint16Array>(vendor_req->getOption(DOCSIS3_V6_ORO));
  789. // Option ORO not found. Don't do anything then.
  790. if (!oro) {
  791. return;
  792. }
  793. uint32_t vendor_id = vendor_req->getVendorId();
  794. boost::shared_ptr<OptionVendor> vendor_rsp(new OptionVendor(Option::V6, vendor_id));
  795. // Get the list of options that client requested.
  796. bool added = false;
  797. const std::vector<uint16_t>& requested_opts = oro->getValues();
  798. BOOST_FOREACH(uint16_t opt, requested_opts) {
  799. for (CfgOptionList::const_iterator copts = co_list.begin();
  800. copts != co_list.end(); ++copts) {
  801. OptionDescriptor desc = (*copts)->get(vendor_id, opt);
  802. if (desc.option_) {
  803. vendor_rsp->addOption(desc.option_);
  804. added = true;
  805. break;
  806. }
  807. }
  808. }
  809. if (added) {
  810. answer->addOption(vendor_rsp);
  811. }
  812. }
  813. void
  814. Dhcpv6Srv::sanityCheck(const Pkt6Ptr& pkt, RequirementLevel clientid,
  815. RequirementLevel serverid) {
  816. OptionCollection client_ids = pkt->getOptions(D6O_CLIENTID);
  817. switch (clientid) {
  818. case MANDATORY:
  819. if (client_ids.size() != 1) {
  820. isc_throw(RFCViolation, "Exactly 1 client-id option expected in "
  821. << pkt->getName() << ", but " << client_ids.size()
  822. << " received");
  823. }
  824. break;
  825. case OPTIONAL:
  826. if (client_ids.size() > 1) {
  827. isc_throw(RFCViolation, "Too many (" << client_ids.size()
  828. << ") client-id options received in " << pkt->getName());
  829. }
  830. break;
  831. case FORBIDDEN:
  832. // doesn't make sense - client-id is always allowed
  833. break;
  834. }
  835. OptionCollection server_ids = pkt->getOptions(D6O_SERVERID);
  836. switch (serverid) {
  837. case FORBIDDEN:
  838. if (!server_ids.empty()) {
  839. isc_throw(RFCViolation, "Server-id option was not expected, but "
  840. << server_ids.size() << " received in " << pkt->getName());
  841. }
  842. break;
  843. case MANDATORY:
  844. if (server_ids.size() != 1) {
  845. isc_throw(RFCViolation, "Invalid number of server-id options received ("
  846. << server_ids.size() << "), exactly 1 expected in message "
  847. << pkt->getName());
  848. }
  849. break;
  850. case OPTIONAL:
  851. if (server_ids.size() > 1) {
  852. isc_throw(RFCViolation, "Too many (" << server_ids.size()
  853. << ") server-id options received in " << pkt->getName());
  854. }
  855. }
  856. }
  857. Subnet6Ptr
  858. Dhcpv6Srv::selectSubnet(const Pkt6Ptr& question) {
  859. // Initialize subnet selector with the values used to select the subnet.
  860. SubnetSelector selector;
  861. selector.iface_name_ = question->getIface();
  862. selector.remote_address_ = question->getRemoteAddr();
  863. selector.first_relay_linkaddr_ = IOAddress("::");
  864. selector.client_classes_ = question->classes_;
  865. // Initialize fields specific to relayed messages.
  866. if (!question->relay_info_.empty()) {
  867. BOOST_REVERSE_FOREACH(Pkt6::RelayInfo relay, question->relay_info_) {
  868. if (!relay.linkaddr_.isV6Zero() &&
  869. !relay.linkaddr_.isV6LinkLocal()) {
  870. selector.first_relay_linkaddr_ = relay.linkaddr_;
  871. break;
  872. }
  873. }
  874. selector.interface_id_ =
  875. question->getAnyRelayOption(D6O_INTERFACE_ID,
  876. Pkt6::RELAY_GET_FIRST);
  877. }
  878. Subnet6Ptr subnet = CfgMgr::instance().getCurrentCfg()->
  879. getCfgSubnets6()->selectSubnet(selector);
  880. // Let's execute all callouts registered for subnet6_receive
  881. if (HooksManager::calloutsPresent(Hooks.hook_index_subnet6_select_)) {
  882. CalloutHandlePtr callout_handle = getCalloutHandle(question);
  883. // We're reusing callout_handle from previous calls
  884. callout_handle->deleteAllArguments();
  885. // Enable copying options from the packet within hook library.
  886. ScopedEnableOptionsCopy<Pkt6> query6_options_copy(question);
  887. // Set new arguments
  888. callout_handle->setArgument("query6", question);
  889. callout_handle->setArgument("subnet6", subnet);
  890. // We pass pointer to const collection for performance reasons.
  891. // Otherwise we would get a non-trivial performance penalty each
  892. // time subnet6_select is called.
  893. callout_handle->setArgument("subnet6collection",
  894. CfgMgr::instance().getCurrentCfg()->
  895. getCfgSubnets6()->getAll());
  896. // Call user (and server-side) callouts
  897. HooksManager::callCallouts(Hooks.hook_index_subnet6_select_, *callout_handle);
  898. // Callouts decided to skip this step. This means that no
  899. // subnet will be selected. Packet processing will continue,
  900. // but it will be severely limited (i.e. only global options
  901. // will be assigned)
  902. if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) {
  903. LOG_DEBUG(hooks_logger, DBG_DHCP6_HOOKS, DHCP6_HOOK_SUBNET6_SELECT_SKIP)
  904. .arg(question->getLabel());
  905. return (Subnet6Ptr());
  906. }
  907. /// @todo: Add support for DROP status.
  908. // Use whatever subnet was specified by the callout
  909. callout_handle->getArgument("subnet6", subnet);
  910. }
  911. if (subnet) {
  912. // Log at higher debug level that subnet has been found.
  913. LOG_DEBUG(packet6_logger, DBG_DHCP6_BASIC_DATA, DHCP6_SUBNET_SELECTED)
  914. .arg(question->getLabel())
  915. .arg(subnet->getID());
  916. // Log detailed information about the selected subnet at the
  917. // lower debug level.
  918. LOG_DEBUG(packet6_logger, DBG_DHCP6_DETAIL_DATA, DHCP6_SUBNET_DATA)
  919. .arg(question->getLabel())
  920. .arg(subnet->toText());
  921. } else {
  922. LOG_DEBUG(packet6_logger, DBG_DHCP6_DETAIL, DHCP6_SUBNET_SELECTION_FAILED)
  923. .arg(question->getLabel());
  924. }
  925. return (subnet);
  926. }
  927. void
  928. Dhcpv6Srv::assignLeases(const Pkt6Ptr& question, Pkt6Ptr& answer,
  929. AllocEngine::ClientContext6& ctx) {
  930. // We need to allocate addresses for all IA_NA options in the client's
  931. // question (i.e. SOLICIT or REQUEST) message.
  932. // @todo add support for IA_TA
  933. // For the lease allocation it is critical that the client has sent
  934. // DUID. There is no need to check for the presence of the DUID here
  935. // because we have already checked it in the sanityCheck().
  936. // Now that we have all information about the client, let's iterate over all
  937. // received options and handle IA_NA options one by one and store our
  938. // responses in answer message (ADVERTISE or REPLY).
  939. //
  940. // @todo: IA_TA once we implement support for temporary addresses.
  941. for (OptionCollection::iterator opt = question->options_.begin();
  942. opt != question->options_.end(); ++opt) {
  943. switch (opt->second->getType()) {
  944. case D6O_IA_NA: {
  945. OptionPtr answer_opt = assignIA_NA(question, answer, ctx,
  946. boost::dynamic_pointer_cast<
  947. Option6IA>(opt->second));
  948. if (answer_opt) {
  949. answer->addOption(answer_opt);
  950. }
  951. break;
  952. }
  953. case D6O_IA_PD: {
  954. OptionPtr answer_opt = assignIA_PD(question, answer, ctx,
  955. boost::dynamic_pointer_cast<
  956. Option6IA>(opt->second));
  957. if (answer_opt) {
  958. answer->addOption(answer_opt);
  959. }
  960. }
  961. default:
  962. break;
  963. }
  964. }
  965. }
  966. void
  967. Dhcpv6Srv::processClientFqdn(const Pkt6Ptr& question, const Pkt6Ptr& answer,
  968. AllocEngine::ClientContext6& ctx) {
  969. D2ClientMgr& d2_mgr = CfgMgr::instance().getD2ClientMgr();
  970. // Get Client FQDN Option from the client's message. If this option hasn't
  971. // been included, do nothing.
  972. Option6ClientFqdnPtr fqdn = boost::dynamic_pointer_cast<
  973. Option6ClientFqdn>(question->getOption(D6O_CLIENT_FQDN));
  974. if (!fqdn) {
  975. D2ClientConfig::ReplaceClientNameMode replace_name_mode =
  976. d2_mgr.getD2ClientConfig()->getReplaceClientNameMode();
  977. if (d2_mgr.ddnsEnabled() &&
  978. (replace_name_mode == D2ClientConfig::RCM_ALWAYS ||
  979. replace_name_mode == D2ClientConfig::RCM_WHEN_NOT_PRESENT)) {
  980. // Fabricate an empty "client" FQDN with flags requesting
  981. // the server do all the updates. The flags will get modified
  982. // below according the configuration options, the name will
  983. // be supplied later on.
  984. fqdn.reset(new Option6ClientFqdn(Option6ClientFqdn::FLAG_S, "",
  985. Option6ClientFqdn::PARTIAL));
  986. LOG_DEBUG(ddns6_logger, DBG_DHCP6_DETAIL, DHCP6_DDNS_GENERATE_FQDN)
  987. .arg(question->getLabel());
  988. } else {
  989. // No FQDN so get the lease hostname from the host reservation if
  990. // there is one.
  991. if (ctx.host_) {
  992. ctx.hostname_ = ctx.host_->getHostname();
  993. }
  994. return;
  995. }
  996. }
  997. LOG_DEBUG(ddns6_logger, DBG_DHCP6_DETAIL, DHCP6_DDNS_RECEIVE_FQDN)
  998. .arg(question->getLabel())
  999. .arg(fqdn->toText());
  1000. // Create the DHCPv6 Client FQDN Option to be included in the server's
  1001. // response to a client.
  1002. Option6ClientFqdnPtr fqdn_resp(new Option6ClientFqdn(*fqdn));
  1003. // Set the server S, N, and O flags based on client's flags and
  1004. // current configuration.
  1005. d2_mgr.adjustFqdnFlags<Option6ClientFqdn>(*fqdn, *fqdn_resp);
  1006. // If there's a reservation and it has a hostname specified, use it!
  1007. if (ctx.host_ && !ctx.host_->getHostname().empty()) {
  1008. // Add the qualifying suffix.
  1009. // After #3765, this will only occur if the suffix is not empty.
  1010. fqdn_resp->setDomainName(d2_mgr.qualifyName(ctx.host_->getHostname(),
  1011. true),
  1012. Option6ClientFqdn::FULL);
  1013. } else {
  1014. // Adjust the domain name based on domain name value and type sent by
  1015. // the client and current configuration.
  1016. d2_mgr.adjustDomainName<Option6ClientFqdn>(*fqdn, *fqdn_resp);
  1017. }
  1018. // Once we have the FQDN setup to use it for the lease hostname. This
  1019. // only gets replaced later if the FQDN is to be generated from the address.
  1020. ctx.hostname_ = fqdn_resp->getDomainName();
  1021. // The FQDN has been processed successfully. Let's append it to the
  1022. // response to be sent to a client. Note that the Client FQDN option is
  1023. // always sent back to the client if Client FQDN was included in the
  1024. // client's message.
  1025. LOG_DEBUG(ddns6_logger, DBG_DHCP6_DETAIL, DHCP6_DDNS_RESPONSE_FQDN_DATA)
  1026. .arg(question->getLabel())
  1027. .arg(fqdn_resp->toText());
  1028. answer->addOption(fqdn_resp);
  1029. }
  1030. void
  1031. Dhcpv6Srv::createNameChangeRequests(const Pkt6Ptr& answer,
  1032. AllocEngine::ClientContext6& ctx) {
  1033. // Don't create NameChangeRequests if DNS updates are disabled.
  1034. if (!CfgMgr::instance().ddnsEnabled()) {
  1035. return;
  1036. }
  1037. // The response message instance is always required. For instance it
  1038. // holds the Client Identifier. It is a programming error if supplied
  1039. // message is NULL.
  1040. if (!answer) {
  1041. isc_throw(isc::Unexpected, "an instance of the object"
  1042. << " encapsulating server's message must not be"
  1043. << " NULL when creating DNS NameChangeRequest");
  1044. }
  1045. // It is likely that client haven't included the FQDN option. In such case,
  1046. // FQDN option will be NULL. This is valid state, so we simply return.
  1047. Option6ClientFqdnPtr opt_fqdn = boost::dynamic_pointer_cast<
  1048. Option6ClientFqdn>(answer->getOption(D6O_CLIENT_FQDN));
  1049. if (!opt_fqdn) {
  1050. return;
  1051. }
  1052. // Get the update directions that should be performed based on our
  1053. // response FQDN flags.
  1054. bool do_fwd = false;
  1055. bool do_rev = false;
  1056. CfgMgr::instance().getD2ClientMgr().getUpdateDirections(*opt_fqdn,
  1057. do_fwd, do_rev);
  1058. if (!do_fwd && !do_rev) {
  1059. // Flags indicate there is Nothing to do, get out now.
  1060. // The Most likely scenario is that we are honoring the client's
  1061. // request that no updates be done.
  1062. return;
  1063. }
  1064. // Get the Client Id. It is mandatory and a function creating a response
  1065. // would have thrown an exception if it was missing. Thus throwing
  1066. // Unexpected if it is missing as it is a programming error.
  1067. OptionPtr opt_duid = answer->getOption(D6O_CLIENTID);
  1068. if (!opt_duid) {
  1069. isc_throw(isc::Unexpected,
  1070. "client identifier is required when creating a new"
  1071. " DNS NameChangeRequest");
  1072. }
  1073. DuidPtr duid = DuidPtr(new DUID(opt_duid->getData()));
  1074. // Get the FQDN in the on-wire format. It will be needed to compute
  1075. // DHCID.
  1076. OutputBuffer name_buf(1);
  1077. opt_fqdn->packDomainName(name_buf);
  1078. const uint8_t* name_data = static_cast<const uint8_t*>(name_buf.getData());
  1079. // @todo currently D2Dhcid accepts a vector holding FQDN.
  1080. // However, it will be faster if we used a pointer name_data.
  1081. std::vector<uint8_t> buf_vec(name_data, name_data + name_buf.getLength());
  1082. // Compute DHCID from Client Identifier and FQDN.
  1083. isc::dhcp_ddns::D2Dhcid dhcid(*duid, buf_vec);
  1084. // Get all IAs from the answer. For each IA, holding an address we will
  1085. // create a corresponding NameChangeRequest.
  1086. OptionCollection answer_ias = answer->getOptions(D6O_IA_NA);
  1087. for (OptionCollection::const_iterator answer_ia =
  1088. answer_ias.begin(); answer_ia != answer_ias.end(); ++answer_ia) {
  1089. /// @todo IA_NA may contain multiple addresses. We should process
  1090. /// each address individually. Currently we get only one.
  1091. Option6IAAddrPtr iaaddr = boost::static_pointer_cast<
  1092. Option6IAAddr>(answer_ia->second->getOption(D6O_IAADDR));
  1093. // We need an address to create a name-to-address mapping.
  1094. // If address is missing for any reason, go to the next IA.
  1095. if (!iaaddr) {
  1096. continue;
  1097. }
  1098. // If the lease for iaaddr is in the list of changed leases, we need
  1099. // to determine if the changes included changes to the FQDN. If there
  1100. // were changes to the FQDN then we need to update DNS, otherwise
  1101. // we do not.
  1102. bool extended_only = false;
  1103. for (Lease6Collection::const_iterator l = ctx.currentIA().changed_leases_.begin();
  1104. l != ctx.currentIA().changed_leases_.end(); ++l) {
  1105. if ((*l)->addr_ == iaaddr->getAddress()) {
  1106. if ((*l)->hostname_ == opt_fqdn->getDomainName() &&
  1107. (*l)->fqdn_fwd_ == do_fwd && (*l)->fqdn_rev_ == do_rev) {
  1108. extended_only = true;
  1109. break;
  1110. }
  1111. }
  1112. }
  1113. if (extended_only) {
  1114. continue;
  1115. }
  1116. // Create new NameChangeRequest. Use the domain name from the FQDN.
  1117. // This is an FQDN included in the response to the client, so it
  1118. // holds a fully qualified domain-name already (not partial).
  1119. // Get the IP address from the lease.
  1120. NameChangeRequestPtr ncr;
  1121. ncr.reset(new NameChangeRequest(isc::dhcp_ddns::CHG_ADD,
  1122. do_fwd, do_rev,
  1123. opt_fqdn->getDomainName(),
  1124. iaaddr->getAddress().toText(),
  1125. dhcid, 0, iaaddr->getValid()));
  1126. LOG_DEBUG(ddns6_logger, DBG_DHCP6_DETAIL,
  1127. DHCP6_DDNS_CREATE_ADD_NAME_CHANGE_REQUEST).arg(ncr->toText());
  1128. // Post the NCR to the D2ClientMgr.
  1129. CfgMgr::instance().getD2ClientMgr().sendRequest(ncr);
  1130. /// @todo Currently we create NCR with the first IPv6 address that
  1131. /// is carried in one of the IA_NAs. In the future, the NCR API should
  1132. /// be extended to map multiple IPv6 addresses to a single FQDN.
  1133. /// In such case, this return statement will be removed.
  1134. return;
  1135. }
  1136. }
  1137. HWAddrPtr
  1138. Dhcpv6Srv::getMAC(const Pkt6Ptr& pkt) {
  1139. CfgMACSources mac_sources = CfgMgr::instance().getCurrentCfg()->
  1140. getMACSources().get();
  1141. HWAddrPtr hwaddr;
  1142. for (CfgMACSources::const_iterator it = mac_sources.begin();
  1143. it != mac_sources.end(); ++it) {
  1144. hwaddr = pkt->getMAC(*it);
  1145. if (hwaddr) {
  1146. return (hwaddr);
  1147. }
  1148. }
  1149. return (hwaddr);
  1150. }
  1151. OptionPtr
  1152. Dhcpv6Srv::assignIA_NA(const Pkt6Ptr& query, const Pkt6Ptr& answer,
  1153. AllocEngine::ClientContext6& ctx,
  1154. boost::shared_ptr<Option6IA> ia) {
  1155. // Check if the client sent us a hint in his IA_NA. Clients may send an
  1156. // address in their IA_NA options as a suggestion (e.g. the last address
  1157. // they used before).
  1158. Option6IAAddrPtr hint_opt =
  1159. boost::dynamic_pointer_cast<Option6IAAddr>(ia->getOption(D6O_IAADDR));
  1160. IOAddress hint = IOAddress::IPV6_ZERO_ADDRESS();
  1161. if (hint_opt) {
  1162. hint = hint_opt->getAddress();
  1163. }
  1164. LOG_DEBUG(lease6_logger, DBG_DHCP6_DETAIL, DHCP6_PROCESS_IA_NA_REQUEST)
  1165. .arg(query->getLabel())
  1166. .arg(ia->getIAID())
  1167. .arg(hint_opt ? hint.toText() : "(no hint)");
  1168. // convenience values
  1169. const Subnet6Ptr& subnet = ctx.subnet_;
  1170. // If there is no subnet selected for handling this IA_NA, the only thing left to do is
  1171. // to say that we are sorry, but the user won't get an address. As a convenience, we
  1172. // use a different status text to indicate that (compare to the same status code,
  1173. // but different wording below)
  1174. if (!subnet) {
  1175. // Create an empty IA_NA option with IAID matching the request.
  1176. // Note that we don't use OptionDefinition class to create this option.
  1177. // This is because we prefer using a constructor of Option6IA that
  1178. // initializes IAID. Otherwise we would have to use setIAID() after
  1179. // creation of the option which has some performance implications.
  1180. boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
  1181. // Insert status code NoAddrsAvail.
  1182. ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoAddrsAvail,
  1183. "Server could not select subnet for"
  1184. " this client"));
  1185. return (ia_rsp);
  1186. }
  1187. // "Fake" allocation is the case when the server is processing the Solicit
  1188. // message without the Rapid Commit option and advertises a lease to
  1189. // the client, but doesn't commit this lease to the lease database. If
  1190. // the Solicit contains the Rapid Commit option and the server is
  1191. // configured to honor the Rapid Commit option, or the client has sent
  1192. // the Request message, the lease will be committed to the lease
  1193. // database. The type of the server's response may be used to determine
  1194. // if this is the fake allocation case or not. When the server sends
  1195. // Reply message it means that it is committing leases. Other message
  1196. // type (Advertise) means that server is not committing leases (fake
  1197. // allocation).
  1198. bool fake_allocation = (answer->getType() != DHCPV6_REPLY);
  1199. // Get DDNS update direction flags
  1200. bool do_fwd = false;
  1201. bool do_rev = false;
  1202. Option6ClientFqdnPtr fqdn = boost::dynamic_pointer_cast<
  1203. Option6ClientFqdn>(answer->getOption(D6O_CLIENT_FQDN));
  1204. if (fqdn) {
  1205. CfgMgr::instance().getD2ClientMgr().getUpdateDirections(*fqdn, do_fwd,
  1206. do_rev);
  1207. }
  1208. // Update per-packet context values.
  1209. ctx.fwd_dns_update_ = do_fwd;
  1210. ctx.rev_dns_update_ = do_rev;
  1211. ctx.fake_allocation_ = fake_allocation;
  1212. // Set per-IA context values.
  1213. ctx.createIAContext();
  1214. ctx.currentIA().iaid_ = ia->getIAID();
  1215. ctx.currentIA().addHint(hint);
  1216. ctx.currentIA().type_ = Lease::TYPE_NA;
  1217. // Use allocation engine to pick a lease for this client. Allocation engine
  1218. // will try to honor the hint, but it is just a hint - some other address
  1219. // may be used instead. If fake_allocation is set to false, the lease will
  1220. // be inserted into the LeaseMgr as well.
  1221. Lease6Collection leases = alloc_engine_->allocateLeases6(ctx);
  1222. /// @todo: Handle more than one lease
  1223. Lease6Ptr lease;
  1224. if (!leases.empty()) {
  1225. lease = *leases.begin();
  1226. }
  1227. // Create IA_NA that we will put in the response.
  1228. // Do not use OptionDefinition to create option's instance so
  1229. // as we can initialize IAID using a constructor.
  1230. Option6IAPtr ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
  1231. if (lease) {
  1232. // We have a lease! Let's wrap its content into IA_NA option
  1233. // with IAADDR suboption.
  1234. LOG_INFO(lease6_logger, fake_allocation ? DHCP6_LEASE_ADVERT : DHCP6_LEASE_ALLOC)
  1235. .arg(query->getLabel())
  1236. .arg(lease->addr_.toText())
  1237. .arg(ia->getIAID());
  1238. LOG_DEBUG(lease6_logger, DBG_DHCP6_DETAIL_DATA, DHCP6_LEASE_DATA)
  1239. .arg(query->getLabel())
  1240. .arg(ia->getIAID())
  1241. .arg(lease->toText());
  1242. ia_rsp->setT1(subnet->getT1());
  1243. ia_rsp->setT2(subnet->getT2());
  1244. Option6IAAddrPtr addr(new Option6IAAddr(D6O_IAADDR, lease->addr_,
  1245. lease->preferred_lft_,
  1246. lease->valid_lft_));
  1247. ia_rsp->addOption(addr);
  1248. // It would be possible to insert status code=0(success) as well,
  1249. // but this is considered waste of bandwidth as absence of status
  1250. // code is considered a success.
  1251. } else {
  1252. // Allocation engine did not allocate a lease. The engine logged
  1253. // cause of that failure. The only thing left is to insert
  1254. // status code to pass the sad news to the client.
  1255. LOG_DEBUG(lease6_logger, DBG_DHCP6_DETAIL, fake_allocation ?
  1256. DHCP6_LEASE_ADVERT_FAIL : DHCP6_LEASE_ALLOC_FAIL)
  1257. .arg(query->getLabel())
  1258. .arg(ia->getIAID());
  1259. ia_rsp->addOption(createStatusCode(*query, *ia_rsp,
  1260. STATUS_NoAddrsAvail,
  1261. "Sorry, no address could be"
  1262. " allocated."));
  1263. }
  1264. return (ia_rsp);
  1265. }
  1266. OptionPtr
  1267. Dhcpv6Srv::assignIA_PD(const Pkt6Ptr& query, const Pkt6Ptr& answer,
  1268. AllocEngine::ClientContext6& ctx,
  1269. boost::shared_ptr<Option6IA> ia) {
  1270. // Check if the client sent us a hint in his IA_PD. Clients may send an
  1271. // address in their IA_PD options as a suggestion (e.g. the last address
  1272. // they used before). While the hint consists of a full prefix (prefix +
  1273. // length), getting just the prefix is sufficient to identify a lease.
  1274. Option6IAPrefixPtr hint_opt =
  1275. boost::dynamic_pointer_cast<Option6IAPrefix>(ia->getOption(D6O_IAPREFIX));
  1276. IOAddress hint = IOAddress::IPV6_ZERO_ADDRESS();
  1277. if (hint_opt) {
  1278. hint = hint_opt->getAddress();
  1279. }
  1280. LOG_DEBUG(lease6_logger, DBG_DHCP6_DETAIL, DHCP6_PROCESS_IA_PD_REQUEST)
  1281. .arg(query->getLabel())
  1282. .arg(ia->getIAID())
  1283. .arg(hint_opt ? hint.toText() : "(no hint)");
  1284. const Subnet6Ptr& subnet = ctx.subnet_;
  1285. // Create IA_PD that we will put in the response.
  1286. // Do not use OptionDefinition to create option's instance so
  1287. // as we can initialize IAID using a constructor.
  1288. boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_PD, ia->getIAID()));
  1289. // If there is no subnet selected for handling this IA_PD, the only thing
  1290. // left to do is to say that we are sorry, but the user won't get an address.
  1291. // As a convenience, we use a different status text to indicate that
  1292. // (compare to the same status code, but different wording below)
  1293. if (!subnet) {
  1294. // Insert status code NoAddrsAvail.
  1295. ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoPrefixAvail,
  1296. "Sorry, no subnet available."));
  1297. return (ia_rsp);
  1298. }
  1299. // "Fake" allocation is the case when the server is processing the Solicit
  1300. // message without the Rapid Commit option and advertises a lease to
  1301. // the client, but doesn't commit this lease to the lease database. If
  1302. // the Solicit contains the Rapid Commit option and the server is
  1303. // configured to honor the Rapid Commit option, or the client has sent
  1304. // the Request message, the lease will be committed to the lease
  1305. // database. The type of the server's response may be used to determine
  1306. // if this is the fake allocation case or not. When the server sends
  1307. // Reply message it means that it is committing leases. Other message
  1308. // type (Advertise) means that server is not committing leases (fake
  1309. // allocation).
  1310. ctx.fake_allocation_ = (answer->getType() != DHCPV6_REPLY);
  1311. // Set per-IA context values.
  1312. ctx.createIAContext();
  1313. ctx.currentIA().iaid_ = ia->getIAID();
  1314. ctx.currentIA().addHint(hint);
  1315. ctx.currentIA().type_ = Lease::TYPE_PD;
  1316. // Use allocation engine to pick a lease for this client. Allocation engine
  1317. // will try to honor the hint, but it is just a hint - some other address
  1318. // may be used instead. If fake_allocation is set to false, the lease will
  1319. // be inserted into the LeaseMgr as well.
  1320. Lease6Collection leases = alloc_engine_->allocateLeases6(ctx);
  1321. if (!leases.empty()) {
  1322. ia_rsp->setT1(subnet->getT1());
  1323. ia_rsp->setT2(subnet->getT2());
  1324. for (Lease6Collection::iterator l = leases.begin();
  1325. l != leases.end(); ++l) {
  1326. // We have a lease! Let's wrap its content into IA_PD option
  1327. // with IAADDR suboption.
  1328. LOG_INFO(lease6_logger, ctx.fake_allocation_ ?
  1329. DHCP6_PD_LEASE_ADVERT : DHCP6_PD_LEASE_ALLOC)
  1330. .arg(query->getLabel())
  1331. .arg((*l)->addr_.toText())
  1332. .arg(static_cast<int>((*l)->prefixlen_))
  1333. .arg(ia->getIAID());
  1334. boost::shared_ptr<Option6IAPrefix>
  1335. addr(new Option6IAPrefix(D6O_IAPREFIX, (*l)->addr_,
  1336. (*l)->prefixlen_, (*l)->preferred_lft_,
  1337. (*l)->valid_lft_));
  1338. ia_rsp->addOption(addr);
  1339. }
  1340. // It would be possible to insert status code=0(success) as well,
  1341. // but this is considered waste of bandwidth as absence of status
  1342. // code is considered a success.
  1343. } else {
  1344. // Allocation engine did not allocate a lease. The engine logged
  1345. // cause of that failure. The only thing left is to insert
  1346. // status code to pass the sad news to the client.
  1347. LOG_DEBUG(lease6_logger, DBG_DHCP6_DETAIL, ctx.fake_allocation_ ?
  1348. DHCP6_PD_LEASE_ADVERT_FAIL : DHCP6_PD_LEASE_ALLOC_FAIL)
  1349. .arg(query->getLabel())
  1350. .arg(ia->getIAID());
  1351. ia_rsp->addOption(createStatusCode(*query, *ia_rsp,
  1352. STATUS_NoPrefixAvail,
  1353. "Sorry, no prefixes could"
  1354. " be allocated."));
  1355. }
  1356. return (ia_rsp);
  1357. }
  1358. OptionPtr
  1359. Dhcpv6Srv::extendIA_NA(const Pkt6Ptr& query, const Pkt6Ptr& answer,
  1360. AllocEngine::ClientContext6& ctx,
  1361. boost::shared_ptr<Option6IA> ia) {
  1362. LOG_DEBUG(lease6_logger, DBG_DHCP6_DETAIL, DHCP6_PROCESS_IA_NA_EXTEND)
  1363. .arg(query->getLabel())
  1364. .arg(ia->getIAID());
  1365. // convenience values
  1366. const Subnet6Ptr& subnet = ctx.subnet_;
  1367. // Create empty IA_NA option with IAID matching the request.
  1368. Option6IAPtr ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
  1369. if (!subnet) {
  1370. /// @todo For simplicity and due to limitations of LeaseMgr we don't
  1371. /// get the binding for the client for which we don't get subnet id.
  1372. /// Subnet id is a required value when searching for the bindings.
  1373. /// The fact that we can't identify the subnet for the returning client
  1374. /// doesn't really mean that the client has no binding. It is possible
  1375. /// that due to server's reconfiguration the subnet has been removed
  1376. /// or modified since the client has got his lease. We may need to
  1377. /// rethink whether it is appropriate to send no binding if the subnet
  1378. /// hasn't been found for the client.
  1379. ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
  1380. "Sorry, no known leases for this duid/iaid."));
  1381. return (ia_rsp);
  1382. }
  1383. // Set up T1, T2 timers
  1384. ia_rsp->setT1(subnet->getT1());
  1385. ia_rsp->setT2(subnet->getT2());
  1386. // Get DDNS udpate directions
  1387. bool do_fwd = false;
  1388. bool do_rev = false;
  1389. Option6ClientFqdnPtr fqdn = boost::dynamic_pointer_cast<
  1390. Option6ClientFqdn>(answer->getOption(D6O_CLIENT_FQDN));
  1391. if (fqdn) {
  1392. CfgMgr::instance().getD2ClientMgr().getUpdateDirections(*fqdn,
  1393. do_fwd, do_rev);
  1394. }
  1395. // Set per-packet context values.
  1396. ctx.fwd_dns_update_ = do_fwd;
  1397. ctx.rev_dns_update_ = do_rev;
  1398. // Set per-IA context values.
  1399. ctx.createIAContext();
  1400. ctx.currentIA().iaid_ = ia->getIAID();
  1401. ctx.currentIA().type_ = Lease::TYPE_NA;
  1402. ctx.currentIA().ia_rsp_ = ia_rsp;
  1403. // Extract the addresses that the client is trying to obtain.
  1404. OptionCollection addrs = ia->getOptions();
  1405. for (OptionCollection::const_iterator it = addrs.begin();
  1406. it != addrs.end(); ++it) {
  1407. if (it->second->getType() != D6O_IAADDR) {
  1408. continue;
  1409. }
  1410. Option6IAAddrPtr iaaddr = boost::dynamic_pointer_cast<Option6IAAddr>(it->second);
  1411. if (!iaaddr) {
  1412. // That's weird. Option code was ok, but the object type was not.
  1413. // This should never happen. The only case would be with badly
  1414. // mis-implemented hook libraries that insert invalid option objects.
  1415. // There's no way to protect against this.
  1416. continue;
  1417. }
  1418. ctx.currentIA().addHint(iaaddr->getAddress());
  1419. }
  1420. Lease6Collection leases = alloc_engine_->renewLeases6(ctx);
  1421. // Ok, now we have the leases extended. We have:
  1422. // - what the client tried to renew in ctx.hints_
  1423. // - what we actually assigned in leases
  1424. // - old leases that are no longer valid in ctx.old_leases_
  1425. // For each IA inserted by the client we have to determine what to do
  1426. // about included addresses and notify the client. We will iterate over
  1427. // those prefixes and remove those that we have already processed. We
  1428. // don't want to remove them from the context, so we need to copy them
  1429. // into temporary container.
  1430. AllocEngine::HintContainer hints = ctx.currentIA().hints_;
  1431. // For all leases we have now, add the IAADDR with non-zero lifetimes.
  1432. for (Lease6Collection::const_iterator l = leases.begin(); l != leases.end(); ++l) {
  1433. Option6IAAddrPtr iaaddr(new Option6IAAddr(D6O_IAADDR,
  1434. (*l)->addr_, (*l)->preferred_lft_, (*l)->valid_lft_));
  1435. ia_rsp->addOption(iaaddr);
  1436. LOG_INFO(lease6_logger, DHCP6_LEASE_RENEW)
  1437. .arg(query->getLabel())
  1438. .arg((*l)->addr_.toText())
  1439. .arg(ia_rsp->getIAID());
  1440. // Now remove this address from the hints list.
  1441. AllocEngine::ResourceType hint_type((*l)->addr_, 128);
  1442. hints.erase(std::remove(hints.begin(), hints.end(), hint_type),
  1443. hints.end());
  1444. }
  1445. // For the leases that we just retired, send the addresses with 0 lifetimes.
  1446. for (Lease6Collection::const_iterator l = ctx.currentIA().old_leases_.begin();
  1447. l != ctx.currentIA().old_leases_.end(); ++l) {
  1448. Option6IAAddrPtr iaaddr(new Option6IAAddr(D6O_IAADDR,
  1449. (*l)->addr_, 0, 0));
  1450. ia_rsp->addOption(iaaddr);
  1451. // Now remove this address from the hints list.
  1452. AllocEngine::ResourceType hint_type((*l)->addr_, 128);
  1453. hints.erase(std::remove(hints.begin(), hints.end(), hint_type), hints.end());
  1454. // If the new FQDN settings have changed for the lease, we need to
  1455. // delete any existing FQDN records for this lease.
  1456. if (((*l)->hostname_ != ctx.hostname_) || ((*l)->fqdn_fwd_ != do_fwd) ||
  1457. ((*l)->fqdn_rev_ != do_rev)) {
  1458. LOG_DEBUG(ddns6_logger, DBG_DHCP6_DETAIL,
  1459. DHCP6_DDNS_LEASE_RENEW_FQDN_CHANGE)
  1460. .arg(query->getLabel())
  1461. .arg((*l)->toText())
  1462. .arg(ctx.hostname_)
  1463. .arg(do_rev ? "true" : "false")
  1464. .arg(do_fwd ? "true" : "false");
  1465. queueNCR(CHG_REMOVE, *l);
  1466. }
  1467. }
  1468. // Finally, if there are any addresses requested that we haven't dealt with
  1469. // already, inform the client that he can't have them.
  1470. for (AllocEngine::HintContainer::const_iterator hint = hints.begin();
  1471. hint != hints.end(); ++hint) {
  1472. Option6IAAddrPtr iaaddr(new Option6IAAddr(D6O_IAADDR,
  1473. hint->first, 0, 0));
  1474. ia_rsp->addOption(iaaddr);
  1475. }
  1476. // All is left is to insert the status code.
  1477. if (leases.empty()) {
  1478. // The server wasn't able allocate new lease and renew an exising
  1479. // lease. In that case, the server sends NoAddrsAvail per RFC7550.
  1480. ia_rsp->addOption(createStatusCode(*query, *ia_rsp,
  1481. STATUS_NoAddrsAvail,
  1482. "Sorry, no addresses could be"
  1483. " assigned at this time."));
  1484. }
  1485. return (ia_rsp);
  1486. }
  1487. OptionPtr
  1488. Dhcpv6Srv::extendIA_PD(const Pkt6Ptr& query,
  1489. AllocEngine::ClientContext6& ctx,
  1490. boost::shared_ptr<Option6IA> ia) {
  1491. LOG_DEBUG(lease6_logger, DBG_DHCP6_DETAIL, DHCP6_PROCESS_IA_PD_EXTEND)
  1492. .arg(query->getLabel())
  1493. .arg(ia->getIAID());
  1494. const Subnet6Ptr& subnet = ctx.subnet_;
  1495. const DuidPtr& duid = ctx.duid_;
  1496. // Let's create a IA_PD response and fill it in later
  1497. Option6IAPtr ia_rsp(new Option6IA(D6O_IA_PD, ia->getIAID()));
  1498. // If there is no subnet for the particular client, we can't retrieve
  1499. // information about client's leases from lease database. We treat this
  1500. // as no binding for the client.
  1501. if (!subnet) {
  1502. // Per RFC3633, section 12.2, if there is no binding and we are
  1503. // processing a Renew, the NoBinding status code should be returned.
  1504. if (query->getType() == DHCPV6_RENEW) {
  1505. // Insert status code NoBinding
  1506. ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
  1507. "Sorry, no known PD leases"
  1508. " for this duid/iaid."));
  1509. return (ia_rsp);
  1510. // Per RFC3633, section 12.2, if there is no binding and we are
  1511. // processing Rebind, the message has to be discarded (assuming that
  1512. // the server doesn't know if the prefix in the IA_PD option is
  1513. // appropriate for the client's link). The exception being thrown
  1514. // here should propagate to the main loop and cause the message to
  1515. // be discarded.
  1516. } else {
  1517. /// @todo: RFC3315bis will probably change that behavior. Client
  1518. /// may rebind prefixes and addresses at the same time.
  1519. isc_throw(DHCPv6DiscardMessageError, "no subnet found for the"
  1520. " client sending Rebind to extend lifetime of the"
  1521. " prefix (DUID=" << duid->toText() << ", IAID="
  1522. << ia->getIAID() << ")");
  1523. }
  1524. }
  1525. // Set up T1, T2 timers
  1526. ia_rsp->setT1(subnet->getT1());
  1527. ia_rsp->setT2(subnet->getT2());
  1528. // Set per-IA context values.
  1529. ctx.createIAContext();
  1530. ctx.currentIA().iaid_ = ia->getIAID();
  1531. ctx.currentIA().type_ = Lease::TYPE_PD;
  1532. ctx.currentIA().ia_rsp_ = ia_rsp;
  1533. // Extract prefixes that the client is trying to renew.
  1534. OptionCollection addrs = ia->getOptions();
  1535. for (OptionCollection::const_iterator it = addrs.begin();
  1536. it != addrs.end(); ++it) {
  1537. if (it->second->getType() != D6O_IAPREFIX) {
  1538. continue;
  1539. }
  1540. Option6IAPrefixPtr prf = boost::dynamic_pointer_cast<Option6IAPrefix>(it->second);
  1541. if (!prf) {
  1542. // That's weird. Option code was ok, but the object type was not.
  1543. // This should never happen. The only case would be with badly
  1544. // mis-implemented hook libraries that insert invalid option objects.
  1545. // There's no way to protect against this.
  1546. continue;
  1547. }
  1548. // Put the client's prefix into the hints list.
  1549. ctx.currentIA().addHint(prf->getAddress(), prf->getLength());
  1550. }
  1551. // Call Allocation Engine and attempt to renew leases. Number of things
  1552. // may happen. Leases may be extended, revoked (if the lease is no longer
  1553. // valid or reserved for someone else), or new leases may be added.
  1554. // Important parameters are:
  1555. // - returned container - current valid leases
  1556. // - old_leases - leases that used to be, but are no longer valid
  1557. // - changed_leases - leases that have FQDN changed (not really important
  1558. // in PD context)
  1559. Lease6Collection leases = alloc_engine_->renewLeases6(ctx);
  1560. // For each IA inserted by the client we have to determine what to do
  1561. // about included prefixes and notify the client. We will iterate over
  1562. // those prefixes and remove those that we have already processed. We
  1563. // don't want to remove them from the context, so we need to copy them
  1564. // into temporary container.
  1565. AllocEngine::HintContainer hints = ctx.currentIA().hints_;
  1566. // For all the leases we have now, add the IAPPREFIX with non-zero lifetimes
  1567. for (Lease6Collection::const_iterator l = leases.begin(); l != leases.end(); ++l) {
  1568. Option6IAPrefixPtr prf(new Option6IAPrefix(D6O_IAPREFIX,
  1569. (*l)->addr_, (*l)->prefixlen_,
  1570. (*l)->preferred_lft_, (*l)->valid_lft_));
  1571. ia_rsp->addOption(prf);
  1572. LOG_INFO(lease6_logger, DHCP6_PD_LEASE_RENEW)
  1573. .arg(query->getLabel())
  1574. .arg((*l)->addr_.toText())
  1575. .arg(static_cast<int>((*l)->prefixlen_))
  1576. .arg(ia->getIAID());
  1577. // Now remove this address from the hints list.
  1578. AllocEngine::ResourceType hint_type((*l)->addr_, (*l)->prefixlen_);
  1579. hints.erase(std::remove(hints.begin(), hints.end(), hint_type),
  1580. hints.end());
  1581. }
  1582. /// @todo: Maybe we should iterate over ctx.old_leases_, i.e. the leases
  1583. /// that used to be valid, but they are not anymore.
  1584. // For all the leases the client had requested, but we didn't assign, put them with
  1585. // zero lifetimes
  1586. // Finally, if there are any addresses requested that we haven't dealt with
  1587. // already, inform the client that he can't have them.
  1588. for (AllocEngine::HintContainer::const_iterator prefix = hints.begin();
  1589. prefix != hints.end(); ++prefix) {
  1590. // Send the prefix with the zero lifetimes only if the prefix
  1591. // contains non-zero value. A zero value indicates that the hint was
  1592. // for the prefix length.
  1593. if (!prefix->first.isV6Zero()) {
  1594. OptionPtr prefix_opt(new Option6IAPrefix(D6O_IAPREFIX, prefix->first,
  1595. prefix->second, 0, 0));
  1596. ia_rsp->addOption(prefix_opt);
  1597. }
  1598. }
  1599. // All is left is to insert the status code.
  1600. if (leases.empty()) {
  1601. // The server wasn't able allocate new lease and renew an exising
  1602. // lease. In that case, the server sends NoPrefixAvail per RFC7550.
  1603. ia_rsp->addOption(createStatusCode(*query, *ia_rsp,
  1604. STATUS_NoPrefixAvail,
  1605. "Sorry, no prefixes could be"
  1606. " assigned at this time."));
  1607. }
  1608. return (ia_rsp);
  1609. }
  1610. void
  1611. Dhcpv6Srv::extendLeases(const Pkt6Ptr& query, Pkt6Ptr& reply,
  1612. AllocEngine::ClientContext6& ctx) {
  1613. // We will try to extend lease lifetime for all IA options in the client's
  1614. // Renew or Rebind message.
  1615. /// @todo add support for IA_TA
  1616. // For the lease extension it is critical that the client has sent
  1617. // DUID. There is no need to check for the presence of the DUID here
  1618. // because we have already checked it in the sanityCheck().
  1619. for (OptionCollection::iterator opt = query->options_.begin();
  1620. opt != query->options_.end(); ++opt) {
  1621. switch (opt->second->getType()) {
  1622. case D6O_IA_NA: {
  1623. OptionPtr answer_opt = extendIA_NA(query, reply, ctx,
  1624. boost::dynamic_pointer_cast<
  1625. Option6IA>(opt->second));
  1626. if (answer_opt) {
  1627. reply->addOption(answer_opt);
  1628. }
  1629. break;
  1630. }
  1631. case D6O_IA_PD: {
  1632. OptionPtr answer_opt = extendIA_PD(query, ctx,
  1633. boost::dynamic_pointer_cast<
  1634. Option6IA>(opt->second));
  1635. if (answer_opt) {
  1636. reply->addOption(answer_opt);
  1637. }
  1638. break;
  1639. }
  1640. default:
  1641. break;
  1642. }
  1643. }
  1644. }
  1645. void
  1646. Dhcpv6Srv::releaseLeases(const Pkt6Ptr& release, Pkt6Ptr& reply,
  1647. AllocEngine::ClientContext6& ctx) {
  1648. // We need to release addresses for all IA_NA options in the client's
  1649. // RELEASE message.
  1650. // @todo Add support for IA_TA
  1651. // @todo Add support for IA_PD
  1652. // @todo Consider supporting more than one address in a single IA_NA.
  1653. // That was envisaged by RFC3315, but it never happened. The only
  1654. // software that supports that is Dibbler, but its author seriously doubts
  1655. // if anyone is really using it. Clients that want more than one address
  1656. // just include more instances of IA_NA options.
  1657. // Let's set the status to be success by default. We can override it with
  1658. // error status if needed. The important thing to understand here is that
  1659. // the global status code may be set to success only if all IA options were
  1660. // handled properly. Therefore the releaseIA_NA and releaseIA_PD options
  1661. // may turn the status code to some error, but can't turn it back to success.
  1662. int general_status = STATUS_Success;
  1663. for (OptionCollection::iterator opt = release->options_.begin();
  1664. opt != release->options_.end(); ++opt) {
  1665. switch (opt->second->getType()) {
  1666. case D6O_IA_NA: {
  1667. OptionPtr answer_opt = releaseIA_NA(ctx.duid_, release, general_status,
  1668. boost::dynamic_pointer_cast<Option6IA>(opt->second));
  1669. if (answer_opt) {
  1670. reply->addOption(answer_opt);
  1671. }
  1672. break;
  1673. }
  1674. case D6O_IA_PD: {
  1675. OptionPtr answer_opt = releaseIA_PD(ctx.duid_, release, general_status,
  1676. boost::dynamic_pointer_cast<Option6IA>(opt->second));
  1677. if (answer_opt) {
  1678. reply->addOption(answer_opt);
  1679. }
  1680. break;
  1681. }
  1682. // @todo: add support for IA_TA
  1683. default:
  1684. // remaining options are stateless and thus ignored in this context
  1685. ;
  1686. }
  1687. }
  1688. // To be pedantic, we should also include status code in the top-level
  1689. // scope, not just in each IA_NA. See RFC3315, section 18.2.6.
  1690. // This behavior will likely go away in RFC3315bis.
  1691. reply->addOption(createStatusCode(*release, general_status,
  1692. "Summary status for all processed IA_NAs"));
  1693. }
  1694. OptionPtr
  1695. Dhcpv6Srv::releaseIA_NA(const DuidPtr& duid, const Pkt6Ptr& query,
  1696. int& general_status, boost::shared_ptr<Option6IA> ia) {
  1697. LOG_DEBUG(lease6_logger, DBG_DHCP6_DETAIL, DHCP6_PROCESS_IA_NA_RELEASE)
  1698. .arg(query->getLabel())
  1699. .arg(ia->getIAID());
  1700. // Release can be done in one of two ways:
  1701. // Approach 1: extract address from client's IA_NA and see if it belongs
  1702. // to this particular client.
  1703. // Approach 2: find a subnet for this client, get a lease for
  1704. // this subnet/duid/iaid and check if its content matches to what the
  1705. // client is asking us to release.
  1706. //
  1707. // This method implements approach 1.
  1708. // That's our response
  1709. boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
  1710. Option6IAAddrPtr release_addr = boost::dynamic_pointer_cast<Option6IAAddr>
  1711. (ia->getOption(D6O_IAADDR));
  1712. if (!release_addr) {
  1713. ia_rsp->addOption(createStatusCode(*query, STATUS_NoBinding,
  1714. "You did not include an address in your RELEASE"));
  1715. general_status = STATUS_NoBinding;
  1716. return (ia_rsp);
  1717. }
  1718. Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
  1719. release_addr->getAddress());
  1720. if (!lease) {
  1721. // client releasing a lease that we don't know about.
  1722. // Insert status code NoBinding.
  1723. ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
  1724. "Sorry, no known leases for this duid/iaid, can't release."));
  1725. general_status = STATUS_NoBinding;
  1726. return (ia_rsp);
  1727. }
  1728. if (!lease->duid_) {
  1729. // Something is gravely wrong here. We do have a lease, but it does not
  1730. // have mandatory DUID information attached. Someone was messing with our
  1731. // database.
  1732. LOG_ERROR(lease6_logger, DHCP6_LEASE_NA_WITHOUT_DUID)
  1733. .arg(query->getLabel())
  1734. .arg(release_addr->getAddress().toText());
  1735. general_status = STATUS_UnspecFail;
  1736. ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_UnspecFail,
  1737. "Database consistency check failed when trying to RELEASE"));
  1738. return (ia_rsp);
  1739. }
  1740. if (*duid != *(lease->duid_)) {
  1741. // Sorry, it's not your address. You can't release it.
  1742. LOG_INFO(lease6_logger, DHCP6_RELEASE_NA_FAIL_WRONG_DUID)
  1743. .arg(query->getLabel())
  1744. .arg(release_addr->getAddress().toText())
  1745. .arg(lease->duid_->toText());
  1746. general_status = STATUS_NoBinding;
  1747. ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
  1748. "This address does not belong to you, you can't release it"));
  1749. return (ia_rsp);
  1750. }
  1751. if (ia->getIAID() != lease->iaid_) {
  1752. // This address belongs to this client, but to a different IA
  1753. LOG_WARN(lease6_logger, DHCP6_RELEASE_NA_FAIL_WRONG_IAID)
  1754. .arg(query->getLabel())
  1755. .arg(release_addr->getAddress().toText())
  1756. .arg(lease->iaid_)
  1757. .arg(ia->getIAID());
  1758. ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
  1759. "This is your address, but you used wrong IAID"));
  1760. general_status = STATUS_NoBinding;
  1761. return (ia_rsp);
  1762. }
  1763. // It is not necessary to check if the address matches as we used
  1764. // getLease6(addr) method that is supposed to return a proper lease.
  1765. bool skip = false;
  1766. // Execute all callouts registered for packet6_send
  1767. if (HooksManager::calloutsPresent(Hooks.hook_index_lease6_release_)) {
  1768. CalloutHandlePtr callout_handle = getCalloutHandle(query);
  1769. // Enable copying options from the packet within hook library.
  1770. ScopedEnableOptionsCopy<Pkt6> query6_options_copy(query);
  1771. // Delete all previous arguments
  1772. callout_handle->deleteAllArguments();
  1773. // Pass the original packet
  1774. callout_handle->setArgument("query6", query);
  1775. // Pass the lease to be updated
  1776. callout_handle->setArgument("lease6", lease);
  1777. // Call all installed callouts
  1778. HooksManager::callCallouts(Hooks.hook_index_lease6_release_, *callout_handle);
  1779. // Callouts decided to skip the next processing step. The next
  1780. // processing step would to send the packet, so skip at this
  1781. // stage means "drop response".
  1782. if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) {
  1783. skip = true;
  1784. LOG_DEBUG(hooks_logger, DBG_DHCP6_HOOKS, DHCP6_HOOK_LEASE6_RELEASE_NA_SKIP)
  1785. .arg(query->getLabel());
  1786. }
  1787. /// @todo: Add support for DROP status
  1788. }
  1789. // Ok, we've passed all checks. Let's release this address.
  1790. bool success = false; // was the removal operation successful?
  1791. if (!skip) {
  1792. success = LeaseMgrFactory::instance().deleteLease(lease->addr_);
  1793. }
  1794. // Here the success should be true if we removed lease successfully
  1795. // and false if skip flag was set or the removal failed for whatever reason
  1796. if (!success) {
  1797. ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_UnspecFail,
  1798. "Server failed to release a lease"));
  1799. LOG_ERROR(lease6_logger, DHCP6_RELEASE_NA_FAIL)
  1800. .arg(query->getLabel())
  1801. .arg(lease->addr_.toText())
  1802. .arg(lease->iaid_);
  1803. general_status = STATUS_UnspecFail;
  1804. return (ia_rsp);
  1805. } else {
  1806. LOG_INFO(lease6_logger, DHCP6_RELEASE_NA)
  1807. .arg(query->getLabel())
  1808. .arg(lease->addr_.toText())
  1809. .arg(lease->iaid_);
  1810. ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_Success,
  1811. "Lease released. Thank you, please come again."));
  1812. // Need to decrease statistic for assigned addresses.
  1813. StatsMgr::instance().addValue(
  1814. StatsMgr::generateName("subnet", lease->subnet_id_, "assigned-nas"),
  1815. static_cast<int64_t>(-1));
  1816. // Check if a lease has flags indicating that the FQDN update has
  1817. // been performed. If so, create NameChangeRequest which removes
  1818. // the entries.
  1819. queueNCR(CHG_REMOVE, lease);
  1820. return (ia_rsp);
  1821. }
  1822. }
  1823. OptionPtr
  1824. Dhcpv6Srv::releaseIA_PD(const DuidPtr& duid, const Pkt6Ptr& query,
  1825. int& general_status, boost::shared_ptr<Option6IA> ia) {
  1826. // Release can be done in one of two ways:
  1827. // Approach 1: extract address from client's IA_NA and see if it belongs
  1828. // to this particular client.
  1829. // Approach 2: find a subnet for this client, get a lease for
  1830. // this subnet/duid/iaid and check if its content matches to what the
  1831. // client is asking us to release.
  1832. //
  1833. // This method implements approach 1.
  1834. // That's our response. We will fill it in as we check the lease to be
  1835. // released.
  1836. boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_PD, ia->getIAID()));
  1837. boost::shared_ptr<Option6IAPrefix> release_prefix =
  1838. boost::dynamic_pointer_cast<Option6IAPrefix>(ia->getOption(D6O_IAPREFIX));
  1839. if (!release_prefix) {
  1840. ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
  1841. "You did not include a prefix in your RELEASE"));
  1842. general_status = STATUS_NoBinding;
  1843. return (ia_rsp);
  1844. }
  1845. Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_PD,
  1846. release_prefix->getAddress());
  1847. if (!lease) {
  1848. // Client releasing a lease that we don't know about.
  1849. // Insert status code NoBinding.
  1850. ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
  1851. "Sorry, no known leases for this duid/iaid, can't release."));
  1852. general_status = STATUS_NoBinding;
  1853. return (ia_rsp);
  1854. }
  1855. if (!lease->duid_) {
  1856. // Something is gravely wrong here. We do have a lease, but it does not
  1857. // have mandatory DUID information attached. Someone was messing with our
  1858. // database.
  1859. LOG_ERROR(lease6_logger, DHCP6_LEASE_PD_WITHOUT_DUID)
  1860. .arg(query->getLabel())
  1861. .arg(release_prefix->getAddress().toText())
  1862. .arg(static_cast<int>(release_prefix->getLength()));
  1863. general_status = STATUS_UnspecFail;
  1864. ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_UnspecFail,
  1865. "Database consistency check failed when trying to RELEASE"));
  1866. return (ia_rsp);
  1867. }
  1868. if (*duid != *(lease->duid_)) {
  1869. // Sorry, it's not your address. You can't release it.
  1870. LOG_INFO(lease6_logger, DHCP6_RELEASE_PD_FAIL_WRONG_DUID)
  1871. .arg(query->getLabel())
  1872. .arg(release_prefix->getAddress().toText())
  1873. .arg(static_cast<int>(release_prefix->getLength()))
  1874. .arg(lease->duid_->toText());
  1875. general_status = STATUS_NoBinding;
  1876. ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
  1877. "This address does not belong to you, you can't release it"));
  1878. return (ia_rsp);
  1879. }
  1880. if (ia->getIAID() != lease->iaid_) {
  1881. // This address belongs to this client, but to a different IA
  1882. LOG_WARN(lease6_logger, DHCP6_RELEASE_PD_FAIL_WRONG_IAID)
  1883. .arg(query->getLabel())
  1884. .arg(release_prefix->getAddress().toText())
  1885. .arg(static_cast<int>(release_prefix->getLength()))
  1886. .arg(lease->iaid_)
  1887. .arg(ia->getIAID());
  1888. ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_NoBinding,
  1889. "This is your address, but you used wrong IAID"));
  1890. general_status = STATUS_NoBinding;
  1891. return (ia_rsp);
  1892. }
  1893. // It is not necessary to check if the address matches as we used
  1894. // getLease6(addr) method that is supposed to return a proper lease.
  1895. bool skip = false;
  1896. // Execute all callouts registered for packet6_send
  1897. if (HooksManager::calloutsPresent(Hooks.hook_index_lease6_release_)) {
  1898. CalloutHandlePtr callout_handle = getCalloutHandle(query);
  1899. // Delete all previous arguments
  1900. callout_handle->deleteAllArguments();
  1901. // Enable copying options from the packet within hook library.
  1902. ScopedEnableOptionsCopy<Pkt6> query6_options_copy(query);
  1903. // Pass the original packet
  1904. callout_handle->setArgument("query6", query);
  1905. // Pass the lease to be updated
  1906. callout_handle->setArgument("lease6", lease);
  1907. // Call all installed callouts
  1908. HooksManager::callCallouts(Hooks.hook_index_lease6_release_, *callout_handle);
  1909. skip = callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP;
  1910. }
  1911. // Ok, we've passed all checks. Let's release this prefix.
  1912. bool success = false; // was the removal operation successful?
  1913. if (!skip) {
  1914. success = LeaseMgrFactory::instance().deleteLease(lease->addr_);
  1915. } else {
  1916. // Callouts decided to skip the next processing step. The next
  1917. // processing step would to send the packet, so skip at this
  1918. // stage means "drop response".
  1919. LOG_DEBUG(hooks_logger, DBG_DHCP6_HOOKS, DHCP6_HOOK_LEASE6_RELEASE_PD_SKIP)
  1920. .arg(query->getLabel());
  1921. }
  1922. // Here the success should be true if we removed lease successfully
  1923. // and false if skip flag was set or the removal failed for whatever reason
  1924. if (!success) {
  1925. ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_UnspecFail,
  1926. "Server failed to release a lease"));
  1927. LOG_ERROR(lease6_logger, DHCP6_RELEASE_PD_FAIL)
  1928. .arg(query->getLabel())
  1929. .arg(lease->addr_.toText())
  1930. .arg(static_cast<int>(lease->prefixlen_))
  1931. .arg(lease->iaid_);
  1932. general_status = STATUS_UnspecFail;
  1933. } else {
  1934. LOG_INFO(lease6_logger, DHCP6_RELEASE_PD)
  1935. .arg(query->getLabel())
  1936. .arg(lease->addr_.toText())
  1937. .arg(static_cast<int>(lease->prefixlen_))
  1938. .arg(lease->iaid_);
  1939. ia_rsp->addOption(createStatusCode(*query, *ia_rsp, STATUS_Success,
  1940. "Lease released. Thank you, please come again."));
  1941. // Need to decrease statistic for assigned prefixes.
  1942. StatsMgr::instance().addValue(
  1943. StatsMgr::generateName("subnet", lease->subnet_id_, "assigned-pds"),
  1944. static_cast<int64_t>(-1));
  1945. }
  1946. return (ia_rsp);
  1947. }
  1948. Pkt6Ptr
  1949. Dhcpv6Srv::processSolicit(const Pkt6Ptr& solicit) {
  1950. sanityCheck(solicit, MANDATORY, FORBIDDEN);
  1951. // Let's create a simplified client context here.
  1952. AllocEngine::ClientContext6 ctx;
  1953. initContext(solicit, ctx);
  1954. setReservedClientClasses(solicit, ctx);
  1955. Pkt6Ptr response(new Pkt6(DHCPV6_ADVERTISE, solicit->getTransid()));
  1956. // Handle Rapid Commit option, if present.
  1957. if (ctx.subnet_ && ctx.subnet_->getRapidCommit()) {
  1958. OptionPtr opt_rapid_commit = solicit->getOption(D6O_RAPID_COMMIT);
  1959. if (opt_rapid_commit) {
  1960. LOG_DEBUG(options6_logger, DBG_DHCP6_DETAIL, DHCP6_RAPID_COMMIT)
  1961. .arg(solicit->getLabel());
  1962. // If Rapid Commit has been sent by the client, change the
  1963. // response type to Reply and include Rapid Commit option.
  1964. response->setType(DHCPV6_REPLY);
  1965. response->addOption(opt_rapid_commit);
  1966. }
  1967. }
  1968. processClientFqdn(solicit, response, ctx);
  1969. assignLeases(solicit, response, ctx);
  1970. copyClientOptions(solicit, response);
  1971. CfgOptionList co_list;
  1972. buildCfgOptionList(solicit, ctx, co_list);
  1973. appendDefaultOptions(solicit, response, co_list);
  1974. appendRequestedOptions(solicit, response, co_list);
  1975. appendRequestedVendorOptions(solicit, response, ctx, co_list);
  1976. // Only generate name change requests if sending a Reply as a result
  1977. // of receiving Rapid Commit option.
  1978. if (response->getType() == DHCPV6_REPLY) {
  1979. createNameChangeRequests(response, ctx);
  1980. }
  1981. return (response);
  1982. }
  1983. Pkt6Ptr
  1984. Dhcpv6Srv::processRequest(const Pkt6Ptr& request) {
  1985. sanityCheck(request, MANDATORY, MANDATORY);
  1986. // Let's create a simplified client context here.
  1987. AllocEngine::ClientContext6 ctx;
  1988. initContext(request, ctx);
  1989. setReservedClientClasses(request, ctx);
  1990. Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, request->getTransid()));
  1991. processClientFqdn(request, reply, ctx);
  1992. assignLeases(request, reply, ctx);
  1993. copyClientOptions(request, reply);
  1994. CfgOptionList co_list;
  1995. buildCfgOptionList(request, ctx, co_list);
  1996. appendDefaultOptions(request, reply, co_list);
  1997. appendRequestedOptions(request, reply, co_list);
  1998. appendRequestedVendorOptions(request, reply, ctx, co_list);
  1999. generateFqdn(reply);
  2000. createNameChangeRequests(reply, ctx);
  2001. return (reply);
  2002. }
  2003. Pkt6Ptr
  2004. Dhcpv6Srv::processRenew(const Pkt6Ptr& renew) {
  2005. sanityCheck(renew, MANDATORY, MANDATORY);
  2006. // Let's create a simplified client context here.
  2007. AllocEngine::ClientContext6 ctx;
  2008. initContext(renew, ctx);
  2009. setReservedClientClasses(renew, ctx);
  2010. Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, renew->getTransid()));
  2011. processClientFqdn(renew, reply, ctx);
  2012. extendLeases(renew, reply, ctx);
  2013. copyClientOptions(renew, reply);
  2014. CfgOptionList co_list;
  2015. buildCfgOptionList(renew, ctx, co_list);
  2016. appendDefaultOptions(renew, reply, co_list);
  2017. appendRequestedOptions(renew, reply, co_list);
  2018. appendRequestedVendorOptions(renew, reply, ctx, co_list);
  2019. generateFqdn(reply);
  2020. createNameChangeRequests(reply, ctx);
  2021. return (reply);
  2022. }
  2023. Pkt6Ptr
  2024. Dhcpv6Srv::processRebind(const Pkt6Ptr& rebind) {
  2025. sanityCheck(rebind, MANDATORY, FORBIDDEN);
  2026. // Let's create a simplified client context here.
  2027. AllocEngine::ClientContext6 ctx;
  2028. initContext(rebind, ctx);
  2029. setReservedClientClasses(rebind, ctx);
  2030. Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, rebind->getTransid()));
  2031. processClientFqdn(rebind, reply, ctx);
  2032. extendLeases(rebind, reply, ctx);
  2033. copyClientOptions(rebind, reply);
  2034. CfgOptionList co_list;
  2035. buildCfgOptionList(rebind, ctx, co_list);
  2036. appendDefaultOptions(rebind, reply, co_list);
  2037. appendRequestedOptions(rebind, reply, co_list);
  2038. appendRequestedVendorOptions(rebind, reply, ctx, co_list);
  2039. generateFqdn(reply);
  2040. createNameChangeRequests(reply, ctx);
  2041. return (reply);
  2042. }
  2043. Pkt6Ptr
  2044. Dhcpv6Srv::processConfirm(const Pkt6Ptr& confirm) {
  2045. sanityCheck(confirm, MANDATORY, FORBIDDEN);
  2046. // Let's create a simplified client context here.
  2047. AllocEngine::ClientContext6 ctx;
  2048. initContext(confirm, ctx);
  2049. setReservedClientClasses(confirm, ctx);
  2050. // Get IA_NAs from the Confirm. If there are none, the message is
  2051. // invalid and must be discarded. There is nothing more to do.
  2052. OptionCollection ias = confirm->getOptions(D6O_IA_NA);
  2053. if (ias.empty()) {
  2054. return (Pkt6Ptr());
  2055. }
  2056. // The server sends Reply message in response to Confirm.
  2057. Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, confirm->getTransid()));
  2058. // Make sure that the necessary options are included.
  2059. copyClientOptions(confirm, reply);
  2060. CfgOptionList co_list;
  2061. buildCfgOptionList(confirm, ctx, co_list);
  2062. appendDefaultOptions(confirm, reply, co_list);
  2063. appendRequestedOptions(confirm, reply, co_list);
  2064. appendRequestedVendorOptions(confirm, reply, ctx, co_list);
  2065. // Indicates if at least one address has been verified. If no addresses
  2066. // are verified it means that the client has sent no IA_NA options
  2067. // or no IAAddr options and that client's message has to be discarded.
  2068. bool verified = false;
  2069. // Check if subnet was selected for the message. If no subnet
  2070. // has been selected, the client is not on link.
  2071. SubnetPtr subnet = ctx.subnet_;
  2072. // Regardless if the subnet has been selected or not, we will iterate
  2073. // over the IA_NA options to check if they hold any addresses. If there
  2074. // are no, the Confirm is discarded.
  2075. // Check addresses in IA_NA options and make sure they are appropriate.
  2076. for (OptionCollection::const_iterator ia = ias.begin();
  2077. ia != ias.end(); ++ia) {
  2078. const OptionCollection& opts = ia->second->getOptions();
  2079. for (OptionCollection::const_iterator opt = opts.begin();
  2080. opt != opts.end(); ++opt) {
  2081. // Ignore options other than IAAddr.
  2082. if (opt->second->getType() == D6O_IAADDR) {
  2083. // Check that the address is in range in the subnet selected.
  2084. Option6IAAddrPtr iaaddr = boost::dynamic_pointer_cast<
  2085. Option6IAAddr>(opt->second);
  2086. // If there is subnet selected and the address has been included
  2087. // in IA_NA, mark it verified and verify that it belongs to the
  2088. // subnet.
  2089. if (iaaddr) {
  2090. // If at least one address is not in range, then return
  2091. // the NotOnLink status code.
  2092. if (subnet && !subnet->inRange(iaaddr->getAddress())) {
  2093. std::ostringstream status_msg;
  2094. status_msg << "Address " << iaaddr->getAddress()
  2095. << " is not on link.";
  2096. reply->addOption(createStatusCode(*confirm,
  2097. STATUS_NotOnLink,
  2098. status_msg.str()));
  2099. return (reply);
  2100. }
  2101. verified = true;
  2102. } else {
  2103. isc_throw(Unexpected, "failed to cast the IA Address option"
  2104. " to the Option6IAAddrPtr. This is programming"
  2105. " error and should be reported");
  2106. }
  2107. }
  2108. }
  2109. }
  2110. // It seems that the client hasn't included any addresses in which case
  2111. // the Confirm must be discarded.
  2112. if (!verified) {
  2113. return (Pkt6Ptr());
  2114. }
  2115. // If there is a subnet, there were addresses in IA_NA options and the
  2116. // addresses where consistent with the subnet then the client is on link.
  2117. if (subnet) {
  2118. // All addresses in range, so return success.
  2119. reply->addOption(createStatusCode(*confirm, STATUS_Success,
  2120. "All addresses are on-link"));
  2121. } else {
  2122. reply->addOption(createStatusCode(*confirm, STATUS_NotOnLink,
  2123. "No subnet selected"));
  2124. }
  2125. return (reply);
  2126. }
  2127. Pkt6Ptr
  2128. Dhcpv6Srv::processRelease(const Pkt6Ptr& release) {
  2129. sanityCheck(release, MANDATORY, MANDATORY);
  2130. // Let's create a simplified client context here.
  2131. AllocEngine::ClientContext6 ctx;
  2132. initContext(release, ctx);
  2133. setReservedClientClasses(release, ctx);
  2134. Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, release->getTransid()));
  2135. copyClientOptions(release, reply);
  2136. CfgOptionList co_list;
  2137. // buildCfgOptionList(release, ctx, co_list);
  2138. appendDefaultOptions(release, reply, co_list);
  2139. releaseLeases(release, reply, ctx);
  2140. /// @todo If client sent a release and we should remove outstanding
  2141. /// DNS records.
  2142. return (reply);
  2143. }
  2144. Pkt6Ptr
  2145. Dhcpv6Srv::processDecline(const Pkt6Ptr& decline) {
  2146. // Do sanity check.
  2147. sanityCheck(decline, MANDATORY, MANDATORY);
  2148. // Create an empty Reply message.
  2149. Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, decline->getTransid()));
  2150. // Let's create a simplified client context here.
  2151. AllocEngine::ClientContext6 ctx;
  2152. initContext(decline, ctx);
  2153. setReservedClientClasses(decline, ctx);
  2154. // Copy client options (client-id, also relay information if present)
  2155. copyClientOptions(decline, reply);
  2156. // Get the configured option list
  2157. CfgOptionList co_list;
  2158. buildCfgOptionList(decline, ctx, co_list);
  2159. // Include server-id
  2160. appendDefaultOptions(decline, reply, co_list);
  2161. if (declineLeases(decline, reply, ctx)) {
  2162. return (reply);
  2163. } else {
  2164. // declineLeases returns false only if the hooks set the next step
  2165. // status to DROP. We'll just doing as requested.
  2166. return (Pkt6Ptr());
  2167. }
  2168. }
  2169. bool
  2170. Dhcpv6Srv::declineLeases(const Pkt6Ptr& decline, Pkt6Ptr& reply,
  2171. AllocEngine::ClientContext6& ctx) {
  2172. // We need to decline addresses for all IA_NA options in the client's
  2173. // RELEASE message.
  2174. // Let's set the status to be success by default. We can override it with
  2175. // error status if needed. The important thing to understand here is that
  2176. // the global status code may be set to success only if all IA options were
  2177. // handled properly. Therefore the declineIA options
  2178. // may turn the status code to some error, but can't turn it back to success.
  2179. int general_status = STATUS_Success;
  2180. for (OptionCollection::iterator opt = decline->options_.begin();
  2181. opt != decline->options_.end(); ++opt) {
  2182. switch (opt->second->getType()) {
  2183. case D6O_IA_NA: {
  2184. OptionPtr answer_opt = declineIA(decline, ctx.duid_, general_status,
  2185. boost::dynamic_pointer_cast<Option6IA>(opt->second));
  2186. if (answer_opt) {
  2187. // We have an answer, let's use it.
  2188. reply->addOption(answer_opt);
  2189. } else {
  2190. // The only case when declineIA could return NULL is if one of the
  2191. // hook callouts set next step status to DROP. We just need to drop
  2192. // this packet.
  2193. return (false);
  2194. }
  2195. break;
  2196. }
  2197. default:
  2198. // We don't care for the remaining options
  2199. ;
  2200. }
  2201. }
  2202. return (true);
  2203. }
  2204. OptionPtr
  2205. Dhcpv6Srv::declineIA(const Pkt6Ptr& decline, const DuidPtr& duid,
  2206. int& general_status, boost::shared_ptr<Option6IA> ia) {
  2207. LOG_DEBUG(lease6_logger, DBG_DHCP6_DETAIL, DHCP6_DECLINE_PROCESS_IA)
  2208. .arg(decline->getLabel())
  2209. .arg(ia->getIAID());
  2210. // Decline can be done in one of two ways:
  2211. // Approach 1: extract address from client's IA_NA and see if it belongs
  2212. // to this particular client.
  2213. // Approach 2: find a subnet for this client, get a lease for
  2214. // this subnet/duid/iaid and check if its content matches to what the
  2215. // client is asking us to decline.
  2216. //
  2217. // This method implements approach 1.
  2218. // That's our response
  2219. boost::shared_ptr<Option6IA> ia_rsp(new Option6IA(D6O_IA_NA, ia->getIAID()));
  2220. const OptionCollection& opts = ia->getOptions();
  2221. int total_addrs = 0; // Let's count the total number of addresses.
  2222. for (OptionCollection::const_iterator opt = opts.begin(); opt != opts.end();
  2223. ++opt) {
  2224. // Let's ignore nested options other than IAADDR (there shouldn't be anything
  2225. // else in IA_NA in Decline message, but let's be on the safe side).
  2226. if (opt->second->getType() != D6O_IAADDR) {
  2227. continue;
  2228. }
  2229. Option6IAAddrPtr decline_addr = boost::dynamic_pointer_cast<Option6IAAddr>
  2230. (opt->second);
  2231. if (!decline_addr) {
  2232. continue;
  2233. }
  2234. total_addrs++;
  2235. Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
  2236. decline_addr->getAddress());
  2237. if (!lease) {
  2238. // Client trying to decline a lease that we don't know about.
  2239. LOG_INFO(lease6_logger, DHCP6_DECLINE_FAIL_NO_LEASE)
  2240. .arg(decline->getLabel()).arg(decline_addr->getAddress().toText());
  2241. // RFC3315, section 18.2.7: "For each IA in the Decline message for
  2242. // which the server has no binding information, the server adds an
  2243. // IA option using the IAID from the Release message and includes
  2244. // a Status Code option with the value NoBinding in the IA option.
  2245. setStatusCode(ia_rsp, createStatusCode(*decline, *ia_rsp, STATUS_NoBinding,
  2246. "Server does not know about such an address."));
  2247. // RFC3315, section 18.2.7: The server ignores addresses not
  2248. // assigned to the IA (though it may choose to log an error if it
  2249. // finds such an address).
  2250. continue; // There may be other addresses.
  2251. }
  2252. if (!lease->duid_) {
  2253. // Something is gravely wrong here. We do have a lease, but it does not
  2254. // have mandatory DUID information attached. Someone was messing with our
  2255. // database.
  2256. LOG_ERROR(lease6_logger, DHCP6_DECLINE_FAIL_LEASE_WITHOUT_DUID)
  2257. .arg(decline->getLabel())
  2258. .arg(decline_addr->getAddress().toText());
  2259. ia_rsp->addOption(createStatusCode(*decline, *ia_rsp, STATUS_UnspecFail,
  2260. "Database consistency check failed when attempting Decline."));
  2261. continue;
  2262. }
  2263. // Ok, there's a sane lease with an address. Let's check if DUID matches first.
  2264. if (*duid != *(lease->duid_)) {
  2265. // Sorry, it's not your address. You can't release it.
  2266. LOG_INFO(lease6_logger, DHCP6_DECLINE_FAIL_DUID_MISMATCH)
  2267. .arg(decline->getLabel())
  2268. .arg(decline_addr->getAddress().toText())
  2269. .arg(lease->duid_->toText());
  2270. ia_rsp->addOption(createStatusCode(*decline, *ia_rsp, STATUS_NoBinding,
  2271. "This address does not belong to you, you can't decline it"));
  2272. continue;
  2273. }
  2274. // Let's check if IAID matches.
  2275. if (ia->getIAID() != lease->iaid_) {
  2276. // This address belongs to this client, but to a different IA
  2277. LOG_INFO(lease6_logger, DHCP6_DECLINE_FAIL_IAID_MISMATCH)
  2278. .arg(decline->getLabel())
  2279. .arg(lease->addr_.toText())
  2280. .arg(ia->getIAID())
  2281. .arg(lease->iaid_);
  2282. setStatusCode(ia_rsp, createStatusCode(*decline, *ia_rsp, STATUS_NoBinding,
  2283. "This is your address, but you used wrong IAID"));
  2284. continue;
  2285. }
  2286. // Ok, all is good. Decline this lease.
  2287. if (!declineLease(decline, lease, ia_rsp)) {
  2288. // declineLease returns false only when hook callouts set the next
  2289. // step status to drop. We just propagate the bad news here.
  2290. return (OptionPtr());
  2291. }
  2292. }
  2293. if (total_addrs == 0) {
  2294. setStatusCode(ia_rsp, createStatusCode(*decline, *ia_rsp, STATUS_NoBinding,
  2295. "No addresses sent in IA_NA"));
  2296. general_status = STATUS_NoBinding;
  2297. }
  2298. return (ia_rsp);
  2299. }
  2300. void
  2301. Dhcpv6Srv::setStatusCode(boost::shared_ptr<isc::dhcp::Option6IA>& container,
  2302. const OptionPtr& status) {
  2303. // Let's delete any old status code we may have.
  2304. container->delOption(D6O_STATUS_CODE);
  2305. container->addOption(status);
  2306. }
  2307. bool
  2308. Dhcpv6Srv::declineLease(const Pkt6Ptr& decline, const Lease6Ptr lease,
  2309. boost::shared_ptr<Option6IA> ia_rsp) {
  2310. // We do not want to decrease the assigned-nas at this time. While
  2311. // technically a declined address is no longer allocated, the primary usage
  2312. // of the assigned-addresses statistic is to monitor pool utilization. Most
  2313. // people would forget to include declined-addresses in the calculation,
  2314. // and simply do assigned-addresses/total-addresses. This would have a bias
  2315. // towards under-representing pool utilization, if we decreased allocated
  2316. // immediately after receiving DHCPDECLINE, rather than later when we recover
  2317. // the address.
  2318. // Let's call lease6_decline hooks if necessary.
  2319. if (HooksManager::calloutsPresent(Hooks.hook_index_lease6_decline_)) {
  2320. CalloutHandlePtr callout_handle = getCalloutHandle(decline);
  2321. // Delete previously set arguments
  2322. callout_handle->deleteAllArguments();
  2323. // Enable copying options from the packet within hook library.
  2324. ScopedEnableOptionsCopy<Pkt6> query6_options_copy(decline);
  2325. // Pass incoming packet as argument
  2326. callout_handle->setArgument("query6", decline);
  2327. callout_handle->setArgument("lease6", lease);
  2328. // Call callouts
  2329. HooksManager::callCallouts(Hooks.hook_index_lease6_decline_,
  2330. *callout_handle);
  2331. // Callouts decided to SKIP the next processing step. The next
  2332. // processing step would to actually decline the lease, so we'll
  2333. // keep the lease as is.
  2334. if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) {
  2335. LOG_DEBUG(hooks_logger, DBG_DHCP6_DETAIL, DHCP6_HOOK_DECLINE_SKIP)
  2336. .arg(decline->getLabel())
  2337. .arg(decline->getIface())
  2338. .arg(lease->addr_.toText());
  2339. return (true);
  2340. }
  2341. // Callouts decided to DROP the packet. Let's simply log it and
  2342. // return false, so callers will act accordingly.
  2343. if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP) {
  2344. LOG_DEBUG(hooks_logger, DBG_DHCP6_DETAIL, DHCP6_HOOK_DECLINE_DROP)
  2345. .arg(decline->getLabel())
  2346. .arg(decline->getIface())
  2347. .arg(lease->addr_.toText());
  2348. return (false);
  2349. }
  2350. }
  2351. // Check if a lease has flags indicating that the FQDN update has
  2352. // been performed. If so, create NameChangeRequest which removes
  2353. // the entries. This method does all necessary checks.
  2354. queueNCR(CHG_REMOVE, lease);
  2355. // Bump up the subnet-specific statistic.
  2356. StatsMgr::instance().addValue(
  2357. StatsMgr::generateName("subnet", lease->subnet_id_, "declined-addresses"),
  2358. static_cast<int64_t>(1));
  2359. // Global declined addresses counter.
  2360. StatsMgr::instance().addValue("declined-addresses", static_cast<int64_t>(1));
  2361. // We need to disassociate the lease from the client. Once we move a lease
  2362. // to declined state, it is no longer associated with the client in any
  2363. // way.
  2364. lease->decline(CfgMgr::instance().getCurrentCfg()->getDeclinePeriod());
  2365. LeaseMgrFactory::instance().updateLease6(lease);
  2366. LOG_INFO(lease6_logger, DHCP6_DECLINE_LEASE).arg(decline->getLabel())
  2367. .arg(lease->addr_.toText()).arg(lease->valid_lft_);
  2368. ia_rsp->addOption(createStatusCode(*decline, *ia_rsp, STATUS_Success,
  2369. "Lease declined. Hopefully the next one will be better."));
  2370. return (true);
  2371. }
  2372. Pkt6Ptr
  2373. Dhcpv6Srv::processInfRequest(const Pkt6Ptr& inf_request) {
  2374. sanityCheck(inf_request, OPTIONAL, OPTIONAL);
  2375. // Let's create a simplified client context here.
  2376. AllocEngine::ClientContext6 ctx;
  2377. initContext(inf_request, ctx);
  2378. setReservedClientClasses(inf_request, ctx);
  2379. // Create a Reply packet, with the same trans-id as the client's.
  2380. Pkt6Ptr reply(new Pkt6(DHCPV6_REPLY, inf_request->getTransid()));
  2381. // Copy client options (client-id, also relay information if present)
  2382. copyClientOptions(inf_request, reply);
  2383. // Build the configured option list for append methods
  2384. CfgOptionList co_list;
  2385. buildCfgOptionList(inf_request, ctx, co_list);
  2386. // Append default options, i.e. options that the server is supposed
  2387. // to put in all messages it sends (server-id for now, but possibly other
  2388. // options once we start supporting authentication)
  2389. appendDefaultOptions(inf_request, reply, co_list);
  2390. // Try to assign options that were requested by the client.
  2391. appendRequestedOptions(inf_request, reply, co_list);
  2392. // Try to assigne vendor options that were requested by the client.
  2393. appendRequestedVendorOptions(inf_request, reply, ctx, co_list);
  2394. return (reply);
  2395. }
  2396. void
  2397. Dhcpv6Srv::processDhcp4Query(const Pkt6Ptr& dhcp4_query) {
  2398. sanityCheck(dhcp4_query, OPTIONAL, OPTIONAL);
  2399. // flags are in transid
  2400. // uint32_t flags = dhcp4_query->getTransid();
  2401. // do nothing with DHCPV4_QUERY_FLAGS_UNICAST
  2402. // Get the DHCPv4 message option
  2403. OptionPtr dhcp4_msg = dhcp4_query->getOption(D6O_DHCPV4_MSG);
  2404. if (dhcp4_msg) {
  2405. // Forward the whole message to the DHCPv4 server via IPC
  2406. Dhcp6to4Ipc::instance().send(dhcp4_query);
  2407. }
  2408. // This method does not return anything as we always sent back
  2409. // the response via Dhcp6To4Ipc.
  2410. }
  2411. void Dhcpv6Srv::classifyByVendor(const Pkt6Ptr& pkt, std::string& classes) {
  2412. OptionVendorClassPtr vclass = boost::dynamic_pointer_cast<
  2413. OptionVendorClass>(pkt->getOption(D6O_VENDOR_CLASS));
  2414. if (!vclass || vclass->getTuplesNum() == 0) {
  2415. return;
  2416. }
  2417. if (vclass->hasTuple(DOCSIS3_CLASS_MODEM)) {
  2418. pkt->addClass(VENDOR_CLASS_PREFIX + DOCSIS3_CLASS_MODEM);
  2419. classes += VENDOR_CLASS_PREFIX + DOCSIS3_CLASS_MODEM + " ";
  2420. } else if (vclass->hasTuple(DOCSIS3_CLASS_EROUTER)) {
  2421. pkt->addClass(VENDOR_CLASS_PREFIX + DOCSIS3_CLASS_EROUTER);
  2422. classes += VENDOR_CLASS_PREFIX + DOCSIS3_CLASS_EROUTER + " ";
  2423. } else {
  2424. pkt->addClass(VENDOR_CLASS_PREFIX + vclass->getTuple(0).getText());
  2425. classes + VENDOR_CLASS_PREFIX + vclass->getTuple(0).getText() + " ";
  2426. }
  2427. }
  2428. void Dhcpv6Srv::classifyPacket(const Pkt6Ptr& pkt) {
  2429. string classes = "";
  2430. // First phase: built-in vendor class processing
  2431. classifyByVendor(pkt, classes);
  2432. // Run match expressions
  2433. // Note getClientClassDictionary() cannot be null
  2434. const ClientClassDefMapPtr& defs_ptr = CfgMgr::instance().getCurrentCfg()->
  2435. getClientClassDictionary()->getClasses();
  2436. for (ClientClassDefMap::const_iterator it = defs_ptr->begin();
  2437. it != defs_ptr->end(); ++it) {
  2438. // Note second cannot be null
  2439. const ExpressionPtr& expr_ptr = it->second->getMatchExpr();
  2440. // Nothing to do without an expression to evaluate
  2441. if (!expr_ptr) {
  2442. continue;
  2443. }
  2444. // Evaluate the expression which can return false (no match),
  2445. // true (match) or raise an exception (error)
  2446. try {
  2447. bool status = evaluate(*expr_ptr, *pkt);
  2448. if (status) {
  2449. LOG_INFO(dhcp6_logger, EVAL_RESULT)
  2450. .arg(it->first)
  2451. .arg(status);
  2452. // Matching: add the class
  2453. pkt->addClass(it->first);
  2454. classes += it->first + " ";
  2455. } else {
  2456. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, EVAL_RESULT)
  2457. .arg(it->first)
  2458. .arg(status);
  2459. }
  2460. } catch (const Exception& ex) {
  2461. LOG_ERROR(dhcp6_logger, EVAL_RESULT)
  2462. .arg(it->first)
  2463. .arg(ex.what());
  2464. } catch (...) {
  2465. LOG_ERROR(dhcp6_logger, EVAL_RESULT)
  2466. .arg(it->first)
  2467. .arg("get exception?");
  2468. }
  2469. }
  2470. }
  2471. void
  2472. Dhcpv6Srv::setReservedClientClasses(const Pkt6Ptr& pkt,
  2473. const AllocEngine::ClientContext6& ctx) {
  2474. if (ctx.host_ && pkt) {
  2475. BOOST_FOREACH(const std::string& client_class,
  2476. ctx.host_->getClientClasses6()) {
  2477. pkt->addClass(client_class);
  2478. }
  2479. }
  2480. const ClientClasses& classes = pkt->getClasses();
  2481. if (!classes.empty()) {
  2482. std::string joined_classes = boost::algorithm::join(classes, ", ");
  2483. LOG_DEBUG(dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_CLASS_ASSIGNED)
  2484. .arg(pkt->getLabel())
  2485. .arg(joined_classes);
  2486. }
  2487. }
  2488. void
  2489. Dhcpv6Srv::generateFqdn(const Pkt6Ptr& answer) {
  2490. if (!answer) {
  2491. isc_throw(isc::Unexpected, "an instance of the object encapsulating"
  2492. " a message must not be NULL when generating FQDN");
  2493. }
  2494. /// @todo Add proper logging for cases when we can't generate FQDN.
  2495. /// See #3885 for details.
  2496. // It is likely that client hasn't included the FQDN option. In such case,
  2497. // FQDN option will be NULL. Also, there is nothing to do if the option
  2498. // is present and conveys the non-empty FQDN.
  2499. Option6ClientFqdnPtr fqdn = boost::dynamic_pointer_cast<
  2500. Option6ClientFqdn>(answer->getOption(D6O_CLIENT_FQDN));
  2501. if (!fqdn || !fqdn->getDomainName().empty()) {
  2502. return;
  2503. }
  2504. // Get the first IA_NA acquired for the client.
  2505. OptionPtr ia = answer->getOption(D6O_IA_NA);
  2506. if (!ia) {
  2507. return;
  2508. }
  2509. // If it has any IAAddr, use the first one to generate unique FQDN.
  2510. Option6IAAddrPtr iaaddr = boost::dynamic_pointer_cast<
  2511. Option6IAAddr>(ia->getOption(D6O_IAADDR));
  2512. if (!iaaddr) {
  2513. return;
  2514. }
  2515. // Get the IPv6 address acquired by the client.
  2516. IOAddress addr = iaaddr->getAddress();
  2517. std::string generated_name =
  2518. CfgMgr::instance().getD2ClientMgr().generateFqdn(addr);
  2519. LOG_DEBUG(ddns6_logger, DBG_DHCP6_DETAIL_DATA, DHCP6_DDNS_FQDN_GENERATED)
  2520. .arg(answer->getLabel())
  2521. .arg(generated_name);
  2522. try {
  2523. // The lease has been acquired but the FQDN for this lease hasn't
  2524. // been updated in the lease database. We now have new FQDN
  2525. // generated, so the lease database has to be updated here.
  2526. // However, never update lease database for Advertise, just send
  2527. // our notion of client's FQDN in the Client FQDN option.
  2528. if (answer->getType() != DHCPV6_ADVERTISE) {
  2529. Lease6Ptr lease =
  2530. LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr);
  2531. if (lease) {
  2532. lease->hostname_ = generated_name;
  2533. LeaseMgrFactory::instance().updateLease6(lease);
  2534. } else {
  2535. isc_throw(isc::Unexpected, "there is no lease in the database "
  2536. " for address " << addr << ", so as it is impossible"
  2537. " to update FQDN data. This is a programmatic error"
  2538. " as the given address is now being handed to the"
  2539. " client");
  2540. }
  2541. }
  2542. // Set the generated FQDN in the Client FQDN option.
  2543. fqdn->setDomainName(generated_name, Option6ClientFqdn::FULL);
  2544. } catch (const Exception& ex) {
  2545. LOG_ERROR(ddns6_logger, DHCP6_DDNS_GENERATED_FQDN_UPDATE_FAIL)
  2546. .arg(answer->getLabel())
  2547. .arg(addr.toText())
  2548. .arg(ex.what());
  2549. }
  2550. }
  2551. void
  2552. Dhcpv6Srv::startD2() {
  2553. D2ClientMgr& d2_mgr = CfgMgr::instance().getD2ClientMgr();
  2554. if (d2_mgr.ddnsEnabled()) {
  2555. // Updates are enabled, so lets start the sender, passing in
  2556. // our error handler.
  2557. // This may throw so wherever this is called needs to ready.
  2558. d2_mgr.startSender(boost::bind(&Dhcpv6Srv::d2ClientErrorHandler,
  2559. this, _1, _2));
  2560. }
  2561. }
  2562. void
  2563. Dhcpv6Srv::stopD2() {
  2564. D2ClientMgr& d2_mgr = CfgMgr::instance().getD2ClientMgr();
  2565. if (d2_mgr.ddnsEnabled()) {
  2566. // Updates are enabled, so lets stop the sender
  2567. d2_mgr.stopSender();
  2568. }
  2569. }
  2570. void
  2571. Dhcpv6Srv::d2ClientErrorHandler(const
  2572. dhcp_ddns::NameChangeSender::Result result,
  2573. dhcp_ddns::NameChangeRequestPtr& ncr) {
  2574. LOG_ERROR(ddns6_logger, DHCP6_DDNS_REQUEST_SEND_FAILED).
  2575. arg(result).arg((ncr ? ncr->toText() : " NULL "));
  2576. // We cannot communicate with kea-dhcp-ddns, suspend further updates.
  2577. /// @todo We may wish to revisit this, but for now we will simply turn
  2578. /// them off.
  2579. CfgMgr::instance().getD2ClientMgr().suspendUpdates();
  2580. }
  2581. // Refer to config_report so it will be embedded in the binary
  2582. const char* const* dhcp6_config_report = isc::detail::config_report;
  2583. std::string
  2584. Dhcpv6Srv::getVersion(bool extended) {
  2585. std::stringstream tmp;
  2586. tmp << VERSION;
  2587. if (extended) {
  2588. tmp << endl << EXTENDED_VERSION << endl;
  2589. tmp << "linked with:" << endl;
  2590. tmp << Logger::getVersion() << endl;
  2591. tmp << CryptoLink::getVersion() << endl;
  2592. tmp << "database:" << endl;
  2593. #ifdef HAVE_MYSQL
  2594. tmp << MySqlLeaseMgr::getDBVersion() << endl;
  2595. #endif
  2596. #ifdef HAVE_PGSQL
  2597. tmp << PgSqlLeaseMgr::getDBVersion() << endl;
  2598. #endif
  2599. #ifdef HAVE_CQL
  2600. tmp << CqlLeaseMgr::getDBVersion() << endl;
  2601. #endif
  2602. tmp << Memfile_LeaseMgr::getDBVersion();
  2603. // @todo: more details about database runtime
  2604. }
  2605. return (tmp.str());
  2606. }
  2607. void Dhcpv6Srv::processRSOO(const Pkt6Ptr& query, const Pkt6Ptr& rsp) {
  2608. if (query->relay_info_.empty()) {
  2609. // RSOO is inserted by relay agents, nothing to do here if it's
  2610. // a direct message.
  2611. return;
  2612. }
  2613. // Get RSOO configuration.
  2614. ConstCfgRSOOPtr cfg_rsoo = CfgMgr::instance().getCurrentCfg()->getCfgRSOO();
  2615. // Let's get over all relays (encapsulation levels). We need to do
  2616. // it in the same order as the client packet traversed the relays.
  2617. for (int i = query->relay_info_.size(); i > 0 ; --i) {
  2618. OptionPtr rsoo_container = query->getRelayOption(D6O_RSOO, i - 1);
  2619. if (rsoo_container) {
  2620. // There are RSOO options. Let's get through them one by one
  2621. // and if it's RSOO-enabled and there's no such option provided yet,
  2622. // copy it to the server's response
  2623. const OptionCollection& rsoo = rsoo_container->getOptions();
  2624. for (OptionCollection::const_iterator opt = rsoo.begin();
  2625. opt != rsoo.end(); ++opt) {
  2626. // Echo option if it is RSOO enabled option and there is no such
  2627. // option added yet.
  2628. if (cfg_rsoo->enabled(opt->second->getType()) &&
  2629. !rsp->getOption(opt->second->getType())) {
  2630. rsp->addOption(opt->second);
  2631. }
  2632. }
  2633. }
  2634. }
  2635. }
  2636. void Dhcpv6Srv::processStatsReceived(const Pkt6Ptr& query) {
  2637. // Note that we're not bumping pkt6-received statistic as it was
  2638. // increased early in the packet reception code.
  2639. string stat_name = "pkt6-unknown-received";
  2640. switch (query->getType()) {
  2641. case DHCPV6_SOLICIT:
  2642. stat_name = "pkt6-solicit-received";
  2643. break;
  2644. case DHCPV6_ADVERTISE:
  2645. // Should not happen, but let's keep a counter for it
  2646. stat_name = "pkt6-advertise-received";
  2647. break;
  2648. case DHCPV6_REQUEST:
  2649. stat_name = "pkt6-request-received";
  2650. break;
  2651. case DHCPV6_CONFIRM:
  2652. stat_name = "pkt6-confirm-received";
  2653. break;
  2654. case DHCPV6_RENEW:
  2655. stat_name = "pkt6-renew-received";
  2656. break;
  2657. case DHCPV6_REBIND:
  2658. stat_name = "pkt6-rebind-received";
  2659. break;
  2660. case DHCPV6_REPLY:
  2661. // Should not happen, but let's keep a counter for it
  2662. stat_name = "pkt6-reply-received";
  2663. break;
  2664. case DHCPV6_RELEASE:
  2665. stat_name = "pkt6-release-received";
  2666. break;
  2667. case DHCPV6_DECLINE:
  2668. stat_name = "pkt6-decline-received";
  2669. break;
  2670. case DHCPV6_RECONFIGURE:
  2671. stat_name = "pkt6-reconfigure-received";
  2672. break;
  2673. case DHCPV6_INFORMATION_REQUEST:
  2674. stat_name = "pkt6-infrequest-received";
  2675. break;
  2676. case DHCPV6_DHCPV4_QUERY:
  2677. stat_name = "pkt6-dhcpv4-query-received";
  2678. break;
  2679. case DHCPV6_DHCPV4_RESPONSE:
  2680. // Should not happen, but let's keep a counter for it
  2681. stat_name = "pkt6-dhcpv4-response-received";
  2682. break;
  2683. default:
  2684. ; // do nothing
  2685. }
  2686. StatsMgr::instance().addValue(stat_name, static_cast<int64_t>(1));
  2687. }
  2688. void Dhcpv6Srv::processStatsSent(const Pkt6Ptr& response) {
  2689. // Increase generic counter for sent packets.
  2690. StatsMgr::instance().addValue("pkt6-sent", static_cast<int64_t>(1));
  2691. // Increase packet type specific counter for packets sent.
  2692. string stat_name;
  2693. switch (response->getType()) {
  2694. case DHCPV6_ADVERTISE:
  2695. stat_name = "pkt6-advertise-sent";
  2696. break;
  2697. case DHCPV6_REPLY:
  2698. stat_name = "pkt6-reply-sent";
  2699. break;
  2700. case DHCPV6_DHCPV4_RESPONSE:
  2701. stat_name = "pkt6-dhcpv4-response-sent";
  2702. break;
  2703. default:
  2704. // That should never happen
  2705. return;
  2706. }
  2707. StatsMgr::instance().addValue(stat_name, static_cast<int64_t>(1));
  2708. }
  2709. int Dhcpv6Srv::getHookIndexBuffer6Send() {
  2710. return (Hooks.hook_index_buffer6_send_);
  2711. }
  2712. };
  2713. };