apache / apache/cloudstack

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

Đang mở
#12,772 8 bình luận 0 reaction 1 người được giao Được @weizhouapache nhận Xem trên GitHub
component:networking Severity:Major type:bug
Ngôn ngữ chính
Java
Star
3.1k
Fork
1.4k
Merge trung bình
6 ngày 19 giờ
Pull request đã merge (30 ngày)
32

Mô tả

##### 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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.