29 :
Option(u, def.getCode(), data.begin(), data.end()),
39 :
Option(u, def.getCode(), first, last),
47 return (cloneInternal<OptionCustom>());
57 << address <<
". Expected a valid IPv" 59 "4" :
"6") <<
" address.");
64 buffers_.push_back(buf);
75 buffers_.push_back(buf);
84 buffers_.push_back(buf);
93 buffers_.push_back(buf);
103 " an option comprising an array of IPv6 prefix values");
108 buffers_.push_back(buf);
117 " an option comprising an array of PSID length / value" 123 buffers_.push_back(buf);
127 OptionCustom::checkIndex(
const uint32_t index)
const {
128 if (index >= buffers_.size()) {
130 <<
" is out of range.");
146 if (data_size == 0) {
159 buffer.resize(data_size);
164 OptionCustom::createBuffers() {
167 std::vector<OptionBuffer> buffers;
184 field != fields.end(); ++field) {
186 createBuffer(buf, *field);
189 buffers.push_back(buf);
201 createBuffer(buf, data_type);
203 buffers.push_back(buf);
208 std::swap(buffers, buffers_);
212 OptionCustom::bufferLength(
const OptionDataType data_type,
bool in_array,
213 OptionBuffer::const_iterator begin,
214 OptionBuffer::const_iterator end)
const {
222 if (data_size == 0) {
233 data_size = fqdn.size() + 1;
243 data_size = std::distance(begin, end);
249 if ((begin == end) && !in_array)
255 data_size =
sizeof(uint8_t) + (prefix.first.asUint8() + 7) / 8;
263 data_size = value.size();
271 isc_throw(OutOfRange,
"option buffer truncated");
279 OptionCustom::createBuffers(
const OptionBuffer& data_buf) {
284 std::vector<OptionBuffer> buffers;
285 OptionBuffer::const_iterator data = data_buf.begin();
297 field != fields.end(); ++field) {
298 size_t data_size = bufferLength(*field,
false,
299 data, data_buf.end());
303 if (std::distance(data, data_buf.end()) < data_size) {
304 isc_throw(OutOfRange,
"option buffer truncated");
308 buffers.push_back(
OptionBuffer(data, data + data_size));
315 while (data != data_buf.end()) {
317 size_t data_size = bufferLength(fields.back(),
true,
318 data, data_buf.end());
319 assert(data_size > 0);
320 if (std::distance(data, data_buf.end()) < data_size) {
323 buffers.push_back(
OptionBuffer(data, data + data_size));
345 if (std::distance(data, data_buf.end()) < data_size) {
346 isc_throw(OutOfRange,
"option buffer truncated");
351 while (data != data_buf.end()) {
352 data_size = bufferLength(data_type,
true, data, data_buf.end());
358 assert(data_size > 0);
364 if (std::distance(data, data_buf.end()) < data_size) {
367 buffers.push_back(
OptionBuffer(data, data + data_size));
374 data_size = bufferLength(data_type,
false, data, data_buf.end());
375 if ((data_size > 0) && (std::distance(data, data_buf.end()) >= data_size)) {
376 buffers.push_back(
OptionBuffer(data, data + data_size));
379 isc_throw(OutOfRange,
"option buffer truncated");
394 std::swap(buffers_, buffers);
399 const uint32_t index)
const {
400 std::ostringstream text;
411 text << static_cast<int>(readInteger<int8_t>(index));
414 text << readInteger<int16_t>(index);
417 text << readInteger<int32_t>(index);
420 text << static_cast<unsigned>(readInteger<uint8_t>(index));
423 text << readInteger<uint16_t>(index);
426 text << readInteger<uint32_t>(index);
433 text <<
"\"" <<
readFqdn(index) <<
"\"";
436 text <<
"\"" <<
readTuple(index) <<
"\"";
444 text <<
"len=" << t.first.asUnsigned() <<
",psid=" << t.second.asUint16();
463 for (std::vector<OptionBuffer>::const_iterator it = buffers_.begin();
464 it != buffers_.end(); ++it) {
485 if (buffers_[index].size() == asiolink::V4ADDRESS_LEN) {
487 }
else if (buffers_[index].size() == asiolink::V6ADDRESS_LEN) {
491 <<
" IP address. Invalid buffer length " 492 << buffers_[index].size() <<
".");
498 const uint32_t index) {
501 if ((address.
isV4() && buffers_[index].size() != V4ADDRESS_LEN) ||
502 (address.
isV6() && buffers_[index].size() != V6ADDRESS_LEN)) {
504 << address <<
". Expected a valid IPv" 505 << (buffers_[index].size() == V4ADDRESS_LEN ?
"4" :
"6")
511 std::swap(buf, buffers_[index]);
517 return (buffers_[index]);
522 const uint32_t index) {
524 buffers_[index] = buf;
537 const uint32_t index)
const {
546 buffers_[index].clear();
556 buffers_[index].clear();
570 buffers_[index].clear();
594 std::swap(buffers_[index], buf);
606 const uint32_t index) {
613 std::swap(buffers_[index], buf);
625 const uint32_t index) {
632 std::swap(buffers_[index], buf);
649 buffers_[index].clear();
669 for (std::vector<OptionBuffer>::const_iterator buf = buffers_.begin();
670 buf != buffers_.end(); ++buf) {
671 length += buf->size();
675 for (OptionCollection::const_iterator it =
options_.begin();
678 length += (*it).second->len();
681 return (static_cast<uint16_t>(length));
694 std::stringstream output;
707 field != fields.end(); ++field) {
708 output <<
" " << dataFieldToText(*field, std::distance(fields.begin(),
715 output <<
" " << dataFieldToText(fields.back(), i);
725 output <<
" " << dataFieldToText(definition_.
getType(), i);
732 return (output.str());
void writeTuple(const std::string &value, const uint32_t index=0)
Write a length and string tuple into a buffer.
std::string suboptionsToText(const int indent=0) const
Returns collection of suboptions in the textual format.
void addArrayDataField(const asiolink::IOAddress &address)
Create new buffer and set its value as an IP address.
Encapsulates PSID length.
asiolink::IOAddress readAddress(const uint32_t index=0) const
Read a buffer as IP address.
Base class representing a DHCP option definition.
uint32_t getDataFieldsNum() const
Return a number of the data fields.
void writeAddress(const asiolink::IOAddress &address, const uint32_t index=0)
Write an IP address into a buffer.
bool readBoolean(const uint32_t index=0) const
Read a buffer as boolean value.
std::vector< OptionDataType > RecordFieldsCollection
List of fields within the record.
static void writePsid(const PSIDLen &psid_len, const PSID &psid, std::vector< uint8_t > &buf)
Append PSID length/value into a buffer.
void packHeader(isc::util::OutputBuffer &buf) const
Store option's header in a buffer.
static const std::string & getDataTypeName(const OptionDataType data_type)
Return option data type name from the data type enumerator.
static std::string readFqdn(const std::vector< uint8_t > &buf)
Read FQDN from a buffer as a string value.
std::string readFqdn(const uint32_t index=0) const
Read a buffer as FQDN.
OptionCustom(const OptionDefinition &def, Universe u)
Constructor, used for options to be sent.
static void writeBool(const bool value, std::vector< uint8_t > &buf)
Append boolean value into a buffer.
boost::shared_ptr< Option > OptionPtr
static void writeFqdn(const std::string &fqdn, std::vector< uint8_t > &buf, const bool downcase=false)
Append FQDN into a buffer.
static int getDataTypeLen(const OptionDataType data_type)
Get data type buffer length.
Universe
defines option universe DHCPv4 or DHCPv6
static void writePrefix(const PrefixLen &prefix_len, const asiolink::IOAddress &prefix, std::vector< uint8_t > &buf)
Append prefix into a buffer.
static bool readBool(const std::vector< uint8_t > &buf)
Read boolean value from a buffer.
std::pair< PrefixLen, asiolink::IOAddress > PrefixTuple
Defines a pair of prefix length / value.
virtual void unpack(OptionBufferConstIter begin, OptionBufferConstIter end)
Parses received buffer.
void writeBoolean(const bool value, const uint32_t index=0)
Write a boolean value into a buffer.
virtual uint16_t getHeaderLen() const
Returns length of header (2 for v4, 4 for v6)
PSIDTuple readPsid(const uint32_t index=0) const
Read a buffer as a PSID length / value tuple.
static PSIDTuple readPsid(const std::vector< uint8_t > &buf)
Read PSID length / value tuple from a buffer.
virtual uint16_t len() const
Returns length of the complete option (data length + DHCPv4/DHCPv6 option header)
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
std::string readTuple(const uint32_t index=0) const
Read a buffer as length and string tuple.
static const IOAddress & IPV6_ZERO_ADDRESS()
Returns an IPv6 zero address.
void writeData(const void *data, size_t len)
Copy an arbitrary length of data into the buffer.
static void writeTuple(const std::string &value, OpaqueDataTuple::LengthFieldType lengthfieldtype, std::vector< uint8_t > &buf)
Append length and string tuple to a buffer.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
static std::string readString(const std::vector< uint8_t > &buf)
Read string value from a buffer.
std::string headerToText(const int indent=0, const std::string &type_name="") const
Returns option header in the textual format.
OptionDataType
Data types of DHCP option fields.
Universe getUniverse() const
returns option universe (V4 or V6)
virtual OptionPtr clone() const
Copies this option and returns a pointer to the copy.
OptionCollection options_
collection for storing suboptions
void writePsid(const PSIDLen &psid_len, const PSID &psid, const uint32_t index=0)
Write PSID length / value into a buffer.
virtual const OptionBuffer & getData() const
Returns pointer to actual data.
void writePrefix(const PrefixLen &prefix_len, const asiolink::IOAddress &prefix, const uint32_t index=0)
Write prefix length and value into a buffer.
void setEncapsulatedSpace(const std::string &encapsulated_space)
Sets the name of the option space encapsulated by this option.
PrefixTuple readPrefix(const uint32_t index=0) const
Read a buffer as variable length prefix.
bool isV6() const
Convenience function to check for an IPv6 address.
bool isV4() const
Convenience function to check for an IPv4 address.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
OptionBuffer::const_iterator OptionBufferConstIter
const_iterator for walking over OptionBuffer
LengthFieldType
Size of the length field in the tuple.
static asiolink::IOAddress readAddress(const std::vector< uint8_t > &buf, const short family)
Read IPv4 or IPv6 address from a buffer.
std::pair< PSIDLen, PSID > PSIDTuple
Defines a pair of PSID length / value.
Defines the logger used by the top-level component of kea-dhcp-ddns.
void packOptions(isc::util::OutputBuffer &buf) const
Store sub options in a buffer.
string encodeHex(const vector< uint8_t > &binary)
Encode binary data in the base16 ('hex') format.
virtual void pack(isc::util::OutputBuffer &buf) const
Writes DHCP option in a wire format to a buffer.
void unpackOptions(const OptionBuffer &buf)
Builds a collection of sub options from the buffer.
const RecordFieldsCollection & getRecordFields() const
Return list of record fields.
void writeBinary(const OptionBuffer &buf, const uint32_t index=0)
Write binary data into a buffer.
static std::string readTuple(const std::vector< uint8_t > &buf, OpaqueDataTuple::LengthFieldType lengthfieldtype)
Read length and string tuple from a buffer.
virtual std::string toText(int indent=0) const
Returns string representation of the option.
std::string getEncapsulatedSpace() const
Returns the name of the option space encapsulated by this option.
static void writeAddress(const asiolink::IOAddress &address, std::vector< uint8_t > &buf)
Append IPv4 or IPv6 address to a buffer.
void validate() const
Check if the option definition is valid.
void writeFqdn(const std::string &fqdn, const uint32_t index=0)
Write an FQDN into a buffer.
static PrefixTuple readPrefix(const std::vector< uint8_t > &buf)
Read prefix from a buffer.
Represents a single instance of the opaque data preceded by length.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
std::vector< OptionDataType >::const_iterator RecordFieldsConstIter
Const iterator for record data fields.
Exception to be thrown when cast to the data type was unsuccessful.
std::string readString(const uint32_t index=0) const
Read a buffer as string value.
The IOAddress class represents an IP addresses (version agnostic)
bool getArrayType() const
Return array type indicator.
OptionDataType getType() const
Return option data type.
void setData(InputIterator first, InputIterator last)
Sets content of this option from buffer.
static void writeString(const std::string &value, std::vector< uint8_t > &buf)
Write UTF8-encoded string into a buffer.
std::string getEncapsulatedSpace() const
Return name of the encapsulated option space.
Encapsulates prefix length.
void writeString(const std::string &text, const uint32_t index=0)
Write a string value into 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.