apache / apache/cloudstack

Bug: GuestNetworkGuru.allocate() incorrectly calls allocateDirectIp() for Isolated networks with SpecifyIpRanges=true

未关闭
#12,772 8 条评论 0 个 reaction 已指派 1 人 已被 @weizhouapache 认领 在 GitHub 查看
component:networking Severity:Major type:bug
主要语言
Java
星标
3.1k
派生
1.4k
平均合并
6 天 19 小时
30 天内合并 PR
32

描述

##### ISSUE TYPE
* Bug Report

##### COMPONENT NAME

~~~
GuestNetworkGuru
~~~

##### CLOUDSTACK VERSION

~~~
main (4.22)
~~~

##### CONFIGURATION

- Advanced zone
- Network with `SpecifyIpRanges=true`
- Isolated network type with CIDR (e.g., 10.0.0.0/8 - private address space)
- All IPs in the zone's public pools are already allocated

##### SUMMARY

`GuestNetworkGuru.allocate()` incorrectly calls `allocateDirectIp()` for Isolated networks with `SpecifyIpRanges=true`. The `allocateDirectIp()` method is designed for Shared networks only and attempts to allocate IPs from zone-wide VLAN pools. For Isolated networks with `SpecifyIpRanges=true`, this causes `InsufficientAddressCapacityException` because Isolated networks should allocate IPs from their own CIDR, not from VLAN pools.

##### STEPS TO REPRODUCE

1. Create an Advanced zone with VLAN ranges configured (e.g., 10.1.1.100-10.1.1.200)
2. Create an Isolated network offering with `SpecifyIpRanges=true` and Source NAT service enabled
3. Create an Isolated network using this offering with CIDR like 10.0.0.0/8
4. Deploy a VM in this network when all IPs in the zone's VLAN pools are already allocated
5. The VM deployment fails with `InsufficientAddressCapacityException`

##### EXPECTED RESULTS

- For **Shared networks** with `SpecifyIpRanges=true`: IP allocation from VLAN pools using `allocateDirectIp()`
- For **Isolated networks** with `SpecifyIpRanges=true`: IP allocation from the network's CIDR using `acquireGuestIpAddress()`

The correct behavior should be:
1. Shared networks → use public IP pool from VLAN ranges
2. Isolated networks → use network's own CIDR for IP allocation

##### ACTUAL RESULTS

`GuestNetworkGuru.allocate()` at line 445-446:
```java
if (network.getSpecifyIpRanges()) {
_ipAddrMgr.allocateDirectIp(nic, dc, vm, network, nic.getRequestedIPv4(), null);
}
```

This unconditionally calls `allocateDirectIp()` for ANY network with `SpecifyIpRanges=true`, regardless of network type.

The stack trace shows:
```
WARN [c.c.n.IpAddressManagerImpl] Unable to get ip address in zone id=1, network id=295
ERROR [c.c.v.UserVmManagerImpl] error during resource reservation and allocation com.cloud.exception.InsufficientAddressCapacityException: Insufficient address capacityScope=interface com.cloud.dc.DataCenter; id=1
```

##### ROOT CAUSE
`GuestNetworkGuru.allocate()` does not check the network type (`getGuestType()`) before calling `allocateDirectIp()`. The method is only valid for Shared networks (`GuestType.Shared`), but it's being called for Isolated networks as well.

The fix should add a network type check:
```java
if (network.getSpecifyIpRanges()) {
if (network.getGuestType() == GuestType.Shared) {
_ipAddrMgr.allocateDirectIp(nic, dc, vm, network, nic.getRequestedIPv4(), null);
} else {
// For Isolated/L2 networks, use acquireGuestIpAddress() to get IP from network CIDR
}
}
```

##### FILES AFFECTED
- `server/src/main/java/com/cloud/network/guru/GuestNetworkGuru.java` - lines 445-446

ps:
actually I'm not sure for root cause. it's a little complicated

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。