]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2324] increaseAddress() added in IterativeAllocator.
authorTomek Mrugalski <tomasz@isc.org>
Thu, 18 Oct 2012 17:35:26 +0000 (19:35 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Thu, 18 Oct 2012 17:35:26 +0000 (19:35 +0200)
src/bin/dhcp6/Makefile.am
src/bin/dhcp6/alloc_engine.cc
src/bin/dhcp6/alloc_engine.h

index 68aadea5adecf63a4b2246fb70ed4f98fd6849f5..13e43f77ecdee534e359976428811b6e284cbca5 100644 (file)
@@ -47,6 +47,7 @@ pkglibexec_PROGRAMS = b10-dhcp6
 b10_dhcp6_SOURCES  = main.cc
 b10_dhcp6_SOURCES += ctrl_dhcp6_srv.cc ctrl_dhcp6_srv.h
 b10_dhcp6_SOURCES += config_parser.cc config_parser.h
+b10_dhcp6_SOURCES += alloc_engine.cc alloc_engine.h
 b10_dhcp6_SOURCES += dhcp6_log.cc dhcp6_log.h
 b10_dhcp6_SOURCES += dhcp6_srv.cc dhcp6_srv.h
 
index 456022154ed07fff365b02d34093c225037a3260..0f67c14285d8674b01a189b5f1a91cac1a49708b 100644 (file)
@@ -24,6 +24,33 @@ AllocEngine::IterativeAllocator::IterativeAllocator()
     :Allocator() {
 }
 
+isc::asiolink::IOAddress
+AllocEngine::IterativeAllocator::increaseAddress(const isc::asiolink::IOAddress& addr) {
+    uint8_t packed[V6ADDRESS_LEN];
+    int len;
+    if (addr.getFamily()==AF_INET) {
+        // IPv4
+        memcpy(packed, addr.getAddress().to_v4().to_bytes().data(), 4);
+        len = 4;
+    } else {
+        // IPv6
+        memcpy(packed, addr.getAddress().to_v6().to_bytes().data(), 16);
+        len = 16;
+    }
+
+    // First we copy the whole address as 16 bytes.
+    bool carry = false;
+    for (int i = len; i >=0; --i) {
+        packed[i]++;
+        if (packed[i] != 0) {
+            break;
+        }
+    }
+
+    return (IOAddress::from_bytes(addr.getFamily(), packed));
+}
+
+
 isc::asiolink::IOAddress
 AllocEngine::IterativeAllocator::pickAddress(const Subnet6Ptr& subnet,
                                              const DuidPtr& duid,
@@ -118,6 +145,14 @@ AllocEngine::allocateAddress6(const Subnet6Ptr& subnet,
         isc_throw(InvalidOperation, "No allocator selected");
     }
 
+    // check if there's existing lease for that subnet/duid/iaid combination.
+    Lease6Ptr existing = LeaseMgr::instance().getLease6(*duid, iaid, subnet->getID());
+    if (existing) {
+        // we have a lease already. This is a returning client, probably after
+        // his reboot.
+        return (existing);
+    }
+
     unsigned int i = attempts_;
     do {
         IOAddress candidate = allocator_->pickAddress(subnet, duid, hint);
@@ -153,12 +188,9 @@ Lease6Ptr AllocEngine::createLease(const Subnet6Ptr& subnet,
                                    uint32_t iaid,
                                    const IOAddress& addr) {
 
-    Lease6Ptr lease = new Lease6(Lease6::LEASE_IA_NA, addr, iaid,
-                                 duid, subnet->getPreferred(),
-                                 subnet->getValid(),
-                                 subnet->getT1(),
-                                 subnet->getT2(),
-                                 subnet->getID());
+    Lease6Ptr lease(new Lease6(Lease6::LEASE_IA_NA, addr, duid, iaid,
+                               subnet->getPreferred(), subnet->getValid(),
+                               subnet->getT1(), subnet->getT2(), subnet->getID()));
 
     bool status = LeaseMgr::instance().addLease(lease);
 
index 8fa0bbdcf01a6d79f2dc5d9a9da9f5f1a76b4f4f..baefe9240b6dc904f3f4deae24af653961ab1999 100644 (file)
@@ -67,7 +67,7 @@ protected:
                         const DuidPtr& duid,
                         const isc::asiolink::IOAddress& hint);
     private:
-        isc::asiolink::IOAddress increaseAddress(isc::asiolink::IOAddress& addr);
+        isc::asiolink::IOAddress increaseAddress(const isc::asiolink::IOAddress& addr);
 
     };