Commit f104a60a authored by Marcin Siodelski's avatar Marcin Siodelski

[2549] Replaced IOAddress::getFamily() with IOAddress::isVx() calls.

parent b25d6802
...@@ -213,7 +213,7 @@ bool IfaceMgr::openSockets4(const uint16_t port) { ...@@ -213,7 +213,7 @@ bool IfaceMgr::openSockets4(const uint16_t port) {
++addr) { ++addr) {
// Skip IPv6 addresses // Skip IPv6 addresses
if (addr->getFamily() != AF_INET) { if (!addr->isV4()) {
continue; continue;
} }
...@@ -248,7 +248,7 @@ bool IfaceMgr::openSockets6(const uint16_t port) { ...@@ -248,7 +248,7 @@ bool IfaceMgr::openSockets6(const uint16_t port) {
++addr) { ++addr) {
// skip IPv4 addresses // skip IPv4 addresses
if (addr->getFamily() != AF_INET6) { if (!addr->isV6()) {
continue; continue;
} }
...@@ -356,12 +356,13 @@ int IfaceMgr::openSocket(const std::string& ifname, const IOAddress& addr, ...@@ -356,12 +356,13 @@ int IfaceMgr::openSocket(const std::string& ifname, const IOAddress& addr,
if (!iface) { if (!iface) {
isc_throw(BadValue, "There is no " << ifname << " interface present."); isc_throw(BadValue, "There is no " << ifname << " interface present.");
} }
switch (addr.getFamily()) { if (addr.isV4()) {
case AF_INET:
return openSocket4(*iface, addr, port); return openSocket4(*iface, addr, port);
case AF_INET6:
} else if (addr.isV6()) {
return openSocket6(*iface, addr, port); return openSocket6(*iface, addr, port);
default:
} else {
isc_throw(BadValue, "Failed to detect family of address: " isc_throw(BadValue, "Failed to detect family of address: "
<< addr.toText()); << addr.toText());
} }
...@@ -798,7 +799,7 @@ IfaceMgr::receive4(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */) { ...@@ -798,7 +799,7 @@ IfaceMgr::receive4(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */) {
s != socket_collection.end(); ++s) { s != socket_collection.end(); ++s) {
// Only deal with IPv4 addresses. // Only deal with IPv4 addresses.
if (s->addr_.getFamily() == AF_INET) { if (s->addr_.isV4()) {
names << s->sockfd_ << "(" << iface->getName() << ") "; names << s->sockfd_ << "(" << iface->getName() << ") ";
// Add this socket to listening set // Add this socket to listening set
...@@ -951,7 +952,7 @@ Pkt6Ptr IfaceMgr::receive6(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */ ...@@ -951,7 +952,7 @@ Pkt6Ptr IfaceMgr::receive6(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */
s != socket_collection.end(); ++s) { s != socket_collection.end(); ++s) {
// Only deal with IPv4 addresses. // Only deal with IPv4 addresses.
if (s->addr_.getFamily() == AF_INET6) { if (s->addr_.isV6()) {
names << s->sockfd_ << "(" << iface->getName() << ") "; names << s->sockfd_ << "(" << iface->getName() << ") ";
// Add this socket to listening set // Add this socket to listening set
......
...@@ -86,7 +86,7 @@ Option4AddrLst::pack4(isc::util::OutputBuffer& buf) { ...@@ -86,7 +86,7 @@ Option4AddrLst::pack4(isc::util::OutputBuffer& buf) {
} }
void Option4AddrLst::setAddress(const isc::asiolink::IOAddress& addr) { void Option4AddrLst::setAddress(const isc::asiolink::IOAddress& addr) {
if (addr.getFamily() != AF_INET) { if (!addr.isV4()) {
isc_throw(BadValue, "Can't store non-IPv4 address in " isc_throw(BadValue, "Can't store non-IPv4 address in "
<< "Option4AddrLst option"); << "Option4AddrLst option");
} }
...@@ -107,7 +107,7 @@ void Option4AddrLst::setAddresses(const AddressContainer& addrs) { ...@@ -107,7 +107,7 @@ void Option4AddrLst::setAddresses(const AddressContainer& addrs) {
void Option4AddrLst::addAddress(const isc::asiolink::IOAddress& addr) { void Option4AddrLst::addAddress(const isc::asiolink::IOAddress& addr) {
if (addr.getFamily() != AF_INET) { if (!addr.isV4()) {
isc_throw(BadValue, "Can't store non-IPv4 address in " isc_throw(BadValue, "Can't store non-IPv4 address in "
<< "Option4AddrLst option"); << "Option4AddrLst option");
} }
......
...@@ -49,7 +49,7 @@ Option6AddrLst::Option6AddrLst(uint16_t type, OptionBufferConstIter begin, ...@@ -49,7 +49,7 @@ Option6AddrLst::Option6AddrLst(uint16_t type, OptionBufferConstIter begin,
void void
Option6AddrLst::setAddress(const isc::asiolink::IOAddress& addr) { Option6AddrLst::setAddress(const isc::asiolink::IOAddress& addr) {
if (addr.getFamily() != AF_INET6) { if (!addr.isV6()) {
isc_throw(BadValue, "Can't store non-IPv6 address in Option6AddrLst option"); isc_throw(BadValue, "Can't store non-IPv6 address in Option6AddrLst option");
} }
......
...@@ -58,14 +58,12 @@ void ...@@ -58,14 +58,12 @@ void
OptionCustom::addArrayDataField(const asiolink::IOAddress& address) { OptionCustom::addArrayDataField(const asiolink::IOAddress& address) {
checkArrayType(); checkArrayType();
if ((address.getFamily() == AF_INET && if ((address.isV4() && definition_.getType() != OPT_IPV4_ADDRESS_TYPE) ||
definition_.getType() != OPT_IPV4_ADDRESS_TYPE) || (address.isV6() && definition_.getType() != OPT_IPV6_ADDRESS_TYPE)) {
(address.getFamily() == AF_INET6 &&
definition_.getType() != OPT_IPV6_ADDRESS_TYPE)) {
isc_throw(BadDataTypeCast, "invalid address specified " isc_throw(BadDataTypeCast, "invalid address specified "
<< address.toText() << ". Expected a valid IPv" << address.toText() << ". Expected a valid IPv"
<< (definition_.getType() == OPT_IPV4_ADDRESS_TYPE ? "4" : "6") << (definition_.getType() == OPT_IPV4_ADDRESS_TYPE ?
<< " address."); "4" : "6") << " address.");
} }
OptionBuffer buf; OptionBuffer buf;
...@@ -454,10 +452,8 @@ OptionCustom::writeAddress(const asiolink::IOAddress& address, ...@@ -454,10 +452,8 @@ OptionCustom::writeAddress(const asiolink::IOAddress& address,
checkIndex(index); checkIndex(index);
if ((address.getFamily() == AF_INET && if ((address.isV4() && buffers_[index].size() != V4ADDRESS_LEN) ||
buffers_[index].size() != V4ADDRESS_LEN) || (address.isV6() && buffers_[index].size() != V6ADDRESS_LEN)) {
(address.getFamily() == AF_INET6 &&
buffers_[index].size() != V6ADDRESS_LEN)) {
isc_throw(BadDataTypeCast, "invalid address specified " isc_throw(BadDataTypeCast, "invalid address specified "
<< address.toText() << ". Expected a valid IPv" << address.toText() << ". Expected a valid IPv"
<< (buffers_[index].size() == V4ADDRESS_LEN ? "4" : "6") << (buffers_[index].size() == V4ADDRESS_LEN ? "4" : "6")
......
...@@ -379,8 +379,7 @@ OptionDefinition::writeToBuffer(const std::string& value, ...@@ -379,8 +379,7 @@ OptionDefinition::writeToBuffer(const std::string& value,
case OPT_IPV6_ADDRESS_TYPE: case OPT_IPV6_ADDRESS_TYPE:
{ {
asiolink::IOAddress address(value); asiolink::IOAddress address(value);
if (address.getFamily() != AF_INET && if (!address.isV4() && !address.isV6()) {
address.getFamily() != AF_INET6) {
isc_throw(BadDataTypeCast, "provided address " << address.toText() isc_throw(BadDataTypeCast, "provided address " << address.toText()
<< " is not a valid " << " is not a valid "
<< (address.getAddress().is_v4() ? "IPv4" : "IPv6") << (address.getAddress().is_v4() ? "IPv4" : "IPv6")
......
...@@ -38,12 +38,11 @@ public: ...@@ -38,12 +38,11 @@ public:
/// @param [out] buf output buffer. /// @param [out] buf output buffer.
void writeAddress(const asiolink::IOAddress& address, void writeAddress(const asiolink::IOAddress& address,
std::vector<uint8_t>& buf) { std::vector<uint8_t>& buf) {
short family = address.getFamily(); if (address.isV4()) {
if (family == AF_INET) {
asio::ip::address_v4::bytes_type buf_addr = asio::ip::address_v4::bytes_type buf_addr =
address.getAddress().to_v4().to_bytes(); address.getAddress().to_v4().to_bytes();
buf.insert(buf.end(), buf_addr.begin(), buf_addr.end()); buf.insert(buf.end(), buf_addr.begin(), buf_addr.end());
} else if (family == AF_INET6) { } else if (address.isV6()) {
asio::ip::address_v6::bytes_type buf_addr = asio::ip::address_v6::bytes_type buf_addr =
address.getAddress().to_v6().to_bytes(); address.getAddress().to_v6().to_bytes();
buf.insert(buf.end(), buf_addr.begin(), buf_addr.end()); buf.insert(buf.end(), buf_addr.begin(), buf_addr.end());
......
...@@ -34,12 +34,11 @@ public: ...@@ -34,12 +34,11 @@ public:
/// @param [out] buf output buffer. /// @param [out] buf output buffer.
void writeAddress(const asiolink::IOAddress& address, void writeAddress(const asiolink::IOAddress& address,
std::vector<uint8_t>& buf) { std::vector<uint8_t>& buf) {
short family = address.getFamily(); if (address.isV4()) {
if (family == AF_INET) {
asio::ip::address_v4::bytes_type buf_addr = asio::ip::address_v4::bytes_type buf_addr =
address.getAddress().to_v4().to_bytes(); address.getAddress().to_v4().to_bytes();
buf.insert(buf.end(), buf_addr.begin(), buf_addr.end()); buf.insert(buf.end(), buf_addr.begin(), buf_addr.end());
} else if (family == AF_INET6) { } else if (address.isV6()) {
asio::ip::address_v6::bytes_type buf_addr = asio::ip::address_v6::bytes_type buf_addr =
address.getAddress().to_v6().to_bytes(); address.getAddress().to_v6().to_bytes();
buf.insert(buf.end(), buf_addr.begin(), buf_addr.end()); buf.insert(buf.end(), buf_addr.begin(), buf_addr.end());
......
...@@ -169,19 +169,23 @@ namespace dhcp { ...@@ -169,19 +169,23 @@ namespace dhcp {
isc::asiolink::IOAddress firstAddrInPrefix(const isc::asiolink::IOAddress& prefix, isc::asiolink::IOAddress firstAddrInPrefix(const isc::asiolink::IOAddress& prefix,
uint8_t len) { uint8_t len) {
if (prefix.getFamily() == AF_INET) { if (prefix.isV4()) {
return firstAddrInPrefix4(prefix, len); return (firstAddrInPrefix4(prefix, len));
} else { } else {
return firstAddrInPrefix6(prefix, len); return (firstAddrInPrefix6(prefix, len));
} }
} }
isc::asiolink::IOAddress lastAddrInPrefix(const isc::asiolink::IOAddress& prefix, isc::asiolink::IOAddress lastAddrInPrefix(const isc::asiolink::IOAddress& prefix,
uint8_t len) { uint8_t len) {
if (prefix.getFamily() == AF_INET) { if (prefix.isV4()) {
return lastAddrInPrefix4(prefix, len); return (lastAddrInPrefix4(prefix, len));
} else { } else {
return lastAddrInPrefix6(prefix, len); return (lastAddrInPrefix6(prefix, len));
} }
} }
......
...@@ -34,7 +34,7 @@ AllocEngine::IterativeAllocator::increaseAddress(const isc::asiolink::IOAddress& ...@@ -34,7 +34,7 @@ AllocEngine::IterativeAllocator::increaseAddress(const isc::asiolink::IOAddress&
int len; int len;
// First we copy the whole address as 16 bytes. // First we copy the whole address as 16 bytes.
if (addr.getFamily()==AF_INET) { if (addr.isV4()) {
// IPv4 // IPv4
std::memcpy(packed, addr.getAddress().to_v4().to_bytes().data(), 4); std::memcpy(packed, addr.getAddress().to_v4().to_bytes().data(), 4);
len = 4; len = 4;
......
...@@ -34,7 +34,7 @@ Pool4::Pool4(const isc::asiolink::IOAddress& first, ...@@ -34,7 +34,7 @@ Pool4::Pool4(const isc::asiolink::IOAddress& first,
const isc::asiolink::IOAddress& last) const isc::asiolink::IOAddress& last)
:Pool(first, last) { :Pool(first, last) {
// check if specified address boundaries are sane // check if specified address boundaries are sane
if (first.getFamily() != AF_INET || last.getFamily() != AF_INET) { if (!first.isV4() || !last.isV4()) {
isc_throw(BadValue, "Invalid Pool4 address boundaries: not IPv4"); isc_throw(BadValue, "Invalid Pool4 address boundaries: not IPv4");
} }
...@@ -48,7 +48,7 @@ Pool4::Pool4(const isc::asiolink::IOAddress& prefix, ...@@ -48,7 +48,7 @@ Pool4::Pool4(const isc::asiolink::IOAddress& prefix,
:Pool(prefix, IOAddress("0.0.0.0")) { :Pool(prefix, IOAddress("0.0.0.0")) {
// check if the prefix is sane // check if the prefix is sane
if (prefix.getFamily() != AF_INET) { if (!prefix.isV4()) {
isc_throw(BadValue, "Invalid Pool4 address boundaries: not IPv4"); isc_throw(BadValue, "Invalid Pool4 address boundaries: not IPv4");
} }
...@@ -67,7 +67,7 @@ Pool6::Pool6(Pool6Type type, const isc::asiolink::IOAddress& first, ...@@ -67,7 +67,7 @@ Pool6::Pool6(Pool6Type type, const isc::asiolink::IOAddress& first,
:Pool(first, last), type_(type), prefix_len_(0) { :Pool(first, last), type_(type), prefix_len_(0) {
// check if specified address boundaries are sane // check if specified address boundaries are sane
if (first.getFamily() != AF_INET6 || last.getFamily() != AF_INET6) { if (!first.isV6() || !last.isV6()) {
isc_throw(BadValue, "Invalid Pool6 address boundaries: not IPv6"); isc_throw(BadValue, "Invalid Pool6 address boundaries: not IPv6");
} }
...@@ -98,7 +98,7 @@ Pool6::Pool6(Pool6Type type, const isc::asiolink::IOAddress& prefix, ...@@ -98,7 +98,7 @@ Pool6::Pool6(Pool6Type type, const isc::asiolink::IOAddress& prefix,
type_(type), prefix_len_(prefix_len) { type_(type), prefix_len_(prefix_len) {
// check if the prefix is sane // check if the prefix is sane
if (prefix.getFamily() != AF_INET6) { if (!prefix.isV6()) {
isc_throw(BadValue, "Invalid Pool6 address boundaries: not IPv6"); isc_throw(BadValue, "Invalid Pool6 address boundaries: not IPv6");
} }
......
...@@ -30,8 +30,8 @@ Subnet::Subnet(const isc::asiolink::IOAddress& prefix, uint8_t len, ...@@ -30,8 +30,8 @@ Subnet::Subnet(const isc::asiolink::IOAddress& prefix, uint8_t len,
:id_(getNextID()), prefix_(prefix), prefix_len_(len), t1_(t1), :id_(getNextID()), prefix_(prefix), prefix_len_(len), t1_(t1),
t2_(t2), valid_(valid_lifetime), t2_(t2), valid_(valid_lifetime),
last_allocated_(lastAddrInPrefix(prefix, len)) { last_allocated_(lastAddrInPrefix(prefix, len)) {
if ( (prefix.getFamily() == AF_INET6 && len > 128) || if ((prefix.isV6() && len > 128) ||
(prefix.getFamily() == AF_INET && len > 32) ) { (prefix.isV4() && len > 32)) {
isc_throw(BadValue, "Invalid prefix length specified for subnet: " << len); isc_throw(BadValue, "Invalid prefix length specified for subnet: " << len);
} }
} }
...@@ -65,7 +65,7 @@ Subnet4::Subnet4(const isc::asiolink::IOAddress& prefix, uint8_t length, ...@@ -65,7 +65,7 @@ Subnet4::Subnet4(const isc::asiolink::IOAddress& prefix, uint8_t length,
const Triplet<uint32_t>& t2, const Triplet<uint32_t>& t2,
const Triplet<uint32_t>& valid_lifetime) const Triplet<uint32_t>& valid_lifetime)
:Subnet(prefix, length, t1, t2, valid_lifetime) { :Subnet(prefix, length, t1, t2, valid_lifetime) {
if (prefix.getFamily() != AF_INET) { if (!prefix.isV4()) {
isc_throw(BadValue, "Non IPv4 prefix " << prefix.toText() isc_throw(BadValue, "Non IPv4 prefix " << prefix.toText()
<< " specified in subnet4"); << " specified in subnet4");
} }
...@@ -136,7 +136,7 @@ Subnet6::Subnet6(const isc::asiolink::IOAddress& prefix, uint8_t length, ...@@ -136,7 +136,7 @@ Subnet6::Subnet6(const isc::asiolink::IOAddress& prefix, uint8_t length,
const Triplet<uint32_t>& valid_lifetime) const Triplet<uint32_t>& valid_lifetime)
:Subnet(prefix, length, t1, t2, valid_lifetime), :Subnet(prefix, length, t1, t2, valid_lifetime),
preferred_(preferred_lifetime){ preferred_(preferred_lifetime){
if (prefix.getFamily() != AF_INET6) { if (!prefix.isV6()) {
isc_throw(BadValue, "Non IPv6 prefix " << prefix.toText() isc_throw(BadValue, "Non IPv6 prefix " << prefix.toText()
<< " specified in subnet6"); << " specified in subnet6");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment