7 #ifndef OPTION_DATA_TYPES_H
8 #define OPTION_DATA_TYPES_H
93 static const bool valid =
false;
94 static const int len = 0;
112 static const int len =
sizeof(uint8_t);
215 : psid_len_(psid_len) {
216 if (psid_len_ >
sizeof(uint16_t) * 8) {
236 return (
static_cast<unsigned>(psid_len_));
257 explicit PSID(
const uint16_t psid)
291 : prefix_len_(prefix_len) {
296 return (prefix_len_);
305 return (
static_cast<unsigned>(prefix_len_));
377 std::vector<uint8_t>& buf);
384 static void writeBinary(
const std::string& hex_str,
385 std::vector<uint8_t>& buf);
394 static std::string
readTuple(
const std::vector<uint8_t>& buf,
403 static void readTuple(
const std::vector<uint8_t>& buf,
411 static void writeTuple(
const std::string& value,
413 std::vector<uint8_t>& buf);
420 std::vector<uint8_t>& buf);
439 static bool readBool(
const std::vector<uint8_t>& buf);
448 static void writeBool(
const bool value, std::vector<uint8_t>& buf);
459 static T
readInt(
const std::vector<uint8_t>& buf) {
462 " by readInteger is unsupported integer type");
467 "failed to read an integer value from a buffer"
468 <<
" - buffer is truncated.");
474 value = *(buf.begin());
490 "invalid size of the data type to be read as integer.");
502 std::vector<uint8_t>& buf) {
508 buf.push_back(
static_cast<uint8_t
>(value));
511 buf.resize(buf.size() + 2);
515 buf.resize(buf.size() + 4);
536 static std::string
readFqdn(
const std::vector<uint8_t>& buf);
552 static void writeFqdn(
const std::string& fqdn,
553 std::vector<uint8_t>& buf,
554 const bool downcase =
false);
565 static unsigned int getLabelCount(
const std::string& text_name);
589 std::vector<uint8_t>& buf);
618 std::vector<uint8_t>& buf);
627 static std::string
readString(
const std::vector<uint8_t>& buf);
634 std::vector<uint8_t>& buf);
639 std::map<std::string, OptionDataType> data_types_;
643 std::map<OptionDataType, std::string> data_type_names_;
665 OptionDataType getDataTypeImpl(
const std::string& data_type)
const;
671 const std::string& getDataTypeNameImpl(
const OptionDataType data_type)
const;
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
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)
Exception to be thrown when cast to the data type was unsuccessful.
BadDataTypeCast(const char *file, size_t line, const char *what)
Exception to be thrown when invalid type specified as template parameter.
InvalidDataType(const char *file, size_t line, const char *what)
Represents a single instance of the opaque data preceded by length.
LengthFieldType
Size of the length field in the tuple.
Utility class for option data types.
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 unsigned int getLabelCount(const std::string &text_name)
Return the number of labels in the Name.
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 void writeInt(const T value, std::vector< uint8_t > &buf)
Append integer or unsigned integer value to a buffer.
static const std::string & getDataTypeName(const OptionDataType data_type)
Return option data type name from the data type enumerator.
static OptionDataType getDataType(const std::string &data_type)
Return option data type from its name.
static void writeBinary(const std::string &hex_str, std::vector< uint8_t > &buf)
Append hex-encoded binary values to a buffer.
static int getDataTypeLen(const OptionDataType data_type)
Get data type buffer length.
static T readInt(const std::vector< uint8_t > &buf)
Read integer value from a buffer.
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.
Universe
defines option universe DHCPv4 or DHCPv6
Encapsulates PSID length.
PSIDLen()
Default constructor.
uint8_t asUint8() const
Returns PSID length as uint8_t value.
unsigned int asUnsigned() const
Returns PSID length as unsigned int.
PSIDLen(const uint8_t psid_len)
Constructor.
uint16_t asUint16() const
Returns PSID value as a number.
PSID(const uint16_t psid)
Constructor.
PSID()
Default constructor.
Encapsulates prefix length.
PrefixLen(const uint8_t prefix_len)
Constructor.
unsigned int asUnsigned() const
Returns prefix length as unsigned int.
PrefixLen()
Default constructor.
uint8_t asUint8() const
Returns prefix length as uint8_t value.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A wrapper interface for the ASIO library.
std::pair< PSIDLen, PSID > PSIDTuple
Defines a pair of PSID length / value.
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.
uint8_t * writeUint32(uint32_t value, void *buffer, size_t length)
Write Unsigned 32-Bit Integer to Buffer.
uint32_t readUint32(const void *buffer, size_t length)
Read Unsigned 32-Bit Integer from Buffer.
uint8_t * writeUint16(uint16_t value, void *buffer, size_t length)
Write Unsigned 16-Bit Integer to Buffer.
uint16_t readUint16(const void *buffer, size_t length)
Read Unsigned 16-Bit Integer from Buffer.
Defines the logger used by the top-level component of kea-lfc.
Trait class for data types supported in DHCP option definitions.
static const bool integer_type
static const OptionDataType type
Encapsulation of option definition parameters and the structure size.
const struct OptionDefParams * optionDefParams
Parameters being used to make up an option definition.
const char * encapsulates
const OptionDataType * records