Commit ed8a874e authored by Marcin Siodelski's avatar Marcin Siodelski

[2549] Changes as a result of the code review.

parent 7cdae45e
...@@ -212,7 +212,7 @@ bool IfaceMgr::openSockets4(const uint16_t port) { ...@@ -212,7 +212,7 @@ bool IfaceMgr::openSockets4(const uint16_t port) {
addr != addrs.end(); addr != addrs.end();
++addr) { ++addr) {
// Skip IPv6 addresses // Skip all but V4 addresses.
if (!addr->isV4()) { if (!addr->isV4()) {
continue; continue;
} }
...@@ -247,7 +247,7 @@ bool IfaceMgr::openSockets6(const uint16_t port) { ...@@ -247,7 +247,7 @@ bool IfaceMgr::openSockets6(const uint16_t port) {
addr != addrs.end(); addr != addrs.end();
++addr) { ++addr) {
// skip IPv4 addresses // Skip all but V6 addresses.
if (!addr->isV6()) { if (!addr->isV6()) {
continue; continue;
} }
...@@ -949,7 +949,7 @@ Pkt6Ptr IfaceMgr::receive6(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */ ...@@ -949,7 +949,7 @@ Pkt6Ptr IfaceMgr::receive6(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */
for (SocketCollection::const_iterator s = socket_collection.begin(); for (SocketCollection::const_iterator s = socket_collection.begin();
s != socket_collection.end(); ++s) { s != socket_collection.end(); ++s) {
// Only deal with IPv4 addresses. // Only deal with IPv6 addresses.
if (s->addr_.isV6()) { if (s->addr_.isV6()) {
names << s->sockfd_ << "(" << iface->getName() << ") "; names << s->sockfd_ << "(" << iface->getName() << ") ";
......
...@@ -381,9 +381,7 @@ OptionDefinition::writeToBuffer(const std::string& value, ...@@ -381,9 +381,7 @@ OptionDefinition::writeToBuffer(const std::string& value,
asiolink::IOAddress address(value); asiolink::IOAddress address(value);
if (!address.isV4() && !address.isV6()) { if (!address.isV4() && !address.isV6()) {
isc_throw(BadDataTypeCast, "provided address " << address.toText() isc_throw(BadDataTypeCast, "provided address " << address.toText()
<< " is not a valid " << " is not a valid IPv4 or IPv6 address.");
<< (address.isV4() ? "IPv4" : "IPv6")
<< " address");
} }
OptionDataTypeUtil::writeAddress(address, buf); OptionDataTypeUtil::writeAddress(address, buf);
return; return;
......
...@@ -53,8 +53,11 @@ isc::asiolink::IOAddress firstAddrInPrefix6(const isc::asiolink::IOAddress& pref ...@@ -53,8 +53,11 @@ isc::asiolink::IOAddress firstAddrInPrefix6(const isc::asiolink::IOAddress& pref
} }
// First we copy the whole address as 16 bytes. // First we copy the whole address as 16 bytes.
// We don't check that it is a valid IPv6 address and thus has
// the required length because it is already checked by
// the calling function.
uint8_t packed[V6ADDRESS_LEN]; uint8_t packed[V6ADDRESS_LEN];
memcpy(packed, &prefix.toBytes()[0], 16); memcpy(packed, &prefix.toBytes()[0], V6ADDRESS_LEN);
// If the length is divisible by 8, it is simple. We just zero out the host // If the length is divisible by 8, it is simple. We just zero out the host
// part. Otherwise we need to handle the byte that has to be partially // part. Otherwise we need to handle the byte that has to be partially
...@@ -95,6 +98,9 @@ isc::asiolink::IOAddress firstAddrInPrefix4(const isc::asiolink::IOAddress& pref ...@@ -95,6 +98,9 @@ isc::asiolink::IOAddress firstAddrInPrefix4(const isc::asiolink::IOAddress& pref
isc_throw(isc::BadValue, "Too large netmask. 0..32 is allowed in IPv4"); isc_throw(isc::BadValue, "Too large netmask. 0..32 is allowed in IPv4");
} }
// We don't check that it is a valid IPv4 address and thus has
// a required length of 4 bytes because it has been already
// checked by the calling function.
uint32_t addr = prefix; uint32_t addr = prefix;
return (IOAddress(addr & (~bitMask4[len]))); return (IOAddress(addr & (~bitMask4[len])));
} }
......
...@@ -30,20 +30,21 @@ AllocEngine::IterativeAllocator::IterativeAllocator() ...@@ -30,20 +30,21 @@ AllocEngine::IterativeAllocator::IterativeAllocator()
isc::asiolink::IOAddress isc::asiolink::IOAddress
AllocEngine::IterativeAllocator::increaseAddress(const isc::asiolink::IOAddress& addr) { AllocEngine::IterativeAllocator::increaseAddress(const isc::asiolink::IOAddress& addr) {
// Get a buffer holding an address.
const std::vector<uint8_t>& vec = addr.toBytes();
// Get the address length.
const int len = vec.size();
// Since the same array will be used to hold the IPv4 and IPv6
// address we have to make sure that the size of the array
// we allocate will work for both types of address.
BOOST_STATIC_ASSERT(V4ADDRESS_LEN <= V6ADDRESS_LEN);
uint8_t packed[V6ADDRESS_LEN]; uint8_t packed[V6ADDRESS_LEN];
int len;
// First we copy the whole address as 16 bytes. // Copy the address. It can be either V4 or V6.
if (addr.isV4()) { std::memcpy(packed, &vec[0], len);
// IPv4
std::memcpy(packed, &addr.toBytes()[0], 4);
len = 4;
} else {
// IPv6
std::memcpy(packed, &addr.toBytes()[0], 16);
len = 16;
}
// Increase the address.
for (int i = len - 1; i >= 0; --i) { for (int i = len - 1; i >= 0; --i) {
++packed[i]; ++packed[i];
if (packed[i] != 0) { if (packed[i] != 0) {
......
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