]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[4308] Subnet selection in v4 tweaked, added two debug messages.
authorTomek Mrugalski <tomasz@isc.org>
Thu, 19 May 2016 11:42:00 +0000 (13:42 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Thu, 19 May 2016 12:11:09 +0000 (14:11 +0200)
src/lib/dhcpsrv/cfg_subnets4.cc
src/lib/dhcpsrv/dhcpsrv_messages.mes
src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc

index 35a246981f8f9dfccf1b5cd7e60eef4f60e1407d..72b0a614dfccf4f5bd53b35f5e8a32d6fbdbafb0 100644 (file)
@@ -147,6 +147,10 @@ CfgSubnets4::selectSubnet(const SubnetSelector& selector) const {
         // selection criteria below.
         if (subnet) {
             return (subnet);
+        } else {
+            // Let's try to get an address from the local interface and
+            // try to match it to defined subnet.
+            iface->getAddress4(address);
         }
     }
 
@@ -180,6 +184,9 @@ CfgSubnets4::selectSubnet(const std::string& iface,
 
         // Eliminate those subnets that do not meet client class criteria.
         if ((*subnet)->clientSupported(client_classes)) {
+            LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE,
+                      DHCPSRV_CFGMGR_SUBNET4_IFACE)
+                .arg((*subnet)->toText()).arg(iface);
             return (*subnet);
         }
     }
@@ -201,6 +208,9 @@ CfgSubnets4::selectSubnet(const IOAddress& address,
 
         // Eliminate those subnets that do not meet client class criteria.
         if ((*subnet)->clientSupported(client_classes)) {
+            LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_CFGMGR_SUBNET4_ADDR)
+                .arg((*subnet)->toText()).arg(address.toText());
+
             return (*subnet);
         }
     }
index 712dab52fae8a7eb9601aeb39a807b3501229616..1a6647d55e812ad8ef47713502216e7ff8882f1e 100644 (file)
@@ -107,6 +107,19 @@ This is a debug message reporting that the DHCP configuration manager has
 returned the specified IPv4 subnet, because detected relay agent address
 matches value specified for this subnet.
 
+% DHCPSRV_CFGMGR_SUBNET4_ADDR selected subnet %1 for packet received by matching address %2
+This is a debug message reporting that the DHCP configuration manager
+has returned the specified IPv4 subnet for a packet received. This particular
+subnet was selected, because an IPv4 address was matched to belong to that
+subnet.
+
+% DHCPSRV_CFGMGR_SUBNET4_IFACE selected subnet %1 for packet received over interface %2
+This is a debug message reporting that the DHCP configuration manager
+has returned the specified IPv4 subnet for a packet received over
+given interface.  This particular subnet was selected, because it
+was specified as being directly reachable over given interface. (see
+'interface' parameter in the subnet4 definition).
+
 % DHCPSRV_CFGMGR_SUBNET6 retrieved subnet %1 for address hint %2
 This is a debug message reporting that the DHCP configuration manager has
 returned the specified IPv6 subnet when given the address hint specified
index 36ec5ae3c8656a5db6526430663935c688b7ca14..5698a2ae9ab7a609caa01fbeb4e2f8d86b014918 100644 (file)
@@ -61,6 +61,43 @@ TEST(CfgSubnets4Test, selectSubnetByCiaddr) {
     EXPECT_FALSE(cfg.selectSubnet(selector));
 }
 
+// This test verifies that it is possible to select a subnet by
+// matching an interface name.
+TEST(CfgSubnets4Test, selectSubnetByIface) {
+    // The IfaceMgrTestConfig object initializes fake interfaces:
+    // eth0, eth1 and lo on the configuration manager. The CfgSubnets4
+    // object uses addresses assigned to these fake interfaces to
+    // select the appropriate subnet.
+    IfaceMgrTestConfig config(true);
+
+    CfgSubnets4 cfg;
+
+    // Create 3 subnets.
+    Subnet4Ptr subnet1(new Subnet4(IOAddress("192.0.2.0"), 26, 1, 2, 3));
+    Subnet4Ptr subnet2(new Subnet4(IOAddress("192.0.2.64"), 26, 1, 2, 3));
+    Subnet4Ptr subnet3(new Subnet4(IOAddress("192.0.2.128"), 26, 1, 2, 3));
+    // No interface defined for subnet1
+    subnet2->setIface("lo");
+    subnet3->setIface("eth1");
+
+    cfg.add(subnet1);
+    cfg.add(subnet2);
+    cfg.add(subnet3);
+
+    // Make sure that initially the subnets don't exist.
+    SubnetSelector selector;
+    // Set an interface to a name that is not defined in the config.
+    // Subnet selection should fail.
+    selector.iface_name_ = "eth0";
+    ASSERT_FALSE(cfg.selectSubnet(selector));
+
+    // Now select an interface name that matches. Selection should succeed
+    // and return subnet3.
+    selector.iface_name_ = "eth1";
+    Subnet4Ptr selected = cfg.selectSubnet(selector);
+    ASSERT_TRUE(selected);
+    EXPECT_EQ(subnet3, selected);
+}
 
 // This test verifies that when the classification information is specified for
 // subnets, the proper subnets are returned by the subnet configuration.