Commit 65021b84 authored by Francis Dupont's avatar Francis Dupont
Browse files

[551-wrong-namespace-for-address-utilities] Moved address utils to isc::asiolink namespace

parent e98c430b
......@@ -45,8 +45,7 @@ const uint8_t revMask6[]= { 0xff, 0x7f, 0x3f, 0x1f, 0xf, 0x7, 0x3, 0x1 };
///
/// @param prefix IPv6 prefix
/// @param len prefix length
isc::asiolink::IOAddress firstAddrInPrefix6(const isc::asiolink::IOAddress& prefix,
uint8_t len) {
IOAddress firstAddrInPrefix6(const IOAddress& prefix, uint8_t len) {
if (len > 128) {
isc_throw(isc::BadValue,
"Too large netmask. 0..128 is allowed in IPv6");
......@@ -82,7 +81,7 @@ isc::asiolink::IOAddress firstAddrInPrefix6(const isc::asiolink::IOAddress& pref
}
// Finally, let's wrap this into nice and easy IOAddress object.
return (isc::asiolink::IOAddress::fromBytes(AF_INET6, packed));
return (IOAddress::fromBytes(AF_INET6, packed));
}
/// @brief calculates the first IPv4 address in a IPv4 prefix
......@@ -92,8 +91,7 @@ isc::asiolink::IOAddress firstAddrInPrefix6(const isc::asiolink::IOAddress& pref
///
/// @param prefix IPv4 prefix
/// @param len netmask length (0-32)
isc::asiolink::IOAddress firstAddrInPrefix4(const isc::asiolink::IOAddress& prefix,
uint8_t len) {
IOAddress firstAddrInPrefix4(const IOAddress& prefix, uint8_t len) {
if (len > 32) {
isc_throw(isc::BadValue, "Too large netmask. 0..32 is allowed in IPv4");
}
......@@ -112,8 +110,7 @@ isc::asiolink::IOAddress firstAddrInPrefix4(const isc::asiolink::IOAddress& pref
///
/// @param prefix IPv4 prefix that we calculate first address for
/// @param len netmask length (0-32)
isc::asiolink::IOAddress lastAddrInPrefix4(const isc::asiolink::IOAddress& prefix,
uint8_t len) {
IOAddress lastAddrInPrefix4(const IOAddress& prefix, uint8_t len) {
if (len > 32) {
isc_throw(isc::BadValue, "Too large netmask. 0..32 is allowed in IPv4");
}
......@@ -129,8 +126,7 @@ isc::asiolink::IOAddress lastAddrInPrefix4(const isc::asiolink::IOAddress& prefi
///
/// @param prefix IPv6 prefix that we calculate first address for
/// @param len netmask length (0-128)
isc::asiolink::IOAddress lastAddrInPrefix6(const isc::asiolink::IOAddress& prefix,
uint8_t len) {
IOAddress lastAddrInPrefix6(const IOAddress& prefix, uint8_t len) {
if (len > 128) {
isc_throw(isc::BadValue,
"Too large netmask. 0..128 is allowed in IPv6");
......@@ -165,16 +161,15 @@ isc::asiolink::IOAddress lastAddrInPrefix6(const isc::asiolink::IOAddress& prefi
}
// Finally, let's wrap this into nice and easy IOAddress object.
return (isc::asiolink::IOAddress::fromBytes(AF_INET6, packed));
return (IOAddress::fromBytes(AF_INET6, packed));
}
}; // end of anonymous namespace
namespace isc {
namespace dhcp {
namespace asiolink {
isc::asiolink::IOAddress firstAddrInPrefix(const isc::asiolink::IOAddress& prefix,
uint8_t len) {
IOAddress firstAddrInPrefix(const IOAddress& prefix, uint8_t len) {
if (prefix.isV4()) {
return (firstAddrInPrefix4(prefix, len));
......@@ -184,8 +179,7 @@ isc::asiolink::IOAddress firstAddrInPrefix(const isc::asiolink::IOAddress& prefi
}
}
isc::asiolink::IOAddress lastAddrInPrefix(const isc::asiolink::IOAddress& prefix,
uint8_t len) {
IOAddress lastAddrInPrefix(const IOAddress& prefix, uint8_t len) {
if (prefix.isV4()) {
return (lastAddrInPrefix4(prefix, len));
......@@ -195,10 +189,10 @@ isc::asiolink::IOAddress lastAddrInPrefix(const isc::asiolink::IOAddress& prefix
}
}
isc::asiolink::IOAddress getNetmask4(uint8_t len) {
IOAddress getNetmask4(uint8_t len) {
if (len > 32) {
isc_throw(BadValue, "Invalid netmask size "
<< static_cast<unsigned>(len) << ", allowed range is 0..32");
isc_throw(BadValue, "Invalid netmask size "
<< static_cast<unsigned>(len) << ", allowed range is 0..32");
}
uint32_t x = ~bitMask4[len];
......@@ -206,8 +200,7 @@ isc::asiolink::IOAddress getNetmask4(uint8_t len) {
}
uint64_t
addrsInRange(const isc::asiolink::IOAddress& min,
const isc::asiolink::IOAddress& max) {
addrsInRange(const IOAddress& min, const IOAddress& max) {
if (min.getFamily() != max.getFamily()) {
isc_throw(BadValue, "Both addresses have to be the same family");
}
......@@ -277,8 +270,7 @@ addrsInRange(const isc::asiolink::IOAddress& min,
}
int
prefixLengthFromRange(const isc::asiolink::IOAddress& min,
const isc::asiolink::IOAddress& max) {
prefixLengthFromRange(const IOAddress& min, const IOAddress& max) {
if (min.getFamily() != max.getFamily()) {
isc_throw(BadValue, "Both addresses have to be the same family");
}
......
// Copyright (C) 2012-2018 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012-2019 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
......@@ -10,7 +10,7 @@
#include <asiolink/io_address.h>
namespace isc {
namespace dhcp {
namespace asiolink {
/// This code is based on similar code from the Dibbler project. I, Tomasz Mrugalski,
/// as a sole creator of that code hereby release it under BSD license for the benefit
......@@ -25,8 +25,7 @@ namespace dhcp {
/// @param len prefix length
///
/// @return first address from a prefix
isc::asiolink::IOAddress firstAddrInPrefix(const isc::asiolink::IOAddress& prefix,
uint8_t len);
IOAddress firstAddrInPrefix(const IOAddress& prefix, uint8_t len);
/// @brief returns a last address in a given prefix
///
......@@ -37,13 +36,12 @@ isc::asiolink::IOAddress firstAddrInPrefix(const isc::asiolink::IOAddress& prefi
/// @param len prefix length
///
/// @return first address from a prefix
isc::asiolink::IOAddress lastAddrInPrefix(const isc::asiolink::IOAddress& prefix,
uint8_t len);
IOAddress lastAddrInPrefix(const IOAddress& prefix, uint8_t len);
/// @brief Generates an IPv4 netmask of specified length
/// @throw BadValue if len is greater than 32
/// @return netmask
isc::asiolink::IOAddress getNetmask4(uint8_t len);
IOAddress getNetmask4(uint8_t len);
/// @brief Returns number of available addresses in the specified range (min - max).
......@@ -56,8 +54,7 @@ isc::asiolink::IOAddress getNetmask4(uint8_t len);
/// @param min the first address in range
/// @param max the last address in range
/// @return number of addresses in range
uint64_t addrsInRange(const isc::asiolink::IOAddress& min,
const isc::asiolink::IOAddress& max);
uint64_t addrsInRange(const IOAddress& min, const IOAddress& max);
/// @brief Returns prefix length from the specified range (min - max).
///
......@@ -68,8 +65,7 @@ uint64_t addrsInRange(const isc::asiolink::IOAddress& min,
/// @param min the first address in range
/// @param max the last address in range
/// @return the prefix length or -1 if the range is not from a prefix
int prefixLengthFromRange(const isc::asiolink::IOAddress& min,
const isc::asiolink::IOAddress& max);
int prefixLengthFromRange(const IOAddress& min, const IOAddress& max);
/// @brief Returns number of available IPv6 prefixes in the specified prefix.
///
......
......@@ -17,7 +17,6 @@
#include <stdlib.h>
using namespace std;
using namespace isc::dhcp;
using namespace isc::asiolink;
namespace {
......
......@@ -17,7 +17,6 @@
using namespace std;
using namespace isc::data;
using namespace isc::asiolink;
using namespace isc::dhcp;
#ifndef HAVE_PRE_0_7_6_SYSREPO
using namespace sysrepo;
#endif
......
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