7#ifndef OPTION_DATA_TYPES_H
8#define OPTION_DATA_TYPES_H
96 static const bool valid =
false;
97 static const int len = 0;
115 static const int len =
sizeof(uint8_t);
218 : psid_len_(psid_len) {
219 if (psid_len_ >
sizeof(uint16_t) * 8) {
239 return (
static_cast<unsigned>(psid_len_));
260 explicit PSID(
const uint16_t psid)
294 : prefix_len_(prefix_len) {
299 return (prefix_len_);
308 return (
static_cast<unsigned>(prefix_len_));
380 std::vector<uint8_t>& buf);
387 static void writeBinary(
const std::string& hex_str,
388 std::vector<uint8_t>& buf);
397 static std::string
readTuple(
const std::vector<uint8_t>& buf,
406 static void readTuple(
const std::vector<uint8_t>& buf,
414 static void writeTuple(
const std::string& value,
416 std::vector<uint8_t>& buf);
423 std::vector<uint8_t>& buf);
442 static bool readBool(
const std::vector<uint8_t>& buf);
451 static void writeBool(
const bool value, std::vector<uint8_t>& buf);
462 static T
readInt(
const std::vector<uint8_t>& buf) {
465 " by readInteger is unsupported integer type");
470 "failed to read an integer value from a buffer"
471 <<
" - buffer is truncated.");
477 value = *(buf.begin());
493 "invalid size of the data type to be read as integer.");
505 std::vector<uint8_t>& buf) {
511 buf.push_back(
static_cast<uint8_t
>(value));
514 buf.resize(buf.size() + 2);
518 buf.resize(buf.size() + 4);
539 static std::string
readFqdn(
const std::vector<uint8_t>& buf);
555 static void writeFqdn(
const std::string& fqdn,
556 std::vector<uint8_t>& buf,
557 const bool downcase =
false);
568 static unsigned int getLabelCount(
const std::string& text_name);
592 std::vector<uint8_t>& buf);
621 std::vector<uint8_t>& buf);
630 static std::string
readString(
const std::vector<uint8_t>& buf);
637 std::vector<uint8_t>& buf);
642 std::map<std::string, OptionDataType> data_types_;
646 std::map<OptionDataType, std::string> data_type_names_;
668 OptionDataType getDataTypeImpl(
const std::string& data_type)
const;
674 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 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.
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