Commit 5310305f authored by Francis Dupont's avatar Francis Dupont

[4061] IOAddress cleaned up

parent 15f370ea
......@@ -1497,7 +1497,7 @@ Dhcpv4Srv::adjustIfaceData(Dhcpv4Exchange& ex) {
// Instead we will need to use the address assigned to the interface
// on which the query has been received. In other cases, we will just
// use this address as a source address for the response.
if (local_addr == IOAddress::IPV4_BCAST_ADDRESS()) {
if (local_addr.isV4Bcast()) {
SocketInfo sock_info = IfaceMgr::instance().getSocket(*query);
local_addr = sock_info.addr_;
}
......@@ -1537,7 +1537,7 @@ Dhcpv4Srv::adjustRemoteAddr(Dhcpv4Exchange& ex) {
if (query->getType() == DHCPINFORM) {
// If client adheres to RFC2131 it will set the ciaddr and in this
// case we always unicast our response to this address.
if (query->getCiaddr() != IOAddress::IPV4_ZERO_ADDRESS()) {
if (!query->getCiaddr().isV4Zero()) {
response->setRemoteAddr(query->getCiaddr());
// If we received DHCPINFORM via relay and the ciaddr is not set we
......@@ -1568,14 +1568,14 @@ Dhcpv4Srv::adjustRemoteAddr(Dhcpv4Exchange& ex) {
// the message is relayed. Therefore, we set the BROADCAST flag so
// as the relay can broadcast the packet.
if ((query->getType() == DHCPINFORM) &&
(query->getCiaddr() == IOAddress::IPV4_ZERO_ADDRESS())) {
query->getCiaddr().isV4Zero()) {
response->setFlags(BOOTP_BROADCAST);
}
response->setRemoteAddr(query->getGiaddr());
// If giaddr is 0 but client set ciaddr, server should unicast the
// response to ciaddr.
} else if (query->getCiaddr() != IOAddress::IPV4_ZERO_ADDRESS()) {
} else if (!query->getCiaddr().isV4Zero()) {
response->setRemoteAddr(query->getCiaddr());
// We can't unicast the response to the client when sending NAK,
......@@ -1585,7 +1585,7 @@ Dhcpv4Srv::adjustRemoteAddr(Dhcpv4Exchange& ex) {
response->setRemoteAddr(IOAddress::IPV4_BCAST_ADDRESS());
// If yiaddr is set it means that we have created a lease for a client.
} else if (response->getYiaddr() != IOAddress::IPV4_ZERO_ADDRESS()) {
} else if (!response->getYiaddr().isV4Zero()) {
// If the broadcast bit is set in the flags field, we have to
// send the response to broadcast address. Client may have requested it
// because it doesn't support reception of messages on the interface
......@@ -2029,8 +2029,8 @@ Dhcpv4Srv::acceptDirectRequest(const Pkt4Ptr& pkt) const {
// to respond if the ciaddr was not present.
try {
if (pkt->getType() == DHCPINFORM) {
if ((pkt->getRemoteAddr() == IOAddress::IPV4_ZERO_ADDRESS()) &&
(pkt->getCiaddr() == IOAddress::IPV4_ZERO_ADDRESS())) {
if (pkt->getRemoteAddr().isV4Zero() &&
pkt->getCiaddr().isV4Zero()) {
return (false);
}
}
......@@ -2040,8 +2040,7 @@ Dhcpv4Srv::acceptDirectRequest(const Pkt4Ptr& pkt) const {
// we validate the message type prior to calling this function.
return (false);
}
return ((pkt->getLocalAddr() != IOAddress::IPV4_BCAST_ADDRESS()
|| selectSubnet(pkt)));
return (!pkt->getLocalAddr().isV4Bcast() || selectSubnet(pkt));
}
bool
......
......@@ -270,7 +270,7 @@ Dhcp4Client::doInform(const bool set_ciaddr) {
void
Dhcp4Client::doRelease() {
if (config_.lease_.addr_ == IOAddress::IPV4_ZERO_ADDRESS()) {
if (config_.lease_.addr_.isV4Zero()) {
isc_throw(Dhcp4ClientError, "failed to send the release"
" message because client doesn't have a lease");
}
......@@ -289,7 +289,7 @@ Dhcp4Client::doRelease() {
void
Dhcp4Client::doDecline() {
if (config_.lease_.addr_ == IOAddress::IPV4_ZERO_ADDRESS()) {
if (config_.lease_.addr_.isV4Zero()) {
isc_throw(Dhcp4ClientError, "failed to send the decline"
" message because client doesn't have a lease");
}
......
......@@ -21,16 +21,6 @@
using namespace isc::asiolink;
namespace {
/// @brief Holds IPv4 address set to "0.0.0.0".
const IOAddress ZERO_ADDRESS("0.0.0.0");
/// @brief Holds IPv4 broadcast address.
const IOAddress BCAST_ADDRESS("255.255.255.255");
} // end of anonymous namespace
namespace isc {
namespace dhcp {
......@@ -54,7 +44,7 @@ CfgSubnets4::selectSubnet(const SubnetSelector& selector) const {
// address will not match with any of the relay addresses accross all
// subnets, but we need to verify that for all subnets before we can try
// to use the giaddr to match with the subnet prefix.
if (selector.giaddr_ != ZERO_ADDRESS) {
if (!selector.giaddr_.isV4Zero()) {
for (Subnet4Collection::const_iterator subnet = subnets_.begin();
subnet != subnets_.end(); ++subnet) {
......@@ -75,19 +65,19 @@ CfgSubnets4::selectSubnet(const SubnetSelector& selector) const {
// what address from the client's packet to use to match with the
// subnets' prefixes.
IOAddress address = ZERO_ADDRESS;
IOAddress address = IOAddress::IPV6_ZERO_ADDRESS();
// If there is a giaddr, use it for subnet selection.
if (selector.giaddr_ != ZERO_ADDRESS) {
if (!selector.giaddr_.isV4Zero()) {
address = selector.giaddr_;
// If it is a Renew or Rebind, use the ciaddr.
} else if ((selector.ciaddr_ != ZERO_ADDRESS) &&
(selector.local_address_ != BCAST_ADDRESS)) {
} else if (!selector.ciaddr_.isV4Zero() &&
!selector.local_address_.isV4Bcast()) {
address = selector.ciaddr_;
// If ciaddr is not specified, use the source address.
} else if ((selector.remote_address_ != ZERO_ADDRESS) &&
(selector.local_address_ != BCAST_ADDRESS)) {
} else if (!selector.remote_address_.isV4Zero() &&
!selector.local_address_.isV4Bcast()) {
address = selector.remote_address_;
// If local interface name is known, use the local address on this
......@@ -105,7 +95,7 @@ CfgSubnets4::selectSubnet(const SubnetSelector& selector) const {
}
// Unable to find a suitable address to use for subnet selection.
if (address == ZERO_ADDRESS) {
if (address.isV4Zero()) {
return (Subnet4Ptr());
}
......
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