summaryrefslogtreecommitdiffstats
path: root/src/lib/dhcpsrv/ip_range.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 12:15:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 12:15:43 +0000
commitf5f56e1a1c4d9e9496fcb9d81131066a964ccd23 (patch)
tree49e44c6f87febed37efb953ab5485aa49f6481a7 /src/lib/dhcpsrv/ip_range.cc
parentInitial commit. (diff)
downloadisc-kea-f5f56e1a1c4d9e9496fcb9d81131066a964ccd23.tar.xz
isc-kea-f5f56e1a1c4d9e9496fcb9d81131066a964ccd23.zip
Adding upstream version 2.4.1.upstream/2.4.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/lib/dhcpsrv/ip_range.cc')
-rw-r--r--src/lib/dhcpsrv/ip_range.cc74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/lib/dhcpsrv/ip_range.cc b/src/lib/dhcpsrv/ip_range.cc
new file mode 100644
index 0000000..4630e15
--- /dev/null
+++ b/src/lib/dhcpsrv/ip_range.cc
@@ -0,0 +1,74 @@
+// Copyright (C) 2020-2023 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+#include <asiolink/addr_utilities.h>
+#include <asiolink/io_address.h>
+#include <dhcpsrv/ip_range.h>
+#include <exceptions/exceptions.h>
+
+using namespace isc::asiolink;
+
+namespace isc {
+namespace dhcp {
+
+AddressRange::AddressRange(const IOAddress& start, const IOAddress& end)
+ : start_(start), end_(end) {
+ // Two IPv4 or two IPv6 addresses are expected as range boundaries.
+ if (start_.getFamily() != end_.getFamily()) {
+ isc_throw(BadValue, "address range boundaries must have the same type: " << start_
+ << ":" << end_);
+ }
+ // The start must be lower or equal the end.
+ if (end_ < start_) {
+ isc_throw(BadValue, "invalid address range boundaries " << start_ << ":" << end_);
+ }
+}
+
+PrefixRange::PrefixRange(const asiolink::IOAddress& prefix, const uint8_t length, const uint8_t delegated)
+ : start_(prefix), end_(IOAddress::IPV6_ZERO_ADDRESS()), prefix_length_(length),
+ delegated_length_(delegated) {
+ if (!start_.isV6()) {
+ isc_throw(BadValue, "IPv6 prefix required for prefix delegation range but "
+ << start_ << " was specified");
+ }
+ if (delegated_length_ < prefix_length_) {
+ isc_throw(BadValue, "delegated length " << static_cast<int>(delegated_length_)
+ << " must not be lower than prefix length " << static_cast<int>(length));
+ }
+ if ((prefix_length_ > 128) || (delegated_length_ > 128)) {
+ isc_throw(BadValue, "delegated length " << static_cast<int>(delegated_length_)
+ << " and prefix length " << static_cast<int>(length)
+ << " must not be greater than 128");
+ }
+ // Now calculate the last prefix in the range.
+ end_ = lastAddrInPrefix(prefix, length);
+}
+
+PrefixRange::PrefixRange(const asiolink::IOAddress& start, const asiolink::IOAddress& end,
+ const uint8_t delegated)
+ : start_(start), end_(end), prefix_length_(prefixLengthFromRange(start, end)),
+ delegated_length_(delegated) {
+ if (!start_.isV6() || !end_.isV6()) {
+ isc_throw(BadValue, "IPv6 prefix required for prefix delegation range but "
+ << start_ << ":" << end_ << " was specified");
+ }
+ // The start must be lower or equal the end.
+ if (end_ < start_) {
+ isc_throw(BadValue, "invalid address range boundaries " << start_ << ":" << end_);
+ }
+ if (prefix_length_ > 128) {
+ isc_throw(BadValue, "the " << start_ << ":" << end_
+ << " does not constitute a valid prefix delegation range");
+ }
+ if (delegated_length_ > 128) {
+ isc_throw(BadValue, "delegated length " << static_cast<int>(delegated_length_)
+ << " must not be greater than 128");
+ }
+}
+
+} // end of namespace isc::dhcp
+} // end of namespace isc