Bug #20475

Implement Random DB IPAM

Added by Lukas Zapletal 7 months ago. Updated 6 months ago.

Status:Closed
Priority:Normal
Assigned To:Lukas Zapletal
Category:DHCP
Target version:-
Difficulty: Bugzilla link:
Found in release: Pull request:https://github.com/theforeman/foreman/pull/4716
Story points-
Velocity based estimate-
Release1.16.0Release relationshipAuto

Description

Default implementation of DB IPAM increases numbers which creates lot of chances for race conditions when provisioning multiple hosts.

We should provide a random implementation that will randomize assigned IPs. It's not bullet-proof solution to the issue, but chances are much lower.

Workaround:

diff --git a/app/services/ipam/db.rb b/app/services/ipam/db.rb
index 87291ab3c..d7adff9f6 100644
--- a/app/services/ipam/db.rb
+++ b/app/services/ipam/db.rb
@@ -6,7 +6,7 @@ module IPAM
       subnet_range = IPAddr.new("#{subnet.network}/#{subnet.mask}", subnet.family).to_range
       from = subnet.from.present? ? IPAddr.new(subnet.from) : subnet_range.first(2).last
       to = subnet.to.present? ? IPAddr.new(subnet.to) : IPAddr.new(subnet_range.last.to_i - 2, subnet.family)
-      (from..to).each do |address|
+      (from..to).to_a.shuffle.each do |address|
         ip = address.to_s
         if !subnet.known_ips.include?(ip) && !excluded_ips.include?(ip)
           logger.debug("Found #{ip}")

Edit: This workaround does not work properly, can lead to huge allocation ending with OOM kill for larger subnets. This needs a proper patch.


Related issues

Related to Smart Proxy - Bug #20474: Multiple free IPs returned after record deletion Closed 08/01/2017

Associated revisions

Revision c84389de
Added by Lukas Zapletal 6 months ago

Fixes #20475 - Random DB IPAM with MAC preservation

History

#1 Updated by Lukas Zapletal 7 months ago

  • Related to Bug #20474: Multiple free IPs returned after record deletion added

#2 Updated by Lukas Zapletal 7 months ago

  • Description updated (diff)

#3 Updated by The Foreman Bot 7 months ago

  • Status changed from New to Ready For Testing
  • Assigned To set to Lukas Zapletal
  • Pull request https://github.com/theforeman/foreman/pull/4716 added

#4 Updated by Timo Goebel 6 months ago

  • Release set to 1.16.0

#5 Updated by Lukas Zapletal 6 months ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

Also available in: Atom PDF