Skip to content

network: custom DHCP range for isolated networks (API and UI) - #14217

Open
rootnomad wants to merge 10 commits into
apache:mainfrom
rootnomad:feature/isolated-dhcp-range
Open

rootnomad wants to merge 10 commits into
apache:mainfrom
rootnomad:feature/isolated-dhcp-range

Conversation

@rootnomad

Copy link
Copy Markdown
Collaborator

Description

An isolated guest network allocates guest IPs from the whole CIDR, so there is no way
to reserve part of the address space or keep the DHCP pool to a sub-range. createNetwork
already takes startip/endip, but NetworkServiceImpl only uses them for shared
networks.

This stores the start and end IP on an isolated network as a DHCP range, in two new
networks columns dhcp_start_ip/dhcp_end_ip, validated to be within the network CIDR,
in order, and not to include the gateway. NetworkModelImpl.getAvailableIps then restricts
the guest IP pool to that range when it is set; without one the whole CIDR is used, so
existing networks are unaffected.

The dnsmasq config on the VR is unchanged: for an isolated network it serves the host entry
CloudStack writes for the IP it allocated, so constraining the allocation is enough and no
system VM template change is needed. The range is returned by listNetworks as startip
and endip.

Creating an isolated network with a range needs gateway and netmask passed too
(already enforced by createNetwork), so the CIDR is deterministic. The create form shows
the start and end IP fields once a gateway is entered, and the network details tab shows the
range on an existing network, so the whole flow is usable from the UI.

Fixes: #12661

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Screenshots (if appropriate):
dhcp-create-form
dhcp-vms-in-network

Isolated network detail showing the DHCP range, and the deployed VMs leased inside it.

How Has This Been Tested?

Unit tests in server, 101 green. NetworkModelImplTest adds two for getAvailableIps:
the pool is restricted to the range when set, and is the whole CIDR (minus the gateway)
when it is not. NetworkServiceImplTest adds five for the validation: a valid range is
stored, the end defaults to the start, and a range outside the CIDR, a start greater than
the end, or a range that includes the gateway are each rejected. DatabaseUpgradeCheckerTest
is green with the schema change. The two changed UI files pass eslint clean.

Manually on a KVM advanced zone. Created an isolated network with gateway 10.99.99.1,
netmask /24 and a DHCP range 10.99.99.10-10.99.99.20, confirmed listNetworks returned
that range, then deployed three VMs on it. All three leased inside the range
(10.99.99.14, .15, .19), where without the change they would draw from the whole /24.

How did you try to break this feature and the system with this change?

  • Range outside the CIDR, reversed range, and a range covering the gateway are all rejected
    at create time.
  • A network created without a range still allocates from the whole CIDR, so existing
    networks and shared networks are unchanged.
  • Deployed several VMs against an 11-address range and confirmed each landed inside it.

@rootnomad rootnomad changed the title network: custom DHCP range for isolated networks (API and UI) network: custom DHCP range for isolated networks (API and UI) Sep 21, 2026
@github-actions

Copy link
Copy Markdown

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@codecov

codecov Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.44444% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 21.18%. Comparing base (8eaff97) to head (6f38cba).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...ain/java/com/cloud/network/NetworkServiceImpl.java 88.88% 6 Missing and 1 partial ⚠️
...ack/api/command/user/network/UpdateNetworkCmd.java 0.00% 6 Missing ⚠️
...pache/cloudstack/api/response/NetworkResponse.java 0.00% 6 Missing ⚠️
...src/main/java/com/cloud/api/ApiResponseHelper.java 0.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              main   #14217       +/-   ##
============================================
+ Coverage     3.86%   21.18%   +17.32%     
- Complexity       0    21612    +21612     
============================================
  Files          494     6080     +5586     
  Lines        42890   552086   +509196     
  Branches      8142    73995    +65853     
============================================
+ Hits          1657   116974   +115317     
- Misses       41001   421294   +380293     
- Partials       232    13818    +13586     
Flag Coverage Δ
uitests 3.86% <ø> (+<0.01%) ⬆️
unittests 22.65% <74.44%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

Copy link
Copy Markdown

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@rootnomad
rootnomad force-pushed the feature/isolated-dhcp-range branch from 6ba5120 to 590e476 Compare October 8, 2026 18:25
@Damans227

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@Damans227 a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 19501

@Damans227 Damans227 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @rootnomad, tested both fixes on a kvm lab and they work. LGTM

@Damans227

Copy link
Copy Markdown
Contributor

tested the two fixes from 1bade4b on a kvm lab. a bad range is refused and no network is left behind. shrinking with guestvmcidr is refused when the range wont fit, and works when it does.

Complete async job-42, jobStatus: FAILED, resultCode: 431 ... "The network has a custom DHCP range 10.2.2.100-10.2.2.110 that falls outside the requested Guest VM CIDR 10.2.2.0/26.

@nvazquez

Copy link
Copy Markdown
Contributor

@blueorangutan test

@nvazquez nvazquez added this to the 24.0 milestone Oct 29, 2026
@RosiKyu

RosiKyu commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@RosiKyu a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@weizhouapache

Copy link
Copy Markdown
Member

can we simply honor the start_ip and end_ip, instead of introducing new columns ?

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian test result (tid-17614)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 68547 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr14217-t17614-kvm-ol8.zip
Smoke tests completed. 153 look OK, 5 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File
test_isolated_network_custom_dhcp_range Error 68.91 test_isolated_network_dhcp_range.py
test_01_sys_vm_start Failure 181.04 test_secondary_storage.py
test_11_destroy_ssvm Failure 923.09 test_ssvm.py
test_1_userdata_on_ssvm Failure 921.41 test_systemvm_userdata.py
test_01_vpc_site2site_vpn_multiple_options Failure 503.91 test_vpc_vpn.py

@RosiKyu

RosiKyu commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

@rootnomad the smoke run on the current commit has 5 errors, and one of them is the new test from this PR: test_isolated_network_custom_dhcp_range (Error, test_isolated_network_dhcp_range.py). Could you please check it in the Marvin logs linked in the result above?

Could you please also answer @weizhouapache's question above (using the existing start_ip and end_ip instead of the new columns), and look at the 3 open review threads from @DaanHoogland?

I will run the lab test once the design question is settled and the new test passes. Thank you!

@rootnomad

Copy link
Copy Markdown
Collaborator Author

@weizhouapache good point. Reworked in 8f911ef to drop the new columns: the custom DHCP range is now stored as network details (dhcpStartIp, dhcpEndIp) instead of the dhcp_start_ip and dhcp_end_ip columns, and read back from the details during guest IP allocation, on the Guest VM CIDR reservation check and in the network response. I kept it off the vlan IP range table on purpose, since a SourceNat isolated network creates no vlan range (it allocates guest IPs straight from the CIDR), so network details is the minimal fit without changing how isolated networks allocate.

@RosiKyu the design is settled above. The new smoke test failure was a cleanup ordering bug in the test, not the feature: the asserts passed (the VM got an IP inside the custom range), it only failed in tearDown because the network was deleted before the VM. Fixed by deleting the VM first.

@DaanHoogland the reservation-within-CIDR check is now extracted into its own method with javadoc. The getDhcpStartIp accessor was removed in favour of the detail keys, so that earlier javadoc suggestion no longer applies.

Ready for the lab re-run.

@RosiKyu

RosiKyu commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

@rootnomad thank you for the rework and the test fix!

@RosiKyu

RosiKyu commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@RosiKyu a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

@weizhouapache

Copy link
Copy Markdown
Member

thanks @rootnomad for the update.

a few things I noticed:

  • it works fine for isolated networks with source NAT.
  • for isolated networks without source NAT, startip and endip are required, so we need to check if it conflicts with this PR.
  • have you tested vpc tiers ? they are isolated networks as well.
  • it looks like the update of dhcp ip range is not implemented yet. isn't it ?

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 20189

@rootnomad
rootnomad force-pushed the feature/isolated-dhcp-range branch from dd21d46 to 9582ea4 Compare November 26, 2026 21:05
@rootnomad

Copy link
Copy Markdown
Collaborator Author

Thanks @weizhouapache.

  • Routed isolated networks: start-end IP there is already the vlan range, so the custom DHCP range is scoped to isolated networks with source NAT (which allocate from the CIDR). Routed networks are unchanged.
  • VPC tiers: a source NAT tier allocates from the tier CIDR through the same getAvailableIps path, so it is supported now, on create and update. Routed VPC tiers (no source NAT) keep their own range, like routed isolated networks. The gate is Isolated plus source NAT, covering standalone networks and VPC tiers alike.
  • Update: updateNetwork takes startip/endip, validated within the CIDR; an empty startip clears it.

Unit tests cover the gate and the update path; smoke tests check a VM lands in the range on a standalone network, after an update, and on a source NAT VPC tier.

@weizhouapache

Copy link
Copy Markdown
Member

Thanks @weizhouapache.

  • Routed isolated networks: start-end IP there is already the vlan range, so the custom DHCP range is scoped to isolated networks with source NAT (which allocate from the CIDR). Routed networks are unchanged.
  • VPC tiers: a source NAT tier allocates from the tier CIDR through the same getAvailableIps path, so it is supported now, on create and update. Routed VPC tiers (no source NAT) keep their own range, like routed isolated networks. The gate is Isolated plus source NAT, covering standalone networks and VPC tiers alike.
  • Update: updateNetwork takes startip/endip, validated within the CIDR; an empty startip clears it.

Unit tests cover the gate and the update path; smoke tests check a VM lands in the range on a standalone network, after an update, and on a source NAT VPC tier.

thanks

please also consider secondary/additional IPs too

  • acquire secondary IP with a specific IP in the range
  • acquire secondary IP with a specific IP not in the range, which should fail
  • acquire secondary IP without specific IP

@github-actions

Copy link
Copy Markdown

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

An isolated guest network allocates guest IPs from the whole CIDR, so there is no
way to reserve part of the address space or restrict the DHCP pool. createNetwork
already takes startip and endip, but they were only used for shared networks.

This stores the start and end IP on an isolated network as a DHCP range, in two new
networks columns dhcp_start_ip and dhcp_end_ip, validated to be within the network
CIDR, in order, and not to include the gateway. NetworkModelImpl.getAvailableIps
then restricts the guest IP pool to that range when it is set. The dnsmasq config on
the VR is unchanged, since it serves the host entry CloudStack writes for the IP it
allocated, so no system VM template change is needed. Without a range the whole CIDR
is used, so existing networks are unaffected. The range is returned by listNetworks.
Show the start/end IP fields on the isolated network create form once a
gateway is set, and surface the range on the network details tab so an
operator can see and set the guest IP allocation window without the API.
… it on reservation

Validate a custom isolated-network DHCP range before committing the network, so a
range outside the CIDR (or reversed, or over the gateway) is rejected up front
instead of throwing after the network is saved and leaving an orphaned network.
The checks move into validateIsolatedNetworkDhcpRange, reused by
storeIsolatedNetworkDhcpRange.

Also reject an IP reservation (guestvmcidr) that would leave the stored DHCP range
outside the reserved Guest VM CIDR, which would otherwise starve guest IP
allocation.
Addresses the review request not to introduce new columns. The optional custom
DHCP range for an isolated network is now stored as network details (dhcpStartIp,
dhcpEndIp) instead of dedicated dhcp_start_ip and dhcp_end_ip columns on the
networks table, and read back from the details during guest IP allocation, on the
Guest VM CIDR reservation check and when building the network response. The
reservation-within-CIDR check is extracted into its own method.
… allow updating it

A custom DHCP range applies to an isolated network that allocates guest IPs
from its CIDR, that is a network with source NAT. This covers a standalone
source NAT isolated network and a source NAT VPC tier, both of which allocate
from the CIDR. A routed (non source NAT) isolated network and a shared network
keep start and end IP for their own IP range. Add updateNetwork start and end
IP to change or clear the range on an existing network, validated before it is
persisted so a bad range leaves the existing one in place.
acquireGuestIpAddress filtered the random pick to the custom DHCP range,
but a specific requested IP was only checked against the CIDR, so a
secondary IP, a VM deployed with an IP or a NIC IP update could still take
an address outside the range. Reject a requested IP that is not in the
allocatable set. Without a custom range that set is every free address in
the CIDR, so nothing changes for other networks.
@rootnomad
rootnomad force-pushed the feature/isolated-dhcp-range branch from 9582ea4 to 91b95d2 Compare December 2, 2026 16:00
@rootnomad

rootnomad commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

Thanks @weizhouapache, you were right. A secondary IP outside the range was still allowed, same for a VM deployed with a specific IP. Fixed in 4222ed4 and added your three cases to the smoke test, it passes on a 2 host KVM env. Also rebased on main for the conflict.

…dation paths

Cover assertCustomDhcpRangeWithinGuestVmCidr, the DHCP range validation
without an end IP or a gateway and with an end IP outside the CIDR, an
unknown offering on update, and getAvailableIps with a half set range.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow Custom DHCP Range for Isolated Guest Networks

7 participants