Parcourir la source

[5364] Added log messages to the DHCP servers about dynamic subnet change.

Marcin Siodelski il y a 7 ans
Parent
commit
7e03503ebc

+ 8 - 0
src/bin/dhcp4/dhcp4_messages.mes

@@ -663,6 +663,14 @@ the client. The first argument includes the client and the
 transaction identification information. The second arguments
 includes the subnet details.
 
+% DHCP4_SUBNET_DYNAMICALLY_CHANGED %1: changed selected subnet %2 to subnet %3 from shared network %4 for client assignments
+This debug message indicates that the server is using another subnet
+than initially selected for client assignments. This newly selected
+subnet belongs to the same shared network as the original subnet.
+Some reasons why the new subnet was selected include: address pool
+exhaustion in the original subnet or the fact that the new subnet
+includes some static reservations for this client.
+
 % DHCP4_SUBNET_SELECTED %1: the subnet with ID %2 was selected for client assignments
 This is a debug message noting the selection of a subnet to be used for
 address and option assignment. Subnet selection is one of the early

+ 12 - 1
src/bin/dhcp4/dhcp4_srv.cc

@@ -1835,7 +1835,18 @@ Dhcpv4Srv::assignLease(Dhcpv4Exchange& ex) {
 
     // Subnet may be modified by the allocation engine, if the initial subnet
     // belongs to a shared network.
-    subnet = ctx->subnet_;
+    if (subnet->getID() != ctx->subnet_->getID()) {
+        SharedNetwork4Ptr network;
+        subnet->getSharedNetwork(network);
+        if (network) {
+            LOG_DEBUG(packet4_logger, DBG_DHCP4_BASIC_DATA, DHCP4_SUBNET_DYNAMICALLY_CHANGED)
+                .arg(query->getLabel())
+                .arg(subnet->toText())
+                .arg(ctx->subnet_->toText())
+                .arg(network->getName());
+        }
+        subnet = ctx->subnet_;
+    }
 
     if (lease) {
         // We have a lease! Let's set it in the packet and send it back to

+ 8 - 0
src/bin/dhcp6/dhcp6_messages.mes

@@ -711,6 +711,14 @@ the client. The first argument includes the client and the
 transaction identification information. The second argument
 includes the subnet details.
 
+% DHCP6_SUBNET_DYNAMICALLY_CHANGED %1: changed selected subnet %2 to subnet %3 from shared network %4 for client assignments
+This debug message indicates that the server is using another subnet
+than initially selected for client assignments. This newly selected
+subnet belongs to the same shared network as the original subnet.
+Some reasons why the new subnet was selected include: address pool
+exhaustion in the original subnet or the fact that the new subnet
+includes some static reservations for this client.
+
 % DHCP6_SUBNET_SELECTED %1: the subnet with ID %2 was selected for client assignments
 This is a debug message noting the selection of a subnet to be used for
 address and option assignment. Subnet selection is one of the early

+ 16 - 0
src/bin/dhcp6/dhcp6_srv.cc

@@ -1195,6 +1195,8 @@ void
 Dhcpv6Srv::assignLeases(const Pkt6Ptr& question, Pkt6Ptr& answer,
                         AllocEngine::ClientContext6& ctx) {
 
+    Subnet6Ptr subnet = ctx.subnet_;
+
     // We need to allocate addresses for all IA_NA options in the client's
     // question (i.e. SOLICIT or REQUEST) message.
     // @todo add support for IA_TA
@@ -1232,6 +1234,20 @@ Dhcpv6Srv::assignLeases(const Pkt6Ptr& question, Pkt6Ptr& answer,
             break;
         }
     }
+
+    // Subnet may be modified by the allocation engine, if the initial subnet
+    // belongs to a shared network.
+    if (subnet->getID() != ctx.subnet_->getID()) {
+        SharedNetwork6Ptr network;
+        subnet->getSharedNetwork(network);
+        if (network) {
+            LOG_DEBUG(packet6_logger, DBG_DHCP6_BASIC_DATA, DHCP6_SUBNET_DYNAMICALLY_CHANGED)
+                .arg(question->getLabel())
+                .arg(subnet->toText())
+                .arg(ctx.subnet_->toText())
+                .arg(network->getName());
+        }
+    }
 }