option_definition.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. // Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef OPTION_DEFINITION_H
  15. #define OPTION_DEFINITION_H
  16. #include <dhcp/option.h>
  17. #include <dhcp/option_data_types.h>
  18. #include <boost/multi_index/hashed_index.hpp>
  19. #include <boost/multi_index/mem_fun.hpp>
  20. #include <boost/multi_index/sequenced_index.hpp>
  21. #include <boost/multi_index_container.hpp>
  22. #include <boost/shared_ptr.hpp>
  23. namespace isc {
  24. namespace dhcp {
  25. /// @brief Exception to be thrown when invalid option value has been
  26. /// specified for a particular option definition.
  27. class InvalidOptionValue : public Exception {
  28. public:
  29. InvalidOptionValue(const char* file, size_t line, const char* what) :
  30. isc::Exception(file, line, what) { };
  31. };
  32. /// @brief Exception to be thrown when option definition is invalid.
  33. class MalformedOptionDefinition : public Exception {
  34. public:
  35. MalformedOptionDefinition(const char* file, size_t line, const char* what) :
  36. isc::Exception(file, line, what) { };
  37. };
  38. /// @brief Exception to be thrown when the particular option definition
  39. /// duplicates existing option definition.
  40. class DuplicateOptionDefinition : public Exception {
  41. public:
  42. DuplicateOptionDefinition(const char* file, size_t line, const char* what) :
  43. isc::Exception(file, line, what) { };
  44. };
  45. /// @brief Forward declaration to OptionDefinition.
  46. class OptionDefinition;
  47. /// @brief Pointer to option definition object.
  48. typedef boost::shared_ptr<OptionDefinition> OptionDefinitionPtr;
  49. /// @brief Forward declaration to OptionInt.
  50. ///
  51. /// This forward declaration is needed to access the OptionInt class without
  52. /// having to include the option_int.h header file. It is required because
  53. /// this header includes libdhcp++.h, and including option_int.h would cause
  54. /// circular inclusion between libdhcp++.h, option_definition.h and
  55. /// option6_int.h.
  56. template<typename T>
  57. class OptionInt;
  58. /// @brief Forward declaration to OptionIntArray.
  59. ///
  60. /// This forward declaration is needed to access the OptionIntArray class
  61. /// without having to include the option_int_array.h header file. It is
  62. /// required because this header includes libdhcp++.h, and including
  63. /// option_int_array.h would cause circular inclusion between libdhcp++.h,
  64. /// option_definition.h and option_int_array.h.
  65. template<typename T>
  66. class OptionIntArray;
  67. /// @brief Base class representing a DHCP option definition.
  68. ///
  69. /// This is a base class representing a DHCP option definition, which describes
  70. /// the format of the option. In particular, it defines:
  71. /// - option name,
  72. /// - option code,
  73. /// - data fields order and their types,
  74. /// - sub options space that the particular option encapsulates.
  75. ///
  76. /// The option type specifies the data type(s) which an option conveys. If
  77. /// this is a single value the option type points to the data type of the
  78. /// value. For example, DHCPv6 option 8 comprises a two-byte option code, a
  79. /// two-byte option length and two-byte field that carries a uint16 value
  80. /// (RFC 3315 - http://ietf.org/rfc/rfc3315.txt). In such a case, the option
  81. /// type is defined as "uint16".
  82. ///
  83. /// When the option has a more complex structure, the option type may be
  84. /// defined as "array", "record" or even "array of records".
  85. ///
  86. /// Array types should be used when the option contains multiple contiguous
  87. /// data values of the same type laid. For example, DHCPv6 option 6 includes
  88. /// multiple fields holding uint16 codes of requested DHCPv6 options (RFC 3315).
  89. /// Such an option can be represented with this class by setting the option
  90. /// type to "uint16" and the array indicator (array_type) to true. The number
  91. /// of elements in the array is effectively unlimited (although it is actually
  92. /// limited by the maximal DHCPv6 option length).
  93. ///
  94. /// Should the option comprise data fields of different types, the "record"
  95. /// option type is used. In such cases the data field types within the record
  96. /// are specified using \ref OptionDefinition::addRecordField.
  97. ///
  98. /// When the OptionDefinition object has been sucessfully created, it can be
  99. /// queried to return the appropriate option factory function for the specified
  100. /// specified option format. There are a number of "standard" factory functions
  101. /// that cover well known (common) formats. If the particular format does not
  102. /// match any common format the generic factory function is returned.
  103. ///
  104. /// The following data type strings are supported:
  105. /// - "empty" (option does not contain data fields)
  106. /// - "boolean"
  107. /// - "int8"
  108. /// - "int16"
  109. /// - "int32"
  110. /// - "uint8"
  111. /// - "uint16"
  112. /// - "uint32"
  113. /// - "ipv4-address" (IPv4 Address)
  114. /// - "ipv6-address" (IPV6 Address)
  115. /// - "string"
  116. /// - "fqdn" (fully qualified name)
  117. /// - "record" (set of data fields of different types)
  118. ///
  119. /// @todo Extend the comment to describe "generic factories".
  120. /// @todo Extend this class to use custom namespaces.
  121. /// @todo Extend this class with more factory functions.
  122. class OptionDefinition {
  123. public:
  124. /// List of fields within the record.
  125. typedef std::vector<OptionDataType> RecordFieldsCollection;
  126. /// Const iterator for record data fields.
  127. typedef std::vector<OptionDataType>::const_iterator RecordFieldsConstIter;
  128. /// @brief Constructor.
  129. ///
  130. /// @param name option name.
  131. /// @param code option code.
  132. /// @param type option data type as string.
  133. /// @param array_type array indicator, if true it indicates that the
  134. /// option fields are the array.
  135. explicit OptionDefinition(const std::string& name,
  136. const uint16_t code,
  137. const std::string& type,
  138. const bool array_type = false);
  139. /// @brief Constructor.
  140. ///
  141. /// @param name option name.
  142. /// @param code option code.
  143. /// @param type option data type.
  144. /// @param array_type array indicator, if true it indicates that the
  145. /// option fields are the array.
  146. explicit OptionDefinition(const std::string& name,
  147. const uint16_t code,
  148. const OptionDataType type,
  149. const bool array_type = false);
  150. /// @brief Constructor.
  151. ///
  152. /// This constructor sets the name of the option space that is
  153. /// encapsulated by this option. The encapsulated option space
  154. /// identifies sub-options that are carried within this option.
  155. /// This constructor does not allow to set array indicator
  156. /// because options comprising an array of data fields must
  157. /// not be used with sub-options.
  158. ///
  159. /// @param name option name.
  160. /// @param code option code.
  161. /// @param type option data type given as string.
  162. /// @param encapsulated_space name of the option space being
  163. /// encapsulated by this option.
  164. explicit OptionDefinition(const std::string& name,
  165. const uint16_t code,
  166. const std::string& type,
  167. const char* encapsulated_space);
  168. /// @brief Constructor.
  169. ///
  170. /// This constructor sets the name of the option space that is
  171. /// encapsulated by this option. The encapsulated option space
  172. /// identifies sub-options that are carried within this option.
  173. /// This constructor does not allow to set array indicator
  174. /// because options comprising an array of data fields must
  175. /// not be used with sub-options.
  176. ///
  177. /// @param name option name.
  178. /// @param code option code.
  179. /// @param type option data type.
  180. /// @param encapsulated_space name of the option space being
  181. /// encapsulated by this option.
  182. explicit OptionDefinition(const std::string& name,
  183. const uint16_t code,
  184. const OptionDataType type,
  185. const char* encapsulated_space);
  186. /// @brief Adds data field to the record.
  187. ///
  188. /// @param data_type_name name of the data type for the field.
  189. ///
  190. /// @throw isc::InvalidOperation if option type is not set to RECORD_TYPE.
  191. /// @throw isc::BadValue if specified invalid data type.
  192. void addRecordField(const std::string& data_type_name);
  193. /// @brief Adds data field to the record.
  194. ///
  195. /// @param data_type data type for the field.
  196. ///
  197. /// @throw isc::InvalidOperation if option type is not set to RECORD_TYPE.
  198. /// @throw isc::BadValue if specified invalid data type.
  199. void addRecordField(const OptionDataType data_type);
  200. /// @brief Return array type indicator.
  201. ///
  202. /// The method returns the bool value to indicate whether the option is a
  203. /// a single value or an array of values.
  204. ///
  205. /// @return true if option comprises an array of values.
  206. bool getArrayType() const { return (array_type_); }
  207. /// @brief Return option code.
  208. ///
  209. /// @return option code.
  210. uint16_t getCode() const { return (code_); }
  211. /// @brief Return name of the encapsulated option space.
  212. ///
  213. /// @return name of the encapsulated option space.
  214. std::string getEncapsulatedSpace() const {
  215. return (encapsulated_space_);
  216. }
  217. /// @brief Return option name.
  218. ///
  219. /// @return option name.
  220. std::string getName() const { return (name_); }
  221. /// @brief Return list of record fields.
  222. ///
  223. /// @return list of record fields.
  224. const RecordFieldsCollection& getRecordFields() const { return (record_fields_); }
  225. /// @brief Return option data type.
  226. ///
  227. /// @return option data type.
  228. OptionDataType getType() const { return (type_); };
  229. /// @brief Check if the option definition is valid.
  230. ///
  231. /// Note that it is a responsibility of the code that created
  232. /// the OptionDefinition object to validate that it is valid.
  233. /// This function will not be called internally anywhere in this
  234. /// class to verify that the option definition is valid. Using
  235. /// invalid option definition to create an instance of the
  236. /// DHCP option leads to undefined behavior.
  237. ///
  238. /// @throw MalformedOptionDefinition option definition is invalid.
  239. void validate() const;
  240. /// @brief Check if specified format is IA_NA option format.
  241. ///
  242. /// @return true if specified format is IA_NA option format.
  243. bool haveIA6Format() const;
  244. /// @brief Check if specified format is IAADDR option format.
  245. ///
  246. /// @return true if specified format is IAADDR option format.
  247. bool haveIAAddr6Format() const;
  248. /// @brief Check if specified format is OPTION_CLIENT_FQDN option format.
  249. ///
  250. /// @return true of specified format is OPTION_CLIENT_FQDN option format,
  251. /// false otherwise.
  252. bool haveClientFqdnFormat() const;
  253. /// @brief Check if option has format of the DHCPv4 Client FQDN
  254. /// %Option.
  255. ///
  256. /// The encoding of the domain-name carried by the FQDN option is
  257. /// conditional and is specified in the flags field of the option.
  258. /// The domain-name can be encoded in the ASCII format or canonical
  259. /// wire format. The ASCII format is deprecated, therefore canonical
  260. /// format is selected for the FQDN option definition and this function
  261. /// returns true if the option definition comprises the domain-name
  262. /// field encoded in canonical format.
  263. ///
  264. /// @return true if option has the format of DHCPv4 Client FQDN
  265. /// %Option.
  266. bool haveFqdn4Format() const;
  267. /// @brief Option factory.
  268. ///
  269. /// This function creates an instance of DHCP option using
  270. /// provided chunk of buffer. This function may be used to
  271. /// create option which is to be sent in the outgoing packet.
  272. ///
  273. /// @warning calling this function on invalid option definition
  274. /// yields undefined behavior. Use \ref validate to test that
  275. /// the option definition is valid.
  276. ///
  277. /// @param u option universe (V4 or V6).
  278. /// @param type option type.
  279. /// @param begin beginning of the option buffer.
  280. /// @param end end of the option buffer.
  281. /// @param callback An instance of the function which parses packet options.
  282. /// If this is set to non NULL value this function will be used instead of
  283. /// @c isc::dhcp::LibDHCP::unpackOptions6 and
  284. /// isc::dhcp::LibDHCP::unpackOptions4.
  285. ///
  286. /// @return instance of the DHCP option.
  287. /// @throw InvalidOptionValue if data for the option is invalid.
  288. OptionPtr optionFactory(Option::Universe u, uint16_t type,
  289. OptionBufferConstIter begin,
  290. OptionBufferConstIter end,
  291. UnpackOptionsCallback callback = NULL) const;
  292. /// @brief Option factory.
  293. ///
  294. /// This function creates an instance of DHCP option using
  295. /// whole provided buffer. This function may be used to
  296. /// create option which is to be sent in the outgoing packet.
  297. ///
  298. /// @warning calling this function on invalid option definition
  299. /// yields undefined behavior. Use \ref validate to test that
  300. /// the option definition is valid.
  301. ///
  302. /// @param u option universe (V4 or V6).
  303. /// @param type option type.
  304. /// @param buf option buffer.
  305. /// @param callback An instance of the function which parses packet options.
  306. /// If this is set to non NULL value this function will be used instead of
  307. /// @c isc::dhcp::LibDHCP::unpackOptions6 and
  308. /// isc::dhcp::LibDHCP::unpackOptions4.
  309. ///
  310. /// @return instance of the DHCP option.
  311. /// @throw InvalidOptionValue if data for the option is invalid.
  312. OptionPtr optionFactory(Option::Universe u, uint16_t type,
  313. const OptionBuffer& buf = OptionBuffer(),
  314. UnpackOptionsCallback callback = NULL) const;
  315. /// @brief Option factory.
  316. ///
  317. /// This function creates an instance of DHCP option using the vector
  318. /// of strings which carry data values for option data fields.
  319. /// The order of values in the vector corresponds to the order of data
  320. /// fields in the option. The supplied string values are cast to
  321. /// their actual data types which are determined based on the
  322. /// option definition. If cast fails due to type mismatch, an exception
  323. /// is thrown. This factory function can be used to create option
  324. /// instance when user specified option value in the <b>comma separated
  325. /// values</b> format in the configuration database. Provided string
  326. /// must be tokenized into the vector of string values and this vector
  327. /// can be supplied to this function.
  328. ///
  329. /// @warning calling this function on invalid option definition
  330. /// yields undefined behavior. Use \ref validate to test that
  331. /// the option definition is valid.
  332. ///
  333. /// @param u option universe (V4 or V6).
  334. /// @param type option type.
  335. /// @param values a vector of values to be used to set data for an option.
  336. ///
  337. /// @return instance of the DHCP option.
  338. /// @throw InvalidOptionValue if data for the option is invalid.
  339. OptionPtr optionFactory(Option::Universe u, uint16_t type,
  340. const std::vector<std::string>& values) const;
  341. /// @brief Factory to create option with address list.
  342. ///
  343. /// @param type option type.
  344. /// @param begin iterator pointing to the beginning of the buffer
  345. /// with a list of IPv4 addresses.
  346. /// @param end iterator pointing to the end of the buffer with
  347. /// a list of IPv4 addresses.
  348. ///
  349. /// @throw isc::OutOfRange if length of the provided option buffer
  350. /// is not multiple of IPV4 address length.
  351. static OptionPtr factoryAddrList4(uint16_t type,
  352. OptionBufferConstIter begin,
  353. OptionBufferConstIter end);
  354. /// @brief Factory to create option with address list.
  355. ///
  356. /// @param type option type.
  357. /// @param begin iterator pointing to the beginning of the buffer
  358. /// with a list of IPv6 addresses.
  359. /// @param end iterator pointing to the end of the buffer with
  360. /// a list of IPv6 addresses.
  361. ///
  362. /// @throw isc::OutOfaRange if length of provided option buffer
  363. /// is not multiple of IPV6 address length.
  364. static OptionPtr factoryAddrList6(uint16_t type,
  365. OptionBufferConstIter begin,
  366. OptionBufferConstIter end);
  367. /// @brief Empty option factory.
  368. ///
  369. /// @param u universe (V6 or V4).
  370. /// @param type option type.
  371. static OptionPtr factoryEmpty(Option::Universe u, uint16_t type);
  372. /// @brief Factory to create generic option.
  373. ///
  374. /// @param u universe (V6 or V4).
  375. /// @param type option type.
  376. /// @param begin iterator pointing to the beginning of the buffer.
  377. /// @param end iterator pointing to the end of the buffer.
  378. static OptionPtr factoryGeneric(Option::Universe u, uint16_t type,
  379. OptionBufferConstIter begin,
  380. OptionBufferConstIter end);
  381. /// @brief Factory for IA-type of option.
  382. ///
  383. /// @param type option type.
  384. /// @param begin iterator pointing to the beginning of the buffer.
  385. /// @param end iterator pointing to the end of the buffer.
  386. ///
  387. /// @throw isc::OutOfRange if provided option buffer is too short or
  388. /// too long. Expected size is 12 bytes.
  389. /// @throw isc::BadValue if specified universe value is not V6.
  390. static OptionPtr factoryIA6(uint16_t type,
  391. OptionBufferConstIter begin,
  392. OptionBufferConstIter end);
  393. /// @brief Factory for IAADDR-type of option.
  394. ///
  395. /// @param type option type.
  396. /// @param begin iterator pointing to the beginning of the buffer.
  397. /// @param end iterator pointing to the end of the buffer.
  398. ///
  399. /// @throw isc::OutOfRange if provided option buffer is too short or
  400. /// too long. Expected size is 24 bytes.
  401. /// @throw isc::BadValue if specified universe value is not V6.
  402. static OptionPtr factoryIAAddr6(uint16_t type,
  403. OptionBufferConstIter begin,
  404. OptionBufferConstIter end);
  405. /// @brief Factory function to create option with integer value.
  406. ///
  407. /// @param u universe (V4 or V6).
  408. /// @param type option type.
  409. /// @param encapsulated_space An option space being encapsulated by the
  410. /// options created by this factory function. The options which belong to
  411. /// encapsulated option space are sub options of this option.
  412. /// @param begin iterator pointing to the beginning of the buffer.
  413. /// @param end iterator pointing to the end of the buffer.
  414. /// @param callback An instance of the function which parses packet options.
  415. /// If this is set to non NULL value this function will be used instead of
  416. /// @c isc::dhcp::LibDHCP::unpackOptions6 and
  417. /// isc::dhcp::LibDHCP::unpackOptions4.
  418. /// @tparam T type of the data field (must be one of the uintX_t or intX_t).
  419. ///
  420. /// @throw isc::OutOfRange if provided option buffer length is invalid.
  421. template<typename T>
  422. static OptionPtr factoryInteger(Option::Universe u, uint16_t type,
  423. const std::string& encapsulated_space,
  424. OptionBufferConstIter begin,
  425. OptionBufferConstIter end,
  426. UnpackOptionsCallback callback) {
  427. OptionPtr option(new OptionInt<T>(u, type, 0));
  428. option->setEncapsulatedSpace(encapsulated_space);
  429. option->setCallback(callback);
  430. option->unpack(begin, end);
  431. return (option);
  432. }
  433. /// @brief Factory function to create option with array of integer values.
  434. ///
  435. /// @param u universe (V4 or V6).
  436. /// @param type option type.
  437. /// @param begin iterator pointing to the beginning of the buffer.
  438. /// @param end iterator pointing to the end of the buffer.
  439. /// @tparam T type of the data field (must be one of the uintX_t or intX_t).
  440. ///
  441. /// @throw isc::OutOfRange if provided option buffer length is invalid.
  442. template<typename T>
  443. static OptionPtr factoryIntegerArray(Option::Universe u,
  444. uint16_t type,
  445. OptionBufferConstIter begin,
  446. OptionBufferConstIter end) {
  447. OptionPtr option(new OptionIntArray<T>(u, type, begin, end));
  448. return (option);
  449. }
  450. private:
  451. /// @brief Check if specified option format is a record with 3 fields
  452. /// where first one is custom, and two others are uint32.
  453. ///
  454. /// This is a helper function for functions that detect IA_NA and IAAddr
  455. /// option formats.
  456. ///
  457. /// @param first_type type of the first data field.
  458. ///
  459. /// @return true if actual option format matches expected format.
  460. bool haveIAx6Format(const OptionDataType first_type) const;
  461. /// @brief Check if specified type matches option definition type.
  462. ///
  463. /// @return true if specified type matches option definition type.
  464. inline bool haveType(const OptionDataType type) const {
  465. return (type == type_);
  466. }
  467. /// @brief Perform lexical cast of the value and validate its range.
  468. ///
  469. /// This function performs lexical cast of a string value to integer
  470. /// or boolean value and checks if the resulting value is within a
  471. /// range of a target type. Note that range checks are not performed
  472. /// on boolean values. The target type should be one of the supported
  473. /// integer types or bool.
  474. ///
  475. /// @param value_str input value given as string.
  476. /// @tparam T target type for lexical cast.
  477. ///
  478. /// @return cast value.
  479. /// @throw BadDataTypeCast if cast was not successful.
  480. template<typename T>
  481. T lexicalCastWithRangeCheck(const std::string& value_str) const;
  482. /// @brief Write the string value into the provided buffer.
  483. ///
  484. /// This method writes the given value to the specified buffer.
  485. /// The provided string value may represent data of different types.
  486. /// The actual data type is specified with the second argument.
  487. /// Based on a value of this argument, this function will first
  488. /// try to cast the string value to the particular data type and
  489. /// if it is successful it will store the data in the buffer
  490. /// in a binary format.
  491. ///
  492. /// @param value string representation of the value to be written.
  493. /// @param type the actual data type to be stored.
  494. /// @param [in, out] buf buffer where the value is to be stored.
  495. ///
  496. /// @throw BadDataTypeCast if data write was unsuccessful.
  497. void writeToBuffer(const std::string& value, const OptionDataType type,
  498. OptionBuffer& buf) const;
  499. /// Option name.
  500. std::string name_;
  501. /// Option code.
  502. uint16_t code_;
  503. /// Option data type.
  504. OptionDataType type_;
  505. /// Indicates wheter option is a single value or array.
  506. bool array_type_;
  507. /// Name of the space being encapsulated by this option.
  508. std::string encapsulated_space_;
  509. /// Collection of data fields within the record.
  510. RecordFieldsCollection record_fields_;
  511. };
  512. /// @brief Multi index container for DHCP option definitions.
  513. ///
  514. /// This container allows to search for DHCP option definition
  515. /// using two indexes:
  516. /// - sequenced: used to access elements in the order they have
  517. /// been added to the container
  518. /// - option code: used to search definitions of options
  519. /// with a specified option code (aka option type).
  520. /// Note that this container can hold multiple options with the
  521. /// same code. For this reason, the latter index can be used to
  522. /// obtain a range of options for a particular option code.
  523. ///
  524. /// @todo: need an index to search options using option space name
  525. /// once option spaces are implemented.
  526. typedef boost::multi_index_container<
  527. // Container comprises elements of OptionDefinition type.
  528. OptionDefinitionPtr,
  529. // Here we start enumerating various indexes.
  530. boost::multi_index::indexed_by<
  531. // Sequenced index allows accessing elements in the same way
  532. // as elements in std::list. Sequenced is an index #0.
  533. boost::multi_index::sequenced<>,
  534. // Start definition of index #1.
  535. boost::multi_index::hashed_non_unique<
  536. // Use option type as the index key. The type is held
  537. // in OptionDefinition object so we have to call
  538. // OptionDefinition::getCode to retrieve this key
  539. // for each element. The option code is non-unique so
  540. // multiple elements with the same option code can
  541. // be returned by this index.
  542. boost::multi_index::const_mem_fun<
  543. OptionDefinition,
  544. uint16_t,
  545. &OptionDefinition::getCode
  546. >
  547. >
  548. >
  549. > OptionDefContainer;
  550. /// Pointer to an option definition container.
  551. typedef boost::shared_ptr<OptionDefContainer> OptionDefContainerPtr;
  552. /// Type of the index #1 - option type.
  553. typedef OptionDefContainer::nth_index<1>::type OptionDefContainerTypeIndex;
  554. /// Pair of iterators to represent the range of options definitions
  555. /// having the same option type value. The first element in this pair
  556. /// represents the beginning of the range, the second element
  557. /// represents the end.
  558. typedef std::pair<OptionDefContainerTypeIndex::const_iterator,
  559. OptionDefContainerTypeIndex::const_iterator> OptionDefContainerTypeRange;
  560. } // namespace isc::dhcp
  561. } // namespace isc
  562. #endif // OPTION_DEFINITION_H