fqdn_unittest.cc 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516
  1. // Copyright (C) 2013-2017 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/option.h>
  11. #include <dhcp/option_custom.h>
  12. #include <dhcp/option6_client_fqdn.h>
  13. #include <dhcp/option6_ia.h>
  14. #include <dhcp/option6_iaaddr.h>
  15. #include <dhcp/option6_status_code.h>
  16. #include <dhcp/option_int_array.h>
  17. #include <dhcp/tests/iface_mgr_test_config.h>
  18. #include <dhcpsrv/lease.h>
  19. #include <dhcpsrv/lease_mgr_factory.h>
  20. #include <dhcpsrv/ncr_generator.h>
  21. #include <dhcp6/tests/dhcp6_test_utils.h>
  22. #include <boost/pointer_cast.hpp>
  23. #include <gtest/gtest.h>
  24. using namespace isc;
  25. using namespace isc::dhcp::test;
  26. using namespace isc::asiolink;
  27. using namespace isc::dhcp;
  28. using namespace isc::dhcp_ddns;
  29. using namespace isc::util;
  30. using namespace isc::hooks;
  31. using namespace std;
  32. namespace {
  33. /// @brief A test fixture class for testing DHCPv6 Client FQDN Option handling.
  34. class FqdnDhcpv6SrvTest : public Dhcpv6SrvTest {
  35. public:
  36. /// Pointer to Dhcpv6Srv that is used in tests
  37. boost::scoped_ptr<NakedDhcpv6Srv> srv_;
  38. // Reference to D2ClientMgr singleton
  39. D2ClientMgr& d2_mgr_;
  40. // Bit Constants for turning on and off DDNS configuration options.
  41. // (Defined here as these are only meaningful to this class.)
  42. static const uint16_t ALWAYS_INCLUDE_FQDN = 1;
  43. static const uint16_t OVERRIDE_NO_UPDATE = 2;
  44. static const uint16_t OVERRIDE_CLIENT_UPDATE = 4;
  45. static const uint16_t REPLACE_CLIENT_NAME = 8;
  46. // Enum used to specify whether a client (packet) should include
  47. // the hostname option
  48. enum ClientNameFlag {
  49. CLIENT_NAME_PRESENT,
  50. CLIENT_NAME_NOT_PRESENT
  51. };
  52. // Enum used to specify whether the server should replace/supply
  53. // the hostname or not
  54. enum ReplacementFlag {
  55. NAME_REPLACED,
  56. NAME_NOT_REPLACED
  57. };
  58. // Type used to indicate whether or not forward updates are expected
  59. struct ExpFwd {
  60. ExpFwd(bool exp_fwd) : value_(exp_fwd){};
  61. bool value_;
  62. };
  63. // Type used to indicate whether or not reverse updates are expected
  64. struct ExpRev {
  65. ExpRev(bool exp_rev) : value_(exp_rev){};
  66. bool value_;
  67. };
  68. /// @brief Constructor
  69. FqdnDhcpv6SrvTest()
  70. : Dhcpv6SrvTest(), srv_(new NakedDhcpv6Srv(0)),
  71. d2_mgr_(CfgMgr::instance().getD2ClientMgr()) {
  72. // generateClientId assigns DUID to duid_.
  73. generateClientId();
  74. lease_.reset(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:1::1"),
  75. duid_, 1234, 501, 502, 503,
  76. 504, 1, HWAddrPtr(), 0));
  77. // Config DDNS to be enabled, all controls off
  78. enableD2();
  79. }
  80. /// @brief Destructor
  81. virtual ~FqdnDhcpv6SrvTest() {
  82. // Default constructor creates a config with DHCP-DDNS updates
  83. // disabled.
  84. D2ClientConfigPtr cfg(new D2ClientConfig());
  85. CfgMgr::instance().setD2ClientConfig(cfg);
  86. }
  87. /// @brief Sets the server's DDNS configuration to ddns updates disabled.
  88. void disableD2() {
  89. // Default constructor creates a config with DHCP-DDNS updates
  90. // disabled.
  91. D2ClientConfigPtr cfg(new D2ClientConfig());
  92. CfgMgr::instance().setD2ClientConfig(cfg);
  93. }
  94. /// @brief Enables DHCP-DDNS updates with the given options enabled.
  95. ///
  96. /// Replaces the current D2ClientConfiguration with a configuration
  97. /// which as updates enabled and the control options set based upon
  98. /// the bit mask of options.
  99. ///
  100. /// @param mask Bit mask of configuration options that should be enabled.
  101. void enableD2(const uint16_t mask = 0) {
  102. D2ClientConfigPtr cfg;
  103. ASSERT_NO_THROW(cfg.reset(new D2ClientConfig(true,
  104. isc::asiolink::IOAddress("::1"), 53001,
  105. isc::asiolink::IOAddress("::"), 0,
  106. 1024,
  107. dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
  108. (mask & ALWAYS_INCLUDE_FQDN),
  109. (mask & OVERRIDE_NO_UPDATE),
  110. (mask & OVERRIDE_CLIENT_UPDATE),
  111. ((mask & REPLACE_CLIENT_NAME) ?
  112. D2ClientConfig::RCM_WHEN_PRESENT
  113. : D2ClientConfig::RCM_NEVER),
  114. "myhost", "example.com")));
  115. ASSERT_NO_THROW(CfgMgr::instance().setD2ClientConfig(cfg));
  116. ASSERT_NO_THROW(srv_->startD2());
  117. }
  118. /// @brief Construct the DHCPv6 Client FQDN option using flags and
  119. /// domain-name.
  120. ///
  121. /// @param flags Flags to be set for the created option.
  122. /// @param fqdn_name A name which should be stored in the option.
  123. /// @param fqdn_type A type of the name carried by the option: partial
  124. /// or fully qualified.
  125. ///
  126. /// @return A pointer to the created option.
  127. Option6ClientFqdnPtr
  128. createClientFqdn(const uint8_t flags,
  129. const std::string& fqdn_name,
  130. const Option6ClientFqdn::DomainNameType fqdn_type) {
  131. return (Option6ClientFqdnPtr(new Option6ClientFqdn(flags,
  132. fqdn_name,
  133. fqdn_type)));
  134. }
  135. /// @brief Create a message with or without DHCPv6 Client FQDN Option.
  136. ///
  137. /// @param msg_type A type of the DHCPv6 message to be created.
  138. /// @param fqdn_flags Flags to be carried in the FQDN option.
  139. /// @param fqdn_domain_name A name to be carried in the FQDN option.
  140. /// @param fqdn_type A type of the name carried by the option: partial
  141. /// or fully qualified.
  142. /// @param include_oro A boolean value which indicates whether the ORO
  143. /// option should be added to the message (if true).
  144. /// @param srvid server id to be stored in the message.
  145. ///
  146. /// @return An object representing the created message.
  147. Pkt6Ptr generateMessage(uint8_t msg_type,
  148. const uint8_t fqdn_flags,
  149. const std::string& fqdn_domain_name,
  150. const Option6ClientFqdn::DomainNameType
  151. fqdn_type,
  152. const bool include_oro,
  153. OptionPtr srvid = OptionPtr()) {
  154. Pkt6Ptr pkt = Pkt6Ptr(new Pkt6(msg_type, 1234));
  155. pkt->setRemoteAddr(IOAddress("fe80::abcd"));
  156. pkt->setIface("eth0");
  157. Option6IAPtr ia = generateIA(D6O_IA_NA, 234, 1500, 3000);
  158. if (msg_type != DHCPV6_REPLY) {
  159. IOAddress hint("2001:db8:1:1::dead:beef");
  160. OptionPtr hint_opt(new Option6IAAddr(D6O_IAADDR, hint, 300, 500));
  161. ia->addOption(hint_opt);
  162. pkt->addOption(ia);
  163. }
  164. OptionPtr clientid = generateClientId();
  165. pkt->addOption(clientid);
  166. if (srvid && (msg_type != DHCPV6_SOLICIT)) {
  167. pkt->addOption(srvid);
  168. }
  169. pkt->addOption(createClientFqdn(fqdn_flags, fqdn_domain_name,
  170. fqdn_type));
  171. if (include_oro) {
  172. OptionUint16ArrayPtr oro(new OptionUint16Array(Option::V6,
  173. D6O_ORO));
  174. oro->addValue(D6O_CLIENT_FQDN);
  175. pkt->addOption(oro);
  176. }
  177. return (pkt);
  178. }
  179. /// @brief Creates instance of the DHCPv6 message with client id and
  180. /// server id.
  181. ///
  182. /// @param msg_type A type of the message to be created.
  183. ///
  184. /// @return An object representing the created message.
  185. Pkt6Ptr generateMessageWithIds(const uint8_t msg_type) {
  186. Pkt6Ptr pkt = Pkt6Ptr(new Pkt6(msg_type, 1234));
  187. // Generate client-id.
  188. OptionPtr opt_clientid = generateClientId();
  189. pkt->addOption(opt_clientid);
  190. if (msg_type != DHCPV6_SOLICIT) {
  191. // Generate server-id.
  192. pkt->addOption(srv_->getServerID());
  193. }
  194. return (pkt);
  195. }
  196. /// @brief Returns an instance of the option carrying FQDN.
  197. ///
  198. /// @param pkt A message holding FQDN option to be returned.
  199. ///
  200. /// @return An object representing DHCPv6 Client FQDN option.
  201. Option6ClientFqdnPtr getClientFqdnOption(const Pkt6Ptr& pkt) {
  202. return (boost::dynamic_pointer_cast<Option6ClientFqdn>
  203. (pkt->getOption(D6O_CLIENT_FQDN)));
  204. }
  205. /// @brief Adds IA option to the message.
  206. ///
  207. /// Addded option holds an address.
  208. ///
  209. /// @param iaid IAID
  210. /// @param pkt A DHCPv6 message to which the IA option should be added.
  211. void addIA(const uint32_t iaid, const IOAddress& addr, Pkt6Ptr& pkt) {
  212. Option6IAPtr opt_ia = generateIA(D6O_IA_NA, iaid, 1500, 3000);
  213. Option6IAAddrPtr opt_iaaddr(new Option6IAAddr(D6O_IAADDR, addr,
  214. 300, 500));
  215. opt_ia->addOption(opt_iaaddr);
  216. pkt->addOption(opt_ia);
  217. }
  218. /// @brief Adds IA option to the message.
  219. ///
  220. /// Added option holds status code.
  221. ///
  222. /// @param iaid IAID
  223. /// @param status_code Status code
  224. /// @param pkt A DHCPv6 message to which the option should be added.
  225. void addIA(const uint32_t iaid, const uint16_t status_code, Pkt6Ptr& pkt) {
  226. Option6IAPtr opt_ia = generateIA(D6O_IA_NA, iaid, 1500, 3000);
  227. addStatusCode(status_code, "", opt_ia);
  228. pkt->addOption(opt_ia);
  229. }
  230. /// @brief Creates status code with the specified code and message.
  231. ///
  232. /// @param code A status code.
  233. /// @param msg A string representation of the message to be added to the
  234. /// Status Code option.
  235. ///
  236. /// @return An object representing the Status Code option.
  237. Option6StatusCodePtr createStatusCode(const uint16_t code,
  238. const std::string& msg) {
  239. Option6StatusCodePtr opt_status(new Option6StatusCode(code, msg));
  240. return (opt_status);
  241. }
  242. /// @brief Adds Status Code option to the IA.
  243. ///
  244. /// @param code A status code value.
  245. /// @param msg A string representation of the message to be added to the
  246. /// Status Code option.
  247. void addStatusCode(const uint16_t code, const std::string& msg,
  248. Option6IAPtr& opt_ia) {
  249. opt_ia->addOption(createStatusCode(code, msg));
  250. }
  251. /// @brief Verifies if the DHCPv6 server processes DHCPv6 Client FQDN option
  252. /// as expected and subsequent interpretation of this processing when
  253. /// creating NCRs, if any should be created.
  254. ///
  255. /// This function simulates generation of the client's message holding FQDN.
  256. /// It then calls the server's @c Dhcpv6Srv::processClientFqdn option to
  257. /// generate server's response to the FQDN. This function returns the FQDN
  258. /// which should be appended to the server's response to the client.
  259. /// This function verifies that the FQDN option returned is correct
  260. /// Optionally, this function then proceeds to call createNameChangeRequests
  261. /// to verify if that method interprets the FQDN information properly.
  262. ///
  263. /// @param msg_type A type of the client's message.
  264. /// @param in_flags A value of flags field to be set for the FQDN carried
  265. /// in the client's message.
  266. /// @param in_domain_name A domain name to be carried in the client's FQDN
  267. /// option.
  268. /// @param in_domain_type A type of the domain name to be carried in the
  269. /// client's FQDM option (partial or fully qualified).
  270. /// @param exp_flags A value of flags expected in the FQDN sent by a server.
  271. /// @param exp_domain_name A domain name expected in the FQDN sent by a
  272. /// server.
  273. /// @param create_ncr_check if true, calls createNameChangeRequests method
  274. /// and tests the outcome.
  275. /// @param exp_fwd indicates whether or not a forward change is expected
  276. /// @param exp_fwd indicates whether or not a reverse change is expected
  277. void testFqdn(const uint16_t msg_type,
  278. const uint8_t in_flags,
  279. const std::string& in_domain_name,
  280. const Option6ClientFqdn::DomainNameType in_domain_type,
  281. const uint8_t exp_flags,
  282. const std::string& exp_domain_name,
  283. const bool create_ncr_check,
  284. const ExpFwd& exp_fwd = ExpFwd(true),
  285. const ExpRev& exp_rev = ExpRev(true)) {
  286. Pkt6Ptr question = generateMessage(msg_type,
  287. in_flags,
  288. in_domain_name,
  289. in_domain_type,
  290. true);
  291. ASSERT_TRUE(getClientFqdnOption(question));
  292. Pkt6Ptr answer = generateMessageWithIds(msg_type == DHCPV6_SOLICIT
  293. ? DHCPV6_ADVERTISE :
  294. DHCPV6_REPLY);
  295. // Create three IAs, each having different address.
  296. addIA(1234, IOAddress("2001:db8:1::1"), answer);
  297. AllocEngine::ClientContext6 ctx;
  298. ASSERT_NO_THROW(srv_->processClientFqdn(question, answer, ctx));
  299. Option6ClientFqdnPtr answ_fqdn = boost::dynamic_pointer_cast<
  300. Option6ClientFqdn>(answer->getOption(D6O_CLIENT_FQDN));
  301. ASSERT_TRUE(answ_fqdn);
  302. const bool flag_n = (exp_flags & Option6ClientFqdn::FLAG_N) != 0;
  303. const bool flag_s = (exp_flags & Option6ClientFqdn::FLAG_S) != 0;
  304. const bool flag_o = (exp_flags & Option6ClientFqdn::FLAG_O) != 0;
  305. EXPECT_EQ(flag_n, answ_fqdn->getFlag(Option6ClientFqdn::FLAG_N));
  306. EXPECT_EQ(flag_s, answ_fqdn->getFlag(Option6ClientFqdn::FLAG_S));
  307. EXPECT_EQ(flag_o, answ_fqdn->getFlag(Option6ClientFqdn::FLAG_O));
  308. EXPECT_EQ(exp_domain_name, answ_fqdn->getDomainName());
  309. // If server is configured to generate full FQDN for a client, and/or
  310. // client sent empty FQDN the expected result of the processing by
  311. // processClientFqdn is an empty, partial FQDN. This is an indication
  312. // for the code which performs lease allocation that the FQDN has to
  313. // be generated from the lease address.
  314. if (exp_domain_name.empty()) {
  315. EXPECT_EQ(Option6ClientFqdn::PARTIAL,
  316. answ_fqdn->getDomainNameType());
  317. } else {
  318. EXPECT_EQ(Option6ClientFqdn::FULL, answ_fqdn->getDomainNameType());
  319. }
  320. if (create_ncr_check) {
  321. // Context flags are normally set during lease allocation. Since that
  322. // hasn't occurred we'll set them here to match the expected values.
  323. // Call createNameChangeRequests
  324. ctx.fwd_dns_update_ = exp_fwd.value_;
  325. ctx.rev_dns_update_ = exp_rev.value_;
  326. ASSERT_NO_THROW(srv_->createNameChangeRequests(answer, ctx));
  327. if (exp_fwd.value_ || exp_rev.value_) {
  328. // Should have created 1 NCR.
  329. NameChangeRequestPtr ncr;
  330. ASSERT_EQ(1, d2_mgr_.getQueueSize());
  331. ASSERT_NO_THROW(ncr = d2_mgr_.peekAt(0));
  332. ASSERT_TRUE(ncr);
  333. EXPECT_EQ(dhcp_ddns::CHG_ADD, ncr->getChangeType());
  334. EXPECT_EQ(exp_fwd.value_, ncr->isForwardChange());
  335. EXPECT_EQ(exp_rev.value_, ncr->isReverseChange());
  336. ASSERT_NO_THROW(d2_mgr_.runReadyIO());
  337. } else {
  338. // Should not have created any NCRs.
  339. EXPECT_EQ(0, d2_mgr_.getQueueSize());
  340. }
  341. }
  342. }
  343. // Test that the server processes the FQDN option (or lack thereof)
  344. // in a client request correctly, according to the replace-client-name
  345. // mode configuration parameter.
  346. //
  347. // @param mode - value to use for replace-client-name mode
  348. //
  349. // @param client_name_flag - specifies whether or not the client request
  350. // should contain a hostname option
  351. // @param exp_replacement_flag - specifies whether or not the server is
  352. // expected to replace (or supply) the FQDN/name in its response
  353. void testReplaceClientNameMode(const char* mode,
  354. enum ClientNameFlag client_name_flag,
  355. enum ReplacementFlag exp_replacement_flag) {
  356. // Configuration "template" with a replaceable mode parameter
  357. const char* config_template =
  358. "{ \"interfaces-config\": { \n"
  359. " \"interfaces\": [ \"eth0\" ] \n"
  360. "}, \n"
  361. "\"valid-lifetime\": 4000, \n"
  362. "\"preferred-lifetime\": 3000, \n"
  363. "\"rebind-timer\": 2000, \n"
  364. "\"renew-timer\": 1000, \n"
  365. "\"subnet6\": [ { \n"
  366. " \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ], \n"
  367. " \"subnet\": \"2001:db8:1::/48\", \n"
  368. " \"interface-id\": \"\", \n"
  369. " \"interface\": \"eth0\" \n"
  370. " } ], \n"
  371. "\"dhcp-ddns\": { \n"
  372. "\"enable-updates\": true, \n"
  373. "\"qualifying-suffix\": \"fake-suffix.isc.org.\", \n"
  374. "\"replace-client-name\": \"%s\" \n"
  375. "}} \n";
  376. // Create the configuration and configure the server
  377. char config_buf[1024];
  378. sprintf(config_buf, config_template, mode);
  379. configure(config_buf, *srv_);
  380. // Build our client packet
  381. Pkt6Ptr query;
  382. if (client_name_flag == CLIENT_NAME_PRESENT) {
  383. query = generateMessage(DHCPV6_SOLICIT, Option6ClientFqdn::FLAG_S,
  384. "my.example.com.", Option6ClientFqdn::FULL,
  385. true);
  386. } else {
  387. query = generateMessageWithIds(DHCPV6_SOLICIT);
  388. }
  389. Pkt6Ptr answer = generateMessageWithIds(DHCPV6_ADVERTISE);
  390. AllocEngine::ClientContext6 ctx;
  391. ASSERT_NO_THROW(srv_->processClientFqdn(query, answer, ctx));
  392. Option6ClientFqdnPtr answ_fqdn = boost::dynamic_pointer_cast<
  393. Option6ClientFqdn>(answer->getOption(D6O_CLIENT_FQDN));
  394. // Verify the contents (or lack thereof) of the FQDN
  395. if (exp_replacement_flag == NAME_REPLACED) {
  396. ASSERT_TRUE(answ_fqdn);
  397. EXPECT_TRUE(answ_fqdn->getDomainName().empty());
  398. EXPECT_EQ(Option6ClientFqdn::PARTIAL,
  399. answ_fqdn->getDomainNameType());
  400. } else {
  401. if (client_name_flag == CLIENT_NAME_PRESENT) {
  402. ASSERT_TRUE(answ_fqdn);
  403. EXPECT_EQ("my.example.com.", answ_fqdn->getDomainName());
  404. EXPECT_EQ(Option6ClientFqdn::FULL,
  405. answ_fqdn->getDomainNameType());
  406. } else {
  407. ASSERT_FALSE(answ_fqdn);
  408. }
  409. }
  410. }
  411. /// @brief Tests that the client's message holding an FQDN is processed
  412. /// and that lease is acquired.
  413. ///
  414. /// @param msg_type A type of the client's message.
  415. /// @param hostname A domain name in the client's FQDN.
  416. /// @param client_flags A bitmask of the client FQDN flags
  417. /// @param include_oro A boolean value which indicates whether the ORO
  418. /// option should be included in the client's message (if true) or not
  419. /// (if false). In the former case, the function will expect that server
  420. /// responds with the FQDN option. In the latter case, the function expects
  421. /// that the server doesn't respond with the FQDN.
  422. void testProcessMessage(const uint8_t msg_type,
  423. const std::string& hostname,
  424. const std::string& exp_hostname,
  425. const uint8_t client_flags =
  426. Option6ClientFqdn::FLAG_S,
  427. const IOAddress& expected_address = IOAddress("2001:db8:1:1::dead:beef"),
  428. const bool include_oro = true) {
  429. // Create a message of a specified type, add server id and
  430. // FQDN option.
  431. OptionPtr srvid = srv_->getServerID();
  432. // Set the appropriate FQDN type. It must be partial if hostname is
  433. // empty.
  434. Option6ClientFqdn::DomainNameType fqdn_type = (hostname.empty() ?
  435. Option6ClientFqdn::PARTIAL : Option6ClientFqdn::FULL);
  436. Pkt6Ptr req = generateMessage(msg_type, client_flags,
  437. hostname, fqdn_type, include_oro, srvid);
  438. // For different client's message types we have to invoke different
  439. // functions to generate response.
  440. Pkt6Ptr reply;
  441. if (msg_type == DHCPV6_SOLICIT) {
  442. ASSERT_NO_THROW(reply = srv_->processSolicit(req));
  443. } else if (msg_type == DHCPV6_REQUEST) {
  444. ASSERT_NO_THROW(reply = srv_->processRequest(req));
  445. } else if (msg_type == DHCPV6_RENEW) {
  446. ASSERT_NO_THROW(reply = srv_->processRenew(req));
  447. } else if (msg_type == DHCPV6_RELEASE) {
  448. // For Release no lease will be acquired so we have to leave
  449. // function here.
  450. ASSERT_NO_THROW(reply = srv_->processRelease(req));
  451. return;
  452. } else {
  453. // We are not interested in testing other message types.
  454. return;
  455. }
  456. // For Solicit, we will get different message type obviously.
  457. if (msg_type == DHCPV6_SOLICIT) {
  458. checkResponse(reply, DHCPV6_ADVERTISE, 1234);
  459. } else {
  460. checkResponse(reply, DHCPV6_REPLY, 1234);
  461. }
  462. // Check verify that IA_NA is correct.
  463. Option6IAAddrPtr addr =
  464. checkIA_NA(reply, 234, subnet_->getT1(), subnet_->getT2());
  465. ASSERT_TRUE(addr);
  466. // Check that we have got the address we requested.
  467. checkIAAddr(addr, expected_address,
  468. Lease::TYPE_NA);
  469. if (msg_type != DHCPV6_SOLICIT) {
  470. // Check that the lease exists.
  471. Lease6Ptr lease =
  472. checkLease(duid_, reply->getOption(D6O_IA_NA), addr);
  473. ASSERT_TRUE(lease);
  474. EXPECT_EQ(exp_hostname, lease->hostname_);
  475. }
  476. // The Client FQDN option should be always present in the server's
  477. // response, regardless if requested using ORO or not.
  478. Option6ClientFqdnPtr fqdn;
  479. ASSERT_TRUE(fqdn = boost::dynamic_pointer_cast<
  480. Option6ClientFqdn>(reply->getOption(D6O_CLIENT_FQDN)));
  481. EXPECT_EQ(exp_hostname, fqdn->getDomainName());
  482. }
  483. /// @brief Verify that NameChangeRequest holds valid values.
  484. ///
  485. /// This function picks first NameChangeRequest from the internal server's
  486. /// queue and checks that it holds valid parameters. The NameChangeRequest
  487. /// is removed from the queue.
  488. ///
  489. /// @param type An expected type of the NameChangeRequest (Add or Remove).
  490. /// @param reverse An expected setting of the reverse update flag.
  491. /// @param forward An expected setting of the forward udpate flag.
  492. /// @param addr A string representation of the IPv6 address held in the
  493. /// NameChangeRequest.
  494. /// @param dhcid An expected DHCID value.
  495. /// @note This value is the value that is produced by
  496. /// dhcp_ddns::D2Dhcid::createDigest() with the appropriate arguments. This
  497. /// method uses encryption tools to produce the value which cannot be
  498. /// easily duplicated by hand. It is more or less necessary to generate
  499. /// these values programmatically and place them here. Should the
  500. /// underlying implementation of createDigest() change these test values
  501. /// will likely need to be updated as well.
  502. /// @param expires A timestamp when the lease associated with the
  503. /// NameChangeRequest expires.
  504. /// @param len A valid lifetime of the lease associated with the
  505. /// NameChangeRequest.
  506. /// @param fqdn The expected string value of the FQDN, if blank the
  507. /// check is skipped
  508. void verifyNameChangeRequest(const isc::dhcp_ddns::NameChangeType type,
  509. const bool reverse, const bool forward,
  510. const std::string& addr,
  511. const std::string& dhcid,
  512. const uint64_t expires,
  513. const uint16_t len,
  514. const std::string& fqdn="") {
  515. NameChangeRequestPtr ncr;
  516. ASSERT_NO_THROW(ncr = d2_mgr_.peekAt(0));
  517. ASSERT_TRUE(ncr);
  518. EXPECT_EQ(type, ncr->getChangeType());
  519. EXPECT_EQ(forward, ncr->isForwardChange());
  520. EXPECT_EQ(reverse, ncr->isReverseChange());
  521. EXPECT_EQ(addr, ncr->getIpAddress());
  522. EXPECT_EQ(dhcid, ncr->getDhcid().toStr());
  523. EXPECT_EQ(expires, ncr->getLeaseExpiresOn());
  524. EXPECT_EQ(len, ncr->getLeaseLength());
  525. EXPECT_EQ(isc::dhcp_ddns::ST_NEW, ncr->getStatus());
  526. if (! fqdn.empty()) {
  527. EXPECT_EQ(fqdn, ncr->getFqdn());
  528. }
  529. // Process the message off the queue
  530. ASSERT_NO_THROW(d2_mgr_.runReadyIO());
  531. }
  532. /// @brief Updates inherited subnet and pool members
  533. ///
  534. /// Hack added to set subnet_ and pool_ members that are buried into lower
  535. /// level tests such as checkLease(), so one can use "configure" functionality
  536. /// rather than hand-building configured objects
  537. /// @param subnet_idx Element index of the desired subnet
  538. /// @param pool_idx Element index of the desired pool within the desired subnet
  539. /// @param type lease type of desired pool
  540. ///
  541. void setSubnetAndPool(int subnet_idx, int pool_idx, Lease::Type type) {
  542. ConstCfgSubnets6Ptr subnets = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6();
  543. ASSERT_TRUE(subnets);
  544. const Subnet6Collection* subnet_col = subnets->getAll();
  545. ASSERT_EQ(subnet_idx + 1, subnet_col->size());
  546. subnet_ = subnet_col->at(subnet_idx);
  547. ASSERT_TRUE(subnet_);
  548. const PoolCollection& pool_col = subnet_->getPools(type);
  549. ASSERT_EQ(pool_idx + 1, pool_col.size());
  550. PoolPtr pool = (subnet_->getPools(type)).at(pool_idx);
  551. ASSERT_TRUE(pool);
  552. pool_ = boost::dynamic_pointer_cast<Pool6>(pool);
  553. ASSERT_TRUE(pool);
  554. }
  555. // Holds a lease used by a test.
  556. Lease6Ptr lease_;
  557. };
  558. // A set of tests verifying server's behavior when it receives the DHCPv6
  559. // Client Fqdn Option.
  560. // Test server's response when client requests that server performs AAAA update.
  561. TEST_F(FqdnDhcpv6SrvTest, serverAAAAUpdate) {
  562. testFqdn(DHCPV6_SOLICIT, Option6ClientFqdn::FLAG_S,
  563. "myhost.example.com",
  564. Option6ClientFqdn::FULL, Option6ClientFqdn::FLAG_S,
  565. "myhost.example.com.", true, ExpFwd(true), ExpRev(true));
  566. }
  567. // Test server's response when client provides partial domain-name and requests
  568. // that server performs AAAA update.
  569. TEST_F(FqdnDhcpv6SrvTest, serverAAAAUpdatePartialName) {
  570. testFqdn(DHCPV6_SOLICIT, Option6ClientFqdn::FLAG_S, "myhost",
  571. Option6ClientFqdn::PARTIAL, Option6ClientFqdn::FLAG_S,
  572. "myhost.example.com.", true, ExpFwd(true), ExpRev(true));
  573. }
  574. // Test server's response when client provides empty domain-name and requests
  575. // that server performs AAAA update.
  576. TEST_F(FqdnDhcpv6SrvTest, serverAAAAUpdateNoName) {
  577. testFqdn(DHCPV6_SOLICIT, Option6ClientFqdn::FLAG_S, "",
  578. Option6ClientFqdn::PARTIAL, Option6ClientFqdn::FLAG_S, "", false);
  579. }
  580. // Test server's response when client requests no DNS update.
  581. TEST_F(FqdnDhcpv6SrvTest, noUpdate) {
  582. testFqdn(DHCPV6_SOLICIT, Option6ClientFqdn::FLAG_N,
  583. "myhost.example.com",
  584. Option6ClientFqdn::FULL, Option6ClientFqdn::FLAG_N,
  585. "myhost.example.com.", true, ExpFwd(false), ExpRev(false));
  586. }
  587. // Test server's response when client requests no DNS update and
  588. // override-no-updates is true.
  589. TEST_F(FqdnDhcpv6SrvTest, overrideNoUpdate) {
  590. enableD2(OVERRIDE_NO_UPDATE);
  591. testFqdn(DHCPV6_SOLICIT, Option6ClientFqdn::FLAG_N,
  592. "myhost.example.com",
  593. Option6ClientFqdn::FULL,
  594. (Option6ClientFqdn::FLAG_S | Option6ClientFqdn::FLAG_O),
  595. "myhost.example.com.", true, ExpFwd(true), ExpRev(true));
  596. }
  597. // Test server's response when client requests that server delegates the AAAA
  598. // update to the client
  599. TEST_F(FqdnDhcpv6SrvTest, clientAAAAUpdate) {
  600. testFqdn(DHCPV6_SOLICIT, 0, "myhost.example.com.",
  601. Option6ClientFqdn::FULL,
  602. 0,
  603. "myhost.example.com.", true, ExpFwd(false), ExpRev(true));
  604. }
  605. // Test server's response when client requests that server delegates the AAAA
  606. // update to the client and this delegation is not allowed.
  607. TEST_F(FqdnDhcpv6SrvTest, clientAAAAUpdateNotAllowed) {
  608. enableD2(OVERRIDE_CLIENT_UPDATE);
  609. testFqdn(DHCPV6_SOLICIT, 0, "myhost.example.com.",
  610. Option6ClientFqdn::FULL,
  611. Option6ClientFqdn::FLAG_S | Option6ClientFqdn::FLAG_O,
  612. "myhost.example.com.", true, ExpFwd(true), ExpRev(true));
  613. }
  614. // Test that exception is thrown if supplied NULL answer packet when
  615. // creating NameChangeRequests.
  616. TEST_F(FqdnDhcpv6SrvTest, createNameChangeRequestsNoAnswer) {
  617. Pkt6Ptr answer;
  618. AllocEngine::ClientContext6 ctx;
  619. ctx.fwd_dns_update_ = ctx.rev_dns_update_ = true;
  620. EXPECT_THROW(srv_->createNameChangeRequests(answer, ctx),
  621. isc::Unexpected);
  622. }
  623. // Test that exception is thrown if supplied answer from the server
  624. // contains no DUID when creating NameChangeRequests.
  625. TEST_F(FqdnDhcpv6SrvTest, createNameChangeRequestsNoDUID) {
  626. Pkt6Ptr answer = Pkt6Ptr(new Pkt6(DHCPV6_REPLY, 1234));
  627. Option6ClientFqdnPtr fqdn = createClientFqdn(Option6ClientFqdn::FLAG_S,
  628. "myhost.example.com",
  629. Option6ClientFqdn::FULL);
  630. answer->addOption(fqdn);
  631. AllocEngine::ClientContext6 ctx;
  632. ctx.fwd_dns_update_ = ctx.rev_dns_update_ = true;
  633. EXPECT_THROW(srv_->createNameChangeRequests(answer, ctx), isc::Unexpected);
  634. }
  635. // Test no NameChangeRequests if Client FQDN is not added to the server's
  636. // response.
  637. TEST_F(FqdnDhcpv6SrvTest, createNameChangeRequestsNoFQDN) {
  638. // Create Reply message with Client Id and Server id.
  639. Pkt6Ptr answer = generateMessageWithIds(DHCPV6_REPLY);
  640. AllocEngine::ClientContext6 ctx;
  641. ctx.fwd_dns_update_ = ctx.rev_dns_update_ = true;
  642. ASSERT_NO_THROW(srv_->createNameChangeRequests(answer, ctx));
  643. // There should be no new NameChangeRequests.
  644. ASSERT_EQ(0, d2_mgr_.getQueueSize());
  645. }
  646. // Test that NameChangeRequests are not generated if an answer message
  647. // contains no addresses.
  648. TEST_F(FqdnDhcpv6SrvTest, createNameChangeRequestsNoAddr) {
  649. // Create Reply message with Client Id and Server id.
  650. Pkt6Ptr answer = generateMessageWithIds(DHCPV6_REPLY);
  651. // Add Client FQDN option.
  652. Option6ClientFqdnPtr fqdn = createClientFqdn(Option6ClientFqdn::FLAG_S,
  653. "myhost.example.com",
  654. Option6ClientFqdn::FULL);
  655. answer->addOption(fqdn);
  656. AllocEngine::ClientContext6 ctx;
  657. ctx.fwd_dns_update_ = ctx.rev_dns_update_ = true;
  658. ASSERT_NO_THROW(srv_->createNameChangeRequests(answer, ctx));
  659. // We didn't add any IAs, so there should be no NameChangeRequests in the
  660. // queue.
  661. ASSERT_EQ(0, d2_mgr_.getQueueSize());
  662. }
  663. // Test that exactly one NameChangeRequest is created as a result of processing
  664. // the answer message which holds 3 IAs and when FQDN is specified.
  665. TEST_F(FqdnDhcpv6SrvTest, createNameChangeRequests) {
  666. // Create Reply message with Client Id and Server id.
  667. Pkt6Ptr answer = generateMessageWithIds(DHCPV6_REPLY);
  668. // Create three IAs, each having different address.
  669. addIA(1234, IOAddress("2001:db8:1::1"), answer);
  670. addIA(2345, IOAddress("2001:db8:1::2"), answer);
  671. addIA(3456, IOAddress("2001:db8:1::3"), answer);
  672. // Use domain name in upper case. It should be converted to lower-case
  673. // before DHCID is calculated. So, we should get the same result as if
  674. // we typed domain name in lower-case.
  675. Option6ClientFqdnPtr fqdn = createClientFqdn(Option6ClientFqdn::FLAG_S,
  676. "MYHOST.EXAMPLE.COM",
  677. Option6ClientFqdn::FULL);
  678. answer->addOption(fqdn);
  679. // Create NameChangeRequest for the first allocated address.
  680. AllocEngine::ClientContext6 ctx;
  681. ctx.fwd_dns_update_ = ctx.rev_dns_update_ = true;
  682. ASSERT_NO_THROW(srv_->createNameChangeRequests(answer, ctx));
  683. ASSERT_EQ(1, d2_mgr_.getQueueSize());
  684. // Verify that NameChangeRequest is correct.
  685. verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
  686. "2001:db8:1::1",
  687. "000201415AA33D1187D148275136FA30300478"
  688. "FAAAA3EBD29826B5C907B2C9268A6F52",
  689. 0, 500);
  690. }
  691. // Checks that NameChangeRequests to add entries are not
  692. // created when ddns updates are disabled.
  693. TEST_F(FqdnDhcpv6SrvTest, noAddRequestsWhenDisabled) {
  694. // Disable DDNS udpates.
  695. disableD2();
  696. // Create Reply message with Client Id and Server id.
  697. Pkt6Ptr answer = generateMessageWithIds(DHCPV6_REPLY);
  698. // Create three IAs, each having different address.
  699. addIA(1234, IOAddress("2001:db8:1::1"), answer);
  700. // Use domain name in upper case. It should be converted to lower-case
  701. // before DHCID is calculated. So, we should get the same result as if
  702. // we typed domain name in lower-case.
  703. Option6ClientFqdnPtr fqdn = createClientFqdn(Option6ClientFqdn::FLAG_S,
  704. "MYHOST.EXAMPLE.COM",
  705. Option6ClientFqdn::FULL);
  706. answer->addOption(fqdn);
  707. // An attempt to send a NCR would throw.
  708. AllocEngine::ClientContext6 ctx;
  709. ctx.fwd_dns_update_ = ctx.rev_dns_update_ = true;
  710. ASSERT_NO_THROW(srv_->createNameChangeRequests(answer, ctx));
  711. }
  712. // Test creation of the NameChangeRequest to remove both forward and reverse
  713. // mapping for the given lease.
  714. TEST_F(FqdnDhcpv6SrvTest, createRemovalNameChangeRequestFwdRev) {
  715. lease_->fqdn_fwd_ = true;
  716. lease_->fqdn_rev_ = true;
  717. // Part of the domain name is in upper case, to test that it gets converted
  718. // to lower case before DHCID is computed. So, we should get the same DHCID
  719. // as if we typed domain-name in lower case.
  720. lease_->hostname_ = "MYHOST.example.com.";
  721. ASSERT_NO_THROW(queueNCR(CHG_REMOVE, lease_));
  722. ASSERT_EQ(1, d2_mgr_.getQueueSize());
  723. verifyNameChangeRequest(isc::dhcp_ddns::CHG_REMOVE, true, true,
  724. "2001:db8:1::1",
  725. "000201415AA33D1187D148275136FA30300478"
  726. "FAAAA3EBD29826B5C907B2C9268A6F52",
  727. lease_->cltt_ + lease_->valid_lft_, 502);
  728. }
  729. // Checks that calling queueNCR would not result in error if DDNS updates are
  730. // disabled.
  731. TEST_F(FqdnDhcpv6SrvTest, noRemovalsWhenDisabled) {
  732. // Disable DDNS updates.
  733. disableD2();
  734. lease_->fqdn_fwd_ = true;
  735. lease_->fqdn_rev_ = true;
  736. // Part of the domain name is in upper case, to test that it gets converted
  737. // to lower case before DHCID is computed. So, we should get the same DHCID
  738. // as if we typed domain-name in lower case.
  739. lease_->hostname_ = "MYHOST.example.com.";
  740. // When DDNS is disabled an attempt to send a request should not throw, but
  741. // nothing is generated. Unfortunately, we can't see if anything get
  742. // generated because getting anything from the queue when DDNS is disabled
  743. // would result in exception.
  744. ASSERT_NO_THROW(queueNCR(CHG_REMOVE, lease_));
  745. }
  746. // Test creation of the NameChangeRequest to remove reverse mapping for the
  747. // given lease.
  748. TEST_F(FqdnDhcpv6SrvTest, createRemovalNameChangeRequestRev) {
  749. lease_->fqdn_fwd_ = false;
  750. lease_->fqdn_rev_ = true;
  751. lease_->hostname_ = "myhost.example.com.";
  752. ASSERT_NO_THROW(queueNCR(CHG_REMOVE, lease_));
  753. ASSERT_EQ(1, d2_mgr_.getQueueSize());
  754. verifyNameChangeRequest(isc::dhcp_ddns::CHG_REMOVE, true, false,
  755. "2001:db8:1::1",
  756. "000201415AA33D1187D148275136FA30300478"
  757. "FAAAA3EBD29826B5C907B2C9268A6F52",
  758. lease_->cltt_ + lease_->valid_lft_, 502);
  759. }
  760. // Test that NameChangeRequest to remove DNS records is not generated when
  761. // neither forward nor reverse DNS update has been performed for a lease.
  762. TEST_F(FqdnDhcpv6SrvTest, createRemovalNameChangeRequestNoUpdate) {
  763. lease_->fqdn_fwd_ = false;
  764. lease_->fqdn_rev_ = false;
  765. ASSERT_NO_THROW(queueNCR(CHG_REMOVE, lease_));
  766. ASSERT_EQ(0, d2_mgr_.getQueueSize());
  767. }
  768. // Test that NameChangeRequest is not generated if the hostname hasn't been
  769. // specified for a lease for which forward and reverse mapping has been set.
  770. TEST_F(FqdnDhcpv6SrvTest, createRemovalNameChangeRequestNoHostname) {
  771. lease_->fqdn_fwd_ = true;
  772. lease_->fqdn_rev_ = true;
  773. lease_->hostname_ = "";
  774. Pkt6Ptr pkt(new Pkt6(DHCPREQUEST, 1234));
  775. ASSERT_NO_THROW(queueNCR(CHG_REMOVE, lease_));
  776. ASSERT_EQ(0, d2_mgr_.getQueueSize());
  777. }
  778. // Test that NameChangeRequest is not generated if the invalid hostname has
  779. // been specified for a lease for which forward and reverse mapping has been
  780. // set.
  781. TEST_F(FqdnDhcpv6SrvTest, createRemovalNameChangeRequestWrongHostname) {
  782. lease_->fqdn_fwd_ = true;
  783. lease_->fqdn_rev_ = true;
  784. lease_->hostname_ = "myhost..example.com.";
  785. ASSERT_NO_THROW(queueNCR(CHG_REMOVE, lease_));
  786. ASSERT_EQ(0, d2_mgr_.getQueueSize());
  787. }
  788. // Test that Advertise message generated in a response to the Solicit will
  789. // not result in generation if the NameChangeRequests.
  790. TEST_F(FqdnDhcpv6SrvTest, processSolicit) {
  791. // Create a Solicit message with FQDN option and generate server's
  792. // response using processSolicit function.
  793. testProcessMessage(DHCPV6_SOLICIT, "myhost.example.com",
  794. "myhost.example.com.");
  795. ASSERT_EQ(0, d2_mgr_.getQueueSize());
  796. }
  797. // Test that client may send two requests, each carrying FQDN option with
  798. // a different domain-name. Server should use existing lease for the second
  799. // request but modify the DNS entries for the lease according to the contents
  800. // of the FQDN sent in the second request.
  801. TEST_F(FqdnDhcpv6SrvTest, processTwoRequestsDiffFqdn) {
  802. // Create a Request message with FQDN option and generate server's
  803. // response using processRequest function. This will result in the
  804. // creation of a new lease and the appropriate NameChangeRequest
  805. // to add both reverse and forward mapping to DNS.
  806. testProcessMessage(DHCPV6_REQUEST, "myhost.example.com",
  807. "myhost.example.com.");
  808. // The lease should have been recorded in the database.
  809. lease_ = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
  810. IOAddress("2001:db8:1:1::dead:beef"));
  811. ASSERT_TRUE(lease_);
  812. ASSERT_EQ(1, d2_mgr_.getQueueSize());
  813. verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
  814. "2001:db8:1:1::dead:beef",
  815. "000201415AA33D1187D148275136FA30300478"
  816. "FAAAA3EBD29826B5C907B2C9268A6F52",
  817. 0, 4000);
  818. // Client may send another request message with a new domain-name. In this
  819. // case the same lease will be returned. The existing DNS entry needs to
  820. // be replaced with a new one. Server should determine that the different
  821. // FQDN has been already added to the DNS. As a result, the old DNS
  822. // entries should be removed and the entries for the new domain-name
  823. // should be added. Therefore, we expect two NameChangeRequests. One to
  824. // remove the existing entries, one to add new entries.
  825. testProcessMessage(DHCPV6_REQUEST, "otherhost.example.com",
  826. "otherhost.example.com.");
  827. ASSERT_EQ(2, d2_mgr_.getQueueSize());
  828. verifyNameChangeRequest(isc::dhcp_ddns::CHG_REMOVE, true, true,
  829. "2001:db8:1:1::dead:beef",
  830. "000201415AA33D1187D148275136FA30300478"
  831. "FAAAA3EBD29826B5C907B2C9268A6F52",
  832. lease_->cltt_ + lease_->valid_lft_, 4000);
  833. verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
  834. "2001:db8:1:1::dead:beef",
  835. "000201D422AA463306223D269B6CB7AFE7AAD265FC"
  836. "EA97F93623019B2E0D14E5323D5A",
  837. 0, 4000);
  838. }
  839. // Test that client may send two requests, each carrying FQDN option with
  840. // the same domain-name. Server should use existing lease for the second
  841. // request and not modify the DNS entries.
  842. TEST_F(FqdnDhcpv6SrvTest, processTwoRequestsSameFqdn) {
  843. // Create a Request message with FQDN option and generate server's
  844. // response using processRequest function. This will result in the
  845. // creation of a new lease and the appropriate NameChangeRequest
  846. // to add both reverse and forward mapping to DNS.
  847. testProcessMessage(DHCPV6_REQUEST, "myhost.example.com",
  848. "myhost.example.com.");
  849. // The lease should have been recorded in the database.
  850. lease_ = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
  851. IOAddress("2001:db8:1:1::dead:beef"));
  852. ASSERT_TRUE(lease_);
  853. ASSERT_EQ(1, d2_mgr_.getQueueSize());
  854. verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
  855. "2001:db8:1:1::dead:beef",
  856. "000201415AA33D1187D148275136FA30300478"
  857. "FAAAA3EBD29826B5C907B2C9268A6F52",
  858. 0, 4000);
  859. // Client may send another request message with a same domain-name. In this
  860. // case the same lease will be returned. The existing DNS entry should be
  861. // left alone, so we expect no NameChangeRequests queued..
  862. testProcessMessage(DHCPV6_REQUEST, "myhost.example.com",
  863. "myhost.example.com.");
  864. ASSERT_EQ(0, d2_mgr_.getQueueSize());
  865. }
  866. // Test that NameChangeRequest is not generated when Solicit message is sent.
  867. // The Solicit is here sent after a lease has been allocated for a client.
  868. // The Solicit conveys a different hostname which would trigger updates to
  869. // DNS if the Request was sent instead of Soicit. The code should differentiate
  870. // behavior depending whether Solicit or Request is sent.
  871. TEST_F(FqdnDhcpv6SrvTest, processRequestSolicit) {
  872. // Create a Request message with FQDN option and generate server's
  873. // response using processRequest function. This will result in the
  874. // creation of a new lease and the appropriate NameChangeRequest
  875. // to add both reverse and forward mapping to DNS.
  876. testProcessMessage(DHCPV6_REQUEST, "myhost.example.com",
  877. "myhost.example.com.");
  878. ASSERT_EQ(1, d2_mgr_.getQueueSize());
  879. verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
  880. "2001:db8:1:1::dead:beef",
  881. "000201415AA33D1187D148275136FA30300478"
  882. "FAAAA3EBD29826B5C907B2C9268A6F52",
  883. 0, 4000);
  884. // When the returning client sends Solicit the code should never generate
  885. // NameChangeRequest and preserve existing DNS entries for the client.
  886. // The NameChangeRequest should only be generated when a client sends
  887. // Request or Renew.
  888. testProcessMessage(DHCPV6_SOLICIT, "otherhost.example.com",
  889. "otherhost.example.com.");
  890. ASSERT_EQ(0, d2_mgr_.getQueueSize());
  891. }
  892. // Test that client may send Request followed by the Renew, both holding
  893. // FQDN options, but each option holding different domain-name. The Renew
  894. // should result in generation of the two NameChangeRequests, one to remove
  895. // DNS entry added previously when Request was processed, another one to
  896. // add a new entry for the FQDN held in the Renew.
  897. /// @todo: Fix will be available on trac3677
  898. TEST_F(FqdnDhcpv6SrvTest, processRequestRenewDiffFqdn) {
  899. // Create a Request message with FQDN option and generate server's
  900. // response using processRequest function. This will result in the
  901. // creation of a new lease and the appropriate NameChangeRequest
  902. // to add both reverse and forward mapping to DNS.
  903. testProcessMessage(DHCPV6_REQUEST, "myhost.example.com",
  904. "myhost.example.com.");
  905. // The lease should have been recorded in the database.
  906. lease_ = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
  907. IOAddress("2001:db8:1:1::dead:beef"));
  908. ASSERT_TRUE(lease_);
  909. ASSERT_EQ(1, d2_mgr_.getQueueSize());
  910. verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
  911. "2001:db8:1:1::dead:beef",
  912. "000201415AA33D1187D148275136FA30300478"
  913. "FAAAA3EBD29826B5C907B2C9268A6F52",
  914. 0, 4000);
  915. // Client may send Renew message with a new domain-name. In this
  916. // case the same lease will be returned. The existing DNS entry needs to
  917. // be replaced with a new one. Server should determine that the different
  918. // FQDN has been already added to the DNS. As a result, the old DNS
  919. // entries should be removed and the entries for the new domain-name
  920. // should be added. Therefore, we expect two NameChangeRequests. One to
  921. // remove the existing entries, one to add new entries.
  922. testProcessMessage(DHCPV6_RENEW, "otherhost.example.com",
  923. "otherhost.example.com.");
  924. ASSERT_EQ(2, d2_mgr_.getQueueSize());
  925. verifyNameChangeRequest(isc::dhcp_ddns::CHG_REMOVE, true, true,
  926. "2001:db8:1:1::dead:beef",
  927. "000201415AA33D1187D148275136FA30300478"
  928. "FAAAA3EBD29826B5C907B2C9268A6F52",
  929. lease_->cltt_ + lease_->valid_lft_, 4000);
  930. verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
  931. "2001:db8:1:1::dead:beef",
  932. "000201D422AA463306223D269B6CB7AFE7AAD265FC"
  933. "EA97F93623019B2E0D14E5323D5A",
  934. 0, 4000);
  935. }
  936. // Test that client may send Request followed by the Renew, both holding
  937. // FQDN options, but each option holding different domain-name. The Renew
  938. // should result in generation of the two NameChangeRequests, one to remove
  939. // DNS entry added previously when Request was processed, another one to
  940. // add a new entry for the FQDN held in the Renew.
  941. TEST_F(FqdnDhcpv6SrvTest, processRequestRenewSameFqdn) {
  942. // Create a Request message with FQDN option and generate server's
  943. // response using processRequest function. This will result in the
  944. // creation of a new lease and the appropriate NameChangeRequest
  945. // to add both reverse and forward mapping to DNS.
  946. testProcessMessage(DHCPV6_REQUEST, "myhost.example.com",
  947. "myhost.example.com.");
  948. ASSERT_EQ(1, d2_mgr_.getQueueSize());
  949. verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
  950. "2001:db8:1:1::dead:beef",
  951. "000201415AA33D1187D148275136FA30300478"
  952. "FAAAA3EBD29826B5C907B2C9268A6F52",
  953. 0, 4000);
  954. ASSERT_EQ(0, d2_mgr_.getQueueSize());
  955. // Client may send Renew message with a same domain-name. In this
  956. // case the same lease will be returned. No DNS updates should be
  957. // required, so the NCR queue should be empty.
  958. testProcessMessage(DHCPV6_RENEW, "myhost.example.com",
  959. "myhost.example.com.");
  960. ASSERT_EQ(0, d2_mgr_.getQueueSize());
  961. }
  962. // Tests that renewals using the same domain name but differing values for
  963. // the directional update flags result in NCRs or not, accordingly.
  964. // If the new leases's flags are the same as the previous lease's flags,
  965. // then no requests should be generated. If at lease one of the new lease's
  966. // flags differ from the previous lease, then:
  967. // A: A removal NCR should be created based on the previous leases's flags
  968. // if at least one of those flags are true
  969. // B: An add NCR should be created based on the new lease's flags, if at
  970. // least one of those flags are true
  971. TEST_F(FqdnDhcpv6SrvTest, processRequestRenewFqdnFlags) {
  972. // Create a Request message with FQDN option but with N flag = 1, which
  973. // means no updates should be done. This should result in no NCRs.
  974. testProcessMessage(DHCPV6_REQUEST, "myhost.example.com",
  975. "myhost.example.com.", Option6ClientFqdn::FLAG_N);
  976. // Queue should be empty.
  977. ASSERT_EQ(0, d2_mgr_.getQueueSize());
  978. // Now renew with Both N and S = 0. This means the server should only
  979. // do reverse updates and should result in a reverse-only NCR.
  980. testProcessMessage(DHCPV6_RENEW, "myhost.example.com",
  981. "myhost.example.com.", 0);
  982. // We should a only have reverse-only ADD, no remove.
  983. ASSERT_EQ(1, d2_mgr_.getQueueSize());
  984. verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, false,
  985. "2001:db8:1:1::dead:beef",
  986. "000201415AA33D1187D148275136FA30300478"
  987. "FAAAA3EBD29826B5C907B2C9268A6F52",
  988. 0, 4000);
  989. // Renew again with the same flags, this should not generate any NCRs.
  990. testProcessMessage(DHCPV6_RENEW, "myhost.example.com",
  991. "myhost.example.com.", 0);
  992. // Queue should be empty.
  993. ASSERT_EQ(0, d2_mgr_.getQueueSize());
  994. // Renew with both N and S flags = 0. This tells the server to update
  995. // both directions, which should change forward flag to true. This should
  996. // generate a reverse only remove and a dual add.
  997. testProcessMessage(DHCPV6_RENEW, "myhost.example.com",
  998. "myhost.example.com.", Option6ClientFqdn::FLAG_S);
  999. // We need the lease for the expiration value.
  1000. lease_ = LeaseMgrFactory::
  1001. instance().getLease6(Lease::TYPE_NA,
  1002. IOAddress("2001:db8:1:1::dead:beef"));
  1003. ASSERT_TRUE(lease_);
  1004. // We should have two NCRs, one remove and one add.
  1005. ASSERT_EQ(2, d2_mgr_.getQueueSize());
  1006. verifyNameChangeRequest(isc::dhcp_ddns::CHG_REMOVE, true, false,
  1007. "2001:db8:1:1::dead:beef",
  1008. "000201415AA33D1187D148275136FA30300478"
  1009. "FAAAA3EBD29826B5C907B2C9268A6F52",
  1010. lease_->cltt_ + lease_->valid_lft_, 4000);
  1011. verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
  1012. "2001:db8:1:1::dead:beef",
  1013. "000201415AA33D1187D148275136FA30300478"
  1014. "FAAAA3EBD29826B5C907B2C9268A6F52",
  1015. 0, 4000);
  1016. // Lastly, we renew with the N flag = 1 (which means no updates) so we
  1017. // should have a dual direction remove NCR but NO add NCR.
  1018. testProcessMessage(DHCPV6_RENEW, "myhost.example.com",
  1019. "myhost.example.com.", Option6ClientFqdn::FLAG_N);
  1020. // We should only have the removal NCR.
  1021. ASSERT_EQ(1, d2_mgr_.getQueueSize());
  1022. verifyNameChangeRequest(isc::dhcp_ddns::CHG_REMOVE, true, true,
  1023. "2001:db8:1:1::dead:beef",
  1024. "000201415AA33D1187D148275136FA30300478"
  1025. "FAAAA3EBD29826B5C907B2C9268A6F52",
  1026. lease_->cltt_ + lease_->valid_lft_, 4000);
  1027. }
  1028. TEST_F(FqdnDhcpv6SrvTest, processRequestRelease) {
  1029. // Create a Request message with FQDN option and generate server's
  1030. // response using processRequest function. This will result in the
  1031. // creation of a new lease and the appropriate NameChangeRequest
  1032. // to add both reverse and forward mapping to DNS.
  1033. testProcessMessage(DHCPV6_REQUEST, "myhost.example.com",
  1034. "myhost.example.com.");
  1035. // The lease should have been recorded in the database.
  1036. lease_ = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
  1037. IOAddress("2001:db8:1:1::dead:beef"));
  1038. ASSERT_TRUE(lease_);
  1039. ASSERT_EQ(1, d2_mgr_.getQueueSize());
  1040. verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
  1041. "2001:db8:1:1::dead:beef",
  1042. "000201415AA33D1187D148275136FA30300478"
  1043. "FAAAA3EBD29826B5C907B2C9268A6F52",
  1044. 0, 4000);
  1045. // Client may send Release message. In this case the lease should be
  1046. // removed and all existing DNS entries for this lease should also
  1047. // be removed. Therefore, we expect that single NameChangeRequest to
  1048. // remove DNS entries is generated.
  1049. testProcessMessage(DHCPV6_RELEASE, "otherhost.example.com",
  1050. "otherhost.example.com.");
  1051. ASSERT_EQ(1, d2_mgr_.getQueueSize());
  1052. verifyNameChangeRequest(isc::dhcp_ddns::CHG_REMOVE, true, true,
  1053. "2001:db8:1:1::dead:beef",
  1054. "000201415AA33D1187D148275136FA30300478"
  1055. "FAAAA3EBD29826B5C907B2C9268A6F52",
  1056. lease_->cltt_ + lease_->valid_lft_, 4000);
  1057. }
  1058. // Checks that the server include DHCPv6 Client FQDN option in its
  1059. // response even when client doesn't request this option using ORO.
  1060. TEST_F(FqdnDhcpv6SrvTest, processRequestWithoutFqdn) {
  1061. // The last parameter disables use of the ORO to request FQDN option
  1062. // In this case, we expect that the FQDN option will not be included
  1063. // in the server's response. The testProcessMessage will check that.
  1064. testProcessMessage(DHCPV6_REQUEST, "myhost.example.com",
  1065. "myhost.example.com.", Option6ClientFqdn::FLAG_S,
  1066. IOAddress("2001:db8:1:1::dead:beef"), false);
  1067. ASSERT_EQ(1, d2_mgr_.getQueueSize());
  1068. verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
  1069. "2001:db8:1:1::dead:beef",
  1070. "000201415AA33D1187D148275136FA30300478"
  1071. "FAAAA3EBD29826B5C907B2C9268A6F52",
  1072. 0, 4000);
  1073. }
  1074. // Checks that FQDN is generated from an ip address, when client sends an empty
  1075. // FQDN.
  1076. TEST_F(FqdnDhcpv6SrvTest, processRequestEmptyFqdn) {
  1077. testProcessMessage(DHCPV6_REQUEST, "",
  1078. "myhost-2001-db8-1-1--dead-beef.example.com.",
  1079. Option6ClientFqdn::FLAG_S,
  1080. IOAddress("2001:db8:1:1::dead:beef"), false);
  1081. ASSERT_EQ(1, d2_mgr_.getQueueSize());
  1082. verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
  1083. "2001:db8:1:1::dead:beef",
  1084. "000201C905E54BE12DE6AF92ADE72752B9F362"
  1085. "13B5A8BC9D217548CD739B4CF31AFB1B",
  1086. 0, 4000);
  1087. }
  1088. // Checks that when the server reuses expired lease, the NameChangeRequest
  1089. // is generated to remove the DNS mapping for the expired lease and second
  1090. // NameChangeRequest to add a DNS mapping for a new lease.
  1091. TEST_F(FqdnDhcpv6SrvTest, processRequestReuseExpiredLease) {
  1092. // This address will be used throughout the test.
  1093. IOAddress addr("2001:db8:1:1::dead:beef");
  1094. // We are going to configure a subnet with a pool that consists of
  1095. // exactly one address. This address will be handed out to the
  1096. // client, will get expired and then be reused.
  1097. CfgMgr::instance().clear();
  1098. subnet_ = Subnet6Ptr(new Subnet6(IOAddress("2001:db8:1:1::"), 56, 1, 2,
  1099. 3, 4));
  1100. subnet_->setIface("eth0");
  1101. pool_ = Pool6Ptr(new Pool6(Lease::TYPE_NA, addr, addr));
  1102. subnet_->addPool(pool_);
  1103. CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->add(subnet_);
  1104. CfgMgr::instance().commit();
  1105. // Allocate a lease.
  1106. testProcessMessage(DHCPV6_REQUEST, "myhost.example.com",
  1107. "myhost.example.com.");
  1108. // Test that the appropriate NameChangeRequest has been generated.
  1109. ASSERT_EQ(1, d2_mgr_.getQueueSize());
  1110. // Get the lease acquired.
  1111. Lease6Ptr lease =
  1112. LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr);
  1113. ASSERT_TRUE(lease);
  1114. verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
  1115. "2001:db8:1:1::dead:beef",
  1116. "000201415AA33D1187D148275136FA30300478"
  1117. "FAAAA3EBD29826B5C907B2C9268A6F52", 0, 4);
  1118. // One of the following: IAID, DUID or subnet identifier has to be changed
  1119. // because otherwise the allocation engine will treat the lease as
  1120. // being renewed by the same client. If we at least change subnet identifier
  1121. // the lease will be treated as expired lease to be reused.
  1122. ++lease->subnet_id_;
  1123. // Move the cllt back in time and make sure that the lease got expired.
  1124. lease->cltt_ = time(NULL) - 10;
  1125. lease->valid_lft_ = 5;
  1126. ASSERT_TRUE(lease->expired());
  1127. // Change the hostname so as the name change request for removing existing
  1128. // DNS mapping is generated.
  1129. lease->hostname_ = "otherhost.example.com.";
  1130. // Update the lease in the lease database.
  1131. LeaseMgrFactory::instance().updateLease6(lease);
  1132. // Simulate another lease acquisition. Since, our pool consists of
  1133. // exactly one address and this address is used by the lease in the
  1134. // lease database, it is guaranteed that the allocation engine will
  1135. // reuse this lease.
  1136. testProcessMessage(DHCPV6_REQUEST, "myhost.example.com.",
  1137. "myhost.example.com.");
  1138. ASSERT_EQ(2, d2_mgr_.getQueueSize());
  1139. // The first name change request generated, should remove a DNS
  1140. // mapping for an expired lease.
  1141. verifyNameChangeRequest(isc::dhcp_ddns::CHG_REMOVE, true, true,
  1142. "2001:db8:1:1::dead:beef",
  1143. "000201D422AA463306223D269B6CB7AFE7AAD2"
  1144. "65FCEA97F93623019B2E0D14E5323D5A",
  1145. lease->cltt_ + lease->valid_lft_, 5);
  1146. // The second name change request should add a DNS mapping for
  1147. // a new lease.
  1148. verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
  1149. "2001:db8:1:1::dead:beef",
  1150. "000201415AA33D1187D148275136FA30300478"
  1151. "FAAAA3EBD29826B5C907B2C9268A6F52", 0, 4);
  1152. }
  1153. TEST_F(FqdnDhcpv6SrvTest, processClientDelegation) {
  1154. testProcessMessage(DHCPV6_REQUEST, "myhost.example.com",
  1155. "myhost.example.com.", 0);
  1156. ASSERT_EQ(1, d2_mgr_.getQueueSize());
  1157. verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, false,
  1158. "2001:db8:1:1::dead:beef",
  1159. "000201415AA33D1187D148275136FA30300478"
  1160. "FAAAA3EBD29826B5C907B2C9268A6F52",
  1161. 0, 4000);
  1162. }
  1163. // Verify that the host reservation is found and used. Lease host name and
  1164. // FQDN should be the reservation hostname suffixed by the qualifying suffix.
  1165. TEST_F(FqdnDhcpv6SrvTest, hostnameReservationSuffix) {
  1166. isc::dhcp::test::IfaceMgrTestConfig test_config(true);
  1167. string config_str = "{ "
  1168. "\"interfaces-config\": {"
  1169. " \"interfaces\": [ \"*\" ]"
  1170. "},"
  1171. "\"valid-lifetime\": 4000, "
  1172. "\"preferred-lifetime\": 3000,"
  1173. "\"rebind-timer\": 2000, "
  1174. "\"renew-timer\": 1000, "
  1175. "\"subnet6\": [ "
  1176. " { "
  1177. " \"subnet\": \"2001:db8:1::/48\", "
  1178. " \"pools\": [ { \"pool\": \"2001:db8:1:1::/64\" } ],"
  1179. " \"interface\" : \"eth0\" , "
  1180. " \"reservations\": ["
  1181. " {"
  1182. " \"duid\": \"" + duid_->toText() + "\","
  1183. " \"ip-addresses\": [ \"2001:db8:1:1::babe\" ],"
  1184. " \"hostname\": \"alice\""
  1185. " }"
  1186. " ]"
  1187. " } ],"
  1188. " \"dhcp-ddns\" : {"
  1189. " \"enable-updates\" : true, "
  1190. " \"qualifying-suffix\" : \"example.com\" }"
  1191. "}";
  1192. configure(config_str);
  1193. // Update subnet_ and pool_ members after config
  1194. setSubnetAndPool(0, 0, Lease::TYPE_NA);
  1195. ASSERT_NO_THROW(srv_->startD2());
  1196. ASSERT_TRUE(CfgMgr::instance().ddnsEnabled());
  1197. // Verify that the host reservation is found and lease name/FQDN are
  1198. // formed properly from the host name and qualifying suffix.
  1199. testProcessMessage(DHCPV6_REQUEST, "myhost.example.com",
  1200. "alice.example.com.", 1, IOAddress("2001:db8:1:1::babe"));
  1201. // Verify that NameChangeRequest is correct.
  1202. verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
  1203. "2001:db8:1:1::babe",
  1204. "000201E2EB74FB53A5778E74AFD43870ECA5"
  1205. "4150B1F52B0CFED434802DA1259D6D3CA4",
  1206. 0, 4000, "alice.example.com.");
  1207. }
  1208. // Verify that the host reservation is found and used, rather than dynamic
  1209. // Address. Lease host name and FQDN should be the reservation hostname
  1210. // without a qualifying suffix.
  1211. TEST_F(FqdnDhcpv6SrvTest, hostnameReservationNoSuffix) {
  1212. isc::dhcp::test::IfaceMgrTestConfig test_config(true);
  1213. string config_str = "{ "
  1214. "\"interfaces-config\": {"
  1215. " \"interfaces\": [ \"*\" ]"
  1216. "},"
  1217. "\"valid-lifetime\": 4000, "
  1218. "\"preferred-lifetime\": 3000,"
  1219. "\"rebind-timer\": 2000, "
  1220. "\"renew-timer\": 1000, "
  1221. "\"subnet6\": [ "
  1222. " { "
  1223. " \"subnet\": \"2001:db8:1::/48\", "
  1224. " \"pools\": [ { \"pool\": \"2001:db8:1:1::/64\" } ],"
  1225. " \"interface\" : \"eth0\" , "
  1226. " \"reservations\": ["
  1227. " {"
  1228. " \"duid\": \"" + duid_->toText() + "\","
  1229. " \"ip-addresses\": [ \"2001:db8:1:1::babe\" ],"
  1230. " \"hostname\": \"alice.example.com\""
  1231. " }"
  1232. " ]"
  1233. " } ],"
  1234. " \"dhcp-ddns\" : {"
  1235. " \"enable-updates\" : true, "
  1236. " \"qualifying-suffix\" : \"\" }"
  1237. "}";
  1238. configure(config_str);
  1239. // Update subnet_ and pool_ members after config
  1240. setSubnetAndPool(0, 0, Lease::TYPE_NA);
  1241. ASSERT_NO_THROW(srv_->startD2());
  1242. ASSERT_TRUE(CfgMgr::instance().ddnsEnabled());
  1243. testProcessMessage(DHCPV6_REQUEST, "myhost.example.com",
  1244. "alice.example.com.", 1,
  1245. IOAddress("2001:db8:1:1::babe"));
  1246. // Verify that NameChangeRequest is correct.
  1247. verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true,
  1248. "2001:db8:1:1::babe",
  1249. "000201E2EB74FB53A5778E74AFD43870ECA5"
  1250. "4150B1F52B0CFED434802DA1259D6D3CA4",
  1251. 0, 4000, "alice.example.com.");
  1252. }
  1253. TEST_F(FqdnDhcpv6SrvTest, hostnameReservationDdnsDisabled) {
  1254. isc::dhcp::test::IfaceMgrTestConfig test_config(true);
  1255. string config_str = "{ "
  1256. "\"interfaces-config\": {"
  1257. " \"interfaces\": [ \"*\" ]"
  1258. "},"
  1259. "\"valid-lifetime\": 4000, "
  1260. "\"preferred-lifetime\": 3000,"
  1261. "\"rebind-timer\": 2000, "
  1262. "\"renew-timer\": 1000, "
  1263. "\"subnet6\": [ "
  1264. " { "
  1265. " \"subnet\": \"2001:db8:1::/48\", "
  1266. " \"pools\": [ { \"pool\": \"2001:db8:1:1::/64\" } ],"
  1267. " \"interface\" : \"eth0\" , "
  1268. " \"reservations\": ["
  1269. " {"
  1270. " \"duid\": \"" + duid_->toText() + "\","
  1271. " \"ip-addresses\": [ \"2001:db8:1:1::babe\" ],"
  1272. " \"hostname\": \"alice\""
  1273. " }"
  1274. " ]"
  1275. " } ],"
  1276. " \"dhcp-ddns\" : {"
  1277. " \"enable-updates\" : false, "
  1278. " \"qualifying-suffix\" : \"disabled.example.com\" }"
  1279. "}";
  1280. configure(config_str);
  1281. // Update subnet_ and pool_ members after config
  1282. setSubnetAndPool(0, 0, Lease::TYPE_NA);
  1283. ASSERT_FALSE(CfgMgr::instance().ddnsEnabled());
  1284. testProcessMessage(DHCPV6_REQUEST, "myhost.example.com",
  1285. "alice.disabled.example.com.", 0,
  1286. IOAddress("2001:db8:1:1::babe"));
  1287. }
  1288. // Verifies that the replace-client-name behavior is correct for each of
  1289. // the supported modes.
  1290. TEST_F(FqdnDhcpv6SrvTest, replaceClientNameModeTest) {
  1291. isc::dhcp::test::IfaceMgrTestConfig test_config(true);
  1292. testReplaceClientNameMode("never",
  1293. CLIENT_NAME_NOT_PRESENT, NAME_NOT_REPLACED);
  1294. testReplaceClientNameMode("never",
  1295. CLIENT_NAME_PRESENT, NAME_NOT_REPLACED);
  1296. testReplaceClientNameMode("always",
  1297. CLIENT_NAME_NOT_PRESENT, NAME_REPLACED);
  1298. testReplaceClientNameMode("always",
  1299. CLIENT_NAME_PRESENT, NAME_REPLACED);
  1300. testReplaceClientNameMode("when-present",
  1301. CLIENT_NAME_NOT_PRESENT, NAME_NOT_REPLACED);
  1302. testReplaceClientNameMode("when-present",
  1303. CLIENT_NAME_PRESENT, NAME_REPLACED);
  1304. testReplaceClientNameMode("when-not-present",
  1305. CLIENT_NAME_NOT_PRESENT, NAME_REPLACED);
  1306. testReplaceClientNameMode("when-not-present",
  1307. CLIENT_NAME_PRESENT, NAME_NOT_REPLACED);
  1308. }
  1309. } // end of anonymous namespace