// 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 <asiolink/io_address.h>
+#include <asiolink/addr_utilities.h>
#include <cc/data.h>
#include <dhcp/hwaddr.h>
-#include <asiolink/io_address.h>
#include <dhcpsrv/lease.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/cfg_consistency.h>
ctx = copied;
}
+ // Check if the prefix length is sane
+ if (prefix_len == 0 || prefix_len > 128) {
+ isc_throw(BadValue, "Invalid prefix length: "
+ << static_cast<unsigned>(prefix_len));
+ }
+
+ if (prefix_len != 128) {
+ IOAddress first_address = firstAddrInPrefix(addr, prefix_len);
+ if (first_address != addr) {
+ isc_throw(BadValue, "Invalid Pool6 address boundaries: " << addr
+ << " is not the first address in prefix: " << first_address
+ << "/" << static_cast<uint32_t>(prefix_len));
+ }
+ }
+
// Let's fabricate some data and we're ready to go.
Lease6Ptr l(new Lease6(type, addr, duid_ptr, iaid, pref_lft, valid_lft,
subnet_id, fqdn_fwd, fqdn_rev, hostname,
" \"command\": \"lease6-add\",\n"
" \"arguments\": {"
" \"subnet-id\": 66,\n"
- " \"ip-address\": \"2001:db8:1::1\",\n"
+ " \"ip-address\": \"2001:db8:1::\",\n"
" \"prefix-len\": 48,\n"
" \"type\": \"IA_PD\",\n"
" \"duid\": \"1a:1b:1c:1d:1e:1f\",\n"
"}";
exp_rsp = "Invalid declined state for PD prefix.";
testCommand(txt, CONTROL_RESULT_ERROR, exp_rsp);
+
+ // Invalid prefix len for PD prefix.
+ txt =
+ "{\n"
+ " \"command\": \"lease6-add\",\n"
+ " \"arguments\": {"
+ " \"subnet-id\": 66,\n"
+ " \"ip-address\": \"2001:db8:1::1\",\n"
+ " \"prefix-len\": 48,\n"
+ " \"type\": \"IA_PD\",\n"
+ " \"duid\": \"1a:1b:1c:1d:1e:1f\",\n"
+ " \"iaid\": 1234\n"
+ " }\n"
+ "}";
+ exp_rsp = "Invalid Pool6 address boundaries: 2001:db8:1::1 is not the first address in prefix: 2001:db8:1::/48";
+ testCommand(txt, CONTROL_RESULT_ERROR, exp_rsp);
}
void Lease6CmdsTest::testLease6Add() {
" \"command\": \"lease6-update\",\n"
" \"arguments\": {"
" \"subnet-id\": 66,\n"
- " \"ip-address\": \"2001:db8:1::1\",\n"
+ " \"ip-address\": \"2001:db8:1::\",\n"
" \"prefix-len\": 48,\n"
" \"type\": \"IA_PD\",\n"
" \"duid\": \"1a:1b:1c:1d:1e:1f\",\n"
"}";
exp_rsp = "Invalid declined state for PD prefix.";
testCommand(txt, CONTROL_RESULT_ERROR, exp_rsp);
+
+ // Invalid prefix len for PD prefix.
+ txt =
+ "{\n"
+ " \"command\": \"lease6-update\",\n"
+ " \"arguments\": {"
+ " \"subnet-id\": 66,\n"
+ " \"ip-address\": \"2001:db8:1::1\",\n"
+ " \"prefix-len\": 48,\n"
+ " \"type\": \"IA_PD\",\n"
+ " \"duid\": \"1a:1b:1c:1d:1e:1f\",\n"
+ " \"iaid\": 1234\n"
+ " }\n"
+ "}";
+ exp_rsp = "Invalid Pool6 address boundaries: 2001:db8:1::1 is not the first address in prefix: 2001:db8:1::/48";
+ testCommand(txt, CONTROL_RESULT_ERROR, exp_rsp);
}
void Lease6CmdsTest::testLease6UpdateNoLease() {
" \"leases\": ["
" {"
" \"subnet-id\": 66,\n"
- " \"ip-address\": \"2001:db8:1::123\",\n"
+ " \"ip-address\": \"2001:db8:1::\",\n"
" \"prefix-len\": 48,\n"
" \"type\": \"IA_PD\",\n"
" \"duid\": \"11:11:11:11:11:11\",\n"
string exp_rsp = "Invalid declined state for PD prefix.";
testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp);
+ // Invalid prefix len for PD prefix.
+ cmd =
+ "{\n"
+ " \"command\": \"lease6-bulk-apply\",\n"
+ " \"arguments\": {"
+ " \"leases\": ["
+ " {"
+ " \"subnet-id\": 66,\n"
+ " \"ip-address\": \"2001:db8:1::123\",\n"
+ " \"prefix-len\": 48,\n"
+ " \"type\": \"IA_PD\",\n"
+ " \"duid\": \"11:11:11:11:11:11\",\n"
+ " \"iaid\": 1234\n"
+ " }"
+ " ]"
+ " }"
+ "}";
+ exp_rsp = "Invalid Pool6 address boundaries: 2001:db8:1::123 is not the first address in prefix: 2001:db8:1::/48";
+ testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp);
+
// Check that the lease was not inserted.
EXPECT_FALSE(lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::123")));
}
" {"
" \"subnet-id\": 66,\n"
" \"ip-address\": \"2001:db8:1234:ab::\",\n"
- " \"prefix-len\": 56,\n"
+ " \"prefix-len\": 64,\n"
" \"type\": \"IA_PD\",\n"
" \"duid\": \"77:77:77:77:77:77\",\n"
" \"iaid\": 1234,\n"
string exp_rsp = "Invalid declined state for PD prefix.";
testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp);
+ // Invalid prefix len for PD prefix.
+ cmd =
+ "{\n"
+ " \"command\": \"lease6-bulk-apply\",\n"
+ " \"arguments\": {"
+ " \"leases\": ["
+ " {"
+ " \"subnet-id\": 66,\n"
+ " \"ip-address\": \"2001:db8:1234:ab::\",\n"
+ " \"prefix-len\": 56,\n"
+ " \"type\": \"IA_PD\",\n"
+ " \"duid\": \"77:77:77:77:77:77\",\n"
+ " \"iaid\": 1234\n"
+ " }"
+ " ]"
+ " }"
+ "}";
+ exp_rsp = "Invalid Pool6 address boundaries: 2001:db8:1234:ab:: is not the first address in prefix: 2001:db8:1234::/56";
+ testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp);
+
// Check that the lease we inserted is stored.
Lease6Ptr lease1 = lmptr_->getLease6(Lease::TYPE_PD, IOAddress("2001:db8:1234:ab::"));
ASSERT_TRUE(lease1);
#include <config.h>
#include <asiolink/io_address.h>
+#include <asiolink/addr_utilities.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/parsers/host_reservation_parser.h>
#include <dhcpsrv/parsers/option_data_parser.h>
<< "' is invalid");
}
- // Remove the slash character and the prefix length
+ if ((prefix_len == 0) || (prefix_len > 128)) {
+ isc_throw(OutOfRange,
+ "'prefix-len' value must be in range of [1..128]");
+ }
+
+ // Remove the slash character and the prefix length
// from the parsed value.
prefix.erase(len_pos);
// Finally, set the reservation type.
resrv_type = IPv6Resrv::TYPE_PD;
+
+ if (prefix_len != 128) {
+ IOAddress addr(prefix);
+ IOAddress first_address = firstAddrInPrefix(addr, prefix_len);
+ if (first_address != addr) {
+ isc_throw(BadValue, "Invalid lease address boundaries: " << addr
+ << " is not the first address in prefix: " << first_address
+ << "/" << static_cast<uint32_t>(prefix_len));
+ }
+ }
}
// Create a reservation for an address or prefix.
}
}
-
} else if (element.first == "client-classes") {
try {
BOOST_FOREACH(ConstElementPtr class_element,
<< static_cast<int>(prefix_len) << ")");
}
- if (((type == Lease::TYPE_NA) || (type == Lease::TYPE_TA)) &&
- (delegated_len != 128)) {
- isc_throw(BadValue, "For IA or TA pools, delegated prefix length must"
+ if ((type != Lease::TYPE_PD) && (delegated_len != 128)) {
+ isc_throw(BadValue, "For NA or TA pools, delegated prefix length must"
<< " be 128.");
}
<< static_cast<int>(delegated_len) << ")");
}
- IOAddress first_address = firstAddrInPrefix(prefix, prefix_len);
- if (first_address != prefix) {
- isc_throw(BadValue, "Invalid Pool6 address boundaries: " << prefix
- << " is not the first address in prefix: " << first_address
- << "/" << static_cast<uint32_t>(prefix_len));
+ if (prefix_len != 128) {
+ IOAddress first_address = firstAddrInPrefix(prefix, prefix_len);
+ if (first_address != prefix) {
+ isc_throw(BadValue, "Invalid Pool6 address boundaries: " << prefix
+ << " is not the first address in prefix: " << first_address
+ << "/" << static_cast<uint32_t>(prefix_len));
+ }
}
/// @todo: We should probably implement checks against weird addresses