16#include <boost/make_shared.hpp>
40 : universe_(u), type_(type) {
45 : universe_(u), type_(type), data_(data) {
51 : universe_(u), type_(type), data_(first, last) {
56 : universe_(option.universe_), type_(option.type_),
57 data_(option.data_), options_(),
58 encapsulated_space_(option.encapsulated_space_) {
64 return (boost::make_shared<Option>(u, type));
69 return (boost::make_shared<Option>(u, type, data));
93 <<
"Only V4 and V6 are allowed.");
99 <<
"For DHCPv4 allowed type range is 0..255");
111 if (!
data_.empty()) {
123 <<
"At most 255 bytes are supported.");
156 list<uint16_t> deferred;
179 for (
auto const& option :
options_) {
180 length += option.second->len();
186 return (
static_cast<uint16_t
>(length));
200 auto const& x =
options_.find(opt_type);
210 for (
auto const& option :
options_) {
212 local_options.insert(std::make_pair(option.second->getType(),
copy));
216 options_copy.swap(local_options);
220 auto const& x =
options_.find(opt_type);
229 std::stringstream output;
232 for (
unsigned int i = 0; i <
data_.size(); i++) {
236 output << setfill(
'0') << setw(2) << hex
237 <<
static_cast<unsigned short>(
data_[i]);
242 std::string printable(
data_.cbegin(),
data_.cend());
243 output <<
" '" << printable <<
"'";
249 return (output.str());
266 }
catch (
const std::exception &ex) {
268 " of option " <<
getType() <<
": " << ex.what());
270 const uint8_t* option_data =
static_cast<const uint8_t*
>(buf.
getData());
274 std::vector<uint8_t> option_vec(option_data + (include_header ? 0 :
getHeaderLen()),
282 std::vector<uint8_t> option_vec =
toBinary(include_header);
286 std::ostringstream s;
287 if (!option_vec.empty()) {
295 std::stringstream output;
296 for (
int i = 0; i < indent; i++)
300 output <<
"type=" << std::setw(field_len) << std::setfill(
'0')
303 if (!type_name.empty()) {
304 output <<
"(" << type_name <<
")";
307 output <<
", len=" << std::setw(field_len) << std::setfill(
'0')
309 return (output.str());
314 std::stringstream output;
317 output <<
"," << std::endl <<
"options:";
319 output << std::endl << opt.second->toText(indent);
323 return (output.str());
338 if (
this == opt.get()) {
344 options_.insert(make_pair(opt->getType(), opt));
348 if (
data_.size() <
sizeof(uint8_t) ) {
350 <<
" that has size " <<
data_.size());
366 data_.resize(
sizeof(value));
371 data_.resize(
sizeof(value));
376 data_.resize(
sizeof(value));
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown if a function is called in a prohibited way.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
static size_t unpackOptions4(const OptionBuffer &buf, const std::string &option_space, isc::dhcp::OptionCollection &options, std::list< uint16_t > &deferred, bool flexible_pad_end=false)
Parses provided buffer as DHCPv4 options and creates Option objects.
static isc::dhcp::OptionPtr optionFactory(isc::dhcp::Option::Universe u, uint16_t type, const OptionBuffer &buf)
Factory function to create instance of option.
static void packOptions4(isc::util::OutputBuffer &buf, const isc::dhcp::OptionCollection &options, bool top=false, bool check=true)
Stores DHCPv4 options in a buffer.
static size_t unpackOptions6(const OptionBuffer &buf, const std::string &option_space, isc::dhcp::OptionCollection &options, size_t *relay_msg_offset=0, size_t *relay_msg_len=0)
Parses provided buffer as DHCPv6 options and creates Option objects.
static void packOptions6(isc::util::OutputBuffer &buf, const isc::dhcp::OptionCollection &options)
Stores DHCPv6 options in a buffer.
static OptionPtr factory(Option::Universe u, uint16_t type, const OptionBuffer &buf)
Factory function to create instance of option.
uint16_t type_
option type (0-255 for DHCPv4, 0-65535 for DHCPv6)
std::string headerToText(const int indent=0, const std::string &type_name="") const
Returns option header in the textual format.
std::string suboptionsToText(const int indent=0) const
Returns collection of suboptions in the textual format.
static bool lenient_parsing_
Governs whether options should be parsed less strictly.
std::string encapsulated_space_
Name of the option space being encapsulated by this option.
std::string getEncapsulatedSpace() const
Returns the name of the option space encapsulated by this option.
bool equals(const OptionPtr &other) const
Checks if options are equal.
virtual const OptionBuffer & getData() const
Returns pointer to actual data.
virtual ~Option()
just to force that every option has virtual dtor
virtual void pack(isc::util::OutputBuffer &buf, bool check=true) const
Writes option in wire-format to a buffer.
bool delOption(uint16_t type)
Attempts to delete first suboption of requested type.
virtual uint16_t getHeaderLen() const
Returns length of header (2 for v4, 4 for v6)
virtual uint16_t len() const
Returns length of the complete option (data length + DHCPv4/DHCPv6 option header)
Universe
defines option universe DHCPv4 or DHCPv6
Universe universe_
option universe (V4 or V6)
OptionPtr getOption(uint16_t type) const
Returns shared_ptr to suboption of specific type.
void addOption(OptionPtr opt)
Adds a sub-option.
void setUint32(uint32_t value)
Sets content of this option to a single uint32 value.
uint16_t getType() const
Returns option type (0-255 for DHCPv4, 0-65535 for DHCPv6)
OptionBuffer data_
contains content of this data
virtual std::string toString() const
Returns string representation of the value.
void unpackOptions(const OptionBuffer &buf)
Builds a collection of sub options from the buffer.
void packOptions(isc::util::OutputBuffer &buf, bool check=true) const
Store sub options in a buffer.
static OptionPtr create(Universe u, uint16_t type)
Factory function creating an instance of the Option.
static const size_t OPTION6_HDR_LEN
length of any DHCPv6 option header
void setUint8(uint8_t value)
Sets content of this option to a single uint8 value.
Option & operator=(const Option &rhs)
Assignment operator.
void setData(InputIterator first, InputIterator last)
Sets content of this option from buffer.
virtual bool valid() const
returns if option is valid (e.g.
OptionCollection options_
collection for storing suboptions
OptionPtr cloneInternal() const
Copies this option and returns a pointer to the copy.
Universe getUniverse() const
returns option universe (V4 or V6)
uint8_t getUint8() const
Returns content of first byte.
virtual std::vector< uint8_t > toBinary(const bool include_header=false) const
Returns binary representation of the option.
void setUint16(uint16_t value)
Sets content of this option to a single uint16 value.
virtual OptionPtr clone() const
Copies this option and returns a pointer to the copy.
virtual void unpack(OptionBufferConstIter begin, OptionBufferConstIter end)
Parses received buffer.
uint16_t getUint16() const
Returns content of first word.
virtual std::string toText(int indent=0) const
Returns string representation of the option.
void packHeader(isc::util::OutputBuffer &buf, bool check=true) const
Store option's header in a buffer.
virtual std::string toHexString(const bool include_header=false) const
Returns string containing hexadecimal representation of option.
uint32_t getUint32() const
Returns content of first double word.
Option(Universe u, uint16_t type)
ctor, used for options constructed, usually during transmission
void check() const
A protected method used for option correctness.
void getOptionsCopy(OptionCollection &options_copy) const
Performs deep copy of suboptions.
static const size_t OPTION4_HDR_LEN
length of the usual DHCPv4 option header (there are exceptions)
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
void writeUint8(uint8_t data)
Write an unsigned 8-bit integer into the buffer.
void writeUint16(uint16_t data)
Write an unsigned 16-bit integer in host byte order into the buffer in network byte order.
void writeData(const void *data, size_t len)
Copy an arbitrary length of data into the buffer.
const uint8_t * getData() const
Return a pointer to the head of the data stored in the buffer.
size_t getLength() const
Return the length of data written in the buffer.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
@ DHO_VENDOR_ENCAPSULATED_OPTIONS
OptionBuffer::const_iterator OptionBufferConstIter
const_iterator for walking over OptionBuffer
std::multimap< unsigned int, OptionPtr > OptionCollection
A collection of DHCP (v4 or v6) options.
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
boost::shared_ptr< Option > OptionPtr
string encodeHex(const vector< uint8_t > &binary)
Encode binary data in the base16 format.
bool isPrintable(const string &content)
Check if a string is printable.
uint8_t * writeUint32(uint32_t const value, void *const buffer, size_t const length)
uint32_t wrapper over writeUint.
uint16_t readUint16(void const *const buffer, size_t const length)
uint16_t wrapper over readUint.
uint8_t * writeUint16(uint16_t const value, void *const buffer, size_t const length)
uint16_t wrapper over writeUint.
uint32_t readUint32(void const *const buffer, size_t const length)
uint32_t wrapper over readUint.
Defines the logger used by the top-level component of kea-lfc.