BIND 10 trac3274, updated. 1791d19899b92a6ee411199f664bdfc690ec08b2 [3274] white_list_ is now of ClientClasses type.
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Feb 10 17:33:35 UTC 2014
The branch, trac3274 has been updated
via 1791d19899b92a6ee411199f664bdfc690ec08b2 (commit)
from 0c74cff26aa147bd1f8b807b441d86a064a90f60 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 1791d19899b92a6ee411199f664bdfc690ec08b2
Author: Tomek Mrugalski <tomasz at isc.org>
Date: Mon Feb 10 18:33:10 2014 +0100
[3274] white_list_ is now of ClientClasses type.
-----------------------------------------------------------------------
Summary of changes:
src/lib/dhcpsrv/subnet.cc | 11 ++++-
src/lib/dhcpsrv/subnet.h | 26 +++++-----
src/lib/dhcpsrv/tests/subnet_unittest.cc | 76 +++++++++++++++++++++++++++++-
3 files changed, 96 insertions(+), 17 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dhcpsrv/subnet.cc b/src/lib/dhcpsrv/subnet.cc
index 4738668..f181a3a 100644
--- a/src/lib/dhcpsrv/subnet.cc
+++ b/src/lib/dhcpsrv/subnet.cc
@@ -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
diff --git a/src/lib/dhcpsrv/subnet.h b/src/lib/dhcpsrv/subnet.h
index 08b6246..ae90761 100644
--- a/src/lib/dhcpsrv/subnet.h
+++ b/src/lib/dhcpsrv/subnet.h
@@ -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:
diff --git a/src/lib/dhcpsrv/tests/subnet_unittest.cc b/src/lib/dhcpsrv/tests/subnet_unittest.cc
index 0af68cf..a16f1a0 100644
--- a/src/lib/dhcpsrv/tests/subnet_unittest.cc
+++ b/src/lib/dhcpsrv/tests/subnet_unittest.cc
@@ -140,7 +140,7 @@ TEST(Subnet4Test, Subnet4_Pool4_checks) {
}
// Tests whether Subnet4 object is able to store and process properly
-// information about allowed client classes.
+// 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 classes.
+// 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));
More information about the bind10-changes
mailing list