Component
network / L3 network
Problem description
L3BasicNetwork.handle(APIGetFreeIpMsg) subtracts the cumulative result size (freeIpInventorys.size()) from the remaining limit after each IP range. The remaining limit must be reduced only by the number returned from the current range.
With several IP ranges and a requested limit, the remaining limit can become negative and later ranges return only one address, so the API returns fewer addresses than requested even when enough free addresses exist.
Relevant code:
https://github.com/ZSvirt/zsvirt/blob/main/network/src/main/java/org/zstack/network/l3/L3BasicNetwork.java#L876
Steps to reproduce
- Create an L3 network with at least six non-overlapping IP ranges, each with at least 20 free IPs.
- Call
GetFreeIpOfL3Network with limit=100.
- Observe that the response contains fewer than 100 free IPs.
Expected behavior
The API should return up to the requested limit across all matching IP ranges.
Proposed fix
Subtract tempFreeIpInventorys.size() from the remaining limit and stop early when the remaining limit is zero. Add a regression test covering multiple ranges.
Component
network / L3 network
Problem description
L3BasicNetwork.handle(APIGetFreeIpMsg)subtracts the cumulative result size (freeIpInventorys.size()) from the remaining limit after each IP range. The remaining limit must be reduced only by the number returned from the current range.With several IP ranges and a requested limit, the remaining limit can become negative and later ranges return only one address, so the API returns fewer addresses than requested even when enough free addresses exist.
Relevant code:
https://github.com/ZSvirt/zsvirt/blob/main/network/src/main/java/org/zstack/network/l3/L3BasicNetwork.java#L876
Steps to reproduce
GetFreeIpOfL3Networkwithlimit=100.Expected behavior
The API should return up to the requested limit across all matching IP ranges.
Proposed fix
Subtract
tempFreeIpInventorys.size()from the remaining limit and stop early when the remaining limit is zero. Add a regression test covering multiple ranges.