<fix>[network]: filter reserved IPs in getFreeIp#3341
Open
zstack-robot-1 wants to merge 1 commit into5.5.6from
Open
<fix>[network]: filter reserved IPs in getFreeIp#3341zstack-robot-1 wants to merge 1 commit into5.5.6from
zstack-robot-1 wants to merge 1 commit into5.5.6from
Conversation
总体说明在 变更
预估代码审查工作量🎯 2 (简单) | ⏱️ ~8 分钟 诗歌
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@network/src/main/java/org/zstack/network/l3/IpRangeHelper.java`:
- Around line 158-170: The current logic in IpRangeHelper builds spareIps then
truncates by limit and only afterwards filters out ReservedIpRangeVO ranges
(checked via NetworkUtils.isInRange), which can leave fewer than limit
addresses; change the logic in the method handling ipr (the block using
spareIps, ReservedIpRangeVO and limit) to first exclude reserved ranges when
generating candidate IPs or, if you prefer minimal change, filter out reserved
IPs and then extend the candidate selection (iterate further in the IP range)
until you either reach the requested limit or exhaust the range; update the code
that builds spareIps so it checks ReservedIpRangeVO_.getStartIp()/getEndIp() via
NetworkUtils.isInRange while collecting candidates and only stops when
collected.size() == limit (or no more IPs).
Comment on lines
158
to
170
| List<ReservedIpRangeVO> reservedRanges = Q.New(ReservedIpRangeVO.class) | ||
| .eq(ReservedIpRangeVO_.l3NetworkUuid, ipr.getL3NetworkUuid()) | ||
| .list(); | ||
| if (!reservedRanges.isEmpty()) { | ||
| spareIps = spareIps.stream().filter(ip -> { | ||
| for (ReservedIpRangeVO reserved : reservedRanges) { | ||
| if (NetworkUtils.isInRange(ip, reserved.getStartIp(), reserved.getEndIp())) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| }).collect(Collectors.toList()); | ||
| } |
There was a problem hiding this comment.
过滤后可能少于 limit,影响可用 IP 分配。
spareIps 先按 limit 截断,再过滤保留范围,可能导致返回数量少于 limit(例如起始候选恰好是保留 IP),从而在仍有可用 IP 的情况下出现分配失败或不足。建议在生成阶段就排除保留范围,或在过滤后继续向后补足直到满足 limit 或耗尽范围。
🤖 Prompt for AI Agents
In `@network/src/main/java/org/zstack/network/l3/IpRangeHelper.java` around lines
158 - 170, The current logic in IpRangeHelper builds spareIps then truncates by
limit and only afterwards filters out ReservedIpRangeVO ranges (checked via
NetworkUtils.isInRange), which can leave fewer than limit addresses; change the
logic in the method handling ipr (the block using spareIps, ReservedIpRangeVO
and limit) to first exclude reserved ranges when generating candidate IPs or, if
you prefer minimal change, filter out reserved IPs and then extend the candidate
selection (iterate further in the IP range) until you either reach the requested
limit or exhaust the range; update the code that builds spareIps so it checks
ReservedIpRangeVO_.getStartIp()/getEndIp() via NetworkUtils.isInRange while
collecting candidates and only stops when collected.size() == limit (or no more
IPs).
Resolves: ZSTAC-81182 Change-Id: Id1bb642154dc66ae9995dcc4d9fc00cdce9bcaf8
60b958c to
6545350
Compare
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.
Resolves: ZSTAC-81182\n\nFilter out reserved IP addresses (gateway) in IpRangeHelper.getFreeIp() to prevent allocating them.
sync from gitlab !9170