Kea 2.7.6
|
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 IOAddress & | IPV4_ZERO_ADDRESS () |
Returns an address set to all zeros. | |
static const IOAddress & | IPV4_BCAST_ADDRESS () |
Returns a "255.255.255.255" broadcast address. | |
static const IOAddress & | IPV6_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. | |
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.
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.
address_str | Textual representation of address. |
Definition at line 38 of file io_address.cc.
References isc_throw.
Referenced by fromBytes(), and subtract().
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.
asio_address | The ASIO ip::address to be converted. |
Definition at line 47 of file io_address.cc.
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.
v4address | IPv4 address represented by uint32_t |
Definition at line 51 of file io_address.cc.
|
inline |
Compare addresses for equality.
other | Address to compare against. |
Definition at line 176 of file io_address.h.
Referenced by isV4Bcast(), isV4Zero(), isV6Zero(), nequals(), and operator==().
|
static |
Creates an address from over wire data.
family | AF_INET for IPv4 or AF_INET6 for IPv6. |
data | pointer to first char of data |
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().
short isc::asiolink::IOAddress::getFamily | ( | ) | const |
Returns the address family.
Definition at line 92 of file io_address.cc.
Referenced by isc::dhcp::AddressRange::AddressRange(), isc::asiolink::addrsInRange(), isc::lease_cmds::LeaseCmdsImpl::getAddressParam(), increase(), isc::perfdhcp::PerfSocket::openSocket(), isc::dhcp::ClientClassDefParser::parse(), isc::dhcp::D2ClientConfigParser::parse(), isc::asiolink::prefixLengthFromRange(), subtract(), and isc::dhcp::D2ClientConfig::validateContents().
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 ::.
addr | address to be increased |
Definition at line 167 of file io_address.cc.
References fromBytes(), getFamily(), and toBytes().
Referenced by isc::asiolink::addrsInRange(), and isc::dhcp::IterativeAllocator::increaseAddress().
|
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().
|
inlinestatic |
Returns an address set to all zeros.
Definition at line 277 of file io_address.h.
Referenced by isc::ha::HAService::HAService(), isc::dhcp::Dhcpv4Srv::adjustIfaceData(), isc::dhcp::Dhcpv4Srv::assignLease(), isc::dhcp::Dhcpv4Srv::buildCfgOptionList(), isc::dhcp::HostMgr::cacheNegative(), isc::dhcp::Dhcpv4Srv::evaluateAdditionalClasses(), isc::dhcp::Network4::getServerId(), isV4Zero(), isc::dhcp::IPRangePermutation::next(), isc::dhcp::PoolFreeLeaseQueueAllocationState::offerFreeLease(), isc::dhcp::D2ClientConfigParser::parse(), isc::dhcp::Dhcpv4Srv::processInform(), isc::dhcp::Host::removeIPv4Reservation(), isc::dhcp::CfgSubnets4::selectSubnet(), and isc::dhcp::Dhcpv4Srv::setFixedFields().
|
inlinestatic |
Returns an IPv6 zero address.
Definition at line 289 of file io_address.h.
Referenced by isc::dhcp::Pool6::Pool6(), isc::dhcp::Dhcpv6Srv::assignIA_NA(), isc::dhcp::Dhcpv6Srv::assignIA_PD(), isV6Zero(), isc::lease_cmds::LeaseCmdsImpl::lease6DelHandler(), isc::dhcp::IPRangePermutation::next(), isc::dhcp::PoolFreeLeaseQueueAllocationState::offerFreeLease(), isc::dhcp::D2ClientConfigParser::parse(), and isc::dhcp::OptionDataTypeUtil::readPrefix().
|
inline |
Convenience function to check for an IPv4 address.
Definition at line 114 of file io_address.h.
Referenced by isc::dhcp::Pool4::Pool4(), isc::dhcp::Pool4::Pool4(), isc::dhcp::Subnet::Subnet(), isc::dhcp::Subnet4::Subnet4(), isc::dhcp::Dhcpv4Srv::acceptServerId(), isc::db::PsqlBindArray::add(), isc::dhcp::Option4AddrLst::addAddress(), isc::dhcp::OptionCustom::addArrayDataField(), isc::db::PsqlBindArray::addInet4(), isc::asiolink::addrsInRange(), isc::dhcp::IfaceMgr::collectBoundAddresses(), isc::dhcp::SubnetConfigParser::createSubnet(), isc::dhcp::CfgHosts::del(), isc::asiolink::firstAddrInPrefix(), isc::dhcp::D2ClientMgr::generateFqdn(), isc::db::PgSqlExchange::getInetValue4(), isc::dhcp::Memfile_LeaseMgr::getLeases4(), isc::dhcp::Memfile_LeaseMgr::getLeases4ByRelayId(), isc::dhcp::Memfile_LeaseMgr::getLeases4ByRemoteId(), isc::lease_cmds::LeaseCmdsImpl::getParameters(), isc::asiolink::hash_value(), isc::dhcp::IfaceMgr::hasOpenSocket(), isc::asiolink::lastAddrInPrefix(), isc::dhcp::IPRangePermutation::next(), isc::asiolink::offsetAddress(), isc::dhcp_ddns::NameChangeUDPListener::open(), isc::dhcp_ddns::NameChangeUDPSender::open(), isc::dhcp::IfaceMgr::openSocket(), isc::dhcp::D2ClientConfigParser::parse(), isc::lease_cmds::Lease4Parser::parse(), isc::lease_cmds::Lease6Parser::parse(), isc::asiolink::prefixLengthFromRange(), isc::d2::D2CfgMgr::reverseIpAddress(), isc::d2::D2CfgMgr::reverseV4Address(), isc::perfdhcp::TestControl::sendRequest4(), isc::perfdhcp::TestControl::sendRequest4(), isc::dhcp::Option4AddrLst::setAddress(), isc::dhcp::Host::setIPv4Reservation(), isc::dhcp::Host::setNextServer(), subtract(), isc::dhcp::CfgIface::use(), isc::dhcp::D2ClientConfig::validateContents(), and isc::dhcp::OptionCustom::writeAddress().
|
inline |
Convenience function to check if it is an IPv4 broadcast address.
Definition at line 129 of file io_address.h.
References equals(), and IPV4_BCAST_ADDRESS().
Referenced by isc::dhcp::Dhcpv4Srv::adjustIfaceData(), isc::dhcp::Dhcpv4Srv::appendServerID(), isc::dhcp::Pkt4::isRelayed(), isc::dhcp::ClientClassDefParser::parse(), isc::dhcp::CfgSubnets4::selectSubnet(), isc::dhcp::Host::setIPv4Reservation(), and isc::dhcp::Host::setNextServer().
|
inline |
Convenience function to check if it is an IPv4 zero address.
Definition at line 121 of file io_address.h.
References equals(), and IPV4_ZERO_ADDRESS().
Referenced by isc::dhcp::Host::Host(), isc::dhcp::Host::Host(), isc::dhcp::Dhcpv4Srv::buildCfgOptionList(), isc::dhcp::Dhcpv4Srv::evaluateAdditionalClasses(), isc::dhcp::Pkt4::isRelayed(), isc::dhcp::CfgSubnets4::selectSubnet(), isc::dhcp::Dhcpv4Srv::setFixedFields(), isc::dhcp::Host::setIPv4Reservation(), isc::dhcp::Host::toElement4(), isc::dhcp::Host::toText(), and isc::dhcp::Subnet4ConfigParser::validateResv().
|
inline |
Convenience function to check for an IPv6 address.
Definition at line 136 of file io_address.h.
Referenced by isc::dhcp::Option6IAAddr::Option6IAAddr(), isc::dhcp::Option6PDExclude::Option6PDExclude(), isc::dhcp::Pool6::Pool6(), isc::dhcp::Pool6::Pool6(), isc::dhcp::PrefixRange::PrefixRange(), isc::dhcp::PrefixRange::PrefixRange(), isc::dhcp::Subnet::Subnet(), isc::dhcp::Subnet6::Subnet6(), isc::dhcp::OptionCustom::addArrayDataField(), isc::db::PsqlBindArray::addInet6(), isc::dhcp::SubnetConfigParser::createSubnet(), isc::db::PgSqlExchange::getInetValue6(), isc::dhcp::Memfile_LeaseMgr::getLeases6(), isc::dhcp::Memfile_LeaseMgr::getLeases6(), isc::dhcp::Memfile_LeaseMgr::getLeases6ByRelayId(), isc::dhcp::Memfile_LeaseMgr::getLeases6ByRemoteId(), isc::lease_cmds::LeaseCmdsImpl::getParameters(), isc::dhcp::IterativeAllocator::increasePrefix(), isc::dhcp::IfaceMgr::openSocket(), isc::dhcp::Option6IAAddr::pack(), isc::dhcp::Option6IAPrefix::pack(), isc::d2::D2CfgMgr::reverseV6Address(), isc::dhcp::IPv6Resrv::set(), isc::dhcp::Option6AddrLst::setAddress(), isc::dhcp::LeaseMgr::upgradeLease6ExtendedInfo(), isc::dhcp::CfgIface::use(), isc::dhcp::OptionCustom::writeAddress(), and isc::dhcp::OptionDataTypeUtil::writePrefix().
bool isc::asiolink::IOAddress::isV6LinkLocal | ( | ) | const |
checks whether and address is IPv6 and is link-local
Definition at line 101 of file io_address.cc.
Referenced by isc::dhcp::Pkt::getMACFromIPv6(), isc::dhcp::PktFilterInet6::openSocket(), and isc::dhcp::CfgIface::use().
bool isc::asiolink::IOAddress::isV6Multicast | ( | ) | const |
checks whether and address is IPv6 and is multicast
Definition at line 109 of file io_address.cc.
Referenced by isc::dhcp::PktFilterInet6::openSocket(), isc::perfdhcp::PerfSocket::openSocket(), isc::dhcp::IPv6Resrv::set(), and isc::dhcp::CfgIface::use().
|
inline |
Convenience function to check if it is an IPv4 zero address.
Definition at line 143 of file io_address.h.
References equals(), and IPV6_ZERO_ADDRESS().
Referenced by isc::dhcp::Pool6::Pool6(), and isc::lease_cmds::LeaseCmdsImpl::createFailedLeaseMap().
|
inline |
Compare addresses for inequality.
other | Address to compare against. |
Definition at line 194 of file io_address.h.
References equals().
Referenced by operator!=().
|
inline |
Compare addresses for inequality.
other | Address to compare against. |
Definition at line 217 of file io_address.h.
References nequals().
|
inline |
Checks if one address is smaller than the other.
other | Address to compare against. |
Definition at line 201 of file io_address.h.
|
inline |
Checks if one address is smaller or equal than the other.
other | Address to compare against. |
Definition at line 208 of file io_address.h.
|
inline |
Compare addresses for equality.
other | Address to compare against. |
Definition at line 185 of file io_address.h.
References equals().
Subtracts one address from another (a - b)
Treats addresses as integers and subtracts them. For example:
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).
BadValue | if addresses are of different family |
a | address to be subtracted from |
b | address to be subtracted |
Definition at line 133 of file io_address.cc.
References IOAddress(), fromBytes(), getFamily(), isc_throw, isV4(), toBytes(), and toUint32().
Referenced by isc::asiolink::addrsInRange().
std::vector< uint8_t > isc::asiolink::IOAddress::toBytes | ( | ) | const |
Return address as set of bytes.
Definition at line 77 of file io_address.cc.
Referenced by isc::dhcp::Option6PDExclude::Option6PDExclude(), isc::dhcp::TokenIpAddress::TokenIpAddress(), isc::dhcp::Dhcpv4Srv::acceptServerId(), isc::asiolink::addrsInRange(), isc::dhcp::TokenPkt4::evaluate(), isc::dhcp::TokenPkt::evaluate(), isc::dhcp::TokenRelay6Field::evaluate(), isc::dhcp::Option6PDExclude::getExcludedPrefix(), isc::dhcp::Pkt::getMACFromIPv6(), isc::asiolink::hash_value(), increase(), isc::dhcp::IterativeAllocator::increasePrefix(), isc::dhcp::ResourceHandler::isLocked(), isc::asiolink::offsetAddress(), isc::dhcp::PktFilterInet6::openSocket(), isc::dhcp::Option6IAAddr::pack(), isc::dhcp::Option6IAPrefix::pack(), isc::asiolink::prefixLengthFromRange(), isc::d2::D2CfgMgr::reverseV4Address(), isc::d2::D2CfgMgr::reverseV6Address(), subtract(), isc::dhcp::ResourceHandler::unLock(), isc::dhcp::OptionDataTypeUtil::writeAddress(), and isc::dhcp::OptionDataTypeUtil::writePrefix().
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.
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::asiolink::addrsInRange(), isc::dhcp::CSVLeaseFile4::append(), isc::dhcp::CSVLeaseFile6::append(), isc::dhcp::Dhcpv6Srv::assignIA_NA(), isc::dhcp::Dhcpv6Srv::assignIA_PD(), isc::dhcp::Dhcpv4Srv::assignLease(), isc::agent::CtrlAgentProcess::configure(), isc::config::HttpCommandMgrImpl::configure(), isc::lease_cmds::LeaseCmdsImpl::createFailedLeaseMap(), isc::dhcp::CfgHosts::del(), isc::dhcp::Subnet6ConfigParser::duplicateOptionWarning(), isc::dhcp::TokenIpAddressToText::evaluate(), isc::dhcp::D2ClientMgr::generateFqdn(), isc::dhcp::CfgHosts::get4(), isc::dhcp::HostMgr::get4(), isc::dhcp::HostMgr::get6(), isc::dhcp::HostMgr::get6(), isc::yang::TranslatorPool::getAddresses(), getAddrStrIA_NA(), getAddrStrIA_PD(), isc::dhcp::HostMgr::getAll4(), isc::dhcp::HostMgr::getAll6(), isc::dhcp::Memfile_LeaseMgr::getLease4(), isc::dhcp::Memfile_LeaseMgr::getLease6(), isc::dhcp::Memfile_LeaseMgr::getLeases4(), isc::dhcp::Memfile_LeaseMgr::getLeases4ByRelayId(), isc::dhcp::Memfile_LeaseMgr::getLeases4ByRemoteId(), isc::dhcp::Memfile_LeaseMgr::getLeases6(), isc::dhcp::Memfile_LeaseMgr::getLeases6(), isc::dhcp::Memfile_LeaseMgr::getLeases6ByRelayId(), isc::dhcp::Memfile_LeaseMgr::getLeases6ByRemoteId(), 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::asiolink::operator<<(), isc::dhcp::D2ClientConfigParser::parse(), isc::lease_cmds::Lease4Parser::parse(), isc::lease_cmds::Lease6Parser::parse(), pkt4_send(), isc::asiolink::prefixLengthFromRange(), isc::dhcp::Dhcpv4Srv::processDecline(), isc::dhcp::CfgSubnets4::selectSubnet(), isc::dhcp::CfgSubnets4::selectSubnet(), isc::dhcp::CfgSubnets6::selectSubnet(), isc::config::HttpCommandConfig::toElement(), isc::d2::D2CfgContext::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::dhcp::Host::toElement4(), isc::d2::D2Params::toText(), isc::d2::DnsServerInfo::toText(), isc::dhcp::D2ClientConfig::toText(), isc::dhcp::Host::toText(), toUint32(), isc::dhcp::ResourceHandler::unLock(), isc::dhcp::CfgIface::use(), isc::dhcp::D2ClientConfig::validateContents(), isc::dhcp::Subnet4ConfigParser::validateResv(), and isc::dhcp::Subnet6ConfigParser::validateResvs().
uint32_t isc::asiolink::IOAddress::toUint32 | ( | ) | const |
Converts IPv4 address to uint32_t.
Will throw BadValue exception if that is not IPv4 address.
Definition at line 117 of file io_address.cc.
References isc_throw, and toText().
Referenced by isc::db::PsqlBindArray::add(), isc::dhcp::PoolFreeLeaseQueueAllocationState::addFreeLease(), isc::asiolink::addrsInRange(), isc::dhcp::IfaceMgr::collectBoundAddresses(), isc::dhcp::PoolFreeLeaseQueueAllocationState::deleteFreeLease(), isc::asiolink::hash_value(), 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(), isc::asiolink::prefixLengthFromRange(), isc::perfdhcp::TestControl::sendRequest4(), isc::perfdhcp::TestControl::sendRequest4(), and subtract().