BIND 10 trac3186, updated. c95421cd2f4719b166700bac51361254483787ef [3186] Implemented initial callouts for subnet_select
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Oct 14 20:21:26 UTC 2013
The branch, trac3186 has been updated
via c95421cd2f4719b166700bac51361254483787ef (commit)
from 6291862d54c72d64178fe3c5f5b489120e297e12 (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 c95421cd2f4719b166700bac51361254483787ef
Author: Thomas Markwalder <tmark at isc.org>
Date: Mon Oct 14 16:16:20 2013 -0400
[3186] Implemented initial callouts for subnet_select
Added initial callout functions and ability to load the user_chk hooks library.
-----------------------------------------------------------------------
Summary of changes:
src/hooks/dhcp/user_chk/Makefile.am | 1 +
src/hooks/dhcp/user_chk/load_unload.cc | 20 ++++-
src/hooks/dhcp/user_chk/subnet_select_co.cc | 94 ++++++++++++++++++++
src/hooks/dhcp/user_chk/tests/Makefile.am | 3 +
.../dhcp/user_chk/tests/user_registry_unittests.cc | 3 +-
5 files changed, 117 insertions(+), 4 deletions(-)
create mode 100644 src/hooks/dhcp/user_chk/subnet_select_co.cc
-----------------------------------------------------------------------
diff --git a/src/hooks/dhcp/user_chk/Makefile.am b/src/hooks/dhcp/user_chk/Makefile.am
index f5bd13a..2dbcff9 100644
--- a/src/hooks/dhcp/user_chk/Makefile.am
+++ b/src/hooks/dhcp/user_chk/Makefile.am
@@ -32,6 +32,7 @@ CLEANFILES = *.gcno *.gcda
lib_LTLIBRARIES = libdhcp_user_chk.la
libdhcp_user_chk_la_SOURCES =
libdhcp_user_chk_la_SOURCES += load_unload.cc
+libdhcp_user_chk_la_SOURCES += subnet_select_co.cc
libdhcp_user_chk_la_SOURCES += user.cc user.h
libdhcp_user_chk_la_SOURCES += user_data_source.cc user_data_source.h
libdhcp_user_chk_la_SOURCES += user_file.cc user_file.h
diff --git a/src/hooks/dhcp/user_chk/load_unload.cc b/src/hooks/dhcp/user_chk/load_unload.cc
index 2d10fa4..d6eec2a 100644
--- a/src/hooks/dhcp/user_chk/load_unload.cc
+++ b/src/hooks/dhcp/user_chk/load_unload.cc
@@ -14,18 +14,34 @@
// load_unload.cc
#include <hooks/hooks.h>
+#include <user_registry.h>
+#include <user_file.h>
using namespace isc::hooks;
+UserRegistryPtr user_registry;
+
extern "C" {
int load(LibraryHandle&) {
- // @todo instantiate registry here
+ // @todo what about exception handling
+
+ // Instantiate the registry.
+ user_registry.reset(new UserRegistry());
+
+ // Create the data source.
+ UserDataSourcePtr user_file(new UserFile("/tmp/user_registry.txt"));
+
+ // Set the registry's data source
+ user_registry->setSource(user_file);
+
+ // Do an initial load of the registry.
+ user_registry->refresh();
return (0);
}
int unload() {
- // @todo destruct registry here
+ user_registry.reset();
return (0);
}
diff --git a/src/hooks/dhcp/user_chk/subnet_select_co.cc b/src/hooks/dhcp/user_chk/subnet_select_co.cc
new file mode 100644
index 0000000..83e5f2c
--- /dev/null
+++ b/src/hooks/dhcp/user_chk/subnet_select_co.cc
@@ -0,0 +1,94 @@
+#include <hooks/hooks.h>
+#include <dhcp/pkt4.h>
+#include <dhcp/dhcp6.h>
+#include <dhcp/pkt6.h>
+#include <user_registry.h>
+
+extern UserRegistryPtr user_registry;
+
+#include <string>
+
+using namespace isc::dhcp;
+using namespace isc::hooks;
+using namespace std;
+
+extern "C" {
+
+// This callout is called at the "subnet4_select" hook.
+int subnet4_select(CalloutHandle& handle) {
+ if (!user_registry) {
+ std::cout << "UserRegistry is null!" << std::endl;
+ }
+
+ try {
+ // Refresh the registry.
+ user_registry->refresh();
+
+ // Get the HWAddress as the user identifier.
+ Pkt4Ptr query;
+ handle.getArgument("query4", query);
+ HWAddrPtr hwaddr = query->getHWAddr();
+
+ // Look for the user.
+ UserPtr registered_user = user_registry->findUser(*hwaddr);
+ if (registered_user) {
+ //@todo give them an unrestricted subnet
+ std::cout << "DHCP4 User is registered! :"
+ << registered_user->getUserId() << std::endl;
+ } else {
+ //@todo give them a restricted subnet
+ std::cout << "DHCP4 User is NOT registered! :"
+ << hwaddr->toText() << std::endl;
+ }
+ } catch (const std::exception& ex) {
+ std::cout << "Exception in subnet4_select callout:" << ex.what()
+ << std::endl;
+
+ }
+
+ return (0);
+}
+
+// This callout is called at the "subnet6_select" hook.
+int subnet6_select(CalloutHandle& handle) {
+ if (!user_registry) {
+ std::cout << "UserRegistry is null!" << std::endl;
+ }
+
+ try {
+ // Refresh the registry.
+ user_registry->refresh();
+
+ // Get the HWAddress as the user identifier.
+ Pkt6Ptr query;
+ handle.getArgument("query6", query);
+
+ DuidPtr duid;
+ OptionPtr opt_duid = query->getOption(D6O_CLIENTID);
+ if (opt_duid) {
+ duid = DuidPtr(new DUID(opt_duid->getData()));
+ } else {
+ std::cout << "DHCP6 query is missing DUID" << std::endl;
+ }
+
+ // Look for the user.
+ UserPtr registered_user = user_registry->findUser(*duid);
+ if (registered_user) {
+ //@todo give them an unrestricted subnet
+ std::cout << "DHCP6 User is registered! :"
+ << registered_user->getUserId() << std::endl;
+ } else {
+ //@todo give them a restricted subnet
+ std::cout << "DHCP6 User is NOT registered! :"
+ << duid->toText() << std::endl;
+ }
+ } catch (const std::exception& ex) {
+ std::cout << "Exception in subnet6_select callout:" << ex.what()
+ << std::endl;
+
+ }
+
+ return (0);
+}
+
+}
diff --git a/src/hooks/dhcp/user_chk/tests/Makefile.am b/src/hooks/dhcp/user_chk/tests/Makefile.am
index 3ee9d09..32d257d 100644
--- a/src/hooks/dhcp/user_chk/tests/Makefile.am
+++ b/src/hooks/dhcp/user_chk/tests/Makefile.am
@@ -30,6 +30,9 @@ if HAVE_GTEST
TESTS += libdhcp_user_chk_unittests
libdhcp_user_chk_unittests_SOURCES =
+libdhcp_user_chk_unittests_SOURCES += ../load_unload.cc
+libdhcp_user_chk_unittests_SOURCES += ../subnet_select_co.cc
+libdhcp_user_chk_unittests_SOURCES += ../version.cc
libdhcp_user_chk_unittests_SOURCES += ../user.cc ../user.h
libdhcp_user_chk_unittests_SOURCES += ../user_data_source.cc ../user_data_source.h
libdhcp_user_chk_unittests_SOURCES += ../user_file.cc ../user_file.h
diff --git a/src/hooks/dhcp/user_chk/tests/user_registry_unittests.cc b/src/hooks/dhcp/user_chk/tests/user_registry_unittests.cc
index 5fee7c5..2061b8b 100644
--- a/src/hooks/dhcp/user_chk/tests/user_registry_unittests.cc
+++ b/src/hooks/dhcp/user_chk/tests/user_registry_unittests.cc
@@ -172,8 +172,7 @@ TEST(UserRegistry, userFileTest) {
// Set the registry's data source and refresh the registry.
ASSERT_NO_THROW(reg->setSource(user_file));
- //ASSERT_NO_THROW(reg->refresh());
- (reg->refresh());
+ ASSERT_NO_THROW(reg->refresh());
// Verify we can find all the expected users.
UserPtr found_user;
More information about the bind10-changes
mailing list