42    : 
Option(u, def.getCode(), first, last),
 
 
   60                  << address << 
". Expected a valid IPv" 
   62                      "4" : 
"6") << 
" address.");
 
   67    buffers_.push_back(buf);
 
 
   77    buffers_.push_back(buf);
 
 
   86    buffers_.push_back(buf);
 
 
   95    buffers_.push_back(buf);
 
 
  105                  " an option comprising an array of IPv6 prefix values");
 
  110    buffers_.push_back(buf);
 
 
  119                  " an option comprising an array of PSID length / value" 
  125    buffers_.push_back(buf);
 
 
  129OptionCustom::checkIndex(
const uint32_t index)
 const {
 
  130    if (index >= buffers_.size()) {
 
  132                  << 
" is out of range.");
 
  148    if (data_size == 0) {
 
  161        buffer.resize(data_size);
 
  166OptionCustom::createBuffers() {
 
  167    definition_.validate();
 
  169    std::vector<OptionBuffer> buffers;
 
  183            definition_.getRecordFields();
 
  185        for (
auto const& field : fields) {
 
  187            createBuffer(buf, field);
 
  190            buffers.push_back(buf);
 
  192    } 
else if (!definition_.getArrayType() &&
 
  202        createBuffer(buf, data_type);
 
  204        buffers.push_back(buf);
 
  209    std::swap(buffers, buffers_);
 
  213OptionCustom::bufferLength(
const OptionDataType data_type, 
bool in_array,
 
  214                           OptionBuffer::const_iterator begin,
 
  215                           OptionBuffer::const_iterator end)
 const {
 
  223    if (data_size == 0) {
 
  235                data_size = fqdn.size() + 1;
 
  236            } 
catch (
const std::exception& ex) {
 
  238                    isc_throw(SkipThisOptionError, 
"failed to read " 
  239                              "domain-name from wire format: " 
  245        } 
else if (!definition_.getArrayType() &&
 
  254            data_size = std::distance(begin, end);
 
  260            if ((begin == end) && !in_array)
 
  266            data_size = 
sizeof(uint8_t) + (prefix.first.asUint8() + 7) / 8;
 
  272            data_size = value.size();
 
  280            isc_throw(OutOfRange, 
"option buffer truncated");
 
  288OptionCustom::createBuffers(
const OptionBuffer& data_buf) {
 
  291    definition_.validate();
 
  293    std::vector<OptionBuffer> buffers;
 
  294    OptionBuffer::const_iterator data = data_buf.begin();
 
  302            definition_.getRecordFields();
 
  305        for (
auto const& field : fields) {
 
  306            size_t data_size = bufferLength(field, 
false,
 
  307                                            data, data_buf.end());
 
  311            if (
static_cast<size_t>(std::distance(data, data_buf.end())) < data_size) {
 
  312                isc_throw(OutOfRange, 
"option buffer truncated");
 
  316            buffers.push_back(
OptionBuffer(data, data + data_size));
 
  322        if (definition_.getArrayType()) {
 
  323            while (data != data_buf.end()) {
 
  325                size_t data_size = bufferLength(fields.back(), 
true,
 
  326                                                data, data_buf.end());
 
  328                if (
static_cast<size_t>(std::distance(data, data_buf.end())) < data_size) {
 
  331                buffers.push_back(
OptionBuffer(data, data + data_size));
 
  353        if (
static_cast<size_t>(std::distance(data, data_buf.end())) < data_size) {
 
  354            isc_throw(OutOfRange, 
"option buffer truncated");
 
  358        if (definition_.getArrayType()) {
 
  359            while (data != data_buf.end()) {
 
  360                data_size = bufferLength(data_type, 
true, data, data_buf.end());
 
  372                if (
static_cast<size_t>(std::distance(data, data_buf.end())) < data_size) {
 
  375                buffers.push_back(
OptionBuffer(data, data + data_size));
 
  382            data_size = bufferLength(data_type, 
false, data, data_buf.end());
 
  383            if ((data_size > 0) &&
 
  384                (
static_cast<size_t>(std::distance(data, data_buf.end())) >= data_size)) {
 
  385                buffers.push_back(
OptionBuffer(data, data + data_size));
 
  388                isc_throw(OutOfRange, 
"option buffer truncated");
 
  403    std::swap(buffers_, buffers);
 
  408                              const uint32_t index)
 const {
 
  409    std::ostringstream text;
 
  421                std::string printable(data.cbegin(), data.cend());
 
  422                text << 
" '" << printable << 
"'";
 
  434        text << readInteger<int16_t>(index);
 
  437        text << readInteger<int32_t>(index);
 
  443        text << readInteger<uint16_t>(index);
 
  446        text << readInteger<uint32_t>(index);
 
  453        text << 
"\"" << 
readFqdn(index) << 
"\"";
 
  456        text << 
"\"" << 
readTuple(index) << 
"\"";
 
  464        text << 
"len=" << t.first.asUnsigned() << 
",psid=" << t.second.asUint16();
 
  484    for (
auto const& it : buffers_) {
 
 
  505    if (buffers_[index].size() == asiolink::V4ADDRESS_LEN) {
 
  507    } 
else if (buffers_[index].size() == asiolink::V6ADDRESS_LEN) {
 
  511                  << 
" IP address. Invalid buffer length " 
  512                  << buffers_[index].size() << 
".");
 
 
  518                           const uint32_t index) {
 
  521    if ((address.
isV4() && buffers_[index].size() != V4ADDRESS_LEN) ||
 
  522        (address.
isV6() && buffers_[index].size() != V6ADDRESS_LEN)) {
 
  524                  << address << 
". Expected a valid IPv" 
  525                  << (buffers_[index].size() == V4ADDRESS_LEN ? 
"4" : 
"6")
 
  531    std::swap(buf, buffers_[index]);
 
 
  537    return (buffers_[index]);
 
 
  542                          const uint32_t index) {
 
  544    buffers_[index] = buf;
 
 
  556                        const uint32_t index)
 const {
 
 
  565    buffers_[index].clear();
 
 
  574    buffers_[index].clear();
 
 
  588    buffers_[index].clear();
 
 
  612    std::swap(buffers_[index], buf);
 
 
  624                          const uint32_t index) {
 
  631    std::swap(buffers_[index], buf);
 
 
  643                        const uint32_t index) {
 
  650    std::swap(buffers_[index], buf);
 
 
  667    buffers_[index].clear();
 
 
  687    for (
auto const& buf : buffers_) {
 
  688        length += buf.size();
 
  693        length += it.second->len();
 
  696    return (
static_cast<uint16_t
>(length));
 
 
  701    setData(first, last);
 
 
  709    std::stringstream output;
 
  716            definition_.getRecordFields();
 
  722        for (
auto const& field : fields) {
 
  723            output << 
" " << dataFieldToText(field, j);
 
  728        if (definition_.getArrayType()) {
 
  730                output << 
" " << dataFieldToText(fields.back(), i);
 
  740            output << 
" " << dataFieldToText(definition_.getType(), i);
 
  747    return (output.str());
 
 
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
The IOAddress class represents an IP addresses (version agnostic)
bool isV6() const
Convenience function to check for an IPv6 address.
bool isV4() const
Convenience function to check for an IPv4 address.
static const IOAddress & IPV6_ZERO_ADDRESS()
Returns an IPv6 zero address.
Exception to be thrown when cast to the data type was unsuccessful.
Represents a single instance of the opaque data preceded by length.
LengthFieldType
Size of the length field in the tuple.
std::string readString(const uint32_t index=0) const
Read a buffer as string value.
bool readBoolean(const uint32_t index=0) const
Read a buffer as boolean value.
virtual uint16_t len() const
Returns length of the complete option (data length + DHCPv4/DHCPv6 option header)
std::string readTuple(const uint32_t index=0) const
Read a buffer as length and string tuple.
void writeFqdn(const std::string &fqdn, const uint32_t index=0)
Write an FQDN into a buffer.
std::string readFqdn(const uint32_t index=0) const
Read a buffer as FQDN.
void writePrefix(const PrefixLen &prefix_len, const asiolink::IOAddress &prefix, const uint32_t index=0)
Write prefix length and value into a buffer.
virtual void unpack(OptionBufferConstIter begin, OptionBufferConstIter end)
Parses received buffer.
void writeAddress(const asiolink::IOAddress &address, const uint32_t index=0)
Write an IP address into a buffer.
virtual void pack(isc::util::OutputBuffer &buf, bool check=true) const
Writes DHCP option in a wire format to a buffer.
void initialize(const OptionBufferConstIter first, const OptionBufferConstIter last)
Sets content of this option from buffer.
const OptionBuffer & readBinary(const uint32_t index=0) const
Read a buffer as binary data.
PrefixTuple readPrefix(const uint32_t index=0) const
Read a buffer as variable length prefix.
void writePsid(const PSIDLen &psid_len, const PSID &psid, const uint32_t index=0)
Write PSID length / value into a buffer.
void writeBoolean(const bool value, const uint32_t index=0)
Write a boolean value into a buffer.
asiolink::IOAddress readAddress(const uint32_t index=0) const
Read a buffer as IP address.
PSIDTuple readPsid(const uint32_t index=0) const
Read a buffer as a PSID length / value tuple.
void writeString(const std::string &text, const uint32_t index=0)
Write a string value into a buffer.
T readInteger(const uint32_t index=0) const
Read a buffer as integer value.
void writeBinary(const OptionBuffer &buf, const uint32_t index=0)
Write binary data into a buffer.
void addArrayDataField(const asiolink::IOAddress &address)
Create new buffer and set its value as an IP address.
virtual OptionPtr clone() const
Copies this option and returns a pointer to the copy.
void writeTuple(const std::string &value, const uint32_t index=0)
Write a length and string tuple into a buffer.
virtual std::string toText(int indent=0) const
Returns string representation of the option.
OptionCustom(const OptionDefinition &def, Universe u)
Constructor, used for options to be sent.
uint32_t getDataFieldsNum() const
Return a number of the data fields.
static PrefixTuple readPrefix(const std::vector< uint8_t > &buf)
Read prefix from a buffer.
static asiolink::IOAddress readAddress(const std::vector< uint8_t > &buf, const short family)
Read IPv4 or IPv6 address from a buffer.
static void writeFqdn(const std::string &fqdn, std::vector< uint8_t > &buf, const bool downcase=false)
Append FQDN into a buffer.
static void writePrefix(const PrefixLen &prefix_len, const asiolink::IOAddress &prefix, std::vector< uint8_t > &buf)
Append prefix into a buffer.
static const std::string & getDataTypeName(const OptionDataType data_type)
Return option data type name from the data type enumerator.
static int getDataTypeLen(const OptionDataType data_type)
Get data type buffer length.
static std::string readFqdn(const std::vector< uint8_t > &buf)
Read FQDN from a buffer as a string value.
static std::string readTuple(const std::vector< uint8_t > &buf, OpaqueDataTuple::LengthFieldType lengthfieldtype)
Read length and string tuple from a buffer.
static void writeAddress(const asiolink::IOAddress &address, std::vector< uint8_t > &buf)
Append IPv4 or IPv6 address to a buffer.
static PSIDTuple readPsid(const std::vector< uint8_t > &buf)
Read PSID length / value tuple from a buffer.
static void writePsid(const PSIDLen &psid_len, const PSID &psid, std::vector< uint8_t > &buf)
Append PSID length/value into a buffer.
static void writeString(const std::string &value, std::vector< uint8_t > &buf)
Write UTF8-encoded string into a buffer.
static void writeTuple(const std::string &value, OpaqueDataTuple::LengthFieldType lengthfieldtype, std::vector< uint8_t > &buf)
Append length and string tuple to a buffer.
static OpaqueDataTuple::LengthFieldType getTupleLenFieldType(Option::Universe u)
Returns Length Field Type for a tuple.
static void writeBool(const bool value, std::vector< uint8_t > &buf)
Append boolean value into a buffer.
static bool readBool(const std::vector< uint8_t > &buf)
Read boolean value from a buffer.
static std::string readString(const std::vector< uint8_t > &buf)
Read string value from a buffer.
Base class representing a DHCP option definition.
std::vector< OptionDataType > RecordFieldsCollection
List of fields within the record.
std::string getEncapsulatedSpace() const
Return name of the encapsulated option space.
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 getEncapsulatedSpace() const
Returns the name of the option space encapsulated by this option.
void setEncapsulatedSpace(const std::string &encapsulated_space)
Sets the name of the option space encapsulated by this option.
virtual const OptionBuffer & getData() const
Returns pointer to actual data.
virtual uint16_t getHeaderLen() const
Returns length of header (2 for v4, 4 for v6)
Universe
defines option universe DHCPv4 or DHCPv6
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.
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)
void packHeader(isc::util::OutputBuffer &buf, bool check=true) const
Store option's header in a buffer.
Option(Universe u, uint16_t type)
ctor, used for options constructed, usually during transmission
void check() const
A protected method used for option correctness.
Encapsulates PSID length.
Encapsulates prefix length.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
void writeData(const void *data, size_t len)
Copy an arbitrary length of data into the buffer.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define isc_throw_assert(expr)
Replacement for assert() that throws if the expression is false.
std::pair< PSIDLen, PSID > PSIDTuple
Defines a pair of PSID length / value.
OptionBuffer::const_iterator OptionBufferConstIter
const_iterator for walking over OptionBuffer
OptionDataType
Data types of DHCP option fields.
std::pair< PrefixLen, asiolink::IOAddress > PrefixTuple
Defines a pair of prefix length / value.
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.
Defines the logger used by the top-level component of kea-lfc.