option_vendor.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Copyright (C) 2013,2015 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef OPTION_VENDOR_H
  15. #define OPTION_VENDOR_H
  16. #include <dhcp/libdhcp++.h>
  17. #include <dhcp/option.h>
  18. #include <dhcp/option_data_types.h>
  19. #include <util/io_utilities.h>
  20. #include <stdint.h>
  21. namespace isc {
  22. namespace dhcp {
  23. /// Indexes for fields in vendor-class (17) DHCPv6 option
  24. const int VENDOR_CLASS_ENTERPRISE_ID_INDEX = 0;
  25. const int VENDOR_CLASS_DATA_LEN_INDEX = 1;
  26. const int VENDOR_CLASS_STRING_INDEX = 2;
  27. /// @brief This class represents vendor-specific information option.
  28. ///
  29. /// As specified in RFC3925, the option formatting is slightly different
  30. /// for DHCPv4 than DHCPv6. The DHCPv4 Option includes additional field
  31. /// holding vendor data length.
  32. class OptionVendor: public Option {
  33. public:
  34. /// @brief Constructor.
  35. ///
  36. /// @param u universe (V4 or V6)
  37. /// @param vendor_id vendor enterprise-id (unique 32 bit integer)
  38. OptionVendor(Option::Universe u, const uint32_t vendor_id);
  39. /// @brief Constructor.
  40. ///
  41. /// This constructor creates option from a buffer. This constructor
  42. /// may throw exception if \ref unpack function throws during buffer
  43. /// parsing.
  44. ///
  45. /// @param u universe (V4 or V6)
  46. /// @param begin iterator to first byte of option data.
  47. /// @param end iterator to end of option data (first byte after option end).
  48. ///
  49. /// @throw isc::OutOfRange if provided buffer is shorter than data size.
  50. /// @todo Extend constructor to set encapsulated option space name.
  51. OptionVendor(Option::Universe u, OptionBufferConstIter begin,
  52. OptionBufferConstIter end);
  53. /// @brief Writes option in wire-format to buf, returns pointer to first
  54. /// unused byte after stored option.
  55. ///
  56. /// @param [out] buf buffer (option will be stored here)
  57. virtual void pack(isc::util::OutputBuffer& buf);
  58. /// @brief Parses received buffer
  59. ///
  60. /// Parses received buffer and returns offset to the first unused byte after
  61. /// parsed option.
  62. ///
  63. /// @param begin iterator to first byte of option data
  64. /// @param end iterator to end of option data (first byte after option end)
  65. ///
  66. /// @throw isc::OutOfRange if provided buffer is shorter than data size.
  67. virtual void unpack(OptionBufferConstIter begin, OptionBufferConstIter end);
  68. /// @brief Sets enterprise identifier
  69. ///
  70. /// @param vendor_id vendor identifier
  71. void setVendorId(const uint32_t vendor_id) { vendor_id_ = vendor_id; }
  72. /// @brief Returns enterprise identifier
  73. ///
  74. /// @return enterprise identifier
  75. uint32_t getVendorId() const { return (vendor_id_); }
  76. /// @brief returns complete length of option
  77. ///
  78. /// Returns length of this option, including option header and suboptions
  79. ///
  80. /// @return length of this option
  81. virtual uint16_t len();
  82. /// @brief Returns the option in the textual format.
  83. ///
  84. /// @param indent Number of spaces to be inserted before the text.
  85. ///
  86. /// @return Vendor option in the textual format.
  87. virtual std::string toText(int indent = 0);
  88. private:
  89. /// @brief Calculates the data-len value for DHCPv4.
  90. ///
  91. /// The data-len field is only present in DHCPv4 space. It follows
  92. /// the vendor-id field. This method is called from the
  93. /// @c OptionVendor::pack and @c OptionVendor::toText to calculate
  94. /// this value.
  95. ///
  96. /// @return Returns calculated data-len value.
  97. uint8_t dataLen();
  98. uint32_t vendor_id_; ///< Enterprise-id
  99. };
  100. /// Pointer to a vendor option
  101. typedef boost::shared_ptr<OptionVendor> OptionVendorPtr;
  102. } // isc::dhcp namespace
  103. } // isc namespace
  104. #endif // OPTION_VENDOR_H