Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Pavel Zhukov
Kea
Commits
10bd3121
Commit
10bd3121
authored
Jun 13, 2019
by
Francis Dupont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[583-cb-cmds-config-get-returns-wrong-subnet-range] Fixed prefixLengthFromRange
parent
ae8cd046
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
97 additions
and
5 deletions
+97
-5
src/lib/asiolink/addr_utilities.cc
src/lib/asiolink/addr_utilities.cc
+11
-1
src/lib/asiolink/tests/addr_utilities_unittest.cc
src/lib/asiolink/tests/addr_utilities_unittest.cc
+11
-1
src/lib/asiolink/tests/udp_socket_unittest.cc
src/lib/asiolink/tests/udp_socket_unittest.cc
+2
-2
src/lib/dhcpsrv/pool.h
src/lib/dhcpsrv/pool.h
+1
-1
src/lib/dhcpsrv/tests/pool_unittest.cc
src/lib/dhcpsrv/tests/pool_unittest.cc
+72
-0
No files found.
src/lib/asiolink/addr_utilities.cc
View file @
10bd3121
// Copyright (C) 2012-201
8
Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012-201
9
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
...
...
@@ -286,7 +286,12 @@ prefixLengthFromRange(const IOAddress& min, const IOAddress& max) {
uint32_t
min_numeric
=
min
.
toUint32
();
// Get the exclusive or which must be one of the bit masks
// and the min must be at the beginning of the prefix
// so it does not contribute to trailing ones.
uint32_t
xor_numeric
=
max_numeric
^
min_numeric
;
if
((
min_numeric
&
~
xor_numeric
)
!=
min_numeric
)
{
return
(
-
1
);
}
for
(
uint8_t
prefix_len
=
0
;
prefix_len
<=
32
;
++
prefix_len
)
{
if
(
xor_numeric
==
bitMask4
[
prefix_len
])
{
// Got it: the wanted value is also the index
...
...
@@ -308,6 +313,11 @@ prefixLengthFromRange(const IOAddress& min, const IOAddress& max) {
bool
zeroes
=
true
;
for
(
uint8_t
i
=
0
;
i
<
16
;
++
i
)
{
uint8_t
xor_byte
=
min_packed
[
i
]
^
max_packed
[
i
];
// The min must be at the beginning of the prefix
// so it does not contribute to trailing ones.
if
((
min_packed
[
i
]
&
~
xor_byte
)
!=
min_packed
[
i
])
{
return
(
-
1
);
}
if
(
zeroes
)
{
// Skipping zero bits searching for one bits
if
(
xor_byte
==
0
)
{
...
...
src/lib/asiolink/tests/addr_utilities_unittest.cc
View file @
10bd3121
// Copyright (C) 2012-201
8
Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012-201
9
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
...
...
@@ -266,6 +266,9 @@ TEST(AddrUtilitiesTest, prefixLengthFromRange4) {
// Fail if a network boundary is crossed
EXPECT_EQ
(
-
1
,
plfr
(
IOAddress
(
"10.0.0.255"
),
IOAddress
(
"10.0.1.1"
)));
// Fail if first is not at the begin
EXPECT_EQ
(
-
1
,
plfr
(
IOAddress
(
"10.0.0.2"
),
IOAddress
(
"10.0.0.5"
)));
// The upper bound cannot be smaller than the lower bound
EXPECT_THROW
(
plfr
(
IOAddress
(
"192.0.2.5"
),
IOAddress
(
"192.0.2.4"
)),
isc
::
BadValue
);
...
...
@@ -323,6 +326,13 @@ TEST(AddrUtilitiesTest, prefixLengthFromRange6) {
EXPECT_EQ
(
-
1
,
plfr
(
IOAddress
(
"2001:db8::ffff"
),
IOAddress
(
"2001:db8::1:1"
)));
// Fail if first is not at the begin
EXPECT_EQ
(
-
1
,
plfr
(
IOAddress
(
"2001:db8::2"
),
IOAddress
(
"2001:db8::5"
)));
EXPECT_EQ
(
-
1
,
plfr
(
IOAddress
(
"2001:db8::2:0"
),
IOAddress
(
"2001:db8::5:ffff"
)));
EXPECT_EQ
(
-
1
,
plfr
(
IOAddress
(
"2001:db8::2:ff00:0"
),
IOAddress
(
"2001:db8::3:00ff:ffff"
)));
// The upper bound cannot be smaller than the lower bound
EXPECT_THROW
(
plfr
(
IOAddress
(
"fe80::5"
),
IOAddress
(
"fe80::4"
)),
isc
::
BadValue
);
...
...
src/lib/asiolink/tests/udp_socket_unittest.cc
View file @
10bd3121
// Copyright (C) 2011-201
6
Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2011-201
9
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
...
...
@@ -166,7 +166,7 @@ TEST(UDPSocket, processReceivedData) {
// Where data is put
// cppcheck-suppress variableScope
size_t
expected
;
// Expected amount of data
// cppcheck-suppress variableScope
// cppcheck-suppress variableScope
size_t
offset
;
// Where to put next data
// cppcheck-suppress variableScope
size_t
cumulative
;
// Cumulative data received
...
...
src/lib/dhcpsrv/pool.h
View file @
10bd3121
...
...
@@ -26,7 +26,7 @@ namespace dhcp {
///
/// Stores information about pool of IPv4 or IPv6 addresses.
/// That is a basic component of a configuration.
class
Pool
:
public
isc
::
data
::
UserContext
{
class
Pool
:
public
isc
::
data
::
UserContext
,
public
isc
::
data
::
CfgToElement
{
public:
/// @note:
...
...
src/lib/dhcpsrv/tests/pool_unittest.cc
View file @
10bd3121
...
...
@@ -10,6 +10,7 @@
#include <cc/data.h>
#include <dhcp/option6_pdexclude.h>
#include <dhcpsrv/pool.h>
#include <testutils/test_to_element.h>
#include <boost/scoped_ptr.hpp>
...
...
@@ -120,6 +121,33 @@ TEST(Pool4Test, toText) {
Pool4
pool2
(
IOAddress
(
"192.0.2.128"
),
28
);
EXPECT_EQ
(
"type=V4, 192.0.2.128-192.0.2.143"
,
pool2
.
toText
());
Pool4
pool3
(
IOAddress
(
"192.0.2.0"
),
IOAddress
(
"192.0.2.127"
));
EXPECT_EQ
(
"type=V4, 192.0.2.0-192.0.2.127"
,
pool3
.
toText
());
}
// Simple check if toElement returns reasonable values
TEST
(
Pool4Test
,
toElement
)
{
Pool4
pool1
(
IOAddress
(
"192.0.2.7"
),
IOAddress
(
"192.0.2.17"
));
std
::
string
expected1
=
"{"
"
\"
pool
\"
:
\"
192.0.2.7-192.0.2.17
\"
, "
"
\"
option-data
\"
: [ ] "
"}"
;
isc
::
test
::
runToElementTest
<
Pool4
>
(
expected1
,
pool1
);
Pool4
pool2
(
IOAddress
(
"192.0.2.128"
),
28
);
std
::
string
expected2
=
"{"
"
\"
pool
\"
:
\"
192.0.2.128/28
\"
, "
"
\"
option-data
\"
: [ ] "
"}"
;
isc
::
test
::
runToElementTest
<
Pool4
>
(
expected2
,
pool2
);
Pool4
pool3
(
IOAddress
(
"192.0.2.0"
),
IOAddress
(
"192.0.2.127"
));
std
::
string
expected3
=
"{"
"
\"
pool
\"
:
\"
192.0.2.0/25
\"
, "
"
\"
option-data
\"
: [ ] "
"}"
;
isc
::
test
::
runToElementTest
<
Pool4
>
(
expected3
,
pool3
);
}
// This test checks that it is possible to specify pool specific options.
...
...
@@ -506,6 +534,50 @@ TEST(Pool6Test, toText) {
" excluded_prefix_len=120"
,
pool3
.
toText
());
Pool6
pool4
(
Lease
::
TYPE_NA
,
IOAddress
(
"2001:db8::"
),
IOAddress
(
"2001:db8::ffff"
));
EXPECT_EQ
(
"type=IA_NA, 2001:db8::-2001:db8::ffff, delegated_len=128"
,
pool4
.
toText
());
}
// Simple check if toElement returns reasonable values
TEST
(
Pool6Test
,
toElement
)
{
Pool6
pool1
(
Lease
::
TYPE_NA
,
IOAddress
(
"2001:db8::1"
),
IOAddress
(
"2001:db8::2"
));
std
::
string
expected1
=
"{"
"
\"
pool
\"
:
\"
2001:db8::1-2001:db8::2
\"
, "
"
\"
option-data
\"
: [ ] "
"}"
;
isc
::
test
::
runToElementTest
<
Pool6
>
(
expected1
,
pool1
);
Pool6
pool2
(
Lease
::
TYPE_PD
,
IOAddress
(
"2001:db8:1::"
),
96
,
112
);
std
::
string
expected2
=
"{"
"
\"
prefix
\"
:
\"
2001:db8:1::
\"
, "
"
\"
prefix-len
\"
: 96, "
"
\"
delegated-len
\"
: 112, "
"
\"
option-data
\"
: [ ] "
"}"
;
isc
::
test
::
runToElementTest
<
Pool6
>
(
expected2
,
pool2
);
Pool6
pool3
(
IOAddress
(
"2001:db8:1::"
),
96
,
112
,
IOAddress
(
"2001:db8:1::1000"
),
120
);
std
::
string
expected3
=
"{"
"
\"
prefix
\"
:
\"
2001:db8:1::
\"
, "
"
\"
prefix-len
\"
: 96, "
"
\"
delegated-len
\"
: 112, "
"
\"
excluded-prefix
\"
:
\"
2001:db8:1::1000
\"
, "
"
\"
excluded-prefix-len
\"
: 120, "
"
\"
option-data
\"
: [ ] "
"}"
;
isc
::
test
::
runToElementTest
<
Pool6
>
(
expected3
,
pool3
);
Pool6
pool4
(
Lease
::
TYPE_NA
,
IOAddress
(
"2001:db8::"
),
IOAddress
(
"2001:db8::ffff"
));
std
::
string
expected4
=
"{"
"
\"
pool
\"
:
\"
2001:db8::/112
\"
, "
"
\"
option-data
\"
: [ ] "
"}"
;
isc
::
test
::
runToElementTest
<
Pool6
>
(
expected4
,
pool4
);
}
// Checks if the number of possible leases in range is reported correctly.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment