Skip to content

[ZSvirt] bug: GetFreeIp returns fewer addresses across multiple IP ranges #29

Description

@tllovesxs

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

  1. Create an L3 network with at least six non-overlapping IP ranges, each with at least 20 free IPs.
  2. Call GetFreeIpOfL3Network with limit=100.
  3. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions