apache / apache/cloudstack

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

Abierto
#12,772 8 comentarios 0 reacciones 1 asignado Reclamado por @weizhouapache Ver en GitHub
component:networking Severity:Major type:bug
Lenguaje dominante
Java
Estrellas
3.1k
Forks
1.4k
Merge medio
6 d 19 h
PR fusionados (30 d)
32

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.