Kea 2.7.5
isc::asiolink::IOAddress Class Reference

The IOAddress class represents an IP addresses (version agnostic) More...

#include <io_address.h>

Classes

struct  Hash
 An IOAddress hash enabling the use in the unordered STL containers. More...
 

Methods returning @c IOAddress objects encapsulating typical addresses.

static const IOAddressIPV4_ZERO_ADDRESS ()
 Returns an address set to all zeros.
 
static const IOAddressIPV4_BCAST_ADDRESS ()
 Returns a "255.255.255.255" broadcast address.
 
static const IOAddressIPV6_ZERO_ADDRESS ()
 Returns an IPv6 zero address.
 

Constructors and Destructor

This class is copyable.

We use default versions of copy constructor and the assignment operator. We use the default destructor.

 IOAddress (const std::string &address_str)
 Constructor from string.
 
 IOAddress (const boost::asio::ip::address &asio_address)
 Constructor from an ASIO ip::address object.
 
 IOAddress (uint32_t v4address)
 Constructor for ip::address_v4 object.
 
std::string toText () const
 Convert the address to a string.
 
short getFamily () const
 Returns the address family.
 
bool isV4 () const
 Convenience function to check for an IPv4 address.
 
bool isV4Zero () const
 Convenience function to check if it is an IPv4 zero address.
 
bool isV4Bcast () const
 Convenience function to check if it is an IPv4 broadcast address.
 
bool isV6 () const
 Convenience function to check for an IPv6 address.
 
bool isV6Zero () const
 Convenience function to check if it is an IPv4 zero address.
 
bool isV6LinkLocal () const
 checks whether and address is IPv6 and is link-local
 
bool isV6Multicast () const
 checks whether and address is IPv6 and is multicast
 
std::vector< uint8_t > toBytes () const
 Return address as set of bytes.
 
bool equals (const IOAddress &other) const
 Compare addresses for equality.
 
bool operator== (const IOAddress &other) const
 Compare addresses for equality.
 
bool nequals (const IOAddress &other) const
 Compare addresses for inequality.
 
bool operator< (const IOAddress &other) const
 Checks if one address is smaller than the other.
 
bool operator<= (const IOAddress &other) const
 Checks if one address is smaller or equal than the other.
 
bool operator!= (const IOAddress &other) const
 Compare addresses for inequality.
 
uint32_t toUint32 () const
 Converts IPv4 address to uint32_t.
 
static IOAddress fromBytes (short family, const uint8_t *data)
 Creates an address from over wire data.
 
static IOAddress subtract (const IOAddress &a, const IOAddress &b)
 Subtracts one address from another (a - b)
 
static IOAddress increase (const IOAddress &addr)
 Returns an address increased by one.
 

Detailed Description

The IOAddress class represents an IP addresses (version agnostic)

This class is a wrapper for the ASIO ip::address class.

Definition at line 45 of file io_address.h.

Constructor & Destructor Documentation

◆ IOAddress() [1/3]

isc::asiolink::IOAddress::IOAddress ( const std::string & address_str)

Constructor from string.

This constructor converts a textual representation of IPv4 and IPv6 addresses into an IOAddress object. If address_str is not a valid representation of any type of address, an exception of class IOError will be thrown. This constructor allocates memory for the object, and if that fails a corresponding standard exception will be thrown.

Parameters
address_strTextual representation of address.

Definition at line 38 of file io_address.cc.

References isc_throw.

Referenced by fromBytes(), and subtract().

◆ IOAddress() [2/3]

isc::asiolink::IOAddress::IOAddress ( const boost::asio::ip::address & asio_address)

Constructor from an ASIO ip::address object.

This constructor is intended to be used within the wrapper implementation; user applications of the wrapper API won't use it.

This constructor never throws an exception.

Parameters
asio_addressThe ASIO ip::address to be converted.

Definition at line 47 of file io_address.cc.

◆ IOAddress() [3/3]

isc::asiolink::IOAddress::IOAddress ( uint32_t v4address)

Constructor for ip::address_v4 object.

This constructor is intended to be used when constructing IPv4 address out of uint32_t type. Passed value must be in host byte order.

Parameters
v4addressIPv4 address represented by uint32_t

Definition at line 51 of file io_address.cc.

Member Function Documentation

◆ equals()

bool isc::asiolink::IOAddress::equals ( const IOAddress & other) const
inline

Compare addresses for equality.

Parameters
otherAddress to compare against.
Returns
true if addresses are equal, false if not.

Definition at line 176 of file io_address.h.

Referenced by isV4Bcast(), isV4Zero(), isV6Zero(), nequals(), and operator==().

◆ fromBytes()

IOAddress isc::asiolink::IOAddress::fromBytes ( short family,
const uint8_t * data )
static

Creates an address from over wire data.

Parameters
familyAF_INET for IPv4 or AF_INET6 for IPv6.
datapointer to first char of data
Returns
Created IOAddress object

Definition at line 62 of file io_address.cc.

References IOAddress(), and isc_throw.

Referenced by isc::dhcp::TokenIpAddressToText::evaluate(), isc::dhcp::Option6PDExclude::getExcludedPrefix(), increase(), isc::dhcp::IterativeAllocator::increasePrefix(), isc::dhcp::CfgSubnets4::initSelector(), isc::asiolink::offsetAddress(), isc::dhcp::OptionDataTypeUtil::readAddress(), isc::dhcp::OptionDataTypeUtil::readPrefix(), subtract(), isc::dhcp::Option6AddrLst::unpack(), isc::dhcp::Option6IAAddr::unpack(), isc::dhcp::Option6IAPrefix::unpack(), isc::dhcp::Option6Dnr::unpackAddresses(), and isc::dhcp::Pkt6::unpackRelayMsg().

+ Here is the call graph for this function:

◆ getFamily()

short isc::asiolink::IOAddress::getFamily ( ) const

Returns the address family.

Returns
AF_INET for IPv4 or AF_INET6 for IPv6.

Definition at line 92 of file io_address.cc.

Referenced by isc::dhcp::AddressRange::AddressRange(), isc::lease_cmds::LeaseCmdsImpl::getAddressParam(), increase(), subtract(), and isc::dhcp::D2ClientConfig::validateContents().

◆ increase()

IOAddress isc::asiolink::IOAddress::increase ( const IOAddress & addr)
static

Returns an address increased by one.

This method works for both IPv4 and IPv6 addresses. For example, increase 192.0.2.255 will become 192.0.3.0.

Address space is a finite field in the mathematical sense, so keep in mind that the address space "loops". 255.255.255.255 increased by one gives 0.0.0.0. The same is true for maximum value of IPv6 (all 1's) looping to ::.

Todo
Determine if we have a use-case for increasing the address by more than one. Increase by one is used in AllocEngine. This method could take extra parameter that specifies the value by which the address should be increased.
Parameters
addraddress to be increased
Returns
address increased by one

Definition at line 167 of file io_address.cc.

References fromBytes(), getFamily(), and toBytes().

Referenced by isc::asiolink::addrsInRange(), and isc::dhcp::IterativeAllocator::increaseAddress().

+ Here is the call graph for this function:

◆ IPV4_BCAST_ADDRESS()

static const IOAddress & isc::asiolink::IOAddress::IPV4_BCAST_ADDRESS ( )
inlinestatic

Returns a "255.255.255.255" broadcast address.

Definition at line 283 of file io_address.h.

Referenced by isc::dhcp::Dhcpv4Srv::adjustRemoteAddr(), and isV4Bcast().

◆ IPV4_ZERO_ADDRESS()

◆ IPV6_ZERO_ADDRESS()

◆ isV4()

◆ isV4Bcast()

bool isc::asiolink::IOAddress::isV4Bcast ( ) const
inline

Convenience function to check if it is an IPv4 broadcast address.

Returns
true if the address is the broadcast IPv4 address.

Definition at line 129 of file io_address.h.

References equals(), and IPV4_BCAST_ADDRESS().

Referenced by isc::dhcp::Pkt4::isRelayed().

+ Here is the call graph for this function:

◆ isV4Zero()

bool isc::asiolink::IOAddress::isV4Zero ( ) const
inline

Convenience function to check if it is an IPv4 zero address.

Returns
true if the address is the zero IPv4 address.

Definition at line 121 of file io_address.h.

References equals(), and IPV4_ZERO_ADDRESS().

Referenced by isc::dhcp::Dhcpv4Srv::buildCfgOptionList(), isc::dhcp::Dhcpv4Srv::evaluateAdditionalClasses(), isc::dhcp::Pkt4::isRelayed(), and isc::dhcp::Host::toText().

+ Here is the call graph for this function:

◆ isV6()

◆ isV6LinkLocal()

bool isc::asiolink::IOAddress::isV6LinkLocal ( ) const

checks whether and address is IPv6 and is link-local

Returns
true if the address is IPv6 link-local, false otherwise

Definition at line 101 of file io_address.cc.

Referenced by isc::dhcp::Pkt::getMACFromIPv6(), isc::dhcp::PktFilterInet6::openSocket(), and isc::dhcp::CfgIface::use().

◆ isV6Multicast()

bool isc::asiolink::IOAddress::isV6Multicast ( ) const

checks whether and address is IPv6 and is multicast

Returns
true if the address is IPv6 multicast, false otherwise

Definition at line 109 of file io_address.cc.

Referenced by isc::dhcp::PktFilterInet6::openSocket(), and isc::dhcp::CfgIface::use().

◆ isV6Zero()

bool isc::asiolink::IOAddress::isV6Zero ( ) const
inline

Convenience function to check if it is an IPv4 zero address.

Returns
true if the address is the zero IPv4 address.

Definition at line 143 of file io_address.h.

References equals(), and IPV6_ZERO_ADDRESS().

+ Here is the call graph for this function:

◆ nequals()

bool isc::asiolink::IOAddress::nequals ( const IOAddress & other) const
inline

Compare addresses for inequality.

Parameters
otherAddress to compare against.
Returns
false if addresses are equal, true if not.

Definition at line 194 of file io_address.h.

References equals().

Referenced by operator!=().

+ Here is the call graph for this function:

◆ operator!=()

bool isc::asiolink::IOAddress::operator!= ( const IOAddress & other) const
inline

Compare addresses for inequality.

Parameters
otherAddress to compare against.
Returns
false if addresses are equal, true if not.

Definition at line 217 of file io_address.h.

References nequals().

+ Here is the call graph for this function:

◆ operator<()

bool isc::asiolink::IOAddress::operator< ( const IOAddress & other) const
inline

Checks if one address is smaller than the other.

Parameters
otherAddress to compare against.

Definition at line 201 of file io_address.h.

◆ operator<=()

bool isc::asiolink::IOAddress::operator<= ( const IOAddress & other) const
inline

Checks if one address is smaller or equal than the other.

Parameters
otherAddress to compare against.

Definition at line 208 of file io_address.h.

◆ operator==()

bool isc::asiolink::IOAddress::operator== ( const IOAddress & other) const
inline

Compare addresses for equality.

Parameters
otherAddress to compare against.
Returns
true if addresses are equal, false if not.

Definition at line 185 of file io_address.h.

References equals().

+ Here is the call graph for this function:

◆ subtract()

IOAddress isc::asiolink::IOAddress::subtract ( const IOAddress & a,
const IOAddress & b )
static

Subtracts one address from another (a - b)

Treats addresses as integers and subtracts them. For example:

192.0.2.5 - 192.0.2.0 = 0.0.0.5
fe80::abcd - fe80:: = ::abcd

It is possible to subtract greater from lesser address, e.g. 192.168.56.10 - 192.168.67.20, but please do understand that the address space is a finite field in mathematical sense, so you may end up with a result that is greater then any of the addresses you specified. Also, subtraction is not commutative, so a - b != b - a.

This operation is essential for calculating the number of leases in a pool, where we need to calculate (max - min).

Exceptions
BadValueif addresses are of different family
Parameters
aaddress to be subtracted from
baddress to be subtracted
Returns
IOAddress object that represents the difference

Definition at line 133 of file io_address.cc.

References IOAddress(), fromBytes(), getFamily(), isc_throw, toBytes(), and toUint32().

Referenced by isc::asiolink::addrsInRange().

+ Here is the call graph for this function:

◆ toBytes()

std::vector< uint8_t > isc::asiolink::IOAddress::toBytes ( ) const

◆ toText()

string isc::asiolink::IOAddress::toText ( ) const

Convert the address to a string.

This method is basically expected to be exception free, but generating the string will involve resource allocation, and if it fails the corresponding standard exception will be thrown.

Returns
A string representation of the address.

Definition at line 57 of file io_address.cc.

Referenced by isc::db::PsqlBindArray::add(), isc::dhcp::Network::RelayInfo::addAddress(), isc::db::PsqlBindArray::addInet4(), isc::db::PsqlBindArray::addInet6(), isc::perfdhcp::TestControl::address6Uniqueness(), isc::dhcp::CfgHosts::del(), isc::dhcp::Subnet6ConfigParser::duplicateOptionWarning(), isc::dhcp::HostMgr::get6(), isc::yang::TranslatorPool::getAddresses(), getAddrStrIA_NA(), getAddrStrIA_PD(), isc::dhcp::Memfile_LeaseMgr::getLease4(), isc::dhcp::Memfile_LeaseMgr::getLease6(), isc::lease_cmds::LeaseCmdsImpl::lease4ResendDdnsHandler(), isc::lease_cmds::LeaseCmdsImpl::lease6ResendDdnsHandler(), isc::dhcp::CSVLeaseFile4::next(), isc::dhcp::PktFilterInet6::openSocket(), isc::dhcp::PktFilterInet::openSocket(), isc::dhcp::PktFilterLPF::openSocket(), isc::lease_cmds::Lease4Parser::parse(), isc::lease_cmds::Lease6Parser::parse(), pkt4_send(), isc::dhcp::Dhcpv4Srv::processDecline(), isc::config::HttpCommandConfig::toElement(), isc::d2::DnsServerInfo::toElement(), isc::dhcp::ClientClassDef::toElement(), isc::dhcp::D2ClientConfig::toElement(), isc::dhcp::Lease4::toElement(), isc::dhcp::Lease6::toElement(), isc::dhcp::Pool4::toElement(), isc::dhcp::Pool6::toElement(), isc::d2::D2Params::toText(), isc::dhcp::D2ClientConfig::toText(), isc::dhcp::Host::toText(), toUint32(), isc::dhcp::ResourceHandler::unLock(), isc::dhcp::CfgIface::use(), and isc::dhcp::D2ClientConfig::validateContents().

◆ toUint32()

uint32_t isc::asiolink::IOAddress::toUint32 ( ) const

Converts IPv4 address to uint32_t.

Will throw BadValue exception if that is not IPv4 address.

Returns
uint32_t that represents IPv4 address in network byte order

Definition at line 117 of file io_address.cc.

References isc_throw, and toText().

Referenced by isc::db::PsqlBindArray::add(), isc::dhcp::IfaceMgr::collectBoundAddresses(), isc::dhcp::IfaceMgr::hasOpenSocket(), isc::asiolink::offsetAddress(), isc::dhcp::PktFilter::openFallbackSocket(), isc::dhcp::PktFilterBPF::openSocket(), isc::dhcp::PktFilterInet::openSocket(), isc::dhcp::PktFilterLPF::openSocket(), isc::dhcp::Pkt4::pack(), and subtract().

+ Here is the call graph for this function:

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