Kea
1.9.9-git
|
The IOAddress
class represents an IP addresses (version agnostic)
More...
#include <io_address.h>
Public Member Functions | |
IOAddress (uint32_t v4address) | |
Constructor for ip::address_v4 object. More... | |
bool | equals (const IOAddress &other) const |
Compare addresses for equality. More... | |
short | getFamily () const |
Returns the address family. More... | |
bool | isV4 () const |
Convenience function to check for an IPv4 address. More... | |
bool | isV4Bcast () const |
Convenience function to check if it is an IPv4 broadcast address. More... | |
bool | isV4Zero () const |
Convenience function to check if it is an IPv4 zero address. More... | |
bool | isV6 () const |
Convenience function to check for an IPv6 address. More... | |
bool | isV6LinkLocal () const |
checks whether and address is IPv6 and is link-local More... | |
bool | isV6Multicast () const |
checks whether and address is IPv6 and is multicast More... | |
bool | isV6Zero () const |
Convenience function to check if it is an IPv4 zero address. More... | |
bool | nequals (const IOAddress &other) const |
Compare addresses for inequality. More... | |
bool | operator!= (const IOAddress &other) const |
Compare addresses for inequality. More... | |
bool | operator< (const IOAddress &other) const |
Checks if one address is smaller than the other. More... | |
bool | operator<= (const IOAddress &other) const |
Checks if one address is smaller or equal than the other. More... | |
bool | operator== (const IOAddress &other) const |
Compare addresses for equality. More... | |
std::vector< uint8_t > | toBytes () const |
Return address as set of bytes. More... | |
std::string | toText () const |
Convert the address to a string. More... | |
uint32_t | toUint32 () const |
Converts IPv4 address to uint32_t. More... | |
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. More... | |
IOAddress (const boost::asio::ip::address &asio_address) | |
Constructor from an ASIO ip::address object. More... | |
Static Public Member Functions | |
static IOAddress | fromBytes (short family, const uint8_t *data) |
Creates an address from over wire data. More... | |
static IOAddress | increase (const IOAddress &addr) |
Returns an address increased by one. More... | |
static IOAddress | subtract (const IOAddress &a, const IOAddress &b) |
Subtracts one address from another (a - b) More... | |
Methods returning @c IOAddress objects encapsulating typical addresses. | |
static const IOAddress & | IPV4_ZERO_ADDRESS () |
Returns an address set to all zeros. More... | |
static const IOAddress & | IPV4_BCAST_ADDRESS () |
Returns a "255.255.255.255" broadcast address. More... | |
static const IOAddress & | IPV6_ZERO_ADDRESS () |
Returns an IPv6 zero address. More... | |
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 33 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 42 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 network byte order
v4address | IPv4 address represented by uint32_t |
Definition at line 46 of file io_address.cc.
|
inline |
Compare addresses for equality.
other | Address to compare against. |
Definition at line 165 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 57 of file io_address.cc.
References IOAddress(), and isc_throw.
Referenced by isc::dhcp::TokenIpAddressToText::evaluate(), isc::dhcp::Option6PDExclude::getExcludedPrefix(), increase(), isc::dhcp::AllocEngine::IterativeAllocator::increasePrefix(), isc::dhcp::CfgSubnets4::initSelector(), isc::asiolink::offsetAddress(), isc::dhcp::OptionDataTypeUtil::readAddress(), isc::dhcp::OptionDataTypeUtil::readPrefix(), isc::dhcp::PktFilterInet6::receive(), subtract(), isc::dhcp::Option6AddrLst::unpack(), isc::dhcp::Option6IAAddr::unpack(), isc::dhcp::Option6IAPrefix::unpack(), and isc::dhcp::Pkt6::unpackRelayMsg().
short isc::asiolink::IOAddress::getFamily | ( | ) | const |
Returns the address family.
Definition at line 88 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 163 of file io_address.cc.
References fromBytes(), getFamily(), and toBytes().
Referenced by isc::asiolink::addrsInRange(), and isc::dhcp::AllocEngine::IterativeAllocator::increaseAddress().
|
inlinestatic |
Returns a "255.255.255.255" broadcast address.
Definition at line 272 of file io_address.h.
Referenced by isc::dhcp::Dhcpv4Srv::adjustRemoteAddr(), and isV4Bcast().
|
inlinestatic |
Returns an address set to all zeros.
Definition at line 266 of file io_address.h.
Referenced by isc::dhcp::Dhcpv4Srv::adjustIfaceData(), isc::dhcp::Dhcpv4Srv::assignLease(), isc::dhcp::Dhcpv4Srv::buildCfgOptionList(), isc::dhcp::HostMgr::cacheNegative(), isc::dhcp::Network4::getServerId(), isV4Zero(), isc::dhcp::IPRangePermutation::next(), isc::dhcp::D2ClientConfigParser::parse(), isc::dhcp::Dhcpv4Srv::processInform(), isc::dhcp::Host::removeIPv4Reservation(), isc::dhcp::Dhcpv4Srv::requiredClassify(), isc::dhcp::CfgSubnets4::selectSubnet(), and isc::dhcp::Dhcpv4Srv::setFixedFields().
|
inlinestatic |
Returns an IPv6 zero address.
Definition at line 278 of file io_address.h.
Referenced by isc::dhcp::Dhcpv6Srv::assignIA_NA(), isc::dhcp::Dhcpv6Srv::assignIA_PD(), isV6Zero(), isc::lease_cmds::LeaseCmdsImpl::lease6DelHandler(), isc::dhcp::IPRangePermutation::next(), isc::dhcp::D2ClientConfigParser::parse(), isc::dhcp::Pool6::Pool6(), and isc::dhcp::OptionDataTypeUtil::readPrefix().
|
inline |
Convenience function to check for an IPv4 address.
Definition at line 103 of file io_address.h.
Referenced by isc::dhcp::Dhcpv4Srv::acceptServerId(), isc::db::PsqlBindArray::add(), isc::dhcp::Option4AddrLst::addAddress(), isc::dhcp::OptionCustom::addArrayDataField(), isc::asiolink::addrsInRange(), isc::dhcp::IfaceMgr::collectBoundAddresses(), isc::db::MySqlBinding::condCreateIPv4Address(), isc::dhcp::MySqlHostDataSource::del(), isc::dhcp::PgSqlHostDataSource::del(), isc::asiolink::firstAddrInPrefix(), isc::dhcp::D2ClientMgr::generateFqdn(), isc::dhcp::MySqlHostDataSource::get4(), isc::dhcp::PgSqlHostDataSource::get4(), isc::dhcp::CqlHostDataSourceImpl::get4(), isc::dhcp::MySqlHostDataSource::getAll4(), isc::dhcp::PgSqlHostDataSource::getAll4(), isc::dhcp::CqlLeaseMgr::getLeases4(), isc::dhcp::Memfile_LeaseMgr::getLeases4(), isc::dhcp::PgSqlLeaseMgr::getLeases4(), isc::dhcp::MySqlLeaseMgr::getLeases4(), isc::lease_cmds::LeaseCmdsImpl::getParameters(), isc::asiolink::hash_value(), isc::dhcp::IfaceMgr::hasOpenSocket(), isc::dhcp_ddns::NameChangeRequest::isV4(), 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::lease_cmds::Lease4Parser::parse(), isc::lease_cmds::Lease6Parser::parse(), isc::dhcp::D2ClientConfigParser::parse(), isc::dhcp::Pool4::Pool4(), isc::asiolink::prefixLengthFromRange(), isc::d2::D2CfgMgr::reverseIpAddress(), isc::d2::D2CfgMgr::reverseV4Address(), isc::perfdhcp::TestControl::sendRequest4(), isc::dhcp::Option4AddrLst::setAddress(), isc::dhcp::Host::setIPv4Reservation(), isc::dhcp::Host::setNextServer(), isc::dhcp::Network4::setSiaddr(), isc::dhcp::Subnet::Subnet(), isc::dhcp::Subnet4::Subnet4(), 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 118 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 110 of file io_address.h.
References equals(), and IPV4_ZERO_ADDRESS().
Referenced by isc::dhcp::Dhcpv4Srv::buildCfgOptionList(), isc::dhcp::CqlLeaseMgr::getLeases4(), isc::dhcp::Host::Host(), isc::dhcp::Pkt4::isRelayed(), isc::dhcp::Dhcpv4Srv::requiredClassify(), 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 125 of file io_address.h.
Referenced by isc::dhcp::OptionCustom::addArrayDataField(), isc::dhcp::MySqlHostDataSource::get6(), isc::dhcp::PgSqlHostDataSource::get6(), isc::dhcp::MySqlHostDataSource::getAll6(), isc::dhcp::PgSqlHostDataSource::getAll6(), isc::dhcp::Memfile_LeaseMgr::getLeases6(), isc::dhcp::CqlLeaseMgr::getLeases6(), isc::dhcp::PgSqlLeaseMgr::getLeases6(), isc::dhcp::MySqlLeaseMgr::getLeases6(), isc::lease_cmds::LeaseCmdsImpl::getParameters(), isc::dhcp::AllocEngine::IterativeAllocator::increasePrefix(), isc::dhcp_ddns::NameChangeRequest::isV6(), isc::dhcp::IfaceMgr::openSocket(), isc::dhcp::Option6IAAddr::Option6IAAddr(), isc::dhcp::Option6PDExclude::Option6PDExclude(), isc::dhcp::Option6IAAddr::pack(), isc::dhcp::Option6IAPrefix::pack(), isc::dhcp::Pool6::Pool6(), isc::dhcp::PrefixRange::PrefixRange(), isc::d2::D2CfgMgr::reverseV6Address(), isc::dhcp::IPv6Resrv::set(), isc::dhcp::Option6AddrLst::setAddress(), isc::dhcp::Subnet::Subnet(), isc::dhcp::Subnet6::Subnet6(), 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 97 of file io_address.cc.
Referenced by isc::dhcp::Pkt::getMACFromIPv6(), isc::dhcp::CfgSubnets6::initSelector(), isc::dhcp::PktFilterInet6::openSocket(), isc::dhcp::PktFilterInet6::receive(), isc::dhcp::Dhcpv4Srv::selectSubnet4o6(), and isc::dhcp::CfgIface::use().
bool isc::asiolink::IOAddress::isV6Multicast | ( | ) | const |
checks whether and address is IPv6 and is multicast
Definition at line 105 of file io_address.cc.
Referenced by isc::dhcp::PktFilterInet6::openSocket(), isc::perfdhcp::PerfSocket::openSocket(), isc::dhcp::PktFilterInet6::receive(), isc::dhcp::IPv6Resrv::set(), and isc::dhcp::CfgIface::use().
|
inline |
Convenience function to check if it is an IPv4 zero address.
Definition at line 132 of file io_address.h.
References equals(), and IPV6_ZERO_ADDRESS().
Referenced by isc::lease_cmds::LeaseCmdsImpl::createFailedLeaseMap(), isc::dhcp::CqlLeaseMgr::getLeases6(), isc::dhcp::PgSqlLeaseMgr::getLeases6(), isc::dhcp::MySqlLeaseMgr::getLeases6(), isc::dhcp::CfgSubnets6::initSelector(), isc::dhcp::Pool6::Pool6(), and isc::dhcp::Dhcpv4Srv::selectSubnet4o6().
|
inline |
Compare addresses for inequality.
other | Address to compare against. |
Definition at line 183 of file io_address.h.
References equals().
Referenced by operator!=().
|
inline |
Compare addresses for inequality.
other | Address to compare against. |
Definition at line 206 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 190 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 197 of file io_address.h.
|
inline |
Compare addresses for equality.
other | Address to compare against. |
Definition at line 174 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 129 of file io_address.cc.
References fromBytes(), getFamily(), IOAddress(), 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 73 of file io_address.cc.
Referenced by isc::asiolink::addrsInRange(), isc::dhcp::TokenPkt::evaluate(), isc::dhcp::TokenPkt4::evaluate(), isc::dhcp::TokenRelay6Field::evaluate(), isc::dhcp::Option6PDExclude::getExcludedPrefix(), isc::dhcp::Pkt::getMACFromIPv6(), isc::asiolink::hash_value(), increase(), isc::dhcp::AllocEngine::IterativeAllocator::increasePrefix(), isc::dhcp::ResourceHandler::isLocked(), isc::asiolink::offsetAddress(), isc::dhcp::PktFilterInet6::openSocket(), isc::dhcp::Option6PDExclude::Option6PDExclude(), isc::dhcp::Option6IAAddr::pack(), isc::dhcp::Option6IAPrefix::pack(), isc::asiolink::prefixLengthFromRange(), isc::d2::D2CfgMgr::reverseV4Address(), isc::d2::D2CfgMgr::reverseV6Address(), subtract(), isc::dhcp::TokenIpAddress::TokenIpAddress(), 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 52 of file io_address.cc.
Referenced by isc::db::PsqlBindArray::add(), isc::dhcp::Network::RelayInfo::addAddress(), isc::asiolink::addrsInRange(), isc::dhcp::CSVLeaseFile6::append(), isc::dhcp::CSVLeaseFile4::append(), isc::db::MySqlBinding::condCreateIPv4Address(), isc::agent::CtrlAgentProcess::configure(), isc::lease_cmds::LeaseCmdsImpl::createFailedLeaseMap(), isc::dhcp::MySqlHostDataSource::del(), isc::dhcp::PgSqlHostDataSource::del(), isc::dhcp::CqlLeaseMgr::deleteLease(), isc::dhcp::PgSqlLeaseMgr::deleteLease(), isc::dhcp::MySqlLeaseMgr::deleteLease(), isc::dhcp::Subnet6ConfigParser::duplicate_option_warning(), isc::dhcp::D2ClientMgr::generateFqdn(), isc::dhcp::HostMgr::get4(), isc::dhcp::CfgHosts::get4(), isc::dhcp::MySqlHostDataSource::get6(), isc::dhcp::HostMgr::get6(), isc::dhcp::CqlHostDataSourceImpl::get6(), isc::yang::TranslatorPool::getAddresses(), getAddrStrIA_NA(), getAddrStrIA_PD(), isc::dhcp::HostMgr::getAll4(), isc::dhcp::CfgHosts::getAll4(), isc::dhcp::MySqlHostDataSource::getAll6(), isc::dhcp::HostMgr::getAll6(), isc::dhcp_ddns::NameChangeRequest::getIpAddress(), isc::dhcp::CqlLeaseMgr::getLease4(), isc::dhcp::Memfile_LeaseMgr::getLease4(), isc::dhcp::PgSqlLeaseMgr::getLease4(), isc::dhcp::MySqlLeaseMgr::getLease4(), isc::dhcp::CqlLeaseMgr::getLease6(), isc::dhcp::Memfile_LeaseMgr::getLease6(), isc::dhcp::PgSqlLeaseMgr::getLease6(), isc::dhcp::MySqlLeaseMgr::getLease6(), isc::dhcp::CqlLeaseMgr::getLeases4(), isc::dhcp::Memfile_LeaseMgr::getLeases4(), isc::dhcp::PgSqlLeaseMgr::getLeases4(), isc::dhcp::MySqlLeaseMgr::getLeases4(), isc::dhcp::Memfile_LeaseMgr::getLeases6(), isc::dhcp::CqlLeaseMgr::getLeases6(), isc::dhcp::PgSqlLeaseMgr::getLeases6(), isc::dhcp::MySqlLeaseMgr::getLeases6(), isc::lease_cmds::LeaseCmdsImpl::lease4ResendDdnsHandler(), isc::lease_cmds::LeaseCmdsImpl::lease6ResendDdnsHandler(), isc::dhcp::CSVLeaseFile4::next(), isc::dhcp::PktFilterInet6::openSocket(), isc::asiolink::operator<<(), isc::lease_cmds::Lease4Parser::parse(), isc::d2::D2SimpleParser::parse(), isc::lease_cmds::Lease6Parser::parse(), isc::dhcp::D2ClientConfigParser::parse(), pkt4_send(), isc::asiolink::prefixLengthFromRange(), isc::dhcp::CqlHostExchange::prepareExchange(), isc::dhcp::CfgSubnets6::selectSubnet(), isc::dhcp::CfgSubnets4::selectSubnet(), isc::dhcp::Subnet4::Subnet4(), isc::d2::D2CfgContext::toElement(), isc::dhcp::D2ClientConfig::toElement(), isc::dhcp::ClientClassDef::toElement(), isc::dhcp::Pool4::toElement(), isc::dhcp::Pool6::toElement(), isc::dhcp::Lease4::toElement(), isc::d2::DnsServerInfo::toElement(), isc::dhcp::Lease6::toElement(), isc::dhcp::Host::toElement4(), isc::dhcp::D2ClientConfig::toText(), isc::d2::D2Params::toText(), isc::d2::DnsServerInfo::toText(), isc::dhcp::Host::toText(), toUint32(), isc::dhcp::ResourceHandler::unLock(), isc::dhcp::CfgIface::use(), isc::dhcp::D2ClientConfig::validateContents(), isc::d2::D2Params::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 113 of file io_address.cc.
References isc_throw, and toText().
Referenced by isc::db::PsqlBindArray::add(), isc::asiolink::addrsInRange(), isc::dhcp::IfaceMgr::collectBoundAddresses(), isc::db::MySqlBinding::condCreateIPv4Address(), isc::dhcp::MySqlHostDataSource::del(), isc::dhcp::PgSqlLeaseMgr::deleteLease(), isc::dhcp::MySqlLeaseMgr::deleteLease(), isc::dhcp::MySqlHostDataSource::get4(), isc::dhcp::CqlHostDataSourceImpl::get4(), isc::dhcp::MySqlHostDataSource::getAll4(), isc::dhcp::CqlHostDataSourceImpl::getAll4(), isc::dhcp::CqlLeaseMgr::getLease4(), isc::dhcp::PgSqlLeaseMgr::getLease4(), isc::dhcp::MySqlLeaseMgr::getLease4(), isc::dhcp::CqlLeaseMgr::getLeases4(), isc::dhcp::PgSqlLeaseMgr::getLeases4(), isc::dhcp::MySqlLeaseMgr::getLeases4(), isc::asiolink::hash_value(), isc::dhcp::IfaceMgr::hasOpenSocket(), isc::asiolink::offsetAddress(), isc::dhcp::PktFilter::openFallbackSocket(), isc::dhcp::PktFilterLPF::openSocket(), isc::dhcp::PktFilterInet::openSocket(), isc::dhcp::PktFilterBPF::openSocket(), isc::dhcp::Pkt4::pack(), isc::asiolink::prefixLengthFromRange(), isc::perfdhcp::TestControl::sendRequest4(), and subtract().