Kea: RRType Class Reference

| Kea 3.2.0-git

RRType Class Reference

The `RRType` class encapsulates DNS resource record types. More...

`#include <rrtype.h>`

## Public Member Functions
Constructors and Destructor
| RRType (uint16_t typecode)
| Constructor from an integer type code.
| RRType (const std::string &typestr)
| Constructor from a string.
| RRType (isc::util::InputBuffer &buffer)
| Constructor from wire-format data.
Converter methods
We use the default copy constructor intentionally. We use the default copy assignment operator intentionally.
const std::string | toText () const
| Convert the `RRType` to a string.
void | toWire (AbstractMessageRenderer &renderer) const
| Render the `RRType` in the wire format.
void | toWire (isc::util::OutputBuffer &buffer) const
| Render the `RRType` in the wire format.
Getter Methods
uint16_t | getCode () const
| Returns the RR type code as a 16-bit unsigned integer.

## Comparison methods
bool | equals (const RRType &other) const
| Return true iff two RRTypes are equal.
bool | operator== (const RRType &other) const
| Same as `equals()`.
bool | nequals (const RRType &other) const
| Return true iff two RRTypes are not equal.
bool | operator!= (const RRType &other) const
| Same as `nequals()`.
bool | operator< (const RRType &other) const
| Less-than comparison for RRType against `other`.
static const RRType & | A ()
static const RRType & | NS ()
static const RRType & | SOA ()
static const RRType & | OPT ()
static const RRType & | PTR ()
static const RRType & | TXT ()
static const RRType & | AAAA ()
static const RRType & | RRSIG ()
static const RRType & | DHCID ()
static const RRType & | TKEY ()
static const RRType & | TSIG ()
static const RRType & | ANY ()

## Detailed Description

The `RRType` class encapsulates DNS resource record types.

This class manages the 16-bit integer type codes in quite a straightforward way. The only non trivial task is to handle textual representations of RR types, such as "A", "AAAA", or "TYPE65534".

This class consults a helper `RRParamRegistry` class, which is a registry of RR related parameters and has the singleton object. This registry provides a mapping between RR type codes and their "well-known" textual representations. Parameters of RR types defined by DNS protocol standards are automatically registered at initialization time and are ensured to be always available for applications unless the application explicitly modifies the registry.

For convenience, this class defines constant class objects corresponding to standard RR types. These are generally referred to as the form of `RRType::{type-text}()`. For example, `RRType::NS()` is an `RRType` object corresponding to the NS resource record (type code 2). Note that these constants are used through a "proxy" function. This is because they may be used to initialize another non-local (e.g. global or namespace-scope) static object as follows:

namespace foo {
const RRType default_type = RRType::A();
}
RRType::RRType
RRType(uint16_t typecode)
Constructor from an integer type code.
Definition rrtype.h:107
RRType::A
static const RRType & A()
Definition rrtype.h:279

In order to ensure that the constant RRType object has been initialized before the initialization for `default_type`, we need help from the proxy function.

In the current implementation, the initialization of the well-known static objects is not thread safe. The same consideration as the `RRParamRegistry` class applies. We may extend the implementation so that the initialization is ensured to be thread safe in a future version.

Note to developers: since it's expected that some of these constant `RRType` objects are frequently used in a performance sensitive path, we define these proxy functions as inline. This makes sense only when the corresponding static objects are defined only once even if they used in different source files. Sufficiently modern compilers should meet this assumption, but if we encounter memory bloat due to this problem with particular compilers we need to revisit the design or think about workaround.

Definition at line 96 of file rrtype.h.

## Constructor & Destructor Documentation

## ◆ RRType() [1/3]

isc::dns::RRType::RRType | ( | uint16_t | typecode | ) |
| inlineexplicit

Constructor from an integer type code.

This constructor never throws an exception.

Parameters

  typecode | An 16-bit integer code corresponding to the RRType.

Definition at line 107 of file rrtype.h.

## ◆ RRType() [2/3]

isc::dns::RRType::RRType | ( | const std::string & | typestr | ) |
| explicit

Constructor from a string.

A valid string is one of "well-known" textual type representations such as "A", "AAAA", or "NS", or in the standard format for "unknown" RR types as defined in RFC3597, i.e., "TYPEnnnn".

More precisely, the "well-known" representations are the ones stored in the `RRParamRegistry` registry (see the class description).

As for the format of "TYPEnnnn", "nnnn" must represent a valid 16-bit unsigned integer, which may contain leading 0's as long as it consists of at most 5 characters (inclusive). For example, "TYPE1" and "TYPE001" are valid and represent the same RR type, but "TYPE65536" and "TYPE000001" are invalid. A "TYPEnnnn" representation is valid even if the corresponding type code is registered in the `RRParamRegistry` object. For example, both "A" and "TYPE1" are valid and represent the same RR type.

All of these representations are case insensitive; "NS" and "ns", and "TYPE1" and "type1" are all valid and represent the same RR types, respectively.

If the given string is not recognized as a valid representation of an RR type, an exception of class `InvalidRRType` will be thrown.

Parameters

  typestr | A string representation of the `RRType`

Definition at line 27 of file rrtype.cc.

## ◆ RRType() [3/3]

isc::dns::RRType::RRType | ( | isc::util::InputBuffer & | buffer | ) |
| explicit

Constructor from wire-format data.

The `buffer` parameter normally stores a complete DNS message containing the RRType to be constructed. The current read position of the buffer points to the head of the type.

If the given data does not large enough to contain a 16-bit integer, an exception of class `IncompleteRRType` will be thrown.

Parameters

  buffer | A buffer storing the wire format data.

Definition at line 36 of file rrtype.cc.

## Member Function Documentation

## ◆ A()

const RRType & isc::dns::RRType::A | ( |  | ) |
| inlinestatic

Definition at line 279 of file rrtype.h.

## ◆ AAAA()

const RRType & isc::dns::RRType::AAAA | ( |  | ) |
| inlinestatic

Definition at line 315 of file rrtype.h.

## ◆ ANY()

const RRType & isc::dns::RRType::ANY | ( |  | ) |
| inlinestatic

Definition at line 345 of file rrtype.h.

## ◆ DHCID()

const RRType & isc::dns::RRType::DHCID | ( |  | ) |
| inlinestatic

Definition at line 327 of file rrtype.h.

## ◆ equals()

bool isc::dns::RRType::equals | ( | const RRType & | other | ) | const
| inline

Return true iff two RRTypes are equal.

Two RRTypes are equal iff their type codes are equal.

This method never throws an exception.

Parameters

  other | the `RRType` object to compare against.

Returns
  true if the two RRTypes are equal; otherwise false.

Definition at line 219 of file rrtype.h.

## ◆ getCode()

uint16_t isc::dns::RRType::getCode | ( |  | ) | const
| inline

Returns the RR type code as a 16-bit unsigned integer.

This method never throws an exception.

Returns
  An 16-bit integer code corresponding to the RRType.

Definition at line 202 of file rrtype.h.

## ◆ nequals()

bool isc::dns::RRType::nequals | ( | const RRType & | other | ) | const
| inline

Return true iff two RRTypes are not equal.

This method never throws an exception.

Parameters

  other | the `RRType` object to compare against.

Returns
  true if the two RRTypes are not equal; otherwise false.

Definition at line 233 of file rrtype.h.

## ◆ NS()

const RRType & isc::dns::RRType::NS | ( |  | ) |
| inlinestatic

Definition at line 285 of file rrtype.h.

## ◆ operator!=()

bool isc::dns::RRType::operator!= | ( | const RRType & | other | ) | const
| inline

Same as `nequals()`.

Definition at line 237 of file rrtype.h.

## ◆ operator<()

bool isc::dns::RRType::operator< | ( | const RRType & | other | ) | const
| inline

Less-than comparison for RRType against `other`.

We define the less-than relationship based on their type codes; one RRType is less than the other iff the code of the former is less than that of the other as unsigned integers. The relationship is meaningless in terms of DNS protocol; the only reason we define this method is that RRType objects can be stored in STL containers without requiring user-defined less-than relationship. We therefore don't define other comparison operators.

This method never throws an exception.

Parameters

  other | the `RRType` object to compare against.

Returns
  true if `this` RRType is less than the `other`; otherwise false.

Definition at line 256 of file rrtype.h.

## ◆ operator==()

bool isc::dns::RRType::operator== | ( | const RRType & | other | ) | const
| inline

Same as `equals()`.

Definition at line 223 of file rrtype.h.

## ◆ OPT()

const RRType & isc::dns::RRType::OPT | ( |  | ) |
| inlinestatic

Definition at line 297 of file rrtype.h.

## ◆ PTR()

const RRType & isc::dns::RRType::PTR | ( |  | ) |
| inlinestatic

Definition at line 303 of file rrtype.h.

## ◆ RRSIG()

const RRType & isc::dns::RRType::RRSIG | ( |  | ) |
| inlinestatic

Definition at line 321 of file rrtype.h.

## ◆ SOA()

const RRType & isc::dns::RRType::SOA | ( |  | ) |
| inlinestatic

Definition at line 291 of file rrtype.h.

## ◆ TKEY()

const RRType & isc::dns::RRType::TKEY | ( |  | ) |
| inlinestatic

Definition at line 333 of file rrtype.h.

## ◆ toText()

const string isc::dns::RRType::toText | ( |  | ) | const

Convert the `RRType` to a string.

If a "well known" textual representation for the type code is registered in the RR parameter registry (see the class description), that will be used as the return value of this method. Otherwise, this method creates a new string for an "unknown" RR type in the format defined in RFC3597, i.e., "TYPEnnnn", and returns it.

If resource allocation for the string fails, a corresponding standard exception will be thrown.

Returns
  A string representation of the `RRType`.

Definition at line 44 of file rrtype.cc.

## ◆ toWire() [1/2]

void isc::dns::RRType::toWire | ( | AbstractMessageRenderer & | renderer | ) | const

Render the `RRType` in the wire format.

This method renders the type code in network byte order via `renderer`, which encapsulates output buffer and other rendering contexts.

If resource allocation in rendering process fails, a corresponding standard exception will be thrown.

Parameters

  renderer | DNS message rendering context that encapsulates the output buffer in which the RRType is to be stored.

Definition at line 54 of file rrtype.cc.

## ◆ toWire() [2/2]

void isc::dns::RRType::toWire | ( | isc::util::OutputBuffer & | buffer | ) | const

Render the `RRType` in the wire format.

This method renders the type code in network byte order into the `buffer`.

If resource allocation in rendering process fails, a corresponding standard exception will be thrown.

Parameters

  buffer | An output buffer to store the wire data.

Definition at line 49 of file rrtype.cc.

## ◆ TSIG()

const RRType & isc::dns::RRType::TSIG | ( |  | ) |
| inlinestatic

Definition at line 339 of file rrtype.h.

## ◆ TXT()

const RRType & isc::dns::RRType::TXT | ( |  | ) |
| inlinestatic

Definition at line 309 of file rrtype.h.

The documentation for this class was generated from the following files:

- rrtype.h
- rrtype.cc