Browse Source

[3186] user_chk hook selects subnet4 based on user registry.

Interrim checkin. Subnet4 selection is working.
Thomas Markwalder 11 years ago
parent
commit
11ec18030d
1 changed files with 25 additions and 12 deletions
  1. 25 12
      src/hooks/dhcp/user_chk/subnet_select_co.cc

+ 25 - 12
src/hooks/dhcp/user_chk/subnet_select_co.cc

@@ -2,6 +2,7 @@
 #include <dhcp/pkt4.h>
 #include <dhcp/dhcp6.h>
 #include <dhcp/pkt6.h>
+#include <dhcpsrv/subnet.h>
 #include <user_registry.h>
 
 extern UserRegistryPtr user_registry;
@@ -32,18 +33,24 @@ int subnet4_select(CalloutHandle& handle) {
         // 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! :" 
+            // User is in the registry, so leave the pre-selected
+            // subnet alone.
+            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! :" 
+            // User is not in the registry, so assign them to
+            // the last subnet in the collection.  By convention
+            // we are assuming this is the restricted subnet.
+            std::cout << "DHCP4 User is NOT registered! :"
                      << hwaddr->toText() << std::endl;
+            const isc::dhcp::Subnet4Collection *subnets = NULL;
+            handle.getArgument("subnet4collection", subnets);
+            handle.setArgument("subnet4", subnets->back());
         }
     } catch (const std::exception& ex) {
-        std::cout << "Exception in subnet4_select callout:" << ex.what() 
+        std::cout << "Exception in subnet4_select callout:" << ex.what()
                   << std::endl;
-            
+
     }
 
     return (0);
@@ -74,18 +81,24 @@ int subnet6_select(CalloutHandle& handle) {
         // 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! :" 
+            // User is in the registry, so leave the pre-selected
+            // subnet alone.
+            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! :" 
+            // User is not in the registry, so assign them to
+            // the last subnet in the collection.  By convention
+            // we are assuming this is the restricted subnet.
+            std::cout << "DHCP6 User is NOT registered! :"
                      << duid->toText() << std::endl;
+            const isc::dhcp::Subnet6Collection *subnets = NULL;
+            handle.getArgument("subnet6collection", subnets);
+            handle.setArgument("subnet6", subnets->back());
         }
     } catch (const std::exception& ex) {
-        std::cout << "Exception in subnet6_select callout:" << ex.what() 
+        std::cout << "Exception in subnet6_select callout:" << ex.what()
                   << std::endl;
-            
+
     }
 
     return (0);