Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
1791d198
Commit
1791d198
authored
Feb 10, 2014
by
Tomek Mrugalski
🛰
Browse files
[3274] white_list_ is now of ClientClasses type.
parent
0c74cff2
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/lib/dhcpsrv/subnet.cc
View file @
1791d198
...
...
@@ -83,12 +83,19 @@ Subnet::clientSupported(const isc::dhcp::ClientClasses& classes) const {
// support everyone.
}
return
(
classes
.
contains
(
white_list_
));
for
(
ClientClasses
::
const_iterator
it
=
white_list_
.
begin
();
it
!=
white_list_
.
end
();
++
it
)
{
if
(
classes
.
contains
(
*
it
))
{
return
(
true
);
}
}
return
(
false
);
}
void
Subnet
::
allowClientClass
(
const
isc
::
dhcp
::
ClientClass
&
class_name
)
{
white_list_
=
class_name
;
white_list_
.
insert
(
class_name
)
;
}
void
...
...
src/lib/dhcpsrv/subnet.h
View file @
1791d198
...
...
@@ -437,6 +437,11 @@ public:
/// it is supported. On the other hand, client belonging to classes
/// "foobar" and "zyxxy" is not supported.
///
/// @todo: Currently the logic is simple: client is supported if it belongs
/// to any class mentioned in white_list_. We will eventually need a
/// way to specify more fancy logic (e.g. to meet all classes, not just
/// any)
///
/// @param client_classes list of all classes the client belongs to
/// @return true if client can be supported, false otherwise
bool
...
...
@@ -588,19 +593,14 @@ protected:
/// @brief optional definition of a client class
///
/// If defined, only clients belonging to that class will be allowed to use
/// this particular subnet. The default value for this is "", which means
/// that any client is allowed, regardless of its class.
///
/// @todo This is just a single class for now, but it will eventually be
/// list of classes (only classes on the list are allowed, the rest is
/// rejected) and we'll also have black-list (only classes on the list are
/// rejected, the rest are allowed). Implementing this will require
/// fancy parser logic, so it may be a while until we support this.
/// This will lead to changing type of white_list_ to ClientClasses.
/// Note that the interface will remain the same (allowClientClass()
/// would still take a single ClientClass. It will just be possible
/// to call it multiple times to allow multiple classes).
ClientClass
white_list_
;
/// this particular subnet. The default value for this is an empty list,
/// which means that any client is allowed, regardless of its class.
///
/// @todo This is just a single list of allowed classes. We'll also need
/// to add a black-list (only classes on the list are rejected, the rest
/// are allowed). Implementing this will require more fancy parser logic,
/// so it may be a while until we support this.
ClientClasses
white_list_
;
private:
...
...
src/lib/dhcpsrv/tests/subnet_unittest.cc
View file @
1791d198
...
...
@@ -140,7 +140,7 @@ TEST(Subnet4Test, Subnet4_Pool4_checks) {
}
// Tests whether Subnet4 object is able to store and process properly
// information about allowed client class
es
.
// information about allowed client class
(a single class)
.
TEST
(
Subnet4Test
,
clientClasses
)
{
// Create the V4 subnet.
Subnet4Ptr
subnet
(
new
Subnet4
(
IOAddress
(
"192.0.2.0"
),
8
,
1
,
2
,
3
));
...
...
@@ -177,6 +177,42 @@ TEST(Subnet4Test, clientClasses) {
EXPECT_TRUE
(
subnet
->
clientSupported
(
three_classes
));
}
// Tests whether Subnet4 object is able to store and process properly
// information about allowed client classes (multiple classes allowed).
TEST
(
Subnet4Test
,
clientClassesMultiple
)
{
// Create the V4 subnet.
Subnet4Ptr
subnet
(
new
Subnet4
(
IOAddress
(
"192.0.2.0"
),
8
,
1
,
2
,
3
));
// This client does not belong to any class.
isc
::
dhcp
::
ClientClasses
no_class
;
// This client belongs to foo only.
isc
::
dhcp
::
ClientClasses
foo_class
;
foo_class
.
insert
(
"foo"
);
// This client belongs to bar only. I like that client.
isc
::
dhcp
::
ClientClasses
bar_class
;
bar_class
.
insert
(
"bar"
);
// No class restrictions defined, any client should be supported
EXPECT_TRUE
(
subnet
->
clientSupported
(
no_class
));
EXPECT_TRUE
(
subnet
->
clientSupported
(
foo_class
));
EXPECT_TRUE
(
subnet
->
clientSupported
(
bar_class
));
// Let's allow clients belongning to "bar" or "foo" class.
subnet
->
allowClientClass
(
"bar"
);
subnet
->
allowClientClass
(
"foo"
);
// Class-less clients are to be rejected.
EXPECT_FALSE
(
subnet
->
clientSupported
(
no_class
));
// Clients in foo class should be accepted.
EXPECT_TRUE
(
subnet
->
clientSupported
(
foo_class
));
// Clients in bar class should be accepted as well.
EXPECT_TRUE
(
subnet
->
clientSupported
(
bar_class
));
}
TEST
(
Subnet4Test
,
addInvalidOption
)
{
// Create the V4 subnet.
Subnet4Ptr
subnet
(
new
Subnet4
(
IOAddress
(
"192.0.2.0"
),
8
,
1
,
2
,
3
));
...
...
@@ -455,7 +491,7 @@ TEST(Subnet6Test, PoolTypes) {
}
// Tests whether Subnet6 object is able to store and process properly
// information about allowed client class
es
.
// information about allowed client class
(a single class)
.
TEST
(
Subnet6Test
,
clientClasses
)
{
// Create the V6 subnet.
Subnet6Ptr
subnet
(
new
Subnet6
(
IOAddress
(
"2001:db8:1::"
),
56
,
1
,
2
,
3
,
4
));
...
...
@@ -492,6 +528,42 @@ TEST(Subnet6Test, clientClasses) {
EXPECT_TRUE
(
subnet
->
clientSupported
(
three_classes
));
}
// Tests whether Subnet6 object is able to store and process properly
// information about allowed client class (multiple classes allowed).
TEST
(
Subnet6Test
,
clientClassesMultiple
)
{
// Create the V6 subnet.
Subnet6Ptr
subnet
(
new
Subnet6
(
IOAddress
(
"2001:db8:1::"
),
56
,
1
,
2
,
3
,
4
));
// This client does not belong to any class.
isc
::
dhcp
::
ClientClasses
no_class
;
// This client belongs to foo only.
isc
::
dhcp
::
ClientClasses
foo_class
;
foo_class
.
insert
(
"foo"
);
// This client belongs to bar only. I like that client.
isc
::
dhcp
::
ClientClasses
bar_class
;
bar_class
.
insert
(
"bar"
);
// No class restrictions defined, any client should be supported
EXPECT_TRUE
(
subnet
->
clientSupported
(
no_class
));
EXPECT_TRUE
(
subnet
->
clientSupported
(
foo_class
));
EXPECT_TRUE
(
subnet
->
clientSupported
(
bar_class
));
// Let's allow only clients belongning to "foo" or "bar" class.
subnet
->
allowClientClass
(
"foo"
);
subnet
->
allowClientClass
(
"bar"
);
// Class-less clients are to be rejected.
EXPECT_FALSE
(
subnet
->
clientSupported
(
no_class
));
// Clients in foo class should be accepted.
EXPECT_TRUE
(
subnet
->
clientSupported
(
foo_class
));
// Clients in bar class should be accepted as well.
EXPECT_TRUE
(
subnet
->
clientSupported
(
bar_class
));
}
TEST
(
Subnet6Test
,
Subnet6_Pool6_checks
)
{
Subnet6Ptr
subnet
(
new
Subnet6
(
IOAddress
(
"2001:db8:1::"
),
56
,
1
,
2
,
3
,
4
));
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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