Fix IP Allocation Bug: Reserved Range Not Detected#2657
Open
Conversation
Ivaylogi98
reviewed
Jan 30, 2026
src/bosh-director/lib/bosh/director/deployment_plan/ip_provider/ip_repo.rb
Show resolved
Hide resolved
…r/ip_repo.rb Co-authored-by: Ivaylo Ivanov <ivaylogi98@gmail.com>
…_provider/ip_repo.rb" This reverts commit 6f689a9.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is this change about?
This PR fixes a bug where BOSH allocates IPs from reserved CIDR ranges, causing CPI failures with "Address is in subnet's reserved address range" errors.
Root Cause: The overlap check in
find_next_available_ipwas unidirectional. It only checked if the candidate IP includes a blocking IP, but not if a blocking IP includes the candidate.When allocating a
/32(single IP) and the reserved range is a/30(4 IPs), the checkcandidate.include?(blocking)always returnsfalsebecause a smaller block cannot include a larger one. The reserved range was invisible to the algorithm.The Bug
Example:
10.0.11.32/3210.0.11.32/3010.0.11.32/32.include?(10.0.11.32/30)→falseThe Fix
Now
10.0.11.32/30.include?(10.0.11.32/32)→true→ correctly blocked.Additional Improvement: Deterministic Deduplication
The deduplication logic that removes redundant IPs (e.g.,
/32entries already covered by a/30block) has been refactored to sort IPs before processing. This ensures deterministic behavior regardless of Set iteration order, making the code easier to test and debug.What tests have you run?
Release notes
Fixed: IP allocation now correctly detects reserved CIDR ranges. Previously, when allocating single IPs (
/32) from a subnet with reserved ranges specified as larger blocks (e.g.,/30), the algorithm failed to detect the overlap and attempted to allocate reserved IPs, causing CPI errors.Breaking change?
No. This is a bug fix.