Kea 2.5.8
ip_range.cc
Go to the documentation of this file.
1// Copyright (C) 2020-2023 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
10#include <dhcpsrv/ip_range.h>
12
13using namespace isc::asiolink;
14
15namespace isc {
16namespace dhcp {
17
19 : start_(start), end_(end) {
20 // Two IPv4 or two IPv6 addresses are expected as range boundaries.
21 if (start_.getFamily() != end_.getFamily()) {
22 isc_throw(BadValue, "address range boundaries must have the same type: " << start_
23 << ":" << end_);
24 }
25 // The start must be lower or equal the end.
26 if (end_ < start_) {
27 isc_throw(BadValue, "invalid address range boundaries " << start_ << ":" << end_);
28 }
29}
30
31PrefixRange::PrefixRange(const asiolink::IOAddress& prefix, const uint8_t length, const uint8_t delegated)
32 : start_(prefix), end_(IOAddress::IPV6_ZERO_ADDRESS()), prefix_length_(length),
33 delegated_length_(delegated) {
34 if (!start_.isV6()) {
35 isc_throw(BadValue, "IPv6 prefix required for prefix delegation range but "
36 << start_ << " was specified");
37 }
39 isc_throw(BadValue, "delegated length " << static_cast<int>(delegated_length_)
40 << " must not be lower than prefix length " << static_cast<int>(length));
41 }
42 if ((prefix_length_ > 128) || (delegated_length_ > 128)) {
43 isc_throw(BadValue, "delegated length " << static_cast<int>(delegated_length_)
44 << " and prefix length " << static_cast<int>(length)
45 << " must not be greater than 128");
46 }
47 // Now calculate the last prefix in the range.
48 end_ = lastAddrInPrefix(prefix, length);
49}
50
52 const uint8_t delegated)
53 : start_(start), end_(end), prefix_length_(prefixLengthFromRange(start, end)),
54 delegated_length_(delegated) {
55 if (!start_.isV6() || !end_.isV6()) {
56 isc_throw(BadValue, "IPv6 prefix required for prefix delegation range but "
57 << start_ << ":" << end_ << " was specified");
58 }
59 // The start must be lower or equal the end.
60 if (end_ < start_) {
61 isc_throw(BadValue, "invalid address range boundaries " << start_ << ":" << end_);
62 }
63 if (prefix_length_ > 128) {
64 isc_throw(BadValue, "the " << start_ << ":" << end_
65 << " does not constitute a valid prefix delegation range");
66 }
67 if (delegated_length_ > 128) {
68 isc_throw(BadValue, "delegated length " << static_cast<int>(delegated_length_)
69 << " must not be greater than 128");
70 }
71}
72
73} // end of namespace isc::dhcp
74} // end of namespace isc
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Defines the logger used by the top-level component of kea-lfc.
asiolink::IOAddress start_
IP address denoting the start of the address range.
Definition: ip_range.h:18
asiolink::IOAddress end_
IP address denoting the end of the address range.
Definition: ip_range.h:20
AddressRange(const asiolink::IOAddress &start, const asiolink::IOAddress &end)
Constructor.
Definition: ip_range.cc:18
uint8_t prefix_length_
Prefix length.
Definition: ip_range.h:39
uint8_t delegated_length_
Delegated prefix length.
Definition: ip_range.h:41
PrefixRange(const asiolink::IOAddress &prefix, const uint8_t length, const uint8_t delegated)
Constructor.
Definition: ip_range.cc:31
asiolink::IOAddress start_
IP address denoting the start of the prefix range.
Definition: ip_range.h:34
asiolink::IOAddress end_
IP address denoting the first address within the last prefix in the prefix range.
Definition: ip_range.h:37