Browse Source

[3747] Ignore Client Id flag is added to Subnet4.

Marcin Siodelski 10 years ago
parent
commit
946fe0113a
3 changed files with 39 additions and 3 deletions
  1. 2 2
      src/lib/dhcpsrv/subnet.cc
  2. 21 1
      src/lib/dhcpsrv/subnet.h
  3. 16 0
      src/lib/dhcpsrv/tests/subnet_unittest.cc

+ 2 - 2
src/lib/dhcpsrv/subnet.cc

@@ -179,8 +179,8 @@ Subnet4::Subnet4(const isc::asiolink::IOAddress& prefix, uint8_t length,
                  const Triplet<uint32_t>& t2,
                  const Triplet<uint32_t>& valid_lifetime,
                  const SubnetID id)
-:Subnet(prefix, length, t1, t2, valid_lifetime,
-        RelayInfo(IOAddress("0.0.0.0")), id), siaddr_(IOAddress("0.0.0.0")) {
+    : Subnet(prefix, length, t1, t2, valid_lifetime, RelayInfo(IOAddress("0.0.0.0")), id),
+      siaddr_(IOAddress("0.0.0.0")), ignore_client_id_(false) {
     if (!prefix.isV4()) {
         isc_throw(BadValue, "Non IPv4 prefix " << prefix.toText()
                   << " specified in subnet4");

+ 21 - 1
src/lib/dhcpsrv/subnet.h

@@ -542,7 +542,24 @@ public:
     /// @return siaddr value
     isc::asiolink::IOAddress getSiaddr() const;
 
-protected:
+    /// @brief Sets the flag indicating if the client identifier should be
+    /// ignored in the client's message.
+    ///
+    /// @param ignore If this value is true, the client identifiers are ignored
+    /// in the messages from the clients for this subnet.
+    void setIgnoreClientId(const bool ignore) {
+        ignore_client_id_ = ignore;
+    }
+
+    /// @brief Returns the flag indicating if the client identifiers should
+    /// be ignored for this subnet.
+    ///
+    /// @return true if client identifiers should be ignored, false otherwise.
+    bool getIgnoreClientId() const {
+        return (ignore_client_id_);
+    }
+
+private:
 
     /// @brief Returns default address for pool selection
     /// @return ANY IPv4 address
@@ -560,6 +577,9 @@ protected:
 
     /// @brief siaddr value for this subnet
     isc::asiolink::IOAddress siaddr_;
+
+    /// @brief Should server ignore client identifiers.
+    bool ignore_client_id_;
 };
 
 /// @brief A pointer to a @c Subnet4 object

+ 16 - 0
src/lib/dhcpsrv/tests/subnet_unittest.cc

@@ -116,6 +116,22 @@ TEST(Subnet4Test, siaddr) {
         BadValue);
 }
 
+// Checks if the ignore-client-id flag can be set and retrieved.
+TEST(Subnet4Test, ignoreClientId) {
+    Subnet4 subnet(IOAddress("192.0.2.1"), 24, 1000, 2000, 3000);
+
+    // By default the flag should be set to false.
+    EXPECT_FALSE(subnet.getIgnoreClientId());
+
+    // Modify it and retrieve.
+    subnet.setIgnoreClientId(true);
+    EXPECT_TRUE(subnet.getIgnoreClientId());
+
+    // Modify again.
+    subnet.setIgnoreClientId(false);
+    EXPECT_FALSE(subnet.getIgnoreClientId());
+}
+
 TEST(Subnet4Test, Pool4InSubnet4) {
 
     Subnet4Ptr subnet(new Subnet4(IOAddress("192.1.2.0"), 24, 1, 2, 3));